A2osX/BIN/SHUTDOWN.S.txt
2020-09-24 08:24:47 +02:00

225 lines
3.9 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.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/shutdown
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/kernel.i
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
Count .BS 1
Index .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DA #32 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.SHUTDOWN .DA MSG.SHUTDOWN
L.MSG.PS .DA MSG.PS
L.MSG.DEV .DA MSG.DEV
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
CS.RUN >LDYA L.MSG.SHUTDOWN
>SYSCALL PutS
jsr CS.RUN.PS
jsr CS.RUN.DEV
>PUSHBI 1
>PUSHBI 1 INITD
>SYSCALL Kill
lda #0
sec
rts
*--------------------------------------
CS.RUN.PS stz Count
ldx #0
stx Index
.1 lda PS.Table.hPS,x
beq .7
>SYSCALL GetMemPtr
>STYA ZPPtr1
.2 lda (ZPPtr1)
bpl .4 HOLD ?
ldy #S.PS.CPID
lda (ZPPtr1),y
.3 jsr CS.GetPSByID
bra .2
.4 ldy #S.PS.S
lda (ZPPtr1),y
cmp #S.PS.S.QUIT
beq .6
ldy #S.PS.PID
lda (ZPPtr1),y
beq .7 don't kill PS0
cmp #1
beq .7 don't kill INITD
cmp (pPS),y don't kill myself
beq .7
jsr CS.RUN.KILL
.5 ldy #S.PS.PPID
lda (ZPPtr1),y
bne .3 go kill parent if not 0
.6 inc Count
.7 >SLEEP
inc Index
ldx Index
cpx #K.PS.MAX
bne .1
lda Count
bne CS.RUN.PS
sec
rts
*--------------------------------------
CS.RUN.KILL >PUSHW L.MSG.PS
ldy #S.PS.PID
lda (ZPPtr1),y
>PUSHA
ldy #S.PS.hARGV
lda (ZPPtr1),y
>SYSCALL GetMemPtr
>PUSHYA
>PUSHBI 3
>SYSCALL PrintF
>PUSHBI 1
ldy #S.PS.PID
lda (ZPPtr1),y
>SYSCALL Kill
rts
*--------------------------------------
CS.RUN.DEV ldx #1
stx Index
.1 lda Dev.Table-1,x
sta ZPPtr1
lda Dev.Table,x
sta ZPPtr1+1
beq .7
>PUSHW L.MSG.DEV
>PUSHB Index
lda ZPPtr1
clc
adc #S.FD.DEV
tay
lda ZPPtr1+1
adc /S.FD.DEV
>PUSHYA
>PUSHBI 3
>SYSCALL PrintF
.7 inc Index
inc Index
ldx Index
cpx #K.DEV.MAX*2+1
bne .1
rts
*--------------------------------------
CS.GetPSByID ldx #0
.1 ldy PS.Table.hPS,x
beq .7
pha
tya
phx
>SYSCALL GetMemPtr
>STYA ZPPtr1
plx
pla
ldy #S.PS.PID
cmp (ZPPtr1),y
beq .8
.7 inx
cpx #K.PS.MAX
bne .1
* sec
rts
.8 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT clc
rts
*--------------------------------------
CS.END
MSG.USAGE .AS "Usage : SHUTDOWN <NEXT.STSTEM>\r\n"
.AZ " -T <seconds> : \r\n"
MSG.SHUTDOWN .AZ "SHUTDOWN:System..."
MSG.PS .AZ "SHUTDOWN:Killing process %3d, %s\r\n"
MSG.DEV .AZ "SHUTDOWN:Closing device %3d, %s\r\n"
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/shutdown.s
ASM