NeoandClaude 14facfdebf Auto-assign new issues to Neo-Desktop (#17)
Add a workflow that adds Neo-Desktop as an assignee when an issue
is opened.


Claude-Session: https://claude.ai/code/session_01B82eRQqxennD6yGZo4WkoY

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 18:26:57 -08:00
2026-11-24 06:20:02 +00:00
2026-11-24 06:20:02 +00:00
2026-11-24 06:20:02 +00:00
2026-11-24 06:20:02 +00:00

OS/2 SDK for clang-retro

C programs for OS/2 with clang-retro's clang, picolibc and JWlink:

Target Triple Output Runs on
16-bit OS/2 1.x i8086-pc-os2 NE program or DLL OS/2 1.x, and 2.x to 4.x and ArcaOS
32-bit OS/2 i386-pc-os2 LX program or DLL OS/2 2.0 to 4.x, eComStation, ArcaOS
clang --target=i386-pc-os2 -Os hello.c -o hello.exe               # 32-bit
clang --target=i386-pc-os2 -mwindows -Os pmhello.c -o pmhello.exe # 32-bit PM
clang --target=i386-pc-os2 -shared -Os mylib.c -o MYLIB.DLL       # 32-bit DLL
clang --target=i8086-pc-os2 -Os hello.c -o hello.exe              # 16-bit, small model
clang --target=i8086-pc-os2 -mcmodel=large -Os app.c -o app.exe   # 16-bit, large model
clang --target=i8086-pc-os2 -shared -Os mylib.c -o MYLIB.DLL      # 16-bit DLL
python3 tools/os2-imports.py MYLIB.DLL > mylib.lnk                # its imports
clang --target=i8086-pc-os2 -Os app.c -Wl,@mylib.lnk -o app.exe   # a program that uses it

What's here

  • include/os21x/: the 16-bit OS/2 1.x API (os2.h): types, the Dos calls, Vio, Kbd and Mou, the error codes, and the OS/2 1.x Presentation Manager: windows, messages, frames, menus, dialogs, the controls, the clipboard and pointers (pmwin.h), presentation spaces, fonts and bitmaps (pmgpi.h), and the switch list and profiles (pmshl.h). Every function is __far __pascal with far pointers, as in the IBM and Microsoft toolkits. A 1.x message is a USHORT and its coordinates are SHORT, and the structures are the 1.x ones (QMSG is 26 bytes, bitmaps use BITMAPINFOHEADER), which tests/headers.c checks.
  • include/os2v2/: the 32-bit API (os2.h): the Dos calls (files and extended attributes, large files, memory, threads, semaphores and timers, queues, named pipes, sessions, exception handlers, modules and resources, national language support, messages, file systems and device IOCTLs), the error codes, and the Presentation Manager: windows and messages, frames, menus, dialogs, accelerators, the standard controls (buttons, entry fields, list boxes, combo boxes, scroll bars, MLEs, spin buttons), the clipboard, pointers and cursors (pmwin.h); presentation spaces, colors, lines, areas, paths, fonts and bitmaps (pmgpi.h); the window list and profiles (pmshl.h); and the file dialog (pmstddlg.h). APIENTRY is the C convention, which is what OS/2's _System is. The video, keyboard and mouse calls (Vio, Kbd, Mou), which are 16-bit on every OS/2, are in bsesub.h (see below).
  • lib/call16.c: the thunk from 32-bit code into the 16-bit API, built into libos2.a with a 16-bit stub for each call of bsesub.h.
  • lib/os2-16.lnk, lib/os2-32.lnk: import directives for every entry point of the OS/2 system DLLs (DOSCALLS, VIOCALLS, KBDCALLS, MOUCALLS, MSG, NLS, PMWIN, PMGPI and the rest). The driver gives them to the linker, which keeps only the imports a program uses. They were made by tools/gen-imports.py from the DLL export lists in Open Watcom's bld/os2api/lib286 and lib386 (the names and ordinals only).
  • tools/: gen-imports.py (above), check-headers.py, which checks that every function the headers declare has an import, and check-syntax.sh, which compiles tests/headers.c against both sets of headers and checks the sizes of the structures. CI runs both. os2rc.py is a resource compiler (see below). gen-bsesub.py writes bsesub.h and the 16-bit stubs. os2-imports.py lists the exports of a 16 or 32-bit DLL as import directives, for linking the programs that use it.
  • build-sysroot.sh: builds picolibc with its OS/2 layer, the compiler-rt builtins, and installs the headers and import lists: build-sysroot.sh 32 i386-os2 makes the 32-bit sysroot, and build-sysroot.sh 16 i8086-msdos adds the 16-bit libraries to the DOS sysroot, in lib/os2/<model> (and lib/os2/<model>/dll, below).
  • build-libcxx.sh: builds libc++ and libc++abi for 32-bit OS/2, with exceptions, RTTI and threads, into the i386-os2 sysroot, and the unwinder runtime/unwind-sjlj.c as libunwind.a.
  • build-libstdcxx.sh: adds GCC's libstdc++ to the i386-os2 sysroot, next to libc++ (see below).
  • examples/: hello.c, sysinfo.c and the PM window pmhello.c (all 16 and 32-bit), and the 32-bit PM program pmnotes.c (a menu, accelerators, dialogs and strings, from pmnotes.rc).

How programs are built

32-bit. clang compiles to ELF objects; JWlink links them with format os2 lx. crt0.o is first: OS/2 calls _start with the environment and the command line, which become environ and argv. The heap is address space reserved with DosAllocMem and committed as malloc grows it. Programs are marked to run in a window (pmcompatible); -mwindows marks a PM program. A DLL (-shared) starts with dllcrt0.o, is initialized for each process that loads it, and has its data per process. Mark its exports with __export (or VisualAge's _Export, or __attribute__((dllexport))): clang leaves an -export: directive for each in the object, which JWlink reads.

16-bit. clang compiles to OMF objects for a memory model (small, medium, compact or large; OS/2 has no tiny or huge model) and JWlink links them with format os2. The code is compiled as for 16-bit Windows: the stack segment may not be DGROUP, so va_list and returned structures are far. The heap is the rest of DGROUP, grown to 64 KiB with DosReallocSeg, in the small and medium models, and a 64 KiB segment from DosAllocSeg in the compact and large ones.

16-bit DLLs. -shared links a DLL with libentry.obj first. Like a 32-bit DLL it is initialized for each process that loads it (initinstance) and each process gets its own DGROUP (manyautodata), so the C library in the DLL keeps a state for each; the initialization sets up the heap and environ and runs the constructors. OS/2 1.x has no call when a DLL is freed, so destructors and atexit functions of a DLL do not run. Export functions with __export __far __pascal; exported functions load the DLL's DGROUP into DS themselves, as with __loadds. A DLL runs on the stack of the thread that calls it, so SS is not DS and a near pointer cannot point to a local. In the small and medium models clang (-mwindows-dll, which -shared gives) keeps the locals whose address escapes in a frame in DGROUP instead, from a 4 KiB region for each thread taken from the DLL's heap; a DLL that needs more defines unsigned short __os2_dll_frame_size = 8192;. The C library built this way is in lib/os2/<model>/dll, which clang links with -shared. Compact and large DLLs need none of it.

Vio, Kbd and Mou from 32-bit code. These calls are 16-bit far Pascal functions in VIOCALLS, KBDCALLS and MOUCALLS. Each function of bsesub.h is an inline one that lays out the 16-bit arguments and calls __os2_call16 (lib/call16.c, in libos2.a, which the driver links). That switches to a 16-bit stack of the thread's own and jumps to the call's stub, 16-bit code in the program that calls the function (call far VIO16WRTTTY, fixed up by the loader as in a 16-bit program) and comes back. Pointers become 16:16 ones through the tiles of OS/2's memory, and a buffer that crosses a 64 KiB boundary is copied for the call.

Resources. tools/os2rc.py compiles a .rc file in the OS/2 toolkits' resource language (STRINGTABLE, MENU, ACCELTABLE, DLGTEMPLATE with DIALOG, FRAME, WINDOW, CONTROL and the predefined controls, RCDATA, ICON, POINTER, BITMAP, FONT and user types, with #include and #define from the headers) and binds the resources into a program: a 32-bit one gets one more object in its LX file, and a 16-bit one a segment for each resource in its NE file, which DosGetResource2 returns:

clang --target=i386-pc-os2 -mwindows -Os pmnotes.c -o pmnotes.exe
python3 tools/os2rc.py -I include/os2v2 examples/pmnotes.rc pmnotes.exe
python3 tools/os2rc.py -l pmnotes.exe     # list the resources
python3 tools/os2rc.py app.rc app16.exe   # a 16-bit program: os21x headers

-r compiles to a .res file only, which a later run binds (-16 -r for a 16-bit program, whose .rc sees the os21x headers).

The C library is picolibc with an OS/2 layer (libos/os2): a file descriptor is the OS/2 file handle, and \n is written as \r\n to the console and other devices. Files are binary. Directories are read with opendir and readdir (DosFindFirst); getcwd, chdir, getpid and getppid work too. chdir sets the current directory of a drive but does not change the current drive.

OS/2 has no fork, so programs are started with DosExecPgm: system runs COMSPEC (or CMD.EXE from the PATH) with /c, and <process.h> has the spawn calls of OS/2's C compilers (spawnl, spawnv, spawnvp, spawnle and the rest). P_WAIT returns the program's exit code, and P_NOWAIT its process id, which waitpid and wait wait for. exec starts the program and exits with its exit code. A name without an extension gets .EXE, and the p forms search the current directory and then the PATH. pipe, dup and dup2 work on OS/2's handles, and popen runs the command with this program's end of the pipe kept from it, so pclose gives it the end of its input.

Threads and C++

32-bit programs have threads: <threads.h> (C11 thrd_create, mutexes, condition variables, tss) runs on DosCreateThread and OS/2's mutex and event semaphores, the C library locks itself, and __thread variables, errno among them, are per thread through clang's emulated TLS. The OS/2 Dos calls for threads and semaphores are in os2.h too.

C++ programs (clang++ --target=i386-pc-os2) link libc++ once build-libcxx.sh has run:

BIN=/path/to/clang-retro/bin LLVM_SRC=/path/to/llvm \
  sh build-libcxx.sh /path/to/clang-retro/i386-os2

Exceptions unwind through setjmp/longjmp-style function contexts (an LX program keeps no tables for a table-driven unwinder), one chain per thread. std::thread, std::mutex, std::condition_variable, thread_local and steady_clock work. The terminate message does not demangle names, which keeps programs smaller.

GCC's libstdc++ (15.2.0, compiled by clang) is the other C++ library. build-libstdcxx.sh adds it, and -stdlib=libstdc++ selects it. docs/libstdcxx.md tells how it is built and what it has.

Testing

tests/ boots OS/2 Warp 3 from its two boot diskettes in QEMU and runs programs from a diskette in drive B: (see tests/README.md). The 16-bit examples pass in all four memory models, and the 32-bit ones pass too. tests/dosapi.c exercises the 32-bit Dos calls (exception handlers, semaphores, queues, named pipes, timers, NLS, file systems, messages and extended attributes), tests/restest.c reads back the resources os2rc.py bound into it with DosGetResource (16 and 32-bit), tests/posix.c tries the directory calls of the C library, tests/spawn.c starts itself with spawn, exec, system and popen and tries pipe (16 and 32-bit), tests/threads.c the C11 threads, locks and per-thread errno, tests/cxx.cpp C++ exceptions (in four threads at once too), RTTI, iostreams and std::thread, and tests/vio.c the Vio, Kbd and Mou calls from 32-bit code. tests/testdll.c is a 16-bit DLL that uses the C library and tests/dllapp.c a program that calls it, and starts itself again to check that the DLL's data is per process. All pass on Warp 3, the DLL in all four memory models. Warp 3's boot diskettes have no Presentation Manager, so PM programs are only built.

Not yet

  • Threads calling into a 16-bit DLL at once: the 16-bit C library is built for one thread.
  • The rarer Vio, Kbd and Mou calls from 32-bit code: bsesub.h has 39 common ones, and a call is added with a line in tools/gen-bsesub.py.
  • Threads and C++ in 16-bit programs.

License

Copyright (C) clang-retro contributors.

The clang-retro OS/2 SDK is free software under the GNU Affero General Public License, version 3 only (AGPL-3.0-only); the full text is in LICENSE. If you distribute a program built with it, or let people use a modified version over a network, you must offer the program's complete source under the same license.

Each contributor keeps the copyright in their own work and contributes it under the same license; see CONTRIBUTING.md.

S
Description
No description provided
Readme AGPL-3.0
282 KiB
0 Stars 1 Watchers 0 Forks
Languages
C 76.1%
Python 16.5%
Shell 4.4%
C++ 3%