Guest User

kernel.asm

a guest
Apr 12th, 2015
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    mov ax, 0x07C0  ; set up segments
  2.    mov ds, ax
  3.    mov es, ax
  4.  
  5.    mov bh, 0
  6.    mov ah, 0x2
  7.    int 0x10
  8.    mov cx, 2000 ; print 2000 chars
  9.    mov bh, 0
  10.    mov bl, 0x1E ; green bg/blue fg
  11.    mov al, 0x20 ; blank char
  12.    mov ah, 0x9
  13.    int 0x10
  14.  
  15.    mov si, welcome
  16.    call print_string
  17.  
  18.  mainloop:
  19.    mov si, prompt
  20.    call print_string
  21.  
  22.    mov di, buffer
  23.    call get_string
  24.  
  25.    mov si, buffer
  26.    cmp byte [si], 0  ; blank line?
  27.    je mainloop       ; yes, ignore it
  28.  
  29.    mov si, buffer
  30.    mov di, cmd_hi  ; "hi" command
  31.    call strcmp
  32.    jc .helloworld
  33.  
  34.    mov si, buffer
  35.    mov di, cmd_help  ; "help" command
  36.    call strcmp
  37.    jc .help
  38.    
  39.    mov si, buffer
  40.    mov di, cmd_shutdown  ; "shutdown" command
  41.    call strcmp
  42.    jc .shutdown
  43.  
  44.    mov si,badcommand
  45.    call print_string
  46.    jmp mainloop  
  47.  
  48.  .helloworld:
  49.    mov si, msg_helloworld
  50.    call print_string
  51.  
  52.    jmp mainloop
  53.  
  54.  .help:
  55.    mov si, msg_help
  56.    call print_string
  57.  
  58.    jmp mainloop
  59.    
  60.  .shutdown:
  61.    mov ax, 0x1000
  62.    mov ax, ss
  63.    mov sp, 0xf000
  64.    mov ax, 0x5307
  65.    mov bx, 1
  66.    mov cx, 3
  67.    int 0x15
  68.  
  69.  welcome db 'Loading Plutonium Kernel (Plutonium version pm.dev-b0.1.1)...', 0x0D, 0x0A, 0
  70.  msg_helloworld db 'pm.dev-b0.1.1, 4-9-15', 0x0D, 0x0A, 0
  71.  badcommand db 'That command is not recognized as a system operation.', 0x0D, 0x0A, 0
  72.  prompt db 'Plutonium >', 0
  73.  cmd_hi db 'info', 0
  74.  cmd_help db 'help', 0
  75.  cmd_shutdown db 'shutdown', 0
  76.  msg_help db 'My OS: Commands: hi, help', 0x0D, 0x0A, 0
  77.  buffer times 64 db 0
  78.  
  79.  ; ================
  80.  ; calls start here
  81.  ; ================
  82.  
  83.  print_string:
  84.    lodsb        ; grab a byte from SI
  85.  
  86.    or al, al  ; logical or AL by itself
  87.    jz .done   ; if the result is zero, get out
  88.  
  89.    mov ah, 0x0E
  90.    int 0x10      ; otherwise, print out the character!
  91.  
  92.    jmp print_string
  93.  
  94.  .done:
  95.    ret
  96.  
  97.  get_string:
  98.    xor cl, cl
  99.  
  100.  .loop:
  101.    mov ah, 0
  102.    int 0x16   ; wait for keypress
  103.  
  104.    cmp al, 0x08    ; backspace pressed?
  105.    je .backspace   ; yes, handle it
  106.  
  107.    cmp al, 0x0D  ; enter pressed?
  108.    je .done      ; yes, we're done
  109.  
  110.    cmp cl, 0x3F  ; 63 chars inputted?
  111.    je .loop      ; yes, only let in backspace and enter
  112.  
  113.    mov ah, 0x0E
  114.    int 0x10      ; print out character
  115.  
  116.    stosb  ; put character in buffer
  117.    inc cl
  118.    jmp .loop
  119.  
  120.  .backspace:
  121.    cmp cl, 0    ; beginning of string?
  122.    je .loop ; yes, ignore the key
  123.  
  124.    dec di
  125.    mov byte [di], 0 ; delete character
  126.    dec cl       ; decrement counter as well
  127.  
  128.    mov ah, 0x0E
  129.    mov al, 0x08
  130.    int 10h      ; backspace on the screen
  131.  
  132.    mov al, ' '
  133.    int 10h      ; blank character out
  134.  
  135.    mov al, 0x08
  136.    int 10h      ; backspace again
  137.  
  138.    jmp .loop    ; go to the main loop
  139.  
  140.  .done:
  141.    mov al, 0    ; null terminator
  142.    stosb
  143.  
  144.    mov ah, 0x0E
  145.    mov al, 0x0D
  146.    int 0x10
  147.    mov al, 0x0A
  148.    int 0x10     ; newline
  149.  
  150.    ret
  151.  
  152.  strcmp:
  153.  .loop:
  154.    mov al, [si]   ; grab a byte from SI
  155.    mov bl, [di]   ; grab a byte from DI
  156.    cmp al, bl     ; are they equal?
  157.    jne .notequal  ; nope, we're done.
  158.  
  159.    cmp al, 0  ; are both bytes (they were equal before) null?
  160.    je .done   ; yes, we're done.
  161.  
  162.    inc di     ; increment DI
  163.    inc si     ; increment SI
  164.    jmp .loop  ; loop!
  165.  
  166.  .notequal:
  167.    clc  ; not equal, clear the carry flag
  168.    ret
  169.  
  170.  .done:    
  171.    stc  ; equal, set the carry flag
  172.    ret
  173.  
  174.    dw 0AA55h ; some BIOSes require this signature
Advertisement
Add Comment
Please, Sign In to add comment