Reputation: 914
I have the following assembly language program for A76 core. As you can see that the value I am loading to X0 is hard coded. How can I pass parameters and run the code in a loop for this program:
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
The value for X0 (0x000000001800009B) is the encoding address of the register which contains variables like cache way and indices. I have to change the way and indices in loop to read different contents of this register from a C code like below:
for(way0 = 0x0;way0 <= 0xFF ; way0++)
{
I0_W0 = tlb_ram_data_register_18_1(way0);
}
One more question is: If I read X0 like I am doing in the assembly code and return from the function, then will that value go to I0_W0?
Upvotes: 1
Views: 4029
Reputation: 71536
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.
Upvotes: 2