Page 1 of 1
baby steps
Posted: Mon Dec 12, 2011 10:03 pm
by ishkabible
ok so im following the babysteps tutorial but im not able to print to "write a message using the BIOS" using qemu. (btw, im using windows)
here is baby.asm, I just copied it out of the tutorial
Code: Select all
; baby.asm
mov ax, 0x07c0
mov ds, ax
mov si, msg
ch_loop:lodsb
or al, al ; zero=end or str
jz hang ; get out
mov ah, 0x0E
int 0x10
jmp ch_loop
hang:
jmp hang
msg db 'Welcome to Macintosh', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
then I build that into the binary "boot.img" as such
Code: Select all
C:\Users\ishka\AppData\Local\nasm\nasm baby.asm -f bin -o boot.bin
C:\cygwin\bin\dd if=boot.bin of=boot.img
pause>nul
then i made a virtual 10 Mb virtual hard drive using qemu-img
Code: Select all
qemu\qemu-img create qemu-hda.img 10M
pause>nul
then i ran this using qemu
Code: Select all
qemu\qemu-system-x86_64 -fda boot.img -boot a qemu-hda.img -L qemu
pause>nul
the bios shows up, gives the date on which everything was made, shows me me devices(10 mb hard drive and a cd drive using ATA), then it says "loading from floopy..." with the cursor under it. then nothing happens. i have no clue what i did wrong :/
Re: baby steps
Posted: Tue Dec 13, 2011 2:15 am
by Combuster
Works here.
Note that the dd step is unnecessary as it will do nothing beyond making a copy of a file. You can even shorten the qemu command to (in your case)
as the harddrive is not used at all.
EDIT: for the record, version numbers?
Re: baby steps
Posted: Tue Dec 13, 2011 3:10 am
by ACcurrent
Do yourself a favor and install slitaz linux or tiny core linux on VirtualBox or VMware. If you really hate the idea of a virtual machine install topologilinux on top of windows.
Re: baby steps
Posted: Tue Dec 13, 2011 5:40 am
by Combuster
ACcurrent wrote:Do yourself a favor and install slitaz linux or tiny core linux on VirtualBox or VMware. If you really hate the idea of a virtual machine install topologilinux on top of windows.
And that helps how?
Re: baby steps
Posted: Tue Dec 13, 2011 8:57 am
by ishkabible
Works here.
...
EDIT: for the record, version numbers?
I know im using a really old version of qemu(like from 2006), and the nasm is the latest copy. I'll get the latest version of qemu and see if that fixes it.
playing around last night i was able to print some extended ASCII characters. I set al to 255 and decremented down to zero to try and print the all the characters. all it printed was the characters for text user interfaces, no letters, not even the ones in extended ASCII :/
also, I couldn't figure out what that dd stuff was there for. im a windows guy, so i had no clue what dd did, only that it did some kind of low level copy.
Re: baby steps
Posted: Tue Dec 13, 2011 9:18 am
by Combuster
im a windows guy, so i had no clue
If you believe that, you should not be doing an OS at all. Go read the forum rules, all of them.
Re: baby steps
Posted: Tue Dec 13, 2011 10:27 am
by ishkabible
http://wiki.osdev.org/Getting_Started#R ... _Knowledge
Sorry about that; I read the "required knowledge"(and the rest of the rules too) and feel I do lack a bit. Of those I'm really only lacking in familiarity with UNIX. I am well versed in C and pretty decent with 32-bit x86. I'm certain I can learn to use UNIX tools however.
Should I drop learning about OSs and learn to use a UNIX based OS first? Is learning it as I go not a practical option? If I shouldn't be making an OS, what should I do first?
Re: baby steps
Posted: Tue Dec 13, 2011 12:49 pm
by AJ
Hi,
I never used a unix-like environment before starting OSDev, either.
In Cygwin, install all the packages mentioned in
GCC Cross-Compiler and have a play around with compiling a few things. Get to know the "configure;make all; make install;" system and get used to building outside a source tree. You'll quickly learn - don't let the Unix thing put you off! As a few other excercises, you may like to play around with Makefiles and shell scripting - another really good way to get familiar with the environment. Just get yourself comfortable enough that if something fails, it's not because you don't know the tools.
Good luck,
Adam
Re: baby steps
Posted: Tue Dec 13, 2011 3:15 pm
by ishkabible
alright, cool deal; I can do all of that just fine. I'm just not familiar with all the non-GCC tool chains.
thanks, I'll try with a newer version of qemu when I get home!
Re: baby steps
Posted: Tue Dec 13, 2011 4:11 pm
by Combuster
ishkabible wrote:Should I drop learning about OSs and learn to use a UNIX based OS first? Is learning it as I go not a practical option? If I shouldn't be making an OS, what should I do first?
Well yes, having a lack of experience with unix tools will generally bite you at some point, but that is much less important than knowing that google exists for any
information you seem to miss. Point in case, you could have grabbed the manual for dd, learn from it's contents, then provide feedback based on whatever relevant you found (or did not find) in there, rather than taking Windows as an excuse.
In other words, we have an instance of The First Commandment of Debugging:
Don't think, know.
Re: baby steps
Posted: Tue Dec 13, 2011 6:14 pm
by ishkabible
ok I've updated to the most recent build of qemu from the cite below. I'm going to walk though everything I do, write it all down and why im doing. maybe then someone can spot what im doing wrong.
http://lassauge.free.fr/qemu/
1) I run the following shell code:
baby.asm is the same as seen above. I'm doing this to assemble the x86 code into a binary that can booted as if it where a floppy.
2) I run the following shell code:
Code: Select all
qemu\qemu -fda boot.bin -L qemu\bios
qemu\qemu is a relative filepath to the qemu binary. boot.bin was created in step 1. qemu\bios is a relative filepath to a directory of several BIOS and ROMs.
I'm doing this to boot "boot.bin" as if it were a floppy disk. -L specifys the directroy for qemu to look for bios.bin and vgabios.bin
i receive the following text:
SeaBIOS (version pre-0.6.3-20110315_1121143-titi)
iPXE v1.0.0-591-g7aee315
iPXE (
http://ipxe.org) 00:03.0 C900 PCI2.10 PnP PMM+07FC8D60+07F88D60 C900
Booting from Floppy...
and it just hangs there. even the following code hangs
Code: Select all
; baby.asm
mov ax, 0x07c0
mov ds, ax
msg db 'Welcome to Macintosh', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
which shouldn't hang as there is no loop.
Re: baby steps
Posted: Tue Dec 13, 2011 6:53 pm
by Combuster
ishkabible wrote:(...code...) which shouldn't hang as there is no loop.
There is always a loop in real mode garbage memory, and that's typically the bios repeatedly restarting an exception. That's also the reason why broken real mode code does not cause resets whereas protected mode boot code does.
Re: baby steps
Posted: Tue Dec 13, 2011 7:20 pm
by ishkabible
ok, that explains that but I still can't figure out how to pin-point the issue. i am able to print all of the extended ASCII characters with the below code
Code: Select all
; baby.asm
mov ax, 0x07c0
mov ds, ax
mov al, 0xFF
test_loop:
cmp al, 0 ;check if done
je hang ;exit if done
mov ah, 0x0E ;specify to print chcracter
int 0x10 ;print chracter
dec al ;next lower value
jmp test_loop;loop back
hang:
jmp hang
msg db 'Welcome to Macintosh', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
but the following code(which is meant to print msg) dose nothing
Code: Select all
; baby.asm
mov ax, 0x07c0
mov ds, ax
mov si, msg
test_loop:
mov al, byte[si] ;load byte from si
cmp al, 0 ;check if done
je hang ;exit if done
mov ah, 0x0E ;specify to print chcracter
int 0x10 ;print chracter
inc si ;next lower value
jmp test_loop;loop back
hang:
jmp hang
msg db 'Welcome to Macintosh', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
I'm going to see if i can write a small function to print the value of al in octal.
edit: although it prints the number backwards, my small test function showed me that byte[si] is zero when im trying to print it so the loop just exits before any characters are printed. what's up with that?? shouldn't it be at the front of block?
edit2: fixed backward thing
here is the function that prints AL in octal
Code: Select all
;function for printing al in octal
;it clobers bl, and bh
printOct:
mov bh, al ;store al for later
shr al, 6 ;first digit
call printOctDigit
mov al, bh ;restore
shr al, 3 ;second digit
call printOctDigit
mov al, bh ;last digit
call printOctDigit
mov al, 0x20 ;for space chracter
mov ah, 0x0E ;specify to print chcracter
int 0x10 ;print chracter
mov al, bh
ret
printOctDigit:
mov bl, al ;store al for later
and al, 7 ;mask first 2 digits
mov ah, 0x0E ;specify to print chcracter
add al, 0x30 ;al += '0' to get ASCII digit value
int 0x10 ;print chracter
mov al, bl ;restore al
ret
Re: baby steps
Posted: Wed Dec 14, 2011 5:40 am
by Combuster
Actually, I'm more interested in the value of SI at the start of that function, just to make sure it doesn't do anything stupid there. It should be about 22 decimal (Give or take a few, I don't know all the instruction lengths by hard and some opcodes have multiple encodings of different lengths). Also if you try disassembling your binary (use ndisasm and force it to 16 bits), you should see something like mov si, 22 or mov si, 0x16 appear.
Just hoping that NASM 2.0 didn't break some rules regarding to older code.
Re: baby steps
Posted: Wed Dec 14, 2011 5:58 pm
by ishkabible
Finely I got it, thank you for telling me to disassemble it! Issue is I don't like how I got it. I dissembled it and i found that there seems to be an issue with the instruction encoding. Rather than mov si,0x44 (what i should be) it is encoded as mov si,0x4400. so I shifted right by 8 bits to get the 0x44 and it worked. I REALLY don't want to have to do that every time I set a register equal to a label :/ how might i fix it?
edit:
appears to be a bug that was fixed in the actual latest stable release. i was using 2.09.08 but the latest is 2.09.10. updating fixed the issue. next time i have an issue, im just going to make sure everything is updated all the way
thanks guys, now I can venture forth in the world of OS dev