libk  Check-in [ec9b2b74b3]

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: ec9b2b74b3c79d6fc96a8e827b3bc7bd8ba7a8dcc387e7bcd2f6964b7c08c356
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
;; x86.cdecl.32.s: x86 cdecl impl
; vim: ft=nasm

%macro ccall 1-*
	%assign i 0
	; arguments must be pushed to the stack backwards
	%assign ct (%0-ct)-1
	%rotate ct
	%rep ct
		%rotate -1
		push %1
	%endrep
	%rotate ct
	push esp ; it's our responsibility to preserve the stack
	call %1
	; the arguments are still on the stack; time to
	; dump them back into the Garbage Zone
	pop esp
%endmacro

Added arch/x86.cdecl.64.s version [f85b8be23e].



































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;; x86.cdecl.64.s: x86-64 cdecl impl
; vim: ft=nasm

%macro ccall 1-*
	%if %0 > ccall.reg.ct
		%assign ct ccall.reg.ct
	%else
		%assign ct %0-1
	%endif
	%assign i 0
	%rotate 1
	%rep ct
		; if the function is well-behaved, all its arguments fit
		; in registers. if not, things get ugly. see below.
		mov ccall.reg. %+ i, %1
		%assign i i+1
		%rotate 1
	%endrep
	%if %0 > ccall.reg.ct
		; if there are more parameters to a C function than the
		; number of permitted registers, they must be pushed in
		; reverse order to the stack.
		; keep your function signatures under control, people.
		%assign ct (%0-ct)-1
		%rotate ct
		%rep ct
			%rotate -1
			push %1
		%endrep
		%rotate ct
		push rsp ; it's our responsibility to preserve the stack
	%endif
	call %1
	%if %0 > ccall.reg.ct
		; the extra arguments are still on the stack; time to
		; dump them back into the Garbage Zone
		pop rsp
	%endif
%endmacro

; register order for ccall convention
%define ccall.reg.ct 6
%define ccall.reg.ret rdi
%define ccall.reg.0 rdi
%define ccall.reg.1 rsi
%define ccall.reg.2 rdx
%define ccall.reg.3 rcx
%define ccall.reg.4 r8
%define ccall.reg.5 r9

Added arch/x86.fbsd.32.s version [a34cfac886].















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "calls.x86.fbsd.32.s"

; extremely stupid freebsd-ism: expects the syscall to
; come from a function
_syscall: int 0x80
          ret

%define sys.call call _syscall

; parameters are passed on the stack
%macro syscall 1-*
	mov eax, %1
	%rep %0-1
		%rotate 1
		push %1
	%endrep
	sys.call
	add esp, 4*(%0-1)
%endmacro

Added arch/x86.fbsd.64.s version [ef3e7f83e4].

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "calls.x86.fbsd.64.s"

; freebsd uses the common x86-64 ABI
%include "x86.syscall.64.s"

Added arch/x86.syscall.64.s version [43eb022a86].















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;; x86.64.s: common x86-64 ABI impl
; vim: ft=nasm

%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
	%endrep 
	syscall
%endmacro

%macro sys.prep 1-8
	; for when we need to modify parameters before we
	; make the actual call.
	%assign i 0
	%rep %0
		mov sys.reg. %+ i, %1
		%rotate 1
		%assign i i+1
	%endrep
%endmacro

; syscall ops
%define sys.call syscall

; register order for syscall convention
%define sys.reg.n 7
%define sys.reg.ret rax
%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
%define sys.reg.5 r8
%define sys.reg.6 r9

Added kcli/makefile version [f0df06fe05].



>
1
include ../modmake

Added kcore/boot.x86.lin.64.s version [2671a43f32].



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; vim: ft=nasm
bits 64
%include "../arch/x86.lin.64.s"
global _start:function
extern _boot
extern entry;

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc
	lea rsi, [rbp + 8] ; argv

	call _boot

	mov sys.reg.1, sys.reg.ret
	mov sys.reg.0, sys.exit
	sys.call

Added kcore/def.fbsd.i version [4373f0187e].





>
>
1
2
#define KVos fbsd
typedef unsigned char stat;

Added kcore/def.lin.i version [0178d496a4].





>
>
1
2
#define KVos lin
typedef unsigned char stat;

Deleted kcore/start.x86.lin.64.s version [fc26b36617].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; vim: ft=nasm
bits 64
%include "../arch/x86.lin.64.s"
global _start
extern _boot
extern entry;

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc
	lea rsi, [rbp + 8] ; argv

	call _boot;

	mov sys.reg.1, sys.reg.ret
	mov sys.reg.0, sys.exit
	sys.call
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


































Added kcore/type.x86.32.i version [fe891b76db].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define KVarch x86
#define KVbits 32

typedef unsigned long sz;

