tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
167 stars 12 forks source link

is flat memory model supported? #121

Open stsp opened 1 year ago

stsp commented 1 year ago

Hi, just a quick question. Does ia16-gcc support flat memory model? I.e. I want to be able to construct flat pointers from 32bit ints (staying within 1st MB of course), and on a dereference of such a pointer, gcc should convert it to seg/off pair. This will allow to port some existing 32bit code. Is that possible?

tkchia commented 1 year ago

Hello @stsp,

There is no support for linear addressing yet — but it does sound like such a thing might be useful. :thinking:

Thank you!

ddejean commented 2 months ago

Hi,

Actually this is partially supported if you use far pointers in C. If you declare a far pointer like: char __far *str it will be a 32 bits pointer that allows you to address anywhere in your memory. However, the 32 bit address stored in the pointer will have the following representation : segment << 16 | offset where segment is the value that should be set in the segment register. For instance a pointer to somewhere in the segment 1 at offset xxxx will be an adress like 0x1000xxxx. Which prevent from doing pointer arithmetic as if it was a linear address space.

@tkchia is there any particular reason why this representation was chosen ? Would it be possible to use a representation like 0x000axxxx where a is the segment number and xxxx the offset ? It would then allow to consider the full address space as flat, and would allow pointer arithmetic to work. It would be more work on code generation side tho.