While I am impatiently waiting for my teensy-3.1 to arrive, I've decided to give qemu-system-arm and arm-none-eabi-gdb commands a whirl, to try to get familiar with the ARM assembly instruction set. I thought this was going to be a slam-dunk, but it is turning out to be a challenge.
I took the teensy3 Blinky example and used the Arduino IDE to compile it so I could be confident that I had a "working" executable. It was a fun easter-egg hunt locating it's elf and hex files, but I did finally locate them (this is one of a few of those dumbing-down things I really hate about the Arduino setup). Before anyone mentions it, note that the shift-Verify/Compile trick does not work on the Mac version of the IDE.
It was suggested elsewhere that the -cpu cortex-a9 (or a8) would be most suitable for a cortex-m4 choice (up to cortex m3 is supported by qemu). My QEMU command was thus (under Mac OSX):
$ qemu-system-arm -cpu cortex-a9 -nographic -monitor null -serial null -semihosting -kernel ./blink.elf -gdb tcp::51234 -S
In a different session I started gdb:
$ arm-none-eabi-gdb ./blink.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140228-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /Users/ve3wwg/work/teensy3.1/blink.elf...done.
(gdb) target remote localhost:51234
Remote debugging using localhost:51234
0x00000000 in gVectors ()
(gdb) load
Loading section .text, size 0x3190 lma 0x0
Loading section .data, size 0x5b8 lma 0x3190
Start address 0x0, load size 14152
Transfer rate: 4606 KB/sec, 1769 bytes/write.
(gdb) info file
Symbols from "/Users/ve3wwg/work/teensy3.1/blink.elf".
Remote serial target in gdb-specific protocol:
Debugging a target over a serial line.
While running this, GDB does not access memory from...
Local exec file:
`/Users/ve3wwg/work/teensy3.1/blink.elf', file type elf32-littlearm.
Entry point: 0x0
0x00000000 - 0x00003190 is .text
0x1fff8000 - 0x1fff80a0 is .usbdescriptortable
0x1fff80a0 - 0x1fff8400 is .usbbuffers
0x1fff8400 - 0x1fff89b8 is .data
0x1fff89b8 - 0x1fff8d80 is .bss
(gdb)
The one disturbing thing here is that it says the Entry point is 0x0, which is where the vectors start:
(gdb) disas 0,10
Dump of assembler code from 0x0 to 0xa:
=> 0x00000000 <gVectors+0>: andcs r8, r0, r0
0x00000004 <gVectors+4>: ; <UNDEFINED> instruction: 0x000001bd
0x00000008 <gVectors+8>: andeq r0, r0, r9, lsl r6
Hmmm... ok, maybe this has partially answered my own question. There must be a "RESET" vector that the (real) CPU chooses to branch through. That must be what QEMU is not doing correctly (it never gets off the ground). I might be able to finagle this with a gdb call command.
But while I am here, I might as well ask if anyone else has had any experience running teensy-3.x code under QEMU? Any "secret sauce" to get this to work correctly?
Warren
I took the teensy3 Blinky example and used the Arduino IDE to compile it so I could be confident that I had a "working" executable. It was a fun easter-egg hunt locating it's elf and hex files, but I did finally locate them (this is one of a few of those dumbing-down things I really hate about the Arduino setup). Before anyone mentions it, note that the shift-Verify/Compile trick does not work on the Mac version of the IDE.
It was suggested elsewhere that the -cpu cortex-a9 (or a8) would be most suitable for a cortex-m4 choice (up to cortex m3 is supported by qemu). My QEMU command was thus (under Mac OSX):
$ qemu-system-arm -cpu cortex-a9 -nographic -monitor null -serial null -semihosting -kernel ./blink.elf -gdb tcp::51234 -S
In a different session I started gdb:
$ arm-none-eabi-gdb ./blink.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140228-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /Users/ve3wwg/work/teensy3.1/blink.elf...done.
(gdb) target remote localhost:51234
Remote debugging using localhost:51234
0x00000000 in gVectors ()
(gdb) load
Loading section .text, size 0x3190 lma 0x0
Loading section .data, size 0x5b8 lma 0x3190
Start address 0x0, load size 14152
Transfer rate: 4606 KB/sec, 1769 bytes/write.
(gdb) info file
Symbols from "/Users/ve3wwg/work/teensy3.1/blink.elf".
Remote serial target in gdb-specific protocol:
Debugging a target over a serial line.
While running this, GDB does not access memory from...
Local exec file:
`/Users/ve3wwg/work/teensy3.1/blink.elf', file type elf32-littlearm.
Entry point: 0x0
0x00000000 - 0x00003190 is .text
0x1fff8000 - 0x1fff80a0 is .usbdescriptortable
0x1fff80a0 - 0x1fff8400 is .usbbuffers
0x1fff8400 - 0x1fff89b8 is .data
0x1fff89b8 - 0x1fff8d80 is .bss
(gdb)
The one disturbing thing here is that it says the Entry point is 0x0, which is where the vectors start:
(gdb) disas 0,10
Dump of assembler code from 0x0 to 0xa:
=> 0x00000000 <gVectors+0>: andcs r8, r0, r0
0x00000004 <gVectors+4>: ; <UNDEFINED> instruction: 0x000001bd
0x00000008 <gVectors+8>: andeq r0, r0, r9, lsl r6
Hmmm... ok, maybe this has partially answered my own question. There must be a "RESET" vector that the (real) CPU chooses to branch through. That must be what QEMU is not doing correctly (it never gets off the ground). I might be able to finagle this with a gdb call command.
But while I am here, I might as well ask if anyone else has had any experience running teensy-3.x code under QEMU? Any "secret sauce" to get this to work correctly?
Warren