Overview
Comment: | make crt behave as a C runtime launcher should; comment code thoroughly |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f0f16493caf8ef1de1c32504d868442c |
User & Date: | lexi on 2019-08-21 03:44:37 |
Original Comment: | make crt behave properly, hopefully fixing segfault on nixos; comment code thoroughly |
Other Links: | manifest | tags |
Context
2019-08-21
| ||
04:24 | modify build system to replace extremely fragile error code generation mechanism check-in: d77ef26adf user: lexi tags: trunk | |
03:44 | make crt behave as a C runtime launcher should; comment code thoroughly check-in: f0f16493ca user: lexi tags: trunk | |
03:10 | add assembly output flag to build.sh check-in: 06e32bd3b4 user: lexi tags: trunk | |
Changes
Modified kcore/boot.rt.c from [6007ea2ce5] to [a5bf4923b7].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <k/core.h> extern stat entry(kenv); stat _boot(unsigned int argc, char** argv) { kenv e = { // todo: determine terminal class and set term vs ansi correctly! { {kiostream_term, 0}, {kiostream_term, 1} }, // chan std { {kiostream_closed}, {kiostream_term, 2} }, // chan err argc, argv, null // no environment yet }; return entry(e); } |
> | > > | | | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <k/core.h> extern stat entry(kenv); unsigned long long _boot(unsigned int argc, /* argument count */ char** argv, /* arguments */ char** envp /* environment */ ) { kenv e = { /* TODO: determine terminal class and set term vs ansi correctly! */ { {kiostream_term, 0}, {kiostream_term, 1} }, // chan std { {kiostream_closed}, {kiostream_term, 2} }, // chan err argc, argv, null // needs parsing }; return entry(e); } |
Modified kcore/boot.rt.x86.lin.64.s from [c4c48f7422] to [3c036595d7].
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 |