From 09b10c7f726e22330c99404fda5e843a18914ae3 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Sat, 20 Jul 2024 12:22:00 +0200 Subject: [PATCH] ... --- software/gdb-stub/.gdbinit | 4 +++ software/gdb-stub/.simucinit | 9 ++++--- software/gdb-stub/src/blgdb.cpp | 4 +-- software/gdb-stub/src/bootloader.cpp | 16 ++---------- software/gdb-stub/src/bootloader.h | 3 --- software/gdb-stub/src/gdb.cpp | 18 +++++++++----- software/gdb-stub/src/gdb.h | 37 ++++++++++++++++------------ 7 files changed, 46 insertions(+), 45 deletions(-) diff --git a/software/gdb-stub/.gdbinit b/software/gdb-stub/.gdbinit index 3001274..8ee87c7 100644 --- a/software/gdb-stub/.gdbinit +++ b/software/gdb-stub/.gdbinit @@ -1,6 +1,9 @@ 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 @@ -10,5 +13,6 @@ set non-stop 1 file dist/gdb-stub_atmega644p.elf set serial baud 115200 +#target remote /dev/pts/13 target remote /dev/ttyUSB1 diff --git a/software/gdb-stub/.simucinit b/software/gdb-stub/.simucinit index 481f243..37fb596 100644 --- a/software/gdb-stub/.simucinit +++ b/software/gdb-stub/.simucinit @@ -1,10 +1,11 @@ -#--board nano-644 +--board nano-644 --pc 0xe000 ---frequency 12000000 ---mmcu atmega644p +#--frequency 12000000 +#--mmcu atmega644p #--log trace --log none #--nosync dist/gdb-stub_atmega644p.elf -../test-2024-07-02/sim/test-nano-644.elf +#sim/dist/gdb-stub_atmega644p.elf +#../test-2024-07-02/sim/test-nano-644.elf diff --git a/software/gdb-stub/src/blgdb.cpp b/software/gdb-stub/src/blgdb.cpp index d99f424..3ce570b 100644 --- a/software/gdb-stub/src/blgdb.cpp +++ b/software/gdb-stub/src/blgdb.cpp @@ -29,9 +29,9 @@ namespace blgdb { void __attribute__((naked)) setGdbConnectedAndStop () { asm volatile ( - "lds r24, 0x08fc \n" + "lds r24, 0x10fc \n" "ori r24, 0x01 \n" - "sts 0x08fc, r24 \n" // gdb.status.isConnected = 1 + "sts 0x10fc, r24 \n" // gdb.status.isConnected = 1 ); #ifdef SIMAVR // simjmptable_stopApplication(); diff --git a/software/gdb-stub/src/bootloader.cpp b/software/gdb-stub/src/bootloader.cpp index 07363cd..940d6a4 100644 --- a/software/gdb-stub/src/bootloader.cpp +++ b/software/gdb-stub/src/bootloader.cpp @@ -87,8 +87,8 @@ namespace bootloader { "__bootloader_start_from_reset: \n" "eor r1, r1 \n" "out 0x3f, r1 \n" // SREG = 0 - "ldi r28, 0xFF \n" // reset SP to 0x08ff (RAMEND) - "ldi r29, 0x08 \n" + "ldi r28, 0xFF \n" // reset SP to 0x01ff (RAMEND for Atmega644p) + "ldi r29, 0x10 \n" "out 0x3e, r29 \n" // SPH = 0x08 "out 0x3d, r28 \n" // SPL = 0xFF "nop \n" @@ -503,18 +503,6 @@ namespace bootloader { } } - void putStatus (int8_t uart) { - struct gdb::Gdb *pgdb = GDB_PTR; - putln(uart); - printChar(uart, 'S'); - printChar(uart, '-'); - printChar(uart, pgdb->status.isAppStarted ? 'A' : 'a'); - printChar(uart, pgdb->status.isStopped ? 'S' : 's'); - printChar(uart, pgdb->status.isConnected ? 'C' : 'x'); - printChar(uart, pgdb->status.isBreakpointValid ? 'B' : 'b'); - putln(uart); - } - void memputc (int8_t uart, PGM_P p) { char c = pgm_read_byte(p); printChar(uart, c); diff --git a/software/gdb-stub/src/bootloader.h b/software/gdb-stub/src/bootloader.h index 4476a35..fe80515 100644 --- a/software/gdb-stub/src/bootloader.h +++ b/software/gdb-stub/src/bootloader.h @@ -84,9 +84,6 @@ namespace bootloader { void memputs (int8_t uart, PGM_P p) ATT_OPTIMIZE ATT_SECTION_BOOTLOADER; int getc (int8_t uart) ATT_OPTIMIZE ATT_SECTION_BOOTLOADER; - // for development - void putStatus (int8_t uart) ATT_OPTIMIZE ATT_SECTION_BOOTLOADER; - uint8_t eepromReadByte (const uint8_t *p) ATT_OPTIMIZE ATT_SECTION_BOOTLOADER __attribute__ ((naked)); void eepromWriteByte (uint8_t *p, uint8_t value) ATT_OPTIMIZE ATT_SECTION_BOOTLOADER __attribute__ ((naked)); diff --git a/software/gdb-stub/src/gdb.cpp b/software/gdb-stub/src/gdb.cpp index 5f1335e..0c0d890 100644 --- a/software/gdb-stub/src/gdb.cpp +++ b/software/gdb-stub/src/gdb.cpp @@ -312,8 +312,8 @@ namespace gdb { } } else if (pgdb->ctrl.stop) { - pgdb->ctrl.stop = 0; if (!pgdb->status.isStopped && pgdb->buffer.state == idle) { + pgdb->ctrl.stop = 0; if (pgdb->status.isAppStarted) { #ifdef GDB_DEBUG_UART printdbgln(GDB_DEBUG_ID_STOP_APPLICATION); @@ -666,7 +666,6 @@ namespace gdb { // case 2: gdb.ctrl.continueApplication = 1; break; // case 3: gdb.ctrl.continueInterrupts = 1; break; // } - bootloader::putStatus(0); if (pgdb->status.isAppStarted) { pgdb->ctrl.interrupt = 1; } else { @@ -675,11 +674,18 @@ namespace gdb { xputsmem(gdb_OK); return; + } else if (i == 10 && sum == 0xc1) { // vCont;s;1;c + // 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; + 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); } } diff --git a/software/gdb-stub/src/gdb.h b/software/gdb-stub/src/gdb.h index 02e8955..702c6eb 100644 --- a/software/gdb-stub/src/gdb.h +++ b/software/gdb-stub/src/gdb.h @@ -26,25 +26,30 @@ namespace gdb { enum BufferState { idle = 0, data, esc, chk1, chk2, chk2err, exec, execerr, send, waitack }; - struct Status { - uint8_t errorFlags; // @0x08fb - uint8_t isConnected:1; // @0x08fc.0x01, address used in bootloader::jmpTableGdbStopApplication() - uint8_t isAppStarted:1; // 0x02 - uint8_t isStopped:1; // 0x04 - uint8_t isBreakpointValid:1; // 0x08 - uint8_t sendingNotification:1; // 0x10 + struct Status { // (gdb) print *((struct gdb::Status *)0x8010fb) + uint8_t errorFlags; // @0x18fb + uint8_t isConnected:1; // @0x18fc.0x01, address used in bootloader::jmpTableGdbStopApplication() + uint8_t isAppStarted:1; // @0x18fc.0x02 + uint8_t isStopped:1; // @0x18fc.0x04 + uint8_t isBreakpointValid:1; // @0x18fc.0x08 + uint8_t sendingNotification:1; // @0x18fc.0x10 }; - struct Control { - uint8_t clearErrors:1; // 0x01 - uint8_t interrupt:1; // 0x02 - uint8_t stop:1; // 0x04 - uint8_t proceed:1; // 0x08 - uint8_t kill:1; // 0x10 - uint8_t start:1; // 0x20 - uint8_t reset:1; // 0x40 + struct Control { // (gdb) print *((struct gdb::Control *)0x8010fd) + uint8_t clearErrors:1; // @0x18fd.0x01 + uint8_t interrupt:1; // @0x18fd.0x02 + uint8_t stop:1; // @0x18fd.0x04 + uint8_t proceed:1; // @0x18fd.0x08 + uint8_t kill:1; // @0x18fd.0x10 + uint8_t start:1; // @0x18fd.0x20 + uint8_t reset:1; // @0x18fd.0x40 }; + // struct Notify { + // uint8_t timer; + // uint8_t stop:1; + // }; + struct Buffer { enum BufferState state; uint8_t rpos; @@ -60,7 +65,7 @@ namespace gdb { uint8_t sfr; }; - struct Gdb { + struct Gdb { // (gdb) set print pretty (gdb) print *((gdb::Gdb *)0x80103b) uint8_t timer; struct Buffer buffer; struct Breakpoint breakpoint; -- 2.39.5