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

wirehaze git hosting

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