Overview
Comment: | add in mechanism to generate syscall tables for x86 linux |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
860229e8ce1a86fe94865aec6da863e3 |
User & Date: | lexi on 2019-06-27 09:57:30 |
Other Links: | manifest | tags |
Context
2019-06-27
| ||
12:13 | updates check-in: 21467a6dc9 user: lexi tags: trunk | |
09:57 | add in mechanism to generate syscall tables for x86 linux check-in: 860229e8ce user: lexi tags: trunk | |
05:52 | updates check-in: f5b7fa5762 user: lexi tags: trunk | |
Changes
Added arch/makefile version [8e0dfa3404].
1 +calls.x86.lin.32.s: /usr/include/asm/unistd_32.h 2 + grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@ 3 +calls.x86.lin.64.s: /usr/include/asm/unistd_64.h 4 + grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@
Modified arch/x86.lin.32.s from [7c5909e17f] to [fed93e863f].
1 +;; abi definition file for x86 linux 32-bit 1 2 ; vim: ft=nasm 2 -%define sys.exit 1 3 -%define sys.fork 2 4 -%define sys.read 3 5 -%define sys.write 4 6 -%define sys.open 5 7 -%define sys.close 6 8 -%define sys.chdir 12 3 + 4 +; syscall32 numbers - syscall table must be created first! 5 +%include "calls.x86.lin.32.s" 9 6 7 +; syscall32 registers 10 8 %define sys.reg.n 6 11 9 %define sys.reg.0 eax 12 10 %define sys.reg.1 ebx 13 11 %define sys.reg.2 ecx 14 12 %define sys.reg.3 edx 15 13 %define sys.reg.4 esi 16 14 %define sys.reg.5 edi 15 + 16 +%macro sys 1-6 17 + %assign i 0 18 + %rep %0 19 + mov sys.reg. %+ i, %1 ; i'm actually shocked this worked 20 + %rotate 1 21 + %assign i i+1 22 + %endrep 23 + syscall 24 +%endmacro 17 25 18 26 %define sys.call int 0x80 ; sysenter is allegedly the 19 27 ; politically correct option but it does not actually 20 28 ; appear to work without a whole lot of extra bullshit 21 29 22 30 ; todo: learn vdsos
Modified arch/x86.lin.64.s from [fcbc285104] to [1f6b1a0933].
1 -;; abi definition file 2 -;; macros: 3 -;; * sys: syscall64 wrapper 4 -;; * ccall: automatically generate code to call a C function 5 -;; with any number of arguments 1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall64 numbers - syscall table must be created first! 5 +%include "calls.x86.lin.64.s" 6 6 7 7 ; syscall ops 8 8 %define sys.call syscall 9 -; syscall numbers 10 -%define sys.write 1 11 -%define sys.brk 12 12 -%define sys.exit 60 13 9 14 10 ; register order for syscall convention 11 +%define sys.reg.n 7 15 12 %define sys.reg.0 rax 16 13 %define sys.reg.1 rdi 17 14 %define sys.reg.2 rsi 18 15 %define sys.reg.3 rdx 19 16 %define sys.reg.4 r10 20 17 %define sys.reg.5 r8 21 18 %define sys.reg.6 r9 ................................................................................ 26 23 %define ccall.reg.1 rsi 27 24 %define ccall.reg.2 rdx 28 25 %define ccall.reg.3 rcx 29 26 %define ccall.reg.4 r8 30 27 %define ccall.reg.5 r9 31 28 32 29 %macro sys 1-8 30 +; syscall64 wrapper, ex. `sys sys.write, 1, msg, msg.len` 33 31 %assign i 0 34 32 %rep %0 35 33 mov sys.reg. %+ i, %1 ; i'm actually shocked this worked 36 34 %rotate 1 37 35 %assign i i+1 38 36 %endrep 39 37 syscall
Modified makefile from [e2aa0ec204] to [0ee3372ddd].
20 20 defs: $(headers) 21 21 tool: $(binmods:%=%.tool) 22 22 23 23 lists = moddirs modules headers objects makefiles binaries binmods 24 24 dbg: 25 25 @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") 26 26 27 -%.obj: %/makefile $(OUT) 27 +%.obj: %/makefile ${TARGET}.calls $(OUT) 28 28 cd $* && $(MAKE) obj 29 29 30 30 %.tool: %/makefile $(OUT) 31 31 cd $* && $(MAKE) tool 32 32 33 33 %.dbg: %/makefile $(OUT) 34 34 cd $* && $(MAKE) dbg 35 35 36 +%.calls: arch/makefile 37 + cd arch && make calls.$*.s 38 + 36 39 $(OUT)/libk.so: mods $(OUT) 37 40 $(CC) -shared -o $@ $(objects) 38 41 39 42 $(OUT)/libk.a: mods $(OUT) 40 43 # using `ar c` and ranlib here instead of 41 44 # `ar cs` in case `ar` isn't the GNU version 42 45 ar c $@ $(objects)