wisp-cvs Mailing List for Wisp interpreter (Page 7)
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-05-17 06:44:40
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv10281
Modified Files:
tran-builtins
Log Message:
allow nesting of :regs declarations
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- tran-builtins 17 May 2003 06:08:31 -0000 1.13
+++ tran-builtins 17 May 2003 06:44:35 -0000 1.14
@@ -77,23 +77,29 @@
interpreter.state = record_state
:regs|family
- if Meaning.has_key(family): raise 'duplicate declaration', family
- f = apply(Register, interpreter.regpath)
- Meaning[family] = f
- Registers[f] = family
- interpreter.regpath.append(0)
+ def regs_state0 (family):
+ if Meaning.has_key(family): raise 'duplicate declaration', family
+ f = apply(Register, interpreter.regpath)
+ Meaning[family] = f
+ Registers[f] = family
+ interpreter.regpath.append(0)
+ interpreter.state = regs_state
def regs_state (tok):
- if tok != Semicolon:
- if Meaning.has_key(tok): raise 'duplicate declaration', tok
+ if tok == Semicolon:
+ interpreter.regpath.pop()
+ interpreter.regpath[-1] += 1
+ if len(interpreter.regpath) == 1:
+ interpreter.state = outer_state
+ elif Meaning.has_key(tok):
+ if Meaning[tok] == Meaning[':regs']:
+ interpreter.state = regs_state0
+ else: raise 'duplicate declaration', tok
+ else:
r = apply(Register, interpreter.regpath)
Meaning[tok] = r
Registers[r] = tok
interpreter.regpath[-1] += 1
- else:
- interpreter.state = outer_state
- interpreter.regpath.pop()
- interpreter.regpath[-1] += 1
- interpreter.state = regs_state
+ regs_state0(family)
align int
interpreter.current.align(long(Regstack.pop()))
|
|
From: <di...@us...> - 2003-05-17 06:08:35
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv31572
Modified Files:
mswhello.tran tran-builtins tran.py
Log Message:
replaced current_register_index and current_register_family by interpreter.regpath
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mswhello.tran 17 May 2003 05:37:51 -0000 1.12
+++ mswhello.tran 17 May 2003 06:08:31 -0000 1.13
@@ -8,8 +8,8 @@
\ Don't forget to translate with -fpe
-include ia32
include i80386
+include ia32
include winapi
\ main entry point
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- tran-builtins 17 May 2003 05:42:31 -0000 1.12
+++ tran-builtins 17 May 2003 06:08:31 -0000 1.13
@@ -78,23 +78,21 @@
:regs|family
if Meaning.has_key(family): raise 'duplicate declaration', family
- Register(current_register_family)
- f = Register(current_register_family)
+ f = apply(Register, interpreter.regpath)
Meaning[family] = f
Registers[f] = family
- current_register_index = 0
+ interpreter.regpath.append(0)
def regs_state (tok):
- global current_register_family, current_register_index
if tok != Semicolon:
if Meaning.has_key(tok): raise 'duplicate declaration', tok
- r = Register(current_register_family, current_register_index)
+ r = apply(Register, interpreter.regpath)
Meaning[tok] = r
Registers[r] = tok
- current_register_index += 1
+ interpreter.regpath[-1] += 1
else:
interpreter.state = outer_state
- current_register_family += 1
- current_register_index = None
+ interpreter.regpath.pop()
+ interpreter.regpath[-1] += 1
interpreter.state = regs_state
align int
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- tran.py 17 May 2003 05:48:12 -0000 1.81
+++ tran.py 17 May 2003 06:08:31 -0000 1.82
@@ -260,13 +260,11 @@
np = (name + '|').split('|')
name = np[0]
pa = np[1]
- g = 'Regstack, current_register_index'
- exec 'def _p (%s):\n global %s\n%s\n' % (pa, g, code)
+ exec 'def _p (%s):\n global Regstack\n%s\n' % (pa, code)
flags = 0
if pa: flags |= MA_PREFIX
Meaning[name] = 'builtin', _p, flags
-current_register_family = 0
Registers = {Generic_Register: 'reg'} # for reverse translation
class container (object): pass
@@ -278,6 +276,7 @@
interpreter.bss = Linkie('<')
interpreter.current = interpreter.text
interpreter.recordee = None
+interpreter.regpath = [0] # for generating new registers
default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'}
verbose = 0
|
|
From: <di...@us...> - 2003-05-17 05:52:52
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv26898 Modified Files: i80386.tran Log Message: syntax highlighting Index: i80386.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/i80386.tran,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- i80386.tran 17 May 2003 05:37:51 -0000 1.1 +++ i80386.tran 17 May 2003 05:52:49 -0000 1.2 @@ -10,3 +10,5 @@ \ registers :regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; + +\ vim: ft=tran |
|
From: <di...@us...> - 2003-05-17 05:48:15
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv25638
Modified Files:
linkie.py tran.py
Log Message:
added the title argument to Linkie.dump
Index: linkie.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- linkie.py 13 May 2003 13:42:34 -0000 1.61
+++ linkie.py 17 May 2003 05:48:12 -0000 1.62
@@ -254,13 +254,13 @@
del this._linker_notes[i]
return len(this._linker_notes)
- def dump (this):
+ def dump (this, title = 'some-linkie'):
filesz = len(this._contents)
skipsz = this._skipped
memsz = filesz + skipsz
- print 'Linkie (0x%x + 0x%x = 0x%x)' % \
- (filesz, skipsz, memsz),
- print 'aligned at 0x%x' % this._alignment
+ print '%s (0x%x + 0x%x = 0x%x)' % (title, filesz, skipsz, memsz),
+ if this._alignment != 1: print 'aligned at 0x%x' % this._alignment,
+ print
rsymbols = {}; othersymbols = []
rnotes = {}; othernotes = []
for sym, val in this._symbols:
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- tran.py 17 May 2003 05:42:30 -0000 1.80
+++ tran.py 17 May 2003 05:48:12 -0000 1.81
@@ -312,9 +312,9 @@
if verbose: print '(%s) %s' % (' '.join(map(str, Regstack)), tok)
interpreter.state(tok)
tok = prep.get_token()
- print 'TEXT'; interpreter.text.dump()
- print 'DATA'; interpreter.data.dump()
- print 'BSS'; interpreter.bss.dump()
+ interpreter.text.dump(title = 'TEXT')
+ interpreter.data.dump(title = 'DATA')
+ interpreter.bss.dump(title = 'BSS')
if Regstack:
raise 'Regstack not empty after parsing ended', Regstack
if format == 'elf':
|
|
From: <di...@us...> - 2003-05-17 05:42:33
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv24175
Modified Files:
tran.py tran-builtins
Log Message:
renamed current_recordee to interpreter.recordee
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- tran.py 17 May 2003 05:38:46 -0000 1.79
+++ tran.py 17 May 2003 05:42:30 -0000 1.80
@@ -260,13 +260,12 @@
np = (name + '|').split('|')
name = np[0]
pa = np[1]
- g = 'Regstack, current_recordee, current_register_index'
+ g = 'Regstack, current_register_index'
exec 'def _p (%s):\n global %s\n%s\n' % (pa, g, code)
flags = 0
if pa: flags |= MA_PREFIX
Meaning[name] = 'builtin', _p, flags
-current_recordee = None
current_register_family = 0
Registers = {Generic_Register: 'reg'} # for reverse translation
@@ -278,6 +277,7 @@
interpreter.data = Linkie('<')
interpreter.bss = Linkie('<')
interpreter.current = interpreter.text
+interpreter.recordee = None
default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'}
verbose = 0
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- tran-builtins 17 May 2003 05:37:51 -0000 1.11
+++ tran-builtins 17 May 2003 05:42:31 -0000 1.12
@@ -67,14 +67,13 @@
name = ' '.join([name] + [matchers(i).next() for i in Regstack])
Regstack = []
if Meaning.has_key(name): raise 'duplicate declaration', name
- current_recordee = Meaning[name] = []
+ interpreter.recordee = Meaning[name] = []
def record_state (tok):
- global current_recordee
if tok == Semicolon:
interpreter.state = outer_state
- current_recordee = None
+ interpreter.recordee = None
else:
- current_recordee.append(tok)
+ interpreter.recordee.append(tok)
interpreter.state = record_state
:regs|family
|
|
From: <di...@us...> - 2003-05-17 05:38:49
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv23237
Modified Files:
tran.py
Log Message:
dropped Register.child_generator
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- tran.py 17 May 2003 05:37:51 -0000 1.78
+++ tran.py 17 May 2003 05:38:46 -0000 1.79
@@ -158,11 +158,6 @@
def parent (this):
if len(this): return apply(Register, this[:-1])
else: return None
- def child_generator (this):
- i = 0
- while 1:
- yield apply(Register, this + (i,))
- i += 1
def __repr__ (this):
return 'Register' + tuple.__repr__(this)
def __str__ (this):
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv22992
Modified Files:
Makefile.am hello.tran ia32.tran mswhello.tran tran-builtins
tran.py
Added Files:
i80386.tran
Log Message:
extracted i80386.tran from ia32.tran
--- NEW FILE: i80386.tran ---
\\\\ i80386.tran - Intel's 80386 instructions
\
\ 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: i80386.tran,v 1.1 2003/05/17 05:37:51 digg Exp $
include i8086
\ registers
:regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ;
Index: Makefile.am
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile.am 17 May 2003 04:45:02 -0000 1.14
+++ Makefile.am 17 May 2003 05:37:51 -0000 1.15
@@ -8,7 +8,7 @@
EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \
coff.py elf.py pe.py \
- i8086.tran ia32.tran hello.tran winapi.tran mswhello.tran \
+ i8086.tran i80386.tran ia32.tran hello.tran winapi.tran mswhello.tran \
makehello.py elfdump.py
all:
Index: hello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/hello.tran,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hello.tran 16 Apr 2003 07:58:57 -0000 1.2
+++ hello.tran 17 May 2003 05:37:51 -0000 1.3
@@ -8,6 +8,7 @@
\ This file is intended to be processed using tran.py
+include i80386
include ia32
\ main entry point
Index: ia32.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ia32.tran 17 May 2003 05:28:17 -0000 1.10
+++ ia32.tran 17 May 2003 05:37:51 -0000 1.11
@@ -6,9 +6,6 @@
\
\\\\ @(#) $Id$
-\ registers
-:regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ;
-
\ These are prefixes for 32-bit mode
:[ ] $o16 #x66 b, ;
:[ ] $o32 ;
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mswhello.tran 17 May 2003 04:26:58 -0000 1.11
+++ mswhello.tran 17 May 2003 05:37:51 -0000 1.12
@@ -9,6 +9,7 @@
\ Don't forget to translate with -fpe
include ia32
+include i80386
include winapi
\ main entry point
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- tran-builtins 17 May 2003 05:08:44 -0000 1.10
+++ tran-builtins 17 May 2003 05:37:51 -0000 1.11
@@ -78,7 +78,7 @@
interpreter.state = record_state
:regs|family
- if Meaning.has_key(family): raise 'duplicate declaration', tok
+ if Meaning.has_key(family): raise 'duplicate declaration', family
Register(current_register_family)
f = Register(current_register_family)
Meaning[family] = f
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- tran.py 17 May 2003 05:08:44 -0000 1.77
+++ tran.py 17 May 2003 05:37:51 -0000 1.78
@@ -247,7 +247,6 @@
Regstack = []
Generic_Register = Register()
-reggen = Generic_Register.child_generator()
MA_PREFIX = 1
Meaning = {'reg': Generic_Register,
|
|
From: <di...@us...> - 2003-05-17 05:28:20
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv20395 Modified Files: ia32.tran Log Message: introduced the $osize macro Index: ia32.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- ia32.tran 17 May 2003 05:17:42 -0000 1.9 +++ ia32.tran 17 May 2003 05:28:17 -0000 1.10 @@ -6,14 +6,19 @@ \ \\\\ @(#) $Id$ +\ registers +:regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; + \ These are prefixes for 32-bit mode :[ ] $o16 #x66 b, ; :[ ] $o32 ; :[ ] $a16 #x67 b, ; :[ ] $a32 ; -\ registers -:regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; +:[ reg32 ] $osize ; \ or $o32 +:[ reg16 ] $osize #x66 b, ; \ or $o16 + +\ instructions :[ reg32 lit ] $mov $o32 swap minor #o270 + b, t, ; :[ reg32 ] $push minor #o120 + b, ; |
|
From: <di...@us...> - 2003-05-17 05:17:45
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv17459 Modified Files: ia32.tran i8086.tran Log Message: moved |$int lit| from ia32.tran to i8086.tran Index: ia32.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ia32.tran 17 May 2003 05:08:44 -0000 1.8 +++ ia32.tran 17 May 2003 05:17:42 -0000 1.9 @@ -15,7 +15,6 @@ \ registers :regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; -:[ lit ] $int #xCD b, b, ; :[ reg32 lit ] $mov $o32 swap minor #o270 + b, t, ; :[ reg32 ] $push minor #o120 + b, ; Index: i8086.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/i8086.tran,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- i8086.tran 17 May 2003 04:45:02 -0000 1.1 +++ i8086.tran 17 May 2003 05:17:42 -0000 1.2 @@ -11,6 +11,10 @@ \ or ia32, too in the future to specify the mode. \ registers - :regs reg16 %ax %cx %dx %bx %sp %bp %si %di ; :regs reg8 %al %cl %dl %bl %ah %ch %dh %bh ; + +\ instructions +:[ lit ] $int #xCD b, b, ; + +\ vim: ft=tran |
|
From: <di...@us...> - 2003-05-17 05:08:47
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv14945
Modified Files:
ia32.tran tran-builtins tran.py winapi.tran
Log Message:
created clearer patterned macro syntax
Index: ia32.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ia32.tran 17 May 2003 04:45:02 -0000 1.7
+++ ia32.tran 17 May 2003 05:08:44 -0000 1.8
@@ -7,19 +7,21 @@
\\\\ @(#) $Id$
\ These are prefixes for 32-bit mode
-:macro $o16 #x66 b, ;
-:macro $o32 ;
-:macro $a16 #x67 b, ;
-:macro $a32 ;
+:[ ] $o16 #x66 b, ;
+:[ ] $o32 ;
+:[ ] $a16 #x67 b, ;
+:[ ] $a32 ;
\ registers
:regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ;
-// lit :macro $int #xCD b, b, ;
-// reg32 lit :macro $mov $o32 swap minor #o270 + b, t, ;
-// reg32 :macro $push minor #o120 + b, ;
+:[ lit ] $int #xCD b, b, ;
+:[ reg32 lit ] $mov $o32 swap minor #o270 + b, t, ;
+:[ reg32 ] $push minor #o120 + b, ;
\ These instructions are not completely operand width portable:
-// lit :macro $push #x68 b, t, ;
-// lit :macro $call #xe8 b, 4 - $-t, ;
+:[ lit ] $push #x68 b, t, ;
+:[ lit ] $call #xe8 b, 4 - $-t, ;
+
+\ vim: ft=tran
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- tran-builtins 17 May 2003 04:48:55 -0000 1.9
+++ tran-builtins 17 May 2003 05:08:44 -0000 1.10
@@ -62,7 +62,7 @@
# intended to be used before the macro's pattern
if Regstack: raise 'stack not empty for :[', Regstack
-:macro|name
+]|name
if len(Regstack) > 2: raise 'too long argument pattern', Regstack
name = ' '.join([name] + [matchers(i).next() for i in Regstack])
Regstack = []
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- tran.py 16 May 2003 17:32:26 -0000 1.76
+++ tran.py 17 May 2003 05:08:44 -0000 1.77
@@ -111,7 +111,7 @@
shlex.__init__(this, instream = open(filename, 'r'), infile = filename)
this.commenters = '\\'
this.quotes = '"'
- this.wordchars += '!#$%*+,-./:;<=>?@'
+ this.wordchars += '!#$%*+,-./:;<=>?@[]'
def get_token (this):
tok = shlex.get_token(this)
if tok == '': tok = None
Index: winapi.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/winapi.tran,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- winapi.tran 16 May 2003 20:49:22 -0000 1.1
+++ winapi.tran 17 May 2003 05:08:45 -0000 1.2
@@ -6,13 +6,13 @@
\
\\\\ @(#) $Id$
-// :macro GetStdHandle \ (handle-number -- handle)
+:[ ] GetStdHandle \ (handle-number -- handle)
commit ref GetStdHandle@kernel32 $call %eax ;
-// :macro WriteFile \ (file buffer count result* overlapped* -- result)
+:[ ] WriteFile \ (file buffer count result* overlapped* -- result)
5rev commit ref WriteFile@kernel32 $call %eax ;
-// :macro ExitProcess \ (code --)
+:[ ] ExitProcess \ (code --)
commit ref ExitProcess@kernel32 $call ;
-\ vim: ft=forth
+\ vim: ft=tran
|
|
From: <di...@us...> - 2003-05-17 04:48:58
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv9778
Modified Files:
tran-builtins
Log Message:
implemented |:[|
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- tran-builtins 16 May 2003 20:34:38 -0000 1.8
+++ tran-builtins 17 May 2003 04:48:55 -0000 1.9
@@ -58,6 +58,10 @@
r = Regstack[-5:]; r.reverse()
Regstack = Regstack[:-5] + r
+:[
+ # intended to be used before the macro's pattern
+ if Regstack: raise 'stack not empty for :[', Regstack
+
:macro|name
if len(Regstack) > 2: raise 'too long argument pattern', Regstack
name = ' '.join([name] + [matchers(i).next() for i in Regstack])
|
|
From: <di...@us...> - 2003-05-17 04:45:05
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv8656
Modified Files:
Makefile.am ia32.tran
Added Files:
i8086.tran
Log Message:
extracted i8086.tran from ia32.tran
--- NEW FILE: i8086.tran ---
\\\\ i8086.tran - Intel's 8086 instructions
\
\ 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: i8086.tran,v 1.1 2003/05/17 04:45:02 digg Exp $
\ Note that these declarations are intended to be usable on i8086
\ *and up*, i386's 32-bit mode. Thusly, you'll need to include ia16
\ or ia32, too in the future to specify the mode.
\ registers
:regs reg16 %ax %cx %dx %bx %sp %bp %si %di ;
:regs reg8 %al %cl %dl %bl %ah %ch %dh %bh ;
Index: Makefile.am
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Makefile.am 16 May 2003 14:09:56 -0000 1.13
+++ Makefile.am 17 May 2003 04:45:02 -0000 1.14
@@ -8,6 +8,7 @@
EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \
coff.py elf.py pe.py \
+ i8086.tran ia32.tran hello.tran winapi.tran mswhello.tran \
makehello.py elfdump.py
all:
Index: ia32.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ia32.tran 17 May 2003 04:26:58 -0000 1.6
+++ ia32.tran 17 May 2003 04:45:02 -0000 1.7
@@ -14,8 +14,6 @@
\ 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 $o32 swap minor #o270 + b, t, ;
|
|
From: <di...@us...> - 2003-05-17 04:27:01
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3529 Modified Files: mswhello.tran ia32.tran Log Message: moved |$call lit| from mswhello.tran to ia32.tran Index: mswhello.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- mswhello.tran 16 May 2003 20:49:21 -0000 1.10 +++ mswhello.tran 17 May 2003 04:26:58 -0000 1.11 @@ -11,8 +11,6 @@ include ia32 include winapi -lit :macro $call #xe8 b, 4 - $-t, ; - \ main entry point label _start Index: ia32.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ia32.tran 15 May 2003 21:11:56 -0000 1.5 +++ ia32.tran 17 May 2003 04:26:58 -0000 1.6 @@ -21,6 +21,7 @@ // reg32 lit :macro $mov $o32 swap minor #o270 + b, t, ; // reg32 :macro $push minor #o120 + b, ; -\ These instructions are not completely register width portable: +\ These instructions are not completely operand width portable: // lit :macro $push #x68 b, t, ; +// lit :macro $call #xe8 b, 4 - $-t, ; |
|
From: <di...@us...> - 2003-05-16 20:49:25
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv25600
Modified Files:
mswhello.tran
Added Files:
winapi.tran
Log Message:
extracted winapi.tran form mswhello.tran
--- NEW FILE: winapi.tran ---
\\\\ winapi.tran - WinAPI support
\
\ 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: winapi.tran,v 1.1 2003/05/16 20:49:22 digg Exp $
// :macro GetStdHandle \ (handle-number -- handle)
commit ref GetStdHandle@kernel32 $call %eax ;
// :macro WriteFile \ (file buffer count result* overlapped* -- result)
5rev commit ref WriteFile@kernel32 $call %eax ;
// :macro ExitProcess \ (code --)
commit ref ExitProcess@kernel32 $call ;
\ vim: ft=forth
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mswhello.tran 16 May 2003 20:34:38 -0000 1.9
+++ mswhello.tran 16 May 2003 20:49:21 -0000 1.10
@@ -9,17 +9,9 @@
\ Don't forget to translate with -fpe
include ia32
+include winapi
lit :macro $call #xe8 b, 4 - $-t, ;
-
-// :macro GetStdHandle \ (handle-number -- handle)
- commit ref GetStdHandle@kernel32 $call %eax ;
-
-// :macro WriteFile \ (file buffer count result* overlapped* -- result)
- 5rev commit ref WriteFile@kernel32 $call %eax ;
-
-// :macro ExitProcess \ (code --)
- commit ref ExitProcess@kernel32 $call ;
\ main entry point
|
|
From: <di...@us...> - 2003-05-16 20:34:45
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv17288
Modified Files:
mswhello.tran tran-builtins
Log Message:
introduced the 3rev, 4rev, and 5rev builtins
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mswhello.tran 16 May 2003 17:27:01 -0000 1.8
+++ mswhello.tran 16 May 2003 20:34:38 -0000 1.9
@@ -15,9 +15,8 @@
// :macro GetStdHandle \ (handle-number -- handle)
commit ref GetStdHandle@kernel32 $call %eax ;
-\ FIXME: reverse arguments
-\ // :macro WriteFile \ (file buffer count result* overlapped* -- result)
-\ commit ref WriteFile@kernel32 $call %eax ;
+// :macro WriteFile \ (file buffer count result* overlapped* -- result)
+ 5rev commit ref WriteFile@kernel32 $call %eax ;
// :macro ExitProcess \ (code --)
commit ref ExitProcess@kernel32 $call ;
@@ -26,8 +25,7 @@
label _start
-11 GetStdHandle
- 0 $push ref rckeep $push 7 $push ref message $push $push
- ref WriteFile@kernel32 $call
+ ref message 7 ref rckeep 0 WriteFile drop
0 ExitProcess
.data
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- tran-builtins 16 May 2003 17:21:27 -0000 1.7
+++ tran-builtins 16 May 2003 20:34:38 -0000 1.8
@@ -43,6 +43,21 @@
//
Regstack = []
+3rev
+ if len(Regstack) < 3: raise 'unstacking is not implemented yet'
+ r = Regstack[-3:]; r.reverse()
+ Regstack = Regstack[:-3] + r
+
+4rev
+ if len(Regstack) < 4: raise 'unstacking is not implemented yet'
+ r = Regstack[-4:]; r.reverse()
+ Regstack = Regstack[:-4] + r
+
+5rev
+ if len(Regstack) < 5: raise 'unstacking is not implemented yet'
+ r = Regstack[-5:]; r.reverse()
+ Regstack = Regstack[:-5] + r
+
:macro|name
if len(Regstack) > 2: raise 'too long argument pattern', Regstack
name = ' '.join([name] + [matchers(i).next() for i in Regstack])
|
|
From: <di...@us...> - 2003-05-16 17:32:30
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv7601
Modified Files:
tran.py
Log Message:
declared format global in main
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- tran.py 16 May 2003 17:27:01 -0000 1.75
+++ tran.py 16 May 2003 17:32:26 -0000 1.76
@@ -290,7 +290,7 @@
format = 'elf'
def main ():
- global prep, verbose
+ global prep, verbose, format
opts, args = getopt(sys.argv[1:], 'vo:f:', ['verbose', 'output=', 'format=', 'list-words'])
output_name = None
list_words = 0
|
|
From: <di...@us...> - 2003-05-16 17:27:58
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv5658 Removed Files: make-pe-exe.py Log Message: obsoleted make-pe-exe.py --- make-pe-exe.py DELETED --- |
|
From: <di...@us...> - 2003-05-16 17:27:04
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv5090
Modified Files:
mswhello.tran tran.py
Log Message:
made tran.py able to generate PE executables
Index: mswhello.tran
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mswhello.tran 22 Apr 2003 22:29:30 -0000 1.7
+++ mswhello.tran 16 May 2003 17:27:01 -0000 1.8
@@ -6,27 +6,28 @@
\
\\\\ @(#) $Id$
-\ NOTE that mswhello.tran is not currently translatable
+\ Don't forget to translate with -fpe
include ia32
lit :macro $call #xe8 b, 4 - $-t, ;
// :macro GetStdHandle \ (handle-number -- handle)
- commit ref GetStdHandle@kernel32#344 $call %eax ;
+ commit ref GetStdHandle@kernel32 $call %eax ;
\ FIXME: reverse arguments
-// :macro WriteFile \ (file buffer count result* overlapped* -- result)
- commit ref WriteFile@kernel32#730 $call %eax ;
+\ // :macro WriteFile \ (file buffer count result* overlapped* -- result)
+\ commit ref WriteFile@kernel32 $call %eax ;
// :macro ExitProcess \ (code --)
- commit ref ExitProcess@kernel32#131 $call ;
+ commit ref ExitProcess@kernel32 $call ;
\ main entry point
label _start
-11 GetStdHandle
- ref message 7 ref rckeep 0 WriteFile drop
+ 0 $push ref rckeep $push 7 $push ref message $push $push
+ ref WriteFile@kernel32 $call
0 ExitProcess
.data
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- tran.py 16 May 2003 15:41:19 -0000 1.74
+++ tran.py 16 May 2003 17:27:01 -0000 1.75
@@ -15,6 +15,7 @@
from linkie import Linkie
from shlex import shlex
import elf
+import pe
import string
import sys
@@ -284,17 +285,21 @@
interpreter.bss = Linkie('<')
interpreter.current = interpreter.text
+default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'}
verbose = 0
+format = 'elf'
def main ():
global prep, verbose
- opts, args = getopt(sys.argv[1:], 'vo:', ['verbose', 'output=', 'list-words'])
- output_name = 'a.out'
+ opts, args = getopt(sys.argv[1:], 'vo:f:', ['verbose', 'output=', 'format=', 'list-words'])
+ output_name = None
list_words = 0
for opt, arg in opts:
if opt in ('-o', '--output'): output_name = arg
if opt in ('-v', '--verbose'): verbose = 1
+ if opt in ('-f', '--format'): format = arg
if opt == '--list-words': list_words = 1
+ if output_name == None: output_name = default_output_names[format]
if list_words:
wd = {}
for w in Meaning.keys():
@@ -318,10 +323,15 @@
print 'BSS'; interpreter.bss.dump()
if Regstack:
raise 'Regstack not empty after parsing ended', Regstack
- binary = elf.make_ELF32_object(text = interpreter.text,
- data = interpreter.data,
- bss = interpreter.bss,
- flags = 's')
+ if format == 'elf':
+ binary = elf.make_ELF32_object(text = interpreter.text,
+ data = interpreter.data,
+ bss = interpreter.bss,
+ flags = 's')
+ elif format == 'pe':
+ binary = pe.make_pe_executable(text = interpreter.text,
+ data = interpreter.data,
+ bss = interpreter.bss)
f = open(output_name, 'w')
binary.get_file().tofile(f)
f.close()
|
|
From: <di...@us...> - 2003-05-16 17:21:34
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv2740
Modified Files:
tran-builtins
Log Message:
fixed commit's attempt to call obsolete Preprocessor.push_macro
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- tran-builtins 16 May 2003 15:41:18 -0000 1.6
+++ tran-builtins 16 May 2003 17:21:27 -0000 1.7
@@ -90,7 +90,7 @@
commit
Regstack.reverse()
- prep.push_macro(['$push'] * len(Regstack))
+ prep.push(Macro_Cursor(['$push'] * len(Regstack)))
drop any
Regstack.pop()
|
|
From: <di...@us...> - 2003-05-16 17:14:32
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv32162
Modified Files:
make-pe-exe.py pe.py
Log Message:
moved make_pe_executable to pe.py
Index: make-pe-exe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- make-pe-exe.py 16 May 2003 17:07:15 -0000 1.68
+++ make-pe-exe.py 16 May 2003 17:14:29 -0000 1.69
@@ -10,14 +10,9 @@
from linkie import Linkie
from pe import *
-from coff import *
-import time
# This file is *very* incomplete
-def roundup (value, boundary):
- return (value + boundary - 1) & ~(boundary - 1)
-
text = Linkie('<') # ia32
text.place_symbol('&_start')
text[::1] = 0x68; text[::4] = -11 # push -11
@@ -40,160 +35,6 @@
bss = Linkie('<')
bss.place_symbol('&rckeep')
bss.skip(4)
-
-imports = Linkie('<')
-
-def make_pe_executable (text = None, data = None, bss = None,
- base_address = 0x00400000):
- e = Linkie('<');
- e.glue(0, make_pe_mz_stub('OS too broken'), 0x100)
- if e.memsz() < 0x80:
- e.align(0x80) # attempt to create a file(1)-friendly exe
- e.align(8) # PE header must be aligned to 8
- e.place_symbol('!pe')
- e.emit_string('PE\0\0')
- e.glue(e.memsz(), make_coff_header(), None)
- e.glue(e.memsz(), make_pe_aout_header(), None)
- text = text.copy() # so we won't add import stubs to the original linkie
- sectnames = ['.text', '.data', '.bss', '.imports']
- sections = {'.text': text, '.data': data, '.bss': bss, '.imports': imports}
- for s in sectnames:
- e.glue(e.memsz(), make_pe_section_header(s), None)
- e.place_symbol('!' + s + '/reloc', 0)
- e.place_symbol('!' + s + '/lineno', 0)
- e.place_symbol('#' + s + '/reloc', 0)
- e.place_symbol('#' + s + '/lineno', 0)
- e.place_symbol('#.text/flags', 0x60000020)
- e.place_symbol('#.data/flags', 0xc0000040)
- e.place_symbol('#.bss/flags', 0xc0000080)
- e.place_symbol('#.imports/flags', 0xc0000040)
- e.align(512)
- e.place_symbol('!aout/header-end')
- ## generate import structures
- # gather names of import functions
- imports_by_dlls = {}
- for s in sectnames:
- for ofs, typ, nam in sections[s].get_notes():
- if nam[0] != '&': continue
- at = nam.find('@')
- if at == -1: continue
- name = nam[1:at]
- dll = nam[at + 1:].lower()
- if not imports_by_dlls.has_key(dll):
- imports_by_dlls[dll] = {}
- imports_by_dlls[dll][name] = None
- # emit import table root
- imports.align(4)
- import_table_start = imports.memsz()
- for dll in imports_by_dlls.keys():
- imports[::4] = '&.imports/%s/hint-name #rva' % dll
- imports[::4] = 0 # timestamp
- imports[::4] = '#.imports/%s/forwarder-chain' % dll
- imports[::4] = '&.imports/%s/dll-name #rva' % dll
- imports[::4] = '&.imports/%s/first-thunk #rva' % dll
- imports.place_symbol('#.imports/' + dll + '/forwarder-chain', 0)
- imports.emit_string('\0' * 20)
- # emit hint/name lists
- for dll in imports_by_dlls.keys():
- imports.align(4)
- imports.place_symbol('&.imports/%s/hint-name' % dll)
- for sym in imports_by_dlls[dll].keys():
- imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
- imports.emit_tetra(0)
- # emit thunk lists
- for dll in imports_by_dlls.keys():
- imports.align(4)
- imports.place_symbol('&.imports/%s/first-thunk' % dll)
- for sym in imports_by_dlls[dll].keys():
- imports.place_symbol('&.imports/slot/' + sym + '@' + dll)
- imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
- imports.emit_tetra(0)
- # emit thunk structures
- for dll in imports_by_dlls.keys():
- for sym in imports_by_dlls[dll].keys():
- imports.place_symbol('&.imports/thunk/%s@%s' % (sym, dll))
- imports.align(2)
- imports[::2] = 0 # ordinal
- imports.emit_string(sym)
- imports[::1] = 0
- # emit DLL names
- for dll in imports_by_dlls.keys():
- imports.place_symbol('&.imports/%s/dll-name' % dll)
- imports.emit_string(dll + '.dll')
- imports[::1] = 0
-
- # generate stub procedures
- for dll in imports_by_dlls.keys():
- for sym in imports_by_dlls[dll].keys():
- text.align(8)
- text.place_symbol('&' + sym + '@' + dll)
- text[::1] = 0xFF, 0x25
- text.emit_tetra_sum(['&.imports/slot/' + sym + '@' + dll])
-
- # paste sections together
- e.align(512)
- base_address = roundup(base_address, 0x1000) # to page boundary
- memory_boundary = base_address
- memory_boundary += 0x1000 # skip the first page
- for s in sectnames:
- # file alignment
- e.align(512)
- # memory alignment
- memory_boundary = roundup(memory_boundary, \
- max(0x1000, sections[s].get_alignment()))
- # establish origin symbols
- e.place_symbol('!' + s)
- e.place_symbol('&' + s, memory_boundary)
- # process sizes
- e.place_symbol('#' + s + '/memsz', sections[s].memsz())
- e.place_symbol('#' + s + '/filesz', roundup(sections[s].filesz(), 0x200))
- # paste bits
- e.glue(e.memsz(), sections[s], memory_boundary)
- # increase memory_boundary
- memory_boundary = roundup(memory_boundary + sections[s].memsz(), 4096)
-
- e.place_symbol('&aout/image-end', memory_boundary)
-
- e.place_symbol('#coff/magic', 0x014C) # I386MAGIC
- e.place_symbol('#coff/nscns', len(sectnames))
- e.place_symbol('#coff/timdat', int(time.time()))
- e.place_symbol('!coff/symptr', 0)
- e.place_symbol('#coff/nsyms', 0)
- e.place_symbol('#coff/opthdr', 0x00E0)
- e.place_symbol('#coff/flags', 0x020F)
- e.place_symbol('#aout/magic', 0x010B) # PE32
- e.place_symbol('#aout/linker-version-major', 0)
- e.place_symbol('#aout/linker-version-minor', 1)
- e.place_symbol('#aout/text-size', roundup(text.memsz(), 0x200))
- e.place_symbol('#aout/data-size', roundup(data.memsz(), 0x200))
- e.place_symbol('#aout/bss-size', roundup(bss.memsz(), 0x200))
- e.place_symbol('#aout/image-base', 0x00400000)
- e.place_symbol('#rva', -0x00400000) # adding this to an address will yield RVA
- e.place_symbol('#aout/memory-align', 4096)
- e.place_symbol('#aout/file-align', 512)
- # 4.0 = MSW95
- e.place_symbol('#aout/os-version-major', 4)
- e.place_symbol('#aout/os-version-minor', 0)
- #
- e.place_symbol('#aout/image-version-major', 0)
- e.place_symbol('#aout/image-version-minor', 1)
- # 4.0 = MSW95
- e.place_symbol('#aout/subsys-version-major', 4)
- e.place_symbol('#aout/subsys-version-minor', 0)
- e.place_symbol('#aout/subsys', PE_SUBSYS.WINDOWS_CHAR)
- e.place_symbol('#aout/dll-flags', 0)
- e.place_symbol('#aout/stack-reserve-size', 1024 * 1024) # one megabyte
- e.place_symbol('#aout/stack-commit-size', 0x1000) # one page
- e.place_symbol('#aout/heap-reserve-size', 1024 * 1024) # one megabyte
- e.place_symbol('#aout/heap-commit-size', 0x1000) # one page
-
- # Note that null RVAs are those that equal base_address
- e.place_symbol('#aout/dict-entry-count', 16)
- populate_pe_directories(e, base_address)
- e.align(512)
-
- e.link()
- return e
e = make_pe_executable(text = text, data = data, bss = bss)
e.dump()
Index: pe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pe.py 16 May 2003 16:47:07 -0000 1.5
+++ pe.py 16 May 2003 17:14:29 -0000 1.6
@@ -7,6 +7,11 @@
#### @(#) $Id$
from mz import *
+from coff import *
+import time
+
+def roundup (value, boundary):
+ return (value + boundary - 1) & ~(boundary - 1)
class PE_SUBSYS:
UNKNOWN = 0
@@ -167,3 +172,156 @@
for s in defaults.keys():
if given.has_key(s): linkie.place_symbol(s, given[s])
else: linkie.place_symbol(s, defaults[s])
+
+def make_pe_executable (text = None, data = None, bss = None,
+ base_address = 0x00400000):
+ e = Linkie('<');
+ e.glue(0, make_pe_mz_stub('OS too broken'), 0x100)
+ if e.memsz() < 0x80:
+ e.align(0x80) # attempt to create a file(1)-friendly exe
+ e.align(8) # PE header must be aligned to 8
+ e.place_symbol('!pe')
+ e.emit_string('PE\0\0')
+ e.glue(e.memsz(), make_coff_header(), None)
+ e.glue(e.memsz(), make_pe_aout_header(), None)
+ text = text.copy() # so we won't add import stubs to the original linkie
+ imports = Linkie('<')
+ sectnames = ['.text', '.data', '.bss', '.imports']
+ sections = {'.text': text, '.data': data, '.bss': bss, '.imports': imports}
+ for s in sectnames:
+ e.glue(e.memsz(), make_pe_section_header(s), None)
+ e.place_symbol('!' + s + '/reloc', 0)
+ e.place_symbol('!' + s + '/lineno', 0)
+ e.place_symbol('#' + s + '/reloc', 0)
+ e.place_symbol('#' + s + '/lineno', 0)
+ e.place_symbol('#.text/flags', 0x60000020)
+ e.place_symbol('#.data/flags', 0xc0000040)
+ e.place_symbol('#.bss/flags', 0xc0000080)
+ e.place_symbol('#.imports/flags', 0xc0000040)
+ e.align(512)
+ e.place_symbol('!aout/header-end')
+ ## generate import structures
+ # gather names of import functions
+ imports_by_dlls = {}
+ for s in sectnames:
+ for ofs, typ, nam in sections[s].get_notes():
+ if nam[0] != '&': continue
+ at = nam.find('@')
+ if at == -1: continue
+ name = nam[1:at]
+ dll = nam[at + 1:].lower()
+ if not imports_by_dlls.has_key(dll):
+ imports_by_dlls[dll] = {}
+ imports_by_dlls[dll][name] = None
+ # emit import table root
+ imports.align(4)
+ import_table_start = imports.memsz()
+ for dll in imports_by_dlls.keys():
+ imports[::4] = '&.imports/%s/hint-name #rva' % dll
+ imports[::4] = 0 # timestamp
+ imports[::4] = '#.imports/%s/forwarder-chain' % dll
+ imports[::4] = '&.imports/%s/dll-name #rva' % dll
+ imports[::4] = '&.imports/%s/first-thunk #rva' % dll
+ imports.place_symbol('#.imports/' + dll + '/forwarder-chain', 0)
+ imports.emit_string('\0' * 20)
+ # emit hint/name lists
+ for dll in imports_by_dlls.keys():
+ imports.align(4)
+ imports.place_symbol('&.imports/%s/hint-name' % dll)
+ for sym in imports_by_dlls[dll].keys():
+ imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
+ imports.emit_tetra(0)
+ # emit thunk lists
+ for dll in imports_by_dlls.keys():
+ imports.align(4)
+ imports.place_symbol('&.imports/%s/first-thunk' % dll)
+ for sym in imports_by_dlls[dll].keys():
+ imports.place_symbol('&.imports/slot/' + sym + '@' + dll)
+ imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
+ imports.emit_tetra(0)
+ # emit thunk structures
+ for dll in imports_by_dlls.keys():
+ for sym in imports_by_dlls[dll].keys():
+ imports.place_symbol('&.imports/thunk/%s@%s' % (sym, dll))
+ imports.align(2)
+ imports[::2] = 0 # ordinal
+ imports.emit_string(sym)
+ imports[::1] = 0
+ # emit DLL names
+ for dll in imports_by_dlls.keys():
+ imports.place_symbol('&.imports/%s/dll-name' % dll)
+ imports.emit_string(dll + '.dll')
+ imports[::1] = 0
+
+ # generate stub procedures
+ for dll in imports_by_dlls.keys():
+ for sym in imports_by_dlls[dll].keys():
+ text.align(8)
+ text.place_symbol('&' + sym + '@' + dll)
+ text[::1] = 0xFF, 0x25
+ text.emit_tetra_sum(['&.imports/slot/' + sym + '@' + dll])
+
+ # paste sections together
+ e.align(512)
+ base_address = roundup(base_address, 0x1000) # to page boundary
+ memory_boundary = base_address
+ memory_boundary += 0x1000 # skip the first page
+ for s in sectnames:
+ # file alignment
+ e.align(512)
+ # memory alignment
+ memory_boundary = roundup(memory_boundary, \
+ max(0x1000, sections[s].get_alignment()))
+ # establish origin symbols
+ e.place_symbol('!' + s)
+ e.place_symbol('&' + s, memory_boundary)
+ # process sizes
+ e.place_symbol('#' + s + '/memsz', sections[s].memsz())
+ e.place_symbol('#' + s + '/filesz', roundup(sections[s].filesz(), 0x200))
+ # paste bits
+ e.glue(e.memsz(), sections[s], memory_boundary)
+ # increase memory_boundary
+ memory_boundary = roundup(memory_boundary + sections[s].memsz(), 4096)
+
+ e.place_symbol('&aout/image-end', memory_boundary)
+
+ e.place_symbol('#coff/magic', 0x014C) # I386MAGIC
+ e.place_symbol('#coff/nscns', len(sectnames))
+ e.place_symbol('#coff/timdat', int(time.time()))
+ e.place_symbol('!coff/symptr', 0)
+ e.place_symbol('#coff/nsyms', 0)
+ e.place_symbol('#coff/opthdr', 0x00E0)
+ e.place_symbol('#coff/flags', 0x020F)
+ e.place_symbol('#aout/magic', 0x010B) # PE32
+ e.place_symbol('#aout/linker-version-major', 0)
+ e.place_symbol('#aout/linker-version-minor', 1)
+ e.place_symbol('#aout/text-size', roundup(text.memsz(), 0x200))
+ e.place_symbol('#aout/data-size', roundup(data.memsz(), 0x200))
+ e.place_symbol('#aout/bss-size', roundup(bss.memsz(), 0x200))
+ e.place_symbol('#aout/image-base', 0x00400000)
+ e.place_symbol('#rva', -0x00400000) # adding this to an address will yield RVA
+ e.place_symbol('#aout/memory-align', 4096)
+ e.place_symbol('#aout/file-align', 512)
+ # 4.0 = MSW95
+ e.place_symbol('#aout/os-version-major', 4)
+ e.place_symbol('#aout/os-version-minor', 0)
+ #
+ e.place_symbol('#aout/image-version-major', 0)
+ e.place_symbol('#aout/image-version-minor', 1)
+ # 4.0 = MSW95
+ e.place_symbol('#aout/subsys-version-major', 4)
+ e.place_symbol('#aout/subsys-version-minor', 0)
+ e.place_symbol('#aout/subsys', PE_SUBSYS.WINDOWS_CHAR)
+ e.place_symbol('#aout/dll-flags', 0)
+ e.place_symbol('#aout/stack-reserve-size', 1024 * 1024) # one megabyte
+ e.place_symbol('#aout/stack-commit-size', 0x1000) # one page
+ e.place_symbol('#aout/heap-reserve-size', 1024 * 1024) # one megabyte
+ e.place_symbol('#aout/heap-commit-size', 0x1000) # one page
+
+ # Note that null RVAs are those that equal base_address
+ e.place_symbol('#aout/dict-entry-count', 16)
+ populate_pe_directories(e, base_address)
+ e.align(512)
+
+ e.link()
+ return e
|
|
From: <di...@us...> - 2003-05-16 17:07:19
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv29613
Modified Files:
make-pe-exe.py
Log Message:
extracted make_pe_executable from the body of make-pe-exe.py
Index: make-pe-exe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- make-pe-exe.py 16 May 2003 16:47:06 -0000 1.67
+++ make-pe-exe.py 16 May 2003 17:07:15 -0000 1.68
@@ -43,153 +43,158 @@
imports = Linkie('<')
-sections = {'.text': text, '.data': data, '.bss': bss, '.imports': imports}
-sectnames = ['.text', '.data', '.bss', '.imports']
-
-e = Linkie('<');
-e.glue(0, make_pe_mz_stub('OS too broken'), 0x100)
-if e.memsz() < 0x80: e.align(0x80) # attempt to create a file(1)-friendly exe
-e.align(8) # PE header must be aligned to 8
-e.place_symbol('!pe')
-e.emit_string('PE\0\0')
-e.glue(e.memsz(), make_coff_header(), None)
-e.glue(e.memsz(), make_pe_aout_header(), None)
-for s in sectnames:
- e.glue(e.memsz(), make_pe_section_header(s), None)
- e.place_symbol('!' + s + '/reloc', 0)
- e.place_symbol('!' + s + '/lineno', 0)
- e.place_symbol('#' + s + '/reloc', 0)
- e.place_symbol('#' + s + '/lineno', 0)
-e.place_symbol('#.text/flags', 0x60000020)
-e.place_symbol('#.data/flags', 0xc0000040)
-e.place_symbol('#.bss/flags', 0xc0000080)
-e.place_symbol('#.imports/flags', 0xc0000040)
-e.align(512)
-e.place_symbol('!aout/header-end')
-## generate import structures
-# gather names of import functions
-imports_by_dlls = {}
-for s in sectnames:
- for ofs, typ, nam in sections[s].get_notes():
- if nam[0] != '&': continue
- at = nam.find('@')
- if at == -1: continue
- name = nam[1:at]
- dll = nam[at + 1:].lower()
- if not imports_by_dlls.has_key(dll):
- imports_by_dlls[dll] = {}
- imports_by_dlls[dll][name] = None
-# emit import table root
-imports.align(4)
-import_table_start = imports.memsz()
-for dll in imports_by_dlls.keys():
- imports[::4] = '&.imports/%s/hint-name #rva' % dll
- imports[::4] = 0 # timestamp
- imports[::4] = '#.imports/%s/forwarder-chain' % dll
- imports[::4] = '&.imports/%s/dll-name #rva' % dll
- imports[::4] = '&.imports/%s/first-thunk #rva' % dll
- imports.place_symbol('#.imports/' + dll + '/forwarder-chain', 0)
-imports.emit_string('\0' * 20)
-# emit hint/name lists
-for dll in imports_by_dlls.keys():
- imports.align(4)
- imports.place_symbol('&.imports/%s/hint-name' % dll)
- for sym in imports_by_dlls[dll].keys():
- imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
- imports.emit_tetra(0)
-# emit thunk lists
-for dll in imports_by_dlls.keys():
+def make_pe_executable (text = None, data = None, bss = None,
+ base_address = 0x00400000):
+ e = Linkie('<');
+ e.glue(0, make_pe_mz_stub('OS too broken'), 0x100)
+ if e.memsz() < 0x80:
+ e.align(0x80) # attempt to create a file(1)-friendly exe
+ e.align(8) # PE header must be aligned to 8
+ e.place_symbol('!pe')
+ e.emit_string('PE\0\0')
+ e.glue(e.memsz(), make_coff_header(), None)
+ e.glue(e.memsz(), make_pe_aout_header(), None)
+ text = text.copy() # so we won't add import stubs to the original linkie
+ sectnames = ['.text', '.data', '.bss', '.imports']
+ sections = {'.text': text, '.data': data, '.bss': bss, '.imports': imports}
+ for s in sectnames:
+ e.glue(e.memsz(), make_pe_section_header(s), None)
+ e.place_symbol('!' + s + '/reloc', 0)
+ e.place_symbol('!' + s + '/lineno', 0)
+ e.place_symbol('#' + s + '/reloc', 0)
+ e.place_symbol('#' + s + '/lineno', 0)
+ e.place_symbol('#.text/flags', 0x60000020)
+ e.place_symbol('#.data/flags', 0xc0000040)
+ e.place_symbol('#.bss/flags', 0xc0000080)
+ e.place_symbol('#.imports/flags', 0xc0000040)
+ e.align(512)
+ e.place_symbol('!aout/header-end')
+ ## generate import structures
+ # gather names of import functions
+ imports_by_dlls = {}
+ for s in sectnames:
+ for ofs, typ, nam in sections[s].get_notes():
+ if nam[0] != '&': continue
+ at = nam.find('@')
+ if at == -1: continue
+ name = nam[1:at]
+ dll = nam[at + 1:].lower()
+ if not imports_by_dlls.has_key(dll):
+ imports_by_dlls[dll] = {}
+ imports_by_dlls[dll][name] = None
+ # emit import table root
imports.align(4)
- imports.place_symbol('&.imports/%s/first-thunk' % dll)
- for sym in imports_by_dlls[dll].keys():
- imports.place_symbol('&.imports/slot/' + sym + '@' + dll)
- imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
- imports.emit_tetra(0)
-# emit thunk structures
-for dll in imports_by_dlls.keys():
- for sym in imports_by_dlls[dll].keys():
- imports.place_symbol('&.imports/thunk/%s@%s' % (sym, dll))
- imports.align(2)
- imports[::2] = 0 # ordinal
- imports.emit_string(sym)
+ import_table_start = imports.memsz()
+ for dll in imports_by_dlls.keys():
+ imports[::4] = '&.imports/%s/hint-name #rva' % dll
+ imports[::4] = 0 # timestamp
+ imports[::4] = '#.imports/%s/forwarder-chain' % dll
+ imports[::4] = '&.imports/%s/dll-name #rva' % dll
+ imports[::4] = '&.imports/%s/first-thunk #rva' % dll
+ imports.place_symbol('#.imports/' + dll + '/forwarder-chain', 0)
+ imports.emit_string('\0' * 20)
+ # emit hint/name lists
+ for dll in imports_by_dlls.keys():
+ imports.align(4)
+ imports.place_symbol('&.imports/%s/hint-name' % dll)
+ for sym in imports_by_dlls[dll].keys():
+ imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
+ imports.emit_tetra(0)
+ # emit thunk lists
+ for dll in imports_by_dlls.keys():
+ imports.align(4)
+ imports.place_symbol('&.imports/%s/first-thunk' % dll)
+ for sym in imports_by_dlls[dll].keys():
+ imports.place_symbol('&.imports/slot/' + sym + '@' + dll)
+ imports[::4] = '&.imports/thunk/%s@%s #rva' % (sym, dll)
+ imports.emit_tetra(0)
+ # emit thunk structures
+ for dll in imports_by_dlls.keys():
+ for sym in imports_by_dlls[dll].keys():
+ imports.place_symbol('&.imports/thunk/%s@%s' % (sym, dll))
+ imports.align(2)
+ imports[::2] = 0 # ordinal
+ imports.emit_string(sym)
+ imports[::1] = 0
+ # emit DLL names
+ for dll in imports_by_dlls.keys():
+ imports.place_symbol('&.imports/%s/dll-name' % dll)
+ imports.emit_string(dll + '.dll')
imports[::1] = 0
-# emit DLL names
-for dll in imports_by_dlls.keys():
- imports.place_symbol('&.imports/%s/dll-name' % dll)
- imports.emit_string(dll + '.dll')
- imports[::1] = 0
-# generate stub procedures
-for dll in imports_by_dlls.keys():
- for sym in imports_by_dlls[dll].keys():
- text.align(8)
- text.place_symbol('&' + sym + '@' + dll)
- text[::1] = 0xFF, 0x25
- text.emit_tetra_sum(['&.imports/slot/' + sym + '@' + dll])
+ # generate stub procedures
+ for dll in imports_by_dlls.keys():
+ for sym in imports_by_dlls[dll].keys():
+ text.align(8)
+ text.place_symbol('&' + sym + '@' + dll)
+ text[::1] = 0xFF, 0x25
+ text.emit_tetra_sum(['&.imports/slot/' + sym + '@' + dll])
-# paste sections together
-e.align(512)
-base_address = 0x00400000
-base_address = roundup(base_address, 0x1000) # to page boundary
-memory_boundary = base_address
-memory_boundary += 0x1000 # skip the first page
-for s in sectnames:
- # file alignment
+ # paste sections together
e.align(512)
- # memory alignment
- memory_boundary = roundup(memory_boundary, \
- max(0x1000, sections[s].get_alignment()))
- # establish origin symbols
- e.place_symbol('!' + s)
- e.place_symbol('&' + s, memory_boundary)
- # process sizes
- e.place_symbol('#' + s + '/memsz', sections[s].memsz())
- e.place_symbol('#' + s + '/filesz', roundup(sections[s].filesz(), 0x200))
- # paste bits
- e.glue(e.memsz(), sections[s], memory_boundary)
- # increase memory_boundary
- memory_boundary = roundup(memory_boundary + sections[s].memsz(), 4096)
+ base_address = roundup(base_address, 0x1000) # to page boundary
+ memory_boundary = base_address
+ memory_boundary += 0x1000 # skip the first page
+ for s in sectnames:
+ # file alignment
+ e.align(512)
+ # memory alignment
+ memory_boundary = roundup(memory_boundary, \
+ max(0x1000, sections[s].get_alignment()))
+ # establish origin symbols
+ e.place_symbol('!' + s)
+ e.place_symbol('&' + s, memory_boundary)
+ # process sizes
+ e.place_symbol('#' + s + '/memsz', sections[s].memsz())
+ e.place_symbol('#' + s + '/filesz', roundup(sections[s].filesz(), 0x200))
+ # paste bits
+ e.glue(e.memsz(), sections[s], memory_boundary)
+ # increase memory_boundary
+ memory_boundary = roundup(memory_boundary + sections[s].memsz(), 4096)
-e.place_symbol('&aout/image-end', memory_boundary)
+ e.place_symbol('&aout/image-end', memory_boundary)
-e.place_symbol('#coff/magic', 0x014C) # I386MAGIC
-e.place_symbol('#coff/nscns', len(sectnames))
-e.place_symbol('#coff/timdat', int(time.time()))
-e.place_symbol('!coff/symptr', 0)
-e.place_symbol('#coff/nsyms', 0)
-e.place_symbol('#coff/opthdr', 0x00E0)
-e.place_symbol('#coff/flags', 0x020F)
-e.place_symbol('#aout/magic', 0x010B) # PE32
-e.place_symbol('#aout/linker-version-major', 0)
-e.place_symbol('#aout/linker-version-minor', 1)
-e.place_symbol('#aout/text-size', roundup(text.memsz(), 0x200))
-e.place_symbol('#aout/data-size', roundup(data.memsz(), 0x200))
-e.place_symbol('#aout/bss-size', roundup(bss.memsz(), 0x200))
-e.place_symbol('#aout/image-base', 0x00400000)
-e.place_symbol('#rva', -0x00400000) # adding this to an address will yield RVA
-e.place_symbol('#aout/memory-align', 4096)
-e.place_symbol('#aout/file-align', 512)
-# 4.0 = MSW95
-e.place_symbol('#aout/os-version-major', 4)
-e.place_symbol('#aout/os-version-minor', 0)
-#
-e.place_symbol('#aout/image-version-major', 0)
-e.place_symbol('#aout/image-version-minor', 1)
-# 4.0 = MSW95
-e.place_symbol('#aout/subsys-version-major', 4)
-e.place_symbol('#aout/subsys-version-minor', 0)
-e.place_symbol('#aout/subsys', PE_SUBSYS.WINDOWS_CHAR)
-e.place_symbol('#aout/dll-flags', 0)
-e.place_symbol('#aout/stack-reserve-size', 1024 * 1024) # one megabyte
-e.place_symbol('#aout/stack-commit-size', 0x1000) # one page
-e.place_symbol('#aout/heap-reserve-size', 1024 * 1024) # one megabyte
-e.place_symbol('#aout/heap-commit-size', 0x1000) # one page
+ e.place_symbol('#coff/magic', 0x014C) # I386MAGIC
+ e.place_symbol('#coff/nscns', len(sectnames))
+ e.place_symbol('#coff/timdat', int(time.time()))
+ e.place_symbol('!coff/symptr', 0)
+ e.place_symbol('#coff/nsyms', 0)
+ e.place_symbol('#coff/opthdr', 0x00E0)
+ e.place_symbol('#coff/flags', 0x020F)
+ e.place_symbol('#aout/magic', 0x010B) # PE32
+ e.place_symbol('#aout/linker-version-major', 0)
+ e.place_symbol('#aout/linker-version-minor', 1)
+ e.place_symbol('#aout/text-size', roundup(text.memsz(), 0x200))
+ e.place_symbol('#aout/data-size', roundup(data.memsz(), 0x200))
+ e.place_symbol('#aout/bss-size', roundup(bss.memsz(), 0x200))
+ e.place_symbol('#aout/image-base', 0x00400000)
+ e.place_symbol('#rva', -0x00400000) # adding this to an address will yield RVA
+ e.place_symbol('#aout/memory-align', 4096)
+ e.place_symbol('#aout/file-align', 512)
+ # 4.0 = MSW95
+ e.place_symbol('#aout/os-version-major', 4)
+ e.place_symbol('#aout/os-version-minor', 0)
+ #
+ e.place_symbol('#aout/image-version-major', 0)
+ e.place_symbol('#aout/image-version-minor', 1)
+ # 4.0 = MSW95
+ e.place_symbol('#aout/subsys-version-major', 4)
+ e.place_symbol('#aout/subsys-version-minor', 0)
+ e.place_symbol('#aout/subsys', PE_SUBSYS.WINDOWS_CHAR)
+ e.place_symbol('#aout/dll-flags', 0)
+ e.place_symbol('#aout/stack-reserve-size', 1024 * 1024) # one megabyte
+ e.place_symbol('#aout/stack-commit-size', 0x1000) # one page
+ e.place_symbol('#aout/heap-reserve-size', 1024 * 1024) # one megabyte
+ e.place_symbol('#aout/heap-commit-size', 0x1000) # one page
-# Note that null RVAs are those that equal base_address
-e.place_symbol('#aout/dict-entry-count', 16)
-populate_pe_directories(e, base_address)
-e.align(512)
+ # Note that null RVAs are those that equal base_address
+ e.place_symbol('#aout/dict-entry-count', 16)
+ populate_pe_directories(e, base_address)
+ e.align(512)
-e.link()
+ e.link()
+ return e
+
+e = make_pe_executable(text = text, data = data, bss = bss)
e.dump()
e.get_file().tofile(open('pehello.exe', 'w'))
|
|
From: <di...@us...> - 2003-05-16 16:47:10
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv22417
Modified Files:
make-pe-exe.py pe.py
Log Message:
wrote populate_pe_directories
Index: make-pe-exe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- make-pe-exe.py 16 May 2003 16:23:04 -0000 1.66
+++ make-pe-exe.py 16 May 2003 16:47:06 -0000 1.67
@@ -187,33 +187,7 @@
# Note that null RVAs are those that equal base_address
e.place_symbol('#aout/dict-entry-count', 16)
-e.place_symbol('&export-table', base_address)
-e.place_symbol('#export-table/size', 0)
-e.place_symbol('&resource-table', base_address)
-e.place_symbol('#resource-table/size', 0)
-e.place_symbol('&exception-table', base_address)
-e.place_symbol('#exception-table/size', 0)
-e.place_symbol('!certificate-table', 0)
-e.place_symbol('#certificate-table/size', 0)
-e.place_symbol('&base-relocation-table', base_address)
-e.place_symbol('#base-relocation-table/size', 0)
-e.place_symbol('&debug-data', base_address)
-e.place_symbol('#debug-data/size', 0)
-e.place_symbol('&architecture-specific', base_address)
-e.place_symbol('#architecture-specific/size', 0)
-e.place_symbol('&global-pointer', base_address)
-e.place_symbol('&thread-local-storage', base_address)
-e.place_symbol('#thread-local-storage/size', 0)
-e.place_symbol('&load-config-table', base_address)
-e.place_symbol('#load-config-table/size', 0)
-e.place_symbol('&bound-import-table', base_address)
-e.place_symbol('#bound-import-table/size', 0)
-e.place_symbol('&import-address-table', base_address)
-e.place_symbol('#import-address-table/size', 0)
-e.place_symbol('&delay-import-descriptor', base_address)
-e.place_symbol('#delay-import-descriptor/size', 0)
-e.place_symbol('&COM+-runtime-header', base_address)
-e.place_symbol('#COM+-runtime-header/size', 0)
+populate_pe_directories(e, base_address)
e.align(512)
e.link()
Index: pe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pe.py 16 May 2003 14:56:59 -0000 1.4
+++ pe.py 16 May 2003 16:47:07 -0000 1.5
@@ -85,9 +85,8 @@
h.emit_tetra_sum(['&aout/image-end', '#rva'])
# !aout/header-end must be a multiple of #aout/file-align
h.emit_tetra_sum(['!aout/header-end'])
- h.emit_tetra(0) # checksum
- h.emit_wyde_sum(['#aout/subsys'])
- h.emit_wyde_sum(['#aout/dll-flags'])
+ h[::4] = 0 # checksum
+ h[::2] = '#aout/subsys', '#aout/dll-flags'
# Known flags for #aout/dll-flags
# 0x0001 - per-process library initialization
# 0x0002 - per-process library termination
@@ -108,26 +107,26 @@
h.emit_tetra_sum(['#resource-table/size'])
h.emit_tetra_sum(['&exception-table', '#rva'])
h.emit_tetra_sum(['#exception-table/size'])
- h.emit_tetra_sum(['!certificate-table'])
- h.emit_tetra_sum(['#certificate-table/size'])
- h.emit_tetra_sum(['&base-relocation-table', '#rva'])
- h.emit_tetra_sum(['#base-relocation-table/size'])
+ h.emit_tetra_sum(['!cert-table'])
+ h.emit_tetra_sum(['#cert-table/size'])
+ h.emit_tetra_sum(['&base-rel-table', '#rva'])
+ h.emit_tetra_sum(['#base-rel-table/size'])
h.emit_tetra_sum(['&debug-data', '#rva'])
h.emit_tetra_sum(['#debug-data/size'])
- h.emit_tetra_sum(['&architecture-specific', '#rva'])
- h.emit_tetra_sum(['#architecture-specific/size'])
+ h.emit_tetra_sum(['&arch-specific', '#rva'])
+ h.emit_tetra_sum(['#arch-specific/size'])
h.emit_tetra_sum(['&global-pointer', '#rva'])
h.emit_tetra(0)
- h.emit_tetra_sum(['&thread-local-storage', '#rva'])
- h.emit_tetra_sum(['#thread-local-storage/size'])
+ h.emit_tetra_sum(['&tls', '#rva'])
+ h.emit_tetra_sum(['#tls/size'])
h.emit_tetra_sum(['&load-config-table', '#rva'])
h.emit_tetra_sum(['#load-config-table/size'])
h.emit_tetra_sum(['&bound-import-table', '#rva'])
h.emit_tetra_sum(['#bound-import-table/size'])
h.emit_tetra_sum(['&import-address-table', '#rva'])
h.emit_tetra_sum(['#import-address-table/size'])
- h.emit_tetra_sum(['&delay-import-descriptor', '#rva'])
- h.emit_tetra_sum(['#delay-import-descriptor/size'])
+ h.emit_tetra_sum(['&delay-import-descr', '#rva'])
+ h.emit_tetra_sum(['#delay-import-descr/size'])
h.emit_tetra_sum(['&COM+-runtime-header', '#rva'])
h.emit_tetra_sum(['#COM+-runtime-header/size'])
h.emit_tetra(0); h.emit_tetra(0) # reserved
@@ -147,3 +146,24 @@
t[::2] = '#%s/lineno' % name
t[::4] = '#%s/flags' % name
return t
+
+def populate_pe_directories (linkie, base, **given):
+ defaults = {
+ '&export-table': base, '#export-table/size': 0,
+ '&resource-table': base, '#resource-table/size': 0,
+ '&exception-table': base, '#exception-table/size': 0,
+ '!cert-table': 0, '#cert-table/size': 0,
+ '&base-rel-table': base, '#base-rel-table/size': 0,
+ '&debug-data': base, '#debug-data/size': 0,
+ '&arch-specific': base, '#arch-specific/size': 0,
+ '&global-pointer': base,
+ '&tls': base, '#tls/size': 0,
+ '&load-config-table': base, '#load-config-table/size': 0,
+ '&bound-import-table': base, '#bound-import-table/size': 0,
+ '&import-address-table': base, '#import-address-table/size': 0,
+ '&delay-import-descr': base, '#delay-import-descr/size': 0,
+ '&COM+-runtime-header': base, '#COM+-runtime-header/size': 0,
+ }
+ for s in defaults.keys():
+ if given.has_key(s): linkie.place_symbol(s, given[s])
+ else: linkie.place_symbol(s, defaults[s])
|
|
From: <di...@us...> - 2003-05-16 16:23:08
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv13813
Modified Files:
coff.py make-pe-exe.py
Log Message:
moved make_coff_header to coff.py
Index: coff.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/coff.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- coff.py 16 May 2003 14:03:29 -0000 1.1
+++ coff.py 16 May 2003 16:23:04 -0000 1.2
@@ -8,6 +8,49 @@
from linkie import Linkie
+def make_coff_header ():
+ h = Linkie('<')
+ h.align(4)
+ h[::2] = '#coff/magic'
+ # Known magic values:
+ # 0x0000 unknown
+ # 0x014C i80386
+ # 0x014D i80486
+ # 0x014E Pentium
+ # 0x0162 Mips Mark I (R2000, R3000)
+ # 0x0163 Mips Mark II (R6000)
+ # 0x0166 Mips Mark III (R4000)
+ # 0x0168 R10000
+ # 0x0184 Alpha AXP
+ # 0x01A2 Hitachi SH3
+ # 0x01A6 Hitachi SH4
+ # 0x01C0 ARM
+ # 0x01F0 PowerPC LittleEndian
+ # 0x0200 ia64
+ # 0x0266 Mips 16
+ # 0x0268 m68k
+ # 0x0284 Alpha AXP 64-bit
+ # 0x0366 Mips with FPU
+ # 0x0466 Mips 16 with FPU
+ h[::2] = '#coff/nscns'
+ h[::4] = '#coff/timdat', '!coff/symptr', '#coff/nsyms'
+ h[::2] = '#coff/opthdr', '#coff/flags'
+ # Flags for COFF:
+ # 0x0001 no relocations -- can only be loaded at the preferred address
+ # 0x0002 executable
+ # 0x0004 no COFF line number data
+ # 0x0008 no COFF local symbol entries
+ # Additional flags for PE:
+ # 0x0010 aggressively trim working set (?)
+ # 0x0020 program is aware of addresses larger than 2Gi
+ # 0x0040 reserved
+ # 0x0200 debugging information stripped away
+ # 0x0400 if file on removable media, copy and run from swap (?)
+ # 0x1000 is a system program (?)
+ # 0x2000 library
+ # 0x4000 should only be run on uniprocessor machines
+ return h
+
def make_coff_section_header (byte_order, name):
h = Linkie(byte_order)
h.align(4)
@@ -22,4 +65,3 @@
h[::2] = '#%s/lineno' % name
h[::4] = '#%s/flags' % name
return h
-
Index: make-pe-exe.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- make-pe-exe.py 16 May 2003 15:02:36 -0000 1.65
+++ make-pe-exe.py 16 May 2003 16:23:04 -0000 1.66
@@ -10,54 +10,13 @@
from linkie import Linkie
from pe import *
+from coff import *
import time
# This file is *very* incomplete
def roundup (value, boundary):
return (value + boundary - 1) & ~(boundary - 1)
-
-def make_coff_header ():
- h = Linkie('<')
- h.align(4)
- h[::2] = '#coff/magic'
- # Known magic values:
- # 0x0000 unknown
- # 0x014C i80386
- # 0x014D i80486
- # 0x014E Pentium
- # 0x0162 Mips Mark I (R2000, R3000)
- # 0x0163 Mips Mark II (R6000)
- # 0x0166 Mips Mark III (R4000)
- # 0x0168 R10000
- # 0x0184 Alpha AXP
- # 0x01A2 Hitachi SH3
- # 0x01A6 Hitachi SH4
- # 0x01C0 ARM
- # 0x01F0 PowerPC LittleEndian
- # 0x0200 ia64
- # 0x0266 Mips 16
- # 0x0268 m68k
- # 0x0284 Alpha AXP 64-bit
- # 0x0366 Mips with FPU
- # 0x0466 Mips 16 with FPU
- h[::2] = '#coff/nscns'
- h[::4] = '#coff/timdat', '!coff/symptr', '#coff/nsyms'
- h[::2] = '#coff/opthdr', '#coff/flags'
- # Flags for PE:
- # 0x0001 no relocations -- can only be loaded at the preferred address
- # 0x0002 executable
- # 0x0004 no COFF line number data
- # 0x0008 no COFF local symbol entries
- # 0x0010 aggressively trim working set (?)
- # 0x0020 program is aware of addresses larger than 2Gi
- # 0x0040 reserved
- # 0x0200 debugging information stripped away
- # 0x0400 if file on removable media, copy and run from swap (?)
- # 0x1000 is a system program (?)
- # 0x2000 library
- # 0x4000 should only be run on uniprocessor machines
- return h
text = Linkie('<') # ia32
text.place_symbol('&_start')
|
|
From: <di...@us...> - 2003-05-16 15:41:23
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv23956
Modified Files:
tran-builtins tran.py
Log Message:
moved sections to the interpreter capsule
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- tran-builtins 16 May 2003 15:24:28 -0000 1.5
+++ tran-builtins 16 May 2003 15:41:18 -0000 1.6
@@ -10,10 +10,10 @@
s = Regstack.pop()
scalar = long(s[0])
symbols = map(str, s[1:])
- cursect.emit_tetra_sum(symbols, delta = scalar % 0x100000000L, relative = 1)
+ interpreter.current.emit_tetra_sum(symbols, delta = scalar % 0x100000000L, relative = 1)
$-t, sym
- cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1)
+ interpreter.current.emit_tetra_sum([str(Regstack.pop())], relative = 1)
+ int int
n = Regstack.pop(); m = Regstack.pop()
@@ -32,13 +32,13 @@
Regstack.append(m - n)
.bss
- cursect = Bss
+ interpreter.current = interpreter.bss
.data
- cursect = Data
+ interpreter.current = interpreter.data
.text
- cursect = Text
+ interpreter.current = interpreter.text
//
Regstack = []
@@ -80,13 +80,13 @@
interpreter.state = regs_state
align int
- cursect.align(long(Regstack.pop()))
+ interpreter.current.align(long(Regstack.pop()))
b, int
- cursect[::1] = long(Regstack.pop())
+ interpreter.current[::1] = long(Regstack.pop())
b, sym
- cursect[::1] = str(Regstack.pop())
+ interpreter.current[::1] = str(Regstack.pop())
commit
Regstack.reverse()
@@ -99,7 +99,7 @@
Regstack.append(Regstack[-1])
label|name
- cursect.place_symbol('&' + name)
+ interpreter.current.place_symbol('&' + name)
minor reg
Regstack.append(Integer_Literal(Regstack.pop()[-1]))
@@ -111,22 +111,22 @@
Regstack.append(Symbol_Literal('&' + name))
reserve int
- cursect.skip(Regstack.pop())
+ interpreter.current.skip(Regstack.pop())
swap any any
y = Regstack.pop(); x = Regstack.pop()
Regstack.append(y); Regstack.append(x)
t, int
- cursect[::4] = long(Regstack.pop())
+ interpreter.current[::4] = long(Regstack.pop())
t, sym
- cursect[::4] = str(Regstack.pop())
+ interpreter.current[::4] = str(Regstack.pop())
w, int
- cursect[::2] = long(Regstack.pop())
+ interpreter.current[::2] = long(Regstack.pop())
w, sym
- cursect[::2] = str(Regstack.pop())
+ interpreter.current[::2] = str(Regstack.pop())
# vim: ft=python
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- tran.py 16 May 2003 15:24:29 -0000 1.73
+++ tran.py 16 May 2003 15:41:19 -0000 1.74
@@ -244,11 +244,6 @@
else: raise 'Unknown meaning type in', `Meaning[tok]`
else: raise 'bad token', tok
-# Main output sections.
-Text = Linkie('<')
-Data = Linkie('<')
-Bss = Linkie('<')
-cursect = Text
Regstack = []
Generic_Register = Register()
reggen = Generic_Register.child_generator()
@@ -270,7 +265,7 @@
np = (name + '|').split('|')
name = np[0]
pa = np[1]
- g = 'cursect, Regstack, current_recordee, current_register_index'
+ g = 'Regstack, current_recordee, current_register_index'
exec 'def _p (%s):\n global %s\n%s\n' % (pa, g, code)
flags = 0
if pa: flags |= MA_PREFIX
@@ -284,6 +279,10 @@
interpreter = container()
interpreter.state = outer_state
+interpreter.text = Linkie('<')
+interpreter.data = Linkie('<')
+interpreter.bss = Linkie('<')
+interpreter.current = interpreter.text
verbose = 0
@@ -314,12 +313,14 @@
if verbose: print '(%s) %s' % (' '.join(map(str, Regstack)), tok)
interpreter.state(tok)
tok = prep.get_token()
- print 'TEXT'; Text.dump()
- print 'DATA'; Data.dump()
- print 'BSS'; Bss.dump()
+ print 'TEXT'; interpreter.text.dump()
+ print 'DATA'; interpreter.data.dump()
+ print 'BSS'; interpreter.bss.dump()
if Regstack:
raise 'Regstack not empty after parsing ended', Regstack
- binary = elf.make_ELF32_object(text = Text, data = Data, bss = Bss,
+ binary = elf.make_ELF32_object(text = interpreter.text,
+ data = interpreter.data,
+ bss = interpreter.bss,
flags = 's')
f = open(output_name, 'w')
binary.get_file().tofile(f)
|
|
From: <di...@us...> - 2003-05-16 15:24:32
|
Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv15726
Modified Files:
tran-builtins tran.py
Log Message:
renamed State to interpreter.state
Index: tran-builtins
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- tran-builtins 1 May 2003 20:52:34 -0000 1.4
+++ tran-builtins 16 May 2003 15:24:28 -0000 1.5
@@ -50,13 +50,13 @@
if Meaning.has_key(name): raise 'duplicate declaration', name
current_recordee = Meaning[name] = []
def record_state (tok):
- global current_recordee, State
+ global current_recordee
if tok == Semicolon:
- State = outer_state
+ interpreter.state = outer_state
current_recordee = None
else:
current_recordee.append(tok)
- State = record_state
+ interpreter.state = record_state
:regs|family
if Meaning.has_key(family): raise 'duplicate declaration', tok
@@ -66,7 +66,7 @@
Registers[f] = family
current_register_index = 0
def regs_state (tok):
- global State, current_register_family, current_register_index
+ global current_register_family, current_register_index
if tok != Semicolon:
if Meaning.has_key(tok): raise 'duplicate declaration', tok
r = Register(current_register_family, current_register_index)
@@ -74,10 +74,10 @@
Registers[r] = tok
current_register_index += 1
else:
- State = outer_state
+ interpreter.state = outer_state
current_register_family += 1
current_register_index = None
- State = regs_state
+ interpreter.state = regs_state
align int
cursect.align(long(Regstack.pop()))
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- tran.py 15 May 2003 13:45:26 -0000 1.72
+++ tran.py 16 May 2003 15:24:29 -0000 1.73
@@ -270,7 +270,7 @@
np = (name + '|').split('|')
name = np[0]
pa = np[1]
- g = 'cursect, Regstack, State, current_recordee, current_register_index'
+ g = 'cursect, Regstack, current_recordee, current_register_index'
exec 'def _p (%s):\n global %s\n%s\n' % (pa, g, code)
flags = 0
if pa: flags |= MA_PREFIX
@@ -278,9 +278,13 @@
current_recordee = None
current_register_family = 0
-State = outer_state
Registers = {Generic_Register: 'reg'} # for reverse translation
+class container (object): pass
+
+interpreter = container()
+interpreter.state = outer_state
+
verbose = 0
def main ():
@@ -308,7 +312,7 @@
tok = prep.get_token()
while tok <> None:
if verbose: print '(%s) %s' % (' '.join(map(str, Regstack)), tok)
- State(tok)
+ interpreter.state(tok)
tok = prep.get_token()
print 'TEXT'; Text.dump()
print 'DATA'; Data.dump()
|