Using GCC for 16bit development

Programming, for all ages and all languages.
Post Reply
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Using GCC for 16bit development

Post 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?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

Post Reply