BootLoader 2

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
Zig
Posts:10
Joined:Fri Feb 20, 2009 11:58 pm
BootLoader 2

Post by Zig » Tue Mar 03, 2009 8:21 am

hi,

I am going through tut 2, and there is something I want to make sure,

In the demo code, I see

Code: Select all

   mov ds, ax		
   mov es, ax
Why do we need to set the data segment and extra segment address to 0? Is there any reason to it?

and the call

Code: Select all

int 0x16
what does it do?

Thanks you

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Tue Mar 03, 2009 9:11 am

At the top of the file, there is an ORG 0x7C00 directive.

This effectivly adds the value 0x7C00 to each of the lables. As a result, bpbOEM is 0x7C03, bpbBytesPerSector is 0x7C0B etc.

Therefore, the only way to address them using the segmet:offset moddle is when the segment is 0, hence why we are zeroing the segment registers.


As for INT 16, this bios function INT16,AX0 is one that returns the number of kilobytes of lower memory. It is not strictly useful at this point but is used later on in the series.

Hope this helps,

~Andyhhp
Image

Zig
Posts:10
Joined:Fri Feb 20, 2009 11:58 pm

Post by Zig » Tue Mar 03, 2009 8:23 pm

thanks for the reply. I understand about the org directive. But could ds be any other value beside 0, say 1?

We have bpbOEM is at 0x7C03 (and it is 8 byte long), the next one is 0x7C0B ....

so the offset is 0x7C03 from the start of the segment, so does it matter what the segment address is? Because the address of bpbOEM is always 0x7C03 at the start of the segment.

about INT 0x16, the comment says it returns the number of kilobytes of lower memory.

I have alook on the net and they say it is to get a char from keyboard and INT 0x12 is to get the memory? Sorry for all the noob question.

Thank so much for all the help. Love the tutorials.

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Tue Mar 03, 2009 8:41 pm

Hi,

No - the segment address cant be anything other than 0 in this case.

You quite correctly say that bpbOEM is 0x7C03 from the start of the segment.

However, at the same time, the bootloader is loaded to the address 0x7C00 in physical memory, with the real bpbOEM being at 0x7C03 in physical memory.

As you CANT move stuff around in physical memory, you have to make a segment:offset pair that maps correctly to physical memory.

As the address of bpbOEM in physical memory is 0x7C03, and the offset into the segment is 0x7C03, the only possible segment address is 0, else your code would be referencing somewhere else in memory.

As for the interrupt, my suggestion is to ignore it. One of the later tutorials deals fully with obtaining memory information using BIOS interrupt calls.

As for the tutorials - I am just as avid a reader of them as you. The are all Mike's doing ^_^

~Anyhhp
Image

Zig
Posts:10
Joined:Fri Feb 20, 2009 11:58 pm

Post by Zig » Tue Mar 03, 2009 9:37 pm

Andyhhp wrote:Hi,

No - the segment address cant be anything other than 0 in this case.

You quite correctly say that bpbOEM is 0x7C03 from the start of the segment.

However, at the same time, the bootloader is loaded to the address 0x7C00 in physical memory, with the real bpbOEM being at 0x7C03 in physical memory.

As you CANT move stuff around in physical memory, you have to make a segment:offset pair that maps correctly to physical memory.

As the address of bpbOEM in physical memory is 0x7C03, and the offset into the segment is 0x7C03, the only possible segment address is 0, else your code would be referencing somewhere else in memory.

As for the interrupt, my suggestion is to ignore it. One of the later tutorials deals fully with obtaining memory information using BIOS interrupt calls.

As for the tutorials - I am just as avid a reader of them as you. The are all Mike's doing ^_^

~Anyhhp
Thanks, Anyhhp. I got it.

Post Reply