OpenSTEP boot process

Started by pTeK, July 02, 2023, 04:16:31 AM

Previous topic - Next topic

pTeK

I've read the NeXTSTEP 3.3 System Administration Chapter 9, System Startup and Shutdown

How does it (boot2) load the hard drive system drivers from the Instance0? Is it a special 1Mb file at the beginning of the partition that has the HD driver file saved so that it can mount the rest of the partition or is it just using standard BIOS calls on the whole partition?

Thanks

cuby

It seems to use BIOS calls according to https://www.nextop.de/NeXTAnswers/1951.html

"5 boot2 also loads the device drivers the kernel needs for initial system startup. Up to this point, all system I/O--disk, keyboard, and display--has been done using BIOS routines. Before NEXTSTEP can go into virtual-memory, multitasking mode, boot2 has to load device drivers the kernel needs to get up and running. These drivers are specified in the ``Boot Drivers'' line in the Instance0.table file. in /private/Driver␅s/i386/System.config/. (If you haven't configured NEXTSTEP yet, it uses Default.table file, in the same directory.)"

pTeK


pTeK

For what it's worth going through a objdump of boot and using boot.c as a guide, they are very close and it has made it a lot easier to guess the similar routines and what one will need to be patched so I can hopefully get OpenStep4.2 then NS3.3 installed on Laptop. I'm thankful that Apple released the source and that MACH was GNU/GPL.

pTeK


I have a small window of opportunity and need perfect timing (less then 1 second after the memory test and it shows the boot prompt, before it freezes) to hit enter to proceed to the next part.

Above is booting on my Dell Inspiron 5150 from a USB stick with OpenStep 4.2 patched image (made with VirtualBox), I need to modify the image to boot of the cd-rom to install.

pTeK

Success, I've finally got text input. After user @Ingo gave me some advice that the RAM setup process at the start could be overwriting ACPI tables.

when boot executes it calls

/* initialize boot info structure */
    getKernBootStruct();

so in file libsaio/bootstruct.c

KERNBOOTSTRUCT *kernBootStruct = (KERNBOOTSTRUCT *)KERNSTRUCT_ADDR;

void
getKernBootStruct()
{
        ...
    /* get the size of the conventional memory */
    kernBootStruct->convmem = memsize(0);
    /* get the size of the extended memory */
    kernBootStruct->extmem = sizememory(kernBootStruct->convmem);   
 ...
}

I installed my band aid and changed:
; get the size of the conventional memory */
; kernBootStruct->convmem = memsize(0);
    44dc:    6a 00                    push   0x0
    44de:    e8 31 d2 ff ff           call   0x1714        ;memsize(0)
    44e3:    89 c2                    mov    edx,eax
    44e5:    a1 18 c7 00 00           mov    eax,ds:0xc718
    44ea:    89 90 b0 00 00 00        mov    DWORD PTR [eax+0xb0],edx
; /* get the size of the extended memory */
; kernBootStruct->extmem = sizememory(kernBootStruct->convmem)
    44f0:    52                       push   edx   ** Change this and one below **
    44f1:    e8 1e d0 ff ff           call   0x1514        ;sizememory(kernBootStruct->convmem);
    44f6:    89 c2                    mov    edx,eax
    44f8:    a1 18 c7 00 00           mov    eax,ds:0xc718
    44fd:    89 90 b4 00 00 00        mov    DWORD PTR [eax+0xb4],edx

Changed to.
; kernBootStruct->extmem = 65536 // 64MB ram
    44f0:    90                       nop      ** Change this and one below **
    44f1:    b8 00 ff 00 00           mov    eax,65536       
    44f6:    89 c2                    mov    edx,eax
    44f8:    a1 18 c7 00 00           mov    eax,ds:0xc718
    44fd:    89 90 b4 00 00 00        mov    DWORD PTR [eax+0xb4],edx

And used https://peterwong.net/blog/creating-an-openstep-boot-cd-2/ to build the 2.88MB boot/driver disk.

I can change the RAM later with the maxmem flag.

And used Grub 2 with Memdisk to boot the disk image of a USB stick

pTeK

Patch for NextSTEP 3.3 (CD Version) /usr/standalone/i386/boot (35504 bytes)

Here is the original:

*** libsaio/bootstruct.c
*** void getKernBootStruct();
    415c: 55                    push   ebp
    415d: 89 e5                mov    ebp,esp
    415f: 83 ec 04              sub    esp,0x4
    4162: 53                    push   ebx
; bzero((char *)kernBootStruct, sizeof(*kernBootStruct));
    4163: 68 fc f4 00 00        push   0xf4fc
    4168: 8b 0d 38 ba 00 00    mov    ecx,DWORD PTR ds:0xba38
    416e: 51                    push   ecx
    416f: e8 d4 2d 00 00        call   0x6f48 ; bzero();
