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

wirehaze git hosting

Update shell.asm
[BOS.git] / kernel / shell / commands.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2003-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Command table and some commands for the shell. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9 ; I should really do something about this file, divide it into
10 ; smaller ones or something. I'm just too lazy. Next version..
11
12
13 commands:
14 db 'ver', 0
15 db 'help', 0
16 db '?', 0
17 db 'about', 0
18 db 'cls', 0
19 db 'clrscr', 0
20 db 'reboot', 0
21 db 'regdump', 0
22 db 'time', 0
23 db 'date', 0
24 db 'delay', 0
25 db 'vgatest', 0
26 db 'memtest', 0
27 db 'fddtest', 0
28 db 0xFF ; end of command table
29
30
31 call_table:
32 dd show_ver ; commands.inc
33 dd show_help ; commands.inc
34 dd show_help ; commands.inc
35 dd show_about ; commands.inc
36 dd clrscr ; commands.inc
37 dd clrscr ; comamnds.inc
38 dd reboot ; commands.inc
39 dd dump_regs ; debug.inc
40 dd print_time ; time_date.inc
41 dd print_date ; time_date.inc
42 dd delay_test ; commands.inc
43 dd vga_test ; commands.inc
44 dd mem_test ; commands.inc
45 dd fdd_test ; commands.inc
46
47
48
49 ;--------------------------;
50 ; not a valid command ;
51 ;--------------------------;
52 not_a_valid_cmd db 13,10,'No such command or program exists.', 0
53
54 no_such_cmd:
55 push esi
56 push bx
57
58 mov esi, not_a_valid_cmd
59 mov bl, 0x04
60 call print
61
62 pop bx
63 pop esi
64 ret
65
66
67 ;-------------------;
68 ; show version ;
69 ;-------------------;
70 bos_ver_str db 13,10,'BOS version 0.05 by Christoffer Bubach, 2003-2005.', 0
71 show_ver:
72 push esi
73 push bx
74
75 mov esi, bos_ver_str
76 mov bl, 0x07
77 call print
78
79 pop bx
80 pop esi
81 ret
82
83
84 ;--------------------;
85 ; show BOS help ;
86 ;--------------------;
87 bos_help_str db 13,10,13,10,' BOS 0.04 by Christoffer Bubach, 2003-2005.',13,10,\
88 '--------------------------------------------',13,10,\
89 'Type a command and press ENTER to execute it.',13,10,13,10,\
90 '"help" or "?" - Displays this text.',13,10,\
91 '"ver" - Shows version information.',13,10,\
92 '"about" - Shows information about the OS.',13,10,\
93 '"cls" or "clrscr" - Clears the screen.',13,10,\
94 '"memtest" - Shows memory info (and allocates/frees some, to test).',13,10,\
95 '"vgatest" - Test some VGA stuff.',13,10,\
96 '"fddtest" - Read and print bootsector from A:',13,10,\
97 '"delay" - Tests the delay function for 5 s.',13,10,\
98 '"time" - Prints current time.',13,10,\
99 '"date" - Prints current date.',13,10,\
100 '"regdump" - Dump some standard registers.',13,10,\
101 '"reboot" - Restarts the computer.',0
102 show_help:
103 push esi
104 push bx
105
106 mov esi, bos_help_str
107 mov bl, 0x07
108 call print
109
110 pop bx
111 pop esi
112 ret
113
114
115 ;-----------------;
116 ; show about ;
117 ;-----------------;
118 bos_about_str db 13,10,'About BOS',13,10,\
119 'Hmm.. I started with OS-dev in late 2003.. Anyway..',13,10,13,10,\
120 'Thanks for helping me get this far goes to:',13,10,\
121 'all people at mega-tokyo.com, osdever.net and flatassembler.net',13,10,\
122 'Robert ',153,'stling for Primula, http://ostling.no-ip.com/',13,10,\
123 'J.Thim for EelOS, http://www.ludd.luth.se/~ivileel/',13,10,\
124 'Tomasz Grysztar for fasm and fasmw, http://flatassembler.net/',13,10,\
125 'ASHLEY4, Candy, John S. Fine and Petroff Heroj.',0
126 show_about:
127 push esi
128 push bx
129
130 mov esi, bos_about_str
131 mov bl, 0x07
132 call print
133
134 pop bx
135 pop esi
136 ret
137
138
139 ;-----------------------;
140 ; clear the screen ;
141 ;-----------------------;
142 clrscr:
143 call cls ; text.inc
144 mov esi, prompt
145 mov bl, 0x0E
146 call print
147 mov edi, cmd_buffer
148 jmp shell ; no normal return, as it gives an extra line feed
149
150
151
152 ;-------------;
153 ; reboot ;
154 ;-------------;
155 reboot:
156 call kbd_wait
157 mov al, 0xFE
158 out 0x64, al
159 jmp $
160 ret
161
162
163 ;-----------------;
164 ; delay test ;
165 ;-----------------;
166 bos_delay_str db 13,10,'~1 second has passed.', 0
167 delay_test:
168 mov ecx, 5
169 .loop:
170 push ecx
171 mov ecx, 100
172 call delay
173 pop ecx
174 mov esi, bos_delay_str
175 mov bl, 0x07
176 call print
177 loop .loop
178 ret
179
180
181 ;----------------;
182 ; VGA test ;
183 ;----------------;
184 bos_vga_str db 13,10,'It works..! :-D', 0
185 vga_test:
186
187 mov ax, 1 ; clear the screen
188 call set_mode_0x13 ; set mode 0x13
189
190 mov cx, 256 ; loop out some pixels
191 .l1:
192 mov bx, cx ; x value
193 mov al, cl
194 push cx
195 mov cx, 50 ; y value
196 call put_0x13_pixel
197 pop cx
198 loop .l1
199
200 ; draw mario and some ground
201 mov esi, mario
202 mov ax, 260 ; x
203 mov bx, 168 ; y
204 mov cx, 20 ; height
205 mov dx, 18 ; width
206 call put_0x13_sprite ; in vga.inc
207 mov esi, grass_l
208 mov ax, 250
209 mov bx, 186
210 mov cx, 20
211 mov dx, 14
212 call put_0x13_sprite
213 mov esi, grass_f
214 mov ax, 265
215 mov bx, 186
216 mov cx, 20
217 mov dx, 14
218 call put_0x13_sprite
219 mov esi, grass_ul
220 mov ax, 280
221 mov bx, 186
222 mov cx, 20
223 mov dx, 14
224 call put_0x13_sprite
225 mov esi, g_lefts
226 mov ax, 280
227 mov bx, 172
228 mov cx, 20
229 mov dx, 14
230 call put_0x13_sprite
231 mov esi, grass_l
232 mov ax, 280
233 mov bx, 158
234 mov cx, 20
235 mov dx, 14
236 call put_0x13_sprite
237 mov esi, g_earth
238 mov ax, 300
239 mov bx, 186
240 mov cx, 20
241 mov dx, 14
242 call put_0x13_sprite
243 mov esi, g_earth
244 mov ax, 300
245 mov bx, 172
246 mov cx, 20
247 mov dx, 14
248 call put_0x13_sprite
249 mov esi, grass_f
250 mov ax, 300
251 mov bx, 158
252 mov cx, 20
253 mov dx, 14
254 call put_0x13_sprite
255
256 call wait_key
257
258 mov ax, 1 ; clear the screen
259 call set_mode_0x03 ; set mode 0x03
260
261 mov esi, bos_vga_str ; print that it worked!
262 mov bl, 1
263 call print
264 ret
265
266
267
268
269 ;--------------------------;
270 ; fdd test ;
271 ;--------------------------;
272 fdd_test:
273 mov bl, 13
274 mov bh, 7 ; make newline
275 call print_char
276
277 mov ecx, 512
278 mov edi, 0x80000
279 .loop511:
280 mov dword [edi], 'shit' ; set DMA buffer to shit, as a test
281 add edi, 4
282 sub ecx, 4
283 cmp ecx, 0
284 jne .loop511
285
286 mov dh, 0x00 ; side
287 mov dl, 0x00 ; drive
288 mov ch, 0x00 ; track
289 mov cl, 0x01 ; sector
290 mov bl, 0x00 ; 1 = write
291 call fdd_read_write
292 jc .error
293
294 mov esi, 0x80000 ; dma buffer
295 mov ecx, 512
296 .print:
297 lodsb
298 mov bl, al
299 mov bh, 7
300 call print_char ; print it. is it still
301 dec ecx ; "shit" ?
302 cmp ecx, 0
303 jne .print
304 jmp .end
305
306 .error:
307 mov bl, 13
308 call print_char
309 mov bl, 10
310 call print_char
311 mov bh, 0x40
312 mov bl, 'E' ; error sign... :'(
313 call print_char
314
315 call fdd_reset
316 mov al, 1
317 call fdd_recal_seek ; do somthing about the error.. :P
318
319 .end:
320 ret
321
322
323
324
325
326 ;------------------------------;
327 ; memory test ;
328 ;------------------------------;
329
330 bos_mem_str1 db 13,10,'Performing memory test. (debugging allocs assume 32mb RAM)', 0
331 bos_mem_str2 db 13,10,'Total installed memory (in bytes): ',0
332 bos_mem_str3 db 13,10,13,10,'Memory chunks:',0
333 bos_mem_str4 db 13,10,'Address Size Type Previous Next',0
334 bos_mem_str5 db 13,10,'-------------------------------------------------------',0
335 bos_mem_str6 db '0x',0
336 bos_mem_str7 db 'Free ',0
337 bos_mem_str8 db 'Used ',0
338 bos_mem_str9 db 'None ',0
339 bos_mem_str0 db ' ',0
340 bos_mem_crlf db 13,10,0
341 current_mem_pos dd 0
342 next_free dd 0
343
344 ;---------DEBUG---------
345 test1_or_2 db 1
346 test_address dd 0
347 test_size dd 0
348 test_address2 dd 0
349 test_size2 dd 0
350 ;---------END DEBUG---------
351
352 mem_test:
353 push eax
354 push ebx
355 push ecx
356 push edx
357
358 ;---------DEBUG---------
359 cmp [test1_or_2],0
360 je .free_the_test_block
361
362 mov ebx, 0x1000000 ;first test
363 mov [test_size2], ebx
364 call allocate_mem
365 mov [test_address2], ebx
366
367 mov ebx, 0xE00000 ; second test
368 mov ecx, ebx
369 call allocate_mem
370 push ebx
371 push ecx
372
373 mov ebx, 0x10000 ; third test
374 mov [test_size], ebx
375 call allocate_mem
376 mov [test_address], ebx ; test allocation
377
378 pop ecx
379 pop ebx
380 call free_mem
381
382 mov [test1_or_2], 0
383 jmp .end_test
384 .free_the_test_block:
385 mov ebx, [test_address]
386 mov ecx, [test_size] ; and freeing
387 call free_mem
388 mov ebx, [test_address2]
389 mov ecx, [test_size2] ; and freeing
390 call free_mem
391 mov [test1_or_2], 1
392 .end_test:
393 ;---------END DEBUG---------
394
395 mov esi, bos_mem_str1
396 mov bl, 0x07
397 call print
398 mov esi, bos_mem_str2
399 mov bl, 0x07
400 call print
401 mov esi, bos_mem_str6
402 mov bl, 0x04
403 call print
404 mov ebx, [ram_amount]
405 mov cl, 0x04
406 call print_hex32
407
408 mov esi, bos_mem_str3
409 mov bl, 0x07
410 call print
411 mov esi, bos_mem_str4
412 mov bl, 0x07
413 call print
414 mov esi, bos_mem_str5
415 mov bl, 0x07
416 call print
417
418 mov [current_mem_pos], 0
419 mov eax, [first_free]
420 mov [next_free], eax
421
422 ;-------------------------;
423 ; this is a used block ;
424 ;-------------------------;
425 .used:
426 mov eax, [current_mem_pos]
427 mov ebx, [next_free]
428 cmp eax, [ram_amount] ; .free will always let us
429 jae .end ; decide if we are to quit or not.
430
431 cmp [next_free], 0
432 jne .more_blocks
433 mov ebx, [ram_amount] ; no next block, use ram size
434 sub ebx, eax ; get size in ebx
435 mov edi, 1
436 call .print_mem_info
437 jmp .end
438
439 .more_blocks:
440 sub ebx, eax
441 mov edi, 1
442 call .print_mem_info
443
444 mov eax, [next_free]
445 cmp eax, 0
446 je .end
447 mov ebx, [eax+8]
448 mov [current_mem_pos], eax
449 mov [next_free], ebx
450
451 ;-------------------------;
452 ; this is a free block ;
453 ;-------------------------;
454 .free:
455 mov eax, [current_mem_pos] ; current pos. in eax
456 mov ebx, [eax+4] ; current size in ebx
457 mov ecx, [eax] ; prev pointer in ecx
458 mov edx, [eax+8] ; next pointer in edx
459 xor edi, edi
460 call .print_mem_info
461
462 add eax, ebx
463 mov [current_mem_pos], eax
464 jmp .used
465
466 .end:
467 pop eax
468 pop ebx
469 pop ecx
470 pop edx
471 ret
472
473 ;-------------------------;
474 ; print mem block info ;
475 ;-------------------------;
476 .print_mem_info:
477 push eax ; current pos
478 push ebx ; current size
479 push ecx ; prev pointer
480 push edx ; next pointer
481 push edi ; 1 = used
482
483 push ebx ; push size
484 mov esi, bos_mem_crlf
485 mov bl, 0x07
486 call print
487 mov esi, bos_mem_str6
488 mov bl, 0x04
489 call print
490
491 push ecx ; push prev
492 mov ebx, eax
493 mov cl, 0x04
494 call print_hex32
495
496 mov esi, bos_mem_str0
497 mov bl, 0x07
498 call print
499 mov esi, bos_mem_str6
500 mov bl, 0x04
501 call print
502
503 pop ecx ; pop prev
504 pop ebx ; pop size
505 push ecx ; push prev
506 mov cl, 0x04
507 call print_hex32
508 mov esi, bos_mem_str0
509 mov bl, 0x07
510 call print
511
512 cmp edi, 1
513 jne .print_free
514 pop ecx ; pop prev
515
516 mov esi, bos_mem_str8 ; it's used
517 mov bl, 0x07
518 call print
519 mov esi, bos_mem_str9
520 mov bl, 0x07
521 call print
522 mov esi, bos_mem_str9
523 mov bl, 0x07
524 call print
525 jmp .print_end
526
527 .print_free:
528 mov esi, bos_mem_str7 ; it's free
529 mov bl, 0x07
530 call print
531 mov esi, bos_mem_str6
532 mov bl, 0x04
533 call print
534
535 pop ebx ; pop the pushed ecx
536 mov cl, 0x04 ; into ebx instead.. ;)
537 call print_hex32
538 mov esi, bos_mem_str0
539 mov bl, 0x07
540 call print
541 mov esi, bos_mem_str6
542 mov bl, 0x04
543 call print
544 mov ebx, edx
545 mov cl, 0x04
546 call print_hex32
547
548 .print_end:
549 pop edi
550 pop edx
551 pop ecx
552 pop ebx
553 pop eax
554 ret