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,__farand__huge(also with one underscore) qualify data pointers and variables, and choose the call of functions and member functions;__pascalis the 16-bit Windows API convention, and__exportmarks a function or variable for export;__loaddsloads DGROUP intoDSon entry;__interruptmakes an interrupt handler that saves every register and returns withIRET;-mwindows-prologue=exported(orall) gives far functions the 16-bit Windows entry sequence, as Open Watcom-zW(-zw) does, and-mwindows-dllcompiles 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*,BSWAPor atomics; with-march=i386or later, 16-bit code uses them. - Calls to
printfandscanfgo to picolibc's integer-only versions when the format allows, which saves several KiB. thread_localvariables 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.