]> wirehaze git hosting - BOS.git/blob - kernel/shell/shell.asm

wirehaze git hosting

ea157aeb2c747da65c86d5b17d08485d755e8e16
[BOS.git] / kernel / shell / shell.asm
1 ;----------------------------------------------------------;
2 ; BOS 0.04 Christoffer Bubach, 2004-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Basic shell. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9
10 ;--------------;
11 ; Variabels ;
12 ;--------------;
13
14 prompt db 'BOS kernel>', 0
15 cmd_buffer: times 255 db 0 ; 255 char command buffer
16
17
18
19 ;----------------------------------------------;
20 ; print the prompt for the first time.. :-) ;
21 ;----------------------------------------------;
22 init_cmd:
23 mov byte [kbd_status], 0 ; reset LEDs to 0..
24 call update_leds
25
26 mov esi, prompt
27 mov bl, 0x0E
28 call print
29
30 mov edi, cmd_buffer
31 ret
32
33
34
35 ;-------------------------------;
36 ; Main shell function & loop ;
37 ;-------------------------------;
38 shell:
39 mov cx, 0 ; max 254 chars in command
40 .loop: ; no. 255 is always a 0
41
42 push cx ; better be sure it´s safe..
43 push edi
44
45 call getc ; keyboard.inc
46
47 pop edi
48 pop cx
49
50 cmp ah, 28 ; enter
51 je .enter
52
53 cmp ah, 14 ; backspace
54 je .backspace
55
56 cmp al, 0 ; no normal key
57 je .loop ; exceptions above..
58
59 cmp cx, 254
60 jae .loop
61
62 stosb ; store char in buffer
63 inc cx
64
65 mov bl, al ; print it..
66 mov bh, 0x07
67 call print_char
68
69 jmp .loop
70
71 .enter:
72 mov al, 0 ; the command buffer is
73 stosb ; in ASCIIZ format..
74 jmp chk_cmd
75
76 .backspace:
77 cmp cx, 0 ; can´t delete the prompt.. ;-)
78 je .loop
79 dec edi ; "remove" one char from buffer
80 call backspace ; do backspace on screen
81 dec cx ; decrease buffer counter
82 jmp .loop
83 jmp $
84 ret
85
86
87
88 ;---------------------------------;
89 ; check for valid cmd ;
90 ;---------------------------------;
91 chk_cmd:
92
93 mov esi, commands
94 mov edi, cmd_buffer
95 mov ebp, 0 ; command-table counter
96
97 ;------------------------------------------;
98 ; big loop, for each command in table ;
99 ;------------------------------------------;
100 .l1:
101 mov ecx, 0 ; char counter
102
103 cmp byte [esi], 0xFF
104 je .no_valid_cmd
105
106 ;------------------------------------------;
107 ; smaller loop for each char in command ;
108 ;------------------------------------------;
109 .l2:
110 cmp byte [edi], ' ' ; space or zero
111 je .l_chk ; both indicate
112 cmp byte [edi], 0 ; "end of command"
113 je .l_chk
114 jmp .l_cont
115
116 .l_chk:
117 cmp byte [esi], 0 ; commands are equal, but
118 jne .new_cmd ; do not match in size..
119 jmp .done
120
121 .l_cont:
122 cmp byte [esi], 0 ; commands are equal, but
123 je .new_cmd ; do not match in size..
124
125 mov al, [esi]
126 cmp al, [edi]
127 jne .new_cmd
128
129 inc esi
130 inc edi
131 inc ecx ; inc char counter
132 jmp .l2
133 ;----------------------;
134 ; end of small loop ;
135 ;----------------------;
136
137 .new_cmd:
138 inc ebp ; inc command counter
139 mov edi, cmd_buffer ; remember to point to the right place.. ;-)
140 .l3:
141 inc esi
142 cmp byte [esi], 0 ; loop until end of command
143 jne .l3
144
145 inc esi
146 jmp .l1
147 ;----------------------;
148 ; end of big loop ;
149 ;----------------------;
150
151
152
153 ;--------------------------;
154 ; done. command found ;
155 ;--------------------------;
156 .done:
157 cmp ecx, 0 ; make sure it´s more
158 je .d_quit ; then 0 chars..
159
160 shl ebp, 2
161 call dword [ebp+call_table]
162
163 .d_quit:
164 jmp .cont ; then go back to the shell
165
166
167 ;--------------------------;
168 ; command not found ;
169 ;--------------------------;
170 .no_valid_cmd:
171
172 ; call search_current_directory_for_file.... :-)
173
174 call no_such_cmd ; print error..
175 jmp .cont ; then go back to the shell
176
177 ;---------------------------------;
178 ; make the prompt appear again ;
179 ;---------------------------------;
180 .cont:
181 call new_line
182 call new_line
183 mov esi, prompt
184 mov bl, 0x0E
185 call print
186 mov edi, cmd_buffer
187 jmp shell
188
189 ret