From b176847778577943a95ceefeb77eafee9c69a724 Mon Sep 17 00:00:00 2001 From: Dave Schmenk Date: Sun, 14 Jan 2018 21:41:47 -0800 Subject: [PATCH] Reduce stack usage for ENTER/LEAVE but incompatible bytecode --- src/toolsrc/codegen.c | 4 ++-- src/toolsrc/codegen.pla | 3 ++- src/vmsrc/cmd.pla | 6 +++--- src/vmsrc/plvm02.s | 6 ++++-- src/vmsrc/plvm802.s | 25 +++++++++++++------------ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/toolsrc/codegen.c b/src/toolsrc/codegen.c index 4060438..06b8791 100755 --- a/src/toolsrc/codegen.c +++ b/src/toolsrc/codegen.c @@ -354,7 +354,7 @@ void emit_header(void) { printf("\t%s\t_SEGEND-_SEGBEGIN\t; LENGTH OF HEADER + CODE/DATA + BYTECODE SEGMENT\n", DW); printf("_SEGBEGIN%c\n", LBL); - printf("\t%s\t$DA7F\t\t\t; MAGIC #\n", DW); + printf("\t%s\t$6502\t\t\t; MAGIC #\n", DW); printf("\t%s\t_SYSFLAGS\t\t\t; SYSTEM FLAGS\n", DW); printf("\t%s\t_SUBSEG\t\t\t; BYTECODE SUB-SEGMENT\n", DW); printf("\t%s\t_DEFCNT\t\t\t; BYTECODE DEF COUNT\n", DW); @@ -802,7 +802,7 @@ void emit_leave(void) { emit_pending_seq(); if (localsize) - printf("\t%s\t$5A\t\t\t; LEAVE\n", DB); + printf("\t%s\t$5A,$%02X\t\t\t; LEAVE\t%d\n", DB, localsize, localsize); else printf("\t%s\t$5C\t\t\t; RET\n", DB); } diff --git a/src/toolsrc/codegen.pla b/src/toolsrc/codegen.pla index 6259e98..82a2a95 100644 --- a/src/toolsrc/codegen.pla +++ b/src/toolsrc/codegen.pla @@ -190,6 +190,7 @@ def emit_leave#0 emit_pending_seq if framesize emit_byte($5A) + emit_byte(framesize) else emit_byte($5C) fin @@ -805,7 +806,7 @@ def writeheader(refnum) len = moddep - 1 - @header modfix = len + RELADDR - codebuff // Convert generated address into module adress header:0 = len + codeptr - codebuff // sizeof header+data+bytecode - header:2 = $DA7F // Magic # + header:2 = $6502 // Magic # header:4 = modsysflags // Module SYSFLAGS header:6 = len + RELADDR + datasize // Byte code offset header:8 = def_cnt // DEFinition count diff --git a/src/vmsrc/cmd.pla b/src/vmsrc/cmd.pla index e04a223..9f229a4 100755 --- a/src/vmsrc/cmd.pla +++ b/src/vmsrc/cmd.pla @@ -938,7 +938,7 @@ def loadmod(mod)#1 moddep = @header.1 defofst = modsize + RELADDR init = 0 - if rdlen > 4 and header:2 == $DA7F // DAVE+1 = magic number :-) + if rdlen > 4 and header:2 == $6502 // DAVE+1 = magic number :-) // // This is an EXTended RELocatable (data+bytecode) module. // @@ -951,7 +951,7 @@ def loadmod(mod)#1 // Load module dependencies. // while ^moddep - if !lookuptbl(moddep, symtbl)//lookupmod(moddep) + if !lookuptbl(moddep, symtbl) close(refnum) refnum = 0 if loadmod(moddep) < 0 @@ -995,7 +995,7 @@ def loadmod(mod)#1 // // Add module to symbol table. // - addsym(mod, modaddr)//addmod(mod, modaddr) + addsym(mod, modaddr) // // Apply all fixups and symbol import/export. // diff --git a/src/vmsrc/plvm02.s b/src/vmsrc/plvm02.s index 5476ea6..d43cc4c 100755 --- a/src/vmsrc/plvm02.s +++ b/src/vmsrc/plvm02.s @@ -1528,7 +1528,7 @@ JMPTMP JMP (TMP) ;* ENTER INY LDA (IP),Y - PHA ; SAVE ON STACK FOR LEAVE +; PHA ; SAVE ON STACK FOR LEAVE EOR #$FF ; ALLOCATE FRAME SEC ADC PPL @@ -1560,7 +1560,9 @@ LEAVEX STA ALTRDOFF LDA PSR PHA PLP -LEAVE PLA ; DEALLOCATE POOL + FRAME +LEAVE ;PLA ; DEALLOCATE POOL + FRAME + +INC_IP + LDA (IP),Y CLC ADC IFPL STA PPL diff --git a/src/vmsrc/plvm802.s b/src/vmsrc/plvm802.s index 38db704..d734bf4 100644 --- a/src/vmsrc/plvm802.s +++ b/src/vmsrc/plvm802.s @@ -1517,8 +1517,8 @@ ENTER INY STA $7D0+31 PLA } - PHA ; SAVE ON STACK FOR LEAVE - DEC HWSP ; UPDATE HWSP TO SKIP FRAME SIZE + ;PHA ; SAVE ON STACK FOR LEAVE + ;DEC HWSP ; UPDATE HWSP TO SKIP FRAME SIZE +ACCMEM16 ; 16 BIT A/M ; AND #$00FF EOR #$FFFF ; ALLOCATE FRAME @@ -1549,7 +1549,16 @@ ENTER INY ;* LEAVE FUNCTION ;* LEAVEX STX ALTRDOFF -LEAVE +ACCMEM8 ; 8 BIT A/M +LEAVE ;PLA ; DEALLOCATE POOL + FRAME + +INC_IP + LDA (IP),Y + AND #$00FF + CLC + ADC IFP + STA PP + PLA ; RESTORE PREVIOUS FRAME + STA IFP + +ACCMEM8 ; 8 BIT A/M TSC ; MOVE HW EVAL STACK TO ZP EVAL STACK EOR #$FF SEC @@ -1587,15 +1596,7 @@ LEAVE +ACCMEM8 ; 8 BIT A/M LDX $C010 + LDX TMPL } - TYX ; RESTORE NEW ESP - PLA ; DEALLOCATE POOL + FRAME - +ACCMEM16 ; 16 BIT A/M - AND #$00FF - CLC - ADC IFP - STA PP - PLA ; RESTORE PREVIOUS FRAME - STA IFP + TYX ; RESTORE NEW ESP SEC ; SWITCH TO EMULATED MODE XCE !AS