Fixup behavior on 64bit platforms

This commit is contained in:
Jeremiah Orians 2019-06-19 21:43:34 -04:00
parent f43aa4a44c
commit 465b4c9c31
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
13 changed files with 90 additions and 53 deletions

View File

@ -20,6 +20,7 @@
** Changed
Tweaked cc_types.c to better match amd64 assembly
Replaced out with output_list in cc_core.c
For 32bit behavior on 64bit platforms
** Fixed

View File

@ -35,7 +35,6 @@ char* break_target_func;
char* break_target_num;
struct token_list* break_frame;
int current_count;
struct type* last_type;
int Address_of;
/* Imported functions */
@ -45,6 +44,9 @@ char* numerate_number(int a);
int numerate_string(char *a);
char* number_to_hex(int a, int bytes);
/* Host touchy function will need custom on 64bit systems*/
int fixup_int32(int a);
struct token_list* emit(char *s, struct token_list* head)
{
struct token_list* t = calloc(1, sizeof(struct token_list));
@ -397,7 +399,7 @@ void primary_expr_number()
{
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture))
{
int size = numerate_string(global_token->s);
int size = fixup_int32(numerate_string(global_token->s));
if((32768 > size) && (size > -32768))
{
emit_out("LOADI R0 ");
@ -499,14 +501,13 @@ struct type* promote_type(struct type* a, struct type* b)
void common_recursion(FUNCTION f)
{
last_type = current_target;
global_token = global_token->next;
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) emit_out("PUSHR R0 R15\t#_common_recursion\n");
else if(X86 == Architecture) emit_out("PUSH_eax\t#_common_recursion\n");
else if(AMD64 == Architecture) emit_out("PUSH_RAX\t#_common_recursion\n");
else if(ARMV7L == Architecture) emit_out("{R0} PUSH_ALWAYS\t#_common_recursion\n");
struct type* last_type = current_target;
global_token = global_token->next;
f();
current_target = promote_type(current_target, last_type);

View File

@ -143,11 +143,14 @@ void require_match(char* message, char* required);
int member_size;
struct type* build_member(struct type* last, int offset)
{
struct type* member_type = type_name();
struct type* i = calloc(1, sizeof(struct type));
i->members = last;
i->offset = offset;
struct type* member_type = type_name();
i->type = member_type;
i->name = global_token->s;
global_token = global_token->next;
i->members = last;
/* Check to see if array */
if(match( "[", global_token->s))
@ -162,8 +165,7 @@ struct type* build_member(struct type* last, int offset)
i->size = member_type->size;
}
member_size = i->size;
i->type = member_type;
i->offset = offset;
return i;
}

22
functions/fixup.c Normal file
View File

@ -0,0 +1,22 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
/* This only works for 32bit architectures */
int fixup_int32(int a)
{
return a;
}

View File

@ -38,6 +38,7 @@ DEFINE JUMP_EQ 0F84
DEFINE JUMP_NE 0F85
DEFINE LOAD_BASE_ADDRESS_rax 488D85
DEFINE LOAD_BYTE 0FBE00
DEFINE LOAD_EFFECTIVE_ADDRESS_rax 488D8424
DEFINE LOAD_EFFECTIVE_ADDRESS_rdi 488DBC24
DEFINE LOAD_EFFECTIVE_ADDRESS_rdx 488D9424
DEFINE LOAD_EFFECTIVE_ADDRESS_rsi 488DB424
@ -55,6 +56,7 @@ DEFINE MODULUS_rax_from_rbx_into_rbx 48F7FB
DEFINE MOVE_rbx_to_rax 4889D8
DEFINE MOVE_rdx_to_rax 4889D0
DEFINE MOVEZX 480FB6C0
DEFINE MOVESX 4863C0
DEFINE MULTIPLY_rax_by_rbx_into_rax 48F7E3
DEFINE NOP 0000000000000000
DEFINE NOT_rax 48F7D0

View File

@ -0,0 +1,24 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
/* Only works for AMD64 with the value in RAX */
int fixup_int32(int a)
{
asm("LOAD_EFFECTIVE_ADDRESS_rax %8"
"LOAD_INTEGER"
"MOVESX");
}

View File

@ -53,10 +53,10 @@ a9cf4422e05075395ad75bbfe4b2659aec4541edd46d8c6b5064d3496b06a0b6 test/results/t
1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary
b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary
68862cbb943373c84f41d454ede6318fe5d20217624dc72ae7f6cf968e661aee test/results/test100-amd64-binary
7fdb5af1f3f3a11d616b0fa41dca001142780287e2c3b4e43dbd6a6839cc2455 test/results/test100-armv7l-binary
c5ecaae26e27fc58b6055182dc31b2d76fcfade0c0e62113e23a8d31852cddba test/results/test100-knight-posix-binary
fb19b73f76074f6144d3e2e0c9c00148a604c423b8f83521ec383e03af343421 test/results/test100-x86-binary
417ad7db393d6b81ec0dc0fb26b426b9ddd9038cf0645d53131af8698cf65097 test/results/test100-amd64-binary
0c03b5826145cfdd0ef7bb9e8d1c2fc3abdac86b0fa57806da80154c1972f314 test/results/test100-armv7l-binary
0ce1baf73766c193bd2aece2ac6caf485dbe0d2c54901d15f2095a2df739323e test/results/test100-knight-posix-binary
67e558164795211e0ccd4e0564d0f0d41b76800df97a635c07bdf63d0cf9feda test/results/test100-x86-binary
34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary
d9d465340abbce2d5964a6bc58e6cdd0ef93fb3d0199eaa823c86ec6abd0452a test/results/test11-armv7l-binary
955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary

View File

@ -27,6 +27,7 @@ set -ex
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f test/common_amd64/functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
@ -72,6 +73,7 @@ then
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \

View File

@ -27,6 +27,7 @@ set -ex
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
@ -72,6 +73,7 @@ then
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \

View File

@ -27,6 +27,7 @@ set -ex
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
@ -67,6 +68,7 @@ then
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \

View File

@ -27,6 +27,7 @@ set -ex
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
@ -72,6 +73,7 @@ then
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/fixup.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \

View File

@ -19,46 +19,22 @@ set -ex
# Build using seed if possible
if [ -f bin/M2-Planet-seed ]
then
[ ! -f test/results ] && mkdir -p test/results
./bin/M2-Planet-seed -f test/common_x86/functions/file.c \
-f test/common_x86/functions/malloc.c \
-f functions/calloc.c \
-f test/common_x86/functions/exit.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/file_print.c \
-f functions/number_pack.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \
-f cc_types.c \
-f cc_core.c \
-f cc.c \
--debug \
-o test/test100/cc.M1 || exit 1
[ ! -f test/results ] && mkdir -p test/results
cp bin/M2-Planet-seed bin/M2-Planet
# Build debug footer
blood-elf -f test/test100/cc.M1 \
-o test/test100/cc-footer.M1 || exit 2
# Macro assemble with libc written in M1-Macro
M1 -f test/common_x86/x86_defs.M1 \
-f test/common_x86/libc-core.M1 \
-f test/test100/cc.M1 \
-f test/test100/cc-footer.M1 \
--LittleEndian \
--architecture x86 \
-o test/test100/cc.hex2 || exit 3
# Resolve all linkages
hex2 -f test/common_x86/ELF-i386-debug.hex2 \
-f test/test100/cc.hex2 \
--LittleEndian \
--architecture x86 \
--BaseAddress 0x8048000 \
-o test/results/test100-x86-binary --exec_enable || exit 4
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "amd64" ]
then
./test/test100/hello-amd64.sh
mv test/results/test100-amd64-binary bin/M2-Planet
elif [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ]
then
./test/test100/hello-x86.sh
mv test/results/test100-x86-binary bin/M2-Planet
elif [ "$(get_machine ${GET_MACHINE_FLAGS})" = "armv7l" ]
then
./test/test100/hello-armv7l.sh
mv test/results/test100-armv7l-binary bin/M2-Planet
fi
else
[ -z "${CC+x}" ] && export CC=gcc
@ -70,6 +46,7 @@ ${CC} ${CFLAGS} \
functions/numerate_number.c \
functions/file_print.c \
functions/number_pack.c \
functions/fixup.c \
functions/string.c \
cc_reader.c \
cc_strings.c \

View File

@ -1 +1 @@
a055c6feac7ac8980d6c0369a18d91750795470a1817587490e7bf386c51e2b7 test/test100/proof
093748f4d5efd09b0b40b7aa7781e1ad3ae7a24e01b43838dcbf0692c5d1a9d3 test/test100/proof