Subversion Repositories SvarDOS

Rev

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

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