Page 1 of 1
enabling pmode reboots my system
Posted: Sun Mar 29, 2009 10:00 pm
by extremecoder
Hi,
I am new to OS development. currently i am into developing my own boot loader. my first set of routines is to switch to pmode. the moment i switch to pmode using CR0, my sys gets rebooted. I am trying this in a VMWare guest with 16MB Ram and a virtual floppy drive. Is it necessary to set up a temp GDT before switching to pmode, because I am planning to set it up in kernel.
Re: enabling pmode reboots my system
Posted: Sun Mar 29, 2009 10:08 pm
by Love4Boobies
Yes, you need to have a GDT when you jump to protected mode (and not only that). Your system restarts because it triple faults without the appropriate data structures set up. You should really do some research before asking such questions. Take a look at the
Intel 64 and IA-32 Architectures Software Developer's Manual for more information.
Also, welcome to OSDev.org and have fun programming your OS.
EDIT: hold on... If you're
new, how come you're a member since 2006?
Re: enabling pmode reboots my system
Posted: Sun Mar 29, 2009 11:14 pm
by extremecoder
hey thank you man !! ... I have read the Intel manuals ... and I do understand about the descriptor tables and segment descriptor information ... like segment limit, base address, D/B, G bit, and all those ... I have the hard copy of the Intel manuals and read about GDT ... earlier was I interested only to focus on Kernel, thus by giving the headache to GRUB ... but I am interested in learning nuts and bolts of whatever i code ... so want to develop my own bootloader ... i have started this only 3 weeks back ..
Re: enabling pmode reboots my system
Posted: Mon Mar 30, 2009 1:42 am
by skyking
Then it's amazing that you even ask this. If you understand the segment translation mechanism in protected mode, where do you imagine that the processor gets it's descriptor from if no GDT (or LDT) is specified?
Perhaps you imagine that the descriptors have an initial state that's useful? To some extent they do, but you normally reload all segment selectors after entering protected mode so the descriptors are reloaded.
Perhaps you imagine that the GDTR and LDTR are initialized to some useful value, maybe they are, but what about the memory that they point to - is this initialized to a useful state? You won't AFAIK find this stated in the documentation and if the documentation does not state that the initial state to be something particular you should not assume anything particular. You can't assume that GDTR and LDTR are anything particular unless you set them.
Perhaps you imagine that the BIOS sets the GDTR and LDTR to something useful? Well don't. I wouldn't count on the BIOS giving the boot sector control in a very well defined processor state - BIOSes tend to even not putting the specified registers in correct state (cs:ip and dl), why should you rely on other registers then?
Perhaps you imagine that GRUB does some initialization? Yes it does, but the documentation explicitly says that you should set up your own tables - so you better do that.
Re: enabling pmode reboots my system
Posted: Tue Mar 31, 2009 4:56 am
by jal
skyking wrote:Perhaps you imagine that GRUB does some initialization? Yes it does, but the documentation explicitly says that you should set up your own tables - so you better do that.
But that's exactly what he did: when Grub boots you, you are in a sane PM environment, and you start setting up your GDT etc. Now the guy writes his own bootloader, and must do what Grub does, but doesn't know what Grub does :).
JAL
Re: enabling pmode reboots my system
Posted: Tue Mar 31, 2009 5:52 pm
by JAAman
well, technically you dont need a GDT before entering PMode (just think about it for a moment... the only time the CPU uses the GDT is when the segment registers are changed) as long as you dont change or reload any of the segment registers you technically dont need a GDT... however this really isnt very practical... so really you should have one before entering PMode
however if you are certain that the tripple-fault is happening as you enable PMode (and not later when loading - either explicitly or implicitly - any segment registers) then your problem is probably that you didnt disable interrupts before entering PMode (interrupts must be either disabled or masked otherwise the CPU will receive hard-ints, and try to load the interrupt from the existing IDT (which, unless you changed it, is located at absolute address 0, and has a limit of 256*4-1) -- which will try to jump to the vectors indicated -- and in doing so, implicitly load segment registers (which dont exist if you havent set up the GDT, and if you have, still probably dont match valid segments)
you can set up (and initialize with IDTR) your IDT either before or after you enter PMode, but interrupts must be disabled between those 2 events
Re: enabling pmode reboots my system
Posted: Tue Mar 31, 2009 6:04 pm
by ehenkes
Look here:
http://www.henkessoft.de/OS_Dev/OS_Dev1.htm
bootloader -> real mode -> PM -> kernel in C -> video -> keyboard
(tutorial is in German, but source code is commented in English)
source:
http://www.henkessoft.de/OS_Dev/Downloads/13%20C.zip
tools: nasm(w), bochs, DJGPP(gcc/ld), partcopy, make/makefile
starts in ASM, switches to C arriving at PM.
Re: enabling pmode reboots my system
Posted: Sat Apr 04, 2009 1:44 am
by extremecoder
hey ehenkes, thank you very much ... the link you have posted was very useful ... but I have another doubt ... which one of the following is recommended:
1) include mode changing in the boot loader
2) include mode changing in the kernel
_ec