mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-01-08 07:31:32 +00:00
Writing out Ext REL file
This commit is contained in:
parent
ad8c954ecb
commit
2fea8165b2
@ -415,7 +415,6 @@ def id_lookup(nameptr, len)
|
||||
idptr = idmatch(nameptr, len, idlocal_tbl, locals)
|
||||
if not idptr
|
||||
idptr = idmatch(nameptr, len, idglobal_tbl, globals)
|
||||
// if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
fin
|
||||
return idptr
|
||||
end
|
||||
@ -423,12 +422,8 @@ def idglobal_lookup(nameptr, len)
|
||||
word idptr
|
||||
|
||||
idptr = idmatch(nameptr, len, idglobal_tbl, globals)
|
||||
// if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
return idptr
|
||||
end
|
||||
def emit_iddata(value, size, namestr)#0
|
||||
emit_fill(size)
|
||||
end
|
||||
def iddata_add(namestr, len, type, size)#0
|
||||
if idmatch(namestr, len, idglobal_tbl, globals); exit_err(ERR_DUP|ERR_ID); fin
|
||||
lastglobal=>idval = datasize
|
||||
@ -464,6 +459,7 @@ def idconst_add(namestr, len, value)#0
|
||||
end
|
||||
def idfunc_add(namestr, len, type, tag, cfnparms, cfnvals)#0
|
||||
idglobal_add(namestr, len, type|FUNC_TYPE, tag, cfnparms, cfnvals)
|
||||
def_cnt++
|
||||
end
|
||||
def idfunc_set(namestr, len, tag, cparms, cvals)#0
|
||||
word idptr
|
||||
@ -760,18 +756,151 @@ def gen_bop(tkn, seq)
|
||||
return seq
|
||||
end
|
||||
//
|
||||
// Write REL file
|
||||
// A DCI string is one that has the high bit set for every character except the last.
|
||||
// More efficient than C or Pascal strings.
|
||||
//
|
||||
def dcitos(dci, str)
|
||||
byte len, c
|
||||
len = 0
|
||||
repeat
|
||||
c = ^(dci + len)
|
||||
len++
|
||||
^(str + len) = c & $7F
|
||||
until not c & $80
|
||||
^str = len
|
||||
return len
|
||||
end
|
||||
def stodci(str, dci)
|
||||
byte len, c
|
||||
len = ^str
|
||||
if not len; return 0; fin
|
||||
c = toupper(^(str + len)) & $7F
|
||||
len--
|
||||
^(dci + len) = c
|
||||
while len
|
||||
c = toupper(^(str + len)) | $80
|
||||
len--
|
||||
^(dci + len) = c
|
||||
loop
|
||||
return ^str
|
||||
end
|
||||
//
|
||||
// Write Extended REL header
|
||||
//
|
||||
def writeheader(refnum)#0
|
||||
word moddep
|
||||
byte header[128]
|
||||
|
||||
moddep = @header:12 // Beginning of module dependency list
|
||||
while moddep_cnt
|
||||
moddep_cnt--
|
||||
moddep = moddep + stodci(@moddep_tbl[moddep_cnt*16], moddep)
|
||||
loop
|
||||
^moddep = 0 // Terminate dependency list
|
||||
moddep++
|
||||
header:0 = moddep - @header + codeptr - codebuff // sizeof header+data+bytecode
|
||||
header:2 = $DA7F // Magic #
|
||||
header:4 = modsysflags // Module SYSFLAGS
|
||||
header:6 = datasize + MODADDR // Byte code offset
|
||||
header:8 = def_cnt // DEFinition count
|
||||
header:10 = entrypoint - codebuff + MODADDR // Init entrypoint
|
||||
fileio:write(refnum, @header, moddep - @header)
|
||||
end
|
||||
//
|
||||
// Write DeFinition Directory
|
||||
//
|
||||
def writeDFD(refnum)#0
|
||||
word dirptr, idptr, idcnt
|
||||
byte defdir[128]
|
||||
|
||||
dirptr, idptr, idcnt = @defdir, idglobal_tbl, globals
|
||||
while idcnt
|
||||
if idptr=>idtype & FUNC_TYPE and not idptr=>idtype & EXTERN_TYPE
|
||||
dirptr->0 = $02
|
||||
dirptr=>1 = (ctag_tbl=>[idptr=>idval] & MASK_CTAG) + MODADDR
|
||||
dirptr = dirptr + 4
|
||||
fin
|
||||
idptr = idptr + idptr->idname + t_id
|
||||
idcnt--
|
||||
loop
|
||||
fileio:write(refnum, @defdir, dirptr - @defdir)
|
||||
end
|
||||
//
|
||||
// Build External Symbol Directory on heap
|
||||
//
|
||||
def buildESD#2
|
||||
byte symnum
|
||||
word dirptr, idptr, idcnt, dirlen
|
||||
|
||||
symnum, dirptr, idptr, idcnt = 0, heapmark, idglobal_tbl, globals
|
||||
while idcnt
|
||||
if idptr=>idtype & EXPORT_TYPE
|
||||
dirptr = dirptr + stodci(idptr=>idname, dirptr)
|
||||
dirptr->0 = $08
|
||||
dirptr=>1 = (ctag_tbl[idptr=>idval] & MASK_CTAG) + MODADDR
|
||||
dirptr = dirptr + 3
|
||||
elsif idptr=>idtype & EXTERN_TYPE
|
||||
dirptr = dirptr + stodci(idptr=>idname, dirptr)
|
||||
dirptr->0 = $10
|
||||
dirptr->1 = symnum
|
||||
dirptr = dirptr + 3
|
||||
idptr->extnum = symnum
|
||||
symnum++
|
||||
fin
|
||||
idptr = idptr + idptr->idname + t_id
|
||||
idcnt--
|
||||
loop
|
||||
^dirptr = 0
|
||||
dirlen = dirptr - heapmark + 1
|
||||
dirptr = heapalloc(dirlen)
|
||||
return dirptr, dirlen
|
||||
end
|
||||
//
|
||||
// Write ReLocation Directory
|
||||
//
|
||||
def writeRLD(refnum)#0
|
||||
word rld, i
|
||||
|
||||
rld = heapmark
|
||||
for i = 0 to fixup_cnt
|
||||
if i & $7F == $40 // Write out blocks of entries
|
||||
fileio:write(refnum, heapmark, rld - heapmark)
|
||||
rld = heapmark
|
||||
fin
|
||||
rld->0 = $01
|
||||
rld = rld + 4
|
||||
next
|
||||
^rld = 0
|
||||
fileio:write(refnum, heapmark, rld - heapmark + 1)
|
||||
end
|
||||
//
|
||||
// Write Extended REL file
|
||||
//
|
||||
def writemodule(refnum)#0
|
||||
word esd, esdlen
|
||||
//
|
||||
// Build module header
|
||||
// Write module header
|
||||
//
|
||||
|
||||
writeheader(refnum)
|
||||
//
|
||||
// Write data/code buffer
|
||||
//
|
||||
|
||||
fileio:write(refnum, codebuff, codeptr - codebuff)
|
||||
//
|
||||
// Write bytecode definition directory
|
||||
//
|
||||
writeDFD(refnum)
|
||||
//
|
||||
// Build EXERN/ENTRY directory
|
||||
//
|
||||
esd, esdlen = buildESD
|
||||
//
|
||||
// Write relocation directory
|
||||
//
|
||||
writeRLD(refnum)
|
||||
//
|
||||
// Write EXTERN/EBTRY directory
|
||||
//
|
||||
fileio:write(refnum, esd, esdlen)
|
||||
heaprelease(esd)
|
||||
end
|
||||
|
@ -214,6 +214,7 @@ struc t_id
|
||||
word idtype
|
||||
byte funcparms
|
||||
byte funcvals
|
||||
byte extnum
|
||||
byte idname
|
||||
end
|
||||
//
|
||||
@ -227,8 +228,9 @@ const OPSEQNUM = 256
|
||||
const CTAGNUM = 1024
|
||||
const IDGLOBALSZ = 2048
|
||||
const IDLOCALSZ = 512
|
||||
const FIXUPNUM = 2048
|
||||
word codetag = -1
|
||||
word idglobal_tbl, idlocal_tbl, ctag_tbl
|
||||
word idglobal_tbl, idlocal_tbl, ctag_tbl, fixup_tbl
|
||||
word pending_seq
|
||||
word globals, lastglobal, lastlocal, savelast
|
||||
word codebufsz, datasize, framesize, savesize
|
||||
@ -236,9 +238,13 @@ byte locals, savelocals
|
||||
word codebuff, codeptr, entrypoint
|
||||
word modsysflags
|
||||
byte[16] moddep_tbl[8]
|
||||
byte moddep_cnt
|
||||
byte moddep_cnt, def_cnt, fixup_cnt
|
||||
predef emit_pending_seq#0
|
||||
//
|
||||
// Module relocation base address
|
||||
//
|
||||
const MODADDR = $1000
|
||||
//
|
||||
// Exports for optimizer module
|
||||
//
|
||||
export word freeop_lst
|
||||
|
@ -1002,7 +1002,7 @@ def loadmod(mod)#1
|
||||
//
|
||||
// Read in remainder of module into memory for fixups.
|
||||
//
|
||||
addr = modaddr//
|
||||
addr = modaddr
|
||||
repeat
|
||||
addr = addr + rdlen
|
||||
rdlen = read(refnum, addr, 4096)
|
||||
@ -1020,7 +1020,7 @@ def loadmod(mod)#1
|
||||
modend = modaddr + modsize
|
||||
rld = modend // Re-Locatable Directory
|
||||
esd = rld // Extern+Entry Symbol Directory
|
||||
while ^esd // Scan to end of ESD
|
||||
while ^esd // Scan to end of ESD
|
||||
esd = esd + 4
|
||||
loop
|
||||
esd = esd + 1
|
||||
|
Loading…
Reference in New Issue
Block a user