Kernel version 0.8 : Fixed a nasty bug in Relocator, but another one still there in K/LoadFile

This commit is contained in:
Rémy GIBERT 2016-09-30 17:04:55 +02:00
parent 4219fe9e0d
commit d1de493789
6 changed files with 96 additions and 91 deletions

Binary file not shown.

Binary file not shown.

View File

@ -130,11 +130,14 @@ H.BIN.JMP .EQ 2
H.BIN.CODE.TYPE .EQ 4
H.BIN.VERSION .EQ 5
H.BIN.CODE.LEN .EQ 8
H.BIN.BIN.DS.SIZE .EQ 10
H.BIN.DEV.HEADER.O .EQ 10
*
H.BIN.EXE.DS.SIZE .EQ 10
H.BIN.EXE.REL.TABLE .EQ 16
*
H.BIN.DRV.DEVCTRLBLK.O .EQ 10
H.BIN.DRV.CODE.O .EQ 12
H.BIN.DRV.CODE.LEN .EQ 14
H.BIN.RELOC.TABLE .EQ 16
H.BIN.DRV.REL.TABLE .EQ 0
*--------------------------------------
* A2osX.SYSCALL Functions Indexes
*--------------------------------------

View File

@ -41,53 +41,53 @@ K.LoadEXEYA.1 >PUSHWI KrnBuf256
jsr K.LoadFile
.9 bcs .99 Error Loading file
>STYA BIN.Relocate.SegLen
>DEBUG
stx K.LoadEXEYA.hMem save hMem
txa
jsr K.GetMemPtrA
>STYA ZPQuickPtr1
ldy #H.BIN.CODE.LEN+1 get Code Len
lda (ZPQuickPtr1),y
tax
dey
lda (ZPQuickPtr1),y
jsr BIN.Relocate.SetCodeLenAX
pha YA=CODE+DATA size
tya
* clc CC from bcs .99
lda BIN.Relocate.Start Get AUXTYPE for actual Base Address
clc
adc BIN.Relocate.SegLen
adc BIN.Relocate.Start Get AUXTYPE for actual Base Address
sta BIN.Relocate.End compute Range End=AUXTYPE+FILELEN
lda BIN.Relocate.Start+1
adc BIN.Relocate.SegLen+1
pla
adc BIN.Relocate.Start+1
sta BIN.Relocate.End+1
lda ZPQuickPtr1
txa
jsr K.GetMemPtrA
>STYA ZPQuickPtr1 set ZPQuickPtr1 -> Code start
>DEBUG
pha YA = actual load address
tya
sec
sbc BIN.Relocate.Start
sta BIN.Relocate.Offset Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
pla
sbc BIN.Relocate.Start+1
sta BIN.Relocate.Offset+1
jsr Bin.RelocateEXE
ldy #H.BIN.CODE.LEN get Code Len
jsr BIN.SetupCodeEndPtr2
jsr BIN.RelocateEXE
>LDYA K.LoadEXEYA.Filename get back bin path
>SYSCALL SYS.NewPStrYA make a copy of this string
bcs .98
phx save copy
lda K.LoadEXEYA.hMem
jsr K.GetMemByIDA
lda K.LoadEXEYA.hMem Keep X=hMem
jsr K.GetMemByIDA X unmodified
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
ora #S.MEM.F.CODE This is a code segment
sta (ZPQuickPtr1)
pla
txa Get Back hMem
ldy #S.MEM.BIN
sta (ZPQuickPtr1),y
@ -111,14 +111,7 @@ K.LoadEXEYA.hMem .BS 1
* BIN.InstallDRV
* pDrv = .DRV File Loaded Address
*--------------------------------------
BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN+1
lda (pDrv),y
tax
dey
lda (pDrv),y
jsr BIN.Relocate.SetCodeLenAX
ldy #H.BIN.DRV.CODE.O
BIN.InstallDRV ldy #H.BIN.DRV.CODE.O
lda (pDrv),y
clc
adc BIN.Relocate.Start Advance start From Bin code to DRV code
@ -128,29 +121,28 @@ BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN+1
adc BIN.Relocate.Start+1
sta BIN.Relocate.Start+1
ldy #H.BIN.DRV.CODE.O
lda BIN.Relocate.SegLen
lda BIN.Relocate.End Compute DRVLen=End-start
sec
sbc (pDrv),y
sbc BIN.Relocate.Start
sta BIN.InstallDRV.DRVLen
iny
lda BIN.Relocate.SegLen+1
sbc (pDrv),y
sta BIN.InstallDRV.DRVLen+1 Compute DRV Len
lda BIN.Relocate.End+1
sbc BIN.Relocate.Start+1
sta BIN.InstallDRV.DRVLen+1
lda DevMgr.Free
clc
adc BIN.InstallDRV.DRVLen
sta BIN.InstallDRV.DRVEnd
tay Save DRVEnd LO
lda DevMgr.Free+1
adc BIN.InstallDRV.DRVLen+1
sta ZPQuickPtr3+1 save it for DrvMove
adc BIN.InstallDRV.DRVLen+1 A = DRVEnd HI
sta BIN.InstallDRV.DRVEnd+1
bcs .98 we crossed $FFFF, out of mem
lda BIN.InstallDRV.DRVEnd
cmp #DevMgr.HiMem
lda BIN.InstallDRV.DRVEnd+1
cpy #DevMgr.HiMem
sbc /DevMgr.HiMem
bcs .98 No More Room to load Driver....
@ -161,7 +153,7 @@ BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN+1
sta DevMgr.LastDevID
ldy #H.BIN.DEV.HEADER.O
ldy #H.BIN.DRV.DEVCTRLBLK.O
lda (pDrv),y
clc
adc pDrv
@ -193,6 +185,9 @@ BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN+1
adc pDrv+1
sta ZPQuickPtr1+1
ldy #H.BIN.DRV.CODE.LEN
jsr BIN.SetupCodeEndPtr2
jsr BIN.RelocateDRV
jsr BIN.MoveDRV
@ -210,7 +205,7 @@ BIN.InstallDRV ldy #H.BIN.DRV.CODE.LEN+1
sec
rts
*--------------------------------------
BIN.MoveDRV ldy #H.BIN.DEV.HEADER.O
BIN.MoveDRV ldy #H.BIN.DRV.DEVCTRLBLK.O
lda (pDrv),y
clc
adc pDrv
@ -259,10 +254,8 @@ BIN.MoveDRV ldy #H.BIN.DEV.HEADER.O
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
>LDYA DevMgr.Free
>STYA ZPQuickPtr2 Make ZPQuickPtr1=Dest location in LC
lda BIN.InstallDRV.DrvLen+1
eor #$ff
@ -276,7 +269,7 @@ BIN.MoveDRV ldy #H.BIN.DEV.HEADER.O
.2 inx
bne .3
pla
inc
dec
beq .8
pha
@ -284,35 +277,41 @@ BIN.MoveDRV ldy #H.BIN.DEV.HEADER.O
sta (ZPQuickPtr2),y
iny
bne .2
inc ZPQuickPtr1+1
inc ZPQuickPtr2+1
bra .2
.8 rts CC from last ADC
.8 rts
*--------------------------------------
BIN.InstallDRV.DrvLen .BS 2
BIN.InstallDRV.DrvEnd .BS 2
*--------------------------------------
BIN.Relocate.SetCodeLenAX
eor #$ff
sta BIN.Relocate.nCodeLen
txa
eor #$ff
sta BIN.Relocate.nCodeLen+1
BIN.SetupCodeEndPtr2
lda (ZPQuickPtr1),y
clc
adc ZPQuickPtr1
sta ZPQuickPtr2 Make ZPQuickPtr2 = ZPQuickPtr1 + CodeLen
iny
lda (ZPQuickPtr1),y
adc ZPQuickPtr1+1
sta ZPQuickPtr2+1
rts
*--------------------------------------
* BIN.Relocate___ :
* In :
* ZPQuickPtr1 = Ptr to Code
* ZPQuickPtr2 = End Of Code
*--------------------------------------
BIN.Relocate.SegLen .BS 2 Code+Data Len
BIN.Relocate.Start .BS 2
BIN.Relocate.End .BS 2
BIN.Relocate.Offset .BS 2
BIN.Relocate.nCodeLen .BS 2 !Code length
*--------------------------------------
BIN.RelocateEXE ldy #H.BIN.JMP relocate Main JMP
BIN.RelocateEXE ldy #H.BIN.HEADER+1
lda (ZPQuickPtr1),y
cmp /H.BIN.HEADER.BIN65
bne *
ldy #H.BIN.JMP relocate Main JMP
lda (ZPQuickPtr1),y
clc
adc BIN.Relocate.Offset
@ -323,14 +322,11 @@ BIN.RelocateEXE ldy #H.BIN.JMP relocate Main JMP
adc BIN.Relocate.Offset+1
sta (ZPQuickPtr1),y
ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
>DEBUG
ldy #H.BIN.EXE.REL.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
.HS 2C bit abs
*--------------------------------------
BIN.RelocateDRV ldy #0
BIN.RelocateDRV ldy #H.BIN.DRV.REL.TABLE
.1 lda (ZPQuickPtr1),y Start Relocate JMP table
tax LO in X
@ -362,24 +358,19 @@ BIN.RelocateDRV ldy #0
bcc .3
inc ZPQuickPtr1+1 ZPQuickPtr1=Current Code PTR
.3 inc BIN.Relocate.nCodeLen
bne .4 nCodeLen reached 0 ?
inc BIN.Relocate.nCodeLen+1
beq .8 no, continue relocating
.4 lda (ZPQuickPtr1) get OPCODE
.3 lda (ZPQuickPtr1) get OPCODE
lsr /2
tax
lda BIN.OPCODES,x get OPCODE definition
bcs .5 go get LO nibble
bcs .4 go get LO nibble
lsr
lsr move HI -> LO
lsr
lsr
.5 and #$0f
.4 and #$0f
bit #$8 abs addressing?
beq .7 no....
beq .6 no....
and #7 save Opcode length...
pha
@ -393,13 +384,13 @@ BIN.RelocateDRV ldy #0
cpx BIN.Relocate.Start
lda (ZPQuickPtr1),y Get HI
sbc BIN.Relocate.Start+1
bcc .6 addr < BIN.Relocate.Start, out of range
bcc .5 addr < BIN.Relocate.Start, out of range
txa Get back LO
cpx BIN.Relocate.End
lda (ZPQuickPtr1),y Get HI
sbc BIN.Relocate.End+1
bcs .6 addr > BIN.Relocate.End, out of range
bcs .5 addr > BIN.Relocate.End, out of range
txa Get back LO
* clc CC from bcs .6
@ -411,14 +402,19 @@ BIN.RelocateDRV ldy #0
adc BIN.Relocate.Offset+1
sta (ZPQuickPtr1),y store relocated addr HI
.6 pla get back Opcode length...
.5 pla get back Opcode length...
.7 clc A = OPCODE length
.6 clc A = OPCODE length
adc ZPQuickPtr1
sta ZPQuickPtr1
bcc .3
bcc .7
inc ZPQuickPtr1+1
bra .3 next opcode....
.7 eor ZPQuickPtr2 A = ZPQuickPtr1
bne .3
lda ZPQuickPtr1+1
eor ZPQuickPtr2+1
bne .3 next opcode....
.8 rts
*--------------------------------------

View File

@ -145,13 +145,13 @@ K.LoadFile jsr K.FOPEN
ldx #SYS.FSEEK.SET
jsr K.LoadFile.Seek
bcs .99
bcs .97
>PUSHW K.LoadFile.Mem
>PUSHW K.LoadFile.Len
>PUSHB K.LoadFile.hFile
jsr K.FREAD
bcs .99
bcs .97
jsr .99
@ -160,6 +160,12 @@ K.LoadFile jsr K.FOPEN
clc
.9 rts
.97 pha
lda K.LoadFile.hMem
jsr K.FreeMemA
pla
.HS 2C
.98 lda #SYSMGR.ERRFTB
.99 pha

View File

@ -265,7 +265,7 @@ PS.Init >LDYA K.CreateProcess.CmdLine
ldy #S.PS.hCS
sta (ZPQuickPtr3),y save CS hMem in TSKSLOT
ldy #H.BIN.BIN.DS.SIZE+1
ldy #H.BIN.EXE.DS.SIZE+1
lda (ZPQuickPtr4),y Load DS.SIZE HI
tax
dey