Overview
Comment: | fixes for shared building |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ec9b2b74b3c79d6fc96a8e827b3bc7bd |
User & Date: | lexi on 2019-06-27 22:14:56 |
Other Links: | manifest | tags |
Context
2019-06-28
| ||
01:59 | add {,un}install rule check-in: 2ed2a90fe5 user: lexi tags: trunk | |
2019-06-27
| ||
22:14 | fixes for shared building check-in: ec9b2b74b3 user: lexi tags: trunk | |
21:39 | development milestone check-in: a14ceee056 user: lexi tags: trunk | |
Changes
Added arch/x86.cdecl.32.s version [6e1eece757].
1 +;; x86.cdecl.32.s: x86 cdecl impl 2 +; vim: ft=nasm 3 + 4 +%macro ccall 1-* 5 + %assign i 0 6 + ; arguments must be pushed to the stack backwards 7 + %assign ct (%0-ct)-1 8 + %rotate ct 9 + %rep ct 10 + %rotate -1 11 + push %1 12 + %endrep 13 + %rotate ct 14 + push esp ; it's our responsibility to preserve the stack 15 + call %1 16 + ; the arguments are still on the stack; time to 17 + ; dump them back into the Garbage Zone 18 + pop esp 19 +%endmacro
Added arch/x86.cdecl.64.s version [f85b8be23e].
1 +;; x86.cdecl.64.s: x86-64 cdecl impl 2 +; vim: ft=nasm 3 + 4 +%macro ccall 1-* 5 + %if %0 > ccall.reg.ct 6 + %assign ct ccall.reg.ct 7 + %else 8 + %assign ct %0-1 9 + %endif 10 + %assign i 0 11 + %rotate 1 12 + %rep ct 13 + ; if the function is well-behaved, all its arguments fit 14 + ; in registers. if not, things get ugly. see below. 15 + mov ccall.reg. %+ i, %1 16 + %assign i i+1 17 + %rotate 1 18 + %endrep 19 + %if %0 > ccall.reg.ct 20 + ; if there are more parameters to a C function than the 21 + ; number of permitted registers, they must be pushed in 22 + ; reverse order to the stack. 23 + ; keep your function signatures under control, people. 24 + %assign ct (%0-ct)-1 25 + %rotate ct 26 + %rep ct 27 + %rotate -1 28 + push %1 29 + %endrep 30 + %rotate ct 31 + push rsp ; it's our responsibility to preserve the stack 32 + %endif 33 + call %1 34 + %if %0 > ccall.reg.ct 35 + ; the extra arguments are still on the stack; time to 36 + ; dump them back into the Garbage Zone 37 + pop rsp 38 + %endif 39 +%endmacro 40 + 41 +; register order for ccall convention 42 +%define ccall.reg.ct 6 43 +%define ccall.reg.ret rdi 44 +%define ccall.reg.0 rdi 45 +%define ccall.reg.1 rsi 46 +%define ccall.reg.2 rdx 47 +%define ccall.reg.3 rcx 48 +%define ccall.reg.4 r8 49 +%define ccall.reg.5 r9
Added arch/x86.fbsd.32.s version [a34cfac886].
1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall numbers - syscall table must be created first! 5 +%include "calls.x86.fbsd.32.s" 6 + 7 +; extremely stupid freebsd-ism: expects the syscall to 8 +; come from a function 9 +_syscall: int 0x80 10 + ret 11 + 12 +%define sys.call call _syscall 13 + 14 +; parameters are passed on the stack 15 +%macro syscall 1-* 16 + mov eax, %1 17 + %rep %0-1 18 + %rotate 1 19 + push %1 20 + %endrep 21 + sys.call 22 + add esp, 4*(%0-1) 23 +%endmacro
Added arch/x86.fbsd.64.s version [ef3e7f83e4].
1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall numbers - syscall table must be created first! 5 +%include "calls.x86.fbsd.64.s" 6 + 7 +; freebsd uses the common x86-64 ABI 8 +%include "x86.syscall.64.s"
Added arch/x86.syscall.64.s version [43eb022a86].
1 +;; x86.64.s: common x86-64 ABI impl 2 +; vim: ft=nasm 3 + 4 +%macro sys 1-8 5 +; syscall64 wrapper, ex. `sys sys.write, 1, msg, msg.len` 6 + %assign i 0 7 + %rep %0 8 + mov sys.reg. %+ i, %1 ; i'm actually shocked this worked 9 + %rotate 1 10 + %assign i i+1 11 + %endrep 12 + syscall 13 +%endmacro 14 + 15 +%macro sys.prep 1-8 16 + ; for when we need to modify parameters before we 17 + ; make the actual call. 18 + %assign i 0 19 + %rep %0 20 + mov sys.reg. %+ i, %1 21 + %rotate 1 22 + %assign i i+1 23 + %endrep 24 +%endmacro 25 + 26 +; syscall ops 27 +%define sys.call syscall 28 + 29 +; register order for syscall convention 30 +%define sys.reg.n 7 31 +%define sys.reg.ret rax 32 +%define sys.reg.0 rax 33 +%define sys.reg.1 rdi 34 +%define sys.reg.2 rsi 35 +%define sys.reg.3 rdx 36 +%define sys.reg.4 r10 37 +%define sys.reg.5 r8 38 +%define sys.reg.6 r9 39 +
Added kcli/makefile version [f0df06fe05].
1 +include ../modmake
Added kcore/boot.x86.lin.64.s version [2671a43f32].
1 +; vim: ft=nasm 2 +bits 64 3 +%include "../arch/x86.lin.64.s" 4 +global _start:function 5 +extern _boot 6 +extern entry; 7 + 8 +_start: 9 + mov rbp, rsp 10 + mov rdi, [rbp + 0] ; argc 11 + lea rsi, [rbp + 8] ; argv 12 + 13 + call _boot 14 + 15 + mov sys.reg.1, sys.reg.ret 16 + mov sys.reg.0, sys.exit 17 + sys.call
Added kcore/def.fbsd.i version [4373f0187e].
1 +#define KVos fbsd 2 +typedef unsigned char stat;
Added kcore/def.lin.i version [0178d496a4].
1 +#define KVos lin 2 +typedef unsigned char stat;
Deleted kcore/start.x86.lin.64.s version [fc26b36617].
1 -; vim: ft=nasm 2 -bits 64 3 -%include "../arch/x86.lin.64.s" 4 -global _start 5 -extern _boot 6 -extern entry; 7 - 8 -_start: 9 - mov rbp, rsp 10 - mov rdi, [rbp + 0] ; argc 11 - lea rsi, [rbp + 8] ; argv 12 - 13 - call _boot; 14 - 15 - mov sys.reg.1, sys.reg.ret 16 - mov sys.reg.0, sys.exit 17 - sys.call
Added kcore/type.x86.32.i version [fe891b76db].
1 +#define KVarch x86 2 +#define KVbits 32 3 + 4 +typedef unsigned long sz; 5 + 6 +typedef unsigned char u8; 7 +typedef signed char s8; 8 +typedef unsigned short u16; 9 +typedef signed short s16; 10 +typedef unsigned long u32; 11 +typedef signed long s32; 12 + 13 +typedef u32 word; 14 +typedef s32 sword;
Added kcore/type.x86.64.i version [03a8b8f372].
1 +#define KVarch x86 2 +#define KVbits 64 3 + 4 +typedef unsigned long long sz; 5 + 6 +typedef unsigned char u8; 7 +typedef signed char s8; 8 +typedef unsigned short u16; 9 +typedef signed short s16; 10 +typedef unsigned long u32; 11 +typedef signed long s32; 12 +typedef unsigned long long u64; 13 +typedef signed long long s64; 14 +typedef __uint128_t u128; 15 +typedef __int128_t s128; 16 + 17 +typedef u64 word; 18 +typedef s64 sword;
Added kio/kiostream.posix.i version [0c9356948c].
1 +int platform_fd; // using posix syscalls for low-level IO
Modified makefile from [2300652a5e] to [216e76c37d].
20 20 endif 21 21 22 22 # include libgcc.a in gcc builds, just in case 23 23 ifeq ($(CC),gcc) 24 24 export COMPLIB = -lgcc 25 25 endif 26 26 27 -all: defs obj tool 27 +all: defs obj tool lib.static lib.shared 28 +lib.static: defs obj $(OUT)/libk.a 29 +lib.shared: defs obj $(OUT)/libk.so 28 30 obj: $(moddirs:%=%.obj) 29 31 defs: $(moddirs:%=%.def) 30 32 tool: $(OUT)/libk.a $(binmods:%=%.tool) 31 33 clean: 32 34 rm -rf $(TMP) $(OUT) 33 35 34 36 lists = moddirs objects binaries binmods POSIX ................................................................................ 46 48 47 49 %.def: %/makefile $(OUT) $(OUT)/k 48 50 cd $* && $(MAKE) def 49 51 50 52 %.calls: arch/makefile 51 53 cd arch && $(MAKE) $(TMP)/calls.$*.s 52 54 53 -$(OUT)/libk.so: obj $(OUT) 54 - $(CC) -shared -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o 55 +$(OUT)/libk.so: obj $(OUT) $(OUT)/boot.o 56 + ld -shared $(COMPLIB) -o $@ $(filter-out kcore.boot.%, $(wildcard *.o)) 57 + # $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o 58 + 59 +$(OUT)/boot.o: $(OUT)/kcore.boot.o $(OUT)/kcore.boot.$(TARGET).o 60 + ld -r $^ -o $(OUT)/boot.o 55 61 56 62 $(OUT)/libk.a: obj $(OUT) 57 63 # using `ar rc` and ranlib here instead of 58 64 # `ar rcs` in case `ar` isn't the GNU version 59 65 ar rc $@ $(OUT)/*.o 60 66 ranlib $@ 61 67 62 68 $(OUT) $(OUT)/k: 63 69 mkdir -p $@
Modified modmake from [adae292a57] to [86d81e4675].
9 9 headers = $(wildcard *.h) $(gen-headers) 10 10 11 11 tools = $(filter exe.%.c, $(src)) 12 12 nontools = $(filter-out exe.%.c, $(src)) 13 13 cobjects = $(filter %.c, $(nontools)) 14 14 sobjects = $(filter %.${TARGET}.s, $(nontools)) 15 15 16 -cflags = -isystem ${OUT} -nostdlib ${COMPLIB} -L${OUT} -lk 16 +cflags = -isystem ${OUT} -fPIC -nostdlib ${COMPLIB} -L${OUT} -lk 17 17 18 18 obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \ 19 19 $(sobjects:%.s=${OUT}/$(mod).%.o) 20 20 tool: $(tools:exe.%.c=${OUT}/$(mod).%) \ 21 21 ${OUT}/libk.a 22 22 23 23 def: $(headers:%=${OUT}/k/%)