I want to write my kernel in C and in 16 bit (real mode) (I need 16 bit for some reasons)
I've writen the bootloader in asm 16bits and its working correctly ,
I tried to use a small kernel in C (16 bits) to print a message on the screen , but it doesn't work ! (when booting the bootloader goes ok but the kernel doesn't work(nothing happen)) , possible reasons are:
+the kernel is compiled in 32bit mode and not in 16bit mode (to compile my c code I used asm("code16gcc \n") in the beginning of the source file ), so is this method the write way to compile it in 16bit mode,
+second possible reason is that my kernel is not in binary format (i.e the executable hase a header) , so how do I compile to get binary format
My question : How can I compile a C code in 16bit mode
what's the syntax of the gcc command to use for that an to get a binary file (I use : gcc -ffreestanding -o kernel.out kernel.c and I tried some others)
thenk you for reading all of this
Write a Kernel in C 16bits
-
- Posts: 3
- Joined: Tue Jul 17, 2007 3:35 pm
- Contact:
Hi,
I always use ld and linker script, where it is quite easy to specify an output format - I don't know if you can do this directly in gcc without cross-compiling (please correct me if I'm wrong)...
I understand that when most people ask about doing 16 bit kernels, a version of Turbo C is generally recommended - you may need to investigate whether you are using the appropriate toolchain.
Out of interest, what are the "some reasons" for using real mode? Maybe it would be better to find workarounds to allow you to go to PMode or Long Mode?
Cheers,
Adam
I always use ld and linker script, where it is quite easy to specify an output format - I don't know if you can do this directly in gcc without cross-compiling (please correct me if I'm wrong)...
I understand that when most people ask about doing 16 bit kernels, a version of Turbo C is generally recommended - you may need to investigate whether you are using the appropriate toolchain.
Out of interest, what are the "some reasons" for using real mode? Maybe it would be better to find workarounds to allow you to go to PMode or Long Mode?
Cheers,
Adam
-
- Posts: 3
- Joined: Tue Jul 17, 2007 3:35 pm
- Contact:
thank you AJ,
my "reasons" : I've just writen that so that no body says to me change to the 32 bit mode it's better than 16 bit , (I want just to start with the 16 bit (it's easier) and then I'll switch to the 32 bit (that will not take a lot of time)
so is there any other suggestion or solution for the problem,,
my "reasons" : I've just writen that so that no body says to me change to the 32 bit mode it's better than 16 bit , (I want just to start with the 16 bit (it's easier) and then I'll switch to the 32 bit (that will not take a lot of time)
so is there any other suggestion or solution for the problem,,
-
- Member
- Posts: 223
- Joined: Thu Jul 05, 2007 8:58 am
one advice, do not underestimate the change from real mode to protected mode, this is not as easy as you might think, cause in real mode you can (and thus often do) use bios interupts. When you do the switch to protected mode this means you will have to rewrite a lot of your drivers.
Another reason to start developing in protected mode is that you can implement certain thing (multitasking, paging, etc.)
Another reason to start developing in protected mode is that you can implement certain thing (multitasking, paging, etc.)
I agree.
It's a useful start to be able to develop in real mode - perhaps by writing a boot loader (as you have) as it gives you some idea how the processor starts, what the BIOS does etc...
However, if you plan to eventually use pmode or long mode, I would go there straight away - certainly don't expect to easily port a real mode kernel (or the apps that run on it).
I'm developping my kernel in 32 bit protected mode and am already wondering if that will be too out of date and I should attempt a long mode port...
Cheers,
Adam
It's a useful start to be able to develop in real mode - perhaps by writing a boot loader (as you have) as it gives you some idea how the processor starts, what the BIOS does etc...
However, if you plan to eventually use pmode or long mode, I would go there straight away - certainly don't expect to easily port a real mode kernel (or the apps that run on it).
I'm developping my kernel in 32 bit protected mode and am already wondering if that will be too out of date and I should attempt a long mode port...
Cheers,
Adam
take a look at this post maybe it will help:
http://www.osdev.org/phpBB2/viewtopic.p ... nel+16bits
http://www.osdev.org/phpBB2/viewtopic.p ... nel+16bits
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
32-bit protected mode is probably actually easier for a first-timer. Especially if you use GRUB as your boot-loader as it makes sure you're already in protected mode .baghdadi13 wrote:thank you AJ,
my "reasons" : I've just writen that so that no body says to me change to the 32 bit mode it's better than 16 bit , (I want just to start with the 16 bit (it's easier) and then I'll switch to the 32 bit (that will not take a lot of time)
so is there any other suggestion or solution for the problem,,
Plus, a switch from 16-bit to 32-bit is sometimes (not always) difficult (you'll find protected mode is very different).
-
- Posts: 3
- Joined: Tue Jul 17, 2007 3:35 pm
- Contact: