picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit 46c1913860bdb59d25d54f3457dd59359e106a14
parent ba78519f05016007bd4b4ebda64e385ca316bd5b
Author: Alexander Burger <abu@software-lab.de>
Date:   Thu, 11 Oct 2012 07:20:00 +0200

emu64 continued
Diffstat:
Msrc64/Makefile | 14++++----------
Msrc64/arch/emu.l | 239++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc64/arch/ppc64.l | 10++++++++--
3 files changed, 132 insertions(+), 131 deletions(-)

diff --git a/src64/Makefile b/src64/Makefile @@ -1,4 +1,4 @@ -# 07oct12abu +# 10oct12abu # (c) Software Lab. Alexander Burger .SILENT: @@ -38,16 +38,12 @@ ifeq ($(UNAME), Linux) SYS = .linux FMT = .s ARCH = x86-64 - MKASM-BASE = - MKASM-LIB = -fpic AS = as else ifeq ($(MACHINE), ppc64) SYS = .linux FMT = .s ARCH = ppc64 - MKASM-BASE = -'prSym "ppc64.symtab"' - MKASM-LIB = -fpic -'rdSym "ppc64.symtab"' AS = as -mppc64 -a64 endif endif @@ -60,8 +56,6 @@ else SYS = .sunOs FMT = .s ARCH = x86-64 - MKASM-BASE = - MKASM-LIB = -fpic AS = gas --64 LD-MAIN = -m64 -lc -lm -ldl -lsocket -lnsl LD-SHARED = -m64 -shared @@ -100,13 +94,13 @@ $(lib)/ht: $(ARCH)$(SYS).ht.o # Explicit builds for cross-assembly $(ARCH)$(SYS).base$(FMT): sysdefs arch/$(ARCH).l $(baseFiles) sys/$(ARCH)$(SYS).code.l - ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) base $(lib)/map $(baseFiles) sys/$(ARCH)$(SYS).code.l $(MKASM-BASE) + ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) base $(lib)/map $(baseFiles) sys/$(ARCH)$(SYS).code.l $(ARCH)$(SYS).ext$(FMT): sysdefs arch/$(ARCH).l ext.l $(ARCH)$(SYS).base$(FMT) - ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) ext "" $(MKASM-LIB) ext.l + ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) ext "" -fpic ext.l $(ARCH)$(SYS).ht$(FMT): sysdefs arch/$(ARCH).l ht.l $(ARCH)$(SYS).base$(FMT) - ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) ht "" $(MKASM-LIB) ht.l + ./mkAsm $(ARCH) "$(SYS)" $(FMT) $(OS) ht "" -fpic ht.l sysdefs: sysdefs.c $(CC) -o sysdefs -D_FILE_OFFSET_BITS=64 sysdefs.c diff --git a/src64/arch/emu.l b/src64/arch/emu.l @@ -1,4 +1,4 @@ -# 09oct12abu +# 10oct12abu # (c) Software Lab. Alexander Burger # *AsmOpcodes *AsmCode *AsmPos *Labels *AsmData *SysFun @@ -982,128 +982,129 @@ (if *LittleEndian (prinl " struct {uint32_t l, h;};") (prinl " struct {uint32_t h, l;};") ) + (prinl "} op, *ptr;") + (prinl) ) + +(de epilog (File) + (mapc prinl + (if *FPic + (quote + "extern uint16_t *PC;" + "extern uint8_t *Stack;" + "extern op A, C, E, X, Y, Z, L, S;" + "extern uint64_t Result;" + "extern int Carry;" + "extern void mul2(uint64_t);" + "extern void div2(uint64_t);" + "extern void begin(int,int,int,int,int,int,int);" + "extern void *argv(int,ptr);" + "extern void retv(int,ptr);" ) + (quote + "uint16_t *PC;" + "uint8_t *Stack;" + "op A, C, E, X, Y, Z, L, S;" + "uint64_t Result;" + "int Carry;" + NIL + "static void run(int);" + NIL + "void mul2(uint64_t src) {" + " uint32_t h = src >> 32;" + " uint32_t l = (uint32_t)src;" + " op a, b;" + NIL + " a.n = (uint64_t)A.l * l;" + " b.n = (uint64_t)A.h * l;" + " C.n = (uint64_t)b.h + ((a.h += b.l) < b.l);" + " b.n = (uint64_t)A.l * h;" + " C.n += (uint64_t)b.h + ((a.h += b.l) < b.l);" + " C.n += (uint64_t)A.h * h;" + " A.n = a.n;" + "}" + NIL + "void div2(uint64_t src) {" + " uint64_t vn0, vn1, q1, q0, rhat;" + " int s;" + NIL + " if (C.n >= src)" + " A.n = C.n = MAX64;" # Overflow + " else {" + " s = 0;" + " while ((int64_t)src > 0) {" # Normalize + " C.n = (C.n << 1) + ((int64_t)A.n < 0);" # Shift dividend left + " A.n <<= 1;" + " src <<= 1;" # and divisor + " ++s;" + " }" + " vn1 = src >> 32;" # Split divisor into high + " vn0 = (uint32_t)src;" # and low 32 bits + " q1 = C.n / vn1;" # First quotient digit + " rhat = C.n - q1 * vn1;" + NIL + " while (q1 >> 32 || q1 * vn0 > (rhat << 32) + A.h) {" + " --q1;" + " if ((rhat += vn1) >> 32)" + " break;" + " }" + " C.n = (C.n << 32) + A.h - q1 * src;" + " q0 = C.n / vn1;" # Second quotient digit + " rhat = C.n - q0 * vn1;" + NIL + " while (q0 >> 32 || q0 * vn0 > (rhat << 32) + A.l) {" + " --q0;" + " if ((rhat += vn1) >> 32)" + " break;" + " }" + " C.n = ((C.n << 32) + A.l - q0 * src) >> s;" # Remainder + " A.n = (q1 << 32) + q0;" # Quotient + " }" + "}" + NIL + "void begin(int i, int a, int c, int e, int x, int y, int z) {" + " S.p -= 8, *(uint16_t**)S.p = PC;" + " S.p -= 8, ((ptr)S.p)->l = Carry;" + " S.p -= 8, ((ptr)S.p)->n = Result;" + " S.p -= 8, *(ptr)S.p = Z, Z.n = z;" + " S.p -= 8, *(ptr)S.p = Y, Y.n = y;" + " S.p -= 8, *(ptr)S.p = X, X.n = x;" + " S.p -= 8, *(ptr)S.p = E, E.n = e;" + " S.p -= 8, *(ptr)S.p = C, C.n = c;" + " S.p -= 8, *(ptr)S.p = A, A.n = a;" + " run(i);" + " A = *(ptr)S.p, S.p += 8;" + " C = *(ptr)S.p, S.p += 8;" + " E = *(ptr)S.p, S.p += 8;" + " X = *(ptr)S.p, S.p += 8;" + " Y = *(ptr)S.p, S.p += 8;" + " Z = *(ptr)S.p, S.p += 8;" + " Result = ((ptr)S.p)->n, S.p += 8;" + " Carry = ((ptr)S.p)->l, S.p += 8;" + " PC = *(uint16_t**)S.p, S.p += 8;" + "}" + NIL + "void *argv(int i, ptr p) {" + " if (p) {" + " if (i == 0)" + " while (((uint8_t**)p)[i] = p[i].p)" + " ++i;" + " else" + " while (--i >= 0)" + " ((uint8_t**)p)[i] = p[i].p;" + " }" + " return p;" + "}" + NIL + "void retv(int i, ptr p) {" + " if (p)" + " while (--i >= 0)" + " p[i].n = (uint64_t)(unsigned long)((uint8_t**)p)[i];" + "}" + NIL ) ) ) (mapc prinl (quote - "} op, *ptr;" - NIL - ~(if *FPic - (quote - "extern uint16_t *PC;" - "extern uint8_t *Stack;" - "extern op A, C, E, X, Y, Z, L, S;" - "extern uint64_t Result;" - "extern int Carry;" - "extern void mul2(uint64_t);" - "extern void div2(uint64_t);" - "extern void begin(int,int,int,int,int,int,int);" - "extern void *argv(int,ptr);" - "extern void retv(int,ptr);" ) - (quote - "uint16_t *PC;" - "uint8_t *Stack;" - "op A, C, E, X, Y, Z, L, S;" - "uint64_t Result;" - "int Carry;" - NIL - "static void run(int);" - NIL - "void mul2(uint64_t src) {" - " uint32_t h = src >> 32;" - " uint32_t l = (uint32_t)src;" - " op a, b;" - NIL - " a.n = (uint64_t)A.l * l;" - " b.n = (uint64_t)A.h * l;" - " C.n = (uint64_t)b.h + ((a.h += b.l) < b.l);" - " b.n = (uint64_t)A.l * h;" - " C.n += (uint64_t)b.h + ((a.h += b.l) < b.l);" - " C.n += (uint64_t)A.h * h;" - " A.n = a.n;" - "}" - NIL - "void div2(uint64_t src) {" - " uint64_t vn0, vn1, q1, q0, rhat;" - " int s;" - NIL - " if (C.n >= src)" - " A.n = C.n = MAX64;" # Overflow - " else {" - " s = 0;" - " while ((int64_t)src > 0) {" # Normalize - " C.n = (C.n << 1) + ((int64_t)A.n < 0);" # Shift dividend left - " A.n <<= 1;" - " src <<= 1;" # and divisor - " ++s;" - " }" - " vn1 = src >> 32;" # Split divisor into high - " vn0 = (uint32_t)src;" # and low 32 bits - " q1 = C.n / vn1;" # First quotient digit - " rhat = C.n - q1 * vn1;" - NIL - " while (q1 >> 32 || q1 * vn0 > (rhat << 32) + A.h) {" - " --q1;" - " if ((rhat += vn1) >> 32)" - " break;" - " }" - " C.n = (C.n << 32) + A.h - q1 * src;" - " q0 = C.n / vn1;" # Second quotient digit - " rhat = C.n - q0 * vn1;" - NIL - " while (q0 >> 32 || q0 * vn0 > (rhat << 32) + A.l) {" - " --q0;" - " if ((rhat += vn1) >> 32)" - " break;" - " }" - " C.n = ((C.n << 32) + A.l - q0 * src) >> s;" # Remainder - " A.n = (q1 << 32) + q0;" # Quotient - " }" - "}" - NIL - "void begin(int i, int a, int c, int e, int x, int y, int z) {" - " S.p -= 8, *(uint16_t**)S.p = PC;" - " S.p -= 8, ((ptr)S.p)->l = Carry;" - " S.p -= 8, ((ptr)S.p)->n = Result;" - " S.p -= 8, *(ptr)S.p = Z, Z.n = z;" - " S.p -= 8, *(ptr)S.p = Y, Y.n = y;" - " S.p -= 8, *(ptr)S.p = X, X.n = x;" - " S.p -= 8, *(ptr)S.p = E, E.n = e;" - " S.p -= 8, *(ptr)S.p = C, C.n = c;" - " S.p -= 8, *(ptr)S.p = A, A.n = a;" - " run(i);" - " A = *(ptr)S.p, S.p += 8;" - " C = *(ptr)S.p, S.p += 8;" - " E = *(ptr)S.p, S.p += 8;" - " X = *(ptr)S.p, S.p += 8;" - " Y = *(ptr)S.p, S.p += 8;" - " Z = *(ptr)S.p, S.p += 8;" - " Result = ((ptr)S.p)->n, S.p += 8;" - " Carry = ((ptr)S.p)->l, S.p += 8;" - " PC = *(uint16_t**)S.p, S.p += 8;" - "}" - NIL - "void *argv(int i, ptr p) {" - " if (p) {" - " if (i == 0)" - " while (((uint8_t**)p)[i] = p[i].p)" - " ++i;" - " else" - " while (--i >= 0)" - " ((uint8_t**)p)[i] = p[i].p;" - " }" - " return p;" - "}" - NIL - "void retv(int i, ptr p) {" - " if (p)" - " while (--i >= 0)" - " p[i].n = (uint64_t)(unsigned long)((uint8_t**)p)[i];" - "}" - NIL ) ) "uint16_t Code[];" NIL - "op Data[] = {" ) ) ) - -(de epilog (File) + "op Data[] = {" ) ) (setq *AsmData (flip *AsmData) *AsmCode (flip *AsmCode) ) diff --git a/src64/arch/ppc64.l b/src64/arch/ppc64.l @@ -1,4 +1,4 @@ -# 04oct12abu +# 10oct12abu # (c) Software Lab. Alexander Burger # Byte order @@ -38,6 +38,10 @@ (zero *DataPos *CodePos) (off *DataLabels *CodeLabels *DataIndex *CodeIndex) +(redef fpic () + (fpic) + (rdSym "ppc64.symtab") ) + (redef label (Lbl Flg) (ifn *FPic (cond @@ -1566,6 +1570,8 @@ ### Decoration ### (de prolog (File)) -(de epilog (File)) +(de epilog (File) + (unless *FPic + (prSym "ppc64.symtab") ) ) # vi:et:ts=3:sw=3