libk  Check-in [860229e8ce]

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: 860229e8ce1a86fe94865aec6da863e39052cdb4bdbbdcfefcfed79edb44586b
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
2
3
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.;" > $@

Modified arch/x86.lin.32.s from [7c5909e17f] to [fed93e863f].


1
2
3

4
5
6
7
8
9

10
11
12
13
14
15
16










17
18
19
20
21
22

; 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


%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











%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
>

<
<
>
|
|
<
<
<

>







>
>
>
>
>
>
>
>
>
>






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
;; abi definition file for x86 linux 32-bit
; vim: ft=nasm



; 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

Modified arch/x86.lin.64.s from [fcbc285104] to [1f6b1a0933].

1
2
3

4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
..
26
27
28
29
30
31
32

33
34
35
36
37
38
39
;; abi definition file
;; macros:
;; * sys: syscall64 wrapper

;; * ccall: automatically generate code to call a C function
;;          with any number of arguments

; 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.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
................................................................................
%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

%macro sys 1-8

	%assign i 0
	%rep %0
		mov sys.reg. %+ i, %1 ; i'm actually shocked this worked
		%rotate 1
		%assign i i+1
	%endrep 
	syscall
|
|
<
>
|
|



<
<
<
<


>







 







>







1
2

3
4
5
6
7
8




9
10
11
12
13
14
15
16
17
18
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;; 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





; 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
%define sys.reg.5 r8
%define sys.reg.6 r9
................................................................................
%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

%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

Modified makefile from [e2aa0ec204] to [0ee3372ddd].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35



36
37
38
39
40
41
42
defs: $(headers)
tool: $(binmods:%=%.tool)

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)
	cd $* && $(MAKE) obj

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

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




$(OUT)/libk.so: mods $(OUT)
	$(CC) -shared -o $@ $(objects)

$(OUT)/libk.a: mods $(OUT)
	# using `ar c` and ranlib here instead of
	# `ar cs` in case `ar` isn't the GNU version
	ar c $@ $(objects)







|








>
>
>







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
defs: $(headers)
tool: $(binmods:%=%.tool)

lists = moddirs modules headers objects makefiles binaries binmods
dbg:
	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")

%.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
	# `ar cs` in case `ar` isn't the GNU version
	ar c $@ $(objects)