1
0
mirror of https://github.com/DoctorWkt/unix-jun72.git synced 2026-01-11 23:53:34 +00:00

- some helpers for building userland code. Very hacky at the moment but

should work until something better comes along.
This commit is contained in:
tim.newsham 2008-05-04 22:20:08 +00:00
parent 3d86f87e10
commit c0adf32ada
2 changed files with 52 additions and 0 deletions

11
tools/as Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
#
# use the v7 assembler to assemble some userland code into an 0405 binary.
# Requires the first .s file to set ". = . + 40014".
#
. tools/assemv7.cfg
export APOUT_ROOT
$APOUT $APOUT_ROOT/bin/as "$@" && tools/fixaout.py

41
tools/fixaout.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
"""
Convert an 0407 binary into an 0405 binary, under the assumption
that the code starts at 040014 (by ". = . + 40014").
See tools/as.
"""
import struct
def words(bs) :
l = len(bs) / 2
return list(struct.unpack('<%dH' % l, bs))
def unwords(ws) :
l = len(ws)
return struct.pack('<%dH' % l, *ws)
def read(fn) :
f = file(fn, 'rb')
d = f.read()
f.close()
return d
def write(fn, d) :
f = file(fn, 'wb')
f.write(d)
f.close()
orig = 040000
d = words(read('a.out'))
hdr = d[:8]
d = d[8 + orig/2 :]
d[0] = 0405
d[1] = hdr[1] - orig
d[2] = 0
d[3] = 0
d[4] = hdr[4]
d[5] = 0
d = d[:d[1] / 2]
write("b.out", unwords(d))