how to single step lpc2292?

Hello!

I have basic memory access working with the amontec jtagkey. Now I’d like to download and run a program. I have this configuration:

#daemon configuration
telnet_port 4444
gdb_port 3333

#interface
interface ft2232
ft2232_device_desc "Amontec JTAGkey A"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0xcff8
jtag_speed 1
#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config trst_and_srst srst_pulls_trst

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe

#target configuration
daemon_startup reset
#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
target_script 0 reset h2292_init.script
run_and_halt_time 0 30
working_area 0 0x40000000 0x40000 nobackup

#flash configuration
#flash bank lpc2000 0x0 0x40000 0 0 lpc2000_v1 0 14765 calc_checksum
flash bank cfi 0x80000000 0x200000 2 2 0

This is my test program:

# define CHIP_WR(baseadr,cadr,val) \
         *((volatile unsigned short *)((baseadr)+(cadr)))=(val)

# define CHIP_RD(baseadr,cadr) \
         (*(1+(volatile unsigned char *)((baseadr)+(cadr))))

static void chipcmd (unsigned char *addr, unsigned cmd)
{
    unsigned int u1=0x5555;
    unsigned int u2=0x2aaa;

    CHIP_WR(addr, u1, 0xaaaa);  /* unl1 */
    CHIP_WR(addr, u2, 0x5555);  /* unl2 */
    CHIP_WR(addr, u1, cmd);
}

static void erase (unsigned char *addr)
{
    unsigned char rval;

    CHIP_WR(addr, 0x000, 0xf0f0);  /* reset */
    chipcmd(addr, 0x8080); /* erase */
    chipcmd(addr, 0x1010); /* chip erase */

    while ((rval = CHIP_RD (addr, 0)) != 0xff) {
        /* FIXME: check timeout */
    }
    while (1)
        ;
}

void dohalt (void)
{
}

void doerase (void)
{
    erase ((unsigned char *)0x80000000);
    dohalt ();
}

This is how I compile the test program:

arm-elf-gcc -c  -Wall -nostartfiles -fomit-frame-pointer -fpic test.c
arm-elf-gcc -Wall -nostartfiles -fomit-frame-pointer -fpic -Wl,-Map -Wl,map test.o  -o test.elf
arm-elf-objcopy -O binary test.elf test.bin

This is the script to load/execute the program:

halt

# Load binary into external RAM
#
load_binary test.bin 0x81000000

# Check whether binary was loaded properly
#
dump_binary test.bla 0x81000000 272

# Linker's memory map says my entry point is located on 0x000080fc, but since
# it is compiled with -fpic, we should be able to move the code to 0x81000000,
# thus the entry point moves 32kb downward.
reg pc 0x810000fc

poll
mdw 0x81000000 70
reg
step
reg

shutdown

I would have expected that exactly one instruction would be executed and the processor would halt after that. But this is what happens:

