assembly - 如何将参数传递给ARM汇编语言?
问题描述
我有以下 A76 内核的汇编语言程序。如您所见,我加载到 X0 的值是硬编码的。如何传递参数并在此程序的循环中运行代码:
EXPORT tlb_ram_data_register_18_1
tlb_ram_data_register_18 PROC
; B asm_Switch2NonSecure
; B EL1_to_EL3_Switch
LDR X0, =0x000000001800009B
SYS #6, c15, c0, #0, X0
DSB SY
ISB
MRS X0, S3_6_c15_c0_1 ; Move ILData0 register to X1
RET
ENDP
X0 (0x000000001800009B) 的值是寄存器的编码地址,其中包含缓存方式和索引等变量。我必须更改循环中的方式和索引以从 C 代码中读取此寄存器的不同内容,如下所示:
for(way0 = 0x0;way0 <= 0xFF ; way0++)
{
I0_W0 = tlb_ram_data_register_18_1(way0);
}
另一个问题是:如果我像在汇编代码中那样读取 X0 并从函数返回,那么该值会转到 I0_W0 吗?
解决方案
technically it is compiler specific, but for ARM a number of them conform to the same ABI. But you can just ask the compiler and it will give you the correct answer. Write a program test program
extern unsigned int tlb_ram_data_register_18_1 ( unsigned int );
unsigned int fun ( void )
{
unsigned int way0;
for(way0 = 0x0;way0 <= 0xFF ; way0++)
{
tlb_ram_data_register_18_1(way0);
}
return(5);
}
for the moment I am building an aarch64 compiler but for now here is what arm looks like, you will see something similar with any target.
I am using a current version of gcc
00000000 <fun>:
0: e92d4010 push {r4, lr}
4: e3a04000 mov r4, #0
8: e1a00004 mov r0, r4
c: e2844001 add r4, r4, #1
10: ebfffffe bl 0 <tlb_ram_data_register_18_1>
14: e3540c01 cmp r4, #256 ; 0x100
18: 1afffffa bne 8 <fun+0x8>
1c: e3a00005 mov r0, #5
20: e8bd4010 pop {r4, lr}
24: e12fff1e bx lr
not so obvious but r0 is being used as the parameter to the function
also note r0 is used for the return value
unsigned int fun ( unsigned int x )
{
return(x+1);
}
00000000 <fun>:
0: e2800001 add r0, r0, #1
4: e12fff1e bx lr
r0 is both the first/only parameter and is also used for the return.
ahh I do have an aarch64 gcc handy
0000000000000000 <fun>:
0: 11000400 add w0, w0, #0x1
4: d65f03c0 ret
w0 on the way and on the way out. you can try this again with a 64bit parameter and see if that changes.
推荐阅读
- ios - 如何从模态视图重新加载后台 UITableView
- java - Java 异常 getMessage() 返回 null
- sql - IS Insert Select FROM CTP 一个原子事务
- javascript - JavaScript 错误 $.param.querystring 不是函数
- algorithm - 计算大指数份额/概率
- excel - 尽管已安装证书,但已签名的 Excel VBA 插件 (*.xlam) 无法正常运行
- javascript - 在 JSHint 中开启循环复杂度
- python - 裁剪图像的圆形区域 (ROI) 并将其放在白色蒙版上
- python-3.x - 删除重复的图例条形图 matplotlib
- python - 如何在 pyspark SQL 中应用日期格式