Skip to content

The 8086 backend

The fork adds i8086 (also spelled i8088, i86 and ia16), 16-bit real-mode x86, to the X86 backend. Code runs on the 8086 and 8088 and on every later x86 CPU.

Memory models

-mcmodel= picks how code and data are addressed:

Model Code Data size_t Notes
tiny near near 16 one 64 KiB segment for everything, a .COM file
small (default) near near 16
medium far near 16 each source file gets its own code segments
compact near far 16
large far far 16
huge far huge 32 pointer arithmetic carries into the segment
huge with -msize-t=16 far huge 16 Open Watcom's huge model

A source file's code over 64 KiB goes on in more code segments in the models with far code. In the far-data models, a variable larger than -mlarge-data-threshold= (32767 bytes by default) gets a segment of its own outside DGROUP, and vtables and type_info objects are far data too. Choosing a memory model helps you pick one.

Keywords

As in Open Watcom and Microsoft C:

  • __near, __far and __huge (also with one underscore) qualify data pointers and variables, and choose the call of functions and member functions;
  • __pascal is the 16-bit Windows API convention, and __export marks a function or variable for export;
  • __loadds loads DGROUP into DS on entry;
  • __interrupt makes an interrupt handler that saves every register and returns with IRET;
  • -mwindows-prologue=exported (or all) gives far functions the 16-bit Windows entry sequence, as Open Watcom -zW (-zw) does, and -mwindows-dll compiles code for a Windows DLL, which runs on its caller's stack.

The dos-sdk pages describe each with examples.

Objects and code

  • Objects are OMF, as DOS linkers expect. Each function and variable has its own section by default, written as a COMDAT, so the linker drops what nothing uses. Names longer than 255 bytes are hashed.
  • Jump tables live in the code segment and are read through CS.
  • Before the 386 there is no BT*, BSWAP or atomics; with -march=i386 or later, 16-bit code uses them.
  • Calls to printf and scanf go to picolibc's integer-only versions when the format allows, which saves several KiB.
  • thread_local variables are ordinary ones on DOS.

C++

libc++, libc++abi and the unwinder build for every model, with changes that keep programs small: a slim ctype for char streams, facets made on first use, a compact std::sort, std::cin and the wide streams in objects of their own, and abort messages without vfprintf. Exceptions use SjLj (setjmp/longjmp) unwinding, and RTTI works with -frtti.