[SOLVED]QEMU not running my OS from Real Mode Assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GrantBlock
Posts: 2
Joined: Sat May 03, 2014 7:49 pm

[SOLVED]QEMU not running my OS from Real Mode Assembly

Post by GrantBlock »

Hello, I am very new to operating system development (this is the first time I have ever tried it) and I am having problems with running my OS in QEMU. I am running Linux Mate (a Ubuntu distro), and I have followed the Real Mode Assembly tutorial and ran these commands to load my OS to a floppy.

Code: Select all

 nasm kernel.asm -f bin -o kernel.bin
dd if=kernel.bin of=/dev/fd0 
Then I ran this command to run it on QEMU:

Code: Select all

 qemu-system-x86_64 -cdrom fd0 
Yes, I was in the corrected directory, I triple checked. The QEMU window popped up, but after some time it returned me with an error saying no bootable device. Of coarse, there is no boot loader in this tutorial, the author said there should be no need for one. Here is my code, which I copied directly from the tutorial :

Code: Select all

 mov ax, 0x07C0  ; set up segments
   mov ds, ax
   mov es, ax
 
   mov si, welcome
   call print_string
 
 mainloop:
   mov si, prompt
   call print_string
 
   mov di, buffer
   call get_string
 
   mov si, buffer
   cmp byte [si], 0  ; blank line?
   je mainloop       ; yes, ignore it
 
   mov si, buffer
   mov di, cmd_hi  ; "hi" command
   call strcmp
   jc .helloworld
 
   mov si, buffer
   mov di, cmd_help  ; "help" command
   call strcmp
   jc .help
 
   mov si,badcommand
   call print_string 
   jmp mainloop  
 
 .helloworld:
   mov si, msg_helloworld
   call print_string
 
   jmp mainloop
 
 .help:
   mov si, msg_help
   call print_string
 
   jmp mainloop
 
 welcome db 'Welcome to My OS!', 0x0D, 0x0A, 0
 msg_helloworld db 'Hello OSDev World!', 0x0D, 0x0A, 0
 badcommand db 'Bad command entered.', 0x0D, 0x0A, 0
 prompt db '>', 0
 cmd_hi db 'hi', 0
 cmd_help db 'help', 0
 msg_help db 'My OS: Commands: hi, help', 0x0D, 0x0A, 0
 buffer times 64 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:
   mov ah, 0
   int 0x16   ; wait for keypress
 
   cmp al, 0x08    ; backspace pressed?
   je .backspace   ; yes, handle it
 
   cmp al, 0x0D  ; enter pressed?
   je .done      ; yes, we're done
 
   cmp cl, 0x3F  ; 63 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:
   cmp cl, 0	; beginning of string?
   je .loop	; yes, ignore the key
 
   dec di
   mov byte [di], 0	; delete character
   dec cl		; decrement counter as well
 
   mov ah, 0x0E
   mov al, 0x08
   int 10h		; backspace on the screen
 
   mov al, ' '
   int 10h		; blank character out
 
   mov al, 0x08
   int 10h		; backspace again
 
   jmp .loop	; go to the main loop
 
 .done:
   mov al, 0	; null terminator
   stosb
 
   mov ah, 0x0E
   mov al, 0x0D
   int 0x10
   mov al, 0x0A
   int 0x10		; newline
 
   ret
 
 strcmp:
 .loop:
   mov al, [si]   ; grab a byte from SI
   mov bl, [di]   ; grab a byte from DI
   cmp al, bl     ; are they equal?
   jne .notequal  ; nope, we're done.
 
   cmp al, 0  ; are both bytes (they were equal before) null?
   je .done   ; yes, we're done.
 
   inc di     ; increment DI
   inc si     ; increment SI
   jmp .loop  ; loop!
 
 .notequal:
   clc  ; not equal, clear the carry flag
   ret
 
 .done: 	
   stc  ; equal, set the carry flag
   ret
 
   times 510-($-$$) db 0
   dw 0AA55h ; some BIOSes require this signature 

Please, if anyone knows what I am doing wrong please let me know, or if this question has been asked before, please refer me to the link. If I have done something extremely stupid please also let me know(I do some very stupid things while programming user space stuff sometimes). I would not be surprised if I am missing something obvious, and if one of you could point it out, I would be grateful. Thank you. [edit] I changed "know" to "knows" [edit]
Last edited by GrantBlock on Sun Aug 10, 2014 5:36 pm, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: QEMU not running my OS from Real Mode Assembly Tutorial

Post by Combuster »

qemu-system-x86_64 -cdrom fd0
I wonder why you tell qemu to read a floppy as if it were a CD-rom, which has different booting mechanisms. I also wonder why you try to use real floppy hardware (with naming errors) rather than a disk image.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Tuxality
Posts: 3
Joined: Tue Apr 08, 2014 2:04 am
Location: Poland
Contact:

Re: QEMU not running my OS from Real Mode Assembly Tutorial

Post by Tuxality »

GrantBlock, after compiling with 'nasm kernel.asm -f bin -o kernel.bin' just run with 'qemu-system-x86_64 -fda kernel.bin'.
It will work, but it would be better to copy this to valid 1.44MB floppy disk image like this:

Code: Select all

nasm kernel.asm -f bin -o kernel.bin
dd if=/dev/zero of=floppy.img bs=512 count=2880
dd if=kernel.bin of=floppy.img conv=notrunc
qemu-system-x86_64 -fda floppy.img
if(person[id].thinks(OS_EQUALS_GUI)) person[id].push_to_hell();
GrantBlock
Posts: 2
Joined: Sat May 03, 2014 7:49 pm

Re: QEMU not running my OS from Real Mode Assembly Tutorial

Post by GrantBlock »

Thank you all for responding. @Tuxality, I tried those four commands and it worked! It seems like I have been spoiled by high level IDEs, and I need to do more research on how QEMU works and how to correctly assemble my files to the right places. Thank you all very much for this, and I will go make a make file ASAP.
Post Reply