A2osX/SYS/KERNEL.S.BIN.txt

685 lines
14 KiB
Plaintext
Raw Normal View History

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
2015-03-14 21:48:35 +00:00
*--------------------------------------
* K.LoadLib.YA
* in :
* Y,A = PTR To "LibName.o" C-String
* out :
* A = hMem To loaded LIB
*--------------------------------------
K.LoadLib.YA jsr BIN.FindLIB.YA
bcs .9
jsr BIN.Load.YA Y,A = "/PATH/BIN"
bcs .9
stx .8+1
>STYA .1+1
txa Pass hLib to LibLoad
ldx #LIBMGR.LOAD
.1 jsr $ffff Self Modified, Call LIB.LOAD function
bcs .99
.8 lda #$ff hLib
clc
.9 rts
.99 pha
lda .8+1
jsr K.FreeMem.A
pla
sec
rts
*--------------------------------------
* K.UnloadLib.A
* in :
* A = hMem To Lib
* out :
*--------------------------------------
K.UnloadLib.A pha
jsr K.GetMemByID.A
>STYA ZPPtr1
ldy #S.MEM.REFCNT
lda (ZPPtr1),y Get count of those referencing this lib
dec only one left ?
beq .1
sta (ZPPtr1),y
pla
clc
rts
.1 ldy #S.MEM.PTR
lda (ZPPtr1),y
sta .2+1
iny
lda (ZPPtr1),y
sta .2+2
ldx #LIBMGR.UNLOAD
.2 jsr $ffff Self Modified, Call LIB.UNLOAD function
pla
jmp K.FreeMem.A
*--------------------------------------
* K.LoadDrv.YA
* in :
* Y,A = PTR to "NAME.DRV [PARAM]" C-String
* out :
* none
*--------------------------------------
K.LoadDrv.YA >STYA .2+1 Save "BIN\0ARGS\0\0"
jsr BIN.FindDRV.YA
bcs .9
jsr BIN.Load.YA Y,A = "/PATH/BIN"
bcs .9
>STYA pDrv
stx .97+1
ldx #$ff
.1 inx Skip "BIN"
.2 lda $ffff,x
bne .1
txa
sec
adc .2+1
tay
lda #0
adc .2+2
jsr .88 call Dev.Detect
bcs .96
2017-10-27 14:56:46 +00:00
jsr BIN.InsDrv
bcs .96
jsr .96 Cleanup...
lda #0 Make sure RC = 0 if success
clc
.9 rts
.96 pha
.97 lda #$ff
jsr K.FreeMem.A
pla
sec
rts
.88 jmp (pDrv)
*--------------------------------------
BIN.FindLIB.YA clc
.HS B0 bcs
BIN.FindDRV.YA sec
>STYA BIN.CmdLine
>LDYAI BIN.Find.ENV.LIB
bcc .1
>LDYAI BIN.Find.ENV.DRV
.1 jsr K.GetEnv.YA get value for Search Path
bcs .9
>PUSHYA
>PUSHW BIN.CmdLine
jsr K.FileSearch.I find LIB/DRV in Search
bcs .9
>LDYAI K.Buf256
clc
.9 rts
*/--------------------------------------
* # FileSearch
* Search a file in the provided PATH list
* And return, if found, the full path to it.
* ## In:
* PUSHW = Ptr to Search Path (CSTR) %LIB%;/SYS/SLIB
* PUSHW = Ptr to File Name (CSTR)
* PUSHW = Ptr to DstBuf
* PUSHW = Ptr to DstStat
* ## Out:
* CC : success
* DstBuf = FilePath
* DstStat = S.STAT
* CS : not found
*\--------------------------------------
K.FileSearch >PULLW .4+1 DstStat
>PULLW .2+1 DstBuf
jsr K.FileSearch.I
bcs .9
ldx #$ff
.1 inx
lda K.Buf256,x
.2 sta $ffff,x Self Modified
bne .1
ldx #S.STAT-1
.3 lda K.S.STAT,x
.4 sta $ffff,x Self Modified
dex
bpl .3
.9 rts
K.FileSearch.I >PULLW .4+1 Filename
>PULLYA Get Search list
jsr K.ExpandStr.YA Expand it
bcs .99
stx .98+1
>STYA .2+1 expanded search list ;
stz .1+1
.1 ldy #$0 Self Modified Index in Search list string
ldx #$0
.2 lda $ffff,y Self Modified, Search list string
beq .3 end of string, try it....
iny
cmp #';'
beq .3
sta K.Buf256,x
inx
bra .2
.3 txa
beq .98 String is empty....nothing to try
sty .1+1 save current index
ldy #$0
.4 lda $ffff,y Self Modified, Append Filename...
sta K.Buf256,x
beq .5
iny
inx
bra .4
.5 >PUSHWI K.S.STAT
>PUSHWI K.Buf256
>SYSCALL STAT -> BNK1
bcs .1 Failed...retry next path...
2017-12-14 16:25:03 +00:00
lda K.S.STAT+S.STAT.P.TYPE
cmp #S.FI.T.DIR Dir ?
beq .1
jsr .98 Discard Expanded hSrch list
clc
2017-12-14 16:25:03 +00:00
.99 rts
.98 lda #$ff SELF MODIFIED : Discard Expanded hSrch list
jsr K.FreeMem.A
lda #MLI.E.FNOTFND
sec
2017-12-14 16:25:03 +00:00
rts
*--------------------------------------
BIN.Find.ENV.DRV >CSTR "DRV"
BIN.Find.ENV.LIB >CSTR "LIB"
*--------------------------------------
* BIN.Load.YA
2015-03-14 21:48:35 +00:00
* in :
* Y,A = /BIN/PATH (CSTR)
2015-03-14 21:48:35 +00:00
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
BIN.Load.YA >STYA BIN.CmdLine
>STYA .2+1
ldx Mem.LastSlot
beq BIN.Load.YA.1
>LDYAI Mem.Table
>STYA ZPPtr1
ldx #0
.1 lda (ZPPtr1)
bpl .6 In Use?
ldy #S.MEM.BIN any BIN PATH in this slot?
lda (ZPPtr1),y
beq .6
jsr K.GetMemPtr.A get pathname
>STYA .3+1
ldy #0
.2 lda $ffff,y SELF MODIFIED
.3 cmp $ffff,y SELF MODIFIED
bne .6
iny
ora #0
bne .2
2015-03-14 21:48:35 +00:00
ldy #S.MEM.REFCNT
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
2015-03-14 21:48:35 +00:00
inc
sta (ZPPtr1),y
txa
jmp K.GetMemPtr.A X=hMem from K.GetMemByNameA
.6 lda ZPPtr1
clc
adc #S.MEM
sta ZPPtr1
bcc .7
inc ZPPtr1+1
.7 inx
cpx Mem.LastSlot
bne .1
*--------------------------------------
BIN.Load.YA.1 >PUSHWI K.S.STAT
>PUSHW BIN.CmdLine
>SYSCALL STAT BANK1!!! Look for AUXTYPE
bcs .9
2016-09-26 16:00:52 +00:00
>LDYA K.S.STAT+S.STAT.P.AUXTYPE
2017-10-27 14:56:46 +00:00
>STYA BIN.R.Start
2016-09-26 16:00:52 +00:00
>PUSHYA Push AUXTYPE
2017-10-27 14:56:46 +00:00
>PUSHBI 6 S.FI.T.BIN
2017-01-12 17:43:45 +00:00
>PUSHBI SYS.FOpen.R
>PUSHW BIN.CmdLine
>SYSCALL LoadFile BANK1!!!
.9 bcs .99 Error Loading file
stx BIN.hMem save hMem
pha YA=CODE+DATA size
tya
* clc CC from bcs .99
2017-10-27 14:56:46 +00:00
adc BIN.R.Start Get AUXTYPE for actual Base Address
sta BIN.R.End compute Range End=AUXTYPE+FILELEN
pla
2017-10-27 14:56:46 +00:00
adc BIN.R.Start+1
sta BIN.R.End+1
txa
jsr K.GetMemPtr.A
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1 set ZPPtr1 -> Code start
pha YA = actual load address
tya
sec
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start
sta BIN.R.Offset Offset=ZPPtr1-AUXTYPE
pla
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start+1
sta BIN.R.Offset+1
ldy #H.BIN.CODE.LEN get Code Len
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
clc
2017-01-12 17:43:45 +00:00
adc ZPPtr1
sta ZPPtr2 Make ZPPtr2 = ZPPtr1 + CodeLen
iny
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPPtr2+1
2017-10-27 14:56:46 +00:00
jsr BIN.RelExe
2015-06-03 18:30:57 +00:00
>LDYA BIN.CmdLine get back bin path
jsr K.NewStr.YA make a copy of this string
2015-03-14 21:48:35 +00:00
bcs .98
lda BIN.hMem Keep X=hMem
jsr K.GetMemByID.A X unmodified
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1
2015-06-03 18:30:57 +00:00
2017-01-12 17:43:45 +00:00
lda (ZPPtr1)
2015-03-14 21:48:35 +00:00
ora #S.MEM.F.CODE This is a code segment
2017-01-12 17:43:45 +00:00
sta (ZPPtr1)
2016-03-13 21:47:19 +00:00
txa Get Back hMem
2015-03-14 21:48:35 +00:00
ldy #S.MEM.BIN
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
2015-06-03 18:30:57 +00:00
lda BIN.hMem
2015-06-03 18:30:57 +00:00
tax return hMEM to Caller...
jmp K.GetMemPtr.A ...and Y,A=PTR to CS
2015-03-14 21:48:35 +00:00
.98 pha
lda BIN.hMem
jsr K.FreeMem.A Discard Loaded Code
2015-03-14 21:48:35 +00:00
pla
2015-06-03 18:30:57 +00:00
sec
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
BIN.CmdLine .BS 2
BIN.hMem .BS 1
*--------------------------------------
2017-10-27 14:56:46 +00:00
* BIN.InsDrv
* In:
* pDrv = .DRV File Loaded Address
* Note:
* BIN.Load.YA called from K.LoadDrvYA
* Already setup correctly pDrv,
2017-10-27 14:56:46 +00:00
* BIN.R.Start,End
*--------------------------------------
2017-10-27 14:56:46 +00:00
BIN.InsDrv ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
2017-10-27 14:56:46 +00:00
adc BIN.R.Start Advance start From AUXTYPE to AUXTYPE+DRV code offset
sta BIN.R.Start
iny
lda (pDrv),y
2017-10-27 14:56:46 +00:00
adc BIN.R.Start+1
sta BIN.R.Start+1
lda DevMgr.Free Offset = Target DRV address-(AUXTYPE+DRV OFFSET)
sec
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start
sta BIN.R.Offset
lda DevMgr.Free+1
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start+1
sta BIN.R.Offset+1
2017-10-27 14:56:46 +00:00
lda BIN.R.End Compute DRVLen=End-start
sec
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start
sta BIN.InsDrv.Len
2017-10-27 14:56:46 +00:00
lda BIN.R.End+1
sbc BIN.R.Start+1
sta BIN.InsDrv.Len+1
lda DevMgr.Free
clc
2017-10-27 14:56:46 +00:00
adc BIN.InsDrv.Len
sta BIN.InsDrv.End
tay Save DRVEnd LO
lda DevMgr.Free+1
2017-10-27 14:56:46 +00:00
adc BIN.InsDrv.Len+1 A = DRVEnd HI
sta BIN.InsDrv.End+1
bcs .9 we crossed $FFFF, out of mem
cpy #DevMgr.HiMem
sbc /DevMgr.HiMem
bcs .9 No More Room to load Driver....
2017-01-12 17:43:45 +00:00
lda DevMgr.Count
cmp #K.DEV.MAX
bne .10 No Device Handle Left
lda #K.E.OOH
sec
rts
.9 lda #K.E.OOM
sec
rts
2017-01-12 17:43:45 +00:00
.10 inc DevMgr.Count
>SYSCALL GetDevByID.A
2017-01-12 17:43:45 +00:00
>STYA ZPPtr2 setup Ptr2 to dest HEADER
ldy #H.BIN.DRV.HEADER.O
lda (pDrv),y
clc
adc pDrv
2017-01-12 17:43:45 +00:00
sta ZPPtr1
iny
lda (pDrv),y
adc pDrv+1
2017-01-12 17:43:45 +00:00
sta ZPPtr1+1 set Ptr1 to Src HEADER
ldy #S.DEV-1
.1 lda (ZPPtr1),y copy header to Dev.Table
2017-01-12 17:43:45 +00:00
sta (ZPPtr2),y
dey
bpl .1
ldy #S.DEV.DRV.JMP+1 Setup Main JMP
lda DevMgr.Free+1
2017-01-12 17:43:45 +00:00
sta (ZPPtr2),y
tax
dey
lda DevMgr.Free
2017-01-12 17:43:45 +00:00
sta (ZPPtr2),y
2017-01-12 17:43:45 +00:00
sta ZPPtr2 set Ptr2 to Dest CODE
stx ZPPtr2+1
ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
adc pDrv
2017-01-12 17:43:45 +00:00
sta ZPPtr1
iny
lda (pDrv),y
adc pDrv+1
2017-01-12 17:43:45 +00:00
sta ZPPtr1+1 set Ptr1 to Src CODE
2017-10-27 14:56:46 +00:00
lda BIN.InsDrv.Len+1
eor #$ff
pha
2017-10-27 14:56:46 +00:00
lda BIN.InsDrv.Len
eor #$ff
tax
ldy #0
.2 inx Move CODE in LC
bne .3
pla
inc
beq .4
pha
2017-01-12 17:43:45 +00:00
.3 lda (ZPPtr1),y
sta (ZPPtr2),y
iny
bne .2
2017-01-12 17:43:45 +00:00
inc ZPPtr1+1
inc ZPPtr2+1
bra .2
.4 ldy #H.BIN.DRV.CODE.LEN
lda DevMgr.Free Make Ptr1 = code start
2017-01-12 17:43:45 +00:00
sta ZPPtr1
clc
adc (pDrv),y
2017-01-12 17:43:45 +00:00
sta ZPPtr2
iny
lda DevMgr.Free+1
2017-01-12 17:43:45 +00:00
sta ZPPtr1+1
adc (pDrv),y
2017-01-12 17:43:45 +00:00
sta ZPPtr2+1 Make ZPPtr2 = ZPPtr1 + CodeLen
2017-10-27 14:56:46 +00:00
jsr BIN.RelDrv
2017-10-27 14:56:46 +00:00
>LDYA BIN.InsDrv.End
>STYA DevMgr.Free
2017-01-12 17:43:45 +00:00
clc
rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
BIN.InsDrv.Len .BS 2
BIN.InsDrv.End .BS 2
*--------------------------------------
2017-10-27 14:56:46 +00:00
* BIN.Rel___ :
* In :
2017-01-12 17:43:45 +00:00
* ZPPtr1 = Ptr to Code
* ZPPtr2 = End Of Code
*--------------------------------------
2017-10-27 14:56:46 +00:00
BIN.R.Start .BS 2
BIN.R.End .BS 2
BIN.R.Offset .BS 2
*--------------------------------------
2017-10-27 14:56:46 +00:00
BIN.RelExe ldy #H.BIN.T+1
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
cmp /H.BIN.T.BIN65
beq .1
cmp /H.BIN.T.DRV65
beq .1
lda #K.E.IBIN
sec
rts
.1 ldy #H.BIN.JMP relocate Main JMP
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
clc
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
iny
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset+1
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
ldy #H.BIN.EXE.REL.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
.HS 2C bit abs
*--------------------------------------
2017-10-27 14:56:46 +00:00
BIN.RelDrv ldy #H.BIN.DRV.REL.TABLE
2017-01-12 17:43:45 +00:00
.1 lda (ZPPtr1),y Start Relocate JMP table
tax LO in X
iny
2017-01-12 17:43:45 +00:00
ora (ZPPtr1),y ORA with HI
beq .2 $0000 = end of table
dey
txa get back LO
clc
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
iny
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset+1
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
iny
bra .1
*--------------------------------------
.2 tya add current offset in Y to Ptr
sec + 1 to skip last 00 from beq .2
2017-01-12 17:43:45 +00:00
adc ZPPtr1
sta ZPPtr1
bcc .3
inc ZPPtr1+1 ZPPtr1=Current Code PTR
.3 lda (ZPPtr1) get OPCODE
lsr /2
tax
lda BIN.OPCODES,x get OPCODE definition
bcs .4 go get LO nibble
lsr
lsr move HI -> LO
lsr
lsr
.4 and #$0f
bit #$8 abs addressing?
beq .6 no....
and #7 save Opcode length...
pha
ldy #1
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y Get LO
tax save LO in X
iny make Y point to HI
2017-10-27 14:56:46 +00:00
cpx BIN.R.Start
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y Get HI
2017-10-27 14:56:46 +00:00
sbc BIN.R.Start+1
bcc .5 addr < BIN.R.Start, out of range
txa Get back LO
2017-10-27 14:56:46 +00:00
cpx BIN.R.End
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y Get HI
2017-10-27 14:56:46 +00:00
sbc BIN.R.End+1
bcs .5 addr > BIN.R.End, out of range
txa Get back LO
* clc CC from bcs .6
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset add Offset to abs address
dey
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y store relocated addr LO
iny
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y Get HI
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset+1
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y store relocated addr HI
.5 pla get back Opcode length...
.6 clc A = OPCODE length
2017-01-12 17:43:45 +00:00
adc ZPPtr1
sta ZPPtr1
bcc .7
2017-01-12 17:43:45 +00:00
inc ZPPtr1+1
2017-01-12 17:43:45 +00:00
.7 eor ZPPtr2 A = ZPPtr1
bne .3
2017-01-12 17:43:45 +00:00
lda ZPPtr1+1
eor ZPPtr2+1
bne .3 next opcode....
.8 rts
*--------------------------------------
* 65C02 OPCODES
* Bit 3 : 1 = absolute addressing
* Bit 2-1-0 : opcode + @ length
*--------------------------------------
* 0.1.2.3.4.5.6.7.8.9.A.B.C.D.E.F
BIN.OPCODES .HS 1.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.B.B.B.3
.HS B.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.B.B.B.3
.HS 1.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.1.B.B.3
.HS 1.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.1.B.B.3
.HS 2.2.2.1.2.2.2.2.1.2.1.1.B.B.B.3
.HS 2.2.2.1.2.2.2.2.1.B.1.1.1.B.B.3
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.BIN
LOAD /A2OSX.SRC/SYS/KERNEL.S
2015-03-14 21:48:35 +00:00
ASM