Page 1 of 1

Boot code doesn't work on real computer

Posted: Tue Feb 10, 2004 8:56 am
by JW
Hello,

I've just started developing my own OS. So far I've written a boot code and a small kernel. The OS works on both Bochs and VMWare. But when I try to run it on a real computer, it seems to crash. I figured out on what line it was crashing (you can see it in the attachment). It's when I move the kernel from 0x7E00 to 0x100000 (1MB). I have no idea why it's crashing. Please help.

If the attachment doesn't work, use this link: http://jwfiles.europe.webmatrixhosting.net/os/boot.asm

Thanks in advance.

ps. I added my attachment, but there already was a boot.asm on the forum which isn't mine. So use the link.

Re:Boot code doesn't work on real computer

Posted: Tue Feb 10, 2004 1:22 pm
by Adek336
your memory moving code does not set the direction flag. Depending on its value when you get to "rep movsb", the memory copied will be in range ESI to ESI+ECX or ESI-ECX to ESI. Try inserting one of these instructions: cld std. Not sure which will suffice.

Anyways, I'm impressed with your code, it's just perfectly commented! Did you write it all yourself?

Cheers,
Adrian

Re:Boot code doesn't work on real computer

Posted: Tue Feb 10, 2004 5:32 pm
by Pype.Clicker
try replacing 'jmp boot' with 'jmp 0000:boot'. Your real hardware may be jumping 0x7c0:0000 instead of 0x0000:0x7c00 ...

Re:Boot code doesn't work on real computer

Posted: Wed Feb 11, 2004 8:26 am
by bubach
isn?t 0x7c0:0000 and 0x0000:0x7c00 the same physical address?
Should it really make a diffrent?

/ Christoffer

Re:Boot code doesn't work on real computer

Posted: Wed Feb 11, 2004 12:58 pm
by JW
Thanks for your replies.

I will try to set cs to zero and the direction flag.
Anyways, I'm impressed with your code, it's just perfectly commented! Did you write it all yourself?
Yes I wrote it myself. Thanks ;D (but I think it could be commented better, especially the A20 part)

Re:Boot code doesn't work on real computer

Posted: Wed Feb 11, 2004 1:56 pm
by JW
It's working....

I had to set the ecx register instead of the cx register in the code where I move the kernel from 0x7E00 to 0x100000 ( maybe I had to set cs to zero too ).

Re:Boot code doesn't work on real computer

Posted: Thu Feb 12, 2004 4:34 am
by Pype.Clicker
bubach wrote: isn?t 0x7c0:0000 and 0x0000:0x7c00 the same physical address?
Should it really make a diffrent?

/ Christoffer
the difference *does* matters.
You have assembled stuff so that the code may have

Code: Select all

jmp 0x7D40
, which is a near jump (absolute address within the same segment). If CS == 0, you'll be jumping at 0x0000:7D40 which is in your bootsector. Fine. Everyone's happy ... But if CS == 7C0, you'll be jumping at 0x07C0:7D40, which should be somewhere at 0x00F940 or something ... out of your bootsector, without a doubt.

Things will even become more ugly if you have something like

Code: Select all

mov ax,cs
mov ds,ax
In which case your data will not be where you expect them to be ... which is harmless in most cases (as the ds:<reg> will still be okay), but which will have sensibly bad effect when trying to give the absolute address of the GDT to the processor, for instance ...