Advertisement
Guest User

Untitled

a guest
Aug 19th, 2009
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.39 KB | None | 0 0
  1.  
  2.  
  3.  
  4. name "NEMUS Kernel"
  5. #make_bin#
  6.  
  7. ; where to load? (for emulator. all these values are saved into .binf file)
  8. #load_segment=0800#
  9. #load_offset=0000#
  10.  
  11. ; these values are set to registers on load, actually only ds, es, cs, ip, ss, sp are
  12. ; important. these values are used for the emulator to emulate real microprocessor state
  13. ; after micro-os_loader transfers control to this kernel (as expected).
  14. #al=0b#
  15. #ah=00#
  16. #bh=00#
  17. #bl=00#
  18. #ch=00#
  19. #cl=02#
  20. #dh=00#
  21. #dl=00#
  22. #ds=0800#
  23. #es=0800#
  24. #si=7c02#
  25. #di=0000#
  26. #bp=0000#
  27. #cs=0800#
  28. #ip=0000#
  29. #ss=07c0#
  30. #sp=03fe#
  31.  
  32.  
  33.  
  34. ; this macro prints a char in al and advances
  35. ; the current cursor position:
  36. putc macro char
  37. push ax
  38. mov al, char
  39. mov ah, 0eh
  40. int 10h
  41. pop ax
  42. endm
  43.  
  44.  
  45. ; sets current cursor position:
  46. gotoxy macro col, row
  47. push ax
  48. push bx
  49. push dx
  50. mov ah, 02h
  51. mov dh, row
  52. mov dl, col
  53. mov bh, 0
  54. int 10h
  55. pop dx
  56. pop bx
  57. pop ax
  58. endm
  59.  
  60.  
  61. print macro x, y, attrib, sdat
  62. LOCAL s_dcl, skip_dcl, s_dcl_end
  63. pusha
  64. mov dx, cs
  65. mov es, dx
  66. mov ah, 13h
  67. mov al, 1
  68. mov bh, 0
  69. mov bl, attrib
  70. mov cx, offset s_dcl_end - offset s_dcl
  71. mov dl, x
  72. mov dh, y
  73. mov bp, offset s_dcl
  74. int 10h
  75. popa
  76. jmp skip_dcl
  77. s_dcl DB sdat
  78. s_dcl_end DB 0
  79. skip_dcl:
  80. endm
  81.  
  82.  
  83.  
  84. ; kernel is loaded at 0800:0000 by micro-os_loader
  85. org 0000h
  86.  
  87. ; skip the data and function delaration section:
  88. jmp start ; first byte of this jump instruction is 0E9h it is
  89. ; used by loader to determine if we had a sucessful launch.
  90.  
  91.  
  92.  
  93. ;==== data section =====================
  94.  
  95. ; welcome message:
  96. msg db 'Welcome to Smartsoft Nemus [Version 1.0]', 0Dh,0Ah
  97. db 'Please be patient while Nemus Loads the command line interface', 0Dh,0Ah
  98. db '------------------------------------------------------------------------------|', 0Dh,0Ah
  99.  
  100. cmd_size equ 10 ; size of command_buffer
  101. command_buffer db cmd_size dup(' ')
  102. clean_str db cmd_size dup(' '), 0
  103. prompt db 'NEMUS COMMAND >', 0
  104.  
  105. ; commands:
  106. chelp db 'help', 0
  107. chelp_tail:
  108. ccls db 'cls', 0
  109. ccls_tail:
  110. cquit db 'quit', 0
  111. cquit_tail:
  112. cexit db 'exit', 0
  113. cexit_tail:
  114. creboot db 'reboot', 0
  115. creboot_tail:
  116.  
  117. help_msg db 'Smartsoft Nemus Help', 0Dh,0Ah
  118. db '-----------------------------------------', 0Dh,0Ah
  119. db 'help - Help Screen', 0Dh,0Ah
  120. db 'cls - Clear the screen', 0Dh,0Ah
  121. db 'reboot - Does reboot your computer', 0Dh,0Ah
  122. db 'quit - Same as Reboot', 0Dh,0Ah
  123. db 'exit - Same as quit', 0Dh,0Ah
  124. db '-----------------------------------------', 0Dh,0Ah, 0
  125.  
  126. unknown db 'Unknow Command, please try again..' , 0
  127.  
  128. ;======================================
  129.  
  130. start:
  131.  
  132. ; set data segment:
  133. push cs
  134. pop ds
  135.  
  136. ; set default video mode 80x25:
  137. mov ah, 00h
  138. mov al, 03h
  139. int 10h
  140.  
  141. ; blinking disabled for compatibility with dos/bios,
  142. ; emulator and windows prompt never blink.
  143. mov ax, 1003h
  144. mov bx, 0 ; disable blinking.
  145. int 10h
  146.  
  147.  
  148. ; clear screen:
  149. call clear_screen
  150.  
  151. ; print out the message:
  152. lea si, msg
  153. call print_string
  154.  
  155.  
  156. eternal_loop:
  157. call get_command
  158.  
  159. call process_cmd
  160.  
  161. ; make eternal loop:
  162. jmp eternal_loop
  163.  
  164.  
  165. ;===========================================
  166. get_command proc near
  167.  
  168. ; set cursor position to bottom
  169. ; of the screen:
  170. mov ax, 40h
  171. mov es, ax
  172. mov al, es:[84h]
  173.  
  174. gotoxy 0, al
  175.  
  176. ; clear command line:
  177. lea si, clean_str
  178. call print_string
  179.  
  180. gotoxy 0, al
  181.  
  182. ; show prompt:
  183. lea si, prompt
  184. call print_string
  185.  
  186.  
  187. ; wait for a command:
  188. mov dx, cmd_size ; buffer size.
  189. lea di, command_buffer
  190. call get_string
  191.  
  192.  
  193. ret
  194. get_command endp
  195. ;===========================================
  196.  
  197. process_cmd proc near
  198.  
  199. ;//// check commands here ///
  200. ; set es to ds
  201. push ds
  202. pop es
  203.  
  204. cld ; forward compare.
  205.  
  206. ; compare command buffer with 'help'
  207. lea si, command_buffer
  208. mov cx, chelp_tail - offset chelp ; size of ['help',0] string.
  209. lea di, chelp
  210. repe cmpsb
  211. je help_command
  212.  
  213. ; compare command buffer with 'cls'
  214. lea si, command_buffer
  215. mov cx, ccls_tail - offset ccls ; size of ['cls',0] string.
  216. lea di, ccls
  217. repe cmpsb
  218. jne not_cls
  219. jmp cls_command
  220. not_cls:
  221.  
  222. ; compare command buffer with 'quit'
  223. lea si, command_buffer
  224. mov cx, cquit_tail - offset cquit ; size of ['quit',0] string.
  225. lea di, cquit
  226. repe cmpsb
  227. je reboot_command
  228.  
  229. ; compare command buffer with 'exit'
  230. lea si, command_buffer
  231. mov cx, cexit_tail - offset cexit ; size of ['exit',0] string.
  232. lea di, cexit
  233. repe cmpsb
  234. je reboot_command
  235.  
  236. ; compare command buffer with 'reboot'
  237. lea si, command_buffer
  238. mov cx, creboot_tail - offset creboot ; size of ['reboot',0] string.
  239. lea di, creboot
  240. repe cmpsb
  241. je reboot_command
  242.  
  243. ;////////////////////////////
  244.  
  245. ; if gets here, then command is
  246. ; unknown...
  247.  
  248. mov al, 1
  249. call scroll_t_area
  250.  
  251. ; set cursor position just
  252. ; above prompt line:
  253. mov ax, 40h
  254. mov es, ax
  255. mov al, es:[84h]
  256. dec al
  257. gotoxy 0, al
  258.  
  259. lea si, unknown
  260. call print_string
  261.  
  262. lea si, command_buffer
  263. call print_string
  264.  
  265. mov al, 1
  266. call scroll_t_area
  267.  
  268. jmp processed
  269.  
  270. ; +++++ 'help' command ++++++
  271. help_command:
  272.  
  273. ; scroll text area 9 lines up:
  274. mov al, 9
  275. call scroll_t_area
  276.  
  277. ; set cursor position 9 lines
  278. ; above prompt line:
  279. mov ax, 40h
  280. mov es, ax
  281. mov al, es:[84h]
  282. sub al, 9
  283. gotoxy 0, al
  284.  
  285. lea si, help_msg
  286. call print_string
  287.  
  288. mov al, 1
  289. call scroll_t_area
  290.  
  291. jmp processed
  292.  
  293.  
  294.  
  295.  
  296. ; +++++ 'cls' command ++++++
  297. cls_command:
  298. call clear_screen
  299. jmp processed
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307. ; +++ 'quit', 'exit', 'reboot' +++
  308. reboot_command:
  309. call clear_screen
  310. print 5,2,0011_1111b," Please eject any floppy disks "
  311. print 5,3,0011_1111b," And press any key to reboot... "
  312. mov ax, 0 ; wait for any key....
  313. int 16h
  314.  
  315. ; store magic value at 0040h:0072h:
  316. ; 0000h - cold boot.
  317. ; 1234h - warm boot.
  318. mov ax, 0040h
  319. mov ds, ax
  320. mov w.[0072h], 0000h ; cold boot.
  321.  
  322. jmp 0ffffh:0000h ; reboot!
  323.  
  324. ; ++++++++++++++++++++++++++
  325.  
  326. processed:
  327. ret
  328. process_cmd endp
  329.  
  330. ;===========================================
  331.  
  332. ; scroll all screen except last row
  333. ; up by value specified in al
  334.  
  335. scroll_t_area proc near
  336.  
  337. mov dx, 40h
  338. mov es, dx ; for getting screen parameters.
  339. mov ah, 06h ; scroll up function id.
  340. mov bh, 07 ; attribute for new lines.
  341. mov ch, 0 ; upper row.
  342. mov cl, 0 ; upper col.
  343. mov di, 84h ; rows on screen -1,
  344. mov dh, es:[di] ; lower row (byte).
  345. dec dh ; don't scroll bottom line.
  346. mov di, 4ah ; columns on screen,
  347. mov dl, es:[di]
  348. dec dl ; lower col.
  349. int 10h
  350.  
  351. ret
  352. scroll_t_area endp
  353.  
  354. ;===========================================
  355.  
  356.  
  357.  
  358.  
  359. ; get characters from keyboard and write a null terminated string
  360. ; to buffer at DS:DI, maximum buffer size is in DX.
  361. ; 'enter' stops the input.
  362. get_string proc near
  363. push ax
  364. push cx
  365. push di
  366. push dx
  367.  
  368. mov cx, 0 ; char counter.
  369.  
  370. cmp dx, 1 ; buffer too small?
  371. jbe empty_buffer ;
  372.  
  373. dec dx ; reserve space for last zero.
  374.  
  375.  
  376. ;============================
  377. ; eternal loop to get
  378. ; and processes key presses:
  379.  
  380. wait_for_key:
  381.  
  382. mov ah, 0 ; get pressed key.
  383. int 16h
  384.  
  385. cmp al, 0Dh ; 'return' pressed?
  386. jz exit
  387.  
  388.  
  389. cmp al, 8 ; 'backspace' pressed?
  390. jne add_to_buffer
  391. jcxz wait_for_key ; nothing to remove!
  392. dec cx
  393. dec di
  394. putc 8 ; backspace.
  395. putc ' ' ; clear position.
  396. putc 8 ; backspace again.
  397. jmp wait_for_key
  398.  
  399. add_to_buffer:
  400.  
  401. cmp cx, dx ; buffer is full?
  402. jae wait_for_key ; if so wait for 'backspace' or 'return'...
  403.  
  404. mov [di], al
  405. inc di
  406. inc cx
  407.  
  408. ; print the key:
  409. mov ah, 0eh
  410. int 10h
  411.  
  412. jmp wait_for_key
  413. ;============================
  414.  
  415. exit:
  416.  
  417. ; terminate by null:
  418. mov [di], 0
  419.  
  420. empty_buffer:
  421.  
  422. pop dx
  423. pop di
  424. pop cx
  425. pop ax
  426. ret
  427. get_string endp
  428.  
  429.  
  430.  
  431.  
  432. ; print a null terminated string at current cursor position,
  433. ; string address: ds:si
  434. print_string proc near
  435. push ax ; store registers...
  436. push si ;
  437.  
  438. next_char:
  439. mov al, [si]
  440. cmp al, 0
  441. jz printed
  442. inc si
  443. mov ah, 0eh ; teletype function.
  444. int 10h
  445. jmp next_char
  446. printed:
  447.  
  448. pop si ; re-store registers...
  449. pop ax ;
  450.  
  451. ret
  452. print_string endp
  453.  
  454.  
  455.  
  456. ; clear the screen by scrolling entire screen window,
  457. ; and set cursor position on top.
  458. ; default attribute is set to white on blue.
  459. clear_screen proc near
  460. push ax ; store registers...
  461. push ds ;
  462. push bx ;
  463. push cx ;
  464. push di ;
  465.  
  466. mov ax, 40h
  467. mov ds, ax ; for getting screen parameters.
  468. mov ah, 06h ; scroll up function id.
  469. mov al, 0 ; scroll all lines!
  470. mov bh, 1001_1111b ; attribute for new lines.
  471. mov ch, 0 ; upper row.
  472. mov cl, 0 ; upper col.
  473. mov di, 84h ; rows on screen -1,
  474. mov dh, [di] ; lower row (byte).
  475. mov di, 4ah ; columns on screen,
  476. mov dl, [di]
  477. dec dl ; lower col.
  478. int 10h
  479.  
  480. ; set cursor position to top
  481. ; of the screen:
  482. mov bh, 0 ; current page.
  483. mov dl, 0 ; col.
  484. mov dh, 0 ; row.
  485. mov ah, 02
  486. int 10h
  487.  
  488. pop di ; re-store registers...
  489. pop cx ;
  490. pop bx ;
  491. pop ds ;
  492. pop ax ;
  493.  
  494. ret
  495. clear_screen endp
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504. ; - Other Assembler Source Codes -
  505.  
  506.  
  507.  
  508.  
  509. ; - asm2html by emu8086 -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement