Page 1 of 1
loading kernel
Posted: Thu Jul 24, 2003 11:00 pm
by HOS
i am rewriting my bootsector from scratch. previously i used a bootloader to load the kernel to 0x100000 (1mb) but now i want to write it myself and i cant quite understand that one. how does the bootsector load the kernel to 1mb in real mode? even if i enable the a20 first, cant real mode only access 1mb + 64k or something? so what if the kernel is bigger than 64k?
thanks
RE:loading kernel
Posted: Thu Jul 24, 2003 11:00 pm
by Jamethiel
I don't know about eveyone else, but my bootsector kicks the CPU into unreal mode before loading the kernel, and then kicks the CPU into pmode before jumping to it.
It all fits in 512 bytes with room to spare, too, although it probably wouldn't if there was a filesystem involved...
--Jamethiel
RE:loading kernel
Posted: Thu Jul 24, 2003 11:00 pm
by HOS
can you explain a little more as far as how exactly to get to "unreal mode" and what this allows you to do?
thank you for your reply
-HOS
RE:loading kernel
Posted: Sat Jul 26, 2003 11:00 pm
by Jamethiel
To get into unreal mode, load your GDT and enable the PMode bit of CR0. Do not jump anywhere at this point. Load a 32-bit flat descriptor into DS and ES. Disable the PMode bit of CR0. Reload DS and ES. You now are in unreal mode. You get real-mode interrupts, real-mode segment addressing, and can use a 32-bit offset for your memory accesses.
Of course, for this to be useful, you also have to disable the A20 line gate.
It is possible to fit all this code into a bootsector, but you probably won't have enough space left over to parse a filesystem if you do.
Although... If you loaded the entire disk image to the 1-meg point, would you have enough space to find where the first cluster of your kernel was loaded, and jump to that? I'll have to think about that...
--Jamethiel
RE:loading kernel
Posted: Sun Jul 27, 2003 11:00 pm
by HOS
ok, i think that i have set this up correctly, my boot sector enables a20, loads a gdt with only a 4gb data descriptor (0x08), puts 0x08 into ds and es, leaves pmode, then pops ds and es (i push them before entering pmode). the program does not crash. but now i want to use int 0x13 to load kernel and it says that it expects es:bx to hold the address of where to read the floppy sectors to. well, i kinda like the idea of loading the entire floppy, say to 1mb or 2mb (not sure yet), but in real ("unreal") mode how can i specify that as a location using only es:bx? or is there some other work around to do this too?
thank you
RE:loading kernel
Posted: Sun Jul 27, 2003 11:00 pm
by Jamethiel
Load it lower in memory and then use the magic of MOVSD.
You may need to hand-code the address size prefix on that, though...