protected mode confusion
Posted: Tue Mar 14, 2006 12:00 am
My bootloader sets up segments in the gdt (code, data and linear) and then runs my kernel program. But I have found a couple of problems which have confused me:
When I want to print to screen i have to use the linear (unreal) selector to access video memory. The data selector doesn't work even though the data segment begins at physical address 0. Why is this? Isn't it just doing mov [0:B8000], ax or whatever?
Secondly, I decided I wanted my kernel to add entries to the gdt after it was loaded by the bootloader so that in addition to the three segments mentioned above, there would be three more (user_code, user_data and tss). But when I switch to the user_data selector and write to the first address in the user_data segment I receive a general protection exception.
If I add the same entries into the gdt in the bootloader then I can access the memory fine from in the kernel.
Here are the segment descriptor thingies:
codeseg db 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x9A, 0xC0, 0x00
dataseg db 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x92, 0xC0, 0x00
unreal db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0x4F, 0x00
tss_seg db 0x1F, 0x00, 0x00, 0x00, 0x00, 0x89, 0xC0, 0x01
user_code db 0xFF, 0x0F, 0x00, 0x00, 0x02, 0xFA, 0xC0, 0x01
user_data db 0xFF, 0x0F, 0x00, 0x00, 0x02, 0xF2, 0xC0, 0x01
Cheers!
Gareth
When I want to print to screen i have to use the linear (unreal) selector to access video memory. The data selector doesn't work even though the data segment begins at physical address 0. Why is this? Isn't it just doing mov [0:B8000], ax or whatever?
Secondly, I decided I wanted my kernel to add entries to the gdt after it was loaded by the bootloader so that in addition to the three segments mentioned above, there would be three more (user_code, user_data and tss). But when I switch to the user_data selector and write to the first address in the user_data segment I receive a general protection exception.
If I add the same entries into the gdt in the bootloader then I can access the memory fine from in the kernel.
Here are the segment descriptor thingies:
codeseg db 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x9A, 0xC0, 0x00
dataseg db 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x92, 0xC0, 0x00
unreal db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0x4F, 0x00
tss_seg db 0x1F, 0x00, 0x00, 0x00, 0x00, 0x89, 0xC0, 0x01
user_code db 0xFF, 0x0F, 0x00, 0x00, 0x02, 0xFA, 0xC0, 0x01
user_data db 0xFF, 0x0F, 0x00, 0x00, 0x02, 0xF2, 0xC0, 0x01
Cheers!
Gareth