Kernel 0.9.1 : ASM rewrite....Local Symbols

This commit is contained in:
Rémy GIBERT 2018-03-22 16:45:23 +00:00
parent 6b6089c89e
commit 1ae1532109
7 changed files with 130 additions and 91 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@ NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
*---------------------------------------
DIR.Init lda #$80
DIR.Reset lda #$80
ldy #ASM.LI.ON
sta (pData),y

View File

@ -15,15 +15,7 @@ AUTO 4,1
* & = octal
* * = PC
*---------------------------------------
EXP.Eval lda #2
sta SRC.ACC.SIZE Default To WORD (2 bytes)
stz SRC.ACC
stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
>STZ.G EXP.Modifier
EXP.Eval >STZ.G EXP.Modifier
>STZ.G EXP.Prefix
>STZ.G EXP.Operator
@ -44,7 +36,15 @@ EXP.Eval.Missing lda #ERR.MISSING.EXP
sec
rts
EXP.Eval.Next jsr SRC.GetNextChar
EXP.Eval.Next lda #2
sta SRC.ACC.SIZE Default To WORD (2 bytes)
stz SRC.ACC
stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetNextChar
bcs EXP.Eval.Missing
EXP.Eval.Next1 cmp #'.' Local Label?
@ -194,7 +194,7 @@ EXP.GetLocal jsr SRC.GetNextChar
lda SRC.ACC
beq EXP.EvalExitSYN .0 is not allowed
jsr SYM.GetLocal
jsr SYM.LookupLocal
bcs EXP.EvalExitUND
rts
@ -223,7 +223,7 @@ EXP.GetSymbolValue jsr SYM.LookupGlobal
bpl .1
lda (pData),y
and #SYM.F.SIZE
and #SYMG.F.SIZE
sta SRC.ACC.SIZE
* clc
rts

View File

@ -95,11 +95,11 @@ FIO.LOAD.ASM.T >STYA ZPPtr2
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPOPtr
sta ZPOpsPtr
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPOPtr+1
sta ZPOpsPtr+1
.9 rts
*---------------------------------------

View File

@ -132,16 +132,16 @@ SRC.ParseLine.Macro >LDA.G ASM.PASS If Pass#2, ignore
SRC.ParseLine.RTS rts
*---------------------------------------
SRC.ParseLine.LABEL lda #0
>STA.G SYM.bGlobal
jsr SRC.GetChar
SRC.ParseLine.LABEL jsr SRC.GetChar
cmp #' ' no label...go scan dir/opcode
beq SRC.ParseLine.DirOp
cmp #'.' local symbol?
bne .1
>LDA.G SYM.bGlobal
beq SRC.ParseLine.InvLbl
jsr SRC.GetNextChar
bcs SRC.ParseLine.InvLbl
jsr SRC.GetDecimal
@ -158,10 +158,11 @@ SRC.ParseLine.LABEL lda #0
bcs SRC.ParseLine.RTS
bra SRC.ParseLine.DirOp
.1 lda #$ff
.1 jsr SYMG.FlushGlobal
bcs SRC.ParseLine.Err
lda #$ff
>STA.G SYM.bGlobal
inc
sta (ZPLocalBuf) Reset Local Labels
>LDA.G ASM.PASS
bne .3
@ -171,11 +172,11 @@ SRC.ParseLine.LABEL lda #0
jsr SYM.LookupGlobal already defined...get it
>LDA.G SYM.Lookup+SYM.F
bit #SYM.F.RW
>LDA.G SYM.Lookup+SYMG.F
bit #SYMG.F.RW
bne .2 R/W, always update...
bit #SYM.F.RESOLVED
bit #SYMG.F.RESOLVED
bne SRC.ParseLine.Redef
.2 jsr SYM.UpdateGlobalPC
@ -210,11 +211,11 @@ SRC.ParseLine.DirOp jsr SRC.GetNextCharNB Scan for an Opcode...
bcs SRC.ParseLine.Err
SRC.ParseLine.Ok clc
rts
SRC.ParseLine.Err rts
SRC.ParseLine.InvLbl
lda #ERR.INV.LABEL
SRC.ParseLine.Err sec
sec
rts
SRC.ParseLine.Redef lda #ERR.SYMBOL.REDEF
@ -245,7 +246,7 @@ SRC.ParseLine.ExecMacro
SRC.ParseLine.OpCode
stz SRC.AM.StrBuf
>LDYA ZPOPtr
>LDYA ZPOpsPtr
>STYA ZPOpDefPtr
.1 lda (ZPOpDefPtr) End Of OpCode List
@ -297,19 +298,13 @@ SRC.ParseLine.OpCode
inc ZPLinePtr+1
.5 tya Skip nPtr+Len+OP
clc
adc #3
adc ZPOpDefPtr
sta ZPOpDefPtr
bcc .6
inc ZPOpDefPtr+1
.6 bra SRC.ParseLine.AM
.5 bra SRC.ParseLine.AM
.7 lda ZPOpDefPtr
clc
adc (ZPOpDefPtr)
tax
lda ZPOpDefPtr+1
ldy #1
adc (ZPOpDefPtr),y
@ -317,7 +312,7 @@ SRC.ParseLine.OpCode
sta ZPOpDefPtr+1
bra .1
.8 jmp SRC.ParseLine.AMCheck
.8 jmp SRC.ParseLine.OPAMCheckFF
.9 lda #ERR.INV.OPCODE
sec
@ -458,7 +453,17 @@ SRC.ParseLine.OPAMCheckFF
>STA.G SRC.AMID
SRC.ParseLine.OPAMCheck
lda (ZPOpDefPtr)
ldy #2 Skip nPtr+Len+OP
lda (ZPOpDefPtr),y LEN
sec LEN Byte
adc #2 nPtr
adc ZPOpDefPtr
sta ZPOpDefPtr
bcc .10
inc ZPOpDefPtr+1
.10 lda (ZPOpDefPtr)
.1 >CMP.G SRC.AMID
beq .3
@ -516,7 +521,7 @@ SRC.ParseLine.OPAMCheck
bra .50
.6 cmp #'r
bne *
>DEBUG

