Page 1 of 1

g++ 16bit

Posted: Fri Jul 02, 2004 6:39 am
by Su
Hi,

I want to create a 16bit OS in C++.

Which parameter do i need for g++ (under linux) to create a bootable 16bit image?

thank you very much for you help :)

Re:g++ 16bit

Posted: Fri Jul 02, 2004 7:50 am
by Solar
As far as I understood it, GNU as (used as a backend for GCC) is unable to generate "pure" 16bit code, which would mean you're out of luck in generating 16bit code with GCC.

I might be wrong, though.

Re:g++ 16bit

Posted: Fri Jul 02, 2004 11:15 pm
by jinksys
gcc/gas provides the .code16, .code16gcc directives for producing 16 bit
code. LD provides a flat binary format for producing binary images.
You can read up about .code16 in the man pages.

Re:g++ 16bit

Posted: Sun Jul 04, 2004 11:59 pm
by Solar
jinksys wrote: gcc/gas provides the .code16, .code16gcc directives for producing 16 bit
code.
While GAS is capable of generating 16 bit code if you know exactly what you're doing as even .code16 doesn't guarantee your code will run on a 286, it's a different ballgame when you're using it in the GCC - GAS - LD toolchain.

GCC generates 32bit code per se, and even .code16gcc doesn't really help with that. From the binutils man's:
.code16gcc provides experimental support for generating 16-bit code from gcc, and differs from .code16 in that call, ret, enter, leave, push, pop, pusha, popa, pushf, and popf instructions default to 32-bit size. This is so that the stack pointer is manipulated in the same way over function calls, allowing access to function parameters at the same stack offsets as in 32-bit mode. .code16gcc also automatically adds address size prefixes where necessary to use the 32-bit addressing modes that gcc generates.
So, no luck in making G++ spit out 16bit code I'm afraid.

Re:g++ 16bit

Posted: Mon Jul 05, 2004 12:49 am
by jinksys
::edited, what I said was about the same thing solar mentioned.