Commit 41a60e401dd76037da040a4937411097b59bd02e
receivedTue, 23. Jul 2024, 16:50:21 (by user sx)
Tue, 23 Jul 2024 14:50:21 +0000 (16:50 +0200)
authorManfred Steiner <sx@htl-kaindorf.at>
Tue, 23 Jul 2024 14:50:13 +0000 (16:50 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Tue, 23 Jul 2024 14:50:13 +0000 (16:50 +0200)
3 files changed:
software/gdb-stub/.gdbinit-gdbstub
software/gdb-stub/src/gdb.cpp
software/gdb-stub/src/gdb.h

index 0f63869c96afc065e6f8ef6bbd2bcfcc0f6444a7..1a053b4b47f3e0d4b84c39e2be81dc504bf11a8d 100644 (file)
@@ -2,7 +2,9 @@ target remote :1234
 layout split
 focus cmd
 #br *0
-#br gdb.cpp:296
+#br gdb.cpp:919
+#br gdb.cpp:92
+#br gdb.cpp:705
 #br gdb.cpp:317
 #br gdb.cpp:325
 #br *0x40
index 5602acc7a26a370e24d23fbd1653702e8504def8..d85064830bba7beebfa14a6d1c0de91ac1e07fe5 100644 (file)
@@ -408,7 +408,7 @@ namespace gdb {
                                pgdb->status.isAppStarted = 0;
                        }
 
-               } else if (pgdb->ctrl.notify && pgdb->buffer.state == idle) {
+               } else if (pgdb->ctrl.notify && pgdb->buffer.state.substate == idle) {
                        pgdb->ctrl.notify = 0;
                        pgdb->timer = 20;
                        xputsmem(gdb_StatusStop);
@@ -440,11 +440,11 @@ namespace gdb {
                struct gdb::Gdb *pgdb = GDB_PTR;
                struct Buffer *p = &pgdb->buffer;
 
-               if (p->state == execerr) {
+               if (p->state.substate == execerr) {
                        xputc('-');
-                       p->state = idle;
+                       p->state.substate = idle;
 
-               } else if (p->state == exec) {
+               } else if (p->state.substate == exec) {
                        xputc('+');
 
                        #ifdef GDB_DEBUG_UART_REQUEST
@@ -461,7 +461,7 @@ namespace gdb {
                        #endif
                        pgdb->status.isConnected = 1;
                        p->buffer[(p->rpos < sizeof(p->buffer) - 1) ? p->rpos : sizeof(p->buffer) - 1] = 0;
-                       p->state = send;
+                       p->state.substate = send;
                        uint8_t i;
 
                        switch(*p->buffer) {
@@ -686,17 +686,23 @@ namespace gdb {
                                        xputsmem(gdb_OK);
                                        return;
 
-                               } else if (i == 11 && sum == 0xa9) { // vFlashWrite:
+                               } else if (i == 10 && sum == 0x6f) { // vFlashWrite
                                        pgdb->ctrl.kill = 1;
                                        executeControl();
-                                       uint8_t i = 12;
+                                       char *pData = (char *)(RAMSTART + 0x400);
+                                       if (!pgdb->buffer.state.binpack || *pData++ != ':') {
+                                               xputsmem(gdb_E00);
+                                               return;
+                                       }
                                        uint32_t address;
-                                       uint8_t size = parseHex(p->buffer, i, &address);
-                                       i += size;
-                                       if (size <= 0 || p->buffer[i++] != ':') {
+                                       uint8_t aSize = parseHex(pData, 0, &address);
+                                       pData += aSize;
+                                       uint16_t size = (uint16_t)p->binpackPtr - (uint16_t)pData - 1;
+
+                                       if (aSize <= 0 || *pData++ != ':' || size <= 0 || size > 0x3ff) {
                                                xputsmem(gdb_E00);
                                        } else {
-                                               flashFill((uint8_t *)&p->buffer[i], p->rpos - i, (uint16_t)address);
+                                               flashFill((uint8_t *)pData, size, (uint16_t)address);
                                                xputsmem(gdb_OK);
                                        }
                                        return;
@@ -824,7 +830,7 @@ namespace gdb {
                                gputc(dec2hex((pbuf->chkSumToGdb >> 4) & 0x0f));
                                gputc(dec2hex(pbuf->chkSumToGdb & 0x0f));
                                if (!pgdb->status.isSendingNotification ) {
-                                       pbuf->state = waitack;
+                                       pbuf->state.substate = waitack;
                                }
                                break;
                        }
@@ -890,24 +896,32 @@ namespace gdb {
                struct gdb::Gdb *pgdb = GDB_PTR;
                struct Buffer *p = &pgdb->buffer;
                if (c == '$') {
-                       if (p->state != idle) {
+                       if (p->state.substate != idle) {
                                // incUint8Cnt(&gdb.status.errCnt);
                                pgdb->status.errorFlags |= 0x02;
                        }
                        p->chkSumFromGdb = 0;
                        p->rpos = 0;
-                       p->state = data;
+                       p->state.substate = data;
+                       p->state.binpack = 0;
+                       p->binpackPtr = (uint8_t *)(RAMEND + 1);
 
                } else {
-                       switch (p->state) {
+                       switch (p->state.substate) {
                                case data: {
                                        if (c == '#') {
-                                               p->state = chk1;
+                                               p->state.substate = chk1;
                                        } else {
                                                p->chkSumFromGdb += c;
+                                               if (p->rpos == 0x0b && p->chkSumFromGdb == 0xa9) { //$vFlashWrite:
+                                                       pushReceivedByte(c); // increase p->rpos
+                                                       p->state.binpack = 1;
+                                                       p->binpackPtr = (uint8_t *)(RAMSTART + 0x400); // first 0x400 bytes for flashFill()
+                                               }
                                                if (c == '}') {
-                                                       p->state = esc;
-
+                                                       p->state.substate = esc;
+                                               } else if (p->state.binpack) {
+                                                       *p->binpackPtr++ = c;
                                                } else {
                                                        pushReceivedByte(c);
                                                }
@@ -917,18 +931,23 @@ namespace gdb {
 
                                case esc: {
                                        p->chkSumFromGdb += c;
-                                       pushReceivedByte(c ^ 0x20);
-                                       p->state = data;
+                                       c ^= 0x20;
+                                       if (p->state.binpack) {
+                                               *p->binpackPtr++ = c;
+                                       } else {
+                                               pushReceivedByte(c);
+                                       }
+                                       p->state.substate = data;
                                        break;
                                }
 
                                case chk1: {
                                        int8_t v = hexValueFromChar(c);
                                        if (v < 0) {
-                                               p->state = chk2err;
+                                               p->state.substate = chk2err;
                                        } else {
                                                p->chkSumFromGdb -= (v << 4);
-                                               p->state = chk2;
+                                               p->state.substate = chk2;
                                        }
                                        break;
                                }
@@ -936,7 +955,7 @@ namespace gdb {
                                case chk2err: {
                                        // incUint8Cnt(&gdb.status.errCnt);
                                        pgdb->status.errorFlags |= 0x04;
-                                       p->state = execerr;
+                                       p->state.substate = execerr;
                                        break;
                                }
 
@@ -948,23 +967,23 @@ namespace gdb {
                                        if (v < 0 || p->chkSumFromGdb != 0) {
                                                // incUint8Cnt(&gdb.status.errCnt);
                                                pgdb->status.errorFlags |= 0x08;
-                                               p->state = execerr;
+                                               p->state.substate = execerr;
 
                                        } else {
-                                               p->state = p->rpos <= BUFFER_SIZE ? exec : execerr;
+                                               p->state.substate = p->rpos <= BUFFER_SIZE ? exec : execerr;
                                        }
                                        break;
                                }
 
                                case waitack: {
                                        if (c == '-') {
-                                               p->state = send;
+                                               p->state.substate = send;
                                        } else {
                                                if (c != '+') {
                                                        // incUint8Cnt(&gdb.status.errCnt);
                                                        pgdb->status.errorFlags |= 0x10;
                                                }
-                                               p->state = idle;
+                                               p->state.substate = idle;
                                        }
                                        break;
                                }
index 56c4a95dc4b2bf53b540c22827306b0f6297af62..37c12366284e27cdd1d59c7aea52abb1d1c1f3c5 100644 (file)
@@ -25,7 +25,7 @@ namespace gdb {
        //const uint8_t BUFFER_SIZE = 13 + 5 + 128 + 3; // "$vFlashWrite:" + "ffff:" + 128 Bytes  + "#00"
        const uint16_t BUFFER_SIZE = 13 + 5 + 300 + 3; // "$vFlashWrite:" + "ffff:" + 128 Bytes  + "#00"
 
-       enum BufferState { idle = 0, data, esc, chk1, chk2, chk2err, exec, execerr, send, waitack };
+       enum BufferSubState { idle = 0, data, esc, chk1, chk2, chk2err, exec, execerr, send, waitack };
 
 
        struct Status { // (gdb) print ((gdb::Gdb *)0x801039)->status
@@ -49,11 +49,20 @@ namespace gdb {
                uint8_t notify:1;      // Bit 7
        };
 
+       struct BufferState {
+               uint8_t binpack:1; // Bit 0
+               uint8_t dbg1:1;    // Bit 1  (for debugging)
+               uint8_t dbg2:1;    // Bit 2  (for debugging)
+               enum BufferSubState substate;
+       };
+
        struct Buffer { // (gdb) print ((gdb::Gdb *)0x801039)->buffer
-               enum BufferState state;
+               // enum BufferState state;
+               struct BufferState state;
                uint16_t rpos;
                uint8_t chkSumFromGdb;
                uint8_t chkSumToGdb;
+               uint8_t *binpackPtr;
                char    buffer[BUFFER_SIZE];
        };