View File

@ -2,35 +2,41 @@ NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
*---------------------------------------
* Global Symbol Record: (8+ bytes)
* 0 : Len (6)
* Global Symbol Record: (8 bytes)
* 0 : Len (8)
* 1 : Flags:
* b7=0=pending,1=resolved
* b6=R/W (.SE)
* b2,b1,b0 : Size (in bytes)
* 2-5 : 32 bits Value
*
* Local Symbol Record: (2 bytes)
* 2 : Local ID (1->255)
* 3 : offset from Global Symbol
* ......
* Ending 0
* 6-7 : LSID (Local Symbols ID)
*---------------------------------------
* Global Symbol Index (Sorted)
* 0 : hGblock
* 1 : Offset in block
* Local Symbol Record: (7 bytes)
* 0 : Len (8)
* 1 : Flags:
* b7=0=pending,1=resolved
* 2-5 : 32 bits Value (PC)
* 6 : Local ID (1->255)
*---------------------------------------
* Private Symbol Record: (7 bytes)
* 0,1 : MacroID
* 2 : Private ID (0->255)
* 3-6 : Value
*---------------------------------------
* Macro Record: ( bytes)
* Private Symbol Record: (9 bytes)
* 0 : Len (8)
* 1 : Flags:
* b7=0=pending,1=resolved
* 2-5 : 32 bits Value (PC)
* 6,7 : MCID (Macro Context ID)
* 8 : Private ID (0->255)
*---------------------------------------
SYM.Init >SYSCALL SListNew
bcs .9
>STA.G SYM.hGlobals
>SYSCALL SListNew
bcs .9
>STA.G SYM.hLocals
>LDYAI 256
>SYSCALL GetMem.YA
bcs .9
@ -41,15 +47,23 @@ SYM.Init >SYSCALL SListNew
.9 rts
*---------------------------------------
SYM.Reset >STZ.G SYM.bGlobal
>STA.G SYM.LocalIndex
rts
*---------------------------------------
SYM.Quit >LDA.G SYM.hLocalBuf
beq .2
>SYSCALL FreeMem.A
.2 >LDA.G SYM.hGlobals
beq .8
.2 >LDA.G SYM.hLocals
beq .3
>SYSCALL SListFree.A
.3 >LDA.G SYM.hGlobals
beq .8
>SYSCALL SListFree.A
.8 clc
rts
*---------------------------------------
@ -81,15 +95,15 @@ SYM.Dump stz ZPLinePtr
adc #0
sta ZPPtr1+1
ldy #SYM.F Get Symbol Size
ldy #SYMG.F Get Symbol Size
lda (ZPPtr1),y
and #SYM.F.SIZE
and #SYMG.F.SIZE
beq .3
pha
tax
iny SYM.V
iny SYMG.V
.2 lda (ZPPtr1),y
>PUSHA
@ -116,12 +130,12 @@ SYM.Dump stz ZPLinePtr
rts
*---------------------------------------
SYM.AddGlobalPC jsr SYM.PC2Global A=PC Size
ora #SYM.F.RESOLVED PC is always known
ora #SYMG.F.RESOLVED PC is always known
*---------------------------------------
SYM.AddGlobal >STA.G SYM.Global+SYM.F
SYM.AddGlobal >STA.G SYM.Global+SYMG.F
lda #5 F+DWORD
>STA.G SYM.Global+SYM.LEN
lda #SYMG.SIZE-1 F+V+LSID
>STA.G SYM.Global+SYMG.LEN
>PUSHB.G SYM.hGlobals
>PUSHW ZPLinePtr
@ -141,7 +155,7 @@ SYM.AddGlobal >STA.G SYM.Global+SYM.F
.HS B0 BCS
.9 sec
tya
>STA.G SYM.ID+1
>STA.G SYM.GlobalID+1
dey
txa
sta (pData),y
@ -161,9 +175,9 @@ SYM.LookupGlobal >PUSHB.G SYM.hGlobals
clc
.1 tya
>STA.G SYM.ID+1
>STA.G SYM.GlobalID+1
txa
>STA.G SYM.ID
>STA.G SYM.GlobalID
.9 rts
*---------------------------------------
@ -172,7 +186,7 @@ SYM.UpdateGlobalPC jsr SYM.PC2Global
*---------------------------------------
SYM.UpdateGlobalAcc ldx #3
ldy #SYM.Global+SYM.V+3
ldy #SYM.Global+SYMG.V+3
.1 lda SRC.ACC,x
sta (pData),y
@ -182,19 +196,22 @@ SYM.UpdateGlobalAcc ldx #3
lda SRC.ACC.SIZE
*---------------------------------------
SYM.UpdateGlobal ora #SYM.F.RESOLVED
>STA.G SYM.Global+SYM.F
SYM.UpdateGlobal ora #SYMG.F.RESOLVED
>STA.G SYM.Global+SYMG.F
lda #5 F+DWORD
>STA.G SYM.Global+SYM.LEN
lda #SYMG.SIZE-1 F+V+LSID
>STA.G SYM.Global+SYMG.LEN
>PUSHB.G SYM.hGlobals
>PUSHW.G SYM.ID
>PUSHW.G SYM.GlobalID
>PUSHEA.G SYM.Global
>SYSCALL SListUpdateByID
rts
*---------------------------------------
SYMG.FlushGlobal clc
rts
*---------------------------------------
SYM.PC2Global ldx #4
ldy #ASM.PC
@ -207,7 +224,7 @@ SYM.PC2Global ldx #4
ldx #4
ldy #SYM.Global+SYM.V+3
ldy #SYM.Global+SYMG.V+3
.2 pla
sta (pData),y
@ -240,7 +257,7 @@ SYM.AddLocalPC tax Save ID
sta (ZPLocalBuf),y
iny
lda #SYM.F.RESOLVED
lda #SYMG.F.RESOLVED
sta (ZPLocalBuf),y
iny
@ -309,7 +326,11 @@ SYM.AddLocalPending tax Save ID
* sec
rts
*---------------------------------------
SYM.GetLocal
SYM.LookupLocal lda #2
sta SRC.ACC.SIZE
lda #$FF
sta SRC.ACC
sta SRC.ACC+1
clc
rts
*---------------------------------------

