简体   繁体   English

当我尝试在 Armv8 程序集中分配数组时执行冻结

[英]Execution freezes when I try to allocate Array in Armv8 assembly

So I am programming in assemply, this is just a simple code so I can learn how to allocate arrays in order to use them on NEON programming later.所以我正在汇编编程,这只是一个简单的代码,所以我可以学习如何分配数组,以便以后在 NEON 编程中使用它们。

ASM_FUNC(FPE)
.data
.balign 8

array: .skip 80 
array1: .word 10,20,30,40

.text

ldr x0,=array
mov x1,#10

check: 
      cmp x1,#1
      bne loop
      b exit

loop:
      str x1,[x0],#8 //Stores the value in x1 into x0 and moves the address +8 bytes
      sub x1,x1,#1   //x1--
      b check


exit:
      mov x0,#11
          ret

So, some parts are commented so I could try to find where the code is breaking (I don't have debug on my system).因此,对某些部分进行了注释,以便我可以尝试找到代码中断的位置(我的系统上没有调试)。
I started commenting the calculation part and added a mov x0,#11 in the end right before the ret to see if the problem was on the calculation.我开始评论计算部分,并在 ret 之前的末尾添加了一个 mov x0,#11 以查看问题是否出在计算上。 Turns out it was not.事实证明不是。 When I uncommented the array: .skip 80 and ldr x0,=array my application would just stick there if no response.当我取消注释数组时: .skip 80 和 ldr x0,=array 如果没有响应,我的应用程序将一直停留在那里。

Can anyone please tell me what I am doing wrong?谁能告诉我我做错了什么? I am using A64 on armv8 assembly我在 armv8 程序集上使用 A64

The entry point is called from this c program:从这个 c 程序调用入口点:

void  PocAsm_EntryPoint ( )
    {
    
    
          Print(L"========== ASM ==========\n");
       
        
          UINT32 fff = FPE();
          Print(L" %d \n",fff);
        
          Print(L"=========== ASM ===========\n");
        
          Print(L"Test version 0.24 \n");
      return 0;
    }

Unfortunately I didn't find the definition of the Print, so I apologize不幸的是我没有找到 Print 的定义,所以我很抱歉

This is an attempt to answer to the following question: does the FPE() function work as expected, while removing everything else from the equation, using standard tools such as qemu-system-aarch64 and GDB .这是试图回答以下问题: FPE()函数是否按预期工作,同时使用qemu-system-aarch64GDB等标准工具从等式中删除其他所有内容。

The code for the FPE() function will be compiled for a Cortex-A53 qemu-virt machine. FPE()函数的代码将为 Cortex-A53 qemu-virt 机器编译。

Prerequisites:先决条件:

  • qemu-system-aarch64 is installed:安装了 qemu-system-aarch64:

Ubuntu 20.04 : sudo apt-get install qemu-system-arm Ubuntu 20.04sudo apt-get install qemu-system-arm
Windows 10 : download and install the qemu-w64-setup-20201120.exe installer from here . Windows 10 :从这里下载并安装qemu-w64-setup-20201120.exe安装程序。

  • the aarch64-none-elf toolchain for Cortex-A is installed.安装了Cortex-Aaarch64-none-elf工具链。 It can be downloaded from the ARM WEB site .它可以从ARM 网站下载。 There are versions for both Linux and Windows 10.有适用于 Linux 和 Windows 10 的版本。

FPE.s : FPE.s :

        .arch armv8-a
        .file   "FPE.s"

        .data
        .balign 8
        .globl array
array:  .skip 80 
array1: .word 10,20,30,40

        .text
        .align  2
        .globl FPE
FPE:
        ldr x0,=array
        mov x1,#10

check: 
        cmp x1,#1
        bne loop
        b exit

loop:
        str x1,[x0],#8  //Stores the value in x1 into x0 and moves the address +8 bits
        sub x1,x1,#1    //x1--
        b check

exit:
        mov x0,#11
        ret
        .end

startup.s : startup.s

                .title startup64.s
                .arch armv8-a
                .text
                .section .text.startup,"ax"    
                .globl _start
_start:
                ldr x0, =__StackTop
                mov sp, x0
                bl FPE
wait:           wfe
                b wait
               .end

Building:建筑:

We will build FPE.elf for the qemu-virt machine (RAM starts at 0x40000000 ):我们将为 qemu-virt 机器构建FPE.elf (RAM 从0x40000000开始):

/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gcc -nostdlib -nostartfiles -ffreestanding -g -Wl,--defsym,__StackTop=0x40010000 -Wl,--section-start=.text=0x40000000 -o FPE.elf startup.s FPE.s

Debugging:调试:

Start qemu in a shell:在 shell 中启动 qemu:

/opt/qemu-5.1.0/bin/qemu-system-aarch64  -semihosting -m 1M -nographic -serial telnet::4444,server,nowait -machine virt,gic-version=2,secure=on,virtualization=on -S -gdb tcp::1234,ipv4 -cpu cortex-a53 -kernel FPE.elf

Start GDB :启动GDB

opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb  --quiet -nx -ex 'target remote localhost:1234' -ex 'load' --ex 'b _start' -ex 'b exit' FPE.elf

GDB should start: GDB应该启动:

Reading symbols from FPE.elf...
Remote debugging using localhost:1234
_start () at startup.s:7
7                       ldr x0, =__StackTop
Loading section .text, size 0x50 lma 0x40000000
Loading section .data, size 0x60 lma 0x40010050
Start address 0x40000000, load size 176
Transfer rate: 85 KB/sec, 88 bytes/write.
Breakpoint 1 at 0x40000000: file startup.s, line 7.
Breakpoint 2 at 0x40000040: file FPE.s, line 28.

From this point, the commands stepi , p/x $x0 , and x/10g 0x40010050 could be used for monitoring the program behavior until it will reach the exit label.从这一点开始,命令stepip/x $x0x/10g 0x40010050可用于监视程序行为,直到它到达exit标签。

We will just here display the 10 elements in the array at the start and exit breakpoints:我们将在此处在开始和退出断点处显示数组中的 10 个元素:

gdb) x/10g 0x40010050
0x40010050:     0       0
0x40010060:     0       0
0x40010070:     0       0
0x40010080:     0       0
0x40010090:     0       0
(gdb) continue
Continuing.

