A2osX/SYS/KERNEL.S.BIN.txt

466 lines
10 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* BIN.LoadExeYA
2015-03-14 21:48:35 +00:00
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
BIN.LoadEXEYA >STYA BIN.LoadExe.Filename
2016-09-21 15:20:37 +00:00
jsr K.PStrUprYA
2016-08-17 06:25:58 +00:00
>LDYA BIN.LoadExe.Filename
2016-09-21 15:20:37 +00:00
jsr K.GetMemByNameYA
bcs .1 not already loaded
2015-06-03 18:30:57 +00:00
>STYA ZPQuickPtr1 Save base address
2015-03-14 21:48:35 +00:00
ldy #S.MEM.REFCNT
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
inc
2015-06-03 18:30:57 +00:00
sta (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
ldy #S.MEM.PTR
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
pha Y,A = MEM PTR...
iny
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y
2016-09-21 15:20:37 +00:00
ply X=hMem from K.GetMemByNameA
2015-03-14 21:48:35 +00:00
clc
rts
.1 >PUSHWI KrnBuf256
>PUSHW BIN.LoadExe.Filename
2016-09-26 16:00:52 +00:00
jsr K.STAT Look for AUXTYPE
bcs .99
>LDYA KrnBuf256+S.STAT.AUXTYPE
>STYA BIN.LoadExe.OldBase
2016-09-26 16:00:52 +00:00
>PUSHYA
2016-09-22 06:19:49 +00:00
>PUSHBI 6 S.FILEINFO.TYPE.BIN
>PUSHBI SYS.FOPEN.R
>PUSHW BIN.LoadExe.Filename
2016-09-22 06:19:49 +00:00
jsr K.LoadFile
bcs .99 Error Loading file
2015-06-03 18:30:57 +00:00
>STYA BIN.LoadExe.SegLen
stx BIN.LoadExe.hMem save hMem
2015-03-14 21:48:35 +00:00
txa
2016-09-21 15:20:37 +00:00
jsr K.GetMemPtrA
>STYA BIN.LoadExe.NewBase
2015-06-03 18:30:57 +00:00
jsr BIN.InstallEXE
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
bcs .98 relocation error, dicard Code segment
2015-06-03 18:30:57 +00:00
>LDYA BIN.LoadExe.Filename get back bin path
2016-09-21 15:20:37 +00:00
jsr K.NewPStrYA make a copy of this string
2015-03-14 21:48:35 +00:00
bcs .98
2016-08-17 06:25:58 +00:00
phx save copy
lda BIN.LoadExe.hMem
2016-09-21 15:20:37 +00:00
jsr K.GetMemByIDA
2015-03-14 21:48:35 +00:00
>STYA ZPQuickPtr1
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
lda (ZPQuickPtr1)
ora #S.MEM.F.CODE This is a code segment
sta (ZPQuickPtr1)
2016-03-13 21:47:19 +00:00
pla
2015-03-14 21:48:35 +00:00
ldy #S.MEM.BIN
sta (ZPQuickPtr1),y
2015-06-03 18:30:57 +00:00
lda BIN.LoadExe.hMem
2015-06-03 18:30:57 +00:00
tax return hMEM to Caller...
2016-09-21 15:20:37 +00:00
jsr K.GetMemPtrA
2015-06-03 18:30:57 +00:00
clc ...and Y,A=PTR to CS
2015-03-14 21:48:35 +00:00
rts
.98 pha
lda BIN.LoadExe.hMem
2016-09-21 15:20:37 +00:00
jsr K.FreeMemA 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.LoadExe.Filename .BS 2
BIN.LoadExe.hMem .BS 1
BIN.LoadExe.OldBase .BS 2
BIN.LoadExe.NewBase .BS 2
BIN.LoadExe.SegLen .BS 2
*--------------------------------------
* BIN.InstallEXE
*--------------------------------------
BIN.InstallEXE >LDYA BIN.LoadExe.NewBase
>STYA ZPQuickPtr1
ldy #H.BIN.CODE.LEN get Code Len
lda (ZPQuickPtr1),y
sta Rel.CodeLen
iny
lda (ZPQuickPtr1),y
sta Rel.CodeLen+1
lda BIN.LoadExe.OldBase
sta Rel.Start Get AUXTYPE for actual Base Address
clc
adc BIN.LoadExe.SegLen
sta Rel.End compute Range End=AUXTYPE+FILELEN
lda BIN.LoadExe.OldBase+1
sta Rel.Start+1
adc BIN.LoadExe.SegLen+1
sta Rel.End+1
lda ZPQuickPtr1
sec
sbc BIN.LoadExe.OldBase
sta Rel.Offset Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
sbc BIN.LoadExe.OldBase+1
sta Rel.Offset+1
jmp Bin.RelocateEXE
*--------------------------------------
* K.InsDrv
* pDrv = .DRV File Loaded Address
*--------------------------------------
BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN
lda (pDrv),y
sta Rel.CodeLen
iny
lda (pDrv),y
sta Rel.CodeLen+1
ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
adc BIN.LoadExe.OldBase
sta Rel.Start
iny
lda (pDrv),y
adc BIN.LoadExe.OldBase+1
sta Rel.Start+1
lda BIN.LoadExe.OldBase
clc
adc BIN.LoadExe.SegLen
sta Rel.End
lda BIN.LoadExe.OldBase+1
adc BIN.LoadExe.SegLen+1
sta Rel.End+1
ldy #H.BIN.DRV.CODE.O
lda BIN.LoadExe.SegLen
sec
sbc (pDrv),y
sta K.InsDrv.DRVLen
iny
lda BIN.LoadExe.SegLen+1
sbc (pDrv),y
sta K.InsDrv.DRVLen+1 Compute DRV Len
lda DevMgr.Free
clc
adc K.InsDrv.DRVLen
sta K.InsDrv.DRVEnd
lda DevMgr.Free+1
adc K.InsDrv.DRVLen+1
sta K.InsDrv.DRVEnd+1
bcs .98 we crossed $FFFF, out of mem
lda K.InsDrv.DRVEnd
sec
sbc #DevMgr.HiMem
lda K.InsDrv.DRVEnd+1
sbc /DevMgr.HiMem
bcs .98 No More Room to load Driver....
lda DevMgr.LastDevID
inc
cmp #K.DEV.MAX
beq .99 No Device Handle Left
sta DevMgr.LastDevID
ldy #H.BIN.DEV.HEADER.O
lda (pDrv),y
clc
adc pDrv
sta ZPQuickPtr1
iny
lda (pDrv),y
adc pDrv+1
sta ZPQuickPtr1+1
ldy #S.DEV.JMP
lda DevMgr.Free
sec
sbc (ZPQuickPtr1),y
sta Rel.Offset
lda DevMgr.Free+1
iny
sbc (ZPQuickPtr1),y
sta Rel.Offset+1
ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
adc pDrv
sta ZPQuickPtr1
iny
lda (pDrv),y
adc pDrv+1
sta ZPQuickPtr1+1
jsr BIN.RelocateDRV
jsr BIN.MoveDRV
>LDYA K.InsDrv.DrvEnd
>STYA DevMgr.Free
clc
rts
.98 lda #DEVMGR.ERROOM
sec
rts
.99 lda #DEVMGR.ERROOH
sec
rts
*--------------------------------------
BIN.MoveDRV ldy #H.BIN.DEV.HEADER.O
lda (pDrv),y
clc
adc pDrv
sta ZPQuickPtr1
iny
lda (pDrv),y
adc pDrv+1
sta ZPQuickPtr1+1
ldy #S.DEV.JMP Relocate Main JMP
lda (ZPQuickPtr1),y
clc
adc Rel.Offset
sta (ZPQuickPtr1),y
iny
lda (ZPQuickPtr1),y
adc Rel.Offset+1
sta (ZPQuickPtr1),y
lda DevMgr.LastDevID
jsr K.GetDevByIDA
>STYA pDev
ldy #S.DEV.SIZE Make sure DevMgr.Table Ends with 0
lda #0
sta (pDev),y
dey
.1 lda (ZPQuickPtr1),y Copy DRV.Header
sta (pDev),y
dey
bpl .1
lda DevMgr.LastDevID Save Dev.ID in the driver for SELECT
ldy #S.DEV.ID
sta (pDev),y
ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
adc pDrv
sta ZPQuickPtr1
iny
lda (pDrv),y
adc pDrv+1
sta ZPQuickPtr1+1 Make ZPQuickPtr1=DRV.CODE
lda DevMgr.Free
sta ZPQuickPtr2
lda DevMgr.Free+1
sta ZPQuickPtr2+1 Make ZPQuickPtr2=Dest Ram Location
ldy K.InsDrv.DrvLen
ldx K.InsDrv.DrvLen+1
.2 lda (ZPQuickPtr1)
sta (ZPQuickPtr2)
inc ZPQuickPtr1
bne .3
inc ZPQuickPtr1+1
.3 inc ZPQuickPtr2
bne .4
inc ZPQuickPtr2+1
.4 tya
bne .5
txa
beq .8
dex
.5 dey
bra .2
.8 rts
*--------------------------------------
K.InsDrv.DrvLen .BS 2
K.InsDrv.DrvEnd .BS 2
*--------------------------------------
* BIN.Relocate___ :
* ZPQuickPtr1 = Ptr to Code
*--------------------------------------
BIN.RelocateEXE ldy #H.BIN.JMP relocate Main JMP
lda (ZPQuickPtr1),y
clc
adc Rel.Offset
sta (ZPQuickPtr1),y
iny
lda (ZPQuickPtr1),y
adc Rel.Offset+1
sta (ZPQuickPtr1),y
ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
.HS 2C bit abs
BIN.RelocateDRV ldy #0
.1 lda (ZPQuickPtr1),y Start Relocate JMP table
tax
iny
ora (ZPQuickPtr1),y
beq .2 $0000 = end of table
dey
txa
clc
adc Rel.Offset
sta (ZPQuickPtr1),y
iny
lda (ZPQuickPtr1),y
adc Rel.Offset+1
sta (ZPQuickPtr1),y
iny
bra .1
.2 lda ZPQuickPtr1
clc
adc Rel.CodeLen Make ZPQuickPtr2=End of code
sta ZPQuickPtr2 =ZPQuickPtr1+AX (code len)
lda ZPQuickPtr1+1
adc Rel.CodeLen+1
sta ZPQuickPtr2+1
iny
tya add current offset in Y to Ptr
clc
adc ZPQuickPtr1
sta ZPQuickPtr1
bcc .5
inc ZPQuickPtr1+1 ZPQuickPtr1=Current Code PTR
clc
.5 lda (ZPQuickPtr1) get OPCODE
tax
lda BIN.OPCODES,x get OPCODE definition
bpl .7 abs addressing?
and #3 save Opcode length...
pha
ldy #1
lda (ZPQuickPtr1),y Get LO
sec
sbc Rel.Start
iny
lda (ZPQuickPtr1),y Get HI
sbc Rel.Start+1
bcc .6 addr < AX, out of range
dey
lda (ZPQuickPtr1),y Get LO
sec
sbc Rel.End
iny
lda (ZPQuickPtr1),y Get HI
sbc Rel.End+1
bcs .6 addr > CX, out of range
dey
lda (ZPQuickPtr1),y Get LO
clc
adc Rel.Offset add DX to abs address
sta (ZPQuickPtr1),y store relocated addr LO
iny
lda (ZPQuickPtr1),y Get HI
adc Rel.Offset+1
sta (ZPQuickPtr1),y store relocated addr HI
.6 pla
.7 clc A = OPCODE length
adc ZPQuickPtr1
sta ZPQuickPtr1
bcc .8
inc ZPQuickPtr1+1
.8 lda ZPQuickPtr1 is Current PTR < Code Limit ?
sec
sbc ZPQuickPtr2
lda ZPQuickPtr1+1
sbc ZPQuickPtr2+1
bcc .5 yes, continue relocating
clc
rts
*--------------------------------------
* 65C02 OPCODES
* Bit 7 : 1 absolute addressing
* Bit 1-0 : opcode + @ length
*--------------------------------------
* x0.x1.x2.x3.x4.x5.x6.x7.x8.x9.xA.xB.xC.xD.xE.xF
BIN.OPCODES .HS 01.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.83.83.83.03
.HS 83.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.83.83.83.03
.HS 01.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03
.HS 01.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03
.HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03
*--------------------------------------
Rel.CodeLen .BS 2
Rel.Start .BS 2
Rel.End .BS 2
Rel.Offset .BS 2
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.BIN
LOAD SYS/KERNEL.S
ASM