Subversion Repositories SvarDOS

Rev

Rev 450 | Rev 460 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 450 Rev 459
1
;
1
;
2
; rmod - resident module of the SvarCOM command interpreter
2
; rmod - resident module of the SvarCOM command interpreter
3
;
3
;
4
; Copyright (C) 2021 Mateusz Viste
4
; Copyright (C) 2021 Mateusz Viste
5
; MIT license
5
; MIT license
6
;
6
;
7
; this is installed in memory by the transient part of SvarCOM. it has only
7
; this is installed in memory by the transient part of SvarCOM. it has only
8
; two jobs: providing a resident buffer for command history, environment, etc
8
; two jobs: providing a resident buffer for command history, environment, etc
9
; and respawning COMMAND.COM whenever necessary.
9
; and respawning COMMAND.COM whenever necessary.
10
 
10
 
11
CPU 8086
11
CPU 8086
-
 
12
org 0x100
-
 
13
 
12
org 0h           ; this is meant to be executed without a PSP
14
PSP_ENVSEG equ 0x2C
13
 
15
 
14
section .text    ; all goes into code segment
16
section .text    ; all goes into code segment
15
 
17
 
16
                 ; offset
18
                 ; offset
17
SIG1 dw 0x1983   ;  +0
19
SIG1 dw 0x1983   ;  +0
18
SIG2 dw 0x1985   ;  +2
20
SIG2 dw 0x1985   ;  +2
19
SIG3 dw 0x2017   ;  +4
21
SIG3 dw 0x2017   ;  +4
20
SIG4 dw 0x2019   ;  +6
22
SIG4 dw 0x2019   ;  +6
21
 
23
 
22
; environment segment - this is updated by SvarCOM at init time
24
; environment segment - this is updated by SvarCOM at init time
23
ENVSEG   dw 0    ;  +8
25
ENVSEG   dw 0    ;  +8
24
 
26
 
25
; exit code of last application
27
; exit code of last application
26
LEXCODE  dw 0    ; +0Ah
28
LEXCODE  dw 0    ; +0Ah
27
 
29
 
28
; offset of the COMSPEC variable in the environment block, 0 means "use
30
; offset of the COMSPEC variable in the environment block, 0 means "use
29
; boot drive". this value is patched by the transient part of COMMAND.COM
31
; boot drive". this value is patched by the transient part of COMMAND.COM
30
COMSPECPTR dw 0  ; +0Ch
32
COMSPECPTR dw 0  ; +0Ch
31
 
33
 
32
; fallback COMSPEC string used if no COMPSEC is present in the environment
34
; fallback COMSPEC string used if no COMPSEC is present in the environment
33
; drive. drive is patched by the transient part of COMMAND.COM
35
; drive. drive is patched by the transient part of COMMAND.COM
34
COMSPECBOOT db "@:\COMMAND.COM", 0 ; +0Eh
36
COMSPECBOOT db "@:\COMMAND.COM", 0 ; +0Eh
35
 
37
 
36
skipsig:         ; +1Dh
38
skipsig:         ; +1Dh
37
 
39
 
38
; set up CS=DS=SS and point SP to my private stack buffer
40
; set up CS=DS=SS and point SP to my private stack buffer
39
mov ax, cs
41
mov ax, cs
40
mov ds, ax
42
mov ds, ax
41
mov es, ax
43
mov es, ax
42
mov ss, ax
44
mov ss, ax
43
mov sp, STACKPTR
45
mov sp, STACKPTR
44
 
46
 
45
; collect the exit code of previous application
47
; collect the exit code of previous application
46
mov ah, 0x4D
48
mov ah, 0x4D
47
int 0x21
49
int 0x21
48
xor ah, ah          ; clear out termination status, I only want the exit code
50
xor ah, ah          ; clear out termination status, I only want the exit code
49
mov [LEXCODE], ax
51
mov [LEXCODE], ax
50
 
52
 
51
; preset the default COMSPEC pointer to ES:DX (ES is already set to DS)
53
; preset the default COMSPEC pointer to ES:DX (ES is already set to DS)
52
mov dx, COMSPECBOOT
54
mov dx, COMSPECBOOT
53
 
55
 
