wisp-cvs Mailing List for Wisp interpreter (Page 18)
Status: Alpha
Brought to you by:
digg
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(30) |
Sep
(312) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(5) |
Feb
(131) |
Mar
(17) |
Apr
(184) |
May
(252) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <di...@us...> - 2003-04-12 12:06:35
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv1524 Modified Files: elfdump.py Log Message: list more section header flags Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- elfdump.py 6 Feb 2003 21:30:45 -0000 1.1 +++ elfdump.py 12 Apr 2003 12:06:32 -0000 1.2 @@ -151,8 +151,8 @@ print 'Section header table:' f.seek(e_shoff) - print 'No type fla addr offset size link info align each' - print '== ==== === ======== ====== ====== ==== ==== ===== ====' + print 'No type flags addr offset size link info align each' + print '== ==== ======== ======== ====== ====== ==== ==== ===== ====' for i in range(e_shnum): shentry = f.read(e_shentsize) sh_name, sh_type, sh_flags, sh_addr, sh_offset, sh_size, \ @@ -179,7 +179,7 @@ SHT.GNU_verneed: 'vern', SHT.GNU_versym: 'vers'}[sh_type], except: print '%4x' % sh_type, - flags_shortly('xaw', sh_flags) + flags_shortly('oism?xaw', sh_flags) print '%8x' % sh_addr, print '%6x' % sh_offset, print '%6x' % sh_size, |
From: <di...@us...> - 2003-04-12 11:18:04
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv21260 Modified Files: .cvsignore Makefile.am Added Files: hello.tran tran.py Log Message: added tran.py and hello.tran --- NEW FILE: hello.tran --- \\\\ hello.tran - produce a friendly greeting \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: hello.tran,v 1.1 2003/04/12 11:17:57 digg Exp $ \ This file is intended to be processed using tran.py \ ia32 registers :regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; :regs reg16 %ax %cx %dx %bx %sp %bp %si %di ; :regs reg8 %al %cl %dl %bl %ah %ch %dh %bh ; lit :macro $int #xCD b, b, ; reg32 lit :macro $mov swap minor #o270 + b, t, ; \ main entry point label _start %edx 6 $mov %ecx ref message $mov %ebx 1 $mov %eax 4 $mov #x80 $int %ebx 0 $mov %eax 1 $mov #x80 $int .data label message #/H b, #/E b, #/L b, #/L b, #/O b, 10 b, \ vim: ft=forth --- NEW FILE: tran.py --- #! /usr/bin/python #### tran.py - an NG Worth translator prototype # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: tran.py,v 1.1 2003/04/12 11:17:57 digg Exp $ from __future__ import generators from shlex import shlex from types import * import elf import string import sys from linkie import Linkie class Lexer (shlex): def __init__ (this, instream = None, infile = None): shlex.__init__(this, instream = instream, infile = infile) this.commenters = '\\' this.quotes = '"' this.wordchars += '!#$%*+,-./:;<=>?@' def get_token (this): tok = shlex.get_token(this) if tok == '': tok = None elif tok[:2] == '#o': tok = string.atol(tok[2:], 8) elif tok[:2] == '#x': tok = string.atol(tok[2:], 16) else: try: tok = string.atol(tok, 10) except: pass return tok class _Register (tuple): def parent (this): if len(this): return _Register(this[:-1]) else: return None def child_generator (this): i = 0 while 1: yield Register(this + (i,)) i += 1 def __repr__ (this): return 'Register' + tuple.__repr__(this) class ClassMarker: def __init__ (this, id): this.id = id def Register (*args): return _Register(args) def b_comma (n): if type(n) == LongType: cursect.emit_byte(n) elif type(n) == StringType: cursect.emit_byte_sum([n]) else: raise 'Literal expected', n def t_comma (n): if type(n) == LongType: cursect.emit_tetra(n) elif type(n) == StringType: cursect.emit_tetra_sum([n]) else: raise 'Literal expected', n def label (name): cursect.place_symbol('&' + name) def dot_data (): global cursect cursect = Data def dot_text (): global cursect cursect = Text def ref (name): Regstack.append('&' + name) def drop (x): pass def minor (reg): Regstack.append(long(reg[-1])) def swap (x, y): Regstack.append(y); Regstack.append(x) def colon_macro (name): global State, Regstack, current_recordee if len(Regstack) > 2: raise 'too long argument pattern', Regstack name = ' '.join([name] + [matchers(i).next() for i in Regstack]) Regstack = [] if Meaning.has_key(name): raise 'duplicate declaration', name newmac = [] Meaning[name] = ('macro', newmac) current_recordee = newmac State = state_record def colon_regs (family): global State, current_register_index if Meaning.has_key(family): raise 'duplicate declaration', tok Register(current_register_family) f = Register(current_register_family) Meaning[family] = 'simple', f Registers[f] = family current_register_index = 0 State = state_regs def plus (a, b): Regstack.append(a + b) def matchers (object): if isinstance(object, ClassMarker): yield object.id elif type(object) == LongType: yield 'int' yield 'lit' elif type(object) == StringType: yield 'sym' yield 'lit' elif isinstance(object, _Register): while object <> None: yield Registers[object] object = object.parent() yield 'any' def match_generator (root): yield root if len(Regstack) < 1: yield None # want more registers m = matchers(Regstack[-1]) try: while 1: yield root + ' ' + m.next() except StopIteration: pass if len(Regstack) < 2: yield None m1 = matchers(Regstack[-2]) try: while 1: n1 = m1.next() m2 = matchers(Regstack[-1]) try: while 1: yield root + ' ' + n1 + ' ' + m2.next() except StopIteration: pass except StopIteration: pass def state_outer (tok): global Regstack if type(tok) == LongType: Regstack.append(tok) elif type(tok) == StringType and tok[:2] == '#/' and len(tok) == 3: Regstack.append(long(ord(tok[2]))) else: root = tok mg = match_generator(root) try: while not Meaning.has_key(tok): tok = mg.next() if tok == None: raise 'stack too empty or meaningless word', root except StopIteration: raise 'meaningless word', root m = Meaning[tok] mtype = m[0] if mtype == 'builtin': argc = m[2] & MA_ARGC if len(Regstack) < argc: raise 'Stack too empty', tok if argc: arg = Regstack[-argc:]; Regstack = Regstack[:-argc] else: arg = [] if m[2] & MA_PREFIX: tok = get_token() if type(tok) <> StringType: raise 'word expected' arg.append(tok) apply(m[1], arg) elif mtype == 'macro': Macrostack.append([0, m[1]]) elif mtype == 'simple': Regstack.append(m[1]) else: raise 'Unknown meaning type in', `Meaning[tok]` def state_record (tok): global State, current_recordee if tok == ';': State = state_outer current_recordee = None else: current_recordee.append(tok) def state_regs (tok): global State, current_register_family, current_register_index if tok != ';': if Meaning.has_key(tok): raise 'duplicate declaration', tok r = Register(current_register_family, current_register_index) Meaning[tok] = 'simple', r Registers[r] = tok current_register_index += 1 else: State = state_outer current_register_family += 1 current_register_index = None # Main output sections. Text = Linkie('<') Data = Linkie('<') cursect = Text Regstack = [] Generic_Register = Register() reggen = Generic_Register.child_generator() MA_ARGC = 007 MA_PREFIX = 010 Meaning = { '.data': ('builtin', dot_data, 0), '.text': ('builtin', dot_text, 0), ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), 'any': ('simple', ClassMarker('any')), 'b, lit': ('builtin', b_comma, 1), 'drop any': ('builtin', drop, 1), 'int': ('simple', ClassMarker('int')), 'label': ('builtin', label, 0 | MA_PREFIX), 'lit': ('simple', ClassMarker('lit')), 'ref': ('builtin', ref, 0 | MA_PREFIX), 'reg': ('simple', Generic_Register), 'swap any any': ('builtin', swap, 2), 't, lit': ('builtin', t_comma, 1), 'minor reg': ('builtin', minor, 1), '+ int int': ('builtin', plus, 2), } current_recordee = None current_register_family = 0 State = state_outer Macrostack = [] Registers = {Generic_Register: 'reg'} # for reverse translation lex = Lexer(instream = open(sys.argv[1], 'r'), infile = sys.argv[1]) def get_token (): if Macrostack: tok = Macrostack[-1][1][Macrostack[-1][0]] Macrostack[-1][0] += 1 if Macrostack[-1][0] >= len(Macrostack[-1][1]): Macrostack.pop() return tok else: return lex.get_token() def mainloop (): tok = get_token() while tok <> None: State(tok) tok = get_token() mainloop() print 'TEXT'; Text.dump() print 'DATA'; Data.dump() if Regstack: raise 'Regstack not empty after parsing ended', Regstack binary = elf.make_ELF32_executable(text = Text, data = Data, want_symbols = 1) f = open('a.out', 'w') binary.get_file().tofile(f) f.close() Index: .cvsignore =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/.cvsignore,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- .cvsignore 8 Apr 2003 16:01:30 -0000 1.5 +++ .cvsignore 12 Apr 2003 11:17:57 -0000 1.6 @@ -3,5 +3,6 @@ *.pyo Makefile Makefile.in +a.out hello hellowosym Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 10 Apr 2003 19:07:20 -0000 1.7 +++ Makefile.am 12 Apr 2003 11:17:57 -0000 1.8 @@ -12,4 +12,4 @@ all: clean: clean-am - -rm -f *~ *.pyc *.pyo *.exe hello hellowosym + -rm -f *~ *.pyc *.pyo *.exe a.out hello hellowosym |
From: <di...@us...> - 2003-04-12 11:10:55
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv18848/users/dig Modified Files: linkie.py Log Message: retabbed elf.py Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- linkie.py 1 Apr 2003 08:03:00 -0000 1.21 +++ linkie.py 12 Apr 2003 11:10:51 -0000 1.22 @@ -242,7 +242,7 @@ # Returns the offset of /that/ inside /this/ after extension. if this._unresolved_locals: raise 'Incomplete linkie', this if that._unresolved_locals: raise 'Incomplete linkie', that - this._origin = 0 + this._origin = 0 if that.filesz(): this.deskip() this.align(that._alignment) delta = this.memsz() - that._origin @@ -260,48 +260,48 @@ return delta def paste (this, offset, that): # Pastes /that/ into /this/ at specified /offset/ (if negative - # /offset/ is treated as an alignment restriction and the actual - # offset is automatically calculated from that). - # Note that the specified alignment of /that/ is IGNORED. - # Origin of /this/ *should* be zero. + # /offset/ is treated as an alignment restriction and the actual + # offset is automatically calculated from that). + # Note that the specified alignment of /that/ is IGNORED. + # Origin of /this/ *should* be zero. if this._unresolved_locals: raise 'Incomplete linkie', this if that._unresolved_locals: raise 'Incomplete linkie', that - # provide sufficient padding - if offset < 0: this.align(- offset) - else: this.skip(offset - this.memsz()) + # provide sufficient padding + if offset < 0: this.align(- offset) + else: this.skip(offset - this.memsz()) - # convert any padding to hard zeroes if needed + # convert any padding to hard zeroes if needed if that.filesz(): this.deskip() # remember the start offset of /that/ - thatofs = this.memsz() + thatofs = this.memsz() # carry over all the bits this._binary.extend(that._binary) this._skipped = that._skipped - # carry over and process the symbols + # carry over and process the symbols for sym, val in that._symbols: - if sym[0] == '!': - this._symbols.append((sym, val + thatofs)) - elif sym[0] in '#&': + if sym[0] == '!': + this._symbols.append((sym, val + thatofs)) + elif sym[0] in '#&': this._symbols.append((sym, val)) else: - raise 'unprefixed symbol', sym + raise 'unprefixed symbol', sym # carry over the linker notes for ofs, typ, arg in that._linker_notes: this._linker_notes.append((ofs + thatofs, typ, arg)) - # return nothing + # return nothing def __add__ (this, that): this = this.copy() this.extend(that) return this def link (this): - symbols = this.get_symbol_dict() + symbols = this.get_symbol_dict() i = len(this._linker_notes) while i > 0: i = i - 1 |
From: <di...@us...> - 2003-04-12 11:06:29
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv17390/users/dig Modified Files: elf.py Log Message: retabbed elf.py Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- elf.py 8 Apr 2003 21:19:06 -0000 1.17 +++ elf.py 12 Apr 2003 11:06:25 -0000 1.18 @@ -493,7 +493,7 @@ for name in shentnames: if guess_ELF32_pflags(name) <> 0: phentnames.append(name) - sections['.shstrtab'].place_symbol('#.shstrtab/strings/' + name) + sections['.shstrtab'].place_symbol('#.shstrtab/strings/' + name) sections['.shstrtab'].emit_string(name) sections['.shstrtab'].emit_byte(0) @@ -504,10 +504,10 @@ section = sections[name] p_flags = guess_ELF32_pflags(name) alignment = section.get_alignment() - binary.place_symbol('#' + name + '/sh_align', alignment) + binary.place_symbol('#' + name + '/sh_align', alignment) if p_flags <> 0: - binary.place_symbol('#' + name + '/p_align', 0x1000) + binary.place_symbol('#' + name + '/p_align', 0x1000) binary.align(min(alignment, 0x1000)) else: # No program header entry => not loaded @@ -520,26 +520,26 @@ address = memory_boundary | (offset & 0xFFF) # take into account alignments larger than a page address = (address + alignment - 1) & ~(alignment - 1) - binary.place_symbol('#' + name + '/p_flags', guess_ELF32_pflags(name)) - binary.place_symbol('#' + name + '/p_type', guess_ELF32_ptype(name)) - section.set_origin(address) - binary.place_symbol('&' + name, address) + binary.place_symbol('#' + name + '/p_flags', guess_ELF32_pflags(name)) + binary.place_symbol('#' + name + '/p_type', guess_ELF32_ptype(name)) + section.set_origin(address) + binary.place_symbol('&' + name, address) else: address = None binary.place_symbol('#' + name + '/memsz', section.memsz()) - binary.place_symbol('#' + name + '/filesz', section.filesz()) - binary.place_symbol('#' + name + '/sh_size', section.filesz()) - binary.place_symbol('#' + name + '/sh_type', guess_ELF32_shtype(name)) - binary.place_symbol('#' + name + '/sh_info', 0) - if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 - else: sh_link = SHN.UNDEF - binary.place_symbol('#' + name + '/sh_link', sh_link) - binary.place_symbol('#' + name + '/sh_entsize', 0) - binary.place_symbol('#' + name + '/sh_flags', guess_ELF32_shflags(name)) + binary.place_symbol('#' + name + '/filesz', section.filesz()) + binary.place_symbol('#' + name + '/sh_size', section.filesz()) + binary.place_symbol('#' + name + '/sh_type', guess_ELF32_shtype(name)) + binary.place_symbol('#' + name + '/sh_info', 0) + if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 + else: sh_link = SHN.UNDEF + binary.place_symbol('#' + name + '/sh_link', sh_link) + binary.place_symbol('#' + name + '/sh_entsize', 0) + binary.place_symbol('#' + name + '/sh_flags', guess_ELF32_shflags(name)) - # alignment has been processed already - binary.place_symbol('!' + name) + # alignment has been processed already + binary.place_symbol('!' + name) binary.paste(-1, section) if want_symbols: symtab = sections['.symtab'] |
From: <di...@us...> - 2003-04-10 19:07:24
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3548 Modified Files: Makefile.am Log Message: made the |clean| make target delete *.exe and hellowosym, too Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 24 Mar 2003 21:18:12 -0000 1.6 +++ Makefile.am 10 Apr 2003 19:07:20 -0000 1.7 @@ -1,6 +1,6 @@ #### users/dig/Makefile.am for the Wisp interpreter # -# Copyleft © 2002 by Andres Soolo (di...@us...) +# Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # @@ -12,4 +12,4 @@ all: clean: clean-am - -rm -f *~ *.pyc *.pyo hello + -rm -f *~ *.pyc *.pyo *.exe hello hellowosym |
From: <di...@us...> - 2003-04-08 22:24:05
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9720 Modified Files: makehello.py Log Message: dropped binround_down and binround_up from makehello.py Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- makehello.py 8 Apr 2003 22:18:10 -0000 1.20 +++ makehello.py 8 Apr 2003 22:24:02 -0000 1.21 @@ -9,11 +9,6 @@ from linkie import Linkie from elf import * -def binround_down (x, unit): - return x & ~(unit - 1) -def binround_up (x, unit): - return (x | (unit - 1)) + 1 - code = Linkie('<') # ia32 code.place_symbol('&_start') code.emit_byte(0xBA); code.emit_tetra(14) # mov edx, 14 |
From: <di...@us...> - 2003-04-08 22:18:13
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv7053 Modified Files: makehello.py Log Message: dropped make_marker Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- makehello.py 8 Apr 2003 21:19:05 -0000 1.19 +++ makehello.py 8 Apr 2003 22:18:10 -0000 1.20 @@ -13,10 +13,6 @@ return x & ~(unit - 1) def binround_up (x, unit): return (x | (unit - 1)) + 1 -def make_marker (name): - m = Linkie('<') - m.place_symbol(name) - return m code = Linkie('<') # ia32 code.place_symbol('&_start') |
From: <di...@us...> - 2003-04-08 21:19:11
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9820 Modified Files: makehello.py elf.py Log Message: moved make_ELF32_executable from makehello.py to elf.py Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- makehello.py 3 Apr 2003 09:12:02 -0000 1.18 +++ makehello.py 8 Apr 2003 21:19:05 -0000 1.19 @@ -33,156 +33,8 @@ data.place_symbol('&message') data.emit_string('Hello, world!\n') -def infer_by_prefix (name, dict): - for l in range(len(name), -1, -1): - prefix = name[:l] - try: return dict[prefix] - except: pass - return None -def guess_shtype (name): - return infer_by_prefix(name, {'': SHT.PROGBITS, - '.bss': SHT.NOBITS, - '.dynstr': SHT.STRTAB, - '.note': SHT.NOTE, - '.shstrtab': SHT.STRTAB, - '.symstr': SHT.STRTAB, - '.symtab': SHT.SYMTAB, - }) -def guess_ptype (name): - return infer_by_prefix(name, {'': PT.LOAD, - '.note': PT.NOTE}) -def guess_flags (name): - return infer_by_prefix(name, {'': 'rw--', - '.bss': 'rw--', - '.comment': '----', - '.data': 'rw--', - '.debug': '----', - '.dynstr': 'a--s', - '.line': '----', - '.note': '----', - '.rodata': 'r---', - '.shstrtab': '---s', - '.symstr': 'a--s', - '.text': 'r-x-'}) -def guess_shflags (name): - flags = guess_flags(name) - sh_flags = 0 - if 'r' in flags or 'a' in flags: sh_flags |= SHF.ALLOC - if 'w' in flags: sh_flags |= SHF.ALLOC | SHF.WRITE - if 'x' in flags: sh_flags |= SHF.ALLOC | SHF.EXECINSTR - if 's' in flags: sh_flags |= SHF.STRINGS - return sh_flags -def guess_pflags (name): - flags = guess_flags(name) - p_flags = 0 - if 'r' in flags: p_flags |= PF.R - if 'w' in flags: p_flags |= PF.W - if 'x' in flags: p_flags |= PF.X - return p_flags - -def make_executable (text = None, data = None, - memory_bottom = 0x08048000, - want_symbols = 1): - # Will set given sections' origins. - - sections = {} - sections['.text'] = code - sections['.data'] = data - - binary = Linkie('<') - memory_boundary = memory_bottom # must be at page boundary - binary.paste(0, make_ELF32_header('<')) - binary.place_symbol('#elf/type', ET.EXEC) - binary.place_symbol('#elf/machine', EM.I386) - binary.place_symbol('#elf/flags', 0) # no flags for ia386 - - shentnames = ['.text', '.data'] - if want_symbols: shentnames += ['.symstr', '.symtab'] - shentnames.append('.shstrtab') - - sections['.shstrtab'] = Linkie('<') - sections['.shstrtab'].emit_byte(0) - - if want_symbols: - sections['.symstr'] = Linkie('<') - sections['.symstr'].emit_byte(0) - - sections['.symtab'] = Linkie('<') - sections['.symtab'].align(4) - sections['.symtab'].emit_string('\0' * 16) - - phentnames = [] - for name in shentnames: - if guess_pflags(name) <> 0: - phentnames.append(name) - sections['.shstrtab'].place_symbol('#.shstrtab/strings/' + name) - sections['.shstrtab'].emit_string(name) - sections['.shstrtab'].emit_byte(0) - - program_header_table = make_ELF32_phtable('<', phentnames) - binary.paste(-4, program_header_table) - - for name in shentnames: - section = sections[name] - p_flags = guess_pflags(name) - alignment = section.get_alignment() - binary.place_symbol('#' + name + '/sh_align', alignment) - - if p_flags <> 0: - binary.place_symbol('#' + name + '/p_align', 0x1000) - binary.align(min(alignment, 0x1000)) - else: - # No program header entry => not loaded - # thusly no larger alignment necessary. - binary.align(min(alignment, 4)) - - offset = binary.filesz() - - if p_flags <> 0: - address = memory_boundary | (offset & 0xFFF) - # take into account alignments larger than a page - address = (address + alignment - 1) & ~(alignment - 1) - binary.place_symbol('#' + name + '/p_flags', guess_pflags(name)) - binary.place_symbol('#' + name + '/p_type', guess_ptype(name)) - section.set_origin(address) - binary.place_symbol('&' + name, address) - else: - address = None - - binary.place_symbol('#' + name + '/memsz', section.memsz()) - binary.place_symbol('#' + name + '/filesz', section.filesz()) - binary.place_symbol('#' + name + '/sh_size', section.filesz()) - binary.place_symbol('#' + name + '/sh_type', guess_shtype(name)) - binary.place_symbol('#' + name + '/sh_info', 0) - if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 - else: sh_link = SHN.UNDEF - binary.place_symbol('#' + name + '/sh_link', sh_link) - binary.place_symbol('#' + name + '/sh_entsize', 0) - binary.place_symbol('#' + name + '/sh_flags', guess_shflags(name)) - - # alignment has been processed already - binary.place_symbol('!' + name) - binary.paste(-1, section) - if want_symbols: - symtab = sections['.symtab'] - symstr = sections['.symstr'] - for symbol, value in section.get_symbols(): - if symbol[0] == '&': # only process memory references - emit_ELF32_symtab_entry(symtab, symstr, symbol, value, - shentnames.index(name) + 1) - - memory_boundary += section.memsz() - memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF - - # create section header table - section_header_table = make_ELF32_shtable('<', shentnames) - binary.paste(-4, section_header_table) - binary.place_symbol('#elf/shstrndx', shentnames.index('.shstrtab') + 1) - binary.link() - return binary - print 'With symbols' -hello = make_executable(text = code, data = data) +hello = make_ELF32_executable(text = code, data = data, want_symbols = 1) hello.dump() f = open('hello', 'w') @@ -190,7 +42,7 @@ f.close() print 'Without symbols' -hellowosym = make_executable(text = code, data = data, want_symbols = 0) +hellowosym = make_ELF32_executable(text = code, data = data, want_symbols = 0) hellowosym.dump() f = open('hellowosym', 'w') Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- elf.py 3 Apr 2003 09:12:01 -0000 1.16 +++ elf.py 8 Apr 2003 21:19:06 -0000 1.17 @@ -406,12 +406,160 @@ symtab.emit_byte(0) # st_other; reserved symtab.emit_wyde(section) +def infer_by_prefix (name, dict): + for l in range(len(name), -1, -1): + prefix = name[:l] + try: return dict[prefix] + except: pass + return None + +def guess_ELF32_shtype (name): + return infer_by_prefix(name, {'': SHT.PROGBITS, + '.bss': SHT.NOBITS, + '.dynstr': SHT.STRTAB, + '.note': SHT.NOTE, + '.shstrtab': SHT.STRTAB, + '.symstr': SHT.STRTAB, + '.symtab': SHT.SYMTAB, + }) + +def guess_ELF32_ptype (name): + return infer_by_prefix(name, {'': PT.LOAD, + '.note': PT.NOTE}) + +def guess_ELF32_flags (name): + return infer_by_prefix(name, {'': 'rw--', + '.bss': 'rw--', + '.comment': '----', + '.data': 'rw--', + '.debug': '----', + '.dynstr': 'a--s', + '.line': '----', + '.note': '----', + '.rodata': 'r---', + '.shstrtab': '---s', + '.symstr': 'a--s', + '.text': 'r-x-'}) + +def guess_ELF32_shflags (name): + flags = guess_ELF32_flags(name) + sh_flags = 0 + if 'r' in flags or 'a' in flags: sh_flags |= SHF.ALLOC + if 'w' in flags: sh_flags |= SHF.ALLOC | SHF.WRITE + if 'x' in flags: sh_flags |= SHF.ALLOC | SHF.EXECINSTR + if 's' in flags: sh_flags |= SHF.STRINGS + return sh_flags + +def guess_ELF32_pflags (name): + flags = guess_ELF32_flags(name) + p_flags = 0 + if 'r' in flags: p_flags |= PF.R + if 'w' in flags: p_flags |= PF.W + if 'x' in flags: p_flags |= PF.X + return p_flags + +def make_ELF32_executable (text = None, data = None, + memory_bottom = 0x08048000, + want_symbols = 0): + # Will set given sections' origins. + + sections = {} + sections['.text'] = text + sections['.data'] = data + + binary = Linkie('<') + memory_boundary = memory_bottom # must be at page boundary + binary.paste(0, make_ELF32_header('<')) + binary.place_symbol('#elf/type', ET.EXEC) + binary.place_symbol('#elf/machine', EM.I386) + binary.place_symbol('#elf/flags', 0) # no flags for ia386 + + shentnames = ['.text', '.data'] + if want_symbols: shentnames += ['.symstr', '.symtab'] + shentnames.append('.shstrtab') + + sections['.shstrtab'] = Linkie('<') + sections['.shstrtab'].emit_byte(0) + + if want_symbols: + sections['.symstr'] = Linkie('<') + sections['.symstr'].emit_byte(0) + + sections['.symtab'] = Linkie('<') + sections['.symtab'].align(4) + sections['.symtab'].emit_string('\0' * 16) + + phentnames = [] + for name in shentnames: + if guess_ELF32_pflags(name) <> 0: + phentnames.append(name) + sections['.shstrtab'].place_symbol('#.shstrtab/strings/' + name) + sections['.shstrtab'].emit_string(name) + sections['.shstrtab'].emit_byte(0) + + program_header_table = make_ELF32_phtable('<', phentnames) + binary.paste(-4, program_header_table) + + for name in shentnames: + section = sections[name] + p_flags = guess_ELF32_pflags(name) + alignment = section.get_alignment() + binary.place_symbol('#' + name + '/sh_align', alignment) + + if p_flags <> 0: + binary.place_symbol('#' + name + '/p_align', 0x1000) + binary.align(min(alignment, 0x1000)) + else: + # No program header entry => not loaded + # thusly no larger alignment necessary. + binary.align(min(alignment, 4)) + + offset = binary.filesz() + + if p_flags <> 0: + address = memory_boundary | (offset & 0xFFF) + # take into account alignments larger than a page + address = (address + alignment - 1) & ~(alignment - 1) + binary.place_symbol('#' + name + '/p_flags', guess_ELF32_pflags(name)) + binary.place_symbol('#' + name + '/p_type', guess_ELF32_ptype(name)) + section.set_origin(address) + binary.place_symbol('&' + name, address) + else: + address = None + + binary.place_symbol('#' + name + '/memsz', section.memsz()) + binary.place_symbol('#' + name + '/filesz', section.filesz()) + binary.place_symbol('#' + name + '/sh_size', section.filesz()) + binary.place_symbol('#' + name + '/sh_type', guess_ELF32_shtype(name)) + binary.place_symbol('#' + name + '/sh_info', 0) + if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 + else: sh_link = SHN.UNDEF + binary.place_symbol('#' + name + '/sh_link', sh_link) + binary.place_symbol('#' + name + '/sh_entsize', 0) + binary.place_symbol('#' + name + '/sh_flags', guess_ELF32_shflags(name)) + + # alignment has been processed already + binary.place_symbol('!' + name) + binary.paste(-1, section) + if want_symbols: + symtab = sections['.symtab'] + symstr = sections['.symstr'] + for symbol, value in section.get_symbols(): + if symbol[0] == '&': # only process memory references + emit_ELF32_symtab_entry(symtab, symstr, symbol, value, + shentnames.index(name) + 1) + + memory_boundary += section.memsz() + memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF + + # create section header table + section_header_table = make_ELF32_shtable('<', shentnames) + binary.paste(-4, section_header_table) + binary.place_symbol('#elf/shstrndx', shentnames.index('.shstrtab') + 1) + binary.link() + return binary + # Thoughts of generating ELF32 files # * In ELF parlance, linker notes are called relocations. # We need to solve relocations only when generating an # executable file. -# * ELF symbols are defined relative to their corresponding sections' -# origins. Basically, a symbol's value consists of two parts: -# reference to its section and its location inside the section. -# * We'll need some symbols to represent offsets in the generated -# file. It's probably best to treat them as ELF absolute symbols. |
From: <di...@us...> - 2003-04-08 16:01:35
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv14144 Modified Files: .cvsignore Log Message: ignore hellowosym Index: .cvsignore =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/.cvsignore,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- .cvsignore 9 Mar 2003 13:54:24 -0000 1.4 +++ .cvsignore 8 Apr 2003 16:01:30 -0000 1.5 @@ -4,3 +4,4 @@ Makefile Makefile.in hello +hellowosym |
From: <di...@us...> - 2003-04-03 09:12:06
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv354 Modified Files: elf.py makehello.py Log Message: wrote emit_ELF32_symtab_entry Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- elf.py 3 Apr 2003 08:49:11 -0000 1.15 +++ elf.py 3 Apr 2003 09:12:01 -0000 1.16 @@ -393,6 +393,19 @@ symstr.emit_byte(0) return ofs +def emit_ELF32_symtab_entry (symtab, symstr, pname, + value = None, section = SHN.ABS): + # No explicit alignment. .symtab doesn't bear padding; if + # you get it out of align, you're out of luck anyway. + ofs = emit_ELF32_symstr_entry (symstr, pname[1:]) + symtab.emit_tetra(ofs) + if value == None: symtab.emit_tetra_sum([pname]) + else: symtab.emit_tetra(value) + symtab.emit_tetra(0) # st_size + symtab.emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) + symtab.emit_byte(0) # st_other; reserved + symtab.emit_wyde(section) + # Thoughts of generating ELF32 files # * In ELF parlance, linker notes are called relocations. # We need to solve relocations only when generating an Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- makehello.py 3 Apr 2003 08:49:12 -0000 1.17 +++ makehello.py 3 Apr 2003 09:12:02 -0000 1.18 @@ -164,16 +164,12 @@ binary.place_symbol('!' + name) binary.paste(-1, section) if want_symbols: + symtab = sections['.symtab'] + symstr = sections['.symstr'] for symbol, value in section.get_symbols(): - if symbol[0] != '&': continue # only process memory references - symbol = symbol[1:] # but not their prefixen - ofs = emit_ELF32_symstr_entry(sections['.symstr'], symbol) - sections['.symtab'].emit_tetra(ofs) - sections['.symtab'].emit_tetra_sum(['&' + name]) - sections['.symtab'].emit_tetra(0) - sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) - sections['.symtab'].emit_byte(0) - sections['.symtab'].emit_wyde(shentnames.index(name) + 1) + if symbol[0] == '&': # only process memory references + emit_ELF32_symtab_entry(symtab, symstr, symbol, value, + shentnames.index(name) + 1) memory_boundary += section.memsz() memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF |
From: <di...@us...> - 2003-04-03 08:49:17
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv13761 Modified Files: elf.py makehello.py Log Message: wrote emit_ELF32_symstr_entry Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- elf.py 24 Mar 2003 21:18:13 -0000 1.14 +++ elf.py 3 Apr 2003 08:49:11 -0000 1.15 @@ -386,6 +386,13 @@ t.place_symbol('#elf/shnum', len(names) + 1) return t +# Returns offset of the string added +def emit_ELF32_symstr_entry (symstr, string): + ofs = symstr.memsz() + symstr.emit_string (string) + symstr.emit_byte(0) + return ofs + # Thoughts of generating ELF32 files # * In ELF parlance, linker notes are called relocations. # We need to solve relocations only when generating an Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- makehello.py 1 Apr 2003 09:07:12 -0000 1.16 +++ makehello.py 3 Apr 2003 08:49:12 -0000 1.17 @@ -167,11 +167,8 @@ for symbol, value in section.get_symbols(): if symbol[0] != '&': continue # only process memory references symbol = symbol[1:] # but not their prefixen - symstr = sections['.symstr'] - symstr.place_symbol('#.symstr/strings/' + symbol) - sections['.symstr'].emit_string(symbol) - sections['.symstr'].emit_byte(0) - sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) + ofs = emit_ELF32_symstr_entry(sections['.symstr'], symbol) + sections['.symtab'].emit_tetra(ofs) sections['.symtab'].emit_tetra_sum(['&' + name]) sections['.symtab'].emit_tetra(0) sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) |
From: <di...@us...> - 2003-04-01 09:07:32
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3355 Modified Files: makehello.py Log Message: made make_executable able to generate symbolless ELF executables Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- makehello.py 24 Mar 2003 21:18:13 -0000 1.15 +++ makehello.py 1 Apr 2003 09:07:12 -0000 1.16 @@ -80,7 +80,9 @@ if 'x' in flags: p_flags |= PF.X return p_flags -def make_executable (text = None, data = None, memory_bottom = 0x08048000): +def make_executable (text = None, data = None, + memory_bottom = 0x08048000, + want_symbols = 1): # Will set given sections' origins. sections = {} @@ -94,17 +96,20 @@ binary.place_symbol('#elf/machine', EM.I386) binary.place_symbol('#elf/flags', 0) # no flags for ia386 - shentnames = ['.text', '.data', '.symstr', '.symtab', '.shstrtab'] + shentnames = ['.text', '.data'] + if want_symbols: shentnames += ['.symstr', '.symtab'] + shentnames.append('.shstrtab') sections['.shstrtab'] = Linkie('<') sections['.shstrtab'].emit_byte(0) - sections['.symstr'] = Linkie('<') - sections['.symstr'].emit_byte(0) + if want_symbols: + sections['.symstr'] = Linkie('<') + sections['.symstr'].emit_byte(0) - sections['.symtab'] = Linkie('<') - sections['.symtab'].align(4) - sections['.symtab'].emit_string('\0' * 16) + sections['.symtab'] = Linkie('<') + sections['.symtab'].align(4) + sections['.symtab'].emit_string('\0' * 16) phentnames = [] for name in shentnames: @@ -158,19 +163,20 @@ # alignment has been processed already binary.place_symbol('!' + name) binary.paste(-1, section) - for symbol, value in section.get_symbols(): - if symbol[0] != '&': continue # only process memory references - symbol = symbol[1:] # but not their prefixen - symstr = sections['.symstr'] - symstr.place_symbol('#.symstr/strings/' + symbol) - sections['.symstr'].emit_string(symbol) - sections['.symstr'].emit_byte(0) - sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) - sections['.symtab'].emit_tetra_sum(['&' + name]) - sections['.symtab'].emit_tetra(0) - sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) - sections['.symtab'].emit_byte(0) - sections['.symtab'].emit_wyde(shentnames.index(name) + 1) + if want_symbols: + for symbol, value in section.get_symbols(): + if symbol[0] != '&': continue # only process memory references + symbol = symbol[1:] # but not their prefixen + symstr = sections['.symstr'] + symstr.place_symbol('#.symstr/strings/' + symbol) + sections['.symstr'].emit_string(symbol) + sections['.symstr'].emit_byte(0) + sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) + sections['.symtab'].emit_tetra_sum(['&' + name]) + sections['.symtab'].emit_tetra(0) + sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) + sections['.symtab'].emit_byte(0) + sections['.symtab'].emit_wyde(shentnames.index(name) + 1) memory_boundary += section.memsz() memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF @@ -182,9 +188,18 @@ binary.link() return binary +print 'With symbols' hello = make_executable(text = code, data = data) hello.dump() f = open('hello', 'w') hello.get_file().tofile(f) +f.close() + +print 'Without symbols' +hellowosym = make_executable(text = code, data = data, want_symbols = 0) +hellowosym.dump() + +f = open('hellowosym', 'w') +hellowosym.get_file().tofile(f) f.close() |
From: <di...@us...> - 2003-04-01 08:03:06
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9154 Modified Files: linkie.py make-pe-exe.py Log Message: reject unprefixed symbols in _emit_sum Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- linkie.py 31 Mar 2003 10:23:30 -0000 1.20 +++ linkie.py 1 Apr 2003 08:03:00 -0000 1.21 @@ -84,6 +84,8 @@ else: # forwards this._unresolved_locals.append((a, size, len(this._binary))) elif type(a) == StringType: # global reference + if not a[0] in '#&!': + raise 'unprefixed symbol being referred to', a this.notify_linker(this.memsz(), size, a) else: raise 'Invalid addend', a return delta Index: make-pe-exe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- make-pe-exe.py 24 Mar 2003 21:18:13 -0000 1.2 +++ make-pe-exe.py 1 Apr 2003 08:03:01 -0000 1.3 @@ -53,10 +53,10 @@ b.place_symbol('&mz/message', b.filesz() - 1) b.emit_string(message[1:]) b.emit_string('\x00' * (0x003C - b.filesz())) - b.emit_tetra_sum(['mz/pe-offset']) + b.emit_tetra_sum(['!pe']) else: b.emit_string('\x00' * (0x003C - b.filesz())) - b.emit_tetra_sum(['mz/pe-offset']) + b.emit_tetra_sum(['!pe']) b.place_symbol('&mz/message') b.emit_string(message) b.place_symbol('#mz/bytes-in-last-block', b.filesz() % 0x200) |
From: <di...@us...> - 2003-03-31 10:23:38
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv28044 Modified Files: linkie.py Log Message: reject unprefixed symbols in place_symbol Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- linkie.py 24 Mar 2003 21:18:13 -0000 1.19 +++ linkie.py 31 Mar 2003 10:23:30 -0000 1.20 @@ -149,8 +149,7 @@ None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol if not symbol[0] in '#&!': - # FIXME: backwards compatibility - print 'WARNING: unprefixed symbol', symbol, 'being placed' + raise 'unprefixed symbol being placed', symbol if value == None: value = len(this._binary) + this._skipped if symbol[0] == '&': value += this._origin this._symbols.append((symbol, value)) |
From: <pi...@us...> - 2003-03-30 19:13:35
|
Update of /cvsroot/wisp/wisp/users/pisi In directory sc8-pr-cvs1:/tmp/cvs-serv5023 Added Files: alterego.c Log Message: alterego hack added --- NEW FILE: alterego.c --- /* alterego.c - keep a process running and handle signals/children as wisp doesn't have correct signaling support and is not SO well suited to run as init - the mother of all processes on a unix system. this is a small wrapper, an "alter ego" or a shadow.. call it whatever, to make a nifty wisp system. this is very linux and wisp and my braindesease specific. it monitors ONE process, restarts it if it quits, and translates a signal to a command that pushes a message into the head of winix message queue. you can send this piece of code two signals: SIGUSR1 - replaces this program with a (posibly) newer version of itself SIGUSR2 - passes /winix/message to winix. this file is public domain, written by a lunatic. */ #include <sys/types.h> #include <sys/wait.h> #include <signal.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #define EGO_LOCATION "/winix/alterego" #define ALTER_EGO_LOCATION "/winix/winix" #define MSG_LOCATION "/winix/msg" pid_t ego; pid_t alter_ego; /* this function replaces the ego with a (possibly) newer one */ int restart_ego (void) { int ego_result; char pid_helper[10]; char *largv[4]; /* we could as well use argv[0] for the executable path.. but hey, who said this code should be nice and perfect? */ snprintf (pid_helper, 9, "%d", alter_ego); largv[0] = EGO_LOCATION; largv[1] = "--alter-ego-pid"; largv[2] = pid_helper; largv[3] = NULL; ego_result = execv (EGO_LOCATION, largv); perror ("Could not restart ego"); return (0); } /* start the alter ego */ int start_alter_ego (void) { int alter_ego_result; char *largv[2]; alter_ego = fork (); if (alter_ego == 0) { /* this is the child, now we exec */ largv[0] = ALTER_EGO_LOCATION; largv[1] = NULL; alter_ego_result = execv (ALTER_EGO_LOCATION, largv); /* we should not get here */ perror ("Could not exec alter ego"); return (0); } else { /* the parent */ if (alter_ego == -1) { perror ("Could not fork alter ego"); return (0); } fprintf (stderr, "Alter ego created: %d\n", alter_ego); return (1); } } int childkiller (void) { pid_t waited_child; int wait_status; while (1) { waited_child = wait (&wait_status); if (waited_child != -1) { if (waited_child == alter_ego) { sleep (1); start_alter_ego (); } } else { if (errno == 10) { printf ("No more children. exiting.\n"); exit (1); } perror ("When waiting"); } } } /* send a message to winix */ int msg_winix (void) { pid_t msg_prgrm; int msg_status; char *largv[4]; largv[0] = MSG_LOCATION; largv[1] = "winix@localhost"; largv[2] = "/winix/message"; largv[3] = NULL; msg_prgrm = fork (); if (msg_prgrm == 0) { /* this is the child, now we exec */ msg_status = execv (MSG_LOCATION, largv); /* we should not get here */ perror ("Could not exec msngr"); return (0); } else { /* the parent */ if (msg_prgrm == -1) { perror ("Could not fork msnger"); return (0); } /* the msg program must be a quickie waitpid(msg_prgrm,NULL,NULL); */ return (1); } } void signal_handler (int signum) { switch (signum) { case SIGUSR1: restart_ego (); break; case SIGUSR2: msg_winix (); break; default: fprintf (stderr, "Don't know how to handle signal %d\n", signum); } } int main (int argc, char *argv[], char *envp[]) { int do_start_alter_ego = 1; struct sigaction act; ego = getpid (); if (ego != 1) { fprintf (stderr, "You should not run this thing as a normal process.\n"); exit (1); } if (argc > 1) { if (!strcmp (argv[1], "--alter-ego-pid")) { do_start_alter_ego = 0; alter_ego = atoi (argv[2]); fprintf (stderr, "Refreshing, alter ego is %d\n", alter_ego); } } if (do_start_alter_ego) start_alter_ego (); /* the most important part - signals */ act.sa_handler = signal_handler; /* block all other signals when handling one */ sigfillset (&act.sa_mask); if (sigaction (SIGUSR1, &act, NULL) < 0) { perror ("sigaction failed"); exit (1); } if (sigaction (SIGUSR2, &act, NULL) < 0) { perror ("sigaction failed"); exit (1); } /* get rid of children */ childkiller (); /* we should never exit from here */ fprintf (stderr, "Sitt lugu, valge mees..."); exit (1); } |
From: <di...@us...> - 2003-03-24 21:18:19
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv20661/users/dig Modified Files: Makefile.am elf.py linkie.py make-pe-exe.py makehello.py Log Message: improved linkie labeling Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 9 Feb 2003 09:31:12 -0000 1.5 +++ Makefile.am 24 Mar 2003 21:18:12 -0000 1.6 @@ -12,4 +12,4 @@ all: clean: clean-am - -rm -f *~ *.pyc *.pyo + -rm -f *~ *.pyc *.pyo hello Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- elf.py 14 Mar 2003 19:01:16 -0000 1.13 +++ elf.py 24 Mar 2003 21:18:13 -0000 1.14 @@ -336,50 +336,54 @@ raise 'Invalid byte order', byte_order h.emit_byte(EV.CURRENT) h.emit_string('\0' * 9) - h.emit_wyde_sum(['elf/type']) - h.emit_wyde_sum(['elf/machine']) + h.emit_wyde_sum(['#elf/type']) + h.emit_wyde_sum(['#elf/machine']) h.emit_tetra(EV.CURRENT) h.emit_tetra_sum(['&_start']) - h.emit_tetra_sum(['elf/phoff']) - h.emit_tetra_sum(['elf/shoff']) - h.emit_tetra_sum(['elf/flags']) + h.emit_tetra_sum(['!elf/proghdr']) + h.emit_tetra_sum(['!elf/secthdr']) + h.emit_tetra_sum(['#elf/flags']) h.emit_wyde(0x34) # e_ehsize h.emit_wyde(32) # e_phentsize - h.emit_wyde_sum(['elf/phnum']) + h.emit_wyde_sum(['#elf/phnum']) h.emit_wyde(40) # e_shentsize - h.emit_wyde_sum(['elf/shnum']) - h.emit_wyde_sum(['elf/shstrndx']) + h.emit_wyde_sum(['#elf/shnum']) + h.emit_wyde_sum(['#elf/shstrndx']) return h def make_ELF32_phtable (byte_order, names): t = Linkie(byte_order) t.align(4) + t.place_symbol('!elf/proghdr') for name in names: - t.emit_tetra_sum([name + '/p_type']) - t.emit_tetra_sum([name + '/offset']) - t.emit_tetra_sum([name]) # p_vaddr - t.emit_tetra_sum([name]) # p_paddr - t.emit_tetra_sum([name + '/filesz']) - t.emit_tetra_sum([name + '/memsz']) - t.emit_tetra_sum([name + '/p_flags']) - t.emit_tetra_sum([name + '/p_align']) + t.emit_tetra_sum(['#' + name + '/p_type']) + t.emit_tetra_sum(['!' + name]) # offset + t.emit_tetra_sum(['&' + name]) # p_vaddr + t.emit_tetra_sum(['&' + name]) # p_paddr + t.emit_tetra_sum(['#' + name + '/filesz']) + t.emit_tetra_sum(['#' + name + '/memsz']) + t.emit_tetra_sum(['#' + name + '/p_flags']) + t.emit_tetra_sum(['#' + name + '/p_align']) + t.place_symbol('#elf/phnum', len(names)) return t def make_ELF32_shtable (byte_order, names): t = Linkie(byte_order) t.align(4) + t.place_symbol('!elf/secthdr') t.emit_string('\0' * 40) # the null entry for name in names: - t.emit_tetra_sum(['.shstrtab/strings/' + name]) - t.emit_tetra_sum([name + '/sh_type']) - t.emit_tetra_sum([name + '/sh_flags']) - t.emit_tetra_sum([name]) - t.emit_tetra_sum([name + '/offset']) - t.emit_tetra_sum([name + '/sh_size']) - t.emit_tetra_sum([name + '/sh_link']) - t.emit_tetra_sum([name + '/sh_info']) - t.emit_tetra_sum([name + '/sh_align']) - t.emit_tetra_sum([name + '/sh_entsize']) + t.emit_tetra_sum(['#.shstrtab/strings/' + name]) + t.emit_tetra_sum(['#' + name + '/sh_type']) + t.emit_tetra_sum(['#' + name + '/sh_flags']) + t.emit_tetra_sum(['&' + name]) + t.emit_tetra_sum(['!' + name]) + t.emit_tetra_sum(['#' + name + '/sh_size']) + t.emit_tetra_sum(['#' + name + '/sh_link']) + t.emit_tetra_sum(['#' + name + '/sh_info']) + t.emit_tetra_sum(['#' + name + '/sh_align']) + t.emit_tetra_sum(['#' + name + '/sh_entsize']) + t.place_symbol('#elf/shnum', len(names) + 1) return t # Thoughts of generating ELF32 files Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- linkie.py 14 Mar 2003 07:01:05 -0000 1.18 +++ linkie.py 24 Mar 2003 21:18:13 -0000 1.19 @@ -144,15 +144,15 @@ """place_symbol(symbol, value = None) => value Places a globally visible symbol in the linkie. Takes care of adding the base address if the symbol - starts in '&' or '$'. + starts in '&'. Does NOT check uniqueness. None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol - if not symbol[0] in '#&$!': + if not symbol[0] in '#&!': # FIXME: backwards compatibility print 'WARNING: unprefixed symbol', symbol, 'being placed' if value == None: value = len(this._binary) + this._skipped - if symbol[0] in '&$': value += this._origin + if symbol[0] == '&': value += this._origin this._symbols.append((symbol, value)) return value def align (this, boundary): @@ -172,8 +172,8 @@ def set_origin (this, origin): """set_origin(origin) Sets the base address of the linkie to the specified value. - Recalculates the &foo and $foo symbols. Does NOT influence - already resolved references to changing labels, so be careful + Recalculates the &foo symbols. Does NOT influence already + resolved references to changing labels, so be careful if using after partial linkage.""" if (origin % this._alignment) != 0: raise 'New base address violates alignment', \ @@ -181,7 +181,7 @@ delta = origin - this._origin for i in range(len(this._symbols)): symbol, value = this._symbols[i] - if symbol[0] in '&$': + if symbol[0] == '&': this._symbols[i] = symbol, value + delta this._origin = origin @@ -237,41 +237,70 @@ that._linker_notes = this._linker_notes[:] that._origin = this._origin return that - def fall (this): - # forces the base address to zero and converts $foo to !foo - for sym, val in this._symbols: - if sym[0] == '$': - this._symbols.append(('!' + sym[1:], val - this._origin)) - this._origin = 0 def extend (this, that): # Returns the offset of /that/ inside /this/ after extension. if this._unresolved_locals: raise 'Incomplete linkie', this if that._unresolved_locals: raise 'Incomplete linkie', that - if this._origin != 0: - this.fall() + this._origin = 0 if that.filesz(): this.deskip() this.align(that._alignment) delta = this.memsz() - that._origin this._binary.extend(that._binary) this._skipped = that._skipped for sym, val in that._symbols: - if sym[0] in '#&$!': + if sym[0] in '#&!': this._symbols.append((sym, val)) else: # FIXME: backwards compatibility print 'WARNING: unprefixed symbol', sym this._symbols.append((sym, val + delta)) - if sym[0] == '$': - this._symbols.append(('!' + sym[1:], val + delta)) for ofs, typ, arg in that._linker_notes: this._linker_notes.append((ofs + delta, typ, arg)) return delta + def paste (this, offset, that): + # Pastes /that/ into /this/ at specified /offset/ (if negative + # /offset/ is treated as an alignment restriction and the actual + # offset is automatically calculated from that). + # Note that the specified alignment of /that/ is IGNORED. + # Origin of /this/ *should* be zero. + + if this._unresolved_locals: raise 'Incomplete linkie', this + if that._unresolved_locals: raise 'Incomplete linkie', that + + # provide sufficient padding + if offset < 0: this.align(- offset) + else: this.skip(offset - this.memsz()) + + # convert any padding to hard zeroes if needed + if that.filesz(): this.deskip() + + # remember the start offset of /that/ + thatofs = this.memsz() + + # carry over all the bits + this._binary.extend(that._binary) + this._skipped = that._skipped + + # carry over and process the symbols + for sym, val in that._symbols: + if sym[0] == '!': + this._symbols.append((sym, val + thatofs)) + elif sym[0] in '#&': + this._symbols.append((sym, val)) + else: + raise 'unprefixed symbol', sym + + # carry over the linker notes + for ofs, typ, arg in that._linker_notes: + this._linker_notes.append((ofs + thatofs, typ, arg)) + # return nothing def __add__ (this, that): this = this.copy() this.extend(that) return this - def link (this, symbols): + def link (this): + symbols = this.get_symbol_dict() i = len(this._linker_notes) while i > 0: i = i - 1 @@ -295,7 +324,7 @@ rsymbols = {}; othersymbols = [] rnotes = {}; othernotes = [] for sym, val in this._symbols: - if sym[0] in '&$': val -= this._origin + if sym[0] == '&': val -= this._origin if sym[0] != '#' and 0 <= val < this.memsz(): if rsymbols.has_key(val): rsymbols[val].append(sym) else: rsymbols[val] = [sym] Index: make-pe-exe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- make-pe-exe.py 9 Mar 2003 14:20:59 -0000 1.1 +++ make-pe-exe.py 24 Mar 2003 21:18:13 -0000 1.2 @@ -61,7 +61,7 @@ b.emit_string(message) b.place_symbol('#mz/bytes-in-last-block', b.filesz() % 0x200) b.place_symbol('#mz/blocks-in-file', (b.filesz() + 0x1FF) / 0x200) - b.link(b.get_symbol_dict()) + b.link() return b p = make_mz_prefix('OS too broken') Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- makehello.py 14 Mar 2003 19:01:18 -0000 1.14 +++ makehello.py 24 Mar 2003 21:18:13 -0000 1.15 @@ -81,17 +81,18 @@ return p_flags def make_executable (text = None, data = None, memory_bottom = 0x08048000): + # Will set given sections' origins. + sections = {} sections['.text'] = code sections['.data'] = data - symbols = {} binary = Linkie('<') memory_boundary = memory_bottom # must be at page boundary - binary.extend(make_ELF32_header('<')) - symbols['elf/type'] = ET.EXEC - symbols['elf/machine'] = EM.I386 - symbols['elf/flags'] = 0 # no flags for ia386 + binary.paste(0, make_ELF32_header('<')) + binary.place_symbol('#elf/type', ET.EXEC) + binary.place_symbol('#elf/machine', EM.I386) + binary.place_symbol('#elf/flags', 0) # no flags for ia386 shentnames = ['.text', '.data', '.symstr', '.symtab', '.shstrtab'] @@ -109,81 +110,76 @@ for name in shentnames: if guess_pflags(name) <> 0: phentnames.append(name) - symbols['.shstrtab/strings/' + name] = sections['.shstrtab'].filesz() + sections['.shstrtab'].place_symbol('#.shstrtab/strings/' + name) sections['.shstrtab'].emit_string(name) sections['.shstrtab'].emit_byte(0) program_header_table = make_ELF32_phtable('<', phentnames) - symbols['elf/phoff'] = binary.extend(program_header_table) - symbols['elf/phnum'] = len(phentnames) + binary.paste(-4, program_header_table) for name in shentnames: section = sections[name] p_flags = guess_pflags(name) alignment = section.get_alignment() - symbols[name + '/sh_align'] = alignment + binary.place_symbol('#' + name + '/sh_align', alignment) if p_flags <> 0: - symbols[name + '/p_align'] = 0x1000 + binary.place_symbol('#' + name + '/p_align', 0x1000) binary.align(min(alignment, 0x1000)) else: # No program header entry => not loaded # thusly no larger alignment necessary. binary.align(min(alignment, 4)) - binary.place_symbol(name) offset = binary.filesz() if p_flags <> 0: address = memory_boundary | (offset & 0xFFF) # take into account alignments larger than a page address = (address + alignment - 1) & ~(alignment - 1) - symbols[name + '/p_flags'] = guess_pflags(name) - symbols[name + '/p_type'] = guess_ptype(name) - symbols[name] = address + binary.place_symbol('#' + name + '/p_flags', guess_pflags(name)) + binary.place_symbol('#' + name + '/p_type', guess_ptype(name)) + section.set_origin(address) + binary.place_symbol('&' + name, address) else: address = None - symbols[name] = 0 - symbols[name + '/offset'] = offset - symbols[name + '/memsz'] = section.memsz() - symbols[name + '/filesz'] = section.filesz() - symbols[name + '/sh_size'] = section.filesz() - symbols[name + '/sh_type'] = guess_shtype(name) - symbols[name + '/sh_info'] = 0 - symbols[name + '/sh_link'] = SHN.UNDEF - symbols[name + '/sh_entsize'] = 0 - symbols[name + '/sh_flags'] = guess_shflags(name) + binary.place_symbol('#' + name + '/memsz', section.memsz()) + binary.place_symbol('#' + name + '/filesz', section.filesz()) + binary.place_symbol('#' + name + '/sh_size', section.filesz()) + binary.place_symbol('#' + name + '/sh_type', guess_shtype(name)) + binary.place_symbol('#' + name + '/sh_info', 0) + if name == '.symtab': sh_link = shentnames.index('.symstr') + 1 + else: sh_link = SHN.UNDEF + binary.place_symbol('#' + name + '/sh_link', sh_link) + binary.place_symbol('#' + name + '/sh_entsize', 0) + binary.place_symbol('#' + name + '/sh_flags', guess_shflags(name)) - binary.from_array(section.get_file()) - if address <> None: - for symbol, value in section.get_symbols(): - symbols[symbol] = address + value + # alignment has been processed already + binary.place_symbol('!' + name) + binary.paste(-1, section) for symbol, value in section.get_symbols(): if symbol[0] != '&': continue # only process memory references - sofs = sections['.symstr'].filesz() - symbols['.symstr/strings/' + symbol] = sofs + symbol = symbol[1:] # but not their prefixen + symstr = sections['.symstr'] + symstr.place_symbol('#.symstr/strings/' + symbol) sections['.symstr'].emit_string(symbol) sections['.symstr'].emit_byte(0) - sections['.symtab'].emit_tetra(sofs) - sections['.symtab'].emit_tetra_sum([name]) + sections['.symtab'].emit_tetra_sum(['#.symstr/strings/' + symbol]) + sections['.symtab'].emit_tetra_sum(['&' + name]) sections['.symtab'].emit_tetra(0) sections['.symtab'].emit_byte(STB.GLOBAL << 4 | STT.NOTYPE) sections['.symtab'].emit_byte(0) sections['.symtab'].emit_wyde(shentnames.index(name) + 1) - for loc, typ, arg in section.get_notes(): - binary.notify_linker(offset + loc, typ, arg) memory_boundary += section.memsz() memory_boundary = (memory_boundary + 0xFFF) & ~0xFFF # create section header table section_header_table = make_ELF32_shtable('<', shentnames) - symbols['elf/shoff'] = binary.extend(section_header_table) - symbols['elf/shnum'] = len(shentnames) + 1 - symbols['elf/shstrndx'] = shentnames.index('.shstrtab') + 1 - symbols['.symtab/sh_link'] = shentnames.index('.symstr') + 1 - binary.link(symbols) + binary.paste(-4, section_header_table) + binary.place_symbol('#elf/shstrndx', shentnames.index('.shstrtab') + 1) + binary.link() return binary hello = make_executable(text = code, data = data) |
From: <di...@us...> - 2003-03-14 19:01:25
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv8594 Modified Files: elf.py makehello.py Log Message: prepare ELF-linking for usage of the origin feature Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- elf.py 17 Feb 2003 20:27:18 -0000 1.12 +++ elf.py 14 Mar 2003 19:01:16 -0000 1.13 @@ -339,7 +339,7 @@ h.emit_wyde_sum(['elf/type']) h.emit_wyde_sum(['elf/machine']) h.emit_tetra(EV.CURRENT) - h.emit_tetra_sum(['_start']) + h.emit_tetra_sum(['&_start']) h.emit_tetra_sum(['elf/phoff']) h.emit_tetra_sum(['elf/shoff']) h.emit_tetra_sum(['elf/flags']) Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- makehello.py 25 Feb 2003 20:28:33 -0000 1.13 +++ makehello.py 14 Mar 2003 19:01:18 -0000 1.14 @@ -19,9 +19,9 @@ return m code = Linkie('<') # ia32 -code.place_symbol('_start') +code.place_symbol('&_start') code.emit_byte(0xBA); code.emit_tetra(14) # mov edx, 14 -code.emit_byte(0xB9); code.emit_tetra_sum(['message']) # mov ecx, message +code.emit_byte(0xB9); code.emit_tetra_sum(['&message']) # mov ecx, message code.emit_byte(0xBB); code.emit_tetra(1) # mov ebx, 1 code.emit_byte(0xB8); code.emit_tetra(4) # mov eax, 4 code.emit_byte(0xCD); code.emit_byte(0x80) # int 0x80 @@ -30,7 +30,7 @@ code.emit_byte(0xCD); code.emit_byte(0x80) # int 0x80 data = Linkie('<') # ia32 -data.place_symbol('message') +data.place_symbol('&message') data.emit_string('Hello, world!\n') def infer_by_prefix (name, dict): @@ -160,7 +160,7 @@ for symbol, value in section.get_symbols(): symbols[symbol] = address + value for symbol, value in section.get_symbols(): - binary.place_symbol(symbol, offset + value) # for dump to work nicely + if symbol[0] != '&': continue # only process memory references sofs = sections['.symstr'].filesz() symbols['.symstr/strings/' + symbol] = sofs sections['.symstr'].emit_string(symbol) |
From: <di...@us...> - 2003-03-14 07:01:13
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv14233 Modified Files: linkie.py Log Message: made Linkie.place_symbol warn when placing unprefixed symbols Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- linkie.py 9 Mar 2003 20:12:38 -0000 1.17 +++ linkie.py 14 Mar 2003 07:01:05 -0000 1.18 @@ -148,6 +148,9 @@ Does NOT check uniqueness. None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol + if not symbol[0] in '#&$!': + # FIXME: backwards compatibility + print 'WARNING: unprefixed symbol', symbol, 'being placed' if value == None: value = len(this._binary) + this._skipped if symbol[0] in '&$': value += this._origin this._symbols.append((symbol, value)) |
From: <di...@us...> - 2003-03-10 15:39:54
|
Update of /cvsroot/wisp/wisp In directory sc8-pr-cvs1:/tmp/cvs-serv28356 Modified Files: wisplint.wisp Log Message: do not check users/pisi/** for lint Index: wisplint.wisp =================================================================== RCS file: /cvsroot/wisp/wisp/wisplint.wisp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- wisplint.wisp 7 Feb 2003 09:10:30 -0000 1.25 +++ wisplint.wisp 10 Mar 2003 15:39:49 -0000 1.26 @@ -89,7 +89,8 @@ (for-each (lambda (name) (if (not (or (char=? (ref name -1) #\~) - (member name '("src/essence.c") string=?))) + (member name '("src/essence.c") string=?) + (string=? name[... 11] "users/pisi/"))) (begin (print "Scanning $,[name] \e[80P\r") ; not a smiley (my suffix (filename-suffix name) |
From: <di...@us...> - 2003-03-09 20:12:46
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv17753 Modified Files: linkie.py Log Message: implemented $foo -> !foo conversion Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- linkie.py 9 Mar 2003 19:33:24 -0000 1.16 +++ linkie.py 9 Mar 2003 20:12:38 -0000 1.17 @@ -234,17 +234,32 @@ that._linker_notes = this._linker_notes[:] that._origin = this._origin return that + def fall (this): + # forces the base address to zero and converts $foo to !foo + for sym, val in this._symbols: + if sym[0] == '$': + this._symbols.append(('!' + sym[1:], val - this._origin)) + this._origin = 0 def extend (this, that): # Returns the offset of /that/ inside /this/ after extension. if this._unresolved_locals: raise 'Incomplete linkie', this if that._unresolved_locals: raise 'Incomplete linkie', that + if this._origin != 0: + this.fall() if that.filesz(): this.deskip() this.align(that._alignment) - delta = this.memsz() + delta = this.memsz() - that._origin this._binary.extend(that._binary) this._skipped = that._skipped for sym, val in that._symbols: - this._symbols.append((sym, val + delta)) + if sym[0] in '#&$!': + this._symbols.append((sym, val)) + else: + # FIXME: backwards compatibility + print 'WARNING: unprefixed symbol', sym + this._symbols.append((sym, val + delta)) + if sym[0] == '$': + this._symbols.append(('!' + sym[1:], val + delta)) for ofs, typ, arg in that._linker_notes: this._linker_notes.append((ofs + delta, typ, arg)) return delta |
From: <di...@us...> - 2003-03-09 19:33:27
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv1458 Modified Files: linkie.py Log Message: made the $ symbol prefix behave like the & prefix currently does Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- linkie.py 9 Mar 2003 13:39:46 -0000 1.15 +++ linkie.py 9 Mar 2003 19:33:24 -0000 1.16 @@ -143,12 +143,13 @@ def place_symbol (this, symbol, value = None): """place_symbol(symbol, value = None) => value Places a globally visible symbol in the linkie. - Takes care of adding the base address if the symbol starts in '&'. + Takes care of adding the base address if the symbol + starts in '&' or '$'. 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 - if symbol[0] == '&': value += this._origin + if symbol[0] in '&$': value += this._origin this._symbols.append((symbol, value)) return value def align (this, boundary): @@ -168,16 +169,16 @@ def set_origin (this, origin): """set_origin(origin) Sets the base address of the linkie to the specified value. - Recalculates the &foo symbols. Does NOT influence already - resolved references to changing labels, so be careful if - using after partial linkage.""" + Recalculates the &foo and $foo symbols. Does NOT influence + already resolved references to changing labels, so be careful + if using after partial linkage.""" if (origin % this._alignment) != 0: raise 'New base address violates alignment', \ (boundary, this._origin) delta = origin - this._origin for i in range(len(this._symbols)): symbol, value = this._symbols[i] - if symbol[0] == '&': + if symbol[0] in '&$': this._symbols[i] = symbol, value + delta this._origin = origin @@ -276,7 +277,7 @@ rsymbols = {}; othersymbols = [] rnotes = {}; othernotes = [] for sym, val in this._symbols: - if sym[0] == '&': val -= this._origin + if sym[0] in '&$': val -= this._origin if sym[0] != '#' and 0 <= val < this.memsz(): if rsymbols.has_key(val): rsymbols[val].append(sym) else: rsymbols[val] = [sym] |
From: <di...@us...> - 2003-03-09 14:52:34
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv17466 Added Files: make-pe-exe.py Log Message: added make-pe-exe.py --- NEW FILE: make-pe-exe.py --- #! /usr/bin/python #### make-pe-exe.py - create a PE-format EXE file # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: make-pe-exe.py,v 1.1 2003/03/09 14:20:59 digg Exp $ from linkie import Linkie import time # This file is *very* incomplete def make_mz_prefix (message = 'OS too broken'): if message.find('$') != -1: raise 'MZ message may not contain dollar signs', message if message.find('\r') == -1: # if no CRs, insert them message = '\r\n'.join(message.split('\n')) b = Linkie('<') b.set_origin(0x100) b.emit_string('MZ') # 'MZ' b.emit_wyde_sum(['#mz/bytes-in-last-block']) b.emit_wyde_sum(['#mz/blocks-in-file']) b.emit_wyde(0) # no relocation b.emit_wyde(0) # empty MZ header--load it all into memory b.emit_wyde(0x40) # low memory limit in paragraphs b.emit_wyde(0x40) # high memory limit in paragraphs b.emit_wyde(-0x10) # initial SS b.emit_wyde(0x100) # initial SP in PSP b.emit_wyde(0) # no checksum b.emit_wyde_sum(['&mz/_start']) # initial IP b.emit_wyde(-0x10) # initial CS b.emit_wyde(0) # relocation table offset b.emit_wyde(0) # not an overlay b.place_symbol('&mz/_start') b.emit_string('\x8C\xC8\x8E\xD8') # mov %ax, %cs; mov %ds, mov %ax b.emit_string('\xB4\x09') # mov %ah, 0x09 b.emit_byte(0xBA); b.emit_wyde_sum(['&mz/message']) # mov %dx, message b.emit_string('\xCD\x21') # int 0x21 b.emit_string('\xB8\xFF\x4C\xCD\x21') # mov %ax, 0x4CFF; int 0x21 message += '$' # Dollar the Terminator # a pointer to the PE signature must appear at the offset 0x003C room = 0x003C - b.filesz() if message[0] == '!': room += 1 if len(message) <= room: if message[0] != '!': b.place_symbol('&mz/message') b.emit_string(message) else: b.place_symbol('&mz/message', b.filesz() - 1) b.emit_string(message[1:]) b.emit_string('\x00' * (0x003C - b.filesz())) b.emit_tetra_sum(['mz/pe-offset']) else: b.emit_string('\x00' * (0x003C - b.filesz())) b.emit_tetra_sum(['mz/pe-offset']) b.place_symbol('&mz/message') b.emit_string(message) b.place_symbol('#mz/bytes-in-last-block', b.filesz() % 0x200) b.place_symbol('#mz/blocks-in-file', (b.filesz() + 0x1FF) / 0x200) b.link(b.get_symbol_dict()) return b p = make_mz_prefix('OS too broken') p.get_file().tofile(open('pehello1.exe', 'w')) p = make_mz_prefix('OS too broken:(') p.get_file().tofile(open('pehello2.exe', 'w')) p = make_mz_prefix('OS too broken :(') p.get_file().tofile(open('pehello3.exe', 'w')) p = make_mz_prefix('! OS too broken!') p.get_file().tofile(open('pehello4.exe', 'w')) p = make_mz_prefix('! OS too broken !') p.get_file().tofile(open('pehello5.exe', 'w')) p = make_mz_prefix('A very long message\nspanning several lines.') p.get_file().tofile(open('pehello6.exe', 'w')) p = make_mz_prefix('Many lines spanning several blocks in total.\n' * 40) p.get_file().tofile(open('pehello7.exe', 'w')) |
From: <di...@us...> - 2003-03-09 13:54:32
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9561 Modified Files: .cvsignore Log Message: ignore *.exe Index: .cvsignore =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/.cvsignore,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- .cvsignore 16 Feb 2003 10:48:17 -0000 1.3 +++ .cvsignore 9 Mar 2003 13:54:24 -0000 1.4 @@ -1,3 +1,4 @@ +*.exe *.pyc *.pyo Makefile |
From: <di...@us...> - 2003-03-09 13:39:49
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv5980 Modified Files: linkie.py Log Message: copy the origin attribute too in Linkie.copy Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- linkie.py 9 Mar 2003 13:11:40 -0000 1.14 +++ linkie.py 9 Mar 2003 13:39:46 -0000 1.15 @@ -231,6 +231,7 @@ that._skipped = this._skipped that._symbols = this._symbols[:] that._linker_notes = this._linker_notes[:] + that._origin = this._origin return that def extend (this, that): # Returns the offset of /that/ inside /this/ after extension. |
From: <di...@us...> - 2003-03-09 13:11:43
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv32215 Modified Files: linkie.py Log Message: added origin attributes to the Linkie instances Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- linkie.py 9 Mar 2003 07:10:28 -0000 1.13 +++ linkie.py 9 Mar 2003 13:11:40 -0000 1.14 @@ -18,6 +18,7 @@ this._skipped = 0 # uninitialized space after bits this._locals = [] # label no -> address this._unresolved_locals = [] # order is irrelevant + this._origin = 0 # the base address of this linkie if byte_order == '<': this.emit_wyde = this.emit_lewyde this.emit_tetra = this.emit_letetra @@ -142,22 +143,43 @@ def place_symbol (this, symbol, value = None): """place_symbol(symbol, value = None) => value Places a globally visible symbol in the linkie. + Takes care of adding the base address if the symbol starts in '&'. 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 + if symbol[0] == '&': value += this._origin this._symbols.append((symbol, value)) return value def align (this, boundary): """align(boundary) Ensures that the following byte's memory address is divisible by - the specified boundary (which must be a power of 2).""" + the specified boundary (which must be a power of 2). Error if + the current base address doesn't match the alignment.""" + if (this._origin % boundary) != 0: + raise 'Base address violates new alignment', \ + (this._origin, boundary) if this._alignment < boundary: this._alignment = boundary delta = (boundary - 1) & - (len(this._binary) + this._skipped) if this._skipped: this._skipped += delta else: this._binary.fromstring(delta * '\0') + def set_origin (this, origin): + """set_origin(origin) + Sets the base address of the linkie to the specified value. + Recalculates the &foo symbols. Does NOT influence already + resolved references to changing labels, so be careful if + using after partial linkage.""" + if (origin % this._alignment) != 0: + raise 'New base address violates alignment', \ + (boundary, this._origin) + delta = origin - this._origin + for i in range(len(this._symbols)): + symbol, value = this._symbols[i] + if symbol[0] == '&': + this._symbols[i] = symbol, value + delta + this._origin = origin def get_file (this): """get_file() -> array of chars @@ -198,6 +220,8 @@ Returns a list of the linker notes from the linkie.""" if this._unresolved_locals: raise 'Incomplete linkie', this return this._linker_notes[:] + def get_origin (this): + return this._origin def copy (this): if this._unresolved_locals: raise 'Incomplete linkie', this @@ -244,11 +268,14 @@ filesz = len(this._binary) skipsz = this._skipped memsz = filesz + skipsz - print 'Linkie (0x%x + 0x%x = 0x%x)' % (filesz, skipsz, memsz), + origin = this._origin + print 'Linkie (0x%x + 0x%x = 0x%x @ 0x%x)' % \ + (filesz, skipsz, memsz, origin), print 'aligned at 0x%x' % this._alignment rsymbols = {}; othersymbols = [] rnotes = {}; othernotes = [] for sym, val in this._symbols: + if sym[0] == '&': val -= this._origin if sym[0] != '#' and 0 <= val < this.memsz(): if rsymbols.has_key(val): rsymbols[val].append(sym) else: rsymbols[val] = [sym] |