; /* get the size of the conventional memory */
; kernBootStruct->convmem = memsize(0);
    4174: 6a 00                push   0x0
    4176: e8 89 d5 ff ff        call   0x1704
    417b: 8b 15 38 ba 00 00    mov    edx,DWORD PTR ds:0xba38
    4181: 89 82 b0 00 00 00    mov    DWORD PTR [edx+0xb0],eax
; /* get the size of the extended memory */
; kernBootStruct->extmem = sizememory(kernBootStruct->convmem);
    4187: 50                    push   eax              ; Change this line and the one below
    4188: e8 7f d3 ff ff        call   0x150c ; sizememory(kernBootStruct->convmem);
    418d: 8b 15 38 ba 00 00    mov    edx,DWORD PTR ds:0xba38
    4193: 89 82 b4 00 00 00    mov    DWORD PTR [edx+0xb4],eax
    4199: e8 86 ff ff ff        call   0x4124 ; numIDEs();


and here is the 6 byte patch

; /* set the extended memory to 65,280KB*/
; kernBootStruct->extmem = 65280;
    4187: 90                    nop              ; This line and the one below (6 bytes)
    4188: b8 00 ff 00 00        mov    eax,0xff00 ;
    418d: 8b 15 38 ba 00 00    mov    edx,DWORD PTR ds:0xba38  ;edx holds KernBootStruct
    4193: 89 82 b4 00 00 00    mov    DWORD PTR [edx+0xb4],eax ;KBS->extmem = 65280KB RAM

Will add this weekend, the patches for NS3.3 Patched boot, OS4.2 Patched boot and Rhapsody DR2.

I don't know if any one else has had problems trying to install on a x86 system and the keyboard freezes straight after the memory check??
The other opcodes are there so when you use a hex editor you know you are in the right spot.
** Use at your own risk **.

Rob Blessin Black Hole

The problems with Freezing may stem from USB as there was no USB Driver for NeXTSTEP or Openstep.
If you disable USB support in the bios that may resolve the issue.

Burn the NeXTSTEP or Openstep.iso images to a CDrom
and make sure and have a NeXT Intel Boot floppy, start install,
then load your 2nd boot floppy when prompted with drivers for CD and hard drive ,
you may need to make a 3rd floppy with the last known drivers, pick the one for dual channel eide support and with any luck ,
it finds the openstep4.2User.iso on the cd  and prompts to start the install,
it should locate the hard drive , a 2gb partition works best .... as it will install on larger hard drives and run until a hard shut down , then the old check disk software or fsck kicks in it doesn't understand the larger disk drive geometries and goes haywire.  NeXT does give the opportunity to set up a dual boot system, but using a different boot manager may afford more options . I think openstep will work with up to 8 gb drives in a single partition where NeXTstep was limited to 2gb partitions. It has been awhile since I've done a direct native openstep install on intel vs VMware, Virtual Box or Parallels and of course previous 68K.
Rob Blessin President computerpowwow ebay  [email protected] http://www.blackholeinc.com
303-741-9998 Serving the NeXT Community  since 2/9/93

pTeK

Change the patch from 6 bytes to one byte in source i386/boot2/sizememory.c

all this does is that now when you press the Left Shift key at boot, instead of skipping the mem check, it now does the mem test.

When it skips the memtest it calls a BIOS function in i386/libsaio/biosfn.c. This calls memsize(1) which is a BIOS function Int 15, AH=88 which tests extended memory from 16MB->64MB max, which was the common function call at the time (The source code has (c)NeXT 1993) before later function calls became more popular. Another BIOS Int15 AH=0x88 page
openstep 4.2 Intel User Patch 3 boot (44,848 bytes)
; *** boot2/sizememory.c_START
; unsigned int sizememory(unsigned int cnvmem)
..
; printf("\nSizing memory...");
17D0  68 3A CB 00 00         push dword 0xcb3a
17D5  E8 26 53 00 00         call 0x6b00       ; printf();
; if (readKeyboardShiftFlags() & 0x2) /* left SHIFT key depressed */
17DA  E8 85 01 00 00         call 0x1964       ; readKeyboardShiftFlags();
17DF  83 C4 04               add esp,byte +0x4
17E2  A8 02                  test al,0x2
17E4  74 1B                  jz 0x1801         ; patch this line.
; printf("[aborted]");
17E6  68 4D CB 00 00         push dword 0xcb4d
17EB  E8 10 53 00 00         call 0x6b00       ; printf();

*** this has to be changed only one byte to
17E2  A8 02                  test al,0x2
17E4  75 1B                  jnz 0x1801        ; patched to 75.
; printf("[aborted]");
17E6  68 4D CB 00 00         push dword 0xcb4d
17EB  E8 10 53 00 00         call 0x6b00       ; printf();

