Add build-sysroot.sh: a ready-made classic Mac OS sysroot
mac-sdk
A redistributable SDK for classic Mac OS applications built with clang (clang-dos/llvm): System 0.1 to Mac OS 9, on 68k and PowerPC.
Headers
include/ has the Toolbox headers. Include them the way Apple's
Universal Interfaces are included (#include <Quickdraw.h>,
<Windows.h>, <Events.h>, ...) or all at once with
<Multiverse.h>. The same headers work for both targets:
clang --target=m68k-apple-macos -O2 -Iinclude -c hello.c # 68k
clang --target=powerpc-apple-macos9 -O2 -Iinclude -c hello.c # PowerPC
- On 68k, Toolbox calls are
pascalfunctions whose calls become their trap words (__attribute__((raw_inline(...)))). Register-based traps (most OS traps, such asNewPtr,GestaltandDelay) are inline functions that load the registers and emit the trap. - On PowerPC, the calls are plain declarations that the linker imports from InterfaceLib and the other shared libraries.
- Records use 68k alignment on both CPUs, as on a real Mac, so they
have the sizes Inside Macintosh gives (
tests/sizes.cchecks them). - 32-bit types are
long, as in Apple's headers, so existing code that passeslong *compiles unchanged.
examples/hello.c uses them; built as a fat application it runs on
every System we have, from System 0.1 on the Mac 128K to Mac OS 9.2.1
on PowerPC, in emulators (MAME, QEMU and SheepShaver).
Which System has which call
docs/systems.md lists, for every call in the headers, the oldest
System that provides it, measured by booting each System we have (29
System and machine pairs, from 0.1 to 9.2.1) and recording its trap
tables, packages and Gestalt selectors (tools/probe/trapprobe.c,
tools/availability.py, data in data/availability.tsv).
TrapAvailable(trap)(OSUtils.h) says at run time whether a trap exists, on every ROM from the 64K ROM on. Check it before calling a trap newer than the oldest System you support, for exampleif (TrapAvailable(_Gestalt)) Gestalt(...).-DMAC_MIN_SYSTEM=0x0605makes clang warn at each call that needs a newer System than 6.0.5 (or a manager Gestalt must report, such as QuickTime).-DMAC_NO_COLOR_QDwarns at each Color QuickDraw call, for the Mac Plus and SE. Without them the headers warn about nothing.- On the 64K ROM the Memory Manager does not set
MemErr, so the 68k calls store D0 there themselves andMemError()works on every System.
Mac OS 8
The Mac OS 8 Toolbox is declared too: the Appearance Manager
(<Appearance.h>), the Control Manager's embedding, keyboard focus and
control data calls with the Appearance control definitions
(<Controls.h>, <ControlDefinitions.h>), the Menu, Dialog and Window
Manager additions (menu command IDs, MenuEvent, StandardAlert,
AutoSizeDialog, window collapsing), the Collection Manager
(<Collections.h>), the Contextual Menu Manager
(<ContextualMenu.h>) and the calls that show and hide the Control
Strip (<ControlStrip.h>).
- What Mac OS 8.0 and 8.1 ran on 68k Macs has its trap and selector,
read from the 68k glue in 8.1's AppearanceLib and 9.2.1's
CollectionsLib (
data/trapinfo-os8.json). The Contextual Menu Manager is trap 0xAA72 with selectors 1 to 4, as the Contextual Menu Extension installs it. - Mac OS 8.5 dropped 68k Macs, so its new calls (Appearance Manager 1.1,
Window Manager 2.0's
CreateNewWindow, window proxies and properties, the 32-bit control values, ...) are declared for PowerPC only. On 68k they are left out, so a call to one fails to compile. - The bevel button, image well, tab and disclosure triangle accessors
are inline calls to
GetControlDataandSetControlDataon 68k.
examples/appearance.c draws with the theme, builds a hierarchy of
Appearance controls and uses a Collection and menu command IDs. Built
fat, it runs on Mac OS 8.1 on both a 68k Mac (QEMU's q800) and a
Power Mac (SheepShaver). Appearance 1.0.1 in 8.1 has no auto-toggling
check boxes or radio buttons (kControlCheckBoxAutoToggleProc draws
an ordinary check box), so the example toggles its check box itself.
Mac OS 9
The calls new in Mac OS 8.5 to 9.2 are declared too: the HFS Plus API
(FSRef, Unicode names, forks, catalog iterators and bulk calls),
Icon Services, Folder Manager 9 (folder descriptors and routing), Power
Manager 2, Sound Manager 3.x (sound converters, output info), Display
Manager 2, anti-aliased text, the VM and resource-file additions, the
Thread Manager (<Threads.h>), Multiprocessing Services
(<Multiprocessing.h>), the Text Encoding and Unicode Converters
(<TextCommon.h>, <TextEncodingConverter.h>, <UnicodeConverter.h>),
URL Access (<URLAccess.h>) and the Keychain Manager (<Keychain.h>).
- Mac OS 9 still runs 68k applications in its emulator, and the
PowerPC glue in 9.2.1's InterfaceLib and its other libraries still
calls a 68k trap for many of these. Those calls have that trap and
selector on 68k (
data/trapinfo-os9.json;tools/retrap.pyattaches them to definitions that had none). The high-level HFS Plus calls (FSOpenFork,FSGetCatalogInfo, ...) are inline glue that fills in a parameter block and calls thePB...Synctrap, as 9.2.1's glue does. - The Thread Manager is trap 0xABF2 on 68k (System 7.5 and later, or the Thread Manager extension). Its callbacks are plain function pointers on PowerPC too, as in Apple's headers, not routine descriptors.
- Multiprocessing Services, the converters, URL Access and the Keychain live in PowerPC-only libraries, so they are declared for PowerPC only. On 68k a call to one fails to compile.
examples/macos9.c runs three cooperative threads, reads the System
Folder's Unicode name with FSFindFolder and FSGetCatalogInfo, plots
its icon with Icon Services and checks anti-aliased text on both CPUs,
and on PowerPC sums numbers in a preemptive MP task and converts Mac
Roman text to UTF-8 with the Text Encoding Converter. Built fat, it runs
on Mac OS 9.2.1 (QEMU's mac99) as PowerPC code, and its 68k build runs
there in the 68k emulator.
QuickTime
<Movies.h>, <ImageCompression.h>, <QuickTimeComponents.h>,
<MediaHandler.h>, <ImageCodec.h> and <MoviesFormat.h> declare the
QuickTime 1.5 API: the Movie Toolbox, the Image Compression Manager, the
movie controller, sequence grabber, standard compression, video
digitizer, media handler and codec component calls (662 calls), with
QuickTime's own 68k code (0xAAAA for the Movie Toolbox, 0xAAA3 for
the Image Compression Manager, _ComponentDispatch for components). On
PowerPC they import from QuickTimeLib. Some 1992 names were renamed or
became macros before QuickTimeLib shipped (SetImageDescriptionExtension,
MCGetMovie, ...); those link on 68k only. <MoviesFormat.h> has no
declarations: the movie file atom records are not in the documentation
that the definitions are written from.
examples/quicktime.c lists the installed compressors, draws 30 frames
in a GWorld, compresses them with the Animation compressor into a new
movie file, opens the file again and plays it in a loop under the
standard movie controller. Its 68k build runs on System 7.1 with
QuickTime 1.5 (QEMU's q800), and built fat it runs as PowerPC code on
Mac OS 9.2.1 with QuickTime 5.
Old routine names
Code written before 1993 uses the original names (GetCtlValue,
DisposPtr, GetDItem, SetCTitle, IUGetIntl, TextBox, ...).
Compile with -DOLDROUTINENAMES=1 and they map to the current ones, as
with Apple's interfaces; 92 names are covered.
Where they come from
The headers are generated by tools/gen-headers.py from the API
definitions in defs/, which come from
Multiversal Interfaces
(MIT license, defs/COPYING.multiversal). Those were derived from the
clean-room Executor project, not from Apple's headers, so they can be
redistributed freely. To regenerate after changing a definition:
pip install pyyaml
python3 tools/gen-headers.py
Since then the definitions have been extended here with the rest of the documented Toolbox: the Component, Display, Text Services, Power, Slot, SCSI, Cursor Device, MIDI, Dictionary and Data Access Managers, the PPC Toolbox, AppleTalk (MPP, ATP, NBP, ZIP, ASP and AFP), Ethernet, the Communications Toolbox (Connection, Terminal and File Transfer Managers, the Communications Resource Manager and the CTB utilities), the HFS Plus API and more.
The QuickTime definitions (defs/QuickTime.yaml) follow Inside
Macintosh: QuickTime and Inside Macintosh: QuickTime Components
(1993): each call, record, type and constant in the file is one that
those books document, with the books' names. The 68k code of each call
(its trap and selector) and the record layouts are interface facts,
checked against QuickTime 1.5 itself (the examples run on it, above).
Calls, records and constants that the books do not document are not in
the file.
tools/mpw2defs.py reads a copy of Apple's MPW C interfaces that you
have and writes definitions from them. Use it only as a local check, to
compare with defs/: do not commit its output, which comes from Apple's
headers.
Checked against a real ROM
The 68k trap words and selectors are checked against the Mac OS ROM. A Power Macintosh ROM contains InterfaceLib, whose PowerPC glue calls each 68k trap through the Mixed Mode Manager; that glue names the trap, the selector and where each argument goes.
tools/trapinfo.py ROM > data/trapinfo.jsonreads that glue (from a 4 MB OldWorld ROM image, such as the Beige G3's) and records each call. The checked-indata/trapinfo.jsoncame from the Beige G3 ROM.tools/check-traps.pycompares every call in the headers with it. All 1,960 calls that the ROM and the Mac OS 8 and 9 libraries describe match.tools/add-protos.py defs/X.yaml < protos.hturns C prototypes into definitions, with the 68k details fromdata/trapinfo.json, and refuses a prototype whose argument sizes disagree with the ROM.tools/add-types.pydoes the same for records and constants.tools/blockinfo.py ROM > data/blockinfo.jsondoes the same for the Communications Toolbox calls, which pass their arguments as a block (laid out like Pascal arguments under a selector word, with A0 pointing at it) to_CommToolboxDispatch. It records the selector and each argument's offset and size;tests/blocks.pychecks all 166 such calls in the headers against it. It needsllvm-mcwith the PowerPC target.tools/check-mpw.py path/to/CIncludes [more dirs]compares the 68k code of every call with the inline code in Apple's MPW C interfaces (the trap word, and the selector loaded before it, however it is loaded). Against MPW 3.2's interfaces (June 1992) and QuickTime 1.5's, all 2,105 calls both declare match; the 18 MPW calls it reports missing have C or glue equivalents here (the low-memory accessors,Fix2Xand friends).tools/coverage.pywrites docs/coverage.md.
Calls with no trap of their own get their 68k glue as inline C in the
headers (m68k-body in the definitions; tools/set-body.py adds it).
The AppleTalk calls set the driver and control code and call PBControl,
as the ROM's PowerPC glue does; the high-level File Manager, Device
Manager and serial calls fill in a parameter block; the lowercase
C-string calls (fsopen, getwtitle, ...) convert their strings and
call the Pascal routine. The glue avoids memcpy, memset and 32-bit
multiplies, so the headers work without the runtime library (BlockMoveData
copies instead). The exceptions are the FixMath conversions between
Fixed or Fract and floating point (Fix2X, X2Fix, Frac2X, X2Frac)
and the 64-bit wide arithmetic (WideAdd, WideMultiply, WideDivide,
...), which use soft float and 64-bit helpers and so need the runtime
library (X2Fix and X2Frac round to nearest and saturate, as SANE
does). The wide calls follow QuickDraw GX's documentation, where they
came from: WideDivide and WideWideDivide round the quotient when
given no remainder, a WideDivide quotient that does not fit is pinned
to 0x7FFFFFFF or 0x80000000, WideShift rounds a right shift and
WideBitShift does not, and WideSquareRoot takes an unsigned value
(its root is rounded to nearest, which the documentation does not say).
SetUpA5 and RestoreA5 keep the saved A5 in a common block of 32
slots rather than on the stack as MPW's do, since clang addresses locals
from SP; they nest, also from interrupts, up to 32 deep. The Power
Manager extras (BatteryStatus, ModemStatus and the wakeup timer)
send the same _PMgrOp commands as MPW's glue (from the 1992
Interface.o), and SetSoundVol makes the same control call to the
Sound Driver. TESetWordBreak and TESetClickLoop take a
pascal Boolean function, as MPW's did, and install a trampoline that
TextEdit calls with its arguments in registers and its answer in the Z
flag; each call site has its own trampoline and remembers one function.
StartSound plays synchronously when given no completion routine, and
otherwise writes to the Sound Driver asynchronously with one of 8
parameter blocks shared by every call site (it waits when all 8 are in
use); StopSound kills the requests and calls the completion routines
that did not run, and SoundDone says whether any request is left. The
Component Manager 3 calls (QuickTime 2.5 and later: OpenAComponent,
GetComponentResource, ...) use the selectors of Apple's Universal
Interfaces 3.x, and TempInsertROMMap sets the low-memory globals as
their inline code does. Glue that keeps state, or a trampoline, reaches it
with 32-bit addresses, so it works in programs of any size.
include/needs-glue.txt lists what is left: mostly
calls that never ran on 68k (Navigation Services, Driver Services, the
Name Registry).
The sysroot
A ready-made sysroot for 68k and PowerPC is in the nightly release of
clang-retro/dos-sdk (get-toolchain.sh -s macos-classic). It has the
headers, the C and C++ libraries, the builtins and macapp.py, so you
do not need to build them. build-sysroot.sh builds it from source.
See docs/sysroot.md.
Building applications
tools/macapp.py compiles C sources with this SDK's headers and links
them into an application, fat (68k and PowerPC) by default:
CLANG=path/to/clang python3 tools/macapp.py -o Hello.bin examples/hello.c
python3 tools/macapp.py --cpu 68k -o Hello68.bin examples/hello.c -- -DDEBUG
hmount disk.img && hcopy -m Hello.bin :Hello && humount
Flags after -- go to clang. The output is MacBinary II, for
hfsutils' hcopy -m. --name, --creator and --size (the memory
partition in KB) set the Finder name, the creator code and the SIZE
resource; --carbon imports from CarbonLib first on PowerPC;
--console window puts the C library's stdin, stdout and stderr
in a window instead of files (see The C library).
--type sets the file type (for example APPC for a control panel
that is an application, or appe for a program that the system starts
from the Extensions folder). --background-only sets onlyBackground
in the SIZE resource, for a faceless background application.
--code-resource TYPE,ID (68k, with --no-libc) makes a file with one
code resource in place of an application: for example a screen saver
module, an INIT or a WDEF. See codelink.py below.
When a 68k program's data is out of the 16-bit PC-relative reach (a
program over about 32 KB), tools/macapp.py compiles it again with
-mcmodel=large, and says so; --large does that from the start. The
runtime and C libraries are built that way, which costs about 1% in
size.
The linkers it runs are in tools/link/ and can be used on their own:
codelink.pylinks the ELF objects that clang'sm68k-apple-macostarget makes, withstart.Sfirst, into one CODE 1 resource linked at address 0, followed by a table of the absolute pointers in it. CODE 0 is a one-entry jump table. At launchstart.Sadds the load address to each pointer, calls_FlushCodeCachewhere the trap exists (not on the 64K ROM, nor on System 6 on a Mac Plus or SE) and callsmain. Code compiled as usual reaches its data PC-relative, within 32 KB; code compiled with-mcmodel=largeuses 32-bit addresses, whichstart.Srelocates, and can be any size. Calls are 32-bit either way.- With
--code-resource TYPE,ID,codelink.pywrites the image as one resource of that type and ID, withstart-coderes.Sfirst in place ofstart.S. The owner of the resource calls its first byte. The handle can move between two calls, so each call compares the load address with the address of the last relocation, and when they are different, adds the difference to each pointer of the table and flushes the cache. Then it jumps tomainwith the caller's stack and registers:maingets the caller's arguments as they are (for a Pascal caller, givemainin assembly, or a C function behind a small assembly entry). A code resource has no A5 world: do not use the QuickDraw globals (qd). peflink.pylinks the XCOFF objects thatpowerpc-apple-macos9makes into a PEF application (acfrg0 resource, the PEF container in the data fork). Each imported call gets a glue stub that restores the TOC. It finds which shared library exports each name inimports.json(from Retro68's import libraries, bygen-imports.py;macos-exports.pymakes one from a real System Folder and ROM). InterfaceLib wins a name that other libraries also export; CarbonLib,Apple;Carbon;Networkingand ControlStripLib are imported weakly. On PowerPC the headers give each Toolbox call the symbol__imp_and its name (MAC_IMPORT). Thus a program function with the same name, such as a Win32ShowWindow, does not replace the Toolbox call. The linker sends__imp_Xto the importX. If no library exportsX, it sends it to the program's ownX.fatlink.pymerges the two: the PowerPC code in the data fork, named bycfrg, and the 68k code in CODE. A Power Mac runs the PowerPC code and a 68k Mac runs CODE.
Both linkers take archives (.a) and link only the members a program
needs. codelink.py lays out .preinit_array, .init_array and
.fini_array and defines the __init_array_start-style symbols that
the C library walks, so static constructors run on 68k. On PowerPC,
clang names each object's constructors and destructors as AIX does
(__sinit and __sterm functions, with the priority in the name), and
peflink.py puts them in the same tables, in priority order. Not done
yet in them: shared libraries (exports), and pattern-compressed PEF
data.
The runtime library
clang calls helper functions for what the CPU cannot do in a few
instructions: on the 68000, 32-bit multiply and divide (__mulsi3,
__udivsi3, ...), and on both CPUs 64-bit divide, soft float on 68k
(__adddf3, ...), conversions, and memcpy and memset for structure
copies. runtime/build.sh builds them into libmacrt.a for each CPU,
from compiler-rt's builtins and runtime/string.c (the mem* functions
and the common str* ones):
CLANG=path/to/clang LLVM_SRC=path/to/clang-retro/llvm runtime/build.sh
It writes lib/m68k/libmacrt.a and lib/ppc/libmacrt.a, which
tools/macapp.py links when they are there (--no-runtime leaves them
out). Without the C library below, declare the <string.h> functions
you use yourself, as tests/runtime.c does. Soft float is large on 68k
and counts towards the 32 KB limit: tests/runtime.c, which uses float
and double arithmetic and conversions, links to 20 KB.
On 68k, the float helpers (__addsf3, __mulsf3, __divsf3, the
comparisons and the int conversions) are in 68000 assembly in
runtime/softfloat-m68k.S. They are 1.3 to 8 times faster than the
helpers of compiler-rt. See docs/softfloat.md.
tests/runtime.c checks each helper, and tests/fixmath.c the FixMath
glue; tests/run.sh runs their 68k builds as a 68000 and a 68020 in
tools/sim68k.py.
The C library
runtime/build-libc.sh builds picolibc
(stdio, stdlib, string, math, setjmp, ...) for both CPUs, and the Mac
layer under it in runtime/libc/:
CLANG=path/to/clang PICOLIBC_SRC=path/to/clang-retro/picolibc runtime/build-libc.sh
It needs meson and ninja, and writes lib/include (picolibc's
headers) and lib/m68k and lib/ppc (libc.a, libmacos.a and libmacconsole.a).
When they are there, tools/macapp.py compiles against those headers,
links both archives before libmacrt.a, and starts the program at
__crt_main, which runs the static constructors and calls
exit(main(argc, argv)) with the application's name as argv[0];
--no-libc leaves the C library out. The Mac layer gives picolibc:
- files over the File Manager:
open,read,write,lseek,close,unlinkandrename(into another folder too, withPBCatMove, on the same volume). Paths are POSIX (a/bis:a:bunder the application's folder,/Disk/aisDisk:a,..is the parent); a name with no/is used as a Mac path as it is. New files areTEXT/ttxt(set the globals_ftypeand_fcreatorto change that). Data is not converted: write\rfor Mac line ends. - file information and folders over the catalog calls:
stat,lstat(the same asstat),fstat,ftruncate,utime,mkdir,rmdir,opendir,readdir,rewinddir,closedirandgetcwd. A folder isS_IFDIRand a file isS_IFREG, with the size of its data fork. A locked file has no write permission. The times are UTC.getcwdgives/Volume/folder. - other POSIX functions for programs from Unix:
dup,fcntl,pread,pwrite,fsync,access,chmod,chdir,realpath,mmap(over the heap),shm_open,poll,select,pipe,uname,dlopenand more. Functions for processes and terminals fail with the usual error. See docs/posix.md. - BSD sockets: TCP and UDP over MacTCP (or Open Transport's MacTCP
driver), names from the MacTCP resolver (
getaddrinfo,gethostbyname), andAF_UNIXsockets and named pipes (mkfifo) between programs over the PPC Toolbox. See docs/network.md. - Open Transport (
OpenTransport.h,OpenTransportProviders.h): on PowerPC over Mac OS's Open Transport, on 68k over Apple's 68k libraries (through the Shared Library Manager) or over MacTCP. Also the MacTCP TCP and UDP blocks (MacTCP.h) and the name resolver (AddressXlation.h). See docs/opentransport.md. - The Shared Library Manager client on 68k (
LibraryManager.h): load an ASLM library and call its functions. See docs/aslm.md. - OpenGL on PowerPC:
GL/gl.h(OpenGL 1.2 and Apple's extensions),GL/glu.handAGL/agl.h, imported weakly from Apple'sOpenGLLibraryandOpenGLUtility. See docs/opengl.md. - QuickDraw 3D on PowerPC:
extras/quesa/build.shbuilds Quesa, the open-source QuickDraw 3D over OpenGL, as a static library, with theQD3D*.hheader names. See docs/quesa.md. CarbonAccessors.h: Carbon's accessor functions (GetPortBounds,GetWindowFromPort,GetMenuIDand others) as inline functions for programs that are not Carbon programs, as Apple's CarbonAccessors.o.- POSIX threads (
pthread.h) over the Thread Manager: cooperative threads, mutexes, condition variables, keys andpthread_once, andsched_yield,nanosleep,usleepandclock_gettime. The C++ library uses them forstd::threadandstd::mutex. See docs/threads.md. stdoutandstderrwritten to the file "App Output" in the application's folder, with\nturned into\r, so SimpleText opens it.stdinreads the file "App Input" there, with\rturned into\n, and is at end of file when there is none. A program can define__mac_console_read(and__mac_console_writeand__mac_console_close) itself to read and write elsewhere.- with
tools/macapp.py --console window, a console window instead:stdoutandstderrshow in a window in Monaco 9 that opens on the first output or input, wraps at its width and scrolls up when full, andstdinreads the lines typed into it (Delete takes back a character; Command-D, Command-period or the close box is the end of input). Reading first flushesstdout, so a prompt with no newline shows. The window initializes the Toolbox when it opens, unless the program sets_console_toolboxto 0 first because it has done that itself. When the program ends, the window stays until a key is pressed or it is clicked. malloc,calloc,reallocandfreeoverNewPtr,SetPtrSizeandDisposePtr, andaligned_alloc,posix_memalignandmemalign, which take a larger block whenNewPtr's is not aligned enough. When the heap has no room for a block of 64 KB or more,malloctakes it from temporary memory (TempNewHandle), on System 7 and later.time,gettimeofdayandftimefromGetDateTime, in UTC: the first call reads the time zone set in the Map control panel (ReadLocation) and, unless the environment has been set, setsTZto that offset, solocaltimegives the Mac's local time. The Mac knows no daylight saving rules, so times in the other season are an hour off.- a fine clock for
CLOCK_MONOTONIC,std::chrono::steady_clock,nanosleepandusleep, and the fractions of a second ofgettimeofday:UpTime,Microsecondsor, on System 6,TickCount. See docs/posix.md. getentropy, forarc4randomandstd::random_device, from the jitter of the fine clock and the state of the Mac, mixed with SHA-256. See docs/posix.md.exitand_exitthroughExitToShell.errnofrom File Manager and Memory Manager errors.
picolibc is built without debug information, since clang crashes writing it for XCOFF. The C library is
large next to 32 KB: tests/libc.c, which uses stdio, strtod, qsort
and localtime, links to about 54 KB of 68k code, so tools/macapp.py
builds it with -mcmodel=large.
tests/libc.c checks it; tests/run.sh runs its 68k build as a 68000
and a 68020 in tools/sim68k.py --os, and its PowerPC build in
tools/simppc.py; it runs tests/console.c with the console window in
both too, typing a line into it.
C++
The SDK compiles and links C++ for 68k and PowerPC: exceptions, RTTI,
static constructors and destructors, and GCC's libstdc++ 15.2 built on
the C library. runtime/build-libstdcxx.sh builds the library, and
tools/macapp.py links it when a source is C++. See
docs/cxx.md.
Testing
tools/sim68k.py App.binruns a 68k application on a 68k CPU emulator (theunicornPython package) and prints each Toolbox trap it makes, with its arguments. Only a few traps are faked, so it checks code generation, relocation and stack balance for small programs, not drawing.--osfakes the Memory Manager and the File Manager's parameter-block calls with the files kept in memory, a PowerBook's_PMgrOp, the Sound Driver (an asynchronous write ends at the next trap, which first runs its completion routine as an interrupt would) andReadLocation(a Mac in UTC-8), the HFS catalog calls (PBGetCatInfo,PBSetCatInfo,PBDirCreate,PBGetFCBInfoandPBCatMove, folders being the prefixes of the file names), and the Thread Manager's cooperative threads;--filesprints the files the program left, and--input TEXTgives the C library'sstdinthat text.--keys TEXTgives a console window that text as key presses, then Command-period; the window's drawing calls are faked andDrawTextprints the text drawn.tools/simppc.py App.binruns a PowerPC application on a PowerPC CPU emulator (unicorntoo): it loads the PEF container, applies its relocations, and gives each imported InterfaceLib function a fake built onsim68k.py's (the Memory Manager, the File Manager,ReadLocation,DrawString,ExitToShell, the console window's calls, with--keystoo, ThreadsLib, the Code Fragment Manager'sGetSharedLibraryandFindSymbol, and a fake OpenGL intools/fakegl.py). A program that calls any other import stops there.tests/run.shruns the runtime, glue, C library, thread, socket, OpenGL and Quesa tests in it.tools/mame/boots Apple's System disks in MAME (Systems 0.1 to 7.1) with an application in place of the Finder:mkroms.pymakes ROM sets from dumps you own,matrix.py App.bin OUTDIRboots every System and screenshots each one,harddisk.shboots System 7 from a hard disk image,mfs.pyreads and writes the MFS 400K disks of Systems 0.1 to 2.0,dc42.pyconverts DiskCopy 4.2 images, andcrashdump.luawrites the registers when an application crashes.tools/qemu/boot-q800.shboots System 7.6.1 or Mac OS 8.1 on QEMU'sq800from a copy of the install CD with the application on it (you supply a Quadra 800 ROM image).tools/qemu/boot.shboots Mac OS 9 on QEMU'smac99with a transfer disk. Mac OS 9.2.1 booted from its install CD (-boot d) does not mount a disk thathformatmade, since it has no partition map; put that image in the second CD drive instead, from the monitor:change ide1-cd0 xfer.img raw. Andtools/qemu/mon.pytakes screenshots and clicks through the QEMU monitor.tools/qemu/nettest.pyruns a network test on Mac OS in QEMU and collects its report (see docs/opentransport.md).- For PowerPC on Mac OS 8.1 and earlier, use SheepShaver with an OldWorld ROM image (such as the beige G3's), with the install CD attached as a CD-ROM.
Tests
CLANG=path/to/clang tests/run.sh
It compiles every header for both targets in C and C++, generates code
for every 68k inline function, checks the size of every record whose
definition gives one, checks the argument-block calls against the ROM,
and links every example into a fat application. With LLVM_SRC set it
also builds the runtime library and runs its test, and with
PICOLIBC_SRC set as well it builds the C library and runs its tests
(tests/libc.c, tests/console.c, tests/thread.c, tests/net.c,
tests/ot.c and the soft float test, tests/softfloat68k.c).
With GCC_SRC set too, it builds the C++ library and runs
tests/cxx.cpp.
.github/workflows/check.yml runs it for every pull request and push,
with the newest clang from clang-retro/llvm's llvm-prebuilt release,
and also fails when include/ or docs/coverage.md differ from what
tools/gen-headers.py and tools/coverage.py write.
Not done yet
- Coverage: the headers declare all but 3 undocumented symbols of what the ROM's InterfaceLib exports (see docs/coverage.md).
- 68k glue for the rest of
needs-glue.txtthat may have run on 68k, whose glue code is not known here:ATEventandATPreFlightEvent(the AppleTalk Transition Queue),GetDefaultUserandStartSecureSession(AppleShare), andKillProcess. - Running all of the C library on a real System:
tests/console.cwith the console window has run on System 7.6.1 (QEMUq800) and Mac OS 9.2.1 (QEMUmac99), buttests/libc.c, with its files, has run only intools/sim68k.pyandtools/simppc.py. - Threads on a real Thread Manager:
tests/thread.chas run only on the simulators' fake Thread Manager. - Sockets on a real network:
tests/net.chas run only on the simulators' fake MacTCP and PPC Toolbox.examples/net/fetch.c(TCP and names) has run on Mac OS 8.1 and 9.2.1 in QEMU. - Shared libraries in the linkers.
- Programs over 32 KB of 68k code are one CODE segment that large.
tests/cxx.cpp(415 KB of 68k code) has run on System 7.6.1, but no System before 7 has been tried with one.
License
Copyright (C) clang-retro contributors.
The clang-retro Mac 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.
defs/ comes from Multiversal Interfaces and stays under the MIT
license (defs/COPYING.multiversal); keep that notice with the headers
generated from it.
Each contributor keeps the copyright in their own work and contributes it under the same license; see CONTRIBUTING.md.