Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv3439
Modified Files:
linkie.py makehello.py
Log Message:
wrote Linkie.link
Index: linkie.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- linkie.py 9 Feb 2003 16:01:39 -0000 1.5
+++ linkie.py 14 Feb 2003 13:50:55 -0000 1.6
@@ -123,7 +123,9 @@
raise 'Duplicate label', label
this._locals[label] = len(this._binary) + this._skipped
# Resolve open references to that label, if any
- for i in range(len(this._unresolved_locals) - 1, -1, -1):
+ i = len(this._unresolved_locals)
+ while i > 0:
+ i = i - 1
referee, type, data = this._unresolved_locals[i]
if referee == label:
if type == -1:
@@ -136,13 +138,14 @@
raise "Can't happen: unknown local reference type", this
del this._unresolved_locals[i] # close the entry
def place_symbol (this, symbol, value = None):
- """place_symbol(symbol, value = None)
+ """place_symbol(symbol, value = None) => value
Places a globally visible symbol in the linkie.
Does NOT check uniqueness.
None signifies the current offset."""
if type(symbol) <> StringType: raise 'Not a string', symbol
if value == None: value = len(this._binary) + this._skipped
this._symbols.append((symbol, value))
+ return value
def align (this, boundary):
"""align(boundary)
Ensures that the following byte's memory address is divisible by
@@ -193,7 +196,6 @@
that._symbols = this._symbols[:]
that._linker_notes = this._linker_notes[:]
return that
-
def extend (this, that):
if this._unresolved_locals: raise 'Incomplete linkie', this
if that._unresolved_locals: raise 'Incomplete linkie', that
@@ -207,11 +209,23 @@
for ofs, typ, arg in that._linker_notes:
this._linker_notes.append((ofs + delta, typ, arg))
return this
-
def __add__ (this, that):
this = this.copy()
this.extend(that)
return this
+
+ def link (this, symbols):
+ i = len(this._linker_notes)
+ while i > 0:
+ i = i - 1
+ offset, type, arg = this._linker_notes[i]
+ if symbols.has_key(arg):
+ if type == 1: this.add_byte(offset, symbols[arg])
+ elif type == 2: this.add_wyde(offset, symbols[arg])
+ elif type == 4: this.add_tetra(offset, symbols[arg])
+ else: raise 'Invalid linker note type', (offset, type, arg)
+ del this._linker_notes[i]
+ return len(this._linker_notes)
def dump (this):
filesz = len(this._binary)
Index: makehello.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- makehello.py 8 Feb 2003 20:21:37 -0000 1.4
+++ makehello.py 14 Feb 2003 13:50:56 -0000 1.5
@@ -36,3 +36,15 @@
(header + make_marker('PHEADER') + pheader + code + data +
make_marker('SHEADER') + sheader).dump()
+
+print; print '=== hello ==='
+hello = Linkie('<')
+hello.extend(make_ELF32_header('<'))
+hello.align(4)
+symbols = {}
+symbols['elf/type'] = ET.EXEC
+symbols['elf/machine'] = EM.I386
+symbols['elf/phoff'] = hello.place_symbol('elf/phoff')
+hello.extend(make_ELF32_pheader('<', '.text'))
+hello.link(symbols)
+hello.dump()
|