-- Rhapsody DR2 Intel boot (39,616 bytes)
; *** boot2/sizememory.c
; unsigned int sizememory(unsigned int cnvmem)
..
; printf("\nSizing memory...");
1528  68 1E BD 00 00        push dword 0xbd1e
152D  E8 3E 50 00 00        call 0x6570       ; printf();
; if (readKeyboardShiftFlags() & 0x2) /* left SHIFT key depressed */
1532  E8 85 01 00 00        call 0x16bc       ; readKeyboardShiftFlags();
1537  83 C4 04              add esp,byte +0x4
153A  A8 02                 test al,0x2
153C  74 1B                 jz 0x1559         ; patch this line.
; printf("[aborted]");
153E  68 31 BD 00 00        push dword 0xbd31
1543  E8 28 50 00 00        call 0x6570       ; printf();


** patched to
153A  A8 02                 test al,0x2
153C  75 1B                 jnz 0x1559        ; patch this line from 74 to 75
; printf("[aborted]");
153E  68 31 BD 00 00        push dword 0xbd31
1543  E8 28 50 00 00        call 0x6570       ; printf();
--------

Thanks Rob.

Yeah this freezing problem is crazy, it only happens on my Inspiron 5150 straight after the memory scan. On my Dual core ASUS S200E laptop with 2GB from 2012 I still get keyboard input the memory scan completes the only problem is that there are no HDD driver for that unit :'(. so 99% of NextStep 3.3 and OpenStep 4.2 (intel) users will not have to apply this

pTeK

#9
It seems that memsize function was updated for os x.

/boot/i386/libsaio/bootstruct.c#L100
void
initKernBootStruct()
{
    unsigned char i;
    bzero( (char *) kernBootStruct, sizeof(*kernBootStruct) );       
    // Get size of conventional memory.
    kernBootStruct->convmem = memsize(0);
    // Get size of extended memory.
    kernBootStruct->extmem  = memsize(1);   
    // Get number of ATA devices.
    kernBootStruct->numIDEs = countIDEDisks();
 ...

/boot/i386/libsaio/biosfn.c#L82

int memsize(int which)
{
    if (which) {
        get_memsize(&bb);       
        return (bb.edx.rr << 16) | bb.eax.rr;
    }
    else {
        /* conventional memory */
        bb.intno = 0x12;
        bios(&bb);
        return bb.eax.rr;
    }
}

/boot/i386/libsaio/bios.s#L133

/*============================================================================
 * Determines the total system memory size using various BIOS Int 15 calls.
 *
 */
ENTRY(get_memsize)
    enter    $0, $0                # create frame pointer (32 bit operand/stack)
    pushal                        # save all registers

    movl    8(%ebp), %ebx        # push input structure pointer to stack
    pushl    %ebx

    call    EXT(_prot_to_real)    # switch to real mode

    ##################################################################
    # In real mode.
    # Do not forget the opcode overrides, since the assembler
    # does not know we have made a transition to 16-bit operation.
    ##################################################################

    data32
    movl    $0xE801, %eax        # Get memory size
    clc
    int        $0x15
    data32
    jnc        getmsz_e801

    data32
    movl    $0xDA88, %eax        # Get memory size
    clc
    int        $0x15
    data32
    jnc        getmsz_da88

    movb    $0x8A, %ah            # Get memory size
    clc
    int        $0x15
    data32
    jnc        getmsz_8a

    movb    $0x88, %ah            # Get memory size
    clc
    int        $0x15
    data32
    jnc        getmsz_88

    xorl    %edx, %edx            # Error, cannot get memory size
    xorl    %eax, %eax

getmsz_done:
    data32
    addr32
    pushl    %eax                # Push EAX to 32-bit stack

    data32
    call    EXT(_real_to_prot)  # Back to protected mode. EAX is modified.

    ##################################################################
    # Back to protected mode.
    ##################################################################

    popl    %eax                # Pop EAX from stack
    popl    %ebx                # Pop pointer to register structure

    # Copy the result to the input structure pointed to by a pointer
    # which is on top of the stack. Write register EAX and EDX to the
    # structure.

    movl    %eax, O_EAX(%ebx)
    movl    %edx, O_EDX(%ebx)

    popal                        # restore all registers
    leave                        # undo enter operator
    ret

getmsz_88:
    orl        %eax, %eax
    data32
    jz        getmsz_64m
    xorl    %edx, %edx

getmsz_8a:
    data32
    movl    $1024, %ebx            # Add in 1M
    addl    %ebx, %eax
    adcl    $0, %edx
    data32
    jmp        getmsz_done

getmsz_64m:
    data32
    movl    $1, %edx
    xorl    %eax, %eax
    data32
    jmp        getmsz_done

getmsz_da88:
    xor        %dh, %dh
    movb    %cl, %dl
    movl    %ebx, %eax
    data32
    jmp        getmsz_8a

getmsz_e801:
    xorl    %edx, %edx
    orl        %ebx, %ebx
    data32
    jz        getmsz_88

    data32
    movl    $64, %eax
    mul        %ebx

    data32
    movl    $16384, %ebx
    addl    %ebx, %eax
    adcl    $0, %edx

    data32
    jmp        getmsz_done