summaryrefslogtreecommitdiff
path: root/aout.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-27 21:12:55 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-27 21:12:55 -0700
commit189e00e249009aba59fa963ef2cd0f2dac832129 (patch)
tree8f281222101d99eee58f62d9ed4c8fa31422db87 /aout.myr
parent2eb61ae0040a66043b41863c2348fdacd37cc091 (diff)
downloadlnk-189e00e249009aba59fa963ef2cd0f2dac832129.tar.gz
Implement Plan 9 a.out
Diffstat (limited to 'aout.myr')
-rw-r--r--aout.myr31
1 files changed, 31 insertions, 0 deletions
diff --git a/aout.myr b/aout.myr
index 8288a45..579f47b 100644
--- a/aout.myr
+++ b/aout.myr
@@ -1,4 +1,5 @@
use std
+use bio
use "types"
@@ -7,5 +8,35 @@ pkg =
;;
const emitaout = {lnk
+ match bio.create(lnk.outf, bio.Wr, 0o755)
+ | `std.Err e:
+ std.fatal("could not open output: {}\n", e)
+ | `std.Ok f:
+ w32(f, magic(26))
+ w32(f, lnk.text.len)
+ w32(f, lnk.data.len)
+ w32(f, (lnk.bss : uint32))
+ w32(f, 0) /* syms */
+ w32(f, (lnk.entry : uint32))
+ w32(f, 0) /* pc/sp offset tab */
+ w32(f, 0) /* pc/lnum tab */
+ wstr(f, lnk.text)
+ wstr(f, lnk.data)
+ bio.close(f)
+ ;;
}
+const magic = {arch
+ -> 0x00008000 | 4*arch*arch+7
+}
+
+const wstr = {f, s; check(bio.write(f, s))}
+const w32 = {f, v : uint32; check(bio.putbe32(f, v))}
+
+generic check = {st : bio.status(@a)
+ match st
+ | `bio.Ok _: /* nothing */
+ | `bio.Err e: std.fatal("i/o error: {}\n", e)
+ | `bio.Eof: std.fatal("i/o error: eof\n")
+ ;;
+}