aarch64: function, function call, arguments, locals and return

This commit is contained in:
deesix 2020-02-01 21:23:49 +01:00
parent 0737a2acf0
commit 02bac66940
3 changed files with 50 additions and 5 deletions

View File

@ -144,6 +144,13 @@ void function_call(char* s, int bool)
emit_out("{BP} PUSH_ALWAYS\t# Protect the old base pointer\n");
emit_out("'0' SP R11 NO_SHIFT MOVE_ALWAYS\t# Copy new base pointer\n");
}
else if(AARCH64 == Architecture)
{
emit_out("PUSH_X16\t# Protect a tmp register we're going to use\n");
emit_out("PUSH_LR\t# Protect the old return pointer (link)\n");
emit_out("PUSH_BP\t# Protect the old base pointer\n");
emit_out("SET_X16_FROM_SP\t# The base pointer to-be\n");
}
if(global_token->s[0] != ')')
{
@ -153,6 +160,7 @@ void function_call(char* s, int bool)
else if(X86 == Architecture) emit_out("PUSH_eax\t#_process_expression1\n");
else if(AMD64 == Architecture) emit_out("PUSH_RAX\t#_process_expression1\n");
else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_process_expression1\n");
else if(AARCH64 == Architecture) emit_out("PUSH_X0\t#_process_expression1\n");
passed = 1;
while(global_token->s[0] == ',')
@ -164,6 +172,7 @@ void function_call(char* s, int bool)
else if(X86 == Architecture) emit_out("PUSH_eax\t#_process_expression2\n");
else if(AMD64 == Architecture) emit_out("PUSH_RAX\t#_process_expression2\n");
else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_process_expression2\n");
else if(AARCH64 == Architecture) emit_out("PUSH_X0\t#_process_expression2\n");
passed = passed + 1;
}
}
@ -206,6 +215,17 @@ void function_call(char* s, int bool)
emit_out("'3' R0 CALL_REG_ALWAYS\n");
emit_out("{LR} POP_ALWAYS\t# Prevent overwrite\n");
}
else if(AARCH64 == Architecture)
{
emit_out("SET_X0_FROM_BP\n");
emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
emit_out(s);
emit_out("\nSUB_X0_X0_X1\n");
emit_out("DEREF_X0\n");
emit_out("SET_BP_FROM_X16\n");
emit_out("SET_X16_FROM_X0\n");
emit_out("BLR_X16\n");
}
}
else
{
@ -239,6 +259,14 @@ void function_call(char* s, int bool)
emit_out(" CALL_ALWAYS\n");
emit_out("{LR} POP_ALWAYS\t# Restore the old link register\n");
}
else if(AARCH64 == Architecture)
{
emit_out("SET_BP_FROM_X16\n");
emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FUNCTION_");
emit_out(s);
emit_out("\n");
emit_out("BLR_X16\n");
}
}
for(; passed > 0; passed = passed - 1)
@ -247,6 +275,7 @@ void function_call(char* s, int bool)
else if(X86 == Architecture) emit_out("POP_ebx\t# _process_expression_locals\n");
else if(AMD64 == Architecture) emit_out("POP_RBX\t# _process_expression_locals\n");
else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _process_expression_locals\n");
else if(AARCH64 == Architecture) emit_out("POP_X1\t# _process_expression_locals\n");
}
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture))
@ -269,6 +298,12 @@ void function_call(char* s, int bool)
emit_out("{BP} POP_ALWAYS\t# Restore old base pointer\n");
emit_out("{R11} POP_ALWAYS\t# Prevent overwrite\n");
}
else if(AARCH64 == Architecture)
{
emit_out("POP_BP\t# Restore the old base pointer\n");
emit_out("POP_LR\t# Restore the old return pointer (link)\n");
emit_out("POP_X16\t# Restore a register we used as tmp\n");
}
}
void constant_load(struct token_list* a)
@ -1004,6 +1039,7 @@ void collect_local()
else if(X86 == Architecture) a->depth = -20;
else if(AMD64 == Architecture) a->depth = -40;
else if(ARMV7L == Architecture) a->depth = 16;
else if(AARCH64 == Architecture) a->depth = 64; /* argc, argv, envp and the local (16 bytes each) */
}
else if((NULL == function->arguments) && (NULL == function->locals))
{
@ -1011,6 +1047,7 @@ void collect_local()
else if(X86 == Architecture) a->depth = -8;
else if(AMD64 == Architecture) a->depth = -16;
else if(ARMV7L == Architecture) a->depth = 8;
else if(AARCH64 == Architecture) a->depth = 16;
}
else if(NULL == function->locals)
{
@ -1018,6 +1055,7 @@ void collect_local()
else if(X86 == Architecture) a->depth = function->arguments->depth - 8;
else if(AMD64 == Architecture) a->depth = function->arguments->depth - 16;
else if(ARMV7L == Architecture) a->depth = function->arguments->depth + 8;
else if(AARCH64 == Architecture) a->depth = function->arguments->depth + 16;
}
else
{
@ -1025,6 +1063,7 @@ void collect_local()
else if(X86 == Architecture) a->depth = function->locals->depth - register_size;
else if(AMD64 == Architecture) a->depth = function->locals->depth - register_size;
else if(ARMV7L == Architecture) a->depth = function->locals->depth + register_size;
else if(AARCH64 == Architecture) a->depth = function->locals->depth + 16;
}
function->locals = a;
@ -1049,6 +1088,7 @@ void collect_local()
else if(X86 == Architecture) emit_out("PUSH_eax\t#");
else if(AMD64 == Architecture) emit_out("PUSH_RAX\t#");
else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#");
else if(AARCH64 == Architecture) emit_out("PUSH_X0\t#");
emit_out(a->s);
emit_out("\n");
}
@ -1314,12 +1354,14 @@ void return_result()
else if(X86 == Architecture) emit_out("POP_ebx\t# _return_result_locals\n");
else if(AMD64 == Architecture) emit_out("POP_RBX\t# _return_result_locals\n");
else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _return_result_locals\n");
else if(AARCH64 == Architecture) emit_out("POP_X1\t# _return_result_locals\n");
}
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) emit_out("RET R15\n");
else if(X86 == Architecture) emit_out("RETURN\n");
else if(AMD64 == Architecture) emit_out("RETURN\n");
else if(ARMV7L == Architecture) emit_out("'1' LR RETURN\n");
else if(AARCH64 == Architecture) emit_out("RETURN\n");
}
void process_break()
@ -1503,6 +1545,7 @@ void collect_arguments()
else if(X86 == Architecture) a->depth = -4;
else if(AMD64 == Architecture) a->depth = -8;
else if(ARMV7L == Architecture) a->depth = 4;
else if(AARCH64 == Architecture) a->depth = 16;
}
else
{
@ -1510,6 +1553,7 @@ void collect_arguments()
else if(X86 == Architecture) a->depth = function->arguments->depth - register_size;
else if(AMD64 == Architecture) a->depth = function->arguments->depth - register_size;
else if(ARMV7L == Architecture) a->depth = function->arguments->depth + register_size;
else if(AARCH64 == Architecture) a->depth = function->arguments->depth + 16;
}
global_token = global_token->next;
@ -1561,6 +1605,7 @@ void declare_function()
else if((X86 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n");
else if((AMD64 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n");
else if((ARMV7L == Architecture) && !match("'1' LR RETURN\n", output_list->s)) emit_out("'1' LR RETURN\n");
else if((AARCH64 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n");
}
}

View File

@ -53,10 +53,10 @@ a0ae067746e7a2b01d33950da1cf640e12c3a70a045ab331ea2025af59dec9af test/results/t
e01b615db5df31392bd1054c45141dcff936b11dfb1cad270edc0aa67653f5a1 test/results/test10-knight-native-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary
b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary
a1f83eb368fd6afa168693a05fd89743d036beb582bb24ec3d030ef1fd6d9dad test/results/test100-amd64-binary
76c143d17b6a26f7b29df5459dc7915846d3855350499024f84f8109fcabd1f4 test/results/test100-armv7l-binary
1235d2a8da677a67d2f42c0377f152f94b47bebc0aa7a00e393f8a572a034449 test/results/test100-knight-posix-binary
5fc5a9096d7f1a48a10b39111403707c6f19e9d57284efaa707aebe14e63fecf test/results/test100-x86-binary
0ac616a1780c1d8a850c1df79eab83bed3e329a64a753d7d434f141bd3f9eed9 test/results/test100-amd64-binary
5d96e204eec7ec48a8ffa6a908dbfe33c5e7bc6175be94b2e9ca8a0898088c99 test/results/test100-armv7l-binary
806620e23be9e276f458778c22286c6147fcfe68be2a2c98cfd155473887eb85 test/results/test100-knight-posix-binary
b6efd96491deafc39956d21a4d8d246ae9499bf85c2d523b3a9d48f2635391b6 test/results/test100-x86-binary
34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary
893695e6f300a0fe055fad935a56abd549bba70d1d39c535a680f41bbb73f117 test/results/test11-armv7l-binary
7115c4a552eb4b2c1a868ac3dca43be7d040c8e89b7b66851d0522d298429af9 test/results/test11-knight-native-binary

View File

@ -1 +1 @@
9c167fc8acc1d97d7d1c9a9356835e6e6b45383cbe62276bd1e863dc49af5ba5 test/test100/proof
215e0b555c1dde37a4f2c16a03995475be055e97a019c71fc047d5e9fda81bd9 test/test100/proof