20

If I upgraded, say, a Macintosh II with larger SIMMs, naturally the machine detected that additional RAM. But how did it perform that check? Does it simply sweep all addresses until it fails? Or does it do something more complex?

  • 5
    I'd say by probing addresses. More recent synchronous RAM modules (SDRAM) have an integrated I2C memory which can be interrogated to probe installed memory (and access times) – TEMLIB May 21 at 21:01
  • 10
    Welcome to Retrocomputing! You accepted the first answer which appeared, less than an hour after the question was posted. Please wait 12 to 24 hours before accepting an answer. This allows others (who may be in other time zones) a chance to write a better answer, especially one that provides citations and links to source material. Thank you. – DrSheldon May 21 at 23:29
20

Yes, part of the POST sequence (which occurs before the display lights up) is a simple memory test which also serves to detect how much RAM is present. The Mac then sets up the hardware and its internal variables to reflect the actual RAM configuration.

Attempted accesses of addresses which do not map to memory will either see a dead bus or alias to another RAM address. Both of these cases can be detected by a RAM test routine.

Modern DIMMs include a small EEPROM connected to an I2C bus on dedicated pins of the DIMM. This is read by the PC BIOS to determine both the size and timings of the RAM on board. Such technology was not practical at the time of the Mac II series.

| improve this answer | |
  • 5
    There's an answer that has forgotten what the phrase "RAM size resistors" used to connote in the Macintosh world. (-: – JdeBP May 21 at 21:38
  • 3
    @JdeBP The question referred to the Mac II series, which didn't have those. They were present on early Macs with 68000 CPUs, as well as some 8-bit machines. – Chromatix May 22 at 10:06
  • 2
    It's impressive that they managed to repurpose the RGB control channel for such a practical purpose as timing readouts! – chrylis -cautiouslyoptimistic- May 22 at 11:28
  • No, the question gave that as an example, introduced by the word "say", not as the sole focus of the question. Read the title again. – JdeBP May 23 at 17:19
15

