|
|
|
1992/0418/sys/src/9/power/bboot.c:1,297 –
1992/0522/sys/src/9/power/bboot.c:0
(short | long | prev)
|
Deleted.
rsc Mon Mar 7 10:32:28 2005
|
|
1990/0424
| |
#include <u.h>
#include <libc.h>
|
|
1992/0319
| |
#include "../boot/boot.h"
|
|
1990/0424
| |
struct a_out_h {
ulong magic; /* magic and sections */
ulong timestamp; /* time and date */
ulong size; /* (HEADR+textsize+datsize) */
ulong symsize; /* nsyms */
ulong opt; /* size of optional hdr and flags */
ulong magicversion; /* magic and version */
ulong text; /* sizes */
ulong data;
ulong bss;
ulong entryva; /* va of entry */
ulong textva; /* va of base of text */
ulong dataca; /* va of base of data */
ulong bssva; /* va of base of bss */
ulong gpregmask; /* gp reg mask */
ulong dummy1;
ulong dummy1;
ulong dummy1;
ulong dummy1;
ulong gpvalue; /* gp value ?? */
ulong mystery; /* complete mystery */
} a_out;
|
|
1992/0319
| |
typedef struct Net Net;
typedef struct Flavor Flavor;
int printcol;
char cputype[NAMELEN];
char terminal[NAMELEN];
char sys[2*NAMELEN];
char username[NAMELEN];
char conffile[2*NAMELEN];
char sysname[2*NAMELEN];
char buf[8*1024];
int mflag;
int fflag;
int kflag;
int cache(int);
Method *rootserver(char*);
|
|
1990/0504
| |
int readconf(int);
|
|
1992/0319
| |
void readkernel(int);
int readseg(int, int, long, long, int);
|
|
1990/0427
| |
/*
|
|
1992/0319
| |
* default boot file
|
|
1990/0427
| |
*/
|
|
1992/0319
| |
#define DEFFILE "/mips/9power"
void
|
|
1990/0427
| |
main(int argc, char *argv[])
|
|
1990/0424
| |
{
|
|
1992/0319
| |
int fd;
Method *mp;
char cmd[64];
char flags[6];
int islocal;
|
|
1992/0322
| |
char bootfile[NAMELEN];
|
|
1990/0424
| |
|
|
1992/0319
| |
sleep(1000);
|
|
1990/0424
| |
|
|
1992/0319
| |
open("#c/cons", OREAD);
open("#c/cons", OWRITE);
open("#c/cons", OWRITE);
|
|
1990/0504
| |
|
|
1992/0319
| |
ARGBEGIN{
case 'u':
strcpy(username, ARGF());
|
|
1990/0427
| |
break;
|
|
1992/0319
| |
case 'k':
kflag = 1;
|
|
1990/0427
| |
break;
|
|
1992/0319
| |
case 'm':
mflag = 1;
break;
case 'f':
fflag = 1;
break;
}ARGEND
|
|
1990/0424
| |
|
|
1992/0319
| |
readenv("cputype", cputype, sizeof(cputype));
readenv("terminal", terminal, sizeof(cputype));
readenv("sysname", sysname, sizeof(sysname));
if(argc > 1)
|
|
1992/0322
| |
strcpy(bootfile, argv[1]);
|
|
1992/0319
| |
else
|
|
1992/0322
| |
strcpy(bootfile, DEFFILE);
|
|
1990/0424
| |
/*
|
|
1992/0319
| |
* pick a method and initialize it
|
|
1990/0424
| |
*/
|
|
1992/0319
| |
mp = rootserver(argc ? *argv : 0);
(*mp->config)(mp);
islocal = strcmp(mp->name, "local") == 0;
|
|
1990/1127
| |
|
|
1990/0424
| |
/*
|
|
1992/0418
| |
* set user to none
*/
fd = open("#c/user", OWRITE|OTRUNC);
if(fd >= 0){
if(write(fd, "none", 4) < 0)
warning("write user name");
close(fd);
}else
warning("open #c/user");
/*
|
|
1992/0319
| |
* connect to the root file system
|
|
1990/0424
| |
*/
|
|
1992/0319
| |
fd = (*mp->connect)();
if(fd < 0)
fatal("can't connect to file server");
if(!islocal){
nop(fd);
session(fd);
if(cfs)
fd = (*cfs)(fd);
|
|
1990/0427
| |
}
|
|
1990/1127
| |
|
|
1992/0319
| |
/*
* create the name space, mount the root fs
*/
if(bind("/", "/", MREPL) < 0)
fatal("bind");
if(mount(fd, "/", MAFTER|MCREATE, "", "") < 0)
fatal("mount");
|
|
1990/0424
| |
close(fd);
|
|
1992/0319
| |
/*
* open the configuration file and read it
* into the kernel
*/
sprint(conffile, "/mips/conf/%s", sysname);
|
|
1990/0504
| |
print("%s...", conffile);
|
|
1992/0319
| |
while((fd = open(conffile, OREAD)) < 0)
|
|
1990/1202
| |
outin("conffile", conffile, sizeof(conffile));
|
|
1990/0504
| |
if(readconf(fd) < 0)
|
|
1992/0319
| |
fatal("readconf");
|
|
1990/0504
| |
close(fd);
|
|
1992/0319
| |
/*
* read in real kernel
*/
|
|
1990/0504
| |
print("%s...", bootfile);
|
|
1992/0319
| |
while((fd = open(bootfile, OREAD)) < 0)
|
|
1990/1202
| |
outin("bootfile", bootfile, sizeof(bootfile));
|
|
1990/0424
| |
readkernel(fd);
|
|
1992/0319
| |
fatal("couldn't read kernel");
|
|
1990/0424
| |
}
|
|
1990/0427
| |
/*
|
|
1992/0319
| |
* ask user from whence cometh the root file system
|
|
1990/0427
| |
*/
|
|
1992/0319
| |
Method*
rootserver(char *arg)
|
|
1990/0427
| |
{
|
|
1992/0319
| |
char prompt[256];
char reply[64];
Method *mp;
char *cp;
int n;
|
|
1990/0427
| |
|
|
1992/0319
| |
mp = method;
n = sprint(prompt, "root is from (%s", mp->name);
for(mp++; mp->name; mp++)
n += sprint(prompt+n, ", %s", mp->name);
sprint(prompt+n, ")");
|
|
1990/0427
| |
|
|
1992/0319
| |
if(arg)
strcpy(reply, arg);
else
strcpy(reply, method->name);
for(;;){
|
|
1992/0322
| |
if(mflag)
|
|
1992/0319
| |
outin(prompt, reply, sizeof(reply));
for(mp = method; mp->name; mp++)
if(*reply == *mp->name){
cp = strchr(reply, '!');
if(cp)
strcpy(sys, cp+1);
return mp;
}
if(mp->name == 0)
continue;
|
|
1990/0427
| |
}
}
/*
|
|
1990/0504
| |
* read the configuration
*/
int
readconf(int fd)
{
int bfd;
int n;
long x;
/*
* read the config file
*/
n = read(fd, buf, sizeof(buf)-1);
if(n <= 0)
return -1;
buf[n] = 0;
/*
* write into 4 meg - 4k
*/
bfd = open("#b/mem", OWRITE);
|
|
1992/0319
| |
if(bfd < 0)
fatal("can't open #b/mem");
|
|
1990/0504
| |
x = 0x80000000 | 4*1024*1024 - 4*1024;
if(seek(bfd, x, 0) != x){
close(bfd);
return -1;
}
if(write(bfd, buf, n+1) != n+1){
close(bfd);
return -1;
}
close(bfd);
return 0;
}
|
|
1992/0319
| |
|
|
1990/0504
| |
/*
|
|
1990/0427
| |
* read the kernel into memory and jump to it
*/
|
|
1992/0319
| |
void
|
|
1990/0427
| |
readkernel(int fd)
{
int n;
int bfd;
bfd = open("#b/mem", OWRITE);
|
|
1992/0319
| |
if(bfd < 0)
fatal("can't open #b/mem");
|
|
1990/0427
| |
n = read(fd, &a_out, sizeof(a_out));
|
|
1992/0319
| |
if(n <= 0)
fatal("can't read boot file");
|
|
1990/0427
| |
print("\n%d", a_out.text);
|
|
1992/0319
| |
if(readseg(fd, bfd, 20*4, a_out.textva, a_out.text)<0)
fatal("can't read boot file");
|
|
1990/0427
| |
print("+%d", a_out.data);
|
|
1992/0319
| |
if(readseg(fd, bfd, 20*4 + a_out.text, a_out.textva + a_out.text, a_out.data)<0)
fatal("can't read boot file");
|
|
1990/0504
| |
print("+%d", a_out.bss);
|
|
1990/0427
| |
close(bfd);
bfd = open("#b/boot", OWRITE);
|
|
1992/0319
| |
if(bfd < 0)
fatal("can't open #b/boot");
|
|
1990/0427
| |
|
|
1990/0504
| |
print(" entry: 0x%ux\n", a_out.entryva);
|
|
1990/0427
| |
sleep(1000);
|
|
1992/0319
| |
if(write(bfd, &a_out.entryva, sizeof a_out.entryva) != sizeof a_out.entryva)
fatal("can't start kernel");
|
|
1990/0427
| |
}
/*
|
|
1992/0319
| |
* read a segment into memory
|
|
1990/0427
| |
*/
int
|
|
1992/0319
| |
readseg(int in, int out, long inoff, long outoff, int len)
|
|
1990/0427
| |
{
|
|
1992/0319
| |
long n, i;
|
|
1990/0427
| |
|
|
1992/0319
| |
if(seek(in, inoff, 0) < 0){
warning("seeking bootfile");
return -1;
|
|
1990/1202
| |
}
|
|
1992/0319
| |
if(seek(out, outoff, 0) != outoff){
warning("seeking #b/mem");
return -1;
}
for(; len > 0; len -= n){
if((n = read(in, buf, sizeof buf)) <= 0){
warning("reading bootfile");
return -1;
}
if(write(out, buf, n) != n){
warning("writing #b/mem");
return -1;
}
}
return 0;
|
|
1990/0424
| |
}
|
|
1992/0319
| |
|