ADDED arch/makefile Index: arch/makefile ================================================================== --- arch/makefile +++ arch/makefile @@ -0,0 +1,4 @@ +calls.x86.lin.32.s: /usr/include/asm/unistd_32.h + grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@ +calls.x86.lin.64.s: /usr/include/asm/unistd_64.h + grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@ Index: arch/x86.lin.32.s ================================================================== --- arch/x86.lin.32.s +++ arch/x86.lin.32.s @@ -1,22 +1,30 @@ +;; abi definition file for x86 linux 32-bit ; vim: ft=nasm -%define sys.exit 1 -%define sys.fork 2 -%define sys.read 3 -%define sys.write 4 -%define sys.open 5 -%define sys.close 6 -%define sys.chdir 12 + +; syscall32 numbers - syscall table must be created first! +%include "calls.x86.lin.32.s" +; syscall32 registers %define sys.reg.n 6 %define sys.reg.0 eax %define sys.reg.1 ebx %define sys.reg.2 ecx %define sys.reg.3 edx %define sys.reg.4 esi %define sys.reg.5 edi + +%macro sys 1-6 + %assign i 0 + %rep %0 + mov sys.reg. %+ i, %1 ; i'm actually shocked this worked + %rotate 1 + %assign i i+1 + %endrep + syscall +%endmacro %define sys.call int 0x80 ; sysenter is allegedly the ; politically correct option but it does not actually ; appear to work without a whole lot of extra bullshit ; todo: learn vdsos Index: arch/x86.lin.64.s ================================================================== --- arch/x86.lin.64.s +++ arch/x86.lin.64.s @@ -1,19 +1,16 @@ -;; abi definition file -;; macros: -;; * sys: syscall64 wrapper -;; * ccall: automatically generate code to call a C function -;; with any number of arguments +;; abi definition file for x86 linux 64-bit +; vim: ft=nasm + +; syscall64 numbers - syscall table must be created first! +%include "calls.x86.lin.64.s" ; syscall ops %define sys.call syscall -; syscall numbers -%define sys.write 1 -%define sys.brk 12 -%define sys.exit 60 ; register order for syscall convention +%define sys.reg.n 7 %define sys.reg.0 rax %define sys.reg.1 rdi %define sys.reg.2 rsi %define sys.reg.3 rdx %define sys.reg.4 r10 @@ -28,10 +25,11 @@ %define ccall.reg.3 rcx %define ccall.reg.4 r8 %define ccall.reg.5 r9 %macro sys 1-8 +; syscall64 wrapper, ex. `sys sys.write, 1, msg, msg.len` %assign i 0 %rep %0 mov sys.reg. %+ i, %1 ; i'm actually shocked this worked %rotate 1 %assign i i+1 Index: makefile ================================================================== --- makefile +++ makefile @@ -22,19 +22,22 @@ lists = moddirs modules headers objects makefiles binaries binmods dbg: @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") -%.obj: %/makefile $(OUT) +%.obj: %/makefile ${TARGET}.calls $(OUT) cd $* && $(MAKE) obj %.tool: %/makefile $(OUT) cd $* && $(MAKE) tool %.dbg: %/makefile $(OUT) cd $* && $(MAKE) dbg +%.calls: arch/makefile + cd arch && make calls.$*.s + $(OUT)/libk.so: mods $(OUT) $(CC) -shared -o $@ $(objects) $(OUT)/libk.a: mods $(OUT) # using `ar c` and ranlib here instead of