View File

@ -19,15 +19,24 @@ ZPMacroBuf .EQ ZPBIN+12
ZPTmpBuf .EQ ZPBIN+14
ZPAMPtr .EQ ZPBIN+16
ZPRPtr .EQ ZPBIN+18
ZPOPtr .EQ ZPBIN+20
ZPOpsPtr .EQ ZPBIN+20
ZPOpDefPtr .EQ ZPBIN+22
*---------------------------------------
SYM.LEN .EQ 0
SYM.F .EQ 1
SYM.F.RESOLVED .EQ %10000000
SYM.F.RW .EQ %01000000
SYM.F.SIZE .EQ %00000111
SYM.V .EQ 2
SYMG.LEN .EQ 0
SYMG.F .EQ 1
SYMG.F.RESOLVED .EQ %10000000
SYMG.F.RW .EQ %01000000
SYMG.F.SIZE .EQ %00000111
SYMG.V .EQ 2
SYMG.LSID .EQ 6
SYMG.SIZE .EQ 8
*---------------------------------------
SYML.LEN .EQ 0
SYML.F .EQ 1
SYML.F.RESOLVED .EQ %10000000
SYML.V .EQ 2
SYML.ID .EQ 6
SYML.SIZE .EQ 7
*---------------------------------------
ASM.T.AM .EQ 0
ASM.T.R .EQ 2
@ -192,8 +201,6 @@ CS.INIT ldy #S.PS.ARGC
jsr MAC.Init
bcs .9
jsr DIR.Init
>LDYAI 256
>SYSCALL GetMem.YA
bcs .9
@ -256,6 +263,9 @@ CS.RUN >SYSCALL GetChar
jsr FIO.OpenFile
bcs .99
jsr DIR.Reset
jsr SYM.Reset
.10 jsr FIO.ReadLine
bcc .2
cmp #$4C End Of File?
@ -271,8 +281,6 @@ CS.RUN >SYSCALL GetChar
bne .1
inc
sta (pData),y
jsr DIR.Init Reset
>DEBUG
clc
rts
@ -469,13 +477,18 @@ ASM.PC.PH .BS 4
SYM.hGlobals .BS 1
SYM.bGlobal .BS 1
SYM.Global .BS 6
SYM.ID .BS 2
SYM.GlobalID .BS 2
SYM.Global .BS SYMG.SIZE
SYM.hLocals .BS 1
SYM.hLocalBuf .BS 1
SYM.LocalIndex .BS 1
SYM.LocalID .BS 2
SYM.Local .BS SYML.SIZE
SYM.Lookup .BS 6
SYM.Lookup .BS SYMG.SIZE
MAC.hMacros .BS 1
MAC.hBuf .BS 1