commit e3c3a235545a110fe16bbd7d3667f3caf8d341d0
parent e802818a169a18c36ec36d084c20d195ed66c3e0
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 4 Feb 2021 12:09:39 -0500
rt: split start_linux and start_ha
Diffstat:
3 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/rt/+linux/start.ha b/rt/+linux/start.ha
@@ -1,29 +1,7 @@
-@symbol("main") fn main() void;
-
-const @symbol("__init_array_start") init_start: [*]*fn() void;
-const @symbol("__init_array_end") init_end: [*]*fn() void;
-const @symbol("__fini_array_start") fini_start: [*]*fn() void;
-const @symbol("__fini_array_end") fini_end: [*]*fn() void;
-
-export fn start_ha(iv: *[*]uintptr) void = {
+export fn start_linux(iv: *[*]uintptr) void = {
// TODO: Find & parse auxv
argc = iv[0z]: size;
argv = &iv[1z]: *[*]*char;
envp = &iv[1z + argc * size(*char) + 1z]: *[*]nullable *char;
-
- const ninit = (&init_end: uintptr - &init_start: uintptr): size
- / size(*fn() void);
- for (let i = 0z; i < ninit; i += 1z) {
- init_start[i]();
- };
-
- main();
-
- const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
- / size(*fn() void);
- for (let i = 0z; i < nfini; i += 1z) {
- fini_start[i]();
- };
-
- exit(0);
+ start_ha();
};
diff --git a/rt/+linux/start.s b/rt/+linux/start.s
@@ -3,4 +3,4 @@
_start:
xor %rbp, %rbp
movq %rsp, %rdi
- call rt.start_ha
+ call rt.start_linux
diff --git a/rt/start.ha b/rt/start.ha
@@ -0,0 +1,24 @@
+@symbol("main") fn main() void;
+
+const @symbol("__init_array_start") init_start: [*]*fn() void;
+const @symbol("__init_array_end") init_end: [*]*fn() void;
+const @symbol("__fini_array_start") fini_start: [*]*fn() void;
+const @symbol("__fini_array_end") fini_end: [*]*fn() void;
+
+export fn start_ha() void = {
+ const ninit = (&init_end: uintptr - &init_start: uintptr): size
+ / size(*fn() void);
+ for (let i = 0z; i < ninit; i += 1z) {
+ init_start[i]();
+ };
+
+ main();
+
+ const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
+ / size(*fn() void);
+ for (let i = 0z; i < nfini; i += 1z) {
+ fini_start[i]();
+ };
+
+ exit(0);
+};