thanks, I am using gdb to debug it.
the OS is compiled with -Ttext = 0, system will jump to 0x10000 as usual.I set a breakpoint at 0x10000 in the OS, which corresponds the symbol named f1 at s1.c (sorry to replace the actual names with them, because the OS is private), if -Ttext is set to 0x10000, the corresponding symbol will be f2 at s2.c(the first instruction of the OS resides in the f2), which is the right and normal situation.
the OS will be copied to the address at 0x10000 while booting, it means the first instruction of the OS(f2) is placed at 0x10000(maybe I am wrong at this point), then set PC to 0x10000 by such method(correct me if I misunderstand this):
- define a symbol by "-defsym f3=0x10000" in linking bootloader;
- declare f3 by "extern f3();"
- unzip OS and copy it to f3;
- call f3 by "f3();"
however CPU executes the instruction in f1(placed at 0x10000 + some offsets) other than f2(placed at 0x10000), here is the gdb outputting:
(arm-gdb) b *10000
Breakpoint 1 at 0x10000: file s1.c, line 386.
(arm-gdb) c
Continuing.
Breakpoint 1, 0x00010000 in _f1__Fv () at s1.c:386
386 printf("\n");
(arm-gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x00010000 in _f1__Fv
at s1.c:386
breakpoint already hit 1 time
(arm-gdb) info registers
r0 0xa 0xa
r1 0xbe78 0xbe78
r2 0xc8000000 0xc8000000
r3 0x0 0x0
r4 0x50020000 0x50020000
r5 0x10000 0x10000
r6 0x1c01270 0x1c01270
r7 0xbf64 0xbf64
r8 0xc8004000 0xc8004000
r9 0x9 0x9
r10 0x6 0x6
r11 0xbf44 0xbf44
r12 0x0 0x0
sp 0xbf58 0xbf58
lr 0x2c50 0x2c50
pc 0x10000 0x10000
cpsr 0x600000d3 0x600000d3
spsr 0xd3 0xd3
idcode 0x19277013 0x19277013
(arm-gdb) step
_f4__FP9arp_cache (v1=0x1c01270) at s1.c:808
808 if ( ! v1 ) {
(arm-gdb) info registers
r0 0xa 0xa
r1 0xbe78 0xbe78
r2 0xc8000000 0xc8000000
r3 0x0 0x0
r4 0x50020000 0x50020000
r5 0x10000 0x10000
r6 0x1c01270 0x1c01270
r7 0xbf64 0xbf64
r8 0xc8004000 0xc8004000
r9 0x9 0x9
r10 0x6 0x6
r11 0xbf44 0xbf44
r12 0xbf58 0xbf58
sp 0xbf48 0xbf48
lr 0x2c50 0x2c50
pc 0x10008 0x10008
cpsr 0x600000d3 0x600000d3
spsr 0xd3 0xd3
idcode 0x19277013 0x19277013
(arm-gdb)
my questions:
- since f2 is placed at 0x10000, why does not the CPU execute it?
- how does the CPU know the address of f1 is 0x10000, then go to execute it?