How to put internal Shell Commands in NASM?

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

How to put internal Shell Commands in NASM?

 
0
  #1
Oct 14th, 2007
I have this kernel with the shell, and I'm trying to put the time and date commands in it but can't seem to make it work. It shows no error while compiling but it doesn't do anything when I test it. Can anyone tell me what I'm doing wrong here?

Here's the code so far:
  1. ;*****************start of the kernel code***************
  2. [org 0x000]
  3. [bits 16]
  4. [SEGMENT .text]
  5.  
  6. ;START #####################################################
  7. mov ax, 0x0100 ;location where kernel is loaded
  8. mov ds, ax
  9. mov es, ax
  10.  
  11. cli
  12. mov ss, ax ;stack segment
  13. mov sp, 0xFFFF ;stack pointer at 64k limit
  14. sti
  15.  
  16. push dx
  17. push es
  18. xor ax, ax
  19. mov es, ax
  20. cli
  21. mov word [es:0x21*4], _int0x21 ; setup interrupt service
  22. mov [es:0x21*4+2], cs
  23. sti
  24. pop es
  25. pop dx
  26.  
  27. mov si, strWelcomeMsg ; load message
  28. mov al, 0x01 ; request sub-service 0x01
  29. int 0x21
  30.  
  31. call _shell ; call the shell
  32.  
  33. int 0x19 ; reboot
  34. ;END #######################################################
  35.  
  36. _int0x21:
  37. _int0x21_ser0x01: ;service 0x01
  38. cmp al, 0x01 ;see if service 0x01 wanted
  39. jne _int0x21_end ;goto next check (now it is end)
  40.  
  41. _int0x21_ser0x01_start:
  42. lodsb ; load next character
  43. or al, al ; test for NUL character
  44. jz _int0x21_ser0x01_end
  45. mov ah, 0x0E ; BIOS teletype
  46. mov bh, 0x00 ; display page 0
  47. mov bl, 0x07 ; text attribute
  48. int 0x10 ; invoke BIOS
  49. jmp _int0x21_ser0x01_start
  50. _int0x21_ser0x01_end:
  51. jmp _int0x21_end
  52.  
  53. _int0x21_end:
  54. iret
  55.  
  56. _shell:
  57. _shell_begin:
  58. ;move to next line
  59. call _display_endl
  60. ;display prompt
  61. call _display_prompt
  62. ;get user command
  63. call _get_command
  64. ;split command into components
  65. call _split_cmd
  66. ;check command & perform action
  67. ; empty command
  68. _cmd_none:
  69. mov si, strCmd0
  70. cmp BYTE [si], 0x00
  71. jne _cmd_ver ;next command
  72. jmp _cmd_done
  73.  
  74. ; display version
  75. _cmd_ver:
  76. mov si, strCmd0
  77. mov di, cmdVer
  78. mov cx, 4
  79. repe cmpsb
  80. jne _cmd_cls ;next command
  81.  
  82. call _display_endl
  83. mov si, strOsName ;display version
  84. mov al, 0x01
  85. int 0x21
  86. call _display_space
  87. mov si, txtVersion ;display version
  88. mov al, 0x01
  89. int 0x21
  90. call _display_space
  91.  
  92. mov si, strMajorVer
  93. mov al, 0x01
  94. int 0x21
  95. mov si, strMinorVer
  96. mov al, 0x01
  97. int 0x21
  98. jmp _cmd_done
  99.  
  100. _cmd_cls:
  101. mov si, strCmd0
  102. mov di, cmdCls
  103. mov cx, 4
  104. repe cmpsb
  105. jne _cmd_date ;next command
  106.  
  107.  
  108. call _display_endl
  109. call _display_endl
  110. call _display_endl
  111. call _display_endl
  112. call _display_endl
  113. call _display_endl
  114. call _display_endl
  115. call _display_endl
  116. call _display_endl
  117. call _display_endl
  118. call _display_endl
  119. call _display_endl
  120. call _display_endl
  121. call _display_endl
  122. call _display_endl
  123. call _display_endl
  124. call _display_endl
  125. call _display_endl
  126. call _display_endl
  127. call _display_endl
  128. call _display_endl
  129. call _display_endl
  130. call _display_endl
  131. call _display_endl
  132. call _display_endl
  133.  
  134. mov bh, 0
  135. mov dl, 0
  136. mov dh, 00
  137. mov ah, 02
  138. int 10h
  139. jmp _cmd_done
  140.  
  141. _cmd_date:
  142. mov si, strCmd0
  143. mov di, cmdDate
  144. mov cx, 4
  145. repe cmpsb
  146. jne _cmd_time ;next command
  147.  
  148.  
  149. jmp overdata
  150.  
  151. overdata:
  152. mov ah,4
  153. int 1Ah
  154.  
  155. mov di,datestring
  156.  
  157. mov al,dh
  158. call byte2hex
  159. mov al,'-'
  160. stosb
  161. mov al,dl
  162. call byte2hex
  163. mov al,'-'
  164. stosb
  165. mov ax,cx
  166. call word2hex
  167. mov al,'$'
  168. stosb
  169.  
  170. mov dx,datestring ;just like "Hello World!"
  171. mov ah,9
  172. int 21h
  173. mov ah,4Ch
  174. int 21h
  175.  
  176. word2hex:
  177. mov bx,ax
  178. shr ax,12
  179. call nyb2hex
  180. mov ax,bx
  181. shr ax,8
  182. call nyb2hex
  183. mov ax,bx
  184. byte2hex:
  185. mov bx,ax
  186. shr ax,4
  187. call nyb2hex
  188. mov ax,bx
  189. nyb2hex:
  190. and al,0Fh
  191. cmp al,10
  192.  
  193. ;sbb al,105
  194. ;das
  195. jc okdigit
  196. add al,7
  197. okdigit:
  198. add al,30h
  199. ;int 029h
  200. stosb
  201. ret
  202.  
  203. jmp _cmd_done
  204.  
  205. _cmd_time:
  206. mov si, strCmd0
  207. mov di, cmdTime
  208. mov cx, 4
  209. repe cmpsb
  210. jne _cmd_hlp
  211.  
  212. jmp _WasteTime
  213.  
  214. global _WasteTime
  215.  
  216. _WasteTime:
  217. mov bx, sp
  218. mov bx, [ss:bx+02h]
  219.  
  220. push si
  221. push di
  222.  
  223. mov ah, 00h
  224. int 1Ah
  225.  
  226. mov di, cx
  227. mov si, dx
  228.  
  229. .Waster:
  230. mov ah, 00h
  231. int 1Ah
  232.  
  233. sub dx, si
  234. sbb cx, di
  235.  
  236. cmp cx, 0
  237. jne .EndOfProc
  238.  
  239. cmp dx, bx
  240. jb .Waster
  241.  
  242. .EndOfProc:
  243. pop di
  244. pop si
  245. ret
  246.  
  247.  
  248. jmp _cmd_done
  249.  
  250. _cmd_hlp:
  251. mov si, strCmd0
  252. mov di, cmdHlp
  253. mov cx, 4
  254. repe cmpsb
  255. jne _cmd_abt ;next command
  256.  
  257. call _display_endl
  258. mov si, strHelp ;display help
  259. mov al, 0x01
  260. int 0x21
  261. call _display_space
  262. mov si, txtHelp ;display help
  263. mov al, 0x01
  264. int 0x21
  265.  
  266. mov si, strCmdOne ;display command
  267. mov al, 0x01
  268. int 0x21
  269. mov si, strCmdTwo
  270. mov al, 0x01
  271. int 0x21
  272. mov si, strCmdThree
  273. mov al, 0x01
  274. int 0x21
  275. mov si, strCmdFour
  276. mov al, 0x01
  277. int 0x21
  278. mov si, strCmdFive
  279. mov al, 0x01
  280. int 0x21
  281. mov si, strCmdSix
  282. mov al, 0x01
  283. int 0x21
  284. jmp _cmd_done
  285.  
  286.  
  287. _cmd_abt:
  288. mov si, strCmd0
  289. mov di, cmdAbt
  290. mov cx, 4
  291. repe cmpsb
  292. jne _cmd_exit ;next command
  293.  
  294. call _display_endl
  295. mov si, txtAbout ;display about
  296. mov al, 0x01
  297. int 0x21
  298. call _display_space
  299. mov si, strAbout ;display about
  300. mov al, 0x01
  301. int 0x21
  302. call _display_space
  303.  
  304. mov si, strMajorAbt
  305. mov al, 0x01
  306. int 0x21
  307. mov si, strMinorAbt
  308. mov al, 0x01
  309. int 0x21
  310. jmp _cmd_done
  311.  
  312. ; exit shell
  313. _cmd_exit:
  314. mov si, strCmd0
  315. mov di, cmdExit
  316. mov cx, 5
  317. repe cmpsb
  318. jne _cmd_unknown ;next command
  319.  
  320. je _shell_end ;exit from shell
  321.  
  322.  
  323. _cmd_unknown:
  324. call _display_endl
  325. mov si, msgUnknownCmd ;unknown command
  326. mov al, 0x01
  327. int 0x21
  328.  
  329. _cmd_done:
  330. ;call _display_endl
  331. jmp _shell_begin
  332.  
  333. _shell_end:
  334. ret
  335.  
  336. _get_command:
  337. ;initiate count
  338. mov BYTE [cmdChrCnt], 0x00
  339. mov di, strUserCmd
  340.  
  341. _get_cmd_start:
  342. mov ah, 0x10 ;get character
  343. int 0x16
  344.  
  345. cmp al, 0x00 ;check if extended key
  346. je _extended_key
  347. cmp al, 0xE0 ;check if new extended key
  348. je _extended_key
  349.  
  350. cmp al, 0x08 ;check if backspace pressed
  351. je _backspace_key
  352.  
  353. cmp al, 0x0D ;check if Enter pressed
  354. je _enter_key
  355.  
  356. mov bh, [cmdMaxLen] ;check if maxlen reached
  357. mov bl, [cmdChrCnt]
  358. cmp bh, bl
  359. je _get_cmd_start
  360. ;add char to buffer, display it and start again
  361. mov [di], al ;add char to buffer
  362. inc di ;increment buffer pointer
  363. inc BYTE [cmdChrCnt] ;inc count
  364.  
  365. mov ah, 0x0E ;display character
  366. mov bl, 0x07
  367. int 0x10
  368. jmp _get_cmd_start
  369.  
  370. _extended_key: ;extended key - do nothing now
  371. jmp _get_cmd_start
  372.  
  373. _backspace_key:
  374. mov bh, 0x00 ;check if count = 0
  375. mov bl, [cmdChrCnt]
  376. cmp bh, bl
  377. je _get_cmd_start ;yes, do nothing
  378.  
  379. dec BYTE [cmdChrCnt] ;dec count
  380. dec di
  381. ;check if beginning of line
  382. mov ah, 0x03 ;read cursor position
  383. mov bh, 0x00
  384. int 0x10
  385.  
  386. cmp dl, 0x00
  387. jne _move_back
  388. dec dh
  389. mov dl, 79
  390. mov ah, 0x02
  391. int 0x10
  392.  
  393. mov ah, 0x09 ; display without moving cursor
  394. mov al, ' '
  395. mov bh, 0x00
  396. mov bl, 0x07
  397. mov cx, 1 ; times to display
  398. int 0x10
  399. jmp _get_cmd_start
  400.  
  401. _move_back:
  402. mov ah, 0x0E ; BIOS teletype acts on backspace!
  403. mov bh, 0x00
  404. mov bl, 0x07
  405. int 0x10
  406. mov ah, 0x09 ; display without moving cursor
  407. mov al, ' '
  408. mov bh, 0x00
  409. mov bl, 0x07
  410. mov cx, 1 ; times to display
  411. int 0x10
  412. jmp _get_cmd_start
  413.  
  414. _enter_key:
  415. mov BYTE [di], 0x00
  416. ret
  417.  
  418. _split_cmd:
  419. ;adjust si/di
  420. mov si, strUserCmd
  421. ;mov di, strCmd0
  422. ;move blanks
  423. _split_mb0_start:
  424. cmp BYTE [si], 0x20
  425. je _split_mb0_nb
  426. jmp _split_mb0_end
  427.  
  428. _split_mb0_nb:
  429. inc si
  430. jmp _split_mb0_start
  431.  
  432. _split_mb0_end:
  433. mov di, strCmd0
  434.  
  435. _split_1_start: ;get first string
  436. cmp BYTE [si], 0x20
  437. je _split_1_end
  438. cmp BYTE [si], 0x00
  439. je _split_1_end
  440. mov al, [si]
  441. mov [di], al
  442. inc si
  443. inc di
  444. jmp _split_1_start
  445.  
  446. _split_1_end:
  447. mov BYTE [di], 0x00
  448. ;move blanks
  449. _split_mb1_start:
  450. cmp BYTE [si], 0x20
  451. je _split_mb1_nb
  452. jmp _split_mb1_end
  453.  
  454. _split_mb1_nb:
  455. inc si
  456. jmp _split_mb1_start
  457.  
  458. _split_mb1_end:
  459. mov di, strCmd1
  460.  
  461. _split_2_start: ;get second string
  462. cmp BYTE [si], 0x20
  463. je _split_2_end
  464. cmp BYTE [si], 0x00
  465. je _split_2_end
  466. mov al, [si]
  467. mov [di], al
  468. inc si
  469. inc di
  470. jmp _split_2_start
  471.  
  472. _split_2_end:
  473. mov BYTE [di], 0x00
  474. ;move blanks
  475. _split_mb2_start:
  476. cmp BYTE [si], 0x20
  477. je _split_mb2_nb
  478. jmp _split_mb2_end
  479.  
  480. _split_mb2_nb:
  481. inc si
  482. jmp _split_mb2_start
  483.  
  484. _split_mb2_end:
  485. mov di, strCmd2
  486.  
  487. _split_3_start: ;get third string
  488. cmp BYTE [si], 0x20
  489. je _split_3_end
  490. cmp BYTE [si], 0x00
  491. je _split_3_end
  492. mov al, [si]
  493. mov [di], al
  494. inc si
  495. inc di
  496. jmp _split_3_start
  497.  
  498. _split_3_end:
  499. mov BYTE [di], 0x00
  500. ;move blanks
  501. _split_mb3_start:
  502. cmp BYTE [si], 0x20
  503. je _split_mb3_nb
  504. jmp _split_mb3_end
  505.  
  506. _split_mb3_nb:
  507. inc si
  508. jmp _split_mb3_start
  509.  
  510. _split_mb3_end:
  511. mov di, strCmd3
  512.  
  513.  
  514. _split_4_start: ;get fourth string
  515. cmp BYTE [si], 0x20
  516. je _split_4_end
  517. cmp BYTE [si], 0x00
  518. je _split_4_end
  519. mov al, [si]
  520. mov [di], al
  521. inc si
  522. inc di
  523. jmp _split_4_start
  524.  
  525. _split_4_end:
  526. mov BYTE [di], 0x00
  527. ;move blanks
  528. _split_mb4_start:
  529. cmp BYTE [si], 0x20
  530. je _split_mb4_nb
  531. jmp _split_mb4_end
  532.  
  533. _split_mb4_nb:
  534. inc si
  535. jmp _split_mb4_start
  536.  
  537. _split_mb4_end:
  538. mov di, strCmd4
  539.  
  540.  
  541. _split_5_start: ;get last string
  542. cmp BYTE [si], 0x20
  543. je _split_5_end
  544. cmp BYTE [si], 0x00
  545. je _split_5_end
  546. mov al, [si]
  547. mov [di], al
  548. inc si
  549. inc di
  550. jmp _split_5_start
  551.  
  552. _split_5_end:
  553. mov BYTE [di], 0x00
  554. ret
  555.  
  556. _display_space:
  557. mov ah, 0x0E ; BIOS teletype
  558. mov al, 0x20
  559. mov bh, 0x00 ; display page 0
  560. mov bl, 0x07 ; text attribute
  561. int 0x10 ; invoke BIOS
  562. ret
  563.  
  564. _display_endl:
  565. mov ah, 0x0E ; BIOS teletype acts on newline!
  566. mov al, 0x0D
  567. mov bh, 0x00
  568. mov bl, 0x07
  569. int 0x10
  570. mov ah, 0x0E ; BIOS teletype acts on linefeed!
  571. mov al, 0x0A
  572. mov bh, 0x00
  573. mov bl, 0x07
  574. int 0x10
  575. ret
  576.  
  577. _display_prompt:
  578. mov si, strPrompt
  579. mov al, 0x01
  580. int 0x21
  581. ret
  582.  
  583.  
  584.  
  585. [SEGMENT .data]
  586. strWelcomeMsg db "Welcome to GeoLiz NaviOS", 0x00
  587. strPrompt db "==>", 0x00
  588. cmdMaxLen db 255 ;maximum length of commands
  589.  
  590. strOsName db "GeoLiz", 0x00 ;OS details
  591. strMajorVer db "0", 0x00
  592. strMinorVer db ".7", 0x0D, 0x0A, 0x00
  593.  
  594. strHelp db "List of ", 0x00 ;Help
  595. strCmdOne db "ver-Get version ", 0x0D, 0x0A, 0x00
  596. strCmdTwo db "exit-Reboot ", 0x0D, 0x0A, 0x00
  597. strCmdThree db "date-Get date today ", 0x0D, 0x0A, 0x00
  598. strCmdFour db "time-Get time now ", 0x0D, 0x0A, 0x00
  599. strCmdFive db "help-list commands ", 0x0D, 0x0A, 0x00
  600. strCmdSix db "abt-about creator", 0x0D, 0x0A, 0x00
  601.  
  602. strAbout db "GeoLiz NaviOS", 0x0D, 0x0A, 0x00 ;about OS
  603. strMajorAbt db "Creators: Geo and Liz", 0x0D, 0x0A, 0x00
  604. strMinorAbt db " Created: Sept.20,2007", 0x0D, 0x0A, 0x00
  605.  
  606. cmdVer db "ver", 0x00 ; internal commands
  607. cmdExit db "exit", 0x00
  608. cmdDate db "date", 0x00
  609. cmdTime db "time", 0x00
  610. cmdHlp db "help", 0x00
  611. cmdAbt db "abt", 0x00
  612. cmdCls db "cls", 0x00
  613.  
  614.  
  615. datestring times 0Eh db 0
  616.  
  617. txtVersion db "Version", 0x00 ;messages and other strings
  618. txtHelp db "Commands:", 0x0D, 0x0A, 0x00
  619. txtAbout db "About", 0x0D, 0x0A, 0x00
  620. msgUnknownCmd db "Unknown command!", 0x00
  621.  
  622.  
  623. [SEGMENT .bss]
  624. strUserCmd resb 256 ;buffer for user commands
  625. cmdChrCnt resb 1 ;count of characters
  626. strCmd0 resb 256 ;buffers for the command components
  627. strCmd1 resb 256
  628. strCmd2 resb 256
  629. strCmd3 resb 256
  630. strCmd4 resb 256
  631.  
  632. ;********************end of the kernel code********************
Attached Files
File Type: txt boot.txt (10.8 KB, 1 views)
File Type: txt kernel.txt (14.0 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 130
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: How to put internal Shell Commands in NASM?

 
0
  #2
Oct 15th, 2007
You have several "int 0x21" calls in your code. These are DOS calls:

http://www.ctyme.com/intr/int-21.htm

Since DOS is not loaded (indeed, you are writing your own OS), then you cannot use these functions. You must restrict yourself to just the BIOS calls.

Nathan.
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 130
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: How to put internal Shell Commands in NASM?

 
0
  #3
Oct 15th, 2007
Here is some reading material:

http://del.icio.us/Evenbit/OS

Nathan.
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 875 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC