hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 71be4f501fc5211cf67c77232cc7c879ee5a3b2e
parent 31551552a14960196c6b540fa9e842f9dc5ed993
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date:   Thu, 18 Mar 2021 15:37:57 +0200

linux: new module for linux-specific stuff

Utility methods for getting auxv come first

Diffstat:
Mgen-stdlib | 17+++++++++++++++++
Alinux/env.ha | 4++++
Alinux/start.ha | 10++++++++++
Mstdlib.mk | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/gen-stdlib b/gen-stdlib @@ -340,6 +340,21 @@ io() { gen_ssa io strings } +linux() { + printf '# linux\n' + gen_srcs linux \ + start.ha \ + env.ha + gen_ssa linux format::elf +} + +linux_vdso() { + printf '# linux::vdso\n' + gen_srcs linux::vdso \ + vdso.ha + gen_ssa linux::vdso linux strings format::elf +} + math_random() { printf '# math::random\n' gen_srcs math::random \ @@ -507,6 +522,8 @@ hare_parse hash hash_fnv io +linux +linux_vdso math_random os os_exec diff --git a/linux/env.ha b/linux/env.ha @@ -0,0 +1,4 @@ +use format::elf; + +// System V auxillary vector for the current process +export let auxv: *[*]format::elf::auxv64 = null: *[*]format::elf::auxv64; diff --git a/linux/start.ha b/linux/start.ha @@ -0,0 +1,10 @@ +use rt; +use format::elf; + +@init fn init_linux() void = { + let i = 0; + for (rt::envp[i] != null) { + i += 1; + }; + auxv = &rt::envp[i + 1]: *[*]elf::auxv64; +}; diff --git a/stdlib.mk b/stdlib.mk @@ -134,6 +134,12 @@ hare_stdlib_deps+=$(stdlib_hash_fnv) stdlib_io=$(HARECACHE)/io/io.o hare_stdlib_deps+=$(stdlib_io) +stdlib_linux=$(HARECACHE)/linux/linux.o +hare_stdlib_deps+=$(stdlib_linux) + +stdlib_linux_vdso=$(HARECACHE)/linux/vdso/linux_vdso.o +hare_stdlib_deps+=$(stdlib_linux_vdso) + stdlib_math_random=$(HARECACHE)/math/random/math_random.o hare_stdlib_deps+=$(stdlib_math_random) @@ -420,6 +426,27 @@ $(HARECACHE)/io/io.ssa: $(stdlib_io_srcs) $(stdlib_rt) $(stdlib_strings) @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nio \ -t$(HARECACHE)/io/io.td $(stdlib_io_srcs) +# linux +stdlib_linux_srcs= \ + $(STDLIB)/linux/start.ha \ + $(STDLIB)/linux/env.ha + +$(HARECACHE)/linux/linux.ssa: $(stdlib_linux_srcs) $(stdlib_rt) $(stdlib_format_elf) + @printf 'HAREC \t$@\n' + @mkdir -p $(HARECACHE)/linux + @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux \ + -t$(HARECACHE)/linux/linux.td $(stdlib_linux_srcs) + +# linux::vdso +stdlib_linux_vdso_srcs= \ + $(STDLIB)/linux/vdso/vdso.ha + +$(HARECACHE)/linux/vdso/linux_vdso.ssa: $(stdlib_linux_vdso_srcs) $(stdlib_rt) $(stdlib_linux) $(stdlib_strings) $(stdlib_format_elf) + @printf 'HAREC \t$@\n' + @mkdir -p $(HARECACHE)/linux/vdso + @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux::vdso \ + -t$(HARECACHE)/linux/vdso/linux_vdso.td $(stdlib_linux_vdso_srcs) + # math::random stdlib_math_random_srcs= \ $(STDLIB)/math/random/random.ha @@ -712,6 +739,12 @@ hare_testlib_deps+=$(testlib_hash_fnv) testlib_io=$(TESTCACHE)/io/io.o hare_testlib_deps+=$(testlib_io) +testlib_linux=$(TESTCACHE)/linux/linux.o +hare_testlib_deps+=$(testlib_linux) + +testlib_linux_vdso=$(TESTCACHE)/linux/vdso/linux_vdso.o +hare_testlib_deps+=$(testlib_linux_vdso) + testlib_math_random=$(TESTCACHE)/math/random/math_random.o hare_testlib_deps+=$(testlib_math_random) @@ -1006,6 +1039,27 @@ $(TESTCACHE)/io/io.ssa: $(testlib_io_srcs) $(testlib_rt) $(testlib_strings) @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nio \ -t$(TESTCACHE)/io/io.td $(testlib_io_srcs) +# linux +testlib_linux_srcs= \ + $(STDLIB)/linux/start.ha \ + $(STDLIB)/linux/env.ha + +$(TESTCACHE)/linux/linux.ssa: $(testlib_linux_srcs) $(testlib_rt) $(testlib_format_elf) + @printf 'HAREC \t$@\n' + @mkdir -p $(TESTCACHE)/linux + @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux \ + -t$(TESTCACHE)/linux/linux.td $(testlib_linux_srcs) + +# linux::vdso +testlib_linux_vdso_srcs= \ + $(STDLIB)/linux/vdso/vdso.ha + +$(TESTCACHE)/linux/vdso/linux_vdso.ssa: $(testlib_linux_vdso_srcs) $(testlib_rt) $(testlib_linux) $(testlib_strings) $(testlib_format_elf) + @printf 'HAREC \t$@\n' + @mkdir -p $(TESTCACHE)/linux/vdso + @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux::vdso \ + -t$(TESTCACHE)/linux/vdso/linux_vdso.td $(testlib_linux_vdso_srcs) + # math::random testlib_math_random_srcs= \ $(STDLIB)/math/random/random.ha