(I was waiting Raffzahn to write an authoritative answer, but he hasn't yet, so I will write it myself.)

In General

Unless noted, sources are the Guide to Macintosh Family Hardware, 2nd edition, 1990.

680x0 processors expect the reset and exception vectors to reside in low memory (addresses 0x000000 to 0x0003ff). During normal operation, all Macs mapped RAM to these locations, to allow software to install their own exception handlers. However, during early startup the ROM needs to be mapped to this address range, to allow the correct reset routine to be executed. Each model of Mac had logic to handle this in one of its custom logic chips; on the early Macs, it was usually the audio chip. This chip also generated the /RESET signal which reset the processor and peripherals.

Executed from ROM, the reset routine configures hardware registers for that particular Mac model. Some models also perform (unspecified) diagnostics on hardware. It then performs a memory test. Apple did not document exactly what happens during this test, but it probably is similar to what is described in Spectre's answer. This ensures that the RAM will retain values (which will not happen if no RAM is installed!) and that address and data bus lines are not shorted together. By writing different values to various regions of memory, it is possible to determine if those regions of memory are unique versus the same memory aliased to different addresses; it seems that this technique was used in later Mac models to determine memory size.

Should the RAM test fail, the Mac made a beep or car-crash sound. It could not display the Sad Mac in this case, as video depended on having RAM! Nor were any subroutines called through this point, because that also depends on having RAM.

If the RAM test succeeded, then global tables and variables are initialized in the bottom of the RAM. The exception vectors are copied from ROM, and RAM is mapped back to low memory. The startup parameters are copied from PRAM, and the operating system "managers" are initialized. A "happy" chime is played. Initialization then proceeds to step 2 described here; expansion hardware is initialized, video devices are started, and the operating system is loaded from a boot volume.

Macintosh 128K, 512K, 512K enhanced

The earliest Macs had a fixed amount of memory, which was not upgradable. Apple's documentation for these models notably does not mention measuring the amount of RAM. Therefore, I believe that the amount of RAM was simply hardcoded into the ROM.

Next, a memory test and several other system tests take place. After the system is fully tested and initialized, the software clears the VIA's overlay bit, mapping the system RAM back where it belongs, starting at address 0. Then the disk startup process begins.

Inside Macintosh: Volume III, p. III-42

Macintosh Plus and SE

The second generation of Macs had four SIMM slots for RAM. Because the data bus is 16 bits, SIMMs were required to be installed in pairs. The size of each pair of SIMMs were indicated by the presence or absence of a 150 ohm resistor. (Later SE models replaced the resistors with jumpers.) It's unclear whether the startup code used the memory test versus reading the resistors to determine the memory size.

Each time you turn on the Macintosh Plus or SE, system software does a memory test and determines how much RAM is installed in the machine. Software stores this information in the global variable MemTop, which contains the address (plus 1) of the last byte in RAM. Because the range of addresses in each SIMM row depends on the size of the DRAMs in the SIMM, the general logic circuits use the SIMM resistors or jumper to determine which row to access for each address range.

Guide to Macintosh Family Hardware, p. 201

Macintosh Portable

The Mac Portable had SRAM instead of DRAM, as the refresh cycles needed by the latter would have quickly drained the battery. There was 1 Mb built into the main board plus a RAM expansion connector for up to 8 Mb, allowing some unusual amounts of total RAM: 1, 2, 5, or 9 Mb. As there are neither jumpers nor signals on the expansion connector to designate the amount of memory, it must be determined dynamically by the reset routine.

Each time you turn on the Macintosh Portable (that is, when the battery is recharged after being completely discharged, or a new battery is installed), system software does a memory test, then determines how much RAM is installed in the machine.

p. 205

Macintosh II and SE/30

These models had 8 SIMM slots. Because the data bus was 32 bits wide, SIMMs had to be used in banks of four identically-sized SIMMs. Bank B must not be larger than bank A. There are no jumpers or signals on the connectors to indicate size, so it is determined by the reset routine.

The startup sequence of these models isn't as well documented as previous models. This is probably because they came with lots of expansion options, including cache slots, SIMMs, and NuBus slots, so the boot sequence is highly variable.

| improve this answer | |
  • 6
    If you're attempting to answer in the style of Raffzahn, you'll need to add some footnotes to seal the deal. – Jim Nelson May 22 at 17:51
  • The dependance on RAM needed as Framebuffer is most likely model-specific. Especially the Mac II (as implied by the initial questioner) relies exclusively on NuBus Cards for Video output. Besides that, very good writeup! – PoC May 22 at 18:41
  • PoC: Yes, and also the Portable had a separate 32k of RAM specifically for video. Neither detail changes the fact that the memory check happens before video is available, so a failed memory test must be indicated by sound, rather than a Sad Mac. – DrSheldon May 22 at 19:55
  • 2
    The 128K could be upgraded (up to 512 KiB), and would properly detect and use the additional RAM; although this was only officially supported on later 128Ks (the ones sold after the release of the 512K, with the "Macintosh 128K" branding), January-to-September-1984 128Ks (with the plain "Apple Macintosh" branding) were also upgradeable to 512 KiB using third-party RAM upgrade kits. – Sean May 22 at 22:34
5

RAM test was common (even ZX48K had it)... How it works:

it simply loop through "whole" address space and detects address mirroring and memory bugs.

something like:

// set system limit
max_adr=0xFFFF
// clear memory to zero
for (adr = 0 ; adr <= max_adr ; adr++) mem[adr] = 0; 
// test memory is zero and set it to 0xAA
for (adr = 0 ; adr <= max_adr ; adr++) 
 {
 if (mem[adr] != 0){ max_adr=adr-1; break; }
 mem[adr] = 0xAA;
 }
// test memory is 0xAA and set it to 0x55
for (adr = 0 ; adr <= max_adr ; adr++) 
 {
 if (mem[adr] != 0xAA){ max_adr=adr-1; break; }
 mem[adr] = 0x55;
 }
// test memory is 0x55 and set it to zero
for (adr = 0 ; adr <= max_adr ; adr++) 
 {
 if (mem[adr] != 0x55){ max_adr=adr-1; break; }
 mem[adr] = 0;
 }
memory_size=max_adr+1;

this one is using 0x00,0xAA,0x55,0x00 pattern. It detects dead buss, wrong data bit (dead cell, shortcut on data bus or address bus). To explain how:

0x00 = 00000000b
0x55 = 01010101b
0xAA = 10101010b

so if any DB is short cuted you would read different bit pattern...

If mirroring occurs you would read already set memory from previous iterations so the value would be already the same as set by the iteration...

you can also distinct between individual cases, and even detect which individual cells are bad, which bits are bad etc ...

To speed this up usually the whole ram is not tested but instead some block covering whole address space with gaps ...

| improve this answer | |
  • The ZX Spectrum tests the lower 2 bits of every location. The Macintosh surely doesn't do that. – OmarL May 22 at 10:24
  • @Wilson that test is also not from ZX its my own I used in (MCU based) robotics ages ago its just an example how it looks/works ... IIRC ZX did used different patterns and incrementing – Spektre May 22 at 10:27
2

Some machines required dip switches or jumpers. Some used memory probes. The Commodore VIC-20 and C64 used a non-destructive memory probe which would read each address, then try storing two distinct values, observe whether they read back, and then rewrite the address with its previously-read value. Other machines would write all of memory with various patterns and then try to read it back. I would guess that some machines probably tested every 256th byte or so, rather than scanning everything, since memory won't generally be added or removed in smaller increments than that, but I don't know of any specifics.

Depending upon how a memory system is designed, an approach based on writing and reading back individual locations (as opposed to writing many and then reading back many) may not be reliable. For example, if someone wanted to design a 2K expander for the VIC-20 to add memory from $2000 to $27FF and didn't have a bunch of surplus 1Kx4 chips lying around, the cheapest way to do that would have been to use a 2Kx8 RAM chip wired to the $2000-$3FFF chip-select; if one did that, then the device would behave as though any write to any of the addresses e.g. $2000, $2800, $3000, or $3800, would simultaneously write all of them, and likewise $2001, $2801, $3001, or $3801, etc. but the startup memory test would think that all of the memory up to $3FFF was usable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.