From 88d89733a939f913b2b22d8feabd30fbf963d5c9 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Sat, 20 Jul 2024 16:38:39 +0200 Subject: [PATCH] ... --- software/gdb-stub/.gdbinit | 11 ++-- software/gdb-stub/.gdbinit-nano | 20 ++++++ software/gdb-stub/.gdbinit-sim | 19 ++++++ software/gdb-stub/src/gdb.cpp | 106 ++++++++++---------------------- 4 files changed, 77 insertions(+), 79 deletions(-) create mode 100644 software/gdb-stub/.gdbinit-nano create mode 100644 software/gdb-stub/.gdbinit-sim diff --git a/software/gdb-stub/.gdbinit b/software/gdb-stub/.gdbinit index 8ee87c7..4859227 100644 --- a/software/gdb-stub/.gdbinit +++ b/software/gdb-stub/.gdbinit @@ -1,3 +1,7 @@ +# start gdb with: +# avr-gdb -nx -x .gdbinit-sim `-ex="target remote $(cat /tmp/sim-megaavr-atmega644p-uart1)" +# avr-gdb -nx -x .gdbinit-nano + alias reset = set *((uint8_t *)0x8010fd) = 0x40 alias startapp = set *((uint8_t *)0x8010fd) = 0x20 alias killapp = set *((uint8_t *)0x8010fd) = 0x10 @@ -9,10 +13,9 @@ set history save on set history size unlimited set history remove-duplicates unlimited set pagination off -set non-stop 1 +#set non-stop 1 file dist/gdb-stub_atmega644p.elf set serial baud 115200 -#target remote /dev/pts/13 -target remote /dev/ttyUSB1 - +#target remote /dev/pts/19 +#target remote /dev/ttyUSB1 diff --git a/software/gdb-stub/.gdbinit-nano b/software/gdb-stub/.gdbinit-nano new file mode 100644 index 0000000..5efcc7b --- /dev/null +++ b/software/gdb-stub/.gdbinit-nano @@ -0,0 +1,20 @@ +# start gdb with `avr-gdb -nx -x .gdbinit-nano` + +alias reset = set *((uint8_t *)0x8010fd) = 0x40 +alias startapp = set *((uint8_t *)0x8010fd) = 0x20 +alias killapp = set *((uint8_t *)0x8010fd) = 0x10 +alias gdbstatus = print *((struct gdb::Status *)0x8010fb) +alias gdbctrl = print *((struct gdb::Control *)0x8010fd) +alias gdbbreakpoint = print *((struct gdb::Breakpoint *)0x8010d7) + +set history save on +set history size unlimited +set history remove-duplicates unlimited +set pagination off +set non-stop 1 +file dist/gdb-stub_atmega644p.elf + +set serial baud 115200 +#target remote /dev/pts/19 +target remote /dev/ttyUSB1 + diff --git a/software/gdb-stub/.gdbinit-sim b/software/gdb-stub/.gdbinit-sim new file mode 100644 index 0000000..f8ef345 --- /dev/null +++ b/software/gdb-stub/.gdbinit-sim @@ -0,0 +1,19 @@ +# start gdb with: avr-gdb -nx -x .gdbinit-sim `-ex="target remote $(cat /tmp/sim-megaavr-atmega644p-uart1)" + +alias reset = set *((uint8_t *)0x8010fd) = 0x40 +alias startapp = set *((uint8_t *)0x8010fd) = 0x20 +alias killapp = set *((uint8_t *)0x8010fd) = 0x10 +alias gdbstatus = print *((struct gdb::Status *)0x8010fb) +alias gdbctrl = print *((struct gdb::Control *)0x8010fd) +alias gdbbreakpoint = print *((struct gdb::Breakpoint *)0x8010d7) + +set history save on +set history size unlimited +set history remove-duplicates unlimited +set pagination off +set non-stop 1 +file dist/gdb-stub_atmega644p.elf + +set serial baud 115200 +#target remote /dev/pts/19 + diff --git a/software/gdb-stub/src/gdb.cpp b/software/gdb-stub/src/gdb.cpp index 0c0d890..711f06b 100644 --- a/software/gdb-stub/src/gdb.cpp +++ b/software/gdb-stub/src/gdb.cpp @@ -17,7 +17,7 @@ // #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' @@ -389,25 +389,6 @@ namespace gdb { 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) @@ -455,16 +436,17 @@ namespace gdb { 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; } @@ -494,22 +476,31 @@ namespace gdb { 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; } @@ -535,9 +526,6 @@ namespace gdb { // 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 ( @@ -612,27 +600,6 @@ namespace gdb { } 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 @@ -659,13 +626,6 @@ namespace gdb { (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 { @@ -678,14 +638,15 @@ namespace gdb { // 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); } } @@ -698,11 +659,6 @@ namespace gdb { } - // 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; -- 2.39.5