Re:Where do i start??
Posted: Mon Dec 09, 2002 5:22 am
There are questions, all right. I'll refrain from asking them, however, no matter how tempting it might be. You've already said you wouldn't answer most of them, anyway.Berserk wrote: all the other questions remain.
There are some things that are beyond my ability. This may be one of them. But I'll give it a shot.Please help.....
Wow. I can't understand how a person could grasp programming in, well, most languages, really, without understanding basic linear addresses. I mean, even LISP has the idea of cons cells, that they are in some sort of linear order and can be referred to by location and so forth. It's difficult to imagine programming in C or C++ without knowing how pointers work and what they mean underneath. This is simply astonishing in someone who claims to be an experienced programmer.
OK, back to basics. Computer memory, at least on the PC, consists of thousands of 8-bit cells or sections called bytes. Each byte can hold a value from 0 to 0xFF (256 decimal). On the PC, bytes are grouped by words (two bytes) and doublewords (four bytes).
Each byte has an address, a value that tells the computer how to retrieve the memory cell's value. On the PC, that address can be represented in a variety of ways, but all of the different representations can be used to generate a single number, which is the memory cell's absolute address. Absolute addressses begin at zero.
A program is represented by a series of bytes filling up a consecutive area of memory. Each of the of individual operations that make up a program can take up from one to six bytes, depending on the instruction and the kind of parameters it takes, and a given program may be comprised of tens of thousands of these opcodes.
For a variety of reasons, it is impossible to use absolute addresses directly on the PC while in real mode, which is how the PC starts up. Instead, all addresses have to be put together from two word (16-bit) values, a segment base and a segment offset. I and others here have explained these often enough; you should be able to look up how they work with the search engine (try reply #4 in this thread to start).
To address (as it were) your specific question, the absolute address that follows absolute address 0x07C00 is 0x07C01. However, given that the boot sector takes up the area from 0x07C00 to 0x07DFF (absolute addresses), the next free memory area past the end of the boot sector where you could safely load you second stage loader would be 0x07E00. Remember, however, that you are really talking about a segmented address, which is probably (but not necessarily) being addressed as 0000:7C00 (that is to say, the Code Segment register CS is set to 0x0000, and the addresses used to refer to the specific addresses are 0x07C00 through 0x07E00, on up 0x0FFFF. Since each real-mode segment offset can only address 65536 bytes, to access more memory than that you need to change the segment base in order to address more than a single 64K area. The combination of segment bases and offset can add up to at most a 20-bit absolute address, giving access to 1Mbyte of memory.
In 32-bit protected mode, it is both more and less complicated. The segment registers are replaced with 24-bit segment selectors, while the segment offsets are now a double word (32-bits) in size, meaning that there is sufficient memory space (4 gigabytes) in a single segment that most systems simply use a single segment for each program. That, combined with paging, can make it appear to an application program as if it had the whole of a single linear memory space available to it. The OS hides all of this complexity away by dealing with the segment selectors and paging requirements for the application programs.
I'm frankly too tired to continue right now. If you have any more questions I'll reply to them as best I can later.