From 740f376828687afc57ddbafc66701d8fc56eb874 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sun, 10 Mar 2019 11:24:13 -0400 Subject: [PATCH] Test02 for ARMv7l --- CHANGELOG.org | 2 +- cc_core.c | 23 +++++++++------- makefile | 4 +++ test/common_armv7l/armv7l_defs.M1 | 11 ++++++++ test/common_armv7l/libc-core.M1 | 1 + test/test.answers | 9 ++++--- test/test02/hello-armv7l.sh | 44 +++++++++++++++++++++++++++++++ test/test100/proof.answer | 2 +- 8 files changed, 80 insertions(+), 16 deletions(-) create mode 100755 test/test02/hello-armv7l.sh diff --git a/CHANGELOG.org b/CHANGELOG.org index 3d47344..7c3d3f1 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -16,7 +16,7 @@ * Current ** Added -Added 2/24 working tests for armv7l +Added 3/24 working tests for armv7l ** Changed diff --git a/cc_core.c b/cc_core.c index ad51961..0404b5e 100644 --- a/cc_core.c +++ b/cc_core.c @@ -445,14 +445,14 @@ void common_recursion(FUNCTION f) if(KNIGHT_POSIX == Architecture) emit_out("PUSHR R0 R15\t#_common_recursion\n"); else if(X86 == Architecture) emit_out("PUSH_eax\t#_common_recursion\n"); - else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#common_recursion\n"); + else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_common_recursion\n"); f(); current_target = promote_type(current_target, last_type); if(KNIGHT_POSIX == Architecture) emit_out("POPR R1 R15\t# _common_recursion\n"); else if(X86 == Architecture) emit_out("POP_ebx\t# _common_recursion\n"); - else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#common_recursion\n"); + else if(ARMV7L == Architecture) emit_out("{R1} POP_ALWAYS\t# _common_recursion\n"); } void general_recursion( FUNCTION f, char* s, char* name, FUNCTION iterate) @@ -693,12 +693,12 @@ void relational_expr_stub() } else if(ARMV7L == Architecture) { - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", "<", relational_expr_stub); - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", "<=", relational_expr_stub); - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", ">=", relational_expr_stub); - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", ">", relational_expr_stub); - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", "==", relational_expr_stub); - general_recursion(additive_expr, "PLACEHOLDER\t#relational_expr_stub\n", "!=", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_L\n", "<", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_LE\n", "<=", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_GE\n", ">=", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_G\n", ">", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_EQUAL\n", "==", relational_expr_stub); + general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!1 R0 LOADI8_NE\n", "!=", relational_expr_stub); } } @@ -906,18 +906,21 @@ void process_if() if(KNIGHT_POSIX == Architecture) emit_out("JUMP.Z R0 @ELSE_"); else if(X86 == Architecture) emit_out("TEST\nJUMP_EQ %ELSE_"); - else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n"); + else if(ARMV7L == Architecture) emit_out("!0 CMPI8 R0 IMM_ALWAYS\n^~ELSE_"); uniqueID_out(function->s, number_string); + if(ARMV7L == Architecture) emit_out(" JUMP_EQUAL\n"); require_match("ERROR in process_if\nMISSING )\n", ")"); statement(); if(KNIGHT_POSIX == Architecture) emit_out("JUMP @_END_IF_"); else if(X86 == Architecture) emit_out("JUMP %_END_IF_"); - else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n"); + else if(ARMV7L == Architecture) emit_out("^~_END_IF_"); uniqueID_out(function->s, number_string); + if(ARMV7L == Architecture) emit_out(" JUMP\n"); + emit_out(":ELSE_"); uniqueID_out(function->s, number_string); diff --git a/makefile b/makefile index 3f2cf6f..d9f08bc 100644 --- a/makefile +++ b/makefile @@ -91,6 +91,7 @@ test: test00-knight-posix-binary \ test100-knight-posix-binary \ test00-armv7l-binary \ test01-armv7l-binary \ + test02-armv7l-binary \ test00-x86-binary \ test01-x86-binary \ test02-x86-binary \ @@ -207,6 +208,9 @@ test00-armv7l-binary: M2-Planet | results test01-armv7l-binary: M2-Planet | results test/test01/hello-armv7l.sh +test02-armv7l-binary: M2-Planet | results + test/test02/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 b6f4c0e..bb9517d 100644 --- a/test/common_armv7l/armv7l_defs.M1 +++ b/test/common_armv7l/armv7l_defs.M1 @@ -48,9 +48,16 @@ DEFINE STORE8 0C DEFINE LOAD32 09 DEFINE LOAD8 0D DEFINE LOADI8_ALWAYS 0A0E3 +DEFINE LOADI8_G 0A0C3 +DEFINE LOADI8_GE 0A0A3 +DEFINE LOADI8_EQUAL 0A003 +DEFINE LOADI8_NE 0A013 +DEFINE LOADI8_LE 0A0D3 +DEFINE LOADI8_l 0A0B3 # JUMP/BRANCH DEFINE JUMP EA +DEFINE JUMP_EQUAL 0A DEFINE CALL_ALWAYS EB # Data movement @@ -59,8 +66,12 @@ DEFINE PUSH_ALWAYS 2DE9 DEFINE POP_ALWAYS bde8 # Arithmetic +DEFINE AUX_ALWAYS E1 +DEFINE IMM_ALWAYS E3 DEFINE ARITH_ALWAYS E2 DEFINE ADD 08 +DEFINE CMP 005 +DEFINE CMPI8 005 # SYSCALL DEFINE SYSCALL_ALWAYS 000000EF diff --git a/test/common_armv7l/libc-core.M1 b/test/common_armv7l/libc-core.M1 index f91674c..c9bf34f 100644 --- a/test/common_armv7l/libc-core.M1 +++ b/test/common_armv7l/libc-core.M1 @@ -15,6 +15,7 @@ ## along with M2-Planet. If not, see . :_start +'0' R13 R12 MOVE_ALWAYS ^~FUNCTION_main CALL_ALWAYS !1 R7 LOADI8_ALWAYS SYSCALL_ALWAYS diff --git a/test/test.answers b/test/test.answers index a7b0e87..059a5f5 100644 --- a/test/test.answers +++ b/test/test.answers @@ -1,9 +1,10 @@ -9bb7fc192780009edb1f890eaa2ffb614f9461e7826bfb2beadc0f13ffe4b495 test/results/test00-armv7l-binary +fae8083f3cda34eb0700e5f737fec8ebd37e2e497dbb07877b08761724db81a0 test/results/test00-armv7l-binary 64879eebceb475f21e54cb1f2e872996ca80e8c1fbb8b5895fb5fb6bac0c4384 test/results/test00-knight-posix-binary c52562bd0aabb86ce8ca177f22f8d0455769b444df2d4d62894faab63b7151d8 test/results/test00-x86-binary -56c6b31f809bc8296a8428bc028f223b5345bf650080cfb191277992a986a83d test/results/test01-armv7l-binary +9b088242569dedc540b8abfd5de2d90ae201ac3b97e5c3dcd6d6760358b9f4b2 test/results/test01-armv7l-binary 486ee05ccea796a9cfa9bfb23189b8e014b7ce8d14fea03b27d679d410fe17dd test/results/test01-knight-posix-binary eae96857f2b6d8e8ba86ac06e72345ea572622b358b23978bb5f2db1baadf41c test/results/test01-x86-binary +791244db88cfeffb73989a0643c3b1e75d2a697f3a954f66158521fbeef85f5a test/results/test02-armv7l-binary e6493845b9e94a617649638252f23502f9212de583fd00cba6cc07fffd296e32 test/results/test02-knight-posix-binary 8ead336d2f3f72d5874230492e0472edec61d355905e8636e3dfb2731695037c test/results/test02-x86-binary 96849d5a9294799a9648c24db21b2dab1555dd5ba69d172d77df800622347226 test/results/test03-knight-posix-binary @@ -22,8 +23,8 @@ f1c01feb865c4d552033186d9ce50dd39468a7e8aebf762886c13ad3e03b5011 test/results/t 3b39e72f3de90ed690adfaf6145af46157cef2ec5e72867ac577fa27a0229894 test/results/test09-x86-binary c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary 020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-x86-binary -091ff86dc5dc8669b2010055929da898caa314227e8c57ddd9adad9e96adcf5f test/results/test100-knight-posix-binary -4978d711e023e622cd793ba6029e53c5eba86f59f13e69a052312d4e0c7efa3d test/results/test100-x86-binary +5279b7ef7b094b7713de63b53c7e082faa33dabef5fefa0a13868ac47589a624 test/results/test100-knight-posix-binary +9e891f4502429e0c39ac47a7bc5e7363548848d603f5c796e94247ad8aa2f642 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/test02/hello-armv7l.sh b/test/test02/hello-armv7l.sh new file mode 100755 index 0000000..f8b9341 --- /dev/null +++ b/test/test02/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/test02/if.c \ + -o test/test02/if.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/test02/if.M1 \ + --LittleEndian \ + --architecture armv7l \ + -o test/test02/if.hex2 || exit 2 + +# Resolve all linkages +hex2 -f test/common_armv7l/ELF-armv7l.hex2 -f test/test02/if.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test02-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/test02-armv7l-binary 2>&1 ) + [ 42 = $? ] || exit 4 + [ "$out" = "Hello mes" ] || exit 5 +fi +exit 0 diff --git a/test/test100/proof.answer b/test/test100/proof.answer index 550450a..00ac4e1 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -3497f140e76eb04dcf28fd8f07d1d332c5a36071a62555a5d3f224d6c1b7a6a1 test/test100/proof +acab74ad112f3818db7760c3a752a674c260f42dd603c9a9d972ddff9448e0dc test/test100/proof