@@ -22,9 +22,11 @@ ; 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. + ; but we pass it just in case. it is + ; also used for finding the environment + ; below. lea rsi, [rsp + 8] ; &arguments ; 2nd argument to _boot(): ptr to argv ; this points to an array of strings @@ -31,16 +33,22 @@ ; 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() + ; this exists on the stack, right above + ; argc - lea rdx, [rsp + 16] ; &environment + lea rdx, [rsp + rdi * 8 + 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. + ; legible and useful C arrays. it exists + ; above the argument list, the math is + ; stack pointer + argc*pointers(8 bytes) + ; + 16 bytes (argc itself and the + ; terminating null from argv) mov rax, 0 ; zero out %rax ; this is required by the C ABI, and is ; reputedly necessary for compatibility