Skip to content
jonathanschillingPublic

About

Macintosh 68k ROM source - reverse engineered

Resources

Stars

35 stars

Watchers

3 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

Macintosh ROM Source Tree

This repository contains a fully commented, buildable 68000 assembly source tree for seven classic-era Macintosh ROMs. The same source tree assembles into bit-identical copies of each ROM via --defsym ROM_TARGET={1..7}.

Legal disclaimer

This is a pure hobby project. No copyright infringements or similar is intended.
Please inform the author about possible legal issues before turning to a lawyer.

Build

Toolchain on Debian / Ubuntu:

sudo apt install binutils-m68k-linux-gnu

(on Arch Linux: m68k-elf-binutils; the Makefile auto-detects either m68k-linux-gnu- or m68k-elf- tools, override with make CROSS=...).

Build all seven ROM variants and verify each one:

make

No original ROM images are needed. Every build is checked against fingerprints of the original ROMs that are hardcoded in the Makefile: the image size, the ROM's own checksum signature in its first four bytes (both the stored value and the checksum recomputed over the image), the ROM version word at offset 8, and the MD5 of the whole image; for the two SE ROMs also the checksums of the two 128 KB ROM chips that the ROM stores at offsets $30 and $34.

If you have the original ROM images, the build additionally compares each one byte-for-byte against them. They are looked up under the path given by the ROM_REF_DIR Makefile variable (default ../macroms/Mac_ROMs/68k, using the file names of the macintoshrepository.org ROM collection); override on the command line if needed:

make ROM_REF_DIR=/path/to/Mac_ROMs/68k

A successful run reports SUCCESS: ALL SEVEN ROMS BIT-IDENTICAL.

The reference ROMs are available here: https://www.macintoshrepository.org/7038-all-macintosh-roms-68k-ppc-

ROM maps

maps/ holds a map of every label of each ROM, generated from the assembled source (make rommap regenerates them in build/):

maps/rom-<target>.lst      the layout of Apple's MPW ROM maps
                           (MacPlusROM.lst, MacSEROM.lst; "ROM.List")
maps/rom-<target>.lst.txt  "name 0xOFFSET l" lines, the format of
                           joevt/68k-mac-rom-maps (for Ghidra's
                           ImportSymbolsScript.py)

Apple's MPW ROM maps (MPW 3.5 GM) are the source of truth for every name they contain: each line of MacPlusROM.lst appears byte-identical in the three Plus maps, and each line of MacSEROM.lst in both SE maps -- the same name at the same offset, with Apple's flag, including Apple's trap-table placeholders (Trap0_xx / Trap1_xxx), MPW's 15-character truncations and the SE's module names. No other label conflicts with an Apple name or with another label, even ignoring case. (Source labels ending in __MAP appear in the maps without that suffix: CONTROL and STATUS cannot be assembler symbols, and MacPlusROM.lst lists SetAppBase at two offsets.) There is no Apple map for the 64K ROM of the Macintosh 128K/512K; there, every trap entry point that the Plus also implements carries the Plus name.

Per-target builds:

make mac_128k      # 1984-01, 64 KB,  $28BA61CE
make mac_512k      # 1984-10, 64 KB,  $28BA4E50
make mac_plus_v1   # 1986-01, 128 KB, $4D1EEEE1
make mac_plus_v2   # 1986-03, 128 KB, $4D1EEAE1  (branch-fix)
make mac_plus_v3   # 1986-03, 128 KB, $4D1F8172  (SCSI patch)
make mac_se        # 1987-03, 256 KB, $B2E362A8
make mac_se_fdhd   # 1989-08, 256 KB, $B306E171

ROM resources (Rez)

The resource forks of the Plus and SE ROMs (drivers, packages, definition procedures, cursors, fonts, ...) are described in Rez, the resource language of Apple's MPW: rez/plus/RomResources.r and rez/se/RomResources.r list the resources in ROM order with their names and attributes, and the fields of the resource map. tools/rez/rezc.py, an independent Rez compiler (Python 3), turns each into include/_rsrc.inc: the resource map with its counts and offsets, and the index and relative handle of every resource. Each resource's data sit in its source file between the macros ROM_RESOURCE and ROM_RESOURCE_END (include/romrsrc.inc), which write the 8-byte resource header and take the size from the data -- nothing of the map or the headers is written by hand. A resource can also come from Rez itself (resource/data/read statements, a 'rez' entry in the 'rrsc' list, and ROM_RESOURCE_REZ where its data go in the ROM).

After editing a .r file: make rez (needs Python 3), then make. A modified ROM no longer matches the fingerprints of make; build it with make build/rom-<target>.bin and fix its checksums with python3 tools/fixup_checksum.py build/rom-<target>.bin (the long at offset 0, and the per-chip checksums of the SE images).

Room for more resources: the Plus ROM is full (its resources end at the extra area, which must stay at $1FFC0: the v3 SCSI patch is called by absolute address). In the SE ROMs the resources are followed by filler, the developer initials repeated up to the date at $3FFEE (13,382 bytes; in the SE FDHD 1,112 bytes up to its patch code at $3D000, which the .Sony driver calls by absolute address). Shorten the .rept counts in se/extra/rom_tail.s to make room; .org guards at these offsets stop the assembly ("attempt to move .org backwards") when the resources grow into them.

rezc.py can also list the resources of a ROM image or write them as a resource fork:

