5/24 working tests for ARMv7l

This commit is contained in:
Jeremiah Orians 2019-03-16 20:03:56 -04:00
parent f357464727
commit eb034f51e8
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
13 changed files with 474 additions and 62 deletions

View File

@ -16,7 +16,7 @@
* Current
** Added
Added 4/24 working tests for armv7l
Added 5/24 working tests for armv7l
** Changed

116
cc_core.c
View File

@ -128,8 +128,9 @@ void function_call(char* s, int bool)
}
else if(ARMV7L == Architecture)
{
emit_out("{R14} PUSH_ALWAYS\t# Protect the old link register\n");
emit_out("{R12} PUSH_ALWAYS\t# Protect the old base pointer\n");
emit_out("{R11} PUSH_ALWAYS\t# Prevent overwriting in recursion\n");
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");
}
if(global_token->s[0] != ')')
@ -174,8 +175,11 @@ void function_call(char* s, int bool)
{
emit_out("!");
emit_out(s);
emit_out("\nR0 LOAD32 R12\n");
emit_out("'0' R13 R12 MOVE_ALWAYS\n");
emit_out("\nR0 LOAD32 BP MEMORY\n");
emit_out("'0' R11 BP NO_SHIFT MOVE_ALWAYS\n");
emit_out("{LR} PUSH_ALWAYS\t# Protect the old link register\n");
emit_out("PLACEHOLDER\t# Calling function in R0");
emit_out("{LR} POP_ALWAYS\t# Prevent overwrite\n");
}
}
else
@ -196,10 +200,12 @@ void function_call(char* s, int bool)
}
else if(ARMV7L == Architecture)
{
emit_out("'0' R13 R12 MOVE_ALWAYS\n");
emit_out("{LR} PUSH_ALWAYS\t# Protect the old link register\n");
emit_out("'0' R11 BP NO_SHIFT MOVE_ALWAYS\n");
emit_out("^~FUNCTION_");
emit_out(s);
emit_out(" CALL_ALWAYS\n");
emit_out("{LR} POP_ALWAYS\t# Restore the old link register\n");
}
}
@ -222,8 +228,8 @@ void function_call(char* s, int bool)
}
else if(ARMV7L == Architecture)
{
emit_out("{R12} POP_ALWAYS\t# Restore old base pointer\n");
emit_out("{R14} POP_ALWAYS\t# Prevent overwrite\n");
emit_out("{BP} POP_ALWAYS\t# Restore old base pointer\n");
emit_out("{R11} POP_ALWAYS\t# Prevent overwrite\n");
}
}
@ -231,7 +237,7 @@ void constant_load(struct token_list* a)
{
if(KNIGHT_POSIX == Architecture) emit_out("LOADI R0 ");
else if(X86 == Architecture) emit_out("LOAD_IMMEDIATE_eax %");
else if(ARMV7L == Architecture) emit_out("!0 R0 LOAD32 R15 MEMORY\n~0 JUMP\n%");
else if(ARMV7L == Architecture) emit_out("!0 R0 LOAD32 R15 MEMORY\n~0 JUMP_ALWAYS\n%");
emit_out(a->arguments->s);
emit_out("\n");
}
@ -250,7 +256,7 @@ void variable_load(struct token_list* a)
else if(ARMV7L == Architecture) emit_out("!");
emit_out(numerate_number(a->depth));
if(ARMV7L == Architecture) emit_out(" R0 ADD R12 ARITH_ALWAYS");
if(ARMV7L == Architecture) emit_out(" R0 SUB BP ARITH_ALWAYS");
emit_out("\n");
if(TRUE == Address_of) return;
@ -317,7 +323,7 @@ void primary_expr_string()
current_count = current_count + 1;
if(KNIGHT_POSIX == Architecture) emit_out("LOADR R0 4\nJUMP 4\n&STRING_");
else if(X86 == Architecture) emit_out("LOAD_IMMEDIATE_eax &STRING_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#primary_expr_string\n");
else if(ARMV7L == Architecture) emit_out("!0 R0 LOAD32 R15 MEMORY\n~0 JUMP_ALWAYS\n&STRING_");
uniqueID_out(function->s, number_string);
/* The target */
@ -365,7 +371,7 @@ void primary_expr_number()
}
else if(ARMV7L == Architecture)
{
emit_out("!0 R0 LOAD32 R15 MEMORY\n~0 JUMP\n%");
emit_out("!0 R0 LOAD32 R15 MEMORY\n~0 JUMP_ALWAYS\n%");
emit_out(global_token->s);
emit_out("\n");
}
@ -481,6 +487,7 @@ int ceil_log2(int a)
a = a >> 1;
}
if(ARMV7L == Architecture) return (result >> 1);
return result;
}
@ -535,28 +542,29 @@ void postfix_expr_array()
char* assign;
if(KNIGHT_POSIX == Architecture) assign = "LOAD R0 R0 0\n";
else if(X86 == Architecture) assign = "LOAD_INTEGER\n";
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#postfix_expr_array\n");
else if(ARMV7L == Architecture) assign = "!0 R0 LOAD32 R0 MEMORY\n";
/* Add support for Ints */
if(match("char*", current_target->name))
{
if(KNIGHT_POSIX == Architecture) assign = "LOAD8 R0 R0 0\n";
else if(X86 == Architecture) assign = "LOAD_BYTE\n";
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#postfix_expr_array\n");
else if(ARMV7L == Architecture) assign = "!0 R0 LOAD8 R0 MEMORY\n";
}
else
{
if(KNIGHT_POSIX == Architecture) emit_out("SALI R0 ");
else if(X86 == Architecture) emit_out("SAL_eax_Immediate8 !");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#postfix_expr_array\n");
else if(ARMV7L == Architecture) emit_out("'0' R0 R0 '");
emit_out(numerate_number(ceil_log2(current_target->indirect->size)));
if(ARMV7L == Architecture) emit_out("' MOVE_ALWAYS");
emit_out("\n");
}
if(KNIGHT_POSIX == Architecture) emit_out("ADD R0 R0 R1\n");
else if(X86 == Architecture) emit_out("ADD_ebx_to_eax\n");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#postfix_expr_array\n");
else if(ARMV7L == Architecture) emit_out("'0' R0 R0 ADD R1 ARITH2_ALWAYS\n");
require_match("ERROR in postfix_expr\nMissing ]\n", "]");
@ -646,13 +654,13 @@ void additive_expr_stub()
}
else if(ARMV7L == Architecture)
{
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "+", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "-", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "*", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "/", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "%", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", "<<", additive_expr_stub);
general_recursion(postfix_expr, "PLACEHOLDER\t#additive_expr_stub\n", ">>", additive_expr_stub);
general_recursion(postfix_expr, "'0' R0 R0 ADD R1 ARITH2_ALWAYS\n", "+", additive_expr_stub);
general_recursion(postfix_expr, "'0' R0 R0 SUB R1 ARITH2_ALWAYS\n", "-", additive_expr_stub);
general_recursion(postfix_expr, "'9' R0 '0' R1 MUL R0 ARITH2_ALWAYS\n", "*", additive_expr_stub);
general_recursion(postfix_expr, "{LR} PUSH_ALWAYS\n^~divide CALL_ALWAYS\n{LR} POP_ALWAYS\n", "/", additive_expr_stub);
general_recursion(postfix_expr, "{LR} PUSH_ALWAYS\n^~modulus CALL_ALWAYS\n{LR} POP_ALWAYS\n", "%", additive_expr_stub);
general_recursion(postfix_expr, "LEFT R0 R0 R1 SHIFT AUX_ALWAYS\n", "<<", additive_expr_stub);
general_recursion(postfix_expr, "RIGHT R0 R0 R1 SHIFT AUX_ALWAYS\n", ">>", additive_expr_stub);
}
}
@ -695,12 +703,12 @@ void relational_expr_stub()
}
else if(ARMV7L == Architecture)
{
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);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_L\n", "<", relational_expr_stub);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_LE\n", "<=", relational_expr_stub);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_GE\n", ">=", relational_expr_stub);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_G\n", ">", relational_expr_stub);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_EQUAL\n", "==", relational_expr_stub);
general_recursion(additive_expr, "'0' R0 CMP R1 AUX_ALWAYS\n!0 R0 LOADI8_ALWAYS\n!1 R0 LOADI8_NE\n", "!=", relational_expr_stub);
}
}
@ -739,11 +747,11 @@ void bitwise_expr_stub()
}
else if(ARMV7L == Architecture)
{
general_recursion(relational_expr, "PLACEHOLDER\t#bitwise_expr_stub\n", "&", bitwise_expr_stub);
general_recursion(relational_expr, "PLACEHOLDER\t#bitwise_expr_stub\n", "&&", bitwise_expr_stub);
general_recursion(relational_expr, "PLACEHOLDER\t#bitwise_expr_stub\n", "|", bitwise_expr_stub);
general_recursion(relational_expr, "PLACEHOLDER\t#bitwise_expr_stub\n", "||", bitwise_expr_stub);
general_recursion(relational_expr, "PLACEHOLDER\t#bitwise_expr_stub\n", "^", bitwise_expr_stub);
general_recursion(relational_expr, "NO_SHIFT R0 R0 AND R1 ARITH2_ALWAYS\n", "&", bitwise_expr_stub);
general_recursion(relational_expr, "NO_SHIFT R0 R0 AND R1 ARITH2_ALWAYS\n", "&&", bitwise_expr_stub);
general_recursion(relational_expr, "NO_SHIFT R0 R0 OR R1 AUX_ALWAYS\n", "|", bitwise_expr_stub);
general_recursion(relational_expr, "NO_SHIFT R0 R0 OR R1 AUX_ALWAYS\n", "||", bitwise_expr_stub);
general_recursion(relational_expr, "'0' R0 R0 XOR R1 ARITH2_ALWAYS\n", "^", bitwise_expr_stub);
}
}
@ -826,13 +834,13 @@ void expression()
{
if(KNIGHT_POSIX == Architecture) store = "STORE R0 R1 0\n";
else if(X86 == Architecture) store = "STORE_INTEGER\n";
else if(ARMV7L == Architecture) emit_out("!0 R0 STORE32 R1 MEMORY\n");
else if(ARMV7L == Architecture) store = "!0 R0 STORE32 R1 MEMORY\n";
}
else
{
if(KNIGHT_POSIX == Architecture) store = "STORE8 R0 R1 0\n";
else if(X86 == Architecture) store = "STORE_CHAR\n";
else if(ARMV7L == Architecture) emit_out("!0 R0 STORE8 R1 MEMORY\n");
else if(ARMV7L == Architecture) store = "!0 R0 STORE8 R1 MEMORY\n";
}
common_recursion(expression);
@ -851,21 +859,25 @@ void collect_local()
{
if(KNIGHT_POSIX == Architecture) a->depth = 20;
else if(X86 == Architecture) a->depth = -20;
else if(ARMV7L == Architecture) a->depth = 4;
}
else if((NULL == function->arguments) && (NULL == function->locals))
{
if(KNIGHT_POSIX == Architecture) a->depth = 4;
else if(X86 == Architecture) a->depth = -8;
else if(ARMV7L == Architecture) a->depth = 4;
}
else if(NULL == function->locals)
{
if(KNIGHT_POSIX == Architecture) a->depth = function->arguments->depth + 8;
else if(X86 == Architecture) a->depth = function->arguments->depth - 8;
else if(ARMV7L == Architecture) a->depth = function->arguments->depth + 4;
}
else
{
if(KNIGHT_POSIX == Architecture) a->depth = function->locals->depth + 4;
else if(X86 == Architecture) a->depth = function->locals->depth - 4;
else if(ARMV7L == Architecture) a->depth = function->locals->depth + 4;
}
function->locals = a;
@ -921,7 +933,7 @@ void process_if()
else if(ARMV7L == Architecture) emit_out("^~_END_IF_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP\n");
if(ARMV7L == Architecture) emit_out(" JUMP_ALWAYS\n");
emit_out(":ELSE_");
uniqueID_out(function->s, number_string);
@ -969,12 +981,16 @@ void process_for()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP.Z R0 @FOR_END_");
else if(X86 == Architecture) emit_out("TEST\nJUMP_EQ %FOR_END_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n");
else if(ARMV7L == Architecture) emit_out("!0 CMPI8 R0 IMM_ALWAYS\n^~FOR_END_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_EQUAL\n");
if(KNIGHT_POSIX == Architecture) emit_out("JUMP @FOR_THEN_");
else if(X86 == Architecture) emit_out("JUMP %FOR_THEN_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n");
else if(ARMV7L == Architecture) emit_out("^~FOR_THEN_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_ALWAYS\n");
emit_out(":FOR_ITER_");
uniqueID_out(function->s, number_string);
@ -983,8 +999,10 @@ void process_for()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP @FOR_");
else if(X86 == Architecture) emit_out("JUMP %FOR_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n");
else if(ARMV7L == Architecture) emit_out("^~FOR_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_ALWAYS\n");
emit_out(":FOR_THEN_");
uniqueID_out(function->s, number_string);
@ -993,8 +1011,10 @@ void process_for()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP @FOR_ITER_");
else if(X86 == Architecture) emit_out("JUMP %FOR_ITER_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n");
else if(ARMV7L == Architecture) emit_out("^~FOR_ITER_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_ALWAYS\n");
emit_out(":FOR_END_");
uniqueID_out(function->s, number_string);
@ -1049,8 +1069,10 @@ void process_do()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP.NZ R0 @DO_");
else if(X86 == Architecture) emit_out("TEST\nJUMP_NE %DO_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_if\n");
else if(ARMV7L == Architecture) emit_out("!0 CMPI8 R0 IMM_ALWAYS\n^~DO_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_EQUAL\t");
emit_out(":DO_END_");
uniqueID_out(function->s, number_string);
@ -1086,8 +1108,9 @@ void process_while()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP.Z R0 @END_WHILE_");
else if(X86 == Architecture) emit_out("TEST\nJUMP_EQ %END_WHILE_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_while\n");
else if(ARMV7L == Architecture) emit_out("!0 CMPI8 R0 IMM_ALWAYS\n^~END_WHILE_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_EQUAL\t");
emit_out("# THEN_while_");
uniqueID_out(function->s, number_string);
@ -1096,8 +1119,9 @@ void process_while()
if(KNIGHT_POSIX == Architecture) emit_out("JUMP @WHILE_");
else if(X86 == Architecture) emit_out("JUMP %WHILE_");
else if(ARMV7L == Architecture) emit_out("PLACEHOLDER\t#process_while\n");
else if(ARMV7L == Architecture) emit_out("^~WHILE_");
uniqueID_out(function->s, number_string);
if(ARMV7L == Architecture) emit_out(" JUMP_ALWAYS\n");
emit_out(":END_WHILE_");
uniqueID_out(function->s, number_string);
@ -1125,7 +1149,7 @@ void return_result()
if(KNIGHT_POSIX == Architecture) emit_out("RET R15\n");
else if(X86 == Architecture) emit_out("RETURN\n");
else if(ARMV7L == Architecture) emit_out("'0' R14 R15 MOVE_ALWAYS\n");
else if(ARMV7L == Architecture) emit_out("'0' LR PC NO_SHIFT MOVE_ALWAYS\n");
}
void process_break()
@ -1296,11 +1320,13 @@ void collect_arguments()
{
if(KNIGHT_POSIX == Architecture) a->depth = 0;
else if(X86 == Architecture) a->depth = -4;
else if(ARMV7L == Architecture) a->depth = 4;
}
else
{
if(KNIGHT_POSIX == Architecture) a->depth = function->arguments->depth + 4;
else if(X86 == Architecture) a->depth = function->arguments->depth - 4;
else if(ARMV7L == Architecture) a->depth = function->arguments->depth + 4;
}
global_token = global_token->next;
@ -1337,7 +1363,7 @@ void declare_function()
/* Prevent duplicate RETURNS */
if((KNIGHT_POSIX == Architecture) && !match("RET R15\n", out->s)) emit_out("RET R15\n");
else if((X86 == Architecture) && !match("RETURN\n", out->s)) emit_out("RETURN\n");
else if((ARMV7L == Architecture) && !match("'0' R14 R15 MOVE_ALWAYS\n", out->s)) emit_out("'0' R14 R15 MOVE_ALWAYS\n");
else if((ARMV7L == Architecture) && !match("'0' LR PC NO_SHIFT MOVE_ALWAYS\n", out->s)) emit_out("'0' LR PC NO_SHIFT MOVE_ALWAYS\n");
}
}

