Open domenpk opened 7 years ago
qemu-arm can also be used: qemu-arm -cpu any program.axf and in debug mode with qemu-arm -cpu any -g 1234 program.axf where 1234 is the local port where the gdb stub is listening.
Then arm-none-eabi-gdb and type in target remote localhost:1234
Changing the RAM from ORIGIN = 0x10000000
to ORIGIN = 0x20000000
fixed things for me :)
And also -D__START=main
Thanks !!!
My big problem now is that "return 0" in main()
is not exiting qemu. How to solve that ???
$ qemu-system-arm -machine lm3s6965evb -kernel hello-CM0.axf -monitor none -serial stdio -semihosting -nographic qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)
R00=00000000 R01=00000000 R02=00000000 R03=00000000 R04=00000000 R05=00000000 R06=00000000 R07=00000000 R08=00000000 R09=00000000 R10=00000000 R11=00000000 R12=00000000 R13=46c0b5d8 R14=fffffff9 R15=00000000 XPSR=40000003 -Z-- A handler FPSCR: 00000000 Aborted (core dumped)
not sure what i did wrong..
$ qemu-system-arm -machine lm3s6965evb -kernel hello-CM0.axf -monitor none -serial stdio -semihosting -nographic qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)
R00=00000000 R01=00000000 R02=00000000 R03=00000000 R04=00000000 R05=00000000 R06=00000000 R07=00000000 R08=00000000 R09=00000000 R10=00000000 R11=00000000 R12=00000000 R13=46c0b5d8 R14=fffffff9 R15=00000000 XPSR=40000003 -Z-- A handler FPSCR: 00000000 Aborted (core dumped)
not sure what i did wrong..
I've seen this and on an M0 I think you'll probably find it's an alignment issue. I had problems with the Application Exited SVC call constant (0x20026) not being properly aligned and got this. Whether that's your problem here I'm not sure.
Also, I've been using the -device loader,file=foo.elf to load the image which takes not of the start address in the ELF file which may make life easier.
Hi,
I did the same changes on qemu-4.2.0 its enters the machine I created but is not executing the hello world!
IN: Reset_Handler 0x0000050c: f7ff fff0 bl #0x4f0
IN: SystemInit 0x000004f0: 4770 bx lr
IN: Reset_Handler 0x00000510: 4c19 ldr r4, [pc, #0x64] 0x00000512: 4d1a ldr r5, [pc, #0x68] 0x00000514: 42ac cmp r4, r5 0x00000516: da0a bge #0x52e
IN: Reset_Handler 0x00000518: 6821 ldr r1, [r4] 0x0000051a: 6862 ldr r2, [r4, #4] 0x0000051c: 68a3 ldr r3, [r4, #8] 0x0000051e: 009b lsls r3, r3, #2 0x00000520: 3b04 subs r3, #4 0x00000522: bfa2 ittt ge 0x00000524: 58c8 ldrge r0, [r1, r3] 0x00000526: 50d0 strge r0, [r2, r3] 0x00000528: e7fa bge #0x520
IN: Reset_Handler 0x00000520: 3b04 subs r3, #4 0x00000522: bfa2 ittt ge 0x00000524: 58c8 ldrge r0, [r1, r3] 0x00000526: 50d0 strge r0, [r2, r3] 0x00000528: e7fa bge #0x520
IN: Reset_Handler 0x0000052a: 340c adds r4, #0xc 0x0000052c: e7f2 b #0x514
IN: Reset_Handler 0x00000514: 42ac cmp r4, r5 0x00000516: da0a bge #0x52e
IN: Reset_Handler 0x0000052e: 4914 ldr r1, [pc, #0x50] 0x00000530: 4a14 ldr r2, [pc, #0x50] 0x00000532: 4b15 ldr r3, [pc, #0x54] 0x00000534: 429a cmp r2, r3 0x00000536: bfbe ittt lt 0x00000538: f851 0b04 ldrlt r0, [r1], #4 0x0000053c: f842 0b04 strlt r0, [r2], #4 0x00000540: e7f8 blt #0x534
IN: Reset_Handler 0x00000534: 429a cmp r2, r3 0x00000536: bfbe ittt lt 0x00000538: f851 0b04 ldrlt r0, [r1], #4 0x0000053c: f842 0b04 strlt r0, [r2], #4 0x00000540: e7f8 blt #0x534
IN: Reset_Handler 0x00000542: 4b12 ldr r3, [pc, #0x48] 0x00000544: 4c12 ldr r4, [pc, #0x48] 0x00000546: 42a3 cmp r3, r4 0x00000548: da09 bge #0x55e
IN: Reset_Handler 0x0000055e: 490d ldr r1, [pc, #0x34] 0x00000560: 4a0d ldr r2, [pc, #0x34] 0x00000562: 2000 movs r0, #0 0x00000564: 4291 cmp r1, r2 0x00000566: bfbc itt lt 0x00000568: f841 0b04 strlt r0, [r1], #4 0x0000056c: e7fa blt #0x564
IN: Reset_Handler 0x00000564: 4291 cmp r1, r2 0x00000566: bfbc itt lt 0x00000568: f841 0b04 strlt r0, [r1], #4 0x0000056c: e7fa blt #0x564
IN: Reset_Handler 0x0000056e: f7ff ff4b bl #0x408
IN: _mainCRTStartup 0x00000408: 2016 movs r0, #0x16 0x0000040a: a131 adr r1, #0xc4 0x0000040c: beab bkpt #0xab
IN: _mainCRTStartup 0x0000040e: 4830 ldr r0, [pc, #0xc0] 0x00000410: 6841 ldr r1, [r0, #4] 0x00000412: 2900 cmp r1, #0 0x00000414: d001 beq #0x41a
IN: _mainCRTStartup 0x00000416: 4a35 ldr r2, [pc, #0xd4] 0x00000418: 6011 str r1, [r2] 0x0000041a: 6801 ldr r1, [r0] 0x0000041c: 2900 cmp r1, #0 0x0000041e: d101 bne #0x424
IN: _mainCRTStartup 0x00000424: 6881 ldr r1, [r0, #8] 0x00000426: 68c2 ldr r2, [r0, #0xc] 0x00000428: 2900 cmp r1, #0 0x0000042a: d000 beq #0x42e
IN: _mainCRTStartup 0x0000042c: 468d mov sp, r1 0x0000042e: 2a00 cmp r2, #0 0x00000430: d001 beq #0x436
IN: _mainCRTStartup 0x00000436: 2100 movs r1, #0 0x00000438: 468b mov fp, r1 0x0000043a: 460f mov r7, r1 0x0000043c: 4825 ldr r0, [pc, #0x94] 0x0000043e: 4a26 ldr r2, [pc, #0x98] 0x00000440: 1a12 subs r2, r2, r0 0x00000442: f001 f87c bl #0x153e
IN: memset 0x0000153e: 4603 mov r3, r0 0x00001540: 4402 add r2, r0 0x00001542: 4293 cmp r3, r2 0x00001544: d100 bne #0x1548
IN: memset 0x00001548: f803 1b01 strb r1, [r3], #1 0x0000154c: e7f9 b #0x1542
IN: memset 0x00001542: 4293 cmp r3, r2 0x00001544: d100 bne #0x1548
IN: memset 0x00001546: 4770 bx lr
IN: _mainCRTStartup 0x00000446: f001 f9bb bl #0x17c0
IN: initialise_monitor_handles 0x000017c0: e92d 47ff push.w {r0, r1, r2, r3, r4, r5, r6, r7, r8, sb, sl, lr} 0x000017c4: f04f 0803 mov.w r8, #3 0x000017c8: 2300 movs r3, #0 0x000017ca: f8df 9094 ldr.w sb, [pc, #0x94] 0x000017ce: 2401 movs r4, #1 0x000017d0: f8cd 9004 str.w sb, [sp, #4] 0x000017d4: af01 add r7, sp, #4 0x000017d6: f8cd 800c str.w r8, [sp, #0xc] 0x000017da: 9302 str r3, [sp, #8] 0x000017dc: 4620 mov r0, r4 0x000017de: 4639 mov r1, r7 0x000017e0: beab bkpt #0xab
IN: HardFault_Handler 0x00000572: e7fe b #0x572
Trace 0: 0x7f27e05d1480 [00000000/00000572/0x312000c1] HardFault_Handler R00=2000018c R01=00000000 R02=20000264 R03=20000264 R04=000023f4 R05=000023f4 R06=00000000 R07=00000000 R08=00000000 R09=00000000 R10=00000000 R11=00000000 R12=00000000 R13=07ffffe0 R14=fffffff9 R15=00000572 XPSR=61000003 -ZC- T handler Linking TBs 0x7f27e05d1480 [00000572] index 0 -> 0x7f27e05d1480 [00000572] Trace 0: 0x7f27e05d1480 [00000000/00000572/0x312000c1] HardFault_Handler R00=2000018c R01=00000000 R02=20000264 R03=20000264 R04=000023f4 R05=000023f4 R06=00000000 R07=00000000 R08=00000000 R09=00000000 R10=00000000 R11=00000000 R12=00000000 R13=07ffffe0 R14=fffffff9 R15=00000572 XPSR=61000003 -ZC- T handler
I am trying this on arm cortex-m3. Memory is same as yours and in addition heap and stack is 0 and 0xc00 respectively. Can any suggest me what else changes to be made.
Did anyone try qemu/semihosting on qemu-4.2.0?
I spend a bit of time struggling with this, and I was surprised I couldn't find a nice resource online, so these are minimum changes I needed to run it.
First realise that qemu needs a "machine" and that defines memory layout (
-M none
, or-machine none
will not work, although you really need an "empty" machine for this test). I see three compatible witharm-cortex-m3
(also m0, since m3 is binary compatible with it) in qemu 2.8:netduino2
,lm3s6965evb
andlm3s811evb
.Changes needed
copy a linker script, .e.g. keep.ld, and change the memory layout (fix RAM address), so it becomes:
Makefile changes:
-LFLAGS=$(USE_NANO) $(USE_SEMIHOST) $(GC) $(MAP) +LFLAGS=$(USE_NANO) $(USE_SEMIHOST) $(GC) $(MAP) -T nokeep.ld
-$(NAME)-$(CORE).axf: $(NAME).c +$(NAME)-$(CORE).axf: $(NAME).c $(STARTUP) $(CC) $^ $(CFLAGS) $(LFLAGS) -o $@
clean:
$ qemu-system-arm -machine lm3s6965evb -kernel hello-CM0.axf -monitor none -serial stdio -semihosting -nographic Hello, world!
$ qemu-system-arm -M netduino2 -cpu cortex-m0 -kernel hello-CM0.axf -monitor none -serial stdio -semihosting -nographic Hello, world!
$ qemu-system-arm -M netduino2 -cpu cortex-m3 -kernel ../qemu/hello-CM3.axf -monitor none -serial stdio -semihosting -nographic Hello, world!