Today I decided to publish my old project idea brewing ten years, but only make possible with the help of AI Tools, from which I only use the free version of Google Gemini AI using a dialog styled workflow, implement, compile, check errors, testing, and fixing bugs. This limit to Small chunks of code, but it is more easy to avoid bugs, and forces a better Control to the AI to make their best job, which is writing boilerplate Code, once a stable blueprint was made.
The project is simple as it displayed by own GitHub page, this is a fork of Wine with a secundary Subsystem to Run User Mode OS/2 programs, the Legendary IBM Operating System from late 1980s and smashed by Microsoft at late 1990s, where both was designed together, before the breakup. Since OS/2 Share many DOS/Windows concepts like letter mounted disk partitions, file extensions like DLL for libraries and EXE for executable files, and the kernel Code shared the GDI and NT Code (In reality IBM and Microsoft had worked together to Build OS/2, and then the Windows NT and GDI32 was derived from OS/2!), using Wine is not only a convenience, it is the only realistic method to Build the Core OS/2 DLLs (Doscalls, viocalls, pmwin, etc) Over the Wine DLLs (NTDLL, gdi32, etc) since the structures and functions are very similar and more natural to wrap around.
To Build the subsystem after using Gemini AI to query methods, and my own design choices, the project started as a loader called wineos2.exe which is a 32-bits Windows PE program that their Task os to Attach the OS/2 program (at corrent stage 16-bits NE files are correctly parsed, and started. 32-bits LX files requires some work to launch them), scan the system DLL and ordinais e Run the program. Due to historical decisions by IBM (which caused Microsoft to hire Cutler to Build Windows NT as pure 32-bits OS), they wanted to support the 286 CPU. Now running protected mode 16-bit with preemptive multithreading on modern 64-bits Linux would be a cathastrophic Nightmare, if the ancient Code Run directly on host CPU. The Gemini also Said a Big NOT to use modify_ldt, and persue a full CPU emulation instead. so I requested to wrote a Ring 3 286 CPU emulator (that was placed on include Folder from Wine source Code), and after 30 cycles of debugging some opcodes was still left. But after Ten days, the first programs (coded with Watcom Assembler for DOS running on DosBox) Run with success, printing with the DosWrite API call from Doscalls.dll (the OS/2 cousin of NTDLL, which the NTAPI from Wine actually implemented many functions!). The emulator itself is almost 3000 lines of old styled C Code and shared on OS/2 DLLs.
The Next step, that was also a thug-of-war between mine models and Gemini suggestions ended with a porper DLL blueprint. OS/2 DLL on mine project are normal 32-bit PE DLL that are built using the Wine Build Tools, without changing a single line of code. Inside them they import both the normal Windows includes, and the OS/2 types and 286 emulator header file (the emulator Code was placed inside a single file) that supports some custom macros. The DLLMain function also allocates a table of ordinais for the 16-bits functions, where wineos2 at startup allocate with a single step the ordinal tables at the LDT table which is a 8192 Arrays for the active program. This feature os part of the 286 emulator. The 16-bits functions only had the emulator context as an argument and inside them it makes marshmalling of the emulator registers to pass the Pascal stack to the 32-bit function, which have the arguments of the official IBM documentations, and then the 32-bit function done the real work using NTAPI and Win32API and return back. The emulator itself it a opcode interpreter, where the opcode 9A Will call the wine_thunk C function and pass the LDT register to call the 16-bit function on the target DLL! And the 16-bit call the 32-bit function and return to the emulator advancing the number of bytes on program counter register given by the 16-bits functions.
Like any Wine DLLs, All symbolic ordinais is placed on spec files, with the gear mounted for LX support which due to 32-bits Nature should Run natively and call the symbolic function directly with native arguments without calling the 16 to 32-bits bridge.
Like the historical OS/2 Subsystem for Windows NT (3.1 to 2000), the subsystem configuration was stored on Windows Registry. Currently the subsystem configuration os not working properly, but the clues are more or less projected. Config.sys is placed on Registry hive, and like NT only LibPath, PROTSHELL and COMSPEC are theoretically supported. Other commands like country, ou Path, may be added, but anything related to Device or other settings like threads are totally ignored. Similar Os2.ini and os2sys.ini are ONLY stored on Registry, but without use for now.
Also I added a Small Control Panel Applet for OS/2 Subsystem Configuration, but it is a long WIP that actually wrote on Registry (It stored the simulated OS/2 version, which is OS/2 2.1 for now).
For now OS/2 programs call Open 64-bits Windows programs using the DosExecPgm API call from Doscalls, or other OS/2 programs, that Will start a New OS/2 loader program, with their own LDT.
As a curiosity, under Wine-os2 a 16-bit program had Access up to 512 MB of RAM (the product of 64kb and 8192 LDT selectors), but Im reality, a single LDT entry to a function ordinal removes a LDT entry. And RAM allocation, although with a flat 32-bits allocation using NTAPI calls, it needs to place a symbolic Key on the LDT for each 64 kb or the 16-bit Code would Crash quickly. Also the first 16 selectors are banned by Memory allocation and ordinal linking due to the 286 nature and the factor that pointed to the first megabyte of RAM that on a real OS/2 1.3 Machine was reserved for kernel mode Code like the OS/2 kernel (called os2krnl) and drivers, and also for the single DOS program (286 can ONLY Run a Single DOS APP without any hardware protection). This means the Selector O is the null Pointer that on real machines cause a kernel panic ou general protection fault which the emulator call DosExit to stop wineos2 safely. Selector 1 to 9 was the Conventional Real Mode Memory shared by DOS and OS/2 kernel (the DOS Coffin zone!). Selector 10 and 11 was shared with video framebuffers, while Selector 12 to 15 to the BIOS and hardware ROMS shared area. Wine-OS/2 simply Lock those selectors to use them, unless in the future may be useful.
The project itself is at early stages, ONLY some console programs (and could make more using assembly) works, bugs are been chased and fixed. It may take a while until the Presentation Manager (the GUI part of OS/2) starting to work. AI was fantastic to wrote parts of Code, but without a strong guidance, the work would be just an huge pile of scrap that neither compiles or neither works at All.
I wanted just to publish my work, and I want to implement step by step with my own work, and suggestions are welcome.