Boot code doesn't work on real computer

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
JW

Boot code doesn't work on real computer

Post 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.
Adek336

Re:Boot code doesn't work on real computer

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Boot code doesn't work on real computer

Post by Pype.Clicker »

try replacing 'jmp boot' with 'jmp 0000:boot'. Your real hardware may be jumping 0x7c0:0000 instead of 0x0000:0x7c00 ...
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Boot code doesn't work on real computer

Post by bubach »

isn?t 0x7c0:0000 and 0x0000:0x7c00 the same physical address?
Should it really make a diffrent?

/ Christoffer
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
JW

Re:Boot code doesn't work on real computer

Post 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)
JW

Re:Boot code doesn't work on real computer

Post 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 ).
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Boot code doesn't work on real computer

Post 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 ...
Post Reply