Alright, i'm still at the stage of coding a bootloader for my "kernel". I'm at a point where i can enable the A20 Gate, then load my kernel off a floppy using BIOS. Now i want to switch to protected mode, and set up my own segmentation. Here's the problem:
I understand the GDT fields, but I don't understand how to create the actual segments, and how to use them now...
I don't understand where i define the "code segment" or "Data segment"...
I don't understand how to jump to my kernel code, etc
Am I way off? Any help would be very much appreciated...
GDT toubles...
Re:GDT toubles...
The segments do not need to be defined anywhere but in the gdt itsself.
By specifying in the gdt, that the code and data segments both start at 0x0 and have a length of 0xffffffff (for example), you already defined them ie they are the parts of memory that range from 0x0 to 0xffffffff - that's all the cpu needs to know from you.
To use the segments, put the selectors of the segments in the corresponding processor registers - for example: ds=your_dataseg_selector; cs=your_codeg_selector (Of course this would be done in assembler, ie "mov ds,your...").
The selectors would be 0x08 (==8d) for the first gdt-entry, 0x10 (16d) for the second one, 0x18 (24d) for the third... (if i recall it right).
Then, whenever you access code or data, the physical adress will be automatically created with the help of the gdt entries those selectors select.
To jump to yur kernel code, you have to know where it is
Probably you will link it as a binary that starts with your main function? If you do this and your bootloader loads the kernel to adress 0xsomething, you will know that your main-function in the kernel starts at 0xsomething too - so you can simply do "jmp 0xsomething".
Hope this helps
By specifying in the gdt, that the code and data segments both start at 0x0 and have a length of 0xffffffff (for example), you already defined them ie they are the parts of memory that range from 0x0 to 0xffffffff - that's all the cpu needs to know from you.
To use the segments, put the selectors of the segments in the corresponding processor registers - for example: ds=your_dataseg_selector; cs=your_codeg_selector (Of course this would be done in assembler, ie "mov ds,your...").
The selectors would be 0x08 (==8d) for the first gdt-entry, 0x10 (16d) for the second one, 0x18 (24d) for the third... (if i recall it right).
Then, whenever you access code or data, the physical adress will be automatically created with the help of the gdt entries those selectors select.
To jump to yur kernel code, you have to know where it is
Probably you will link it as a binary that starts with your main function? If you do this and your bootloader loads the kernel to adress 0xsomething, you will know that your main-function in the kernel starts at 0xsomething too - so you can simply do "jmp 0xsomething".
Hope this helps
Re:GDT toubles...
Also, it helps if you write a macro to convert between the entry number and the selector (i.e. it would change 0x01 into 0x08). This can save debugging time for when you make mistakes (plus it make code more readable)!