54
; do I have a valid COMSPEC?
56
; do I have a valid COMSPEC?
55
or [COMSPECPTR], word 0
57
or [COMSPECPTR], word 0
56
jz USEDEFAULTCOMSPEC
58
jz USEDEFAULTCOMSPEC
57
; set ES:DX to actual COMSPEC
59
; set ES:DX to actual COMSPEC (in env segment)
58
mov es, [ENVSEG]
60
mov es, [PSP_ENVSEG]
59
mov dx, [COMSPECPTR]
61
mov dx, [COMSPECPTR]
60
USEDEFAULTCOMSPEC:
62
USEDEFAULTCOMSPEC:
61
 
63
 
62
; prepare the exec param block
64
; prepare the exec param block
63
mov ax, [ENVSEG]
65
mov ax, [PSP_ENVSEG]
64
mov [EXEC_PARAM_REC], ax
66
mov [EXEC_PARAM_REC], ax
65
mov ax, CMDTAIL
67
mov ax, CMDTAIL
66
mov [EXEC_PARAM_REC+2], ax
68
mov [EXEC_PARAM_REC+2], ax
67
mov [EXEC_PARAM_REC+4], cs
69
mov [EXEC_PARAM_REC+4], cs
68
 
70
 
69
; execute command.com
71
; execute command.com
70
mov ax, 0x4B00         ; DOS 2+ - load & execute program
72
mov ax, 0x4B00         ; DOS 2+ - load & execute program
71
push es                ;
73
push es                ;
72
pop ds                 ;
74
pop ds                 ;
73
;mov dx, COMSPEC       ; DS:DX  - ASCIZ program name (preset already)
75
;mov dx, COMSPEC       ; DS:DX  - ASCIZ program name (preset already)
74
push cs
76
push cs
75
pop es
77
pop es
76
mov bx, EXEC_PARAM_REC ; ES:BX  - parameter block pointer
78
mov bx, EXEC_PARAM_REC ; ES:BX  - parameter block pointer
77
int 0x21
79
int 0x21
78
 
80
 
79
; if all went well, jump back to start
81
; if all went well, jump back to start
80
jnc skipsig
82
jnc skipsig
81
 
83
 
82
; restore DS=CS
84
; restore DS=CS
83
mov bx, cs
85
mov bx, cs
84
mov ds, bx
86
mov ds, bx
85
 
87
 
86
; update error string so it contains the error number
88
; update error string so it contains the error number
87
add al, '0'
89
add al, '0'
88
mov [ERRLOAD + 4], al
90
mov [ERRLOAD + 4], al
89
 
91
 
90
; display error message
92
; display error message
91
mov ah, 0x09
93
mov ah, 0x09
92
mov dx, ERRLOAD
94
mov dx, ERRLOAD
93
int 0x21
95
int 0x21
94
 
96
 
95
; wait for keypress
97
; wait for keypress
96
mov ah, 0x08
98
mov ah, 0x08
97
int 0x21
99
int 0x21
98
 
100
 
99
; back to program start
101
; back to program start
100
jmp skipsig
102
jmp skipsig
101
 
103
 
102
; command.com tail arguments, in PSP format (length byte followed by arg)
104
; command.com tail arguments, in PSP format (length byte followed by arg)
103
CMDTAIL db 0
105
CMDTAIL db 0
104
 
106
 
105
; ExecParamRec used by INT 21h, AX=4b00 (load and execute program), 14 bytes:
107
; ExecParamRec used by INT 21h, AX=4b00 (load and execute program), 14 bytes:
106
;  offset  size  content
108
;  offset  size  content
107
;     +0     2   segment of environment for child (0 = current)
109
;     +0     2   segment of environment for child (0 = current)
108
;     +2     4   address of command line to place at PSP:0080
110
;     +2     4   address of command line to place at PSP:0080
109
;     +6     4   address of an FCB to be placed at PSP:005c
111
;     +6     4   address of an FCB to be placed at PSP:005c
110
;    +0Ah    4   address of an FCB to be placed at PSP:006c
112
;    +0Ah    4   address of an FCB to be placed at PSP:006c
111
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
113
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
112
 
114
 
113
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
115
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
114
 
116
 
115
; DOS int 21h functions that I use require at least 32 bytes of stack, here I
117
; DOS int 21h functions that I use require at least 32 bytes of stack, here I
116
; allocate 64 bytes to be sure
118
; allocate 64 bytes to be sure
117
STACKBUF db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
119
STACKBUF db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
118
STACKPTR db "xx"
120
STACKPTR db "xx"
119
 
121