Eigenes Betriebssystem Booten



  • Hallo Zusammen.
    Wie kann ich mein eigenes Betriebssystem vom USB stick booten
    hier der code:

    boot.asm
      org 0x7C00 ; set up start address 
        ; setup a stack 
        mov ax, 0x9000  ; address of the stack SS:SP
        mov ss, ax      ; SS = 0x9000 (stack segment)
        xor sp, sp      ; SP = 0x0000 (stack pointer)
        ; start
        mov [bootdrive], dl ; boot drive from DL
        call load_kernel    ; load kernel
     
        ; jump to kernel
        jmp 0x1000:0x0000   ; address of kernel
     
        bootdrive db 0      ; boot drive
        loadmsg db "bootloader message: loading kernel ...",13,10,0
     
        ; print string
    print_string:
        lodsb             ; grab a byte from SI
        or al, al         ; NUL?
        jz .done          ; if the result is zero, get out
        mov ah, 0x0E
        int 0x10          ; otherwise, print out the character!
        jmp print_string
     .done:
        ret
     
        ; read kernel from floppy disk
    load_kernel:
        mov dl,[bootdrive] ; select boot drive 
        xor ax, ax         ; mov ax, 0  => function "reset"
        int 0x13          
        jc load_kernel     ; trouble? try again
    
    load_kernel1:
        mov ax, 0x1000    
        mov es, ax         ; ES:BX = 0x10000
        xor bx, bx         ; mov bx, 0
     
        ; set parameters for reading function
        ; 8-Bit-wise for better overview
        mov dl,[bootdrive] ; select boot drive
        mov al,10          ; read 10 sectors
        mov ch, 0          ; cylinder = 0
        mov cl, 2          ; sector   = 2
        mov dh, 0          ; head     = 0
        mov ah, 2          ; function "read"  
        int 0x13          
        jc load_kernel1    ; trouble? try again
    
              ; show loading message
        mov si,loadmsg
        call print_string 
        ret
    
        times 510-($-$$) hlt
        db 0x55
        db 0xAA
    
    
    kernel.bin
    
      mov ax, 0x07C0  ; set up segments
      mov ds, ax
      mov es, ax
    
      mov si, welcome
      call print_string
    
    loop:
      mov si, prompt
      call print_string
    
      mov di, buffer
      call get_string
    
      mov si, buffer
      cmp byte [si], 0  ; blank line?
      je loop           ; yes, ignore it
    
      mov di, cmd_hi    ; "hi" command
      call strcmp
      jz .helloworld
    
      mov si, buffer
      mov di, cmd_help  ; "help" command
      call strcmp
      jz .help
    
      mov si, buffer
      mov di, cmd_questionmark  ; "?" command
      call strcmp
      jz .help
     
      mov si, buffer
      mov di, cmd_exit  ; "exit" command
      call strcmp
      jz .exit
    
      mov si,badcommand
      call print_string
      jmp loop 
    
    .helloworld:
      mov si, msg_helloworld
      call print_string
    
      jmp loop
    
    .help:
      mov si, msg_help
      call print_string
    
      jmp loop
    
    .exit:
      mov si, msg_exit
      call print_string
      jmp 0xffff:0x0000  ; Reboot
    
    welcome db 'OS', 13, 10, 0
    msg_helloworld db 'Hello World!', 13, 10, 0
    badcommand db 'Command unknown.', 13, 10, 0
    prompt db 'A:\>', 0
    cmd_hi db 'hi', 0
    cmd_help db 'help', 0
    cmd_questionmark db '?', 0
    cmd_exit db 'exit', 0
    msg_help db 'Commands: hi, help, ?, exit', 13, 10, 0
    msg_exit db 'Reboot starts now.', 13, 10, 0
    
    buffer times 32 db 0
    
    ; ================
    ; calls start here
    ; ================
    
    print_string:
      lodsb        ; grab a byte from SI
    
      or al, al    ; logical or AL by itself
      jz .done     ; if the result is zero, get out
    
      mov ah, 0x0E
      int 0x10       ; otherwise, print out the character!
    
      jmp print_string
    
    .done:
      ret
    
    get_string:
      xor cl, cl
    
    .loop:
      xor ah, ah    ; mov ah, 0
      int 0x16      ; wait for keypress
    
      cmp al, 8     ; backspace pressed?
      je .backspace ; yes, handle it
    
      cmp al, 13    ; enter pressed?
      je .done      ; yes, we're done
    
      cmp cl, 31    ; 31 chars inputted?
      je .loop      ; yes, only let in backspace and enter
    
      mov ah, 0x0E
      int 0x10      ; print out character
    
      stosb  ; put character in buffer
      inc cl
      jmp .loop
    
    .backspace:
      or cl, cl     ; zero? (start of the string)
      jz .loop      ; if yes, ignore the key
    
      dec di
      mov byte [di], 0  ; delete character
      dec cl        ; decrement counter as well
    
      mov ax, 0x0E08
      int 0x10      ; backspace on the screen
    
      mov al, ' '
      int 0x10      ; blank character out
    
      mov al, 8
      int 0x10      ; backspace again
    
      jmp .loop     ; go to the main loop
    
    .done:
      mov al, 0     ; null terminator
      stosb
    
      mov ax, 0x0E0D
      int 0x10
      mov al, 0x0A
      int 0x10      ; newline
    
      ret
    
    strcmp:
    .loop:
      mov al, [si]   ; fetch a byte from SI
      cmp al, [di]   ; are SI and DI equal?
      jne .done      ; if no, we're done.
    
      or al, al      ; zero?
      jz .done       ; if yes, we're done.
    
      inc di         ; increment DI
      inc si         ; increment SI
      jmp .loop      ; goto .loop
    
    .done:    
      ret
    
      times 510-($-$$) hlt  ; as alternative to db 0
      db 0x55        ; boot signature check (byte 511 in sector 1)
      db 0xAA        ; boot signature check (byte 512 in sector 1)
    
    copy boot.bin+kernel.bin OS.img
    
    

    wie kriege ich dies jetzt auf meinen USB stick?
    zum booten?



  • Google mal nach "write raw image to usb stick" oder sowas (ohne die "").


Anmelden zum Antworten