Remove test/common_amd64 files and switch amd64 to M2libc

This commit is contained in:
Jeremiah Orians 2021-02-03 00:32:47 -05:00
parent 6f8e2eb905
commit 695672985e
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
19 changed files with 6 additions and 830 deletions

2
M2libc

@ -1 +1 @@
Subproject commit fcf4a814581e264ee1dbc9472ea0fcef6116fa62
Subproject commit cb870984babf6ea27f556715599b1cf995d27fda

View File

@ -1,74 +0,0 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### 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
3E 00 # e_machine Indicating AMD64
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

View File

@ -1,74 +0,0 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### 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
3E 00 # e_machine Indicating AMD64
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

View File

@ -1,99 +0,0 @@
## 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/>.
DEFINE ADD_IMMEDIATE_to_rax 4805
DEFINE ADD_IMMEDIATE_to_rbp 4881C5
DEFINE ADD_rax_to_rbx 4801C3
DEFINE ADD_rbp_to_rax 4801E8
DEFINE ADD_rbx_to_rax 4801D8
DEFINE AND_rax_rbx 4821D8
DEFINE CALL_IMMEDIATE E8
DEFINE CALL_rax FFD0
DEFINE CMP 4839C3
DEFINE COPY_rax_to_rcx 4889C1
DEFINE COPY_rax_to_rdi 4889C7
DEFINE COPY_rbx_to_rax 4889D8
DEFINE COPY_rbp_to_rax 4889E8
DEFINE COPY_rbx_to_rdi 4889DF
DEFINE COPY_rdi_to_rbp 4889FD
DEFINE COPY_rsp_to_rbp 4889E5
DEFINE COPY_RSP_to_RDI 4889E7
DEFINE CQTO 4899
DEFINE DIVIDE_rax_by_rbx_into_rax 48F7F3
DEFINE DIVIDES_rax_by_rbx_into_rax 48F7FB
DEFINE JUMP E9
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
DEFINE LOAD_IMMEDIATE_r10 48C7C2
DEFINE LOAD_IMMEDIATE_rax 48C7C0
DEFINE LOAD_IMMEDIATE_rbx 48C7C3
DEFINE LOAD_IMMEDIATE_rdi 48C7C7
DEFINE LOAD_IMMEDIATE_rdx 48C7C2
DEFINE LOAD_IMMEDIATE_rsi 48C7C6
DEFINE LOAD_INTEGER 488B00
DEFINE LOAD_INTEGER_rdi 488B3F
DEFINE LOAD_INTEGER_rdx 488B12
DEFINE LOAD_INTEGER_rsi 488B36
DEFINE LOAD_RSP_IMMEDIATE_into_rax 488B8424
DEFINE MODULUS_rax_from_rbx_into_rbx 48F7F3
DEFINE MODULUSS_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 48F7EB
DEFINE MULTIPLYS_rax_by_rbx_into_rax 48F7E3
DEFINE NULL 0000000000000000
DEFINE NOT_rax 48F7D0
DEFINE OR_rax_rbx 4809D8
DEFINE POP_RAX 58
DEFINE POP_RBP 5D
DEFINE POP_RBX 5B
DEFINE POP_RDI 5F
DEFINE PUSH_RAX 50
DEFINE PUSH_RBP 55
DEFINE PUSH_RBX 53
DEFINE PUSH_RDI 57
DEFINE RETURN C3
DEFINE SAL_rax_Immediate8 48C1E0
DEFINE SHL_rax_cl 48D3E0
DEFINE SAL_rax_cl 48D3F0
DEFINE SHR_rax_cl 48D3E8
DEFINE SAR_rax_cl 48D3F8
DEFINE SETA 0F97C0
DEFINE SETAE 0F93C0
DEFINE SETB 0F92C0
DEFINE SETBE 0F96C0
DEFINE SETE 0F94C0
DEFINE SETG 0F9FC0
DEFINE SETGE 0F9DC0
DEFINE SETL 0F9CC0
DEFINE SETLE 0F9EC0
DEFINE SETNE 0F95C0
DEFINE STORE_CHAR 8803
DEFINE STORE_INTEGER 488903
DEFINE SUBTRACT_rax_from_rbx_into_rbx 4829C3
DEFINE SYSCALL 0F05
DEFINE TEST 4885C0
DEFINE XCHG_rax_rbx 4893
DEFINE XOR_rbx_rax_into_rax 4831D8

