From 31df6146bfe0f9431c823afa583ad71b2289560b Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Mon, 14 Apr 2025 13:14:20 -0400 Subject: [PATCH] Remove print.c --- Makefile | 14 +---- print.c | 173 ------------------------------------------------------- 2 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 print.c diff --git a/Makefile b/Makefile index d8d0b3e..2c56f05 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: print print_x64 print_aarch64 print_mips32 buildtest +all: buildtest clean: if test -f print; then rm print; fi @@ -15,18 +15,6 @@ buildtest: bldtst bldtst_llvm bldtst_x64 bldtst_aarch64 bldtst_mips32 .PHONY: all buildtest clean -print: - gcc -static -nostdlib -Wno-builtin-declaration-mismatch -fno-stack-protector -o print print.c -print_x64: print.c - clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_x64 print.c - -print_aarch64: print.c - clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_aarch64 print.c - -print_mips32: print.c - clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o print_mips32 print.c - - bldtst: buildtest.c arch/*.c gcc -static -nostdlib -Wno-builtin-declaration-mismatch -fno-stack-protector -o bldtst buildtest.c arch/*.c diff --git a/print.c b/print.c deleted file mode 100644 index ddcafa1..0000000 --- a/print.c +++ /dev/null @@ -1,173 +0,0 @@ -long print(const void *buf, long count) { -#if defined(__x86_64__) - asm volatile ( - "syscall" - : - : "a"(1), "D"(1), "S"(buf), "d"(count) // RDI, RSI, RDX are used in x86-64 for write args - : "rcx", "r11", "memory" - ); - #elif defined(__aarch64__) - asm ( "mov x0, #1\n" // Move the exit status into register x0 - "mov x1, %0\n" // Syscall number for 'exit' is 93 in AArch64 - "mov x2, %1\n" // Syscall number for 'exit' is 93 in AArch64 - "mov x8, #64\n" // Syscall number for 'exit' is 93 in AArch64 - "svc #0\n" // Make the syscall - : // No output operands - : "r" (buf), "r"(count) // Input operand: status - : "x0", "x8" // Clobbered registers - ); - #elif defined(__mips__) - asm ( "li $a0, 1\n" - "move $a1, %0\n" - "move $a2, %1\n" - "li $v0, 4004\n" - "syscall" - : - : "r"(buf), "r"(count) - : "a0", "a1", "a2", "v0" //TODO: temp registers clobbered by syscall should probably also be listed but this fn returns right away so it should be fine? - ); - #endif - return 0; -} - -#define CLONE_CHILD_SETTID 0x1000000 -#define CLONE_CHILD_CLEARTID 0x200000 -#if defined(__aarch64__) -long int fork() { - long int rtn; - long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID; - asm volatile ( - // Assembly Instructions - "mov x8, #220\n" // Syscall number for 'clone' is 220 in AArch64 - "mov x0, %1\n" // clone flags - "mov x1, #0\n" // child stack pointer - "mov x2, #0\n" // parent_tidptr - "mov x3, #0\n" // tls - "mov x4, #0\n" // child_tidptr - "svc #0\n" // Make the syscall - "mov %0, x0\n" // save return value - // Output operands - : "=r" (rtn) - // Input operand - : "r" (flags) - // Clobbered registers - : "x0", "x1", "x2", "x3", "x4", "x8" - ); - return rtn; -} -#elif defined(__x86_64__) -long int fork() { - long int rtn; - /* - long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID; - asm volatile( - "movq %%rax, 56\n" // syscall number for 'clone' is 56 for x86-64 - "movq %%rdi, %1\n" // clone flags - "movq %%rsi, 0\n" // child stack pointer - "movq %%rdx, 0\n" // parent tidptr - "movq %%r10, 0\n" // child tidptr - "movq %%r8, 0\n" // tls - "syscall\n" // syscall - "movq %0, %%rax\n" // save return value - : "=r"(rtn) - : "r"(flags) - : "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9", "r10", "r11" - ); - */ - asm volatile( - "syscall\n" // syscall - "movq %0, %%rax\n" // save return value - : "=r"(rtn) - : "a"(57) - : - ); - return rtn; -} -#elif defined(__mips__) -long int fork() { - int rtn; - asm ( - "li $v0, 4002\n" - "syscall\n" - "move %0, $v0" - :"=r" (rtn) - : - : "a0", "v0" - ); - return (long int)rtn; -} -#endif - -void exit(int status) { -#if defined(__x86_64__) - asm volatile( - "syscall" - : - : "a"(60), "D"(status) - : - ); - #elif defined(__aarch64__) - asm ( "mov x0, %0\n" // Move the exit status into register x0 - "mov x8, #93\n" // Syscall number for 'exit' is 93 in AArch64 - "svc #0\n" // Make the syscall - : // No output operands - : "r" ((long)status) // Input operand: status - : "x0", "x8" // Clobbered registers - ); - #elif defined(__mips__) - asm ( "move $a0, %0\n" - "li $v0, 4001\n" - "syscall" - : - : "r" (status) - : "a0", "v0" - ); - #endif - for(;;); -} - - -int main() { -#if defined(__x86_64__) || defined(__aarch64__) || defined(__mips__) - long int pid = fork(); - char msg[17] = {' '}; - msg[16] = '\n'; - for(int i = 0; i < 16; ++i) { - char nibble = (pid >> ((15 - i) * 4)) & 0xf; - char c; - if (nibble > 9) {c = nibble + '7';} - else {c = nibble + '0';} - msg[i] = c; - } - print(msg, 17); - #else - char *msg = "Hello World!\n"; - print(msg, 13); -#endif - return 69; -} -void __libc_start_main() {exit(main());} - -void _start() { - __libc_start_main(); -} - -void __start() { - _start(); -} -/* -#if defined(__x86_64__) - printf("Compiled for x86_64 architecture\n"); - #elif defined(__i386__) - printf("Compiled for x86 architecture\n"); - #elif defined(__arm__) - printf("Compiled for ARM architecture\n"); - #elif defined(__aarch64__) - printf("Compiled for ARM64 architecture\n"); - #elif defined(__mips__) - printf("Compiled for ARM architecture\n"); - #else - printf("Unknown architecture\n"); - #endif -*/ -