Page 1 of 1

Using GCC for 16bit development

Posted: Mon Feb 11, 2008 7:37 am
by AlfaOmega08
Hi everyone
I've wrote my bootloader, so than it loads and jump to the C kernel in real mode with A20 disabled. I'd like to do all the pmode initializing in C. How can I configure GCC or LD to give me 16 bit code?

Posted: Mon Feb 11, 2008 7:56 am
by AJ
Hi,

My advice to you is to use assembly language. As one of the major parts of PMode initialisation, you will want direct control of the segment registers. GCC assumes a flat memory model with no segmentation. I think you will be doing yourself a favour by writing an assembly stub to do the required switching.

IIRC (I have never used a 16 bit C compiler), GCC is generally not used for 16 bit programming. The people in this community who do 16 bit C seem to use Turbo C.

Cheers,
Adam

Posted: Mon Feb 11, 2008 8:19 am
by Solar
Binutils (2.9.1.0.25+) now fully support 16-bit mode (registers and addressing) on i386 PCs. Use .code16 and .code32 to switch between assembly modes.

Also, a neat trick used by several people (including the oskit authors) is to force GCC to produce code for 16-bit real mode, using an inline assembly statement asm(".code16\n"). GCC will still emit only 32-bit addressing modes, but GAS will insert proper 32-bit prefixes for them.
Use this at your own risk. It is a feature seldom used, and that means it is a feature seldom tested. I'm not sure if the GCC people officially support it at all.

Posted: Mon Feb 11, 2008 9:39 am
by binutils