View File

@ -94,6 +94,8 @@ test: test00-knight-posix-binary \
test02-armv7l-binary \
test03-armv7l-binary \
test04-armv7l-binary \
test05-armv7l-binary \
test06-armv7l-binary \
test00-x86-binary \
test01-x86-binary \
test02-x86-binary \
@ -219,6 +221,12 @@ test03-armv7l-binary: M2-Planet | results
test04-armv7l-binary: M2-Planet | results
test/test04/hello-armv7l.sh
test05-armv7l-binary: M2-Planet | results
test/test05/hello-armv7l.sh
test06-armv7l-binary: M2-Planet | results
test/test06/hello-armv7l.sh
test00-x86-binary: M2-Planet | results
test/test00/hello-x86.sh

View File

@ -0,0 +1,220 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### This file is part of stage0.
###
### stage0 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.
###
### stage0 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 stage0. If not, see <http://www.gnu.org/licenses/>.
### stage0's hex2 format
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### elf32.hex2: 32 bit elf header in hex2
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
00 # e_ident[EI_OSABI] Set at 0 because none cares
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
28 00 # e_machine Indicating 32bit ARM
01 00 00 00 # e_version Indicating original elf
&ELF_text # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
%ELF_section_headers>ELF_base # e_shoff Address of section header table
00 02 00 05 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
02 00 # e_phnum number of entries in program table
28 00 # e_shentsize size of a section header table
07 00 # e_shnum number of entries in section table
04 00 # e_shstrndx index of the section names
# @34
00 00 00 00
00 00 00 00
00 00 00 00
# @40
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
05 00 00 00 # p_flags
00 00 01 00 # alignment
# @60
:ELF_program_header__data
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
%ELF_end>ELF_base # ph_filesz
%ELF_end>ELF_base # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_align
# @80
:ELF_comment
4d 45 53 00 # MES
00 00 00 00 # align
00 00 00 00
00 00 00 00
4d 45 53 00 # MES
00 00 00 00 # align
00 00 00 00
00 00 00 00
# @a0
:ELF_shstr
00
:ELF_shstr__text
2e 74 65 78 74 00 # .text
:ELF_shstr__data
2e 64 61 74 61 00 # .data
:ELF_shstr__comment
2e 63 6f 6d 6d 65 6e 74 00 # .comment
:ELF_shstr__shstr
2e 73 68 73 74 72 74 61 62 00 # .shstrtab
:ELF_shstr__sym
2e 73 79 6d 74 61 62 00 # .symtab
:ELF_shstr__str
2e 73 74 72 74 61 62 00 # .strtab
# @d0
:ELF_section_headers
00 00 00 00 # sh_name
00 00 00 00 # sh_type
00 00 00 00 # sh_flags
00 00 00 00 # sh_addr
00 00 00 00 # sh_offset
00 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
## FIXME: M0 for calculations?
:ELF_section_header_text
%ELF_shstr__text>ELF_shstr # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
06 00 00 00 # sh_flags = SHF-ALLOC|SHF-EXEC =2 | 4 = 6
&ELF_text # sh_addr
%ELF_text>ELF_base # sh_offset
%ELF_data>ELF_text # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_data
%ELF_shstr__data>ELF_shstr # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
03 00 00 00 # sh_flags = SHF-WRITE|SHF-ALLOC = 1 | 2 = 3
&ELF_data # sh_addr
%ELF_data>ELF_base # sh_offset
%ELF_sym>ELF_data # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_comment
%ELF_shstr__comment>ELF_shstr # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
00 00 00 00 # sh_flags
&ELF_comment # sh_addr
%ELF_comment>ELF_base # sh_offset
%ELF_shstr>ELF_comment # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_shstr
%ELF_shstr__shstr>ELF_shstr # sh_name
03 00 00 00 # sh_type: str-sht-strtab
00 00 00 00 # sh_flags
&ELF_shstr # sh_addr
%ELF_shstr>ELF_base # sh_offset
%ELF_section_headers>ELF_shstr # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_sym
%ELF_shstr__sym>ELF_shstr # sh_name
02 00 00 00 # sh_type: str-sht-symtab
00 00 00 00 # sh_flags
&ELF_sym # sh_addr
%ELF_sym>ELF_base # sh_offset
%ELF_end>ELF_sym # sh_length
06 00 00 00 # sh_link:6
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
10 00 00 00 # sh_entsize
:ELF_section_header_str
%ELF_shstr__str>ELF_shstr # sh_name
03 00 00 00 # sh_type: str-sht-strtab
00 00 00 00 # sh_flags
&ELF_str # sh_addr
%ELF_str>ELF_base # sh_offset
%ELF_sym>ELF_str # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
# @1e8
00 00 00 00 # align
00 00 00 00
# @1f0
00 00 00 00 # align
00 00 00 00
00 00 00 00
00 00 00 00
# @200
:ELF_text