python3 tools/rez/rezc.py --rom-image build/rom-mac_se.bin --list
python3 tools/rez/rezc.py --rom-image build/rom-mac_se.bin --rsrc se.rsrc

Layout

rom_original.s         Master include for Mac 128K / 512K
rom_plus.s             Master include for Mac Plus (all variants)
rom_se.s               Master include for Mac SE and Mac SE FDHD
original/              Mac 128K / 512K source tree
plus/                  Mac Plus source tree
se/                    Mac SE / SE FDHD source tree
include/               Assembler equates (traps, low-mem, hw regs)
maps/                  ROM maps of all seven ROMs (see above)
tools/verify_rom.sh    ROM verifier (size, checksum, version, MD5, cmp)
tools/rom_map.sh       ROM map generator (make rommap)
tools/rom_map_flags.txt  flags of the Apple map entries, for rom_map.sh
tools/fixup_checksum.py  recompute the checksums of a modified ROM
tools/rez/             Rez compiler (rezc.py) and its templates
rez/                   Rez descriptions of the ROM resource forks
Makefile               Self-contained build pipeline

include/ files:

rom_target.inc         ROM target selector (MAC_128K..MAC_SE_FDHD)
traps.inc              287 A-line trap macros
traps_se.inc           37 SE-era A-line trap macros
lowmem.inc             386 low-memory globals
lowmem_se.inc          SE overrides + 28 SE-era new symbols
hwregs.inc             Hardware registers (VIA, SCC, IWM, SCSI)
sysequ.inc             System equates (IOParam, queues, events)
fsequ.inc              File system equates (VCB, FCB)
toolequ.inc            Toolbox equates (Window, Control, Menu, TE)
sonyequ.inc            Sony disk-driver equates
private.inc            Private system equates (memory mgr internals)
macros.inc             Helper macros (UNLINK, etc.)
romrsrc.inc            ROM resource fork: block-header constants and the
                       ROM_RESOURCE / ROM_RESOURCE_END / map macros
plus_rsrc.inc          generated from rez/plus/RomResources.r (make rez)
se_rsrc.inc            generated from rez/se/RomResources.r (make rez)

ROM variants and checksums

Target Date Size Checksum MD5 Notes
mac_128k 1984-01 64 KB 28BA61CE 1d7f52d2d490524954f6afce083d9593 Original Mac
mac_512k 1984-10 64 KB 28BA4E50 db7e6d3205a2b48023fba5aa867ac6d6 "Fat Mac"
mac_plus_v1 1986-01 128 KB 4D1EEEE1 4d8d1e81fa606f57c7ed7188b8b5f410 First Plus
mac_plus_v2 1986-03 128 KB 4D1EEAE1 16b516e13918a439cf9031ec24353610 Branch-condition fixes
mac_plus_v3 1986-03 128 KB 4D1F8172 8a41e0754ffd1bb00d8183875c55164c SCSI patch (default)
mac_se 1987-03 256 KB B2E362A8 9fb38bdcc0d53d9d380897ee53dc1322 SE (800K drives)
mac_se_fdhd 1989-08 256 KB B306E171 886444d7abc1185112391b8656c7e448 SE w/ SuperDrive

The 128 K and 512 K Macs differ at only 6 sites totaling 57 bytes; all are wrapped in .if ROM_TARGET == MAC_128K / .else / .endif.

The three Plus variants differ at 6 sites totaling 33 bytes (v1->v3) or 31 bytes (v2->v3); all are wrapped in .if ROM_TARGET == MAC_PLUS_V<x>.

The 1987 Mac SE and the 1989 SE FDHD share the se/ tree; they differ at 5 sites (checksum, the two per-chip checksums, a RAM-test hook, the .Sony driver and the developer-initials/patch tail), wrapped in .if ROM_TARGET == MAC_SE.

Source-tree organization

Each file holds one subsystem as Apple's own sources divide the ROM: one module of Apple's link map of the SE ROM (MacSEROM.lst) or one System 7.1 source file (the 1983 QuickDraw files keep their names), with the same file name in all three trees. Each .s file begins with a banner that names its routines and its Apple source. ROM byte order is fixed, so a subsystem that a ROM links in two places has two files.

original/ (1984 ROM, 68 files): boot/, hw/, os/, drivers/ (the 64K ROM's built-in drivers; it has no resource fork), toolbox/ (with quickdraw/)

plus/ (1986 ROM, 90 files): boot/, debugger/, hw/, os/, toolbox/ (with quickdraw/), resources/ (the ROM resource fork), extra/

se/ (1987 SE and 1989 SE FDHD ROMs, 102 files): the same directories as plus/, with the Apple Desktop Bus Manager (os/adb_mgr.s), both .Sony drivers (resources/res_drvr_sony.s for the SE, resources/res_drvr_sony_fdhd.s for the SE FDHD), .XPP, CDEF 0/1, MBDF 0, WDEF 1 and the hidden team photos (res_tcsl.s, res_bbmc.s)

Acknowledgements

This repo builds on the massive amount of the work of others, last but not least by the team at Apple Computer Inc., who designed and implemented the Macintosh ROM.

A list of information sources that went into this project is provided below. It is likely incomplete - please open an issue if you find that a given resource missing.

About

Macintosh 68k ROM source - reverse engineered

Resources

Stars

35 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages