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
file dist/gdb-stub_atmega644p.elf
set serial baud 115200
+#target remote /dev/pts/13
target remote /dev/ttyUSB1
-#--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
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();
"__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"
}
}
- 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);
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));
}
} 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);
// 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 {
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);
}
}
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;
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;