boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

start.S (601B)


      1 /* x86_64 _start: mirror P1/entry-libc.P1pp.
      2  *
      3  * On entry rsp points at [argc][argv0]…[NULL][envp0]…[NULL][auxv]. Convert
      4  * to (rdi=argc, rsi=argv) and run __libc_init(argc, argv) → main(argc, argv)
      5  * → exit(rc). If exit returns, spin.
      6  */
      7     .text
      8     .globl _start
      9 _start:
     10     movq    (%rsp), %r12          // argc (callee-saved r12)
     11     leaq    8(%rsp), %r13         // argv (callee-saved r13)
     12 
     13     movq    %r12, %rdi
     14     movq    %r13, %rsi
     15     call    __libc_init
     16 
     17     movq    %r12, %rdi
     18     movq    %r13, %rsi
     19     call    main
     20 
     21     movq    %rax, %rdi
     22     call    exit
     23 1:  jmp     1b