A2osX/SYS/KERNEL.S.BIN.txt

466 lines
10 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* BIN.LoadExeYA
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
BIN.LoadEXEYA >STYA BIN.LoadExe.Filename
jsr K.PStrUprYA
>LDYA BIN.LoadExe.Filename
jsr K.GetMemByNameYA
bcs .1 not already loaded
>STYA ZPQuickPtr1 Save base address
ldy #S.MEM.REFCNT
lda (ZPQuickPtr1),y
inc
sta (ZPQuickPtr1),y
ldy #S.MEM.PTR
lda (ZPQuickPtr1),y
pha Y,A = MEM PTR...
iny
lda (ZPQuickPtr1),y
ply X=hMem from K.GetMemByNameA
clc
rts
.1 >PUSHWI KrnBuf256
>PUSHW BIN.LoadExe.Filename
jsr K.STAT Look for AUXTYPE
bcs .99
>LDYA KrnBuf256+S.STAT.AUXTYPE
>STYA BIN.LoadExe.OldBase
>PUSHYA
>PUSHBI 6 S.FILEINFO.TYPE.BIN
>PUSHBI SYS.FOPEN.R
>PUSHW BIN.LoadExe.Filename
jsr K.LoadFile
bcs .99 Error Loading file
>STYA BIN.LoadExe.SegLen
stx BIN.LoadExe.hMem save hMem
txa
jsr K.GetMemPtrA
>STYA BIN.LoadExe.NewBase
jsr BIN.InstallEXE
bcs .98 relocation error, dicard Code segment
>LDYA BIN.LoadExe.Filename get back bin path
jsr K.NewPStrYA make a copy of this string
bcs .98
phx save copy
lda BIN.LoadExe.hMem
jsr K.GetMemByIDA
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
ora #S.MEM.F.CODE This is a code segment
sta (ZPQuickPtr1)
pla
ldy #S.MEM.BIN
sta (ZPQuickPtr1),y
lda BIN.LoadExe.hMem
tax return hMEM to Caller...
jsr K.GetMemPtrA
clc ...and Y,A=PTR to CS
rts
.98 pha
lda BIN.LoadExe.hMem
jsr K.FreeMemA Discard Loaded Code
pla
sec
.99 rts
*--------------------------------------
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
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.BIN
LOAD SYS/KERNEL.S
ASM