File tree 23 files changed +218
-571
lines changed
23 files changed +218
-571
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ BINDIR = $(PREFIX)/bin
5
5
# variables used during build
6
6
PLATFORM = openbsd
7
7
ARCH = x86_64
8
- HARECFLAGS =
8
+ HARECFLAGS = -N "" -m .main
9
9
QBEFLAGS =
10
10
ASFLAGS =
11
11
LDLINKFLAGS = -z nobtcfi
@@ -18,7 +18,7 @@ LIBS = -lm
18
18
CC = cc
19
19
# OpenBSD: gas is in the binutils package. as from the base system is too old.
20
20
AS = gas
21
- LD = ld
21
+ LD = cc
22
22
QBE = qbe
23
23
24
24
# build locations
Original file line number Diff line number Diff line change 1
1
RTSCRIPT = rt/hare.sc
2
2
3
- _rt_ha = rt/+$(PLATFORM ) /syscallno.ha
3
+ _rt_ha = \
4
+ rt/malloc.ha \
5
+ rt/+$(PLATFORM ) /syscallno.ha \
6
+ rt/+$(PLATFORM ) /segmalloc.ha
7
+
8
+ _rt_s = \
9
+ rt/+$(PLATFORM ) /start+$(ARCH ) .s \
10
+ rt/+$(PLATFORM ) /syscall+$(ARCH ) .s
Original file line number Diff line number Diff line change 1
1
RTSCRIPT = rt/hare.sc
2
2
3
- _rt_ha = rt/+$(PLATFORM ) /syscallno+$(ARCH ) .ha
3
+ _rt_ha = \
4
+ rt/malloc.ha \
5
+ rt/+$(PLATFORM ) /syscallno+$(ARCH ) .ha \
6
+ rt/+$(PLATFORM ) /segmalloc.ha
7
+
8
+ _rt_s = \
9
+ rt/+$(PLATFORM ) /start+$(ARCH ) .s \
10
+ rt/+$(PLATFORM ) /syscall+$(ARCH ) .s
Original file line number Diff line number Diff line change 1
1
RTSCRIPT = rt/hare+$(PLATFORM ) .sc
2
2
3
- _rt_ha = rt/+$(PLATFORM ) /syscallno.ha
3
+ _rt_ha = \
4
+ rt/malloc.ha \
5
+ rt/+$(PLATFORM ) /syscallno.ha \
6
+ rt/+$(PLATFORM ) /segmalloc.ha
7
+
8
+ _rt_s = \
9
+ rt/+$(PLATFORM ) /start+$(ARCH ) .s \
10
+ rt/+$(PLATFORM ) /syscall+$(ARCH ) .s
Original file line number Diff line number Diff line change 1
1
RTSCRIPT = rt/hare+$(PLATFORM ) .sc
2
2
3
- _rt_ha = rt/+$(PLATFORM ) /syscallno.ha
3
+ _rt_ha = \
4
+ rt/malloc+libc.ha
5
+
6
+ _rt_s = \
7
+ rt/+openbsd/platformstart.s
Original file line number Diff line number Diff line change @@ -24,23 +24,21 @@ rt_ha = \
24
24
rt/compile.ha \
25
25
rt/cstrings.ha \
26
26
rt/ensure.ha \
27
- rt/malloc.ha \
28
27
rt/memcpy.ha \
29
28
rt/memmove.ha \
30
29
rt/memset.ha \
31
- rt/rtmain.ha \
32
30
rt/strcmp.ha \
33
31
rt/+$(PLATFORM ) /errno.ha \
34
- rt/+$(PLATFORM ) /segmalloc.ha \
35
32
rt/+$(PLATFORM ) /syscalls.ha \
33
+ rt/+$(PLATFORM ) /start.ha \
36
34
$(_rt_ha )
37
35
38
36
$(HARECACHE ) /rt.ssa : $(rt_ha )
39
37
@mkdir -p -- $(HARECACHE )
40
38
@printf ' HAREC\t%s\n' ' $@'
41
39
@$(TDENV ) $(BINOUT ) /harec $(HARECFLAGS ) -o $@ -t $(HARECACHE ) /rt.td.tmp -N rt $(rt_ha )
42
40
43
- rt_s = $(HARECACHE ) /rt.s rt/+ $( PLATFORM ) /start+ $( ARCH ) .s rt/+ $( PLATFORM ) /syscall+ $( ARCH ) .s
41
+ rt_s = $(HARECACHE ) /rt.s $( _rt_s )
44
42
$(HARECACHE ) /rt.o : $(rt_s )
45
43
@printf ' AS\t%s\n' ' $@'
46
44
@$(AS ) $(ASFLAGS ) -o $@ $(rt_s )
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ @symbol("main") fn main() void;
2
+
3
+ const @symbol("__init_array_start") init_start: [*]*fn() void;
4
+ const @symbol("__init_array_end") init_end: [*]*fn() void;
5
+ const @symbol("__fini_array_start") fini_start: [*]*fn() void;
6
+ const @symbol("__fini_array_end") fini_end: [*]*fn() void;
7
+
8
+ let argc: size = 0;
9
+ let argv: *[*]*const u8 = null: *[*]*const u8;
10
+ let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
11
+
12
+ export let status = 0;
13
+
14
+ export fn start_ha(iv: *[*]uintptr) never = {
15
+ const ninit = (&init_end: uintptr - &init_start: uintptr): size
16
+ / size(*fn() void);
17
+ for (let i = 0z; i < ninit; i += 1) {
18
+ init_start[i]();
19
+ };
20
+
21
+ argc = iv[0]: size;
22
+ argv = &iv[1]: *[*]*const u8;
23
+ envp = &argv[argc + 1]: *[*]nullable *const u8;
24
+
25
+ main();
26
+
27
+ const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
28
+ / size(*fn() void);
29
+ for (let i = 0z; i < nfini; i += 1) {
30
+ fini_start[i]();
31
+ };
32
+
33
+ exit(status);
34
+ };
Original file line number Diff line number Diff line change
1
+ @symbol("main") fn main() void;
2
+
3
+ const @symbol("__init_array_start") init_start: [*]*fn() void;
4
+ const @symbol("__init_array_end") init_end: [*]*fn() void;
5
+ const @symbol("__fini_array_start") fini_start: [*]*fn() void;
6
+ const @symbol("__fini_array_end") fini_end: [*]*fn() void;
7
+
8
+ let argc: size = 0;
9
+ let argv: *[*]*const u8 = null: *[*]*const u8;
10
+ let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
11
+
12
+ export let status = 0;
13
+
14
+ export fn start_ha(iv: *[*]uintptr) never = {
15
+ const ninit = (&init_end: uintptr - &init_start: uintptr): size
16
+ / size(*fn() void);
17
+ for (let i = 0z; i < ninit; i += 1) {
18
+ init_start[i]();
19
+ };
20
+
21
+ argc = iv[0]: size;
22
+ argv = &iv[1]: *[*]*const u8;
23
+ envp = &argv[argc + 1]: *[*]nullable *const u8;
24
+
25
+ main();
26
+
27
+ const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
28
+ / size(*fn() void);
29
+ for (let i = 0z; i < nfini; i += 1) {
30
+ fini_start[i]();
31
+ };
32
+
33
+ exit(status);
34
+ };
Original file line number Diff line number Diff line change
1
+ .section ".preinit_array"
2
+ .balign 8
3
+ .init.initfunc.0:
4
+ .quad preinit_hare+0
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ // (c) Hare authors <https://harelang.org>
3
+
4
+ let argc: size = 0;
5
+ let argv: *[*]*const u8 = null: *[*]*const u8;
6
+ let envp: *[*]nullable *const u8 = null: *[*]nullable *const u8;
7
+
8
+ export let status = 0;
9
+
10
+ // The real main function.
11
+ @symbol(".main") fn main() void;
12
+
13
+ // The setup of envp and args is done here. This is called by crt0 before
14
+ // normal init functions are called.
15
+ export @symbol("preinit_hare") fn preinit_hare(
16
+ c_argc: int,
17
+ c_argv: *[*]*const u8,
18
+ c_envp: *[*]nullable *const u8
19
+ ) void = {
20
+ argc = c_argc: size;
21
+ argv = c_argv;
22
+ envp = c_envp;
23
+ };
24
+
25
+ // The purpose of this "fake" main function is to make sure we exit with the
26
+ // correct exit code in the case that rt::exit() is not called from within the
27
+ // program. The intilization and finilization functions are not run from here,
28
+ // they are ran by crt0.
29
+ export @symbol("main") fn _main() void = {
30
+ main();
31
+ exit(status);
32
+ };
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments