diff --git a/CHANGELOG.org b/CHANGELOG.org index 97410f7..3d47344 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -16,7 +16,7 @@ * Current ** Added -Added 1/24 working tests for armv7l +Added 2/24 working tests for armv7l ** Changed diff --git a/cc_core.c b/cc_core.c index ff811b6..ad51961 100644 --- a/cc_core.c +++ b/cc_core.c @@ -128,8 +128,8 @@ void function_call(char* s, int bool) } else if(ARMV7L == Architecture) { - emit_out("'0' R14 PUSH_ALWAYS\t# Protect the old link register\n"); - emit_out("'0' R12 PUSH_ALWAYS\t# Protect the old base pointer\n"); + emit_out("{R14} PUSH_ALWAYS\t# Protect the old link register\n"); + emit_out("{R12} PUSH_ALWAYS\t# Protect the old base pointer\n"); } if(global_token->s[0] != ')') @@ -137,7 +137,7 @@ void function_call(char* s, int bool) expression(); if(KNIGHT_POSIX == Architecture) emit_out("PUSHR R0 R15\t#_process_expression1\n"); else if(X86 == Architecture) emit_out("PUSH_eax\t#_process_expression1\n"); - else if(ARMV7L == Architecture) emit_out("REG R0 PUSH_ALWAYS\t#_process_expression1\n"); + else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_process_expression1\n"); passed = 1; while(global_token->s[0] == ',') @@ -146,7 +146,7 @@ void function_call(char* s, int bool) expression(); if(KNIGHT_POSIX == Architecture) emit_out("PUSHR R0 R15\t#_process_expression2\n"); else if(X86 == Architecture) emit_out("PUSH_eax\t#_process_expression2\n"); - else if(ARMV7L == Architecture) emit_out("REG R0 PUSH_ALWAYS\t#_process_expression2\n"); + else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_process_expression2\n"); passed = passed + 1; } } @@ -175,7 +175,7 @@ void function_call(char* s, int bool) emit_out("!"); emit_out(s); emit_out("\nR0 LOAD32 R12\n"); - emit_out("'0' R12 R13 MOVE_ALWAYS\n"); + emit_out("'0' R13 R12 MOVE_ALWAYS\n"); } } else @@ -196,7 +196,7 @@ void function_call(char* s, int bool) } else if(ARMV7L == Architecture) { - emit_out("'0' R12 R13 MOVE_ALWAYS\n"); + emit_out("'0' R13 R12 MOVE_ALWAYS\n"); emit_out("^~FUNCTION_"); emit_out(s); emit_out(" CALL_ALWAYS\n"); @@ -207,7 +207,7 @@ void function_call(char* s, int bool) { if(KNIGHT_POSIX == Architecture) emit_out("POPR R1 R15\t# _process_expression_locals\n"); else if(X86 == Architecture) emit_out("POP_ebx\t# _process_expression_locals\n"); - else if(ARMV7L == Architecture) emit_out("'0' R1 POP_ALWAYS\t# _process_expression_locals\n"); + else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _process_expression_locals\n"); } if(KNIGHT_POSIX == Architecture) @@ -222,8 +222,8 @@ void function_call(char* s, int bool) } else if(ARMV7L == Architecture) { - emit_out("'0' R12 POP_ALWAYS\t# Restore old base pointer\n"); - emit_out("'0' R14 POP_ALWAYS\t# Prevent overwrite\n"); + emit_out("{R12} POP_ALWAYS\t# Restore old base pointer\n"); + emit_out("{R14} POP_ALWAYS\t# Prevent overwrite\n"); } } @@ -884,7 +884,7 @@ void collect_local() if(KNIGHT_POSIX == Architecture) emit_out("PUSHR R0 R15\t#"); else if(X86 == Architecture) emit_out("PUSH_eax\t#"); - else if(ARMV7L == Architecture) emit_out("'0' R0 PUSH_ALWAYS\t#"); + else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#"); emit_out(a->s); emit_out("\n"); } @@ -1115,7 +1115,7 @@ void return_result() { if(KNIGHT_POSIX == Architecture) emit_out("POPR R1 R15\t# _return_result_locals\n"); else if(X86 == Architecture) emit_out("POP_ebx\t# _return_result_locals\n"); - else if(ARMV7L == Architecture) emit_out("'0' R1 POP_ALWAYS\t# _return_result_locals\n"); + else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _return_result_locals\n"); } if(KNIGHT_POSIX == Architecture) emit_out("RET R15\n"); @@ -1137,7 +1137,7 @@ void process_break() if(NULL == i) break; if(KNIGHT_POSIX == Architecture) emit_out("POPR R1 R15\t# break_cleanup_locals\n"); else if(X86 == Architecture) emit_out("POP_ebx\t# break_cleanup_locals\n"); - else if(ARMV7L == Architecture) emit_out("'0' R1 POP_ALWAYS\t# break_cleanup_locals\n"); + else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# break_cleanup_locals\n"); i = i->next; } global_token = global_token->next; @@ -1176,7 +1176,7 @@ void recursive_statement() { if(KNIGHT_POSIX == Architecture) emit_out("POPR R1 R15\t# _recursive_statement_locals\n"); else if(X86 == Architecture) emit_out( "POP_ebx\t# _recursive_statement_locals\n"); - else if(ARMV7L == Architecture) emit_out("'0' R1 POP_ALWAYS\t# _recursive_statement_locals\n"); + else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _recursive_statement_locals\n"); } } function->locals = frame; diff --git a/makefile b/makefile index 046f809..3f2cf6f 100644 --- a/makefile +++ b/makefile @@ -90,6 +90,7 @@ test: test00-knight-posix-binary \ test99-knight-posix-binary \ test100-knight-posix-binary \ test00-armv7l-binary \ + test01-armv7l-binary \ test00-x86-binary \ test01-x86-binary \ test02-x86-binary \ @@ -203,6 +204,9 @@ test100-knight-posix-binary: M2-Planet | results test00-armv7l-binary: M2-Planet | results test/test00/hello-armv7l.sh +test01-armv7l-binary: M2-Planet | results + test/test01/hello-armv7l.sh + test00-x86-binary: M2-Planet | results test/test00/hello-x86.sh diff --git a/test/common_armv7l/armv7l_defs.M1 b/test/common_armv7l/armv7l_defs.M1 index 30d2622..b6f4c0e 100644 --- a/test/common_armv7l/armv7l_defs.M1 +++ b/test/common_armv7l/armv7l_defs.M1 @@ -14,7 +14,7 @@ ## You should have received a copy of the GNU General Public License ## along with stage0. If not, see . -#Registers +# Registers DEFINE R0 0 DEFINE R1 1 DEFINE R2 2 @@ -35,6 +35,12 @@ DEFINE LR E DEFINE R15 F DEFINE PC F +# Register masks for push/pop16 +DEFINE {R0} 0100 +DEFINE {R1} 0200 +DEFINE {R12} 0010 +DEFINE {R14} 0040 + # LOAD/STORE DEFINE MEMORY E5 DEFINE STORE32 08 @@ -45,10 +51,16 @@ DEFINE LOADI8_ALWAYS 0A0E3 # JUMP/BRANCH DEFINE JUMP EA -DEFINE BL_ALWAYS EB +DEFINE CALL_ALWAYS EB # Data movement DEFINE MOVE_ALWAYS 0A0E1 +DEFINE PUSH_ALWAYS 2DE9 +DEFINE POP_ALWAYS bde8 + +# Arithmetic +DEFINE ARITH_ALWAYS E2 +DEFINE ADD 08 # SYSCALL DEFINE SYSCALL_ALWAYS 000000EF diff --git a/test/common_armv7l/functions/exit.c b/test/common_armv7l/functions/exit.c new file mode 100644 index 0000000..0fdf384 --- /dev/null +++ b/test/common_armv7l/functions/exit.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2016 Jeremiah Orians + * This file is part of M2-Planet. + * + * M2-Planet is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * M2-Planet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with M2-Planet. If not, see . + */ + +// CONSTANT EXIT_FAILURE 1 +// CONSTANT EXIT_SUCCESS 0 + +void exit(int value) +{ + asm("!0 R0 LOAD32 R13 MEMORY" + "!1 R7 LOADI8_ALWAYS" + "SYSCALL_ALWAYS"); +} diff --git a/test/common_armv7l/functions/putchar.c b/test/common_armv7l/functions/putchar.c new file mode 100644 index 0000000..4fd4371 --- /dev/null +++ b/test/common_armv7l/functions/putchar.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2016 Jeremiah Orians + * This file is part of M2-Planet. + * + * M2-Planet is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * M2-Planet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with M2-Planet. If not, see . + */ + +void putchar(int c) +{ + asm("!1 R0 LOADI8_ALWAYS" + "!1 R2 LOADI8_ALWAYS" + "!4 R7 LOADI8_ALWAYS" + "!0 R1 ADD R12 ARITH_ALWAYS" + "SYSCALL_ALWAYS"); +} diff --git a/test/common_armv7l/libc-core.M1 b/test/common_armv7l/libc-core.M1 index b223d7c..f91674c 100644 --- a/test/common_armv7l/libc-core.M1 +++ b/test/common_armv7l/libc-core.M1 @@ -15,6 +15,6 @@ ## along with M2-Planet. If not, see . :_start -^~FUNCTION_main BL_ALWAYS +^~FUNCTION_main CALL_ALWAYS !1 R7 LOADI8_ALWAYS SYSCALL_ALWAYS diff --git a/test/test.answers b/test/test.answers index 94b6a17..a7b0e87 100644 --- a/test/test.answers +++ b/test/test.answers @@ -1,6 +1,7 @@ 9bb7fc192780009edb1f890eaa2ffb614f9461e7826bfb2beadc0f13ffe4b495 test/results/test00-armv7l-binary 64879eebceb475f21e54cb1f2e872996ca80e8c1fbb8b5895fb5fb6bac0c4384 test/results/test00-knight-posix-binary c52562bd0aabb86ce8ca177f22f8d0455769b444df2d4d62894faab63b7151d8 test/results/test00-x86-binary +56c6b31f809bc8296a8428bc028f223b5345bf650080cfb191277992a986a83d test/results/test01-armv7l-binary 486ee05ccea796a9cfa9bfb23189b8e014b7ce8d14fea03b27d679d410fe17dd test/results/test01-knight-posix-binary eae96857f2b6d8e8ba86ac06e72345ea572622b358b23978bb5f2db1baadf41c test/results/test01-x86-binary e6493845b9e94a617649638252f23502f9212de583fd00cba6cc07fffd296e32 test/results/test02-knight-posix-binary @@ -21,8 +22,8 @@ f1c01feb865c4d552033186d9ce50dd39468a7e8aebf762886c13ad3e03b5011 test/results/t 3b39e72f3de90ed690adfaf6145af46157cef2ec5e72867ac577fa27a0229894 test/results/test09-x86-binary c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary 020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-x86-binary -99b751c78142ff919f0b12c28313e612ff4e3b48e9e3ca5aa7add4ca5efa35d2 test/results/test100-knight-posix-binary -f244c5339b3a8f53484a1dc27ef582afa00b6df923b8c42ad843c3812d86441a test/results/test100-x86-binary +091ff86dc5dc8669b2010055929da898caa314227e8c57ddd9adad9e96adcf5f test/results/test100-knight-posix-binary +4978d711e023e622cd793ba6029e53c5eba86f59f13e69a052312d4e0c7efa3d test/results/test100-x86-binary 63fd5fbf389d1b19031026df193ec55e98d923b8568007125b80bc246c094496 test/results/test11-knight-posix-binary 3fd11bad4a426ce1ff8fd9c6d7d2b943effae9f3f5740b7376e426e9b0555851 test/results/test11-x86-binary 313536f9209d29d4c3b40f6ada898f81c1fb3b650ca1a84754f90b1db3b9e001 test/results/test12-knight-posix-binary diff --git a/test/test01/hello-armv7l.sh b/test/test01/hello-armv7l.sh new file mode 100755 index 0000000..6a9fa7a --- /dev/null +++ b/test/test01/hello-armv7l.sh @@ -0,0 +1,44 @@ +#! /bin/sh +## Copyright (C) 2017 Jeremiah Orians +## This file is part of M2-Planet. +## +## M2-Planet is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## M2-Planet is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with M2-Planet. If not, see . + +set -x +# Build the test +bin/M2-Planet --architecture armv7l -f test/common_armv7l/functions/putchar.c \ + -f test/common_armv7l/functions/exit.c \ + -f test/test01/library_call.c \ + -o test/test01/library_call.M1 || exit 1 + +# Macro assemble with libc written in M1-Macro +M1 -f test/common_armv7l/armv7l_defs.M1 \ + -f test/common_armv7l/libc-core.M1 \ + -f test/test01/library_call.M1 \ + --LittleEndian \ + --architecture armv7l \ + -o test/test01/library_call.hex2 || exit 2 + +# Resolve all linkages +hex2 -f test/common_armv7l/ELF-armv7l.hex2 -f test/test01/library_call.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test01-armv7l-binary --exec_enable || exit 3 + +# Ensure binary works if host machine supports test +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "armv7l" ] +then + # Verify that the compiled program returns the correct result + out=$(./test/results/test01-armv7l-binary 2>&1) + [ 42 = $? ] || exit 3 + [ "$out" = "Hello mes" ] || exit 4 +fi +exit 0 diff --git a/test/test100/proof.answer b/test/test100/proof.answer index e7dec69..550450a 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -2ebd53349f203e0dd41ad294c3cd725693b3abd4500ac30e793ad02ddea57eaf test/test100/proof +3497f140e76eb04dcf28fd8f07d1d332c5a36071a62555a5d3f224d6c1b7a6a1 test/test100/proof