Im currently setting up a GDT for my bootloader. I have 3 (4) segments:
- (zero segment)
- 4GB Kernel Code segment
- 4GB Kernel Data segment
- 2GB Stack Data section (i forgot to set 1 bit to 0 when i made the screenshots. Later this will be 1mb)
Here is my Code for setting up the GDT:
7 ; GDT null segment
8 gdt_null:
9 dq 0x00
10
11 ; GDT code segment (4GB)
12 gdt_code:
13 dw 0xFFFF
14 dw 0x00
15 db 0x00
16 db 10011010b
17 db 11001111b
18 db 0x00
19
20 ; GDT data segment (4GB)
21 gdt_data:
22 dw 0xFFFF
23 dw 0x00
24 db 0x00
25 db 10010010b
26 db 11001111b
27 db 0x00
28
29 ; Extra segmet for stack
30 ; Preventing bufferoverflows from stack could write into other data
31 ; Size is 1M (0x100 * 4kb) startting from base 7e00 (512 bytes after 7c00)
32 gdt_stack:
33 dw 0x0100
34 dw 0x7e00
35 db 0x00
36 db 10010010b
37 db 11001000b
38 db 0x00
But when I loading the binary into bochs it gives me following result:
The Bytes loaded exactly as i defined them into memory:
Here i realised that 0xFFF is added every time to a segment. Is this because I used 4kb as granularity?
When I choose 0xFF as size with 4kb granularity will be this extended to 0xFFFFF, so i can only make the segment 1mb - 1 byte big?