A2osX/SYS/KERNEL.S.BIN.txt

462 lines
9.6 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
AUTO 4,1
2019-01-04 13:17:31 +00:00
*--------------------------------------
.DUMMY
.OR FAC 15 Bytes
BIN.CmdLine .BS 2
BIN.hMem .BS 1
BIN.Move.Len .BS 2
BIN.R.CS.Start .BS 2
BIN.R.CS.End .BS 2
BIN.R.End .BS 2
BIN.R.Offset .BS 2
.ED
2015-03-14 21:48:35 +00:00
*--------------------------------------
2018-07-20 05:43:11 +00:00
* LoadLib
* in :
* Y,A = PTR To "LibName.o" C-String
* out :
* A = hMem To loaded LIB
*--------------------------------------
2019-01-21 06:52:04 +00:00
K.LoadLib jsr ENV.Search.LIB
bcs .9
2019-01-18 16:06:44 +00:00
>LDYAI K.Buf256
2019-02-03 21:58:26 +00:00
2018-06-22 06:24:35 +00:00
jsr BIN.Load Y,A = "/PATH/BIN"
bcs .9
>STYA .1+1
2019-02-03 21:58:26 +00:00
stx .8+1
txa Pass hLib to LibLoad
ldx #LIBMGR.LOAD
2019-02-03 21:58:26 +00:00
.1 jsr $ffff SELF MODIFIED, Call LIB.LOAD function
2019-02-03 21:58:26 +00:00
ldx .8+1
2019-01-26 14:01:05 +00:00
bcs BIN.Load.Cleanup
2019-02-03 21:58:26 +00:00
.8 lda #$ff SELF MODIFIED, hLib
* clc
.9 rts
*--------------------------------------
2018-07-20 05:43:11 +00:00
* UnloadLib
* in :
* A = hMem To Lib
* out :
*--------------------------------------
2018-06-18 06:22:50 +00:00
K.UnloadLib pha
2018-12-20 16:23:43 +00:00
jsr K.GetMemPtr
>STYA .2+1
2019-02-03 21:58:26 +00:00
ldy #S.MEM.REFCNT
lda (ZPMemMgrSPtr),y
dec
2019-02-05 13:45:15 +00:00
bne .8
2018-12-20 16:23:43 +00:00
.1 ldx #LIBMGR.UNLOAD
.2 jsr $ffff Self Modified, Call LIB.UNLOAD function
pla
2018-06-22 06:24:35 +00:00
jmp K.FreeMem
2019-02-05 13:45:15 +00:00
.8 sta (ZPMemMgrSPtr),y
pla
* clc
rts
2018-06-21 15:12:10 +00:00
*/--------------------------------------
* # LoadDrv
2018-07-20 05:43:11 +00:00
* ## ASM
2018-06-21 15:12:10 +00:00
* **In:**
* Y,A = PTR to "NAME.DRV [PARAM]" C-String
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-06-21 15:12:10 +00:00
* none
*\--------------------------------------
2018-06-18 06:22:50 +00:00
K.LoadDrv >STYA .2+1 Save "BIN\0ARGS\0\0"
2019-01-21 06:52:04 +00:00
jsr ENV.Search.DRV
bcs .9
2019-01-18 16:06:44 +00:00
>LDYAI K.Buf256
2018-06-22 06:24:35 +00:00
jsr BIN.Load Y,A = "/PATH/BIN"
bcs .9
2018-07-05 15:39:36 +00:00
>STYA .3+1
2019-02-03 21:58:26 +00:00
stx .8+1
ldx #$ff
.1 inx Skip "BIN"
.2 lda $ffff,x
bne .1
txa
sec
adc .2+1
tay
lda #0
2018-06-28 15:26:34 +00:00
adc .2+2 Y,A = ARGS
2018-07-05 15:39:36 +00:00
.3 jsr $ffff SELF MODIFIED, call Dev.Detect
2019-02-03 21:58:26 +00:00
.8 ldx #$ff SELF MODIFIED, hMem
2019-01-26 14:01:05 +00:00
jsr BIN.Load.Cleanup
2019-02-03 21:58:26 +00:00
bcs .9
lda #0 Make sure RC = 0 if success
clc
.9 rts
2019-01-26 14:01:05 +00:00
BIN.Load.Cleanup
2019-02-03 21:58:26 +00:00
php
2019-01-26 14:01:05 +00:00
pha
2019-02-03 21:58:26 +00:00
txa
2018-06-22 06:24:35 +00:00
jsr K.FreeMem
pla
2019-02-03 21:58:26 +00:00
plp
2019-01-26 14:01:05 +00:00
BIN.Load.Cleanup.RTS
rts
*--------------------------------------
2018-06-28 15:26:34 +00:00
* BIN.Load
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
*--------------------------------------
2018-06-22 06:24:35 +00:00
BIN.Load >STYA BIN.CmdLine
2018-12-20 16:23:43 +00:00
ldx #0
2018-08-20 15:15:37 +00:00
.1 cpx Mem.LastSlot
beq BIN.Load.1
2018-12-20 16:23:43 +00:00
inx we will skip Slot 0...
2018-08-20 15:15:37 +00:00
2018-12-20 16:23:43 +00:00
txa
2019-02-01 20:01:54 +00:00
jsr MEM.GetMemByID
2018-12-20 16:23:43 +00:00
lda (ZPMemMgrSPtr)
2018-08-20 15:15:37 +00:00
bpl .1 In Use?
ldy #S.MEM.BIN any BIN PATH in this slot?
2018-12-20 16:23:43 +00:00
lda (ZPMemMgrSPtr),y
2018-08-20 15:15:37 +00:00
beq .1
2018-08-20 15:15:37 +00:00
jsr K.GetMemPtr X unmodified, get pathname
>STYA .3+1
ldy #0
2019-01-04 13:17:31 +00:00
.2 lda (BIN.CmdLine),y
.3 cmp $ffff,y SELF MODIFIED
2018-08-20 15:15:37 +00:00
bne .1
iny
ora #0
bne .2
2018-12-20 16:23:43 +00:00
txa
2019-02-03 21:58:26 +00:00
jsr MEM.GetMemByID
2018-12-20 16:23:43 +00:00
2019-02-03 21:58:26 +00:00
ldy #S.MEM.REFCNT
lda (ZPMemMgrSPtr),y
inc
sta (ZPMemMgrSPtr),y
2018-08-20 15:15:37 +00:00
clc
2019-02-03 21:58:26 +00:00
jmp MEM.GetMEMPTR
2018-12-20 16:23:43 +00:00
* X=hMem, Y,A=Ptr
*--------------------------------------
2019-01-26 14:01:05 +00:00
* STAT Already called by Filesearch in FindDRV, FindLIB
* STAT Already called by PS.Load (TXT,BIN,SYS)
*--------------------------------------
BIN.Load.1 >LDYA K.S.STAT+S.STAT.P.AUXTYPE
2018-06-29 14:16:40 +00:00
>STYA BIN.R.CS.Start
2016-09-26 16:00:52 +00:00
>PUSHYA Push AUXTYPE
2018-06-29 14:16:40 +00:00
>PUSHBI S.FI.T.BIN
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY
2018-07-25 15:26:14 +00:00
>LDYA BIN.CmdLine
>SYSCALL LoadFile BANK1!!!
2019-01-26 14:01:05 +00:00
bcs BIN.Load.Cleanup.RTS Error Loading file
stx BIN.hMem save hMem
pha YA=CODE+DATA size
tya
* clc CC from bcs .99
2018-07-13 14:38:24 +00:00
adc BIN.R.CS.Start Get AUXTYPE for actual Base Address
2017-10-27 14:56:46 +00:00
sta BIN.R.End compute Range End=AUXTYPE+FILELEN
pla
2018-06-29 14:16:40 +00:00
adc BIN.R.CS.Start+1
2017-10-27 14:56:46 +00:00
sta BIN.R.End+1
txa
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
>STYA ZPPtr1 set ZPPtr1 -> Code start
2018-06-21 15:12:10 +00:00
pha YA = actual load address
tya
sec
2018-06-29 14:16:40 +00:00
sbc BIN.R.CS.Start
2018-06-21 15:12:10 +00:00
sta BIN.R.Offset Offset=ZPPtr1-AUXTYPE
pla
2018-06-29 14:16:40 +00:00
sbc BIN.R.CS.Start+1
2017-10-27 14:56:46 +00:00
sta BIN.R.Offset+1
2018-09-11 13:32:56 +00:00
ldy #H.BIN.CS.SIZE get Code Len
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
clc
2018-07-19 15:33:55 +00:00
adc BIN.R.CS.Start
2018-07-13 14:38:24 +00:00
sta BIN.R.CS.End ZPPtr1 + CodeLen
iny
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
2018-07-19 15:33:55 +00:00
adc BIN.R.CS.Start+1
2018-07-13 14:38:24 +00:00
sta BIN.R.CS.End+1
2017-10-27 14:56:46 +00:00
jsr BIN.RelExe
2015-06-03 18:30:57 +00:00
2018-06-21 15:12:10 +00:00
>LDYA BIN.CmdLine get back bin path
2018-12-20 16:23:43 +00:00
>SYSCALL StrDup make a copy of this string
2015-03-14 21:48:35 +00:00
bcs .98
2019-02-03 21:58:26 +00:00
lda BIN.hMem Keep X=new string hMem
2019-01-30 06:20:13 +00:00
jsr MEM.GetMemByID X unmodified
2015-06-03 18:30:57 +00:00
2018-12-20 16:23:43 +00:00
lda (ZPMemMgrSPtr)
2015-03-14 21:48:35 +00:00
ora #S.MEM.F.CODE This is a code segment
2018-12-20 16:23:43 +00:00
sta (ZPMemMgrSPtr)
2016-03-13 21:47:19 +00:00
2018-12-20 16:23:43 +00:00
txa Get Back Cmd line hMem
2015-03-14 21:48:35 +00:00
ldy #S.MEM.BIN
2018-12-20 16:23:43 +00:00
sta (ZPMemMgrSPtr),y
2015-06-03 18:30:57 +00:00
2018-12-20 16:23:43 +00:00
ldx BIN.hMem return hMEM to Caller...
clc
2019-02-03 21:58:26 +00:00
jmp MEM.GetMEMPTR ...and Y,A=PTR to CS
2015-03-14 21:48:35 +00:00
2019-02-03 21:58:26 +00:00
.98 ldx BIN.hMem
jmp BIN.Load.Cleanup Discard Loaded Code, exits CS
2018-06-28 15:26:34 +00:00
*/--------------------------------------
2018-07-20 05:43:11 +00:00
* # InsDrv
* ## C
2018-07-17 15:45:59 +00:00
* `void * insdrv (void * src, void * crvcsstart, void * drvcsend, void * drvend);`
2018-07-20 05:43:11 +00:00
* ## ASM
2018-06-28 15:26:34 +00:00
* **In:**
2018-07-19 15:33:55 +00:00
* `>PUSHW DRV.END`
* `>PUSHW DRV.CS.END`
* `>PUSHW DRV.CS.START`
* `>LDYA L.SRC`
* `SYSCALL insdrv`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-07-17 15:45:59 +00:00
* Y,A = Ptr to installed driver
2018-06-28 15:26:34 +00:00
*\--------------------------------------
2019-01-11 16:06:05 +00:00
K.InsDrv >STYA ZPPtr2 SRC PTR
2018-07-17 15:45:59 +00:00
>PULLW BIN.R.CS.Start
2018-06-29 14:16:40 +00:00
>PULLW BIN.R.CS.End
>PULLW BIN.R.End
2018-07-17 15:45:59 +00:00
2017-10-27 14:56:46 +00:00
lda BIN.R.End Compute DRVLen=End-start
sec
2018-06-29 14:16:40 +00:00
sbc BIN.R.CS.Start
2018-07-17 15:45:59 +00:00
sta BIN.Move.Len
2019-01-11 16:06:05 +00:00
tay
2017-10-27 14:56:46 +00:00
lda BIN.R.End+1
2018-06-29 14:16:40 +00:00
sbc BIN.R.CS.Start+1
2018-07-17 15:45:59 +00:00
sta BIN.Move.Len+1
2019-01-11 16:06:05 +00:00
jsr MEM.GetKrnlBuf Y,A = LEN
bcs .9 No More Room to load Driver
>STYA ZPPtr1 Y,A = DST Buf for RelDrv...
>STYA ZPPtr3 ...for move...
sty .7+1 ...and for exit
sta .8+1
2019-01-11 16:06:05 +00:00
lda ZPPtr1
2018-06-29 14:16:40 +00:00
sec
sbc BIN.R.CS.Start
sta BIN.R.Offset
2019-01-11 16:06:05 +00:00
lda ZPPtr1+1
2018-06-29 14:16:40 +00:00
sbc BIN.R.CS.Start+1
sta BIN.R.Offset+1
2018-07-17 15:45:59 +00:00
lda BIN.Move.Len+1
eor #$ff
pha
2018-07-17 15:45:59 +00:00
lda BIN.Move.Len
eor #$ff
tax
ldy #0
2018-06-29 14:16:40 +00:00
.1 inx
bne .2
2019-01-11 16:06:05 +00:00
pla
inc
2018-06-29 14:16:40 +00:00
beq .3
2019-01-11 16:06:05 +00:00
pha
2019-01-11 16:06:05 +00:00
.2 lda (ZPPtr2),y
sta (ZPPtr3),y
iny
2018-06-29 14:16:40 +00:00
bne .1
2017-01-12 17:43:45 +00:00
inc ZPPtr2+1
2019-01-11 16:06:05 +00:00
inc ZPPtr3+1
2018-06-29 14:16:40 +00:00
bra .1
2019-01-11 16:06:05 +00:00
.3 jsr BIN.RelDrv Relocate at Ptr1
.7 ldy #$ff SELF MODIFIED
.8 lda #$ff SELF MODIFIED
.9 rts
*--------------------------------------
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
2018-10-21 20:54:07 +00:00
lda #E.IBIN
sec
rts
.1 ldy #H.BIN.JMP relocate Main JMP
2019-01-11 16:06:05 +00:00
jsr BIN.RelocateAtPtr1Y
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
2018-07-17 15:45:59 +00:00
2019-01-11 16:06:05 +00:00
.1 iny
2018-09-09 08:11:42 +00:00
lda (ZPPtr1),y HI in A
beq .2 $00xx = end of table
dey
2019-01-11 16:06:05 +00:00
jsr BIN.RelocateAtPtr1Y
iny
bra .1
*--------------------------------------
2018-12-20 16:23:43 +00:00
.2 jsr MEM.AddYp1ToPtr1 add current offset in Y to Ptr
* + 1 to skip last 00 from beq .2
* ZPPtr1=Current Code PTR
2018-07-20 05:43:11 +00:00
.3 lda BIN.R.CS.End compute new CS.END to stop relocating
2018-07-19 15:33:55 +00:00
clc
adc BIN.R.Offset
sta .7+1
lda BIN.R.CS.End+1
adc BIN.R.Offset+1
2019-01-11 16:06:05 +00:00
sta .8+1
2018-07-19 15:33:55 +00:00
2018-07-20 05:43:11 +00:00
lda (ZPPtr1) get OPCODE
lsr /2
tax
2018-06-29 14:16:40 +00:00
lda BIN.65816,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
2019-01-11 16:06:05 +00:00
jsr BIN.RelocateAtPtr1Y
.5 pla get back Opcode length...
.6 clc A = OPCODE length
adc ZPPtr1
sta ZPPtr1
bcc .7
inc ZPPtr1+1
clc Make sure exit with CC
.7 eor #$ff SELF MODIFIED A = ZPPtr1
bne .3
lda ZPPtr1+1
.8 eor #$ff SELF MODIFIED
bne .3 next opcode....
rts
*--------------------------------------
BIN.RelocateAtPtr1Y
2018-07-17 15:45:59 +00:00
lda (ZPPtr1),y Get LO
tax save LO in X
iny make Y point to HI
2018-07-17 15:45:59 +00:00
lda (ZPPtr1),y Get HI
2019-01-11 16:06:05 +00:00
2018-06-29 14:16:40 +00:00
cpx BIN.R.CS.Start
sbc BIN.R.CS.Start+1
2019-01-11 16:06:05 +00:00
bcc .9 addr < BIN.R.CS.Start, out of range
txa Get back LO
2017-10-27 14:56:46 +00:00
cpx BIN.R.End
2018-07-17 15:45:59 +00:00
lda (ZPPtr1),y Get HI
2017-10-27 14:56:46 +00:00
sbc BIN.R.End+1
2019-01-11 16:06:05 +00:00
bcs .9 addr > BIN.R.End, out of range
txa Get back LO
dey
2019-01-11 16:06:05 +00:00
clc
adc BIN.R.Offset
sta (ZPPtr1),y
iny
2019-01-11 16:06:05 +00:00
lda (ZPPtr1),y
2017-10-27 14:56:46 +00:00
adc BIN.R.Offset+1
2019-01-11 16:06:05 +00:00
sta (ZPPtr1),y
2019-01-11 16:06:05 +00:00
.9 rts
*--------------------------------------
2019-01-04 13:17:31 +00:00
* 6502/65C02/65816 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.65816
* TO DO : Make 2 different tables
* http://axis.llx.com/~nparker/a2/opcodes.html
*--------------------------------------
* 65R02 OPCODES
*--------------------------------------
* 0.1.2.3.4.5.6.7.8.9.A.B.C.D.E.F
BIN.65R02 .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
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.BIN
LOAD USR/SRC/SYS/KERNEL.S
2015-03-14 21:48:35 +00:00
ASM