A2osX/SYS/KERNEL.S.INIT.txt

885 lines
18 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
Kernel.Init sei
ldx #$FF
txs
sta SETALTZP
stx A2osX.SaveSM
stx A2osX.SaveSX
sta CLRALTZP Make sure MAIN ZP is enabled for X.PRINT.F
*--------------------------------------
Kernel.Init2 >LDAXI MSG.Init2
jsr PrintFAX
>LDYAI A2osX.GP
>STYA ZPPtr1
>LDYAI A2osX.SYSCALL
>STYA ZPPtr2
>LDYAI A2osX.D1-A2osX.GP^$FFFF
>STYA ZPPtr3
jsr Kernel.Move
sta CLRALTZP
>LDAXI MSG.D2
jsr PrintFAX
sta SETALTZP
bit RRAMWRAMBNK2
bit RRAMWRAMBNK2
>LDYAI A2osX.D2
>STYA ZPPtr1
>LDYAI $D000
>STYA ZPPtr2
>LDYAI A2osX.E0-A2osX.D2^$FFFF
>STYA ZPPtr3
jsr Kernel.Move
sta CLRALTZP
>LDAXI MSG.D1
jsr PrintFAX
sta SETALTZP
bit RRAMWRAMBNK1
bit RRAMWRAMBNK1
>LDYAI A2osX.D1
>STYA ZPPtr1
>LDYAI $D000
>STYA ZPPtr2
>LDYAI A2osX.D2-A2osX.D1^$FFFF
>STYA ZPPtr3
jsr Kernel.Move
sta CLRALTZP
>LDAXI MSG.E0
jsr PrintFAX
sta SETALTZP
bit RRAMWRAMBNK1
bit RRAMWRAMBNK1
>LDYAI A2osX.E0
>STYA ZPPtr1
>LDYAI $E000
>STYA ZPPtr2
>LDYAI A2osX.E0.E-A2osX.E0^$FFFF
>STYA ZPPtr3
jsr Kernel.Move
>LDYAI K.STACK
>STYA pStack init Kernel Soft Stack
sta CLRALTZP Make MAIN ZP is enabled for X.PRINT.F
cli
jsr KConfigLoad
lda A2osX.HZ
pha push HZ
>LDAXI MSG.HZ
jsr PrintFAX
jsr CPU.Init
>LDAXI MSG.Init2.OK
jsr PrintFAX
*--------------------------------------
>DEBUGOA
*--------------------------------------
Kernel.Init3 sta SETALTZP
bit RRAMWRAMBNK1
bit RRAMWRAMBNK1
jsr MemMgrInit
jsr PS0Init
bcs *
>LDYAI MSG.Init3
>SYSCALL PrintF.YA
jsr DevMgrInit
bcs *
jsr IrqMgrInit
bcs *
jsr EvtMgrInit
bcs *
jsr FltMgrInit
bcs *
jsr TskMgrInit
bcs *
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtr.A
>PUSHYA
>LDYAI MSG.Prefix
>SYSCALL PrintF.YA
>PUSHWI STARTUP.CMDLINE
>LDYAI MSG.Startup
>SYSCALL PrintF.YA
>LDYAI STARTUP.CMDLINE
>SYSCALL ExpandStr.YA
phx Save Expanded CMDLINE for discard
>SYSCALL CreateProcessYA
bcs .9
pla
>SYSCALL FreeMem.A ...discard...
>LDYAI MSG.Init3.OK
>SYSCALL PrintF.YA
>DEBUGOA
jmp CORE.Run
.9 >PUSHA
>LDYAI MSG.StartupErr
>SYSCALL PrintF.YA
bra * No need to discard Expanded CMDLINE
*--------------------------------------
Kernel.Move ldy #0
.1 inc ZPPtr3
bne .2
inc ZPPtr3+1
beq .9
.2 lda (ZPPtr1),y
sta (ZPPtr2),y
iny
bne .1
inc ZPPtr1+1
inc ZPPtr2+1
bne .1
.9 rts
*--------------------------------------
CPU.Init >LDAXI MSG.CPU
jsr PrintFAX
jsr Detect6502 A = CPU type
sta A2osX.CPUTYPE
ldx MSG.CPUTYPEH,y
lda MSG.CPUTYPEL,y
jsr PrintFAX
lda MACHID
and #MACHID.TYPE
cmp #MACHID.TYPE.IIc
beq CPU.Init.Z80
>LDAXI MSG.CPU.SPEED
jsr PrintFAX
stz A2osX.RANDOM16
stz A2osX.RANDOM16+1
php
sei
.1 bit VBL
bpl .2
.2 bit VBL
bmi .2
ldx #0 Count LO
lda #0 Count HI
.3 ldy #3 (2)
.4 nop (2)
dey (2)
bne .4 (2*)
inc A2osX.RANDOM16 (6)
bne .5 (2*)
inc A2osX.RANDOM16+1 (6)
bit VBL (4)
bpl .3 (2*)
bmi .6
.5 nop (2)
nop (2)
nop (2)
bit VBL (4)
bpl .3 (2*)
.6 plp
stz A2osX.CPUSPEED
.7 sec
lda A2osX.RANDOM16
sbc #100
tax
lda A2osX.RANDOM16+1
sbc /100
bcc .8
stx A2osX.RANDOM16
sta A2osX.RANDOM16+1
inc A2osX.CPUSPEED
bra .7
.8 lda A2osX.RANDOM16
sta A2osX.CPUSPEED+1
pha push CPU speed LO
lda A2osX.CPUSPEED
pha push CPU speed HI
>LDAXI MSG.CPU.SPEEDOK
jsr PrintFAX
CPU.Init.Z80 >LDAXI MSG.Z80
jsr PrintFAX
jsr DetectZ80
bcs .9
sta A2osX.Z80SLOT
pha Push Z80Slot
tax
lda #A2osX.SLOTS.Z80
sta A2osX.SLOTS,x
>LDAXI MSG.Z80.OK
jsr PrintFAX
rts
.9 >LDAXI MSG.Z80.KO
jsr PrintFAX
rts
*--------------------------------------
* Out:
* A = $60, 6502
* A = $61, 65C02
* A = $62, 65R02
* A = $63, 65816
*--------------------------------------
Detect6502 ldy #0 Test 6502 BCD bug
sed
lda #$99
clc
adc #$01
cld
bmi .9 BUG!, we have 6502
ldy #3 test 65C816 TYX Instruction
ldx #0
.OP 65816
tyx TYX: if 65C816, x becomes non-zero
.OP 65C02
bne .9 worked! 65C816
dey y=2 -> R65C02
ldx $EA save zp $EA
stz $EA store 0 in $EA
* .OP 65R02
.HS F7EA For compatibility with A2osX.ASM
* smb 7,$EA if not Rockwell, assemble as nop nop
* .OP 65C02
asl $EA cs if Rockwell
stx $EA restore zp $EA
bcs .9
dey y=1 -> 65C02
.9 tya
ora #$60
rts
*--------------------------------------
* Out:
* A = Z80 Slot
*--------------------------------------
DetectZ80 ldx #Z80Code.Size
.1 lda Z80Code.Start-1,x
sta $1000-1,x 00000H for Z80
dex
bne .1
stz ZPPtr1
lda #$C1
sta ZPPtr1+1
.2 sta (ZPPtr1)
lda $100D
bmi .8
inc ZPPtr1+1
lda ZPPtr1+1
cmp #$C8
beq .9 CS
clc
adc #$20
sta $100A
bra .2
.8 lda ZPPtr1+1
and #$0F
clc
.9 rts
*--------------------------------------
KConfigLoad >LDAXI MSG.KCREAD
jsr PrintFAX
jsr MLI
.DA #MLIOPEN
.DA MLIOPEN00
bcs .9
lda MLIOPEN00+5
sta MLIREAD00+1
sta MLICLOSE00+1
jsr MLI
.DA #MLIREAD
.DA MLIREAD00
php
pha
jsr MLI
.DA #MLICLOSE
.DA MLICLOSE00
pla
plp
bcs .9
>LDAXI MSG.KCREAD.OK
jsr PrintFAX
rts
.9 >LDAXI MSG.KCREAD.KO
jsr PrintFAX
rts
*--------------------------------------
Z80Code.Start .HS 31FFFF START: LD SP,0FFFFH Init Stack
.HS 3EFF LD A,0FFH Set Flag
.HS 320D00 LD (FLAG),A
.HS 3200E1 LD (0E100H),A Back to 6502
.HS 18F3 JR START Loop
.HS 00 FLAG: .DB 0
Z80Code.Size .EQ *-Z80Code.Start
*--------------------------------------
MemMgrInit >LDYAI MemMgr.MHiMem
>STYA MemMgr.HiMem
>STYA MemMgr.Free
>LDYAI MemMgr.MLoMem
>STYA MemMgr.LoMem
stz MemMgr.LastSlot Reserve Slot #0
sta SETWRITEAUX
>LDYAI MemMgr.XHiMem
>STYA MemMgr.HiMem
>STYA MemMgr.Free
>LDYAI MemMgr.XLoMem
>STYA MemMgr.LoMem
stz MemMgr.LastSlot Reserve Slot #0
sta CLRWRITEAUX
rts
*--------------------------------------
PS0Init ldx #S.DEV*2 NUL,SYS
.1 lda DevMgr.NUL-1,x
sta DevMgr.Table-1,x
dex
bne .1
lda #2
sta DevMgr.Count
>LDYAI TskMgr.Table Select Process 0 (Kernel)
>STYA pPs
ldy #S.PS-1
lda #0
.2 sta (pPs),y Blank PS0
dey
bpl .2
>LDYAI DEV.SYS
>SYSCALL MkNod.YA
bcs .9
ldy #S.PS.hStdIn
sta (pPs),y
ldy #S.PS.hStdOut
sta (pPs),y
ldy #S.PS.hStdErr
sta (pPs),y
clc
.9 rts
*--------------------------------------
DevMgr.NUL cld
jmp (DevMgr.NUL.Code,x)
.DA #S.DEV.S.WRITE+S.DEV.S.READ+S.DEV.S.OPENED
.BS 6
>PSTR "NUL" NAME
.HS 00 NAME must Be 4 bytes long
*--------------------------------------
DevMgr.SYS cld
jmp (DevMgr.SYS.Code,x)
.DA #S.DEV.S.WRITE+S.DEV.S.READ
.BS 6
>PSTR "SYS" NAME
.HS 00 NAME must Be 4 bytes long
*--------------------------------------
* Setup AuxLC $FFFE->Kernel IRQ Handler
* if irq not handled, jmp (S.IrqMgrOldFFFE)
*--------------------------------------
SETMOUSE .EQ $12 Sets mouse mode
SERVEMOUSE .EQ $13 Services mouse interrupt
READMOUSE .EQ $14 Reads mouse position
*--------------------------------------
IrqMgrInit >LDYAI MSG.IRQ
>SYSCALL PrintF.YA
php
sei
>LDYA $FFFE
>STYA K.IrqMgrOldFFFE
>LDYAI K.IrqHandlerAuxLC
>STYA $FFFE
>LDYAI IrqHandler
>STYA K.MLI.PARAMS+2
>MLICALL MLIALLOCIRQ
bcs .9
lda K.MLI.PARAMS+1
sta ProDOS.INTNUM
stz ZPPtr1 Try finding a Mouse Card...
lda #$C1
sta ZPPtr1+1
.1 ldx #Mouse.SIG-Mouse.OFS-1
.2 ldy Mouse.OFS,x
lda (ZPPtr1),y
cmp Mouse.SIG,x
bne .3
dex
bpl .2
bra .4
.3 inc ZPPtr1+1 no match, try next slot....
lda ZPPtr1+1
cmp #$C8
bne .1
plp
clc
rts
.9 plp
sec
rts
.4 lda ZPPtr1+1
sta K.IrqMgrVBL.MSM+2
sta K.IrqMgrVBL.MRM+2
and #$0f
sta K.IrqMgrVBL.0n
asl
asl
asl
asl
sta K.IrqMgrVBL.n0
ldy #SERVEMOUSE
lda (ZPPtr1),y
sta K.IrqMgrVBL.MSM+1
ldy #READMOUSE
lda (ZPPtr1),y
sta K.IrqMgrVBL.MRM+1
bit RROMBNK2 Renable ROM to allow MOUSE II firmware works properly
ldy #SETMOUSE
lda (ZPPtr1),y
sta .7+1
lda #9 #MOUSEMODx.INTVBL+MOUSEMODx.ACTIVE
ldx ZPPtr1+1 DEVSLOTCn
stx .7+2
ldy K.IrqMgrVBL.n0
.7 jsr $ffff self Modified, CALL SETMOUSE
bcs *
bit RRAMWRAMBNK1 Back To LC Ram
bit RRAMWRAMBNK1
inc K.IrkMgr.VBL set=1 awaiting IrqMgr confirmation
plp
>LDYAI MSG.IRQ.VBL
>SYSCALL PrintF.YA
clc
rts
*--------------------------------------
Mouse.OFS .HS 05070B0CFB
Mouse.SIG .HS 38180120D6
*--------------------------------------
DevMgrInit >LDYAI MSG.DEV
>SYSCALL PrintF.YA
stz ZPPtr1
lda #$C1
sta ZPPtr1+1
lda #1
sta DEV.HEADER+S.DEV.BUSID
.1 lda #1
sta DEV.HEADER+S.DEV.DEVID
ldx #SmartPort.SIG-SmartPort.OFS-1
.2 ldy SmartPort.OFS,x Check if there is a smartport firmware
lda (ZPPtr1),y
cmp SmartPort.SIG,x
bne .8 not a Disk Controller...
dex
bpl .2
ldy #$ff
lda (ZPPtr1),y
bne .3 $0, Disk II, 16sect
jsr DevMgrInit.DII
ldy #A2osX.SLOTS.DII
bra .7
.3 inc
beq .7 $ff, Disk II 13 Sect, ignore
ldy #7
lda (ZPPtr1),y
bne .4 $Cn07=00 : SmartPort
jsr DevMgrInit.SP
ldy #A2osX.SLOTS.SP
bra .7
.4 jsr DevMgrInit.BLK
ldy #A2osX.SLOTS.BLK
.7 lda ZPPtr1+1
and #$0f
tax
tya
sta A2osX.SLOTS,x
.8 inc DEV.HEADER+S.DEV.BUSID
inc ZPPtr1+1
lda ZPPtr1+1
cmp #$C8
bne .1
clc
rts
*--------------------------------------
DevMgrInit.DII >LDYAI A2osX.DIIDrv
>STYA DEV.HEADER+S.DEV.DRV.JMP
jsr DevMgrInit.AddDev
inc DEV.HEADER+S.DEV.DEVID
jsr DevMgrInit.AddDev
rts
*--------------------------------------
DevMgrInit.BLK ldy #$ff
lda (ZPPtr1),y
sta DEV.HEADER+S.DEV.ROM.JMP
lda ZPPtr1+1
sta DEV.HEADER+S.DEV.ROM.JMP+1
>LDYAI A2osX.BlkDrv
>STYA DEV.HEADER+S.DEV.DRV.JMP
jsr DevMgrInit.AddDev
inc DEV.HEADER+S.DEV.DEVID
jsr DevMgrInit.AddDev
rts
*--------------------------------------
DevMgrInit.SP ldy #$ff
lda (ZPPtr1),y
clc
adc #3 Compute smartport entry point
sta .1+1
sta .3+1
sta DEV.HEADER+S.DEV.ROM.JMP
lda ZPPtr1+1
sta .1+2
sta .3+2
sta DEV.HEADER+S.DEV.ROM.JMP+1
>LDYAI A2osX.PrtDrv
>STYA DEV.HEADER+S.DEV.DRV.JMP
.1 jsr $ffff Self Modified
.DA #0 Status
.DA SP.CTRL.STATUS
bcs .9
lda SP.CTRL.STATUS.DATA
beq .9 no device
.2 lda #1
sta SP.DEV.STATUS.DEVID
.3 jsr $ffff Self Modified
.DA #0 Status
.DA SP.DEV.STATUS
bcs .7
lda SP.DEV.STATUS.DATA+S.DEVSTAT.S
sta DEV.HEADER+S.DEV.S
jsr DevMgrInit.AddDev
.7 inc SP.DEV.STATUS.DEVID
inc DEV.HEADER+S.DEV.DEVID
dec SP.CTRL.STATUS.DATA
bne .3
.9 rts
*--------------------------------------
DevMgrInit.AddDev
lda DevMgr.Count
cmp #K.DEV.MAX
beq .9
inc DevMgr.Count
>SYSCALL GetDevByID.A
>STYA ZPPtr2
lda DEV.HEADER+S.DEV.BUSID
ora #$30
sta DEV.HEADER+S.DEV.NAME+2 SnDy
lda DEV.HEADER+S.DEV.DEVID
ora #$30
sta DEV.HEADER+S.DEV.NAME+4 SxDn
ldy #S.DEV-1
.1 lda DEV.HEADER,y
sta (ZPPtr2),y
dey
bpl .1
clc
rts
.9 lda #DEVMGR.ERROOH
sec
rts
*--------------------------------------
DEV.HEADER clc
jmp ($ffff,x)
.DA #S.DEV.S.BLOCK S
.BS 1 F
.BS 1 BUS.ID
.BS 1 DEV.ID
.BS 2 ROM.JMP
.BS 1
>PSTR "S1D1" 5 bytes
*--------------------------------------
SmartPort.OFS .HS 010305
SmartPort.SIG .HS 200003
*--------------------------------------
SP.CTRL.STATUS .DA #3
.DA #0
.DA SP.CTRL.STATUS.DATA
.DA #0
SP.CTRL.STATUS.DATA
.BS 8 DevCnt
SP.DEV.STATUS .DA #3
SP.DEV.STATUS.DEVID
.BS 1
.DA SP.DEV.STATUS.DATA
.DA #3 return DIB
SP.DEV.STATUS.DATA
.BS S.DEVSTAT
*--------------------------------------
EvtMgrInit >LDYAI MSG.EVT
>SYSCALL PrintF.YA
lda #$A5
sta A2osX.TIMER16
lda #$9B
sta A2osX.TIMER16+1
lda /EvtMgr.Table
sta pEvent+1
clc
rts
*--------------------------------------
FltMgrInit >LDYAI MSG.FLT
>SYSCALL PrintF.YA
stz FltMgr.Table
clc
rts
*--------------------------------------
TskMgrInit >LDYAI MSG.TSK
>SYSCALL PrintF.YA
>LDYAI TskMgr.Table+S.PS Clear whole process table except PS0
>STYA .2+1
ldx #K.PS.MAX-1
.1 lda #0
ldy #S.PS-1
.2 sta $ffff,y Self Modified
dey
bpl .2
lda .2+1
clc
adc #S.PS
sta .2+1
bcc .3
inc .2+2
.3 dex
bne .1
>LDYAI K.ENV.SIZE get a buffer for ENV
>SYSCALL GetMem0.YA make sure blank!!
bcs .9
txa
ldy #S.PS.hENV
sta (pPs),y
>LDYAI K.Buf256
>STYA K.MLI.PARAMS+1
>MLICALL MLIGETPREFIX
bcs .9
ldy K.Buf256
iny
lda #0
jsr K.GetMem.YA
>STYA ZPPtr1
txa
ldy #S.PS.hPREFIX
sta (pPs),y
ldy K.Buf256
lda #0
sta (ZPPtr1),y
.4 lda K.Buf256,y
dey
sta (ZPPtr1),y
bne .4
>PUSHW ZPPtr1 push ENV value = PREFIX
>PUSHWI I.ENV.A2osX push ENV name = A2OSX
>SYSCALL SetEnv
bcs .9
>LDYAI I.ENV.PATH
>SYSCALL PutEnv.YA
bcs .9
>LDYAI I.ENV.LIB
>SYSCALL PutEnv.YA
bcs .9
>LDYAI I.ENV.DRV
>SYSCALL PutEnv.YA
.9 rts
*--------------------------------------
MSG.Init2 >CSTR "A2osX[Stage2]:Init\nInstalling KERNEL...\n - $BE00 Global Page...\n"
MSG.D1 >CSTR " - $D000 Bank1...\n"
MSG.D2 >CSTR " - $D000 Bank2...\n"
MSG.E0 >CSTR " - $E000...\n"
MSG.HZ >CSTR "Kernel SYS Timer Set For %d0 hz Machine.\n"
MSG.Init2.OK >CSTR "A2osX[Stage2]:Complete.\n"
*--------------------------------------
MSG.Init3 >CSTR "A2osX[Stage3]:Init\r\n"
MSG.DEV >CSTR "-Device Manager...\r\n"
MSG.IRQ >CSTR "-Interrupt Manager...\r\n"
MSG.IRQ.VBL >CSTR " (VBL IRQ Activated)\r\n"
MSG.EVT >CSTR "-Event Manager...\r\n"
MSG.FLT >CSTR "-Path Filter...\r\n"
MSG.TSK >CSTR "-Task Manager...\r\n"
MSG.Prefix >CSTR "Prefix:%s\r\n"
MSG.Startup >CSTR "Executing Kernel Startup Script...\r\nCmd:%s\r\n"
MSG.StartupErr >CSTR "Failed : [$%h]\r\n"
MSG.Init3.OK >CSTR "A2osX[Stage3]:Complete.\r\n"
*--------------------------------------
MSG.CPU >CSTR "Checking CPU..."
MSG.CPU.SPEED >CSTR "Detecting CPU Speed..."
MSG.CPUTYPEL .DA #MSG.6502
.DA #MSG.65C02
.DA #MSG.65R02
.DA #MSG.65816
MSG.CPUTYPEH .DA /MSG.6502
.DA /MSG.65C02
.DA /MSG.65R02
.DA /MSG.65816
MSG.6502 >CSTR "6502.\n"
MSG.65C02 >CSTR "65C02.\n"
MSG.65R02 >CSTR "65R02.\n"
MSG.65816 >CSTR "65816.\n"
MSG.CPU.SPEEDOK >CSTR "%d.%02d Mhz.\n"
MSG.Z80 >CSTR "Detecting Z80 CPU..."
MSG.Z80.OK >CSTR "Detected In Slot %d.\n"
MSG.Z80.KO >CSTR "Not Detected.\n"
MSG.KCREAD >CSTR "Reading Kernel Config File..."
MSG.KCREAD.OK >CSTR "OK\n"
MSG.KCREAD.KO >CSTR "\nError While Reading Kernel Config File, Using Default.\n"
*--------------------------------------
DEV.SYS >PSTR "SYS"
I.ENV.A2osX >CSTR "A2OSX"
I.ENV.PATH >CSTR "PATH=${A2OSX}SBIN/;${A2OSX}BIN/"
I.ENV.LIB >CSTR "LIB=${A2OSX}LIB/"
I.ENV.DRV >CSTR "DRV=${A2OSX}DRV/"
STARTUP.CMDLINE >CSTR "${A2OSX}SBIN/SHELL ${A2OSX}A2osX.STARTUP"
*--------------------------------------
MLIOPEN00 .DA #3
.DA A2OSXCONF
.DA $1000
.BS 1
A2OSXCONF >PSTR "A2osX.KCONFIG"
*--------------------------------------
MLIREAD00 .DA #4
.BS 1
.DA A2osX.HZ
.DA 16
.BS 2
*--------------------------------------
MLICLOSE00 .DA #1
.BS 1
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.INIT
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM