9fans archive / 1997 / 02 / 9 /    prev next

From: Tad Hunt tad@chi...
Subject: porting question about "initcode"...
Date: Mon, 17 Feb 1997 12:41:32 -0500

    I'm porting the most recent plan9 distribution to the DECstation 5000/1xx
series workstations.  I'm moving along fairly well, but I've got one
real question stumping me.  The DECstation 5000 is a mips R3000 machine,
so I have been basing my port on the indigo3k port.  In indigo3k/main.c
 in userinit() (line 356), the author maps in a page for the text segment
 and then memcpys the entire initcode array onto that page.

    The array is simply a hexdump of the entire "init.out" executable.  That
means that the initcode array contains three things: the plan9 exec header,
the text segment, and the data segment.  If I disassemble the init.out
executable, the instruction ( MOVW $setR30(SB),R30 ) sets the
data offset pointer to where it expects the data segment to live:

 0x1000:       23bdfff4        addi    sp,sp,-12
 0x1004:       afbf0000        sw      r31,0(sp) 
 0x1008:       3c1e0000        lui     r30,0	      <- MOVW $setR30(SB), R30
 0x100c:       37de908e        ori     r30,r30,0x908e <-
 0x1010:       27c1800a        addiu   r1,r30,-32758
 0x1014:       23a2000c        addi    r2,sp,12
 0x1018:       afa10004        sw      r1,4(sp)
 0x101c:       0c00041b        jal     0x106c
 0x1020:       afa20008        sw      r2,8(sp)
 0x1024:       24010010        li      r1,16
 0x1028:       afa10004        sw      r1,4(sp)
 0x102c:       24010013        li      r1,19
 0x1030:       0000000c        syscall

    But the data segment is really on the first page of the executable
because the entire executable was just copied to the page allocated to it.
Thus exec("/boot") fails and falls through to the "print r1" system call loop.

    My question is how does this init process work on an indigo3k?
(I don't have access to one, so I can't test it out).  I suppose
I could map in a data page for that information myself, but a quick look
at the other ports shows them doing the same thing as the indigo3k port.
(And then main.c would have to know about Exec headers.)  Am I just
missing something really obvious?

Thanks!
    -Tad