[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Native /// bootstrapping?



Steve Nickolas <lyricalnanoha@dosius.ath.cx> wrote:

> David Empson wrote:
> > schmidtd <schmidtd@my-deja.com> wrote:
> > 
> >> On Feb 23, 5:57 pm, lyricalnan...@dosius.ath.cx (Steve Nickolas)
> >> wrote:
> >> > I'm trying to figure out how the SOS bootloader loads sos.kernel, and
> >> > I'm
> >> > not really getting it (although apparently the bootloader flips the
> >> > system
> >> > up to the topmost memory bank).
> >> 
> >> Jeppson has a pretty good discussion of the boot sequence:
> >> "Boot Sequence: On power-up, or after control-reset, the boot process
> >> begins in ROM#1 (ROM#2 doesn't yet exist). Low-level diagnostics are
> >> performed. Then block 0 is read from the disk in the built-in drive.
> >> This is the SOS boot code and is present on every disk that has been
> >> formatted by the System Utilities program. It must be present for a
> >> successful boot. It consists of one block of "absolute" code and is
> >> loaded into the computer at $A000, where it begins to run.
> >> 
> >> The boot code begins by locating and switching in the highest bank of
> >> RAM. Then it goes back to the disk and loads in five more blocks
> >> (blocks 1..5). These are placed in $A200..ABFF. Block 1 currently
> >> contains all zeros; blocks 2..5 are the disk directory. The boot code
> >> then scans the directory and locates SOS.Kernel, which it loads into
> >> memory at $1E00..73FF."
> >> http://apple3.org/Documents/Magazines/AppleIIIBits.html
> > 
> > Drive-by curiosity makes me ask...
> > 
> > How does that tally with the original layout of ProDOS 5.25" boot disks,
> > which have the ProDOS boot loader in block 0 and the SOS boot loader in
> > block 1?
> > 
> > Is there some trick the Apple /// is doing to recognise valid code in
> > block 0 and if it can't find it, trying block 1 instead, or is part of
> > the ProDOS boot block actually a SOS stub loader (at some offset into
> > the block) which fetches and executes block 1?
> > 
> > The ProDOS boot block starts with an $01 byte, which is not a valid 6502
> > instruction.
> 
> I'm attempting a rudimentary conversion from whatever the heck asm this is
> written in.
> 
> XBOOT:    .BYTE     1                   ; (ProDOS boot ID)
> ENTRY:    SEC                           ; (Apple /// enters XBOOT 'ORA $38')
> BCS       ENTRY1              ; branch if not Apple /// native mode
> JMP       GOAPL3              ; go do Apple /// boot!
> ENTRY1:   STX       UNIT                ; save unit number
> 
> Apparently the "01 38" is valid 6502, and disassembles to "ORA ($38, X)".

Ah yes, my mistake. I was thinking that the ProDOS boot code didn't
disassemble properly if you started at offset 0.

Explanation:

The Apple II starts execution at offset 1 (with SEC, BCS around the
JMP), as per rules established by the Disk ][ Controller.

The Apple /// ROM must do a CLC before it JMPs to offset 0, so the SEC
is hidden by the ORA ($38,X) and the BCS is not taken. It jumps to the
GOAPL3 location (presumably later in block 0, assuming it was loaded at
$A000), which will load block 1 (probably with help from a ROM
subroutine) and jump to it to do the normal Apple /// boot.

Diverting into explanation of the Apple ][ boot process (for ProDOS):

The rest of sector 0 (first half of block 0) has the code needed by
ProDOS to load the sector which is the second half of block 0, and the
whole thing then loads the directory (blocks 2 through 5) and tries to
locate the PRODOS file to continue booting.