Mac OS 9 Discussion > Mac OS 9, Hacks & Upgrades

The Trampoline (Inside booting the Mac with a microscope)

(1/11) > >>

Protools5LEGuy:

--- Quote from: Protools5LEGuy on May 17, 2016, 10:55:59 PM ---To be more on topic I split some things

http://macos9lives.com/smforum/index.php/topic,3195.0.html

Let's keep "Anyone will to help create 9.2.3 for " for 9.2.3 developments

I beg you all to make a proper post on the trampoline as the Dream team post mentions because that was the only "relevant" info on that post.

Also, the new understandings on how you are disecting how OS9 boots deserve a own post.

Thanks for sharing all your valuable time with our community.


--- End quote ---

--- Quote from: ELN on May 18, 2016, 01:59:08 AM ---Perhaps I should start a new thread for all of our "theoretical" stuff?

--- End quote ---


--- Quote from: nanopico on May 18, 2016, 06:26:16 AM ---Are you asking for an update post on where we are at and how we are doing this in which thread?

--- End quote ---

We were talking about the trampoline on "Anyone wanna help out 9.2.3?" And also on the "Dream Team" post. To focus our community to be on topic we thought it would be great to split some topics and merge all the post on unsupported machines with the same specs.

So, Elliot, Nanopico, iMic, Mac OS Plus, MacTron, cc333 and anyone willing, this is da place

nanopico:
Got it.

nanopico:
Here's what we know now (this may be across several other threads too, but here it is in one spot).

This should be pretty accurate based on documentation and experimentation, but this process may be modified as we find out more.
The order of a few items might be just slightly off, but overall it gives a good picture of the general order of things.

Outline of the boot process (this applies to new world machines. Old World are a bit different).

* Press The Power Button, Okay I think we all knew that part, but in case you didn't then now you know.
* The boot firmware embedded on the machine is executed first

* Boot firmware interrogates and probes all devices on the motherboard and attached to any external ports.
* While it finds hardware it builds the device tree. For each device it checks for firmware and properties. And adds this info to the device tree. This includes addresses of the device, interrupt data required to startup and configure the device and any fcode drivers for the device.
The device tree is just a data structure in memory that is used during boot by the OS.  Manipulating the in memory version will only have effect until the machine is rebooted. (Thus the reason for the use of nvram scripts that have been used for things like changing cpu version numbers).

* The firmware then looks to the boot environment variable to find the device and file to load and execute.

* If you hold down the key combo for Open Firmware then rather than boot the firmware drops into the Client Interface program.
* In the case of Mac OS 9 the ROM file is a CHRP Script with a payload.  Once this is loaded Open Firmware executes the script
* The script sets up memory to hold the trampoline code and the parcels package, and sets variables for Open Firmware to know where to copy the code to and where to start execution
* At the end of the CHRP Script is an instruction for Open Firmware to start executing
* Open Firmware loads the programs to the requested location and jumps to the start point to start executing. (Keep in mind that Open Firmware is still exists at this point)
* The first thing to run is the trampoline code.  For the most part this is a dumb program (not that it isn't important, but more that it really doesn't know very little about what it's doing).

* The trampoline code starts up an Open Firmware connection through the Client Interface API's. 
* The trampoline code asks Open Firmware for the device tree and iterates through it and copies all node, device and property info into a flat structure that OS 9 will be able to use.
* While the trampoline code is looping through the device tree it compares each nodes type, name property and compatibility property to the data in the parcels.  If there is a match it look into the parcel for instruction on what to add to the device (properties, drivers, configuration instruction).  This is where drivers that are required to be in place for early boot are loaded.
Some of the things loaded are actually the libraries and routines that are needed very early that are needed to be loaded before the nano kernel can load them as they are used very early on for setting up other things.

* The trampoline code turns off open firmware (thus the reason for copying the device tree)
* The trampoline code does some page setup of memory, moves some things around, setups up the Virtual Memory.
* The trampoline code  then jumps to the nanokernel in the loaded toolbox. And it's job is done.
* And now we are to the nanokernel (the actual OS is now starting up.

* Happy Mac Icon displayed
* The nanokernel looks to the boot block of the start up device to find the location of the System folder, name of the first application to launch (The finder), and the name of the debugger if there is one.
* Font Manager and System Error Handler initialized.
* Set up Disk cache and CPU Specific software patches are executed.
* The 68k Emulator is started up.  Not surprisingly a lot of the low level OS stuff runs off this.
* Some  more required hardware is setup and initialized (remember the trampoline installed some drivers needing to be there for boot?  That's because the OS doesn't yet have a way to load them)
* The resource manager is started up
* The Time Manager is started and initialized along with the NVRAMServices.  This is required for drivers to be installed and hardware started up.
* Script systems are loaded and initialized and initialization resources are executed from the System File
* Data structures are setup for internal use
* The debugger if specified is loaded. so that early startup function can be debugged.This is loaded at the top of RAM usually.  When the memory manager starts, if it finds there is a debugger it leave's it's memory alone and doesn't manage it so it runs completely outside of the control of the OS.
An interrupt and trap is set so that the debugger can be jumped too.

* The nanokernel starts loading system extensions (including control panels). 
These load very early so that they can patch other parts of the system before they start up.
* Some more managers are started (not really sure at this point exactly what goes on so from here to the process manager may be a bit off)
* Memory Manager Is loaded and started up.
This one really got me at first. I figured this would be started much earlier, but according to Apple documentation it does appear to start fairly late.  If this is true then it will be easier to patch the system to get access to the full 2GB of ram installed on some machines.

* Additional services and managers are started
* The memory manager allocats the stack and heap for the process manager.
* The process manager starts.  The process managers works pretty close with the memory manager at this point for loading programs allocating memory and executing programs
All programs actually run from with in the memory allocated by the memory manager to the process manager.
Programs are loaded at the top of available memory of the process manager.  So programs load from top to bottom in memory.

* Depending on configuration certian parts of AppleTalk related to printing are loaded
* The Finder (Or what ever was specified in the boot block) is loaded and started and you are ready to use the machine

DieHard:
I have read almost every classic Mac OS startup sequence and they pale in comparison to yours !

Excellent breakdown, cleared up a few things I had in the totally wrong sequence, thanks so much :)

nanopico:

--- Quote from: DieHard on May 26, 2016, 02:46:03 PM ---I have read almost every classic Mac OS startup sequence and they pale in comparison to yours !

Excellent breakdown, cleared up a few things I had in the totally wrong sequence, thanks so much :)

--- End quote ---

What  were the things you thought happened in a different order?

Also some of the things may be a little out of sequence so I'm still looking to make this completely accurate. 

The only thing I don't understand yet is
A). What order do all the managers actually start in, I know pretty good some groups of them but I need to figure out the exact order (not that it's super important, but my brain needs to know).
B). How it determines the order to load extensions and control panels.


A lot of the stuff I was reading only focused on a parts of it. 
The details of the trampoline code is where most of the experimentation comes in.
The rest of it was learned from Inside Macintosh and Tech Notes from Apple.
Sadly it's not all in one place so it was a matter of taking notes as I read and then piecing it together as I went.  Also having a very food understanding of general operating system design doesn't hurt. 

Navigation

[0] Message Index

[#] Next page

Go to full version