View File

@ -28,6 +28,7 @@ DEFINE R9 9
DEFINE R10 A
DEFINE R11 B
DEFINE R12 C
DEFINE BP C
DEFINE R13 D
DEFINE SP D
DEFINE R14 E
@ -38,8 +39,15 @@ DEFINE PC F
# Register masks for push/pop16
DEFINE {R0} 0100
DEFINE {R1} 0200
DEFINE {R12} 0010
DEFINE {R14} 0040
DEFINE {R11} 0008
DEFINE {BP} 0010
DEFINE {LR} 0040
# Bitshift constants
DEFINE NO_SHIFT 0
DEFINE LEFT 1
DEFINE RIGHT 2
DEFINE ARITH_RIGHT 5
# LOAD/STORE
DEFINE MEMORY E5
@ -56,12 +64,12 @@ DEFINE LOADI8_LE 0A0D3
DEFINE LOADI8_L 0A0B3
# JUMP/BRANCH
DEFINE JUMP EA
DEFINE JUMP_ALWAYS EA
DEFINE JUMP_EQUAL 0A
DEFINE CALL_ALWAYS EB
# Data movement
DEFINE MOVE_ALWAYS 0A0E1
DEFINE MOVE_ALWAYS A0E1
DEFINE MVN_ALWAYS 0E0E1
DEFINE PUSH_ALWAYS 2DE9
DEFINE POP_ALWAYS bde8
@ -72,10 +80,14 @@ DEFINE IMM_ALWAYS E3
DEFINE ARITH_ALWAYS E2
DEFINE ARITH2_ALWAYS E0
DEFINE ADD 08
DEFINE XOR 02
DEFINE AND 00
DEFINE CMP 005
DEFINE CMPI8 005
DEFINE MUL 0
DEFINE OR 08
DEFINE SHIFT A0
DEFINE SUB 04
DEFINE XOR 02
# SYSCALL
DEFINE SYSCALL_ALWAYS 000000EF

