[Wisp-cvs] wisp/users/dig elf.py,1.36,1.37 tran.py,1.9,1.10
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-15 21:27:35
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9161 Modified Files: elf.py tran.py Log Message: added .bss handling Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- elf.py 14 Apr 2003 22:19:55 -0000 1.36 +++ elf.py 15 Apr 2003 21:27:31 -0000 1.37 @@ -498,14 +498,17 @@ if 'x' in flags: p_flags |= PF.X return p_flags -def make_ELF32_object (text = None, data = None, flags = '', +def make_ELF32_object (text = None, data = None, bss = None, flags = '', memory_bottom = 0x08048000): + # Will set given sections' origins. want_symbols = 's' in flags want_relocatable = 'r' in flags - # Will set given sections' origins. + if bss <> None and bss.filesz() <> 0: + raise '.bss not bitless', bss sections = {} - sections['.text'] = text - sections['.data'] = data + if text <> None: sections['.text'] = text + if data <> None: sections['.data'] = data + if bss <> None: sections['.bss'] = bss binary = Linkie('<') memory_boundary = memory_bottom # must be at page boundary @@ -517,7 +520,10 @@ binary.place_symbol('#elf/machine', EM.I386) binary.place_symbol('#elf/flags', 0) # no flags for ia386 - shentnames = ['.text', '.data'] + shentnames = [] + for s in '.text', '.data', '.bss': + if sections.has_key(s): + shentnames.append(s) if want_symbols or want_relocatable: shentnames += ['.symstr', '.symtab'] sections['.symstr'] = ELF32_strtab('<') Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- tran.py 15 Apr 2003 15:44:09 -0000 1.9 +++ tran.py 15 Apr 2003 21:27:32 -0000 1.10 @@ -62,6 +62,9 @@ else: raise 'Literal expected', n def label (name): cursect.place_symbol('&' + name) +def dot_bss (): + global cursect + cursect = Bss def dot_data (): global cursect cursect = Data @@ -71,6 +74,8 @@ def ref (name): Regstack.append('&' + name) def drop (x): pass +def align (n): cursect.align(n) +def reserve (n): cursect.skip(n) def minor (reg): Regstack.append(long(reg[-1])) def swap (x, y): @@ -193,6 +198,7 @@ # Main output sections. Text = Linkie('<') Data = Linkie('<') +Bss = Linkie('<') cursect = Text Regstack = [] Generic_Register = Register() @@ -203,10 +209,13 @@ Meaning = { '+ int int': ('builtin', plus, 2), '- int int': ('builtin', minus, 2), + '.bss': ('builtin', dot_bss, 0), '.data': ('builtin', dot_data, 0), '.text': ('builtin', dot_text, 0), ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), - ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), + ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), + 'align int': ('builtin', align, 1), + 'reserve int': ('builtin', reserve, 1), 'any': ('simple', ClassMarker('any')), 'b, lit': ('builtin', b_comma, 1), 'drop any': ('builtin', drop, 1), @@ -255,9 +264,11 @@ mainloop() print 'TEXT'; Text.dump() print 'DATA'; Data.dump() + print 'BSS'; Bss.dump() if Regstack: raise 'Regstack not empty after parsing ended', Regstack - binary = elf.make_ELF32_object(text = Text, data = Data, flags = 's') + binary = elf.make_ELF32_object(text = Text, data = Data, bss = Bss, + flags = 's') f = open(output_name, 'w') binary.get_file().tofile(f) f.close() |