Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Khaos

Boot Sector

This topic is 6172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have spent a large portion of today debugging a stupid boot sector, and am not sure what''s wrong. I am using the BIOS interrupt 10h to display an "array" of characters. Since the BIOS has no print string function that I know of, you have to point to a message and display one character at a time, until terminated by a certain character. I am using 0 as that character for some reason. My code is fine, I took out the stack and bootup code, and left my function to display a string. I set it up with DOS instead, and it worked wonderfully. This leads me to think something is wrong with my stack setup. What initial bootup and stack code should I use, so then I could lead right into my routine to display a string, and get on with it? Right now, when booted, the cursor blinks on and off, but nothing is displayed, I press a key and it reboots. So any help on the initial most startup code would be nice. Here is what I have now... org 7c00h ; bios boot location cli ; disable interrupts mov ax, 7c00h ; set up ds mov ds, ax ; load ds with 7c00h mov ax, 9000h ; place stack at 9000h mov ss, ax ; set ss to 9000h mov sp, 2000h ; reserve 8 kb sti ; enable interrupts This taken out, and set up with DOS instead, makes everything work wonderfully. So, thanks very much for your help. ===== Khaos =====

Share this post


Link to post
Share on other sites
Advertisement
Well, I can''t see anything wrong with your stack-setup. It looks like it should work. Are you sure you want DS to point to the code though?

Perhaps you could post some more code?

Share this post


Link to post
Share on other sites
Thanks for the reply. After another annoying day, I have found the problem. It seems small, and it was in the general area (the stack setup) I thought it was in. But, I guess I don''t understand it. I know if you showed me why, I would get the picture quite quickly. Well, here is my new code.


org 0h ; start relative to 0h

jmp start
nop ; required ?

start:
cli ; interrputs off
mov ax, 07c0h
mov ds, ax ; setup ds register
mov ax, 9000h
mov es, ax
mov sp, 2000h ; setup stack for 8kb
sti ; interrupts on


Okay, I put "org 0h" in instead of "org 7c00h" because I heard it was better to do that and load DS with the segment instead. The only part of the code that was "wrong" was with the line "mov ax, 07c0h". When I had it "mov ax, 7c00h" it didn''t work. After a few dozen debugging reboots, I changed it to "07c0h" instead of "7c00h", and it worked fine. Why is that? I was pretty sure I heard the BIOS wanted you at "7c00h", yet that doesn''t work. What is "07c0h" and where did that come from, and why does it work?

This may seem an odd question, all my code works great, and for being made from scratch, I am pretty proud of it. But I just don''t see why that works that way. Thanks for any help.

=====
Khaos
=====

Share this post


Link to post
Share on other sites
The reason you have to use 07c0h is because you put that value into a segment register. Then when the processor wants to access memory relative to that segment it uses the following formula (this only applies for real mode):

physical_address = segment*10h + offset

so whenever you use the segment register containing 07c0 it will be multiplied with 10h, resulting in 7c00h

That ''nop'' instruction is not needed.

Share this post


Link to post
Share on other sites
Yeah, you don''t need the NOP, you only need it if you do a
jmp short start

Direwolf

"Shhweeet, look atem blow" - Anonymous dwarf
"Hmm, I always thought I was a pretty nice guy, but no, apparently I''m the Antichrist..." -Rudan

Share this post


Link to post
Share on other sites
quote:
Original post by godballz
Yeah, you don''t need the NOP, you only need it if you do a
jmp short start


Why would the ''nop'' be needed with a ''jmp short start''?
It shouldn''t matter if the jump is a short or long one.
(or am I missing something here?)

Share this post


Link to post
Share on other sites
Yeah, it''s actually Intel x86 assembly programming. And indeed it is interesting. I learned it from The Art of Assembly (found on the internet) and two assembly books I purchased several years ago.

=====
Khaos
=====

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!