4 ms·
0000:7c00 (segment 0, offset 0x7c00) and 07c0:0000 (segment 0x7c0, offset 0) are at the same physical address of 0x00007c00, so the processor will see the same
by david-given 10y ago
0000:7c00 (segment 0, offset 0x7c00) and 07c0:0000 (segment 0x7c0, offset 0) are at the same physical address of 0x00007c00, so the processor will see the same bytes each way. The latter's more useful in 16-bit mode, though, as it allows you to use offsets 0x0000 to 0xffff to access the 64kB of data starting at physical address 0x00007c00.
So typically the first thing you do on entry to the boot sector is to do a far jump to change code segments. But you don't have to; if you're immediately switching to 32-bit mode it may not be worth it.
Here's my boot sector --- everyone's written one. Mine's intended to load and run raw tiny mode executables on floppy.
https://github.com/davidgiven/ack/blob/default/plat/pc86/boot.s https://github.com/davidgiven/ack/blob/default/plat/pc86/boo...
- bogomipz 10y agoThanks for the clarification and your link. Maybe I am reading this wrong then? "Since our code resides at 0x7C00, the data segment may begin at 0x7C0" If those are both the same address how can the code segment and the data segment occupy the same address? Thanks.
- david-given 10y agoYup, they can. That way your code and data share the same address range, so you need to make sure that the offsets within the address range don't overlap. It's also possible to configure the system so that your code lives in one segment, and your data and stack live in another. That way, you get 64kB for code and another 64kB for data. We have to put the stack in the same segment as the data because C requires the stack to be addressable; if you're not working in C, you can put the stack in a third segment and get a bit more space. Of course, if you're willing to use pointers which contain the segment as well as the offset, so 32 bits wide, you can use multiple segments, but that raises all sort of complexity that's not really worth thinking about these days.
- bogomipz 10y agoAh OK the segments have the same address just different offsets from that address is that correct? You mention: "We have to put the stack in the same segment as the data because C requires the stack to be addressable" Are symbols only "reachable" if they are within the base and limit of same memory segment then? If this was the case I would think that the code and stack must be in the same segment? Why is the data segment? Cheers.