View File

@ -20,7 +20,8 @@
void exit(int value)
{
asm("!0 R0 LOAD32 R13 MEMORY"
asm("!4 R0 SUB R12 ARITH_ALWAYS"
"!0 R0 LOAD32 R0 MEMORY"
"!1 R7 LOADI8_ALWAYS"
"SYSCALL_ALWAYS");
}

View File

@ -20,6 +20,6 @@ void putchar(int c)
asm("!1 R0 LOADI8_ALWAYS"
"!1 R2 LOADI8_ALWAYS"
"!4 R7 LOADI8_ALWAYS"
"!0 R1 ADD R12 ARITH_ALWAYS"
"!4 R1 SUB R12 ARITH_ALWAYS"
"SYSCALL_ALWAYS");
}

View File

@ -15,7 +15,15 @@
## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
:_start
'0' R13 R12 MOVE_ALWAYS
'0' R13 R12 NO_SHIFT MOVE_ALWAYS
^~FUNCTION_main CALL_ALWAYS
!1 R7 LOADI8_ALWAYS
SYSCALL_ALWAYS
# Stub that simply returns
:divide
'0' R14 R15 NO_SHIFT MOVE_ALWAYS
# Stub that simply returns
:modulus
'0' R14 R15 NO_SHIFT MOVE_ALWAYS

