Compare commits

..

No commits in common. "6902b49be2d3f27091cfbb91cd41ea5d34c51c1a" and "ff71a50db7f057350405535ef8d08f7460aac832" have entirely different histories.

4 changed files with 13 additions and 43 deletions

View File

@ -25,8 +25,8 @@ bldtst_llvm: buildtest.c arch/*.c
bldtst_x64: buildtest.c arch/x86_64.c
clang --target=x86_64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_x64 buildtest.c arch/x86_64.c
bldtst_aarch64: buildtest.c arch/aarch64.c
bldtst_aarch64: buildtest.c
clang --target=aarch64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_aarch64 buildtest.c arch/aarch64.c
bldtst_mips32: buildtest.c arch/mips.c
bldtst_mips32: buildtest.c
clang --target=mips-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -fno-pic -o bldtst_mips32 buildtest.c arch/mips.c

View File

@ -14,45 +14,19 @@ void exit(int8_t status){
intptr_t write(int32_t fd, const void* buf, intptr_t size){
intptr_t n_written = 0;
//register int32_t fd_w asm("w0") = fd;
asm volatile(
// Assembly Instructions
"mov x0, %1\n" // Set x0 to value of fd
"mov x1, %2\n" // Set x1 to value of buf
"mov x2, %3\n" // Set x2 to value of size
"mov x8, #64\n" // Syscall number for 'write' is 64 in AArch64
"svc #0\n" // Make syscall
"mov %0, x0\n" // Store return value in n_written
// Output operands
: "=r"(n_written)
// Input operands
: "r"((int64_t)fd), "r" (buf), "r"(size)
// Clobbered registers
: "x0", "x1", "x2", "x8"
"mov x0, %2\n"
"mov x1, %0\n"
"mov x2, %1\n"
"mov x8, #64\n"
"svc #0\n"
: //TODO: n_written
: "r" (buf), "r"(size), "r"(fd)
: "x0", "x8" // Clobbered registers
);
return n_written;
}
intptr_t read(int32_t fd, const void* buf, intptr_t size){
intptr_t n_read = 0;
asm volatile(
// Assembly Instructions
"mov x0, %1\n" // Set x0 to value of fd
"mov x1, %2\n" // Set x1 to value of buf
"mov x2, %3\n" // Set x2 to value of size
"mov x8, #63\n" // Syscall number for 'read' is 63 in AArch64
"svc #0\n" // Make syscall
"mov %0, x0\n" // Store return value in n_read
// Output operands
: "=r"(n_read)
// Input operands
: "r"((int64_t)fd), "r" (buf), "r"(size)
// Clobbered registers
: "x0", "x1", "x2", "x8"
);
return n_read;
}
#define CLONE_CHILD_SETTID 0x1000000
#define CLONE_CHILD_CLEARTID 0x200000
uint32_t fork(){

View File

@ -3,12 +3,8 @@
int main() {
// Test the write syscall
intptr_t n = write(STDIO, "Hello\n", 6);
if(n != 6) return n;
// Test the fork syscall
uint64_t pid = fork();
// Print the pid in hex
char msg[17] = {' '};
msg[16] = '\n';
@ -25,7 +21,7 @@ int main() {
if(pid == 0) return 0;
//TODO: wait on child to remove zombie process
#if defined(__x86_64__) || defined(__aarch64__)
#if defined(__x86_64__)
// Test the read syscall
#define INPUT_BUFFER_LEN 4096
char input_buffer[INPUT_BUFFER_LEN] = {0};

2
sys.h
View File

@ -6,7 +6,7 @@ void exit(int8_t status);
#define STDIO 1
#define STDERR 2
intptr_t write(int32_t fd, const void* buf, intptr_t size);
#if defined(__x86_64__) || defined(__aarch64__)
#if defined(__x86_64__)
intptr_t read(int32_t fd, const void* buf, intptr_t size);
#endif