typedef unsigned char  u8;
typedef signed char    s8;
typedef unsigned short u16;
typedef signed short   s16;
typedef unsigned long  u32;
typedef signed long    s32;

typedef u32  word;
typedef s32 sword;

Added kcore/type.x86.64.i version [03a8b8f372].





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#define KVarch x86
#define KVbits 64

typedef unsigned long long sz;

typedef unsigned char      u8;
typedef signed char        s8;
typedef unsigned short     u16;
typedef signed short       s16;
typedef unsigned long      u32;
typedef signed long        s32;
typedef unsigned long long u64;
typedef signed long long   s64;
typedef __uint128_t        u128;
typedef __int128_t         s128;

typedef u64  word;
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
21
22
23
24
25
26
27


28
29
30
31
32
33
34
..
46
47
48
49
50
51
52
53

54



55
56
57
58
59
60
61
62
63
endif

# include libgcc.a in gcc builds, just in case
ifeq ($(CC),gcc)
export COMPLIB = -lgcc
endif

all: defs obj tool


obj: $(moddirs:%=%.obj)
defs: $(moddirs:%=%.def)
tool: $(OUT)/libk.a $(binmods:%=%.tool) 
clean:
	rm -rf $(TMP) $(OUT)

lists = moddirs objects binaries binmods POSIX
................................................................................

%.def: %/makefile $(OUT) $(OUT)/k
	cd $* && $(MAKE) def

%.calls: arch/makefile
	cd arch && $(MAKE) $(TMP)/calls.$*.s

$(OUT)/libk.so: obj $(OUT)

	$(CC) -shared -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o




$(OUT)/libk.a: obj $(OUT)
	# using `ar rc` and ranlib here instead of
	# `ar rcs` in case `ar` isn't the GNU version
	ar rc $@ $(OUT)/*.o
	ranlib $@

$(OUT) $(OUT)/k:
	mkdir -p $@







|
>
>







 







|
>
|
>
>
>









20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
endif

# include libgcc.a in gcc builds, just in case
ifeq ($(CC),gcc)
export COMPLIB = -lgcc
endif

all: defs obj tool lib.static lib.shared
lib.static: defs obj $(OUT)/libk.a
lib.shared: defs obj $(OUT)/libk.so
obj: $(moddirs:%=%.obj)
defs: $(moddirs:%=%.def)
tool: $(OUT)/libk.a $(binmods:%=%.tool) 
clean:
	rm -rf $(TMP) $(OUT)

lists = moddirs objects binaries binmods POSIX
................................................................................

%.def: %/makefile $(OUT) $(OUT)/k
	cd $* && $(MAKE) def

%.calls: arch/makefile
	cd arch && $(MAKE) $(TMP)/calls.$*.s

$(OUT)/libk.so: obj $(OUT) $(OUT)/boot.o
	ld -shared $(COMPLIB) -o $@ $(filter-out kcore.boot.%, $(wildcard *.o))
	# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o

$(OUT)/boot.o: $(OUT)/kcore.boot.o $(OUT)/kcore.boot.$(TARGET).o
	ld -r $^ -o $(OUT)/boot.o

$(OUT)/libk.a: obj $(OUT)
	# using `ar rc` and ranlib here instead of
	# `ar rcs` in case `ar` isn't the GNU version
	ar rc $@ $(OUT)/*.o
	ranlib $@

$(OUT) $(OUT)/k:
	mkdir -p $@

Modified modmake from [adae292a57] to [86d81e4675].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
headers = $(wildcard *.h) $(gen-headers)

tools    = $(filter     exe.%.c,   $(src))
nontools = $(filter-out exe.%.c,   $(src))
cobjects = $(filter     %.c,       $(nontools))
sobjects = $(filter %.${TARGET}.s, $(nontools))

cflags = -isystem ${OUT} -nostdlib ${COMPLIB} -L${OUT} -lk

obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
	 $(sobjects:%.s=${OUT}/$(mod).%.o)
tool: $(tools:exe.%.c=${OUT}/$(mod).%) \
	  ${OUT}/libk.a

def: $(headers:%=${OUT}/k/%)







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
headers = $(wildcard *.h) $(gen-headers)

tools    = $(filter     exe.%.c,   $(src))
nontools = $(filter-out exe.%.c,   $(src))
cobjects = $(filter     %.c,       $(nontools))
sobjects = $(filter %.${TARGET}.s, $(nontools))

cflags = -isystem ${OUT} -fPIC -nostdlib ${COMPLIB} -L${OUT} -lk

obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
	 $(sobjects:%.s=${OUT}/$(mod).%.o)
tool: $(tools:exe.%.c=${OUT}/$(mod).%) \
	  ${OUT}/libk.a

def: $(headers:%=${OUT}/k/%)