A2osX/BIN/SHUTDOWN.S.txt

381 lines
5.8 KiB
Plaintext
Raw Normal View History

2020-07-27 15:19:35 +00:00
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
2020-09-24 15:31:48 +00:00
*--------------------------------------
DEFAULT.TIMEOUT .EQ 60
2020-07-27 15:19:35 +00:00
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
2020-07-30 11:14:37 +00:00
ZPPtr1 .BS 2
2020-09-24 15:31:48 +00:00
ArgPtr .BS 2
2020-07-27 15:19:35 +00:00
Count .BS 1
Index .BS 1
2020-09-24 15:31:48 +00:00
Timeout .BS 4
bSec .BS 1
bTimeout .BS 1
bRestart .BS 1
2020-08-25 14:54:30 +00:00
ZS.END .ED
2020-07-27 15:19:35 +00:00
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2020-09-24 15:31:48 +00:00
.DA #S.PS.F.EVENT
2020-07-27 15:19:35 +00:00
.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
2020-09-24 15:31:48 +00:00
.DA CS.DOEVENT
2020-07-27 15:19:35 +00:00
.DA CS.QUIT
2020-09-24 06:24:47 +00:00
L.MSG.USAGE .DA MSG.USAGE
2020-09-24 15:31:48 +00:00
L.MSG.CRLF .DA MSG.CRLF
2020-09-24 06:24:47 +00:00
L.MSG.SHUTDOWN .DA MSG.SHUTDOWN
L.MSG.PS .DA MSG.PS
L.MSG.DEV .DA MSG.DEV
2020-07-27 15:19:35 +00:00
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
2020-09-24 15:31:48 +00:00
CS.RUN lda #DEFAULT.TIMEOUT
sta Timeout
.1 inc Index
lda Index
>SYSCALL ArgV
bcs .8
>STYA ZPPtr1
2020-09-25 06:02:05 +00:00
2020-09-24 15:31:48 +00:00
lda (ZPPtr1)
cmp #'-'
beq .2
lda ArgPtr+1
bne .9
>LDYA ZPPtr1
>STYA ArgPtr
2020-09-25 12:05:23 +00:00
lda #3
sta TimeOut
2020-09-24 15:31:48 +00:00
bra .1
.2 ldy #2
lda (ZPPtr1),y
bne .9
dey
lda (ZPPtr1),y
cmp #'a'
bcc .3
cmp #'z'+1
bcs .3
eor #$20
.3 cmp #'T'
bne .4
inc Index
lda Index
>SYSCALL ArgV
bcs .9
>SYSCALL atol
bcs .9
>PULLL Timeout
bra .1
.4 cmp #'R'
bne .9
sec
ror bRestart
bra .1
.8 jsr CS.RUN.WAIT
bcs .99
2020-09-24 06:24:47 +00:00
jsr CS.RUN.PS
2020-07-30 11:14:37 +00:00
jsr CS.RUN.DEV
2020-09-25 06:02:05 +00:00
jsr CS.RUN.SYS
2020-09-24 15:31:48 +00:00
2020-09-22 15:34:51 +00:00
>PUSHBI 1
2020-09-24 15:31:48 +00:00
* lda #1 INITD
2020-08-25 14:54:30 +00:00
>SYSCALL Kill
2020-07-30 11:14:37 +00:00
lda #0
sec
2020-09-24 15:31:48 +00:00
.99 rts
*--------------------------------------
.9 >PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN.WAIT >PUSHW L.MSG.SHUTDOWN
>PUSHL Timeout
>PUSHBI 4
>SYSCALL PrintF
.1 >SLEEP
2020-11-19 15:34:02 +00:00
ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FEOF
bcs .2
tay
bne .2 CC
>SYSCALL GetChar
bcs .9
cmp #$03 Ctrl-C
beq .9 CS
.2 lda bSec
2020-09-24 15:31:48 +00:00
bpl .1
stz bSec
lda bTimeout
bpl CS.RUN.WAIT
>PUSHW L.MSG.CRLF
>PUSHBI 0
>SYSCALL PrintF
clc
2020-11-19 15:34:02 +00:00
.9 rts
2020-07-30 11:14:37 +00:00
*--------------------------------------
2020-09-24 06:24:47 +00:00
CS.RUN.PS stz Count
2020-07-27 15:19:35 +00:00
ldx #0
stx Index
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
.1 lda PS.Table.hPS,x
beq .7
>SYSCALL GetMemPtr
2020-07-30 11:14:37 +00:00
>STYA ZPPtr1
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.2 lda (ZPPtr1)
bpl .4 HOLD ?
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
ldy #S.PS.CPID
lda (ZPPtr1),y
.3 jsr CS.GetPSByID
bra .2
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.4 ldy #S.PS.S
2020-09-22 15:34:51 +00:00
lda (ZPPtr1),y
2020-07-27 15:19:35 +00:00
cmp #S.PS.S.QUIT
beq .6
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
ldy #S.PS.PID
2020-07-30 11:14:37 +00:00
lda (ZPPtr1),y
2020-07-30 15:45:10 +00:00
beq .7 don't kill PS0
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
cmp #1
beq .7 don't kill INITD
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
cmp (pPS),y don't kill myself
beq .7
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
jsr CS.RUN.KILL
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.5 ldy #S.PS.PPID
lda (ZPPtr1),y
bne .3 go kill parent if not 0
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.6 inc Count
.7 >SLEEP
inc Index
ldx Index
cpx #K.PS.MAX
bne .1
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
lda Count
bne CS.RUN.PS
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
sec
rts
*--------------------------------------
CS.RUN.KILL >PUSHW L.MSG.PS
2020-07-27 15:19:35 +00:00
ldy #S.PS.PID
2020-07-30 11:14:37 +00:00
lda (ZPPtr1),y
2020-07-27 15:19:35 +00:00
>PUSHA
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
ldy #S.PS.hARGV
2020-07-30 11:14:37 +00:00
lda (ZPPtr1),y
2020-07-27 15:19:35 +00:00
>SYSCALL GetMemPtr
>PUSHYA
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
>PUSHBI 3
2020-08-25 14:54:30 +00:00
>SYSCALL PrintF
2020-09-24 15:31:48 +00:00
2020-09-22 15:34:51 +00:00
>PUSHBI 1
2020-09-24 15:31:48 +00:00
2020-07-27 15:19:35 +00:00
ldy #S.PS.PID
2020-07-30 11:14:37 +00:00
lda (ZPPtr1),y
2020-08-25 14:54:30 +00:00
>SYSCALL Kill
2020-09-24 06:24:47 +00:00
rts
2020-07-30 11:14:37 +00:00
*--------------------------------------
CS.RUN.DEV ldx #1
stx Index
2020-09-24 15:31:48 +00:00
2020-07-30 11:14:37 +00:00
.1 lda Dev.Table-1,x
sta ZPPtr1
lda Dev.Table,x
sta ZPPtr1+1
beq .7
2020-07-27 15:19:35 +00:00
2020-09-24 06:24:47 +00:00
>PUSHW L.MSG.DEV
2020-07-30 11:14:37 +00:00
>PUSHB Index
2020-09-24 15:31:48 +00:00
2020-07-30 11:14:37 +00:00
lda ZPPtr1
clc
adc #S.FD.DEV
tay
lda ZPPtr1+1
adc /S.FD.DEV
>PUSHYA
2020-09-24 15:31:48 +00:00
2020-07-30 11:14:37 +00:00
>PUSHBI 3
>SYSCALL PrintF
2020-09-24 15:31:48 +00:00
2020-07-30 11:14:37 +00:00
.7 inc Index
2020-08-25 14:54:30 +00:00
inc Index
2020-07-27 15:19:35 +00:00
2020-07-30 11:14:37 +00:00
ldx Index
cpx #K.DEV.MAX*2+1
2020-09-24 15:31:48 +00:00
bne .1
2020-07-27 15:19:35 +00:00
rts
*--------------------------------------
2020-09-25 06:02:05 +00:00
CS.RUN.SYS stz $280
>LDYA ArgPtr
beq .9
>PUSHYA
>PUSHWI $281
>SYSCALL RealPath
bcs .9
2020-09-25 12:05:23 +00:00
ldx #$ff
2020-09-25 06:02:05 +00:00
.1 inx
2020-09-25 12:05:23 +00:00
lda $281,x
2020-09-25 06:02:05 +00:00
bne .1
stx $280
.9 rts
*--------------------------------------
2020-09-24 06:24:47 +00:00
CS.GetPSByID ldx #0
.1 ldy PS.Table.hPS,x
beq .7
pha
tya
phx
>SYSCALL GetMemPtr
>STYA ZPPtr1
plx
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
pla
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
ldy #S.PS.PID
cmp (ZPPtr1),y
beq .8
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.7 inx
cpx #K.PS.MAX
bne .1
2020-09-24 15:31:48 +00:00
* sec
2020-09-24 06:24:47 +00:00
rts
2020-09-24 15:31:48 +00:00
2020-09-24 06:24:47 +00:00
.8 clc
rts
*--------------------------------------
2020-09-24 15:31:48 +00:00
CS.DOEVENT lda (pEvent)
bpl .9
asl
bpl .9
sta bSec
ldx #4
ldy #0
clc
.1 lda Timeout,y
sbc #0
sta Timeout,y
iny
dex
bne .1
ror
eor #$80
sta bTimeout
.9 sec
2020-07-27 15:19:35 +00:00
rts
*--------------------------------------
CS.QUIT clc
rts
*--------------------------------------
2020-09-24 15:31:48 +00:00
CS.END
2020-11-19 15:34:02 +00:00
MSG.USAGE .AS "Usage : SHUTDOWN <NEXT.SYSTEM>\r\n"
2020-09-24 15:31:48 +00:00
.AS " -R : Restart System\r\n"
.AS " -T <seconds> : default to 60"
MSG.CRLF .AZ "\r\n"
MSG.SHUTDOWN .AZ "\r\e[KSHUTDOWN:System will stop in %u seconds..."
2020-09-24 06:24:47 +00:00
MSG.PS .AZ "SHUTDOWN:Killing process %3d, %s\r\n"
MSG.DEV .AZ "SHUTDOWN:Closing device %3d, %s\r\n"
2020-07-27 15:19:35 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
2020-08-25 14:54:30 +00:00
DS.END .ED
2020-07-27 15:19:35 +00:00
*--------------------------------------
MAN
SAVE usr/src/bin/shutdown.s
ASM