g++ 16bit

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Su

g++ 16bit

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

Re:g++ 16bit

Post 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.
Every good solution is obvious once you've found it.
jinksys

Re:g++ 16bit

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

Re:g++ 16bit

Post 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.
Every good solution is obvious once you've found it.
jinksys

Re:g++ 16bit

Post by jinksys »

::edited, what I said was about the same thing solar mentioned.
Post Reply