View File

@ -1,20 +1,22 @@
95f2ceced02ccdf5704e96d44fd36d07d769cabb2d1bca926145929d0a3cb8ed test/results/test00-armv7l-binary
8433f2c58f8e04a61a4403b9a5d5245513d8d52b9eb0d42c6b5ed66829394aa6 test/results/test00-armv7l-binary
64879eebceb475f21e54cb1f2e872996ca80e8c1fbb8b5895fb5fb6bac0c4384 test/results/test00-knight-posix-binary
c52562bd0aabb86ce8ca177f22f8d0455769b444df2d4d62894faab63b7151d8 test/results/test00-x86-binary
7b711844a2c472626430d9e0db63a99abfc599f9df55df6c44b523732267441f test/results/test01-armv7l-binary
d77efa49034f3590ed7c77a8a18339d98be613f872ca7ee0adf41821d66bad81 test/results/test01-armv7l-binary
486ee05ccea796a9cfa9bfb23189b8e014b7ce8d14fea03b27d679d410fe17dd test/results/test01-knight-posix-binary
eae96857f2b6d8e8ba86ac06e72345ea572622b358b23978bb5f2db1baadf41c test/results/test01-x86-binary
3d10a15119546b1fe2368ef849c348a0ac6303bddf5e724de841bce1225506f6 test/results/test02-armv7l-binary
e85fdccb8626730ac9c3058225de1181af1da3004a4c8a776122e82bddc3ad20 test/results/test02-armv7l-binary
e6493845b9e94a617649638252f23502f9212de583fd00cba6cc07fffd296e32 test/results/test02-knight-posix-binary
8ead336d2f3f72d5874230492e0472edec61d355905e8636e3dfb2731695037c test/results/test02-x86-binary
458494405d2a56556775d317bc59e88e8844a18658417752da78c315f4434b64 test/results/test03-armv7l-binary
4aabcedfb3b0a47808da7adc91616b03968dfe5876a656c8870c5aafe83ee0e7 test/results/test03-armv7l-binary
96849d5a9294799a9648c24db21b2dab1555dd5ba69d172d77df800622347226 test/results/test03-knight-posix-binary
2313cb3f1a2b9eb6bf15f8d43418e15d6c16f7f1b5c22700fdfc2b38beb59192 test/results/test03-x86-binary
49d35e2e98f7975ce8f401b23475421caa1eb5274b1a42eabcf9c8bd5e17eea1 test/results/test04-armv7l-binary
3014112897ad80d2f72382104b5bf3badd95db52fb60cdfd71c93148c16a38de test/results/test04-armv7l-binary
df9ba08dfa69ac6cbb4483146dbbe079ef575d7de8318e2e52283151ebf24bd3 test/results/test04-knight-posix-binary
b7ddb37063c541c6a315809c4438aa235d6702f54bb64f4ffc88dbe78617de81 test/results/test04-x86-binary
400f8b25f27b31d26b956686c8cc1f4f174466f6f3d0c4cc1d02e2718e005606 test/results/test05-armv7l-binary
5db3a2fbd84150dae41e1c778f2822d053a0539cbdf59bba56e5514222f46674 test/results/test05-knight-posix-binary
b5b76320ccda887a30b0bbefc2a5c302c8f2aa3c398d92ef3a79526690b25d6f test/results/test05-x86-binary
2d0d9778c9de385f7a78009bee00345611a90b24e7418f9e8773018bd6113bd4 test/results/test06-armv7l-binary
b177d769ae44c3509d9a08d0ee631ec69654dc5d723408bf0decdc67c42aae27 test/results/test06-knight-posix-binary
663fc6eefe965f237b6bf5a211398c8ae1210f97ff39b59603677e92462c68c7 test/results/test06-x86-binary
9159c4ba8196b24ec78bc9ebfbc7066d510ddbf03461736e7795a48634134dc5 test/results/test07-knight-posix-binary
@ -25,8 +27,8 @@ f1c01feb865c4d552033186d9ce50dd39468a7e8aebf762886c13ad3e03b5011 test/results/t
3b39e72f3de90ed690adfaf6145af46157cef2ec5e72867ac577fa27a0229894 test/results/test09-x86-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary
020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-x86-binary
9eebb281d1dbf75aa7febadc1f5777c01a3802375ab237d9f5e2318229861e25 test/results/test100-knight-posix-binary
eb4f05476690361112c2f57f98c4d4dd16f755fbbfb879012de5d773884ea63b test/results/test100-x86-binary
fd5054d7d5ae525c4231a9351c98b373cff53275b80ee0853404cd17548f40d0 test/results/test100-knight-posix-binary
bb3a90999ee64b8560e76379ebcb60e3c700d41210bcb4c3cbf031185e5ace8c 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

