libk  Diff

Differences From Artifact [c4c48f7422]:

To Artifact [3c036595d7]:


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