A2osX/SYS/KERNEL.S.BIN.txt

264 lines
6.3 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
.OP 65C02
*--------------------------------------
* S.LoadBinA
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
2015-06-03 18:30:57 +00:00
S.LoadBinA sta S.LoadBinA.hFilename save file path
2015-03-14 21:48:35 +00:00
jsr S.GetMemByNameA
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
2015-03-14 21:48:35 +00:00
ply X=hMem from S.GetMemByNameA
clc
rts
2015-06-03 18:30:57 +00:00
.1 lda S.LoadBinA.hFilename
2015-03-14 21:48:35 +00:00
jsr S.LoadFileA
2015-06-03 18:30:57 +00:00
bcc .2
rts Error Loading file
.2 >STYA S.LoadBinA.FileLen
stx S.LoadBinA.hMem save hMem
2015-03-14 21:48:35 +00:00
txa
jsr S.GetMemPtrA
2015-06-03 18:30:57 +00:00
>STYA ZPQuickPtr1 save base address for relocation
ldy #H.BIN.CODE.LEN make AX = Code Len
lda (ZPQuickPtr1),y
sta R.AL
iny
lda (ZPQuickPtr1),y
sta R.AH
lda S.LoadBinA.hFilename
2015-03-14 21:48:35 +00:00
jsr S.MLIGetFileInfoA Get File Info for AUXTYPE
bcs .98
2015-06-03 18:30:57 +00:00
>STYA ZPQuickPtr2
2015-03-14 21:48:35 +00:00
ldy #2 get AUXTYPE
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr2),y
sta R.BL Make BX=Range Start=AUXTYPE
sta S.LoadBinA.AuxType
clc
adc S.LoadBinA.FileLen
sta R.CL Make CX=Range End=AUXTYPE+FILELEN
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr2),y
sta R.BH
sta S.LoadBinA.AuxType+1
adc S.LoadBinA.FileLen+1
sta R.CH
lda ZPQuickPtr1 Compute relocation offset in DX
2015-03-14 21:48:35 +00:00
sec
2015-06-03 18:30:57 +00:00
sbc S.LoadBinA.AuxType
sta R.DL DX=Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
sbc S.LoadBinA.AuxType+1
sta R.DH
>LDYA ZPQuickPtr1
jsr S.BinRelocateYA
2015-03-14 21:48:35 +00:00
bcs .98 relocation error, dicard Code segment
2015-06-03 18:30:57 +00:00
lda S.LoadBinA.hFilename get back bin path
2015-03-14 21:48:35 +00:00
jsr S.PStrCpyA
bcs .98
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
pha save copy of bin path
2015-06-03 18:30:57 +00:00
lda S.LoadBinA.hMem
2015-03-14 21:48:35 +00:00
jsr S.GetMemByIDA
>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)
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
ldy #S.MEM.BIN
pla get back copy of bin path
sta (ZPQuickPtr1),y
2015-06-03 18:30:57 +00:00
lda S.LoadBinA.hMem
tax return hMEM to Caller...
jsr S.GetMemPtrA
clc ...and Y,A=PTR to CS
2015-03-14 21:48:35 +00:00
rts
.98 pha
2015-06-03 18:30:57 +00:00
lda S.LoadBinA.hMem
jsr S.FreeMemA Discard Loaded Code
2015-03-14 21:48:35 +00:00
pla
2015-06-03 18:30:57 +00:00
sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
S.LoadBinA.hFilename .BS 1
S.LoadBinA.hMem .BS 1
S.LoadBinA.AuxType .BS 2
S.LoadBinA.FileLen .BS 2
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
* S.BinRelocateYA :
* YA = Ptr to Code
* R.AX = Code Length
* R.BX = Range Start address to relocate
* R.CX = Range End address to relocate
* R.DX = offset to apply to all abs addresses between R.BX and R.CX
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
S.BinRelocateYA >STYA ZPQuickPtr1
ldy #H.BIN.JMP relocate Main JMP
lda (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
clc
2015-06-03 18:30:57 +00:00
adc R.DL
2015-03-14 21:48:35 +00:00
sta (ZPQuickPtr1),y
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
iny
lda (ZPQuickPtr1),y
2015-06-03 18:30:57 +00:00
adc R.DH
sta (ZPQuickPtr1),y
ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
bra S.JmpRelocate
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
S.DrvRelocateYA >STYA ZPQuickPtr1
ldy #0
S.JmpRelocate lda (ZPQuickPtr1),y Start Relocate JMP table
tax
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
ora (ZPQuickPtr1),y
beq S.CodeRelocate $0000 = end of table
2015-03-14 21:48:35 +00:00
dey
2015-06-03 18:30:57 +00:00
txa
clc
adc R.DL
sta (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y
adc R.DH
sta (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
bra S.JmpRelocate
S.CodeRelocate lda ZPQuickPtr1
2015-03-14 21:48:35 +00:00
clc
2015-06-03 18:30:57 +00:00
adc R.AL Make ZPQuickPtr2=End of code
sta ZPQuickPtr2 =ZPQuickPtr1+AX (code len)
lda ZPQuickPtr1+1
adc R.AH
sta ZPQuickPtr2+1
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
tya add current offset in Y to Ptr
2015-03-14 21:48:35 +00:00
clc
2015-06-03 18:30:57 +00:00
adc ZPQuickPtr1
2015-03-14 21:48:35 +00:00
sta ZPQuickPtr1
2015-06-03 18:30:57 +00:00
bcc .5
inc ZPQuickPtr1+1 ZPQuickPtr1=Current Code PTR
clc
.5 lda (ZPQuickPtr1) get OPCODE
2015-03-14 21:48:35 +00:00
tax
lda OPCODES,x get OPCODE definition
bpl .7 abs addressing?
2015-06-03 18:30:57 +00:00
and #3 save Opcode length...
pha
2015-03-14 21:48:35 +00:00
ldy #1
lda (ZPQuickPtr1),y Get LO
sec
sbc R.BL
iny
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y Get HI
2015-03-14 21:48:35 +00:00
sbc R.BH
2015-06-03 18:30:57 +00:00
bcc .6 addr < AX, out of range
2015-03-14 21:48:35 +00:00
dey
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y Get LO
sec
sbc R.CL
2015-03-14 21:48:35 +00:00
iny
2015-06-03 18:30:57 +00:00
lda (ZPQuickPtr1),y Get HI
sbc R.CH
bcs .6 addr > CX, out of range
dey
lda (ZPQuickPtr1),y Get LO
2015-03-14 21:48:35 +00:00
clc
2015-06-03 18:30:57 +00:00
adc R.DL add DX to abs address
sta (ZPQuickPtr1),y store relocated addr LO
iny
lda (ZPQuickPtr1),y Get HI
adc R.DH
sta (ZPQuickPtr1),y store relocated addr HI
.6 pla
.7 clc A = OPCODE length
2015-03-14 21:48:35 +00:00
adc ZPQuickPtr1
sta ZPQuickPtr1
bcc .8
inc ZPQuickPtr1+1
2015-06-03 18:30:57 +00:00
.8 lda ZPQuickPtr1 is Current PTR < Code Limit ?
sec
sbc ZPQuickPtr2
lda ZPQuickPtr1+1
sbc ZPQuickPtr2+1
bcc .5 yes, continue relocating
2015-03-14 21:48:35 +00:00
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
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
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.BIN
LOAD SYS/KERNEL.S
ASM