When debugging an AT91SAM9260 with a SAM-ICE and the gdb-server, we cannot single step through or set a breakpoint near certain memory accesses (seem to be accesses using a non-divisible by 4 offset from a register - the target location is aligned) - it causes an incorrect value to be loaded into the register. The correct value is loaded if we just run the code without setting breakpoints or single stepping. Here is more detail:
The first case incorrectly reads 0xff00 into r0 from a gpio register.
Setting a breakpoint and then continuing was ok, but single-
stepping the ldr instruction resulting in a bad read. Single stepping
through the other cases worked properly
Case 1:
mvn r1, #2304
ldr r0, [r1, #-195]
Case 2:
mvn r1, #2304
sub r1, r1, #195
ldr r0, [r1]
Case 3:
mov r1, #0xb0000000
mov r1, r1, asr #19
ldr r0, [r1, #60]
Playing around with different ldr offsets showed that anything that wasn't a
multiple of 4 would return a shifted value.
This seems to be a problem with the GDB server, because if I use the
jlink.exe utility to single-step through Case 1, it reads the PIO correctly.
---------------------------------------------------------------
The second issue is regarding resetting the chip, since we use a particular reset mode register setting that
disables NRST and causes the Atmel reset manager to be busy doing an external reset (using NRST) for
30ms after boot. We were having a real hard time being able to terminate and relaunch a process in
the debugger, as the j-link GDB server would try to reset the chip, then complain it could not connect.
We'd have to power cycle the board. Here is a gdb init routine that I found through trial and error that
seems to be working for now.. Note that it only works if you always use this - if it's already in the bad
state I described, this won't get it out of that state, you gotta powercycle.
target remote localhost:2331
# Wait for firmware external reset to be done?
monitor sleep 500
# Enable external reset pin
monitor long 0xFFFFFD08 0xA5000001
monitor reset
monitor speed 30
monitor speed auto
# Disable watchdog
monitor long 0xfffffd44 0xa0008000
The first case incorrectly reads 0xff00 into r0 from a gpio register.
Setting a breakpoint and then continuing was ok, but single-
stepping the ldr instruction resulting in a bad read. Single stepping
through the other cases worked properly
Case 1:
mvn r1, #2304
ldr r0, [r1, #-195]
Case 2:
mvn r1, #2304
sub r1, r1, #195
ldr r0, [r1]
Case 3:
mov r1, #0xb0000000
mov r1, r1, asr #19
ldr r0, [r1, #60]
Playing around with different ldr offsets showed that anything that wasn't a
multiple of 4 would return a shifted value.
This seems to be a problem with the GDB server, because if I use the
jlink.exe utility to single-step through Case 1, it reads the PIO correctly.
---------------------------------------------------------------
The second issue is regarding resetting the chip, since we use a particular reset mode register setting that
disables NRST and causes the Atmel reset manager to be busy doing an external reset (using NRST) for
30ms after boot. We were having a real hard time being able to terminate and relaunch a process in
the debugger, as the j-link GDB server would try to reset the chip, then complain it could not connect.
We'd have to power cycle the board. Here is a gdb init routine that I found through trial and error that
seems to be working for now.. Note that it only works if you always use this - if it's already in the bad
state I described, this won't get it out of that state, you gotta powercycle.
target remote localhost:2331
# Wait for firmware external reset to be done?
monitor sleep 500
# Enable external reset pin
monitor long 0xFFFFFD08 0xA5000001
monitor reset
monitor speed 30
monitor speed auto
# Disable watchdog
monitor long 0xfffffd44 0xa0008000