48
test/test05/hello-armv7l.sh Executable file
View File

@ -0,0 +1,48 @@
#! /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 <http://www.gnu.org/licenses/>.
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/test05/string.c \
--debug \
-o test/test05/string.M1 || exit 1
blood-elf -f test/test05/string.M1 -o test/test05/string-footer.M1 || exit 2
# 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/test05/string.M1 \
-f test/test05/string-footer.M1 \
--LittleEndian \
--architecture armv7l \
-o test/test05/string.hex2 || exit 3
# Resolve all linkages
hex2 -f test/common_armv7l/ELF-armv7l-debug.hex2 -f test/test05/string.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test05-armv7l-binary --exec_enable || exit 4
# 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/test05-armv7l-binary 2>&1 )
[ 42 = $? ] || exit 4
[ "$out" = "Hello mes" ] || exit 5
fi
exit 0

43
test/test06/hello-armv7l.sh Executable file
View File

@ -0,0 +1,43 @@
#! /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 <http://www.gnu.org/licenses/>.
set -ex
# Build the test
bin/M2-Planet --architecture armv7l -f test/common_armv7l/functions/putchar.c \
-f test/test06/for.c \
-o test/test06/for.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/test06/for.M1 \
--LittleEndian \
--architecture armv7l \
-o test/test06/for.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_armv7l/ELF-armv7l.hex2 -f test/test06/for.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test06-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 resulting file works
./test/results/test06-armv7l-binary >| test/test06/proof || exit 4
out=$(sha256sum -c test/test06/proof.answer)
[ "$out" = "test/test06/proof: OK" ] || exit 5
fi
exit 0

44
test/test07/hello-armv7l.sh Executable file
View File

@ -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 <http://www.gnu.org/licenses/>.
set -ex
# Build the test
bin/M2-Planet --architecture armv7l -f test/common_armv7l/functions/putchar.c \
-f test/common_armv7l/functions/exit.c \
-f test/test07/do.c \
-o test/test07/do.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/test07/do.M1 \
--LittleEndian \
--architecture armv7l \
-o test/test07/do.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_armv7l/ELF-armv7l.hex2 -f test/test07/do.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test07-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 resulting file works
./test/results/test07-armv7l-binary >| test/test07/proof || exit 4
out=$(sha256sum -c test/test07/proof.answer)
[ "$out" = "test/test07/proof: OK" ] || exit 5
fi
exit 0

View File

@ -1 +1 @@
499dee39dc26fc7a6c5299033c596895b96a3354a20de85f4a5c02e1aef77bf8 test/test100/proof
60ad787cab898a4f762b48afd533f4a902deb026d15da53c4d1cd777712452c6 test/test100/proof