簡體   English   中英

如何運行單行程序集,然后查看[R1]和條件標志

[英]How to run a single line of assembly, then see [R1] and condition flags

我正在努力教自己裝配。 我有多年和一年的C,Java和Python經驗 - 但我不能在這里取得任何進展,我即將放棄。

所以,我下載了uVision4,並假設我可以編寫一個基本的匯編程序:

MOV R1,  #0x7F0E0C2D
MOV R3,  #0x1048B3C5
ADCS  R1, R3, ROR #0x18
END

所以,建立兩個變量,做一個操作,完成。 當然,檢查寄存器的輸出和調試器是否有條件標志。

顯然,這是不可能的。

我創建文本文件,編寫我的代碼,保存為.asm文件,然后嘗試構建 -

它討厭這個。

好的,所以我創建了一個新項目,添加.asm文件,

它拒絕,要求我顯然寫了一個完整的設備驅動程序來做一個該死的你好世界。

如何運行簡單的幾行代碼才能開始學習?

我一直在x86桌面上做這樣的事情,使用gdb來執行單步代碼。 通常使用x86指令,但它也適用於ARM交叉開發。 使用gcc -nostdlib foo.S構建,它應該將默認入口點設置為.text部分的開頭。 但是,您確實會從鏈接器收到警告:

$ arm-linux-gnueabi-gcc -nostdlib arm-simple.S 
/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000010098

我不得不修改你的源碼來組裝。 這是我的手臂簡單。:

.globl _start                                                                                                                                                       
_start:                        @ make debugging easier to have a symbol name                                                                                        

ldr   R1,  =#0x7F0E0C2D       @ ARM immediate constants can't be arbitrary 32-bit values.  Use the ldr reg, =value pseudo-op, which in this case assembles to a PC-relative load from a nearby literal pool.  Often it can use mov reg, #imm or movn reg, #imm
ldr   R3,  =#0x1048B3C5
ADCS  R1, R3, ROR #0x18

@END  This isn't an instruction.

然后你可以使用gdb並在第一條指令處設置斷點,運行它,然后單步執行。

您甚至可以在交叉開發環境中執行此操作,只需要一些皺紋。


在一個終端中, 在二進制文件上運行QEMU,等待調試器連接

$ arm-linux-gnueabi-gcc -g -nostdlib arm-simple.S
$ qemu-arm -g 12345 ./a.out                    # user-mode emulation, waiting for gdb to connect

如果你想要特定的話,使用-mcpu=something gcc的-mcpu=something和qemu的-cpu model


在另一個終端中,運行ARM gdb (在我的例子中,來自Ubuntu的gdb-arm-none-eabi包,因為它們Ubuntu不為x86分發arm-linux-gnueabi-gdb跨ARM-gdb包)。

TODO:嘗試gdb-multiarch。 x86桌面上的常規gdb只能調試x86二進制文件,所以你絕對不能使用它。

$ arm-none-eabi-gdb ./a.out          # give the gdb client the same binary to read symbols / debug info
(gdb) target remote localhost:12345
(gdb) layout asm
(gdb) layout reg
(gdb) si               # single step by instruction, not source line
(gdb) si

然后gdb顯示:

+--Register group: general-----------------------------------------------------------------------------------------------------------------------------------------+
|r0             0x0      0                             r1             0x7f0e0c2d       2131627053            r2             0x0      0                             |
|r3             0x1048b3c5       273200069             r4             0x0      0                             r5             0x0      0                             |
|r6             0x0      0                             r7             0x0      0                             r8             0x0      0                             |
|r9             0x0      0                             r10            0x100ac  65708                         r11            0x0      0                             |
|r12            0x0      0                             sp             0xf6ffea40       0xf6ffea40            lr             0x0      0                             |
|pc             0x100a0  0x100a0 <_start+8>            cpsr           0x10     16                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
   ----------------------------------------------------------------------------------------------------------------------------------------------------------------+
   |0x10098 <_start>        ldr    r1, [pc, #4]    ; 0x100a4 <_start+12>                                                                                           |
   |0x1009c <_start+4>      ldr    r3, [pc, #4]    ; 0x100a8 <_start+16>                                                                                           |
  >|0x100a0 <_start+8>      adcs   r1, r1, r3, ror #24                                                                                                             |
   |0x100a4 <_start+12>     svcvc  0x000e0c2d                                                                                                                      |
   |0x100a8 <_start+16>     subne  r11, r8, r5, asr #7                                                                                                             |
   |0x100ac                 andeq  r1, r0, r1, asr #18                                                                                                             |
   |0x100b0                 cmnvs  r5, r0, lsl #2                                                                                                                  |
   |0x100b4                 tsteq  r0, r2, ror #18                                                                                                                 |
   |0x100b8                 andeq  r0, r0, pc                                                                                                                      |
   |0x100bc                 subseq r3, r4, r5, lsl #10                                                                                                             |
   |0x100c0                 tsteq  r8, r6, lsl #6                                                                                                                  |
   |0x100c4                 andeq  r0, r0, r9, lsl #2                                                                                                              |
   |0x100c8                 andeq  r0, r0, r12, lsl r0                                                                                                             |
   |0x100cc                 andeq  r0, r0, r2                                                                                                                      |
   |0x100d0                 andeq  r0, r4, r0                                                                                                                      |
   +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
remote Remote target In: _start                                                                                                              Line: 6    PC: 0x100a0 
(gdb) si

它突出顯示了最后修改的寄存器,這非常棒。

但是,象征性地解碼標志似乎太舊了。 現代的x86 gdb做到了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM