Page 1 of 1

Boot sector doesn't run

Posted: Wed Nov 16, 2011 8:30 am
by romfox
Hello all, first, sorry for my english.

So, I post here cause I have troubles that I didn't had on my last computer : I am actually running on Win7-0x64 and I want to make my own MBR.
I mounted my virtual floppy, put my BIN on, and launch it with Qemu. It works ! But still don't launch my MBR...

My MBR is simple, but to be sure I tried different codes, and I'm sure that Qemu(I have tried with VB too) doesn't launch it. I just have a black window which doesn't move.

I use Virtual Floppy Drive to create virtual floppies.
And the most strange is that I could launch my MBR using this method with my last computer which was in 32 bits... I don't know.

Thank all.

Re: Boot sector doesn't run

Posted: Wed Nov 16, 2011 10:19 am
by Brendan
Hi,
romfox wrote:So, I post here cause I have troubles that I didn't had on my last computer : I am actually running on Win7-0x64 and I want to make my own MBR.
I mounted my virtual floppy, put my BIN on, and launch it with Qemu. It works ! But still don't launch my MBR...

My MBR is simple, but to be sure I tried different codes, and I'm sure that Qemu(I have tried with VB too) doesn't launch it. I just have a black window which doesn't move.

I use Virtual Floppy Drive to create virtual floppies.
And the most strange is that I could launch my MBR using this method with my last computer which was in 32 bits... I don't know.
I'm sorry to hear your code is having troubles.

If you ever need help, don't forget that you can ask questions on the forums. You can even post source code if you want to (so that people can check for any bugs, etc).


Cheers,

Brendan

Re: Boot sector doesn't run

Posted: Wed Nov 16, 2011 12:34 pm
by romfox
Thanks for answers :)

This is one of the code I tested from the wiki :

Code: Select all

; boot.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 'Salut !', 13, 10, 0
   times 510-($-$$) db 0
   db 0x55
   db 0xAA
Is there a type of floppies to use ? I use the Virtual Floppy Driver's default settings.

So I do :

nasmw -f bin boot.asm -o boot.bin
copy boot.bin A:
qemu -L . -boot a -fda A:

It starts but doesn't launch anything.

Thanks.

Re: Boot sector doesn't run

Posted: Wed Nov 16, 2011 2:52 pm
by Combuster
copy boot.bin A:
That does not overwrite the bootsector at all. It only places a "boot.bin" at some random location on the floppy.
I suggest you try actually following the instructions in the Babystep1 tutorial instead of inventing your own.

Re: Boot sector doesn't run

Posted: Thu Nov 17, 2011 10:43 am
by romfox
Yeah it works ! :)

Now I tried a boot sector which spawn a message, init the drive, read the sectors :

Code: Select all

init_drive:
   xor ax, ax
   int 0x13
   jc init_drive 

   push es
read_drive:
   mov ax, BASE  ; base set as 0x100
   mov es, ax 
   mov ah, 0x02
   mov al, 1
   xor bx, bx
   mov ch, 0   ; No cylinders
   mov cl, 2   ; Read the second segment
   mov dl, [bootdriver]
   mov dh, 0x00 
   int 0x13
   jc read_drive

   pop es
Then I jump to the readed (don't think 'readed' is correct...) where is my kernel.

Code: Select all

jump dword BASE:00
But it looks never launching the kernel because I have an infinite loop on the boot sector's message whenever using the "-no-reboot" Qemu's option.

I tried lot of things, but whithout correct internet connection this is hard. So I tried to copy a simple boot sector which do the same thing but still the same problem.

To make the img file I do :

copy boot.bin/B+kernel.bin/B OS.img

Thanks..

Edit : I tried with VBox, it only spawns 1 time the message but doesn't spawn the kernel's one.
But something gones bad. I know I maybe look like a noob who wants to run before walk, but I'm programming asm since a little moment, and a simple OS (in real mode using BIOS first) will be a good way to learn and have fun I think :)

Re: Boot sector doesn't run

Posted: Thu Nov 17, 2011 5:03 pm
by romfox
Done :) It was a code error (cause parse code when you have to copy from your phone is hard :p)

Really happy :)

I have one last question now :

When spawning a char to screen whithout using the BIOS, the tuto show that I have to mov AX to ES:DI and I'm not sure I understand.

Does it simply move the char and its properties to ES:DI which is the video memory ? It looks too 'easy'.

Re: Boot sector doesn't run

Posted: Thu Nov 17, 2011 6:19 pm
by Brendan
Hi,
romfox wrote:I have one last question now :

When spawning a char to screen whithout using the BIOS, the tuto show that I have to mov AX to ES:DI and I'm not sure I understand.

Does it simply move the char and its properties to ES:DI which is the video memory ? It looks too 'easy'.
Yes - it stores the character and it's attribute into video display memory (and ES:DI points to the address in video display memory).

Before doing this you should make sure the video card actually is in text mode. Eventually you'd have code to handle things like tracking the current position and scrolling the screen.

Also note that (sooner or later) for modern OSs you typically want to use a graphics mode (where you control individual pixels, and can draw pictures, icons, menus, etc; and aren't limited to pre-supplied text characters or 16 colours). That's where it starts getting more complicated.


Cheers,

Brendan

Re: Boot sector doesn't run

Posted: Wed Nov 23, 2011 10:10 pm
by romfox
Hi, sorry, couldn't connect before.

So now my OS looks like a... textbox :p
I made a little keyboard driver, but I think it could be nice to sometime can use C. But I got a "cannot perform PE operations on non PE file" or something like that. I know a little about cross compiling, but I don't know which choice to do. I use windows 7 64bits, I think Cygwin could be a good choice.
But will it work ?
Thanks.

Re: Boot sector doesn't run

Posted: Wed Nov 23, 2011 11:28 pm
by bluemoon
romfox wrote:I know a little about cross compiling
WIKI is your friend. See GCC_Cross-Compiler
I suggest to have a look at it before deciding to use or not to use it.

Re: Boot sector doesn't run

Posted: Sat Nov 26, 2011 10:37 am
by romfox
Thanks, the question was : Will it work with Cygwin ? Cause I am not sûre I really understand.

Re: Boot sector doesn't run

Posted: Sat Nov 26, 2011 11:53 am
by bluemoon
I don't know if you can use cygwin host compiler for os development, it might work if you provided enough compiler flags and do it very carefully.

However, you can build a cross compiler on top of cygwin environment, which the procedure and advantages is listed on the wiki link above. and most people here are more familiar with that environment.

Re: Boot sector doesn't run

Posted: Sat Nov 26, 2011 1:07 pm
by romfox
Thanks, I have to follow the wiki but downloading with an edge connection at 5kb/s... I Will do it at a friend's home... Thanks, m'y OS now handles what is written :) But all in asm....

Re: Boot sector doesn't run

Posted: Sat Nov 26, 2011 3:30 pm
by romfox
One more question : yesterday I could try my os copying to my external HD, but it doesnt work anymore, I simply use "dd if=os32.img of=\\.\g: bs=512 count=2880", I dont know why cause it worked fine... I have looked if my sectors are really copied and it does...