Remove test/common_aarch64 files and switch AArch64 to M2libc
This commit is contained in:
parent
a65619dbf4
commit
62eedce858
|
@ -1,75 +0,0 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
### 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/>.
|
||||
|
||||
### stage0's hex2 format
|
||||
### !<label> 1 byte relative
|
||||
### $<label> 2 byte address
|
||||
### @<label> 2 byte relative
|
||||
### &<label> 4 byte address
|
||||
### %<label> 4 byte relative
|
||||
|
||||
### 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
|
||||
|
||||
02 # e_ident[EI_CLASS] Indicating 64 bit
|
||||
01 # e_ident[EI_DATA] Indicating little endianness
|
||||
01 # e_ident[EI_VERSION] Indicating original elf
|
||||
|
||||
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
|
||||
00 # e_ident[EI_ABIVERSION] See above
|
||||
|
||||
00 00 00 00 00 00 00 # e_ident[EI_PAD]
|
||||
|
||||
02 00 # e_type Indicating Executable
|
||||
B7 00 # e_machine Indicating AArch64
|
||||
01 00 00 00 # e_version Indicating original elf
|
||||
|
||||
&ELF_text 00 00 00 00 # e_entry Address of the entry point
|
||||
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
|
||||
%ELF_section_headers>ELF_base 00 00 00 00 # e_shoff Address of section header table
|
||||
|
||||
00 00 00 00 # e_flags
|
||||
|
||||
40 00 # e_ehsize Indicating our 64 Byte header
|
||||
|
||||
38 00 # e_phentsize size of a program header table
|
||||
01 00 # e_phnum number of entries in program table
|
||||
|
||||
40 00 # e_shentsize size of a section header table
|
||||
05 00 # e_shnum number of entries in section table
|
||||
|
||||
02 00 # e_shstrndx index of the section names
|
||||
|
||||
|
||||
:ELF_program_headers
|
||||
:ELF_program_header__text
|
||||
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
00 00 00 00 00 00 00 00 # ph_offset
|
||||
&ELF_base 00 00 00 00 # ph_vaddr
|
||||
&ELF_base 00 00 00 00 # ph_physaddr
|
||||
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
|
||||
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
|
||||
01 00 00 00 00 00 00 00 # ph_align
|
||||
|
||||
:ELF_text
|
|
@ -1,75 +0,0 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
### 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/>.
|
||||
|
||||
### stage0's hex2 format
|
||||
### !<label> 1 byte relative
|
||||
### $<label> 2 byte address
|
||||
### @<label> 2 byte relative
|
||||
### &<label> 4 byte address
|
||||
### %<label> 4 byte relative
|
||||
|
||||
### 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
|
||||
|
||||
02 # e_ident[EI_CLASS] Indicating 64 bit
|
||||
01 # e_ident[EI_DATA] Indicating little endianness
|
||||
01 # e_ident[EI_VERSION] Indicating original elf
|
||||
|
||||
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
|
||||
00 # e_ident[EI_ABIVERSION] See above
|
||||
|
||||
00 00 00 00 00 00 00 # e_ident[EI_PAD]
|
||||
|
||||
02 00 # e_type Indicating Executable
|
||||
B7 00 # e_machine Indicating AArch64
|
||||
01 00 00 00 # e_version Indicating original elf
|
||||
|
||||
&ELF_text 00 00 00 00 # e_entry Address of the entry point
|
||||
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
|
||||
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
|
||||
|
||||
00 00 00 00 # e_flags
|
||||
|
||||
40 00 # e_ehsize Indicating our 64 Byte header
|
||||
|
||||
38 00 # e_phentsize size of a program header table
|
||||
01 00 # e_phnum number of entries in program table
|
||||
|
||||
00 00 # e_shentsize size of a section header table
|
||||
00 00 # e_shnum number of entries in section table
|
||||
|
||||
00 00 # e_shstrndx index of the section names
|
||||
|
||||
|
||||
:ELF_program_headers
|
||||
:ELF_program_header__text
|
||||
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
00 00 00 00 00 00 00 00 # ph_offset
|
||||
&ELF_base 00 00 00 00 # ph_vaddr
|
||||
&ELF_base 00 00 00 00 # ph_physaddr
|
||||
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
|
||||
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
|
||||
01 00 00 00 00 00 00 00 # ph_align
|
||||
|
||||
:ELF_text
|
|
@ -1,150 +0,0 @@
|
|||
## Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
## Copyright (C) 2020 Sanne Wouda
|
||||
## 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/>.
|
||||
|
||||
DEFINE NULL 0000000000000000
|
||||
|
||||
# Stack (x18 as SP, 64 bits per element)
|
||||
DEFINE PUSH_X0 408e1ff8
|
||||
DEFINE PUSH_X1 418e1ff8
|
||||
DEFINE PUSH_X16 508e1ff8
|
||||
DEFINE PUSH_BP 518e1ff8
|
||||
DEFINE PUSH_LR 5e8e1ff8
|
||||
|
||||
DEFINE POP_X0 408640f8
|
||||
DEFINE POP_X1 418640f8
|
||||
DEFINE POP_X16 508640f8
|
||||
DEFINE POP_BP 518640f8
|
||||
DEFINE POP_LR 5e8640f8
|
||||
|
||||
DEFINE INIT_SP f2030091 # mov x18, sp
|
||||
|
||||
|
||||
# Jump/branch/call/return
|
||||
DEFINE BR_X16 00021fd6
|
||||
DEFINE BLR_X16 00023fd6
|
||||
DEFINE RETURN c0035fd6
|
||||
|
||||
DEFINE CBZ_X0_PAST_BR a00000b4
|
||||
DEFINE CBNZ_X0_PAST_BR a00000b5
|
||||
|
||||
DEFINE SKIP_INST_EQ 40000054
|
||||
DEFINE SKIP_INST_NE 41000054
|
||||
DEFINE SKIP_INST_LT 4b000054
|
||||
DEFINE SKIP_INST_LE 4d000054
|
||||
DEFINE SKIP_INST_GT 4c000054
|
||||
DEFINE SKIP_INST_GE 4a000054
|
||||
|
||||
DEFINE SKIP_INST_LO 43000054
|
||||
DEFINE SKIP_INST_LS 49000054
|
||||
DEFINE SKIP_INST_HS 42000054
|
||||
DEFINE SKIP_INST_HI 48000054
|
||||
|
||||
DEFINE SKIP_32_DATA 02000014
|
||||
|
||||
|
||||
# Load literals (PC-relative)
|
||||
DEFINE LOAD_W0_AHEAD 40000098
|
||||
DEFINE LOAD_W1_AHEAD 41000018
|
||||
DEFINE LOAD_W2_AHEAD 42000018
|
||||
DEFINE LOAD_W16_AHEAD 50000018
|
||||
|
||||
|
||||
# Load/store/dereference
|
||||
DEFINE LDR_X0_[SP] 400240f9
|
||||
DEFINE STR_X0_[X1] 200000f9
|
||||
DEFINE STR_BYTE_W0_[X1] 20000039
|
||||
DEFINE DEREF_X0 000040f9
|
||||
DEFINE DEREF_X0_BYTE 00004039
|
||||
|
||||
|
||||
# Move data between registers
|
||||
DEFINE SET_X0_FROM_BP e00311aa
|
||||
DEFINE SET_X1_FROM_X0 e10300aa
|
||||
DEFINE SET_X1_FROM_SP e10312aa
|
||||
DEFINE SET_X2_FROM_X0 e20300aa
|
||||
DEFINE SET_X3_FROM_X0 e30300aa
|
||||
DEFINE SET_X4_FROM_X0 e40300aa
|
||||
DEFINE SET_X5_FROM_X0 e50300aa
|
||||
DEFINE SET_X6_FROM_X0 e60300aa
|
||||
DEFINE SET_X16_FROM_X0 f00300aa
|
||||
DEFINE SET_X16_FROM_SP f00312aa
|
||||
DEFINE SET_BP_FROM_X16 f10310aa
|
||||
DEFINE SET_BP_FROM_SP f10312aa
|
||||
|
||||
|
||||
# Move constant to register
|
||||
DEFINE SET_X0_TO_0 000080d2
|
||||
DEFINE SET_X0_TO_1 200080d2
|
||||
DEFINE SET_X0_TO_17 200280d2
|
||||
DEFINE SET_X0_TO_MINUS_1 00008092
|
||||
DEFINE SET_W0_TO_MINUS_1 00008012
|
||||
DEFINE SET_X1_TO_0 010080d2
|
||||
DEFINE SET_X1_TO_2 410080d2
|
||||
DEFINE SET_X1_TO_8 010180d2
|
||||
DEFINE SET_X2_TO_1 220080d2
|
||||
DEFINE SET_X0_TO_FCNTL_H_AT_FDCWD 600c8092
|
||||
|
||||
|
||||
# Arith/logic/relational
|
||||
DEFINE ADD_X0_X1_X0 2000008b
|
||||
DEFINE ADD_X0_BP_X0 2002008b
|
||||
DEFINE ADD_X1_SP_8 41220091
|
||||
|
||||
DEFINE SUB_X0_X1_X0 200000cb
|
||||
DEFINE SUB_X0_X0_X1 000001cb
|
||||
DEFINE SUB_X0_8 002000d1
|
||||
DEFINE SUB_X0_16 004000d1
|
||||
DEFINE SUB_X0_24 006000d1
|
||||
DEFINE MSUB_X0_X0_X2_X1 0084029b
|
||||
|
||||
DEFINE MUL_X0_X1_X0 207c009b
|
||||
DEFINE SDIV_X0_X1_X0 200cc09a
|
||||
DEFINE SDIV_X2_X1_X0 220cc09a
|
||||
DEFINE UDIV_X0_X1_X0 2008c09a
|
||||
DEFINE UDIV_X2_X1_X0 2208c09a
|
||||
|
||||
DEFINE LSHIFT_X0_X0_X2 0020c29a
|
||||
DEFINE LSHIFT_X0_X1_X0 2020c09a
|
||||
DEFINE LOGICAL_RSHIFT_X0_X1_X0 2024c09a
|
||||
DEFINE ARITH_RSHIFT_X0_X1_X0 2028c09a
|
||||
|
||||
DEFINE MVN_X0 e00320aa
|
||||
DEFINE AND_X0_X1_X0 2000008a
|
||||
DEFINE OR_X0_X1_X0 200000aa
|
||||
DEFINE XOR_X0_X1_X0 000001ca
|
||||
|
||||
DEFINE CMP_X1_X0 3f0000eb
|
||||
|
||||
|
||||
# Syscall
|
||||
DEFINE SET_X8_TO_SYS_BRK c81a80d2
|
||||
DEFINE SET_X8_TO_SYS_CHDIR 280680d2
|
||||
DEFINE SET_X8_TO_SYS_CLONE 881b80d2
|
||||
DEFINE SET_X8_TO_SYS_CLOSE 280780d2
|
||||
DEFINE SET_X8_TO_SYS_EXECVE a81b80d2
|
||||
DEFINE SET_X8_TO_SYS_EXIT a80b80d2
|
||||
DEFINE SET_X8_TO_SYS_FACCESSAT 080680d2
|
||||
DEFINE SET_X8_TO_SYS_FCHDIR 480680d2
|
||||
DEFINE SET_X8_TO_SYS_FCHMODAT a80680d2
|
||||
DEFINE SET_X8_TO_SYS_GETCWD 280280d2
|
||||
DEFINE SET_X8_TO_SYS_LSEEK c80780d2
|
||||
DEFINE SET_X8_TO_SYS_OPENAT 080780d2
|
||||
DEFINE SET_X8_TO_SYS_READ e80780d2
|
||||
DEFINE SET_X8_TO_SYS_UNAME 081480d2
|
||||
DEFINE SET_X8_TO_SYS_WAIT4 882080d2
|
||||
DEFINE SET_X8_TO_SYS_WRITE 080880d2
|
||||
DEFINE SYSCALL 010000d4
|
|
@ -1,29 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
int access(char* pathname, int mode)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_TO_0"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X0_TO_FCNTL_H_AT_FDCWD"
|
||||
"SET_X8_TO_SYS_FACCESSAT"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
int chdir(char* path)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_CHDIR"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
int fchdir(int fd)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_FCHDIR"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
void exit(int value);
|
||||
|
||||
void _exit(int value)
|
||||
{
|
||||
exit(value);
|
||||
}
|
||||
|
||||
int waitpid(int pid, int* status_ptr, int options)
|
||||
{
|
||||
asm("SET_X0_TO_MINUS_1"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_WAIT4"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
int execve(char* file_name, char** argv, char** envp)
|
||||
{
|
||||
asm(
|
||||
"SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_EXECVE"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// CONSTANT EXIT_FAILURE 1
|
||||
// CONSTANT EXIT_SUCCESS 0
|
||||
|
||||
void exit(int value)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_EXIT"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/* Copyright (C) 2016 Jeremiah Orians
|
||||
* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// CONSTANT stdin 0
|
||||
// CONSTANT stdout 1
|
||||
// CONSTANT stderr 2
|
||||
// CONSTANT EOF 0xFFFFFFFF
|
||||
|
||||
int fgetc(FILE* f)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"PUSH_X0"
|
||||
"SET_X1_FROM_SP"
|
||||
"SET_X2_TO_1"
|
||||
"SET_X8_TO_SYS_READ"
|
||||
"SYSCALL"
|
||||
"SET_X1_TO_0"
|
||||
"CMP_X1_X0"
|
||||
"POP_X0"
|
||||
"SKIP_INST_NE"
|
||||
"SET_X0_TO_MINUS_1");
|
||||
}
|
||||
|
||||
|
||||
void fputc(char s, FILE* f)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X2_TO_1"
|
||||
"SET_X8_TO_SYS_WRITE"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
/* Important values needed for open
|
||||
* O_RDONLY => 0
|
||||
* O_WRONLY => 1
|
||||
* O_RDWR => 2
|
||||
* O_CREAT => 64
|
||||
* O_TRUNC => 512
|
||||
* S_IRWXU => 00700
|
||||
* S_IXUSR => 00100
|
||||
* S_IWUSR => 00200
|
||||
* S_IRUSR => 00400
|
||||
*/
|
||||
|
||||
FILE* open(char* name, int flag, int mode)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_TO_FCNTL_H_AT_FDCWD"
|
||||
"SET_X8_TO_SYS_OPENAT"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
FILE* fopen(char* filename, char* mode)
|
||||
{
|
||||
FILE* f;
|
||||
if('w' == mode[0])
|
||||
{ /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
|
||||
f = open(filename, 577 , 384);
|
||||
}
|
||||
else
|
||||
{ /* Everything else is a read */
|
||||
f = open(filename, 0, 0);
|
||||
}
|
||||
/* Negative numbers are error codes */
|
||||
if(0 > f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_CLOSE"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
int fclose(FILE* stream)
|
||||
{
|
||||
int error = close(stream);
|
||||
return error;
|
||||
}
|
||||
|
||||
int fflush(FILE *stream){
|
||||
/* We don't buffer, nothing to flush */
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CONSTANT SEEK_SET 0
|
||||
// CONSTANT SEEK_CUR 1
|
||||
// CONSTANT SEEK_END 2
|
||||
|
||||
int fseek(FILE* f, long offset, int whence)
|
||||
{
|
||||
asm("SET_X0_TO_MINUS_1"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_24" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_LSEEK"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
void rewind(FILE* f)
|
||||
{
|
||||
fseek(f, 0, SEEK_SET);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
int fork()
|
||||
{
|
||||
asm("SET_X0_TO_0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X4_FROM_X0"
|
||||
"SET_X5_FROM_X0"
|
||||
"SET_X6_FROM_X0"
|
||||
"SET_X0_TO_17"
|
||||
"SET_X8_TO_SYS_CLONE"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
int getchar()
|
||||
{
|
||||
asm("SET_X0_TO_0"
|
||||
"PUSH_X0"
|
||||
"SET_X1_FROM_SP"
|
||||
"SET_X2_TO_1"
|
||||
"SET_X8_TO_SYS_READ"
|
||||
"SYSCALL"
|
||||
"SET_X1_TO_0"
|
||||
"CMP_X1_X0"
|
||||
"POP_X0"
|
||||
"SKIP_INST_NE"
|
||||
"SET_X0_TO_MINUS_1");
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/* Copyright (C) 2020 Jeremiah Orians
|
||||
* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include<stdlib.h>
|
||||
//CONSTANT PATH_MAX 4096
|
||||
#define PATH_MAX 4096
|
||||
|
||||
int _getcwd(char* buf, size_t size)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_GETCWD"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
char* getcwd(char* buf, size_t size)
|
||||
{
|
||||
int c = _getcwd(buf, size);
|
||||
if(0 == c) return NULL;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* getwd(char* buf)
|
||||
{
|
||||
return getcwd(buf, PATH_MAX);
|
||||
}
|
||||
|
||||
char* get_current_dir_name()
|
||||
{
|
||||
return getcwd(malloc(PATH_MAX), PATH_MAX);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// CONSTANT NULL 0
|
||||
|
||||
int brk(void *addr)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_BRK"
|
||||
"SYSCALL");
|
||||
}
|
||||
|
||||
long _malloc_ptr;
|
||||
long _brk_ptr;
|
||||
|
||||
void* malloc(int size)
|
||||
{
|
||||
if(NULL == _brk_ptr)
|
||||
{
|
||||
_brk_ptr = brk(0);
|
||||
_malloc_ptr = _brk_ptr;
|
||||
}
|
||||
|
||||
if(_brk_ptr < _malloc_ptr + size)
|
||||
{
|
||||
_brk_ptr = brk(_malloc_ptr + size);
|
||||
if(-1 == _brk_ptr) return 0;
|
||||
}
|
||||
|
||||
long old_malloc = _malloc_ptr;
|
||||
_malloc_ptr = _malloc_ptr + size;
|
||||
return old_malloc;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
void putchar(int c)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_TO_1"
|
||||
"SET_X2_TO_1"
|
||||
"SET_X8_TO_SYS_WRITE"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/* Copyright (C) 2016 Jeremiah Orians
|
||||
* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* chmod() changes the mode of the file specified whose pathname is given in
|
||||
* pathname, which is dereferenced if it is a symbolic link.
|
||||
* fchmod() changes the mode of the file referred to by the open file
|
||||
* descriptor fd.
|
||||
* The new file mode is specified in mode, which is a bit mask created by
|
||||
* ORing together zero or more of the following:
|
||||
* S_ISUID (04000) set-user-ID (set process effective user ID on execve(2))
|
||||
* S_ISGID (02000) set-group-ID (set process effective group ID on execve(2)
|
||||
* mandatory locking, as described in fcntl(2); take a new file's group from
|
||||
* parent directory, as described in chown(2) and mkdir(2))
|
||||
* S_ISVTX (01000) sticky bit (restricted deletion flag, as described in
|
||||
* unlink(2))
|
||||
* S_IRUSR (00400) read by owner
|
||||
* S_IWUSR (00200) write by owner
|
||||
* S_IXUSR (00100) execute/search by owner ("search" applies for directories
|
||||
* , and means that entries within the directory can be accessed)
|
||||
* S_IRGRP (00040) read by group
|
||||
* S_IWGRP (00020) write by group
|
||||
* S_IXGRP (00010) execute/search by group
|
||||
* S_IROTH (00004) read by others
|
||||
* S_IWOTH (00002) write by others
|
||||
* S_IXOTH (00001) execute/search by others
|
||||
*/
|
||||
|
||||
int chmod(char *pathname, int mode)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_16" "DEREF_X0"
|
||||
"SET_X2_FROM_X0"
|
||||
"SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X1_FROM_X0"
|
||||
"SET_X0_TO_0"
|
||||
"SET_X3_FROM_X0"
|
||||
"SET_X0_TO_FCNTL_H_AT_FDCWD"
|
||||
"SET_X8_TO_SYS_FCHMODAT"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/* Copyright (C) 2016 Jeremiah Orians
|
||||
* Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
struct utsname
|
||||
{
|
||||
char sysname[65]; /* Operating system name (e.g., "Linux") */
|
||||
char nodename[65]; /* Name within "some implementation-defined network" */
|
||||
char release[65]; /* Operating system release (e.g., "2.6.28") */
|
||||
char version[65]; /* Operating system version */
|
||||
char machine[65]; /* Hardware identifier */
|
||||
};
|
||||
|
||||
int uname(struct utsname* unameData)
|
||||
{
|
||||
asm("SET_X0_FROM_BP" "SUB_X0_8" "DEREF_X0"
|
||||
"SET_X8_TO_SYS_UNAME"
|
||||
"SYSCALL");
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
## Copyright (C) 2020 deesix <deesix@tuta.io>
|
||||
## 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/>.
|
||||
|
||||
:_start
|
||||
INIT_SP
|
||||
LDR_X0_[SP]
|
||||
ADD_X1_SP_8
|
||||
SET_BP_FROM_SP
|
||||
PUSH_X0
|
||||
PUSH_X1
|
||||
SET_X1_TO_2
|
||||
ADD_X0_X1_X0
|
||||
SET_X1_TO_8
|
||||
MUL_X0_X1_X0
|
||||
ADD_X0_BP_X0
|
||||
PUSH_X0
|
||||
|
||||
LOAD_W16_AHEAD
|
||||
SKIP_32_DATA
|
||||
&FUNCTION_main
|
||||
BLR_X16
|
||||
SET_X8_TO_SYS_EXIT
|
||||
SYSCALL
|
|
@ -179,7 +179,7 @@ ba2e2e1bbe66fea15d5984678175229fcb0adc6faa394be2cfde8bea1d3026de test/results/t
|
|||
5afa9027627815aed92b0f239f4ac85318ca11c15c0c44ae0a0b9bc4ca599119 test/results/test0106-knight-native-binary
|
||||
44d0b9e0433f12b5567ecddc9285b6a7d41ea646a7134e6fc3c394b4a973f6ba test/results/test0106-knight-posix-binary
|
||||
1f83e1cbac44aabd9f87eae601e020b584b572e7edb738d6274972d6d100fa3c test/results/test0106-x86-binary
|
||||
f2fdafa1f4697d505f4e6b0305149e4a41fb50bae7024b420559ef8b42c5813a test/results/test1000-aarch64-binary
|
||||
0d0434bf7cb456375765ee2b049b1a0e656ab428a8445236dfc40892e47556ca test/results/test1000-aarch64-binary
|
||||
8a85c62b07cc8b5203e50ca0f2400b2ffa522e196726648b4d128fb62a034913 test/results/test1000-amd64-binary
|
||||
3b951779a5ea70097d4a46c420a19413c5e99df5108e93be39cff5a4abd1c12d test/results/test1000-armv7l-binary
|
||||
3758195a742867a22237a1371a5f4b19c4e9b8a0c6675d76f09fd748a46aed46 test/results/test1000-knight-posix-binary
|
||||
|
|
|
@ -24,10 +24,7 @@ mkdir -p ${TMPDIR}
|
|||
# Build the test
|
||||
./bin/M2-Planet \
|
||||
--architecture aarch64 \
|
||||
-f test/common_aarch64/functions/file.c \
|
||||
-f test/common_aarch64/functions/malloc.c \
|
||||
-f functions/calloc.c \
|
||||
-f test/common_aarch64/functions/exit.c \
|
||||
-f M2libc/aarch64/Linux/bootstrap.c \
|
||||
-f functions/match.c \
|
||||
-f functions/in_set.c \
|
||||
-f functions/numerate_number.c \
|
||||
|
@ -58,8 +55,8 @@ blood-elf \
|
|||
|
||||
# Macro assemble with libc written in M1-Macro
|
||||
M1 \
|
||||
-f test/common_aarch64/aarch64_defs.M1 \
|
||||
-f test/common_aarch64/libc-core.M1 \
|
||||
-f M2libc/aarch64/aarch64_defs.M1 \
|
||||
-f M2libc/aarch64/libc-core.M1 \
|
||||
-f ${TMPDIR}/cc.M1 \
|
||||
-f ${TMPDIR}/cc-footer.M1 \
|
||||
--little-endian \
|
||||
|
@ -69,7 +66,7 @@ M1 \
|
|||
|
||||
# Resolve all linkages
|
||||
hex2 \
|
||||
-f test/common_aarch64/ELF-aarch64-debug.hex2 \
|
||||
-f M2libc/aarch64/ELF-aarch64-debug.hex2 \
|
||||
-f ${TMPDIR}/cc.hex2 \
|
||||
--little-endian \
|
||||
--architecture aarch64 \
|
||||
|
|
Loading…
Reference in New Issue