Subversion Repositories SvarDOS

Rev

Rev 450 | Rev 460 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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