View File

@ -1,26 +0,0 @@
/* Copyright (C) 2020 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/>.
*/
int access(char* pathname, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %21"
"SYSCALL");
}

View File

@ -1,32 +0,0 @@
/* Copyright (C) 2020 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/>.
*/
int chdir(char* path)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %80"
"SYSCALL");
}
int fchdir(int fd)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %81"
"SYSCALL");
}

View File

@ -1,50 +0,0 @@
/* 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/>.
*/
void exit(int value);
void _exit(int value)
{
exit(value);
}
int waitpid (int pid, int* status_ptr, int options)
{
/* Uses wait4 with struct rusage *ru set to NULL */
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_r10 %0"
"LOAD_IMMEDIATE_rax %61"
"SYSCALL");
}
int execve(char* file_name, char** argv, char** envp)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %59"
"SYSCALL");
}

View File

@ -1,27 +0,0 @@
/* 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/>.
*/
// CONSTANT EXIT_FAILURE 1
// CONSTANT EXIT_SUCCESS 0
void exit(int value)
{
asm("POP_RBX"
"POP_RDI"
"LOAD_IMMEDIATE_rax %0x3C"
"SYSCALL");
}

View File

@ -1,136 +0,0 @@
/* 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/>.
*/
// CONSTANT stdin 0
// CONSTANT stdout 1
// CONSTANT stderr 2
// CONSTANT EOF 0xFFFFFFFF
int fgetc(FILE* f)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %0"
"PUSH_RAX"
"LOAD_EFFECTIVE_ADDRESS_rsi %0"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL"
"LOAD_IMMEDIATE_rbx %0"
"CMP"
"POP_RAX"
"JUMP_NE %FUNCTION_fgetc_Done"
"LOAD_IMMEDIATE_rax %-1"
":FUNCTION_fgetc_Done");
}
void fputc(char s, FILE* f)
{
asm("LOAD_IMMEDIATE_rax %1"
"LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL");
}
/* Important values needed for open */
// CONSTANT O_RDONLY 0
// CONSTANT O_WRONLY 1
// CONSTANT O_RDWR 2
// CONSTANT O_CREAT 64
// CONSTANT O_TRUNC 512
/* 00700 in octal is 448*/
// CONSTANT S_IRWXU 448
/* 00100 in octal is 64 */
// CONSTANT S_IXUSR 64
/* 00200 in octal is 128 */
// CONSTANT S_IWUSR 128
/* 00400 in octal is 256 */
// CONSTANT S_IRUSR 256
FILE* open(char* name, int flag, int mode)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %2"
"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("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %3"
"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)
{
/* Uses lseek directly */
asm("LOAD_EFFECTIVE_ADDRESS_rdi %24"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %16"
"LOAD_INTEGER_rsi"
"LOAD_EFFECTIVE_ADDRESS_rdx %8"
"LOAD_INTEGER_rdx"
"LOAD_IMMEDIATE_rax %8"
"SYSCALL");
}
void rewind(FILE* f)
{
fseek(f, 0, SEEK_SET);
}

View File

@ -1,23 +0,0 @@
/* 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/>.
*/
int fork()
{
asm("LOAD_IMMEDIATE_rax %57"
"LOAD_IMMEDIATE_rdi %0"
"SYSCALL");
}

View File

@ -1,32 +0,0 @@
/* 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/>.
*/
int getchar()
{
asm("LOAD_IMMEDIATE_rdi %0"
"LOAD_IMMEDIATE_rax %0"
"PUSH_RAX"
"LOAD_EFFECTIVE_ADDRESS_rsi %0"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL"
"LOAD_IMMEDIATE_rbx %0"
"CMP"
"POP_RAX"
"JUMP_NE %FUNCTION_getchar_Done"
"LOAD_IMMEDIATE_rax %-1"
":FUNCTION_getchar_Done");
}

View File

