diff options
Diffstat (limited to 'tools/include/nolibc/arch-riscv.h')
-rw-r--r-- | tools/include/nolibc/arch-riscv.h | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index a3bdd9803f8c..e197fcb10ac0 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -7,18 +7,6 @@ #ifndef _NOLIBC_ARCH_RISCV_H #define _NOLIBC_ARCH_RISCV_H -/* O_* macros for fcntl/open are architecture-specific */ -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#define O_CREAT 0x40 -#define O_EXCL 0x80 -#define O_NOCTTY 0x100 -#define O_TRUNC 0x200 -#define O_APPEND 0x400 -#define O_NONBLOCK 0x800 -#define O_DIRECTORY 0x10000 - struct sys_stat_struct { unsigned long st_dev; /* Device. */ unsigned long st_ino; /* File serial number. */ @@ -182,23 +170,39 @@ struct sys_stat_struct { _arg1; \ }) +char **environ __attribute__((weak)); +const unsigned long *_auxv __attribute__((weak)); + /* startup code */ -__asm__ (".section .text\n" - ".weak _start\n" - "_start:\n" - ".option push\n" - ".option norelax\n" - "lla gp, __global_pointer$\n" - ".option pop\n" - "lw a0, 0(sp)\n" // argc (a0) was in the stack - "add a1, sp, "SZREG"\n" // argv (a1) = sp - "slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ... - "add a2, a2, "SZREG"\n" // + SZREG (skip null) - "add a2,a2,a1\n" // + argv - "andi sp,a1,-16\n" // sp must be 16-byte aligned - "call main\n" // main() returns the status code, we'll exit with it. - "li a7, 93\n" // NR_exit == 93 - "ecall\n" - ""); +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) +{ + __asm__ volatile ( + ".option push\n" + ".option norelax\n" + "lla gp, __global_pointer$\n" + ".option pop\n" + "lw a0, 0(sp)\n" // argc (a0) was in the stack + "add a1, sp, "SZREG"\n" // argv (a1) = sp + "slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ... + "add a2, a2, "SZREG"\n" // + SZREG (skip null) + "add a2,a2,a1\n" // + argv + + "add a3, a2, zero\n" // iterate a3 over envp to find auxv (after NULL) + "0:\n" // do { + "ld a4, 0(a3)\n" // a4 = *a3; + "add a3, a3, "SZREG"\n" // a3 += sizeof(void*); + "bne a4, zero, 0b\n" // } while (a4); + "lui a4, %hi(_auxv)\n" // a4 = &_auxv (high bits) + "sd a3, %lo(_auxv)(a4)\n" // store a3 into _auxv + + "lui a3, %hi(environ)\n" // a3 = &environ (high bits) + "sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ + "andi sp,a1,-16\n" // sp must be 16-byte aligned + "call main\n" // main() returns the status code, we'll exit with it. + "li a7, 93\n" // NR_exit == 93 + "ecall\n" + ); + __builtin_unreachable(); +} #endif // _NOLIBC_ARCH_RISCV_H |