Info:    openocd.c:84 main(): Open On-Chip Debugger (2006-11-22 14:00 CEST)
Warning: arm7_9_common.c:683 arm7_9_assert_reset(): srst resets test logic, too
Info:    target.c:219 target_init_handler(): executing reset script 'h2222_init.script'
Info:    configuration.c:50 configuration_output_handler(): requesting target halt...
Warning: arm7_9_common.c:842 arm7_9_halt(): target was already halted
Info:    configuration.c:50 configuration_output_handler(): target already halted
Info:    configuration.c:50 configuration_output_handler(): downloaded 272 byte in 0s 13318us
Info:    configuration.c:50 configuration_output_handler(): dumped 272 byte in 0s 20778us
Info:    configuration.c:50 configuration_output_handler(): pc (/32): 0x810000fc
Info:    configuration.c:50 configuration_output_handler(): target state: halted
Info:    configuration.c:50 configuration_output_handler(): target halted in Thumb state due to debug request, current mode: System
Info:    configuration.c:50 configuration_output_handler(): cpsr: 0x4000001f pc: 0x810000fc
Info:    configuration.c:50 configuration_output_handler(): 0x81000000: e24dd010 e58d000c e58d1008 e3a03c55 e2833055 e58d3004 e3a03daa e283302a
Info:    configuration.c:50 configuration_output_handler(): 0x81000020: e58d3000 e59d300c e59d2004 e0833002 e3e02c55 e2422055 e1a01002 e1c310b0
Info:    configuration.c:50 configuration_output_handler(): 0x81000040: e59d300c e59d2000 e0833002 e3a02c55 e2822055 e1a01002 e1c310b0 e59d300c
Info:    configuration.c:50 configuration_output_handler(): 0x81000060: e59d2004 e0833002 e1dd20b8 e1c320b0 e28dd010 e1a0f00e e92d4000 e24dd008
Info:    configuration.c:50 configuration_output_handler(): 0x81000080: e58d0004 e59d3004 e3e02c0f e242200f e1a01002 e1c310b0 e59d0004 e3a01902
Info:    configuration.c:50 configuration_output_handler(): 0x810000a0: e2811080 ebffffd5 e59d0004 e3a01a01 e2811010 ebffffd1 e3a03001 e59d2004
Info:    configuration.c:50 configuration_output_handler(): 0x810000c0: e2823001 e5d32000 e5cd2003 e20230ff e35300ff 1a000000 ea000000 eafffff5
Info:    configuration.c:50 configuration_output_handler(): 0x810000e0: e1a00000 ea000000 ea000000 eafffffc e28dd008 e8bd8000 e1a0f00e e92d4000
Info:    configuration.c:50 configuration_output_handler(): 0x81000100: e3a00102 ebffffdb ebfffffa e8bd8000 00000000 00000000
Info:    configuration.c:50 configuration_output_handler(): (0) r0 (/32): 0x000000ff (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (1) r1 (/32): 0x00003df3 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (2) r2 (/32): 0x00000000 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (3) r3 (/32): 0xe0020004 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (4) r4 (/32): 0x000001d0 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (5) r5 (/32): 0x0001c000 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (6) r6 (/32): 0x40000d8c (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (7) r7 (/32): 0x400035d0 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (8) r8 (/32): 0x400036c4 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (9) r9 (/32): 0xe5cd2003 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (10) r10 (/32): 0x400034a8 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (11) r11 (/32): 0x400036e8 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (12) r12 (/32): 0x000012a9 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (13) r13_usr (/32): 0x40003590 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (14) lr_usr (/32): 0x00003df3 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (15) pc (/32): 0x810000fc (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (16) r8_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (17) r9_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (18) r10_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (19) r11_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (20) r12_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (21) r13_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (22) lr_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (23) r13_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (24) lr_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (25) r13_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (26) lr_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (27) r13_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (28) lr_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (29) r13_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (30) lr_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (31) cpsr (/32): 0x4000001f (dirty: 0, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (32) spsr_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (33) spsr_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (34) spsr_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (35) spsr_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (36) spsr_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (37) debug_ctrl (/6): 0x05 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (38) debug_status (/5): 0x09 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (39) comms_ctrl (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (40) comms_data (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (41) watch 0 addr value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (42) watch 0 addr mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (43) watch 0 data value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (44) watch 0 data mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (45) watch 0 control value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (46) watch 0 control mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (47) watch 1 addr value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (48) watch 1 addr mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (49) watch 1 data value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (50) watch 1 data mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (51) watch 1 control value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (52) watch 1 control mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    target.c:219 target_init_handler(): executing reset script 'h2222_init.script'
Info:    configuration.c:50 configuration_output_handler(): requesting target halt...
Warning: arm7_9_common.c:842 arm7_9_halt(): target was already halted
Info:    configuration.c:50 configuration_output_handler(): target already halted
Info:    configuration.c:50 configuration_output_handler(): downloaded 272 byte in 0s 11907us
Info:    configuration.c:50 configuration_output_handler(): dumped 272 byte in 0s 19976us
Info:    configuration.c:50 configuration_output_handler(): pc (/32): 0x810000fc
Info:    configuration.c:50 configuration_output_handler(): target state: halted
Info:    configuration.c:50 configuration_output_handler(): target halted in Thumb state due to single step, current mode: System
Info:    configuration.c:50 configuration_output_handler(): cpsr: 0x0000001f pc: 0x810000fc
Info:    configuration.c:50 configuration_output_handler(): 0x81000000: e24dd010 e58d000c e58d1008 e3a03c55 e2833055 e58d3004 e3a03daa e283302a
Info:    configuration.c:50 configuration_output_handler(): 0x81000020: e58d3000 e59d300c e59d2004 e0833002 e3e02c55 e2422055 e1a01002 e1c310b0
Info:    configuration.c:50 configuration_output_handler(): 0x81000040: e59d300c e59d2000 e0833002 e3a02c55 e2822055 e1a01002 e1c310b0 e59d300c
Info:    configuration.c:50 configuration_output_handler(): 0x81000060: e59d2004 e0833002 e1dd20b8 e1c320b0 e28dd010 e1a0f00e e92d4000 e24dd008
Info:    configuration.c:50 configuration_output_handler(): 0x81000080: e58d0004 e59d3004 e3e02c0f e242200f e1a01002 e1c310b0 e59d0004 e3a01902
Info:    configuration.c:50 configuration_output_handler(): 0x810000a0: e2811080 ebffffd5 e59d0004 e3a01a01 e2811010 ebffffd1 e3a03001 e59d2004
Info:    configuration.c:50 configuration_output_handler(): 0x810000c0: e2823001 e5d32000 e5cd2003 e20230ff e35300ff 1a000000 ea000000 eafffff5
Info:    configuration.c:50 configuration_output_handler(): 0x810000e0: e1a00000 ea000000 ea000000 eafffffc e28dd008 e8bd8000 e1a0f00e e92d4000
Info:    configuration.c:50 configuration_output_handler(): 0x81000100: e3a00102 ebffffdb ebfffffa e8bd8000 00000000 00000000
Info:    configuration.c:50 configuration_output_handler(): (0) r0 (/32): 0x000000ff (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (1) r1 (/32): 0x00003df3 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (2) r2 (/32): 0x00000000 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (3) r3 (/32): 0xe0020004 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (4) r4 (/32): 0x000001d0 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (5) r5 (/32): 0x0001c000 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (6) r6 (/32): 0x40000d8c (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (7) r7 (/32): 0x400035d0 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (8) r8 (/32): 0x400036c4 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (9) r9 (/32): 0xe5cd2003 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (10) r10 (/32): 0x400034a8 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (11) r11 (/32): 0x400036e8 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (12) r12 (/32): 0x000012a9 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (13) r13_usr (/32): 0x40003590 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (14) lr_usr (/32): 0x00003df3 (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (15) pc (/32): 0x810000fc (dirty: 1, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (16) r8_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (17) r9_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (18) r10_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (19) r11_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (20) r12_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (21) r13_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (22) lr_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (23) r13_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (24) lr_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (25) r13_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (26) lr_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (27) r13_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (28) lr_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (29) r13_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (30) lr_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (31) cpsr (/32): 0x0000001f (dirty: 0, valid: 1)
Info:    configuration.c:50 configuration_output_handler(): (32) spsr_fiq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (33) spsr_irq (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (34) spsr_svc (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (35) spsr_abt (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (36) spsr_und (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (37) debug_ctrl (/6): 0x05 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (38) debug_status (/5): 0x09 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (39) comms_ctrl (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (40) comms_data (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (41) watch 0 addr value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (42) watch 0 addr mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (43) watch 0 data value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (44) watch 0 data mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (45) watch 0 control value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (46) watch 0 control mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (47) watch 1 addr value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (48) watch 1 addr mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (49) watch 1 data value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (50) watch 1 data mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (51) watch 1 control value (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    configuration.c:50 configuration_output_handler(): (52) watch 1 control mask (/32): 0x00000000 (dirty: 0, valid: 0)
Info:    target.c:219 target_init_handler(): executing reset script 'h2222_init.script'
[ ... ]

As you can see, the reset script is executed over and over again when the “step” command is executed. Looks like executing the instruction 0xe92d4000 resets the target. I am sure I’m doing something very stupid, but I can’t figure out what. Any ideas?

Hi

I think there may be an error in OpenOCD target.c:target_init_handler.

(for Dominic, developer.berlios.de is not in a good mood):

The target_init_handler must be unregistered from the callback list before processing of the reset_script, because if the target is halted during the processing of the reset_script then the target init handler is called (recursively) as event handler.

Try using run_and_halt instead of run_and_init and se if this helps.

Regards,

Magnus

Thanks for the answer, Magnus!

mlu:
I think there may be an error in OpenOCD target.c:target_init_handler.

(for Dominic, developer.berlios.de is not in a good mood):

The target_init_handler must be unregistered from the callback list before processing of the reset_script, because if the target is halted during the processing of the reset_script then the target init handler is called (recursively) as event handler.

This sounds reasonable. But why does the target do a reset in the first place? Or is this script called not only on reset but on halt, .too?

Try using run_and_halt instead of run_and_init and se if this helps.

I'll try this tomorrow, thanks!

mlu:
Try using run_and_halt instead of run_and_init and se if this helps.

I've tried now. The recursive loop don't occur anymore. But I have still troubles to get

reasonable behavior.from the target. Currently, I seem to have two major problems:

  1. It seems that after reset, the processor gets into a random state. Sometimes it is in Tumb mode after reset, sometimes it is in ARM mode. I don’t see how one can get proper execution when you can’t rely which instruction set is active after reset.

  2. In either mode, I can’t even get the first instruction to execute properly. According to the assembler output, the first instruction is

doerase:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, current_function_anonymous_args = 0
        mov     r0, #-2147483648

If I understand correctly, this should load 0x8000000 into r0. But this simply don’t happen, regardless whether the target is in ARM mode or in Thumb mode. According to the linker-map, this first instruction is located at 0x810000fc. But the instruction on this address (0xe92d4000) don’t look like “mov r0,#0x8000000” to me. In particular, I don’t see the 0x80000000 in the hexdump:

Info:    configuration.c:50 configuration_output_handler(): 0x81000000: e24dd010 e58d000c e58d1008 e3a03c55 e2833055 e58d3004 e3a03daa e283302a
Info:    configuration.c:50 configuration_output_handler(): 0x81000020: e58d3000 e59d300c e59d2004 e0833002 e3e02c55 e2422055 e1a01002 e1c310b0
Info:    configuration.c:50 configuration_output_handler(): 0x81000040: e59d300c e59d2000 e0833002 e3a02c55 e2822055 e1a01002 e1c310b0 e59d300c
Info:    configuration.c:50 configuration_output_handler(): 0x81000060: e59d2004 e0833002 e1dd20b8 e1c320b0 e28dd010 e1a0f00e e92d4000 e24dd008
Info:    configuration.c:50 configuration_output_handler(): 0x81000080: e58d0004 e59d3004 e3e02c0f e242200f e1a01002 e1c310b0 e59d0004 e3a01902
Info:    configuration.c:50 configuration_output_handler(): 0x810000a0: e2811080 ebffffd5 e59d0004 e3a01a01 e2811010 ebffffd1 e3a03001 e59d2004
Info:    configuration.c:50 configuration_output_handler(): 0x810000c0: e2823001 e5d32000 e5cd2003 e20230ff e35300ff 1a000000 ea000000 eafffff5
Info:    configuration.c:50 configuration_output_handler(): 0x810000e0: e1a00000 ea000000 ea000000 eafffffc e28dd008 e8bd8000 e1a0f00e e92d4000
Info:    configuration.c:50 configuration_output_handler(): 0x81000100: e3a00102 ebffffdb ebfffffa e8bd8000 00000000 00000000

Any ideas?

BTW: This is definitely not a hardware problem. I have uclinux running on it without any problems.

Hi

I dont think there is any reset, target_init_handler is called when OpenOCD detects a processor debug halt. The target_init_handler code was written to be called once on the first halt after coming out of reset, and the debug info reflects this assumption. When there is a real reset then there are much more debug messages shown.

The processor mode depends on if we are halting in a Thumb mode bootloader or user supplied code (arm or thumb) or an exception handler (always arm).

There is a core_state command to set either arm or thumb mode, without testing I think it is:

armv4_5 core_state arm

The opcode for mov r0, #-2147483648 is 0xe3a00102, and this can be found at 0x81000100 in your memory dump.

0xe92d4000 is the opcode for stmfd sp!, {lr} which is the function prologue register saving, push LR to the stack.

Regards,

Magnus

mlu:
I dont think there is any reset, target_init_handler is called when OpenOCD detects a processor debug halt.

Yes, you're right. With reset_and_halt and executing the commands manually there is no reset.

BTW: You were right with your assumption further up in the thread. This patch:

Index: openocd/src/target/target.c
===================================================================
--- openocd/src/target/target.c (Revision 122)
+++ openocd/src/target/target.c (Arbeitskopie)
@@ -209,6 +209,8 @@

        if ((event == TARGET_EVENT_HALTED) && (target->reset_script))
        {
+               target_unregister_event_callback(target_init_handler, priv);
+
                script = fopen(target->reset_script, "r");
                if (!script)
                {
@@ -221,8 +223,6 @@
                fclose(script);

                jtag_execute_queue();
-
-               target_unregister_event_callback(target_init_handler, priv);
        }

        return ERROR_OK;

fixes the problem with the endless recursion. Would somebody please apply the patch?

There is a core_state command to set either arm or thumb mode, without testing I think it is:

armv4_5 core_state arm

Ah, OK! This works.

The opcode for mov r0, #-2147483648 is 0xe3a00102, and this can be found at 0x81000100 in your memory dump.

Oh! Guess I need to find out why the linker-map don't match actual code. I've probably mis-interpreted the linker map...

0xe92d4000 is the opcode for stmfd sp!, {lr} which is the function prologue register saving, push LR to the stack.

Ough! I can't see a prologue in the assembler output. I think I should go and check the makefile ;-)

Thanks!

I have submitted the patch to OpenOCD development tree

/Magnus

jw:

mlu:
The opcode for mov r0, #-2147483648 is 0xe3a00102, and this can be found at 0x81000100 in your memory dump.

Oh! Guess I need to find out why the linker-map don't match actual code. I've probably mis-interpreted the linker map...

0xe92d4000 is the opcode for stmfd sp!, {lr} which is the function prologue register saving, push LR to the stack.

Ough! I can't see a prologue in the assembler output. I think I should go and check the makefile ;-)
Ough, stupid me. I've compiled the assebler output with -O2 but the real program without -O2. So the actual instructions didn't match what I expected :roll:

Thanks for the patch (and thanks magnus for submitting it to the patch tracker). I’ve just added it to my local tree.

Regards,

Dominic

Dominic:
Thanks for the patch (and thanks magnus for submitting it to the patch tracker). I’ve just added it to my local tree.

It still don't seem to be available via svn. Does berlios take so long to propagate it?

Sorry, my local tree != berlios SVN. I’ve added it here, but haven’t had a chance to further look at it yet. Catched a cold pretty badly, and I haven’t done a lot at the PC since monday.

Regards,

Dominic

Dominic:
Sorry, my local tree != berlios SVN. I’ve added it here, but haven’t had a chance to further look at it yet.

Oh, I misinterpreted it :slight_smile:

Catched a cold pretty badly, and I haven’t done a lot at the PC since monday.

Get well soon!