2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
bits 64
%include "../arch/posix/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
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
|
|
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
bits 64
%include "../arch/posix/x86.lin.64.s"
global _start:function
extern _boot
extern entry
_start:
mov rbp, 0 ; zero the stack base ptr.
; attempted fix for a difficult-to-
; reproduce bug
mov rdi, 0 ; zero rdi - because argc
; is 32 bits long, we have to store
; its value in the lower half of rdi.
; this ensures that the upper half is
; zeroed as well.
mov edi, [rsp + 0] ; sizeof arguments
; first argument to _boot(): argc
; this is a 32-bit signed(??) integer
; that is equal to the number of
; elements in argv (see below). it is
; not strictly necessary, because argv
; is per spec always null-terminated,
; but we pass it just in case.
lea rsi, [rsp + 8] ; &arguments
; 2nd argument to _boot(): ptr to argv
; this points to an array of strings
; containing the program's command line
; arguments. _boot() does not need to
; parse this, but it does need to store
; it in the structure passed to main()
lea rdx, [rsp + 16] ; &environment
; third argument to _boot(): ptr to envp
; this points to the list of environment
; variables for the running program. it
; is the responsibility of _boot to parse
; this list and arrange it into a set of
; legible and useful C arrays.
mov rax, 0 ; zero out %rax
; this is required by the C ABI, and is
; reputedly necessary for compatibility
; with icc, intel's own proprietary C
; compiler.
call _boot ; invoke the start function
; that will set up the runtime and
; construct the necessary structures
; that will be bassed to libc.
; boot has returned and left its
; return value in the register %rax.
; regardless of the size of the
; return value of main(), _boot always
; returns the system word length.
mov sys.reg.1, sys.reg.ret ; fill in
; the return value as exit's argument
mov sys.reg.0, sys.exit ; set %rax to
; the syscall number of exit
sys.call ; invoke the kernel
|