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

wirehaze git hosting

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