Commit 09b10c7f726e22330c99404fda5e843a18914ae3
receivedSat, 20. Jul 2024, 12:22:10 (by user sx)
Sat, 20 Jul 2024 10:22:10 +0000 (12:22 +0200)
authorManfred Steiner <sx@htl-kaindorf.at>
Sat, 20 Jul 2024 10:22:00 +0000 (12:22 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Sat, 20 Jul 2024 10:22:00 +0000 (12:22 +0200)
7 files changed:
software/gdb-stub/.gdbinit
software/gdb-stub/.simucinit
software/gdb-stub/src/blgdb.cpp
software/gdb-stub/src/bootloader.cpp
software/gdb-stub/src/bootloader.h
software/gdb-stub/src/gdb.cpp
software/gdb-stub/src/gdb.h

index 300127407a69b2077ecfcd31cb25007a5a52e351..8ee87c78114dab8feeea20b5edbca5b928d0e2e2 100644 (file)
@@ -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
 
index 481f243862e5b0328b768a538dc8ad317a37ea16..37fb596866c74c5a5ab6b1c6ba37bde40017ca1a 100644 (file)
@@ -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
 
index d99f4249eda9940c033e848ed41755e11ffa805b..3ce570bcff3cad5fa94394321e9ada408a14596d 100644 (file)
@@ -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();
index 07363cd7434be0655dc57096d2e870d112c9809f..940d6a4fc4b19e11d7fab2767d5d843cdb753a23 100644 (file)
@@ -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);
index 4476a35b94f075c95cd94f10292dfcaa02467016..fe8051566b2b2b925937eb81533f5d33d0631b7b 100644 (file)
@@ -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));
 
index 5f1335e7f9657a378539fae2e102d3eab1395633..0c0d890559cdc45f5b5ee1b835ad82ca3fd41e6e 100644 (file)
@@ -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);
                                }
 
                        }
index 02e8955d54483c1a5a04b0dba465732614b255a3..702c6ebaabc5b637523cc05aea6aa93df94b62ba 100644 (file)
@@ -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;