Page 1 of 1

Pmode in C++???

Posted: Thu Jan 01, 2004 12:00 am
by Berry
Hello,

I've decided to do no grub, but to make the bootloader myself :). But when I read the junk about going to P-mode, with GDT's and so on, I'll get mad :(. So is it possible to just make an Real-Mode bootloader, witch loads the kernel, and let the kernel set up P-Mode?

RE:Pmode in C++???

Posted: Thu Jan 01, 2004 12:00 am
by Dangamoose
Yes.

You could even stay in real mode, if you wanted, although i wouldn't recommend it.

However, i dont see how getting your OS kernel to switch to pmode is going to improve the process of making the switch. You'll still have as much opertunity to screw up the mode switch as with switching in the bootloader before loading the kernel.

Dangamoose.

RE:Pmode in C++???

Posted: Thu Jan 01, 2004 12:00 am
by Berry
Yes, but I ain't to good in ASM, but I know C/C++ very well! Or will I have to use as much assemby as by switching before kernel?

RE:Pmode in C++???

Posted: Thu Jan 01, 2004 12:00 am
by Dangamoose
Urm, well normally i would say yes, and as a rule of thumb yes, but according to carbonBased you can use C and C++ in real mode, and so therefore, a bootloader, something i thought you couldn't do.

But the bootloader is only a 510byte program, and using assembly would mean you'd be getting every much needed bytes worth of space into useful instructions.

Dangamoose.

RE:Pmode in C++???

Posted: Thu Jan 01, 2004 12:00 am
by carbonBased
Indeed... you're certainly gonna want to use assembly language for a boot loader.  Unless you're doing something fairly dramatic (like what Grub does), assembly is almost always your best choice.

Grub is written in C, but I'm sure you can also see that the actual boot sector, and any disk/hardware routines are written in assembly (stage1.S)

Cheers,
Jeff

RE:Pmode in C++???

Posted: Fri Jan 02, 2004 12:00 am
by Berry
Yes, but I mean, that I can make the bootloader in ASM and then load the kernel, and let the C++ kernel do the switch. I have taken a look at this: http://www.osdever.net/tutorials/pmodet ... ?the_id=19 They use C to make the switch. The only problem are the header files, like dos.h, that I must write

RE:Pmode in C++???

Posted: Fri Jan 02, 2004 12:00 am
by carbonBased
You _can't_ use C to switch from real mode to protected mode... and if you'd actually downloaded the source, you'll notice that there will be an assembly language routine that performs the actual switch.  They may _call it_ from C, but the operations are, indeed, done with assembly language.

This is one, in a list of things (although, not an overly large list), that _must_ be done in assembly language (or another low level language, such as Spinx C--, perhaps... if it even exists anymore).

You can certainly, as you want, switch to p-mode inside your kernel, rather then in the boot loader.  I did that with my first OS.  The only annoyance is that now your kernel has to have a real mode stub, with a protected mode kernel attached to it.  Personally (now) I like the idea of the boot loader switching to pmode, such that the kernel can just be one big linear executable, with no stub.

Again, though, it's personal preference.

Cheers,
Jeff

RE:Pmode in C++???

Posted: Fri Jan 02, 2004 12:00 am
by Berry
Yes, It still exist. C-- looks nicer than ASM. But where can I find tutorials? Because I don't know how to make this program:

----------------------------------------------------------------------
? include "WRITE.H--"

main ()              /* execution always starts at main () */
{
WRITESTR("Hello World!\n");  /* write the string to the screen */
}
--------------------------------------------------------------------

16 bits
start at 0x7C00
be 512 bytes long

I can use inline ASM with C--, buth this doesn't work:
times 510-($-$$) db 0

so what to do??

thanks for your help!!!

RE:Pmode in C++???

Posted: Sat Jan 03, 2004 12:00 am
by Berry
Sorry, I mean:

how can I make that piece off code:

16 bits
start at 0x7C00
be 512 bytes long

so that it can be my 'bootloader' (just for the test...)