Breakpoint 2, exit () at FPE.s:28
28              mov x0,#11
(gdb) x/10g 0x40010050
0x40010050:     10      9
0x40010060:     8       7
0x40010070:     6       5
0x40010080:     4       3
0x40010090:     2       0

Single-stepping from this point shows that the program returns properly from its execution:从这一点开始的单步执行表明程序从执行中正确返回:

(gdb) stepi
29              ret
(gdb) stepi
wait () at startup.s:10
10      wait:           wfe
(gdb) stepi
11                      b wait
(gdb) stepi
10      wait:           wfe

The answer to the question would therefore be: Yes, the code for the FPE() function is working properly.因此,问题的答案是:是的, FPE()函数的代码运行正常。

The exact same procedure can be run on Windows 10, this is just a matter of adjusting the three commands that were used for running aarch64-none-elf-gcc , qemu-system-aarch64 and GDB .完全相同的过程可以在 Windows 10 上运行,这只是调整用于运行aarch64-none-elf-gccqemu-system-aarch64GDB的三个命令的问题。


Comparing a dump of your object file with the one I tested may help understanding the issue:将目标文件的转储与我测试的转储进行比较可能有助于理解问题:

/opt.arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/aarch64-none-elf-as -o FPE.o FPE.s
/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/aarch64-none-elf-objdump -D FPE.o 

FPE.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <FPE>:
   0:   58000140        ldr     x0, 28 <exit+0x8>
   4:   d2800141        mov     x1, #0xa                        // #10

0000000000000008 <check>:
   8:   f100043f        cmp     x1, #0x1
   c:   54000041        b.ne    14 <loop>  // b.any
  10:   14000004        b       20 <exit>

0000000000000014 <loop>:
  14:   f8008401        str     x1, [x0], #8
  18:   d1000421        sub     x1, x1, #0x1
  1c:   17fffffb        b       8 <check>

0000000000000020 <exit>:
  20:   d2800160        mov     x0, #0xb                        // #11
  24:   d65f03c0        ret
        ...

Disassembly of section .data:

0000000000000000 <array>:
        ...

0000000000000050 <array1>:
  50:   0000000a        .inst   0x0000000a ; undefined
  54:   00000014        .inst   0x00000014 ; undefined
  58:   0000001e        .inst   0x0000001e ; undefined
  5c:   00000028        .inst   0x00000028 ; undefined

Dumping the complete ELF file of the minimal example would give:转储最小示例的完整 ELF 文件将给出:

opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/aarch64-none-elf-objdump -D FPE.elf

FPE.elf:     file format elf64-littleaarch64


Disassembly of section .text:

0000000040000000 <_start>:
    40000000:   580000c0        ldr     x0, 40000018 <wait+0xc>
    40000004:   9100001f        mov     sp, x0
    40000008:   94000006        bl      40000020 <FPE>

000000004000000c <wait>:
    4000000c:   d503205f        wfe
    40000010:   17ffffff        b       4000000c <wait>
    40000014:   00000000        .inst   0x00000000 ; undefined
    40000018:   40010000        .inst   0x40010000 ; undefined
    4000001c:   00000000        .inst   0x00000000 ; undefined

0000000040000020 <FPE>:
    40000020:   58000140        ldr     x0, 40000048 <exit+0x8>
    40000024:   d2800141        mov     x1, #0xa                        // #10

0000000040000028 <check>:
    40000028:   f100043f        cmp     x1, #0x1
    4000002c:   54000041        b.ne    40000034 <loop>  // b.any
    40000030:   14000004        b       40000040 <exit>

0000000040000034 <loop>:
    40000034:   f8008401        str     x1, [x0], #8
    40000038:   d1000421        sub     x1, x1, #0x1
    4000003c:   17fffffb        b       40000028 <check>

0000000040000040 <exit>:
    40000040:   d2800160        mov     x0, #0xb                        // #11
    40000044:   d65f03c0        ret
    40000048:   40010050        .inst   0x40010050 ; undefined
    4000004c:   00000000        .inst   0x00000000 ; undefined

Disassembly of section .data:

0000000040010050 <__data_start>:
        ...

00000000400100a0 <array1>:
    400100a0:   0000000a        .inst   0x0000000a ; undefined
    400100a4:   00000014        .inst   0x00000014 ; undefined
    400100a8:   0000001e        .inst   0x0000001e ; undefined
    400100ac:   00000028        .inst   0x00000028 ; undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM