Thursday, October 21, 2010

ARM Program Test with QEMU under Windows, Cygwin

* the lines with # charactor is just a mark of comment, do not paste it to your console

#1.  preparation setup environment and developing kits

#1.1 download and install cygwin, a eabi arm toolchains (i.e. G++ Lite) and qemu
#    setup PATH env to make all the executable available from command line

#    cygwin from
#    note: cygwin is not necessary, but it comes with 'make' which will be userful

#    G++ Lite from
#    alternative choices would be winarm and gnuarm

#    qemu
#    note: I tried 0.9.0~0.12.5, only 0.9.1 worked.
#    I dont't know why versions after 0.10 cannot output any single line to stdout.
#    And 0.9.0 comes with only two ARM chip emulator and without the support of cortex-m3.

#1.2 virtual serial port emulator from
#    or choose another from
#    create a virtual connector i.e COM9 and startup it

#2.  write arm asm program and compile, link

user@machine /cygdrive/c/home/user/embed/lm3s811evb
vi add.s
        .syntax unified

sp:     .word 0x200
reset:  .word start+1

        mov r0, #4
        mov r1, #5
        add r2, r1, r0

stop:   b stop

user@machine /cygdrive/c/home/user/embed/lm3s811evb
$ arm-none-eabi-as -mcpu=cortex-m3 add.s -o add.o

user@machine /cygdrive/c/home/user/embed/lm3s811evb
$ arm-none-eabi-ld -Ttext=0x0 -o add.elf add.o

user@machine /cygdrive/c/home/user/embed/lm3s811evb
$ arm-none-eabi-objcopy -O binary add.elf add.bin

#3.  startup qemu and test with qemu monitor commands
#3.1 startup qemu without graphic and map monitor to COM9
#    note: the virtual com port setup is required after you startup qemu, just click OK
#    it's important to emulate a virtual port, and the COM9 need to be uppercase
#    otherwise you will get error such as
#    "Unable to open driver: stdio"
#    "qemu: could not open serial device 'mon:stdio'"   
#    or
#    "qemu: could not open monitor device 'com9'"

user@machine /cygdrive/c/home/user/embed/lm3s811evb
$ qemu-system-arm -M lm3s811evb -kernel add.bin -nographic -serial null -monitor COM9

#3.2 with super terminal or other terminal utilities
#    i.e. TeraTerm


#    show the registers

(qemu) info registers
R00=00000004 R01=00000005 R02=00000009 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=00000000 R13=00000200 R14=00000000 R15=00000014
PSR=40000173 -Z-- T svc32
s00=00000000(       0) s01=00000000(       0) d00=0000000000000000(       0)
s02=00000000(       0) s03=00000000(       0) d01=0000000000000000(       0)
s04=00000000(       0) s05=00000000(       0) d02=0000000000000000(       0)
s06=00000000(       0) s07=00000000(       0) d03=0000000000000000(       0)
s08=00000000(       0) s09=00000000(       0) d04=0000000000000000(       0)
s10=00000000(       0) s11=00000000(       0) d05=0000000000000000(       0)
s12=00000000(       0) s13=00000000(       0) d06=0000000000000000(       0)
s14=00000000(       0) s15=00000000(       0) d07=0000000000000000(       0)
s16=00000000(       0) s17=00000000(       0) d08=0000000000000000(       0)
s18=00000000(       0) s19=00000000(       0) d09=0000000000000000(       0)
s20=00000000(       0) s21=00000000(       0) d10=0000000000000000(       0)
s22=00000000(       0) s23=00000000(       0) d11=0000000000000000(       0)
s24=00000000(       0) s25=00000000(       0) d12=0000000000000000(       0)
s26=00000000(       0) s27=00000000(       0) d13=0000000000000000(       0)
s28=00000000(       0) s29=00000000(       0) d14=0000000000000000(       0)
s30=00000000(       0) s31=00000000(       0) d15=0000000000000000(       0)
FPSCR: 00000000

#    decompile the program

(qemu) xp /10i 0x9
0x00000009:  mov.w      r0, #4  ; 0x4
0x0000000d:  mov.w      r1, #5  ; 0x5
0x00000011:  add.w      r2, r1, r0
0x00000015:  b.n        0x14
0x00000017:  lsls       r0, r0, #0
0x00000019:  lsls       r0, r0, #0
0x0000001b:  lsls       r0, r0, #0
0x0000001d:  lsls       r0, r0, #0
0x0000001f:  lsls       r0, r0, #0
0x00000021:  lsls       r0, r0, #0

No comments:

Post a Comment