// #define GDB_DEBUG_UART_FLASHERASE GDB_DEBUG_UART
// #define GDB_DEBUG_UART_FLASHWRITE GDB_DEBUG_UART
// #define GDB_DEBUG_UART_REQUEST_PACKET GDB_DEBUG_UART
-#define GDB_DEBUG_UART_STOP_APPLICATION
+// #define GDB_DEBUG_UART_STOP_APPLICATION
#define GDB_DEBUG_ID_RESTART_BOOTLOADER 'B'
#define GDB_DEBUG_ID_FLASH_ERASE 'E'
return;
}
- // case 'T': {
- // // https://sourceware.org/gdb/onlinedocs/gdb/Packets.html#index-T-packet
- // // Find out if the thread thread-id is alive.
- // uint8_t ok = 0;
- // uint8_t threadId = p->buffer[1] - '0';
- // switch (threadId) {
- // case 1: ok = 1; break;
- // case 2: ok = gdb.status.isAppStarted; break;
- // case 3: ok = gdb.status.isAppStarted; break;
- // }
- // if (ok) {
- // gdb.status.currentThread = threadId; // ??? notwendig?
- // xputsmem(gdb_OK);
- // } else {
- // xputsmem(gdb_E00);
- // }
- // return;
- // }
-
case 'g': {
// https://sourceware.org/gdb/onlinedocs/gdb/Packets.html#index-g-packet
// Read general registers (used on gdb command load)
if (addH == 0) {
// flash
vx = pgm_read_byte( (PGM_P)px );
- } else if ( (uint16_t)px >= 0x900) {
- // eeprom
- vx = bootloader::eepromReadByte((uint8_t *)(px - 0x900));
+
+ } else if (addH == 0x80 && (uint16_t)px >= 0xf000) {
+ // eeprom (0x80f000..0x80ffff -> 4KiB)
+ vx = bootloader::eepromReadByte((uint8_t *)(px - 0xf000));
} else if (addH == 0x82) {
// crc8 from flash
vx = createFlashCrc((PGM_P)((uint16_t)px * SPM_PAGESIZE), SPM_PAGESIZE);
} else {
- // io-regs (0x000 - 0x0ff), sram (0x100 - 0x8ff)
+ // io-regs (0x000 - 0x0ff), sram (0x100 - 0x10ff)
vx = *px;
}
for (j = 0; j < l; j++) {
uint8_t vx = *pFrom++;
if (addH == 0) {
- // flash
+ // flash - write not supported yet
xputsmem(gdb_E00);
return;
- } else if (addH == 0xa0) {
- xputsmem(gdb_OK);
- return;
- }
- if ( (uint16_t)pTo >= 0xf000) {
- // eeprom
+
+ } else if ( addH == 0x80 && (uint16_t)pTo >= 0xf000) {
+ // eeprom (0x80f000..0x80ffff -> 4KiB)
bootloader::eepromWriteByte((uint8_t *)(pTo - 0xf000), vx);
- } else if ( (uint16_t)pTo >= 0x100) {
- // sram
- *pTo = vx;
+ } else if (addH == 0x82) {
+ // crc8 from flash -> not writeable
+ xputsmem(gdb_E00);
+ return;
+
+ } else if (addH == 0x80) {
+ if ((uint16_t)pTo < 0x20 || (uint16_t)pTo > 0x10ff) {
+ // io-regs (0x000 - 0x0ff), sram (0x100 - 0x10ff)
+ // invalid address
+ xputsmem(gdb_E00);
+ return;
+ } else {
+ *pTo = vx;
+ }
} else {
+ // address not supported
xputsmem(gdb_E00);
return;
}
// Tell the remote stub about features supported by GDB, and query the stub for features it supports.
xputc('$');
xputsmem(gdb_QNonStop);
- // xputc(';'); xputsmem(gdb_QXferMemoryMapRead);
- // xputc(';'); xputsmem(gdb_QStartNoAckMode);
- // xputc(';'); xputsmem(gdb_QXferExecFileRead);
xputc('#');
return;
} else if (
}
return;
- // } else if (i == 13 && sum == 0x4b) { // QStartNoAckMode
- // // https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#index-QStartNoAckMode-packet
- // // Request that the remote stub disable the normal ‘+’/‘-’ protocol acknowledgments (see Packet Acknowledgment).
- // xputsmem(gdb_OK);
-
-
-
- // } else if (i == 11 && sum == 0xbb) { // qfThreadInfo
- // // https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#index-qfThreadInfo-packet
- // // Start to obtain a list of all active thread IDs from the target
- // // !! don't user xputs here, because dgb_stub does not initialize static data in sram
- // xputsmem(gdb_m1_);
- // if (gdb.status.isAppStarted) {
- // xputc(',');
- // xputc('2');
- // xputc(',');
- // xputc('3');
- // }
- // xputc('#');
- // return;
-
} else if (i == 11 && sum == 0xc8) { // qsThreadInfo
// https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#index-qfThreadInfo-packet
// Continue to obtain a list of all active thread IDs from the target
(i == 6 && sum == 0xb9) // vCont;t (https://sourceware.org/gdb/onlinedocs/gdb/Packets.html#index-vCont-packet -> Resume the inferior, specifying different actions for each thread.)
|| (i == 5 && sum == 0x4e) // vCtrlC (https://sourceware.org/gdb/onlinedocs/gdb/Packets.html#index-vCtrlC-packet -> Interrupt remote target as if a control-C was pressed on the remote terminal.)
) {
- // uint8_t threadId = p->buffer[8] - '0';
- // gdb.status.currentThread = threadId & 0x03;
- // switch (threadId) {
- // case 1: gdb.ctrl.continueGdbStub = 1; break;
- // case 2: gdb.ctrl.continueApplication = 1; break;
- // case 3: gdb.ctrl.continueInterrupts = 1; break;
- // }
if (pgdb->status.isAppStarted) {
pgdb->ctrl.interrupt = 1;
} else {
// https://sourceware.org/gdb/onlinedocs/gdb/Packets.html#index-vCont-packet
// Resume the inferior, specifying different actions for each thread.
xputsmem(gdb_OK);
- pgdb->ctrl.stop = 1;
+ pgdb->status.isStopped = 0;
+ pgdb->ctrl.interrupt = 1;
return;
} else {
- bootloader::putnc(0, c, 1);
- bootloader::putnc(0, ' ', 1); bootloader::putUint8Hex(0, i);
- bootloader::putnc(0, ' ',2); bootloader::putUint8Hex(0, sum);
- bootloader::putln(0);
+ // bootloader::putnc(0, c, 1);
+ // bootloader::putnc(0, ' ', 1); bootloader::putUint8Hex(0, i);
+ // bootloader::putnc(0, ' ',2); bootloader::putUint8Hex(0, sum);
+ // bootloader::putln(0);
}
}
}
- // void reset () {
- // struct gdb::Gdb *pgdb = GDB_PTR;
- // memset((void *)&pgdb->buffer, 0, sizeof(pgdb->buffer) - BUFFER_SIZE);
- // }
-
void checkByteFromGdb () {
// don't use bootloader::printChar here, because checkByteFromGdb called from there
struct gdb::Gdb *pgdb = GDB_PTR;