@ -1,47 +0,0 @@
/* Copyright (C) 2020 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/>.
*/
#include<stdlib.h>
//CONSTANT PATH_MAX 4096
#define PATH_MAX 4096
int _getcwd(char* buf, size_t size)
{
asm("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %79"
"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);
}

View File

@ -1,50 +0,0 @@
/* 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/>.
*/
// CONSTANT NULL 0
int brk(void *addr)
{
asm("LOAD_RSP_IMMEDIATE_into_rax %8"
"PUSH_RAX"
"LOAD_IMMEDIATE_rax %12"
"POP_RBX"
"COPY_rbx_to_rdi"
"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;
}

View File

@ -1,25 +0,0 @@
/* 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/>.
*/
void putchar(int c)
{
asm("LOAD_IMMEDIATE_rax %1"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_IMMEDIATE_rdi %1"
"LOAD_IMMEDIATE_rdx %1"
"SYSCALL");
}

View File

@ -1,51 +0,0 @@
/* 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/>.
*/
/*
* 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("LOAD_EFFECTIVE_ADDRESS_rdi %16"
"LOAD_INTEGER_rdi"
"LOAD_EFFECTIVE_ADDRESS_rsi %8"
"LOAD_INTEGER_rsi"
"LOAD_IMMEDIATE_rax %90"
"SYSCALL");
}

View File

@ -1,33 +0,0 @@
/* 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/>.
*/
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("LOAD_EFFECTIVE_ADDRESS_rdi %8"
"LOAD_INTEGER_rdi"
"LOAD_IMMEDIATE_rax %63"
"SYSCALL");
}

View File

@ -1,42 +0,0 @@
## 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/>.
:_start
COPY_rsp_to_rbp ; Protect rsp
;; Prepare argv
LOAD_BASE_ADDRESS_rax %8 ; ARGV_address = RBP + 8
PUSH_RAX ; Put argv on the stack
;; Prepare envp
COPY_rbp_to_rax ; Address we need to load from
LOAD_INTEGER ; Get ARGC
ADD_IMMEDIATE_to_rax %2 ; OFFSET = ARGC + 2
SAL_rax_Immediate8 !3 ; OFFSET = OFFSET * WORDSIZE
ADD_rbp_to_rax ; ENVP_address = RSP + OFFSET
PUSH_RAX ; Put envp on the stack
;; Stack offset
ADD_IMMEDIATE_to_rbp %8 ; Fix rbp
;; Perform the main loop
CALL_IMMEDIATE %FUNCTION_main
;; Exit to kernel
COPY_rax_to_rdi ; Using the return code given by main
LOAD_IMMEDIATE_rax %0x3C ; Syscall exit
SYSCALL ; Exit with that code

View File

@ -180,7 +180,7 @@ ba2e2e1bbe66fea15d5984678175229fcb0adc6faa394be2cfde8bea1d3026de test/results/t
44d0b9e0433f12b5567ecddc9285b6a7d41ea646a7134e6fc3c394b4a973f6ba test/results/test0106-knight-posix-binary
1f83e1cbac44aabd9f87eae601e020b584b572e7edb738d6274972d6d100fa3c test/results/test0106-x86-binary
f2fdafa1f4697d505f4e6b0305149e4a41fb50bae7024b420559ef8b42c5813a test/results/test1000-aarch64-binary
0ca1cd3601969f50596d8c46f43ba1ec8faf6de41deae69d8fb199b35a3a3c99 test/results/test1000-amd64-binary
8a85c62b07cc8b5203e50ca0f2400b2ffa522e196726648b4d128fb62a034913 test/results/test1000-amd64-binary
869ff8d396e1d99897669733cf5756ef88c061689066163a969eb724e901a3e2 test/results/test1000-armv7l-binary
3758195a742867a22237a1371a5f4b19c4e9b8a0c6675d76f09fd748a46aed46 test/results/test1000-knight-posix-binary
72b941a1c9708605eb531702bbf2ddc2a21fc1a7f60977fa936dc6fbca3bea19 test/results/test1000-x86-binary

View File

@ -24,10 +24,7 @@ mkdir -p ${TMPDIR}
# Build the test
./bin/M2-Planet \
--architecture amd64 \
-f test/common_amd64/functions/file.c \
-f test/common_amd64/functions/malloc.c \
-f functions/calloc.c \
-f test/common_amd64/functions/exit.c \
-f M2libc/amd64/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_amd64/amd64_defs.M1 \
-f test/common_amd64/libc-core.M1 \
-f M2libc/amd64/amd64_defs.M1 \
-f M2libc/amd64/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_amd64/ELF-amd64-debug.hex2 \
-f M2libc/amd64/ELF-amd64-debug.hex2 \
-f ${TMPDIR}/cc.hex2 \
--little-endian \
--architecture amd64 \