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.CODE.TYPE .EQ 4
H.BIN.VERSION .EQ 5 H.BIN.VERSION .EQ 5
H.BIN.CODE.LEN .EQ 8 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.O .EQ 12
H.BIN.DRV.CODE.LEN .EQ 14 H.BIN.DRV.CODE.LEN .EQ 14
H.BIN.RELOC.TABLE .EQ 16 H.BIN.DRV.REL.TABLE .EQ 0
*-------------------------------------- *--------------------------------------
* A2osX.SYSCALL Functions Indexes * A2osX.SYSCALL Functions Indexes
*-------------------------------------- *--------------------------------------

View File

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

View File

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

View File

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