Indent with 8-space tabs. This reduces the diffs to the newer ixp425
boot2 and may make it easier to merge these files in the future...
This commit is contained in:
parent
a1ecc28a8f
commit
06afbca3c8
@ -99,199 +99,203 @@ static int dskread(void *, unsigned, unsigned);
|
||||
static inline int
|
||||
xfsread(ino_t inode, void *buf, size_t nbyte)
|
||||
{
|
||||
if ((size_t)fsread(inode, buf, nbyte) != nbyte)
|
||||
return -1;
|
||||
return 0;
|
||||
if ((size_t)fsread(inode, buf, nbyte) != nbyte)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
getstr(int c)
|
||||
{
|
||||
char *s;
|
||||
char *s;
|
||||
|
||||
s = cmd;
|
||||
if (c == 0)
|
||||
c = getc(10000);
|
||||
for (;;) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
break;
|
||||
case '\177':
|
||||
case '\b':
|
||||
if (s > cmd) {
|
||||
s--;
|
||||
printf("\b \b");
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
*s = 0;
|
||||
return;
|
||||
default:
|
||||
if (s - cmd < sizeof(cmd) - 1)
|
||||
*s++ = c;
|
||||
xputchar(c);
|
||||
s = cmd;
|
||||
if (c == 0)
|
||||
c = getc(10000);
|
||||
for (;;) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
break;
|
||||
case '\177':
|
||||
case '\b':
|
||||
if (s > cmd) {
|
||||
s--;
|
||||
printf("\b \b");
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
*s = 0;
|
||||
return;
|
||||
default:
|
||||
if (s - cmd < sizeof(cmd) - 1)
|
||||
*s++ = c;
|
||||
xputchar(c);
|
||||
}
|
||||
c = getc(10000);
|
||||
}
|
||||
c = getc(10000);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int autoboot, c = 0;
|
||||
ino_t ino;
|
||||
int autoboot, c = 0;
|
||||
ino_t ino;
|
||||
|
||||
board_init();
|
||||
board_init();
|
||||
|
||||
dmadat = (void *)(0x20000000 + (16 << 20));
|
||||
/* Process configuration file */
|
||||
dmadat = (void *)(0x20000000 + (16 << 20));
|
||||
/* Process configuration file */
|
||||
|
||||
autoboot = 1;
|
||||
autoboot = 1;
|
||||
|
||||
if ((ino = lookup(PATH_CONFIG)))
|
||||
fsread(ino, cmd, sizeof(cmd));
|
||||
if ((ino = lookup(PATH_CONFIG)))
|
||||
fsread(ino, cmd, sizeof(cmd));
|
||||
|
||||
if (*cmd) {
|
||||
if (parse())
|
||||
autoboot = 0;
|
||||
printf("%s: %s", PATH_CONFIG, cmd);
|
||||
/* Do not process this command twice */
|
||||
*cmd = 0;
|
||||
}
|
||||
if (*cmd) {
|
||||
if (parse())
|
||||
autoboot = 0;
|
||||
printf("%s: %s", PATH_CONFIG, cmd);
|
||||
/* Do not process this command twice */
|
||||
*cmd = 0;
|
||||
}
|
||||
|
||||
/* Present the user with the boot2 prompt. */
|
||||
/* Present the user with the boot2 prompt. */
|
||||
|
||||
if (*kname == '\0')
|
||||
strcpy(kname, PATH_KERNEL);
|
||||
for (;;) {
|
||||
printf("\nDefault: %s\nboot: ", kname);
|
||||
if (!autoboot || (c = getc(2)) != -1)
|
||||
getstr(c);
|
||||
xputchar('\n');
|
||||
autoboot = 0;
|
||||
c = 0;
|
||||
if (parse())
|
||||
xputchar('\a');
|
||||
if (*kname == '\0')
|
||||
strcpy(kname, PATH_KERNEL);
|
||||
for (;;) {
|
||||
printf("\nDefault: %s\nboot: ", kname);
|
||||
if (!autoboot || (c = getc(2)) != -1)
|
||||
getstr(c);
|
||||
xputchar('\n');
|
||||
autoboot = 0;
|
||||
c = 0;
|
||||
if (parse())
|
||||
xputchar('\a');
|
||||
#ifdef XMODEM_DL
|
||||
else if (*cmd == '*')
|
||||
Update();
|
||||
else if (*cmd == '*')
|
||||
Update();
|
||||
#endif
|
||||
else
|
||||
load();
|
||||
}
|
||||
else
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load(void)
|
||||
{
|
||||
Elf32_Ehdr eh;
|
||||
static Elf32_Phdr ep[2];
|
||||
caddr_t p;
|
||||
ino_t ino;
|
||||
uint32_t addr;
|
||||
int i, j;
|
||||
Elf32_Ehdr eh;
|
||||
static Elf32_Phdr ep[2];
|
||||
caddr_t p;
|
||||
ino_t ino;
|
||||
uint32_t addr;
|
||||
int i, j;
|
||||
|
||||
if (!(ino = lookup(kname))) {
|
||||
if (!ls)
|
||||
printf("No %s\n", kname);
|
||||
return;
|
||||
}
|
||||
if (xfsread(ino, &eh, sizeof(eh)))
|
||||
return;
|
||||
if (!IS_ELF(eh)) {
|
||||
printf("Invalid %s\n", "format");
|
||||
return;
|
||||
}
|
||||
fs_off = eh.e_phoff;
|
||||
for (j = i = 0; i < eh.e_phnum && j < 2; i++) {
|
||||
if (xfsread(ino, ep + j, sizeof(ep[0])))
|
||||
return;
|
||||
if (ep[j].p_type == PT_LOAD)
|
||||
j++;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
p = (caddr_t)ep[i].p_paddr;
|
||||
fs_off = ep[i].p_offset;
|
||||
if (xfsread(ino, p, ep[i].p_filesz))
|
||||
return;
|
||||
}
|
||||
addr = eh.e_entry;
|
||||
((void(*)(int))addr)(opts & RBX_MASK);
|
||||
if (!(ino = lookup(kname))) {
|
||||
if (!ls)
|
||||
printf("No %s\n", kname);
|
||||
return;
|
||||
}
|
||||
if (xfsread(ino, &eh, sizeof(eh)))
|
||||
return;
|
||||
if (!IS_ELF(eh)) {
|
||||
printf("Invalid %s\n", "format");
|
||||
return;
|
||||
}
|
||||
fs_off = eh.e_phoff;
|
||||
for (j = i = 0; i < eh.e_phnum && j < 2; i++) {
|
||||
if (xfsread(ino, ep + j, sizeof(ep[0])))
|
||||
return;
|
||||
if (ep[j].p_type == PT_LOAD)
|
||||
j++;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
p = (caddr_t)ep[i].p_paddr;
|
||||
fs_off = ep[i].p_offset;
|
||||
if (xfsread(ino, p, ep[i].p_filesz))
|
||||
return;
|
||||
}
|
||||
addr = eh.e_entry;
|
||||
((void(*)(int))addr)(opts & RBX_MASK);
|
||||
}
|
||||
|
||||
static int
|
||||
parse()
|
||||
{
|
||||
char *arg = cmd;
|
||||
char *ep, *p;
|
||||
int c, i;
|
||||
char *arg = cmd;
|
||||
char *ep, *p;
|
||||
int c, i;
|
||||
|
||||
while ((c = *arg++)) {
|
||||
if (c == ' ' || c == '\t' || c == '\n')
|
||||
continue;
|
||||
for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
|
||||
ep = p;
|
||||
if (*p)
|
||||
*p++ = 0;
|
||||
if (c == '-') {
|
||||
while ((c = *arg++)) {
|
||||
for (i = 0; c != optstr[i]; i++)
|
||||
if (i == NOPT - 1)
|
||||
return -1;
|
||||
opts ^= OPT_SET(flags[i]);
|
||||
}
|
||||
} else {
|
||||
arg--;
|
||||
if ((i = ep - arg)) {
|
||||
if ((size_t)i >= sizeof(kname))
|
||||
return -1;
|
||||
memcpy(kname, arg, i + 1);
|
||||
}
|
||||
while ((c = *arg++)) {
|
||||
if (c == ' ' || c == '\t' || c == '\n')
|
||||
continue;
|
||||
for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
|
||||
ep = p;
|
||||
if (*p)
|
||||
*p++ = 0;
|
||||
if (c == '-') {
|
||||
while ((c = *arg++)) {
|
||||
for (i = 0; c != optstr[i]; i++)
|
||||
if (i == NOPT - 1)
|
||||
return -1;
|
||||
opts ^= OPT_SET(flags[i]);
|
||||
}
|
||||
} else {
|
||||
arg--;
|
||||
if ((i = ep - arg)) {
|
||||
if ((size_t)i >= sizeof(kname))
|
||||
return -1;
|
||||
memcpy(kname, arg, i + 1);
|
||||
}
|
||||
}
|
||||
arg = p;
|
||||
}
|
||||
arg = p;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dskread(void *buf, unsigned lba, unsigned nblk)
|
||||
{
|
||||
struct dos_partition *dp;
|
||||
struct disklabel *d;
|
||||
char *sec;
|
||||
int i;
|
||||
struct dos_partition *dp;
|
||||
struct disklabel *d;
|
||||
char *sec;
|
||||
int i;
|
||||
|
||||
if (!dsk_meta) {
|
||||
sec = dmadat->secbuf;
|
||||
dsk_start = 0;
|
||||
if (drvread(sec, DOSBBSECTOR, 1))
|
||||
return -1;
|
||||
dp = (void *)(sec + DOSPARTOFF);
|
||||
for (i = 0; i < NDOSPART; i++) {
|
||||
if (dp[i].dp_typ == DOSPTYP_386BSD)
|
||||
break;
|
||||
if (!dsk_meta) {
|
||||
sec = dmadat->secbuf;
|
||||
dsk_start = 0;
|
||||
if (drvread(sec, DOSBBSECTOR, 1))
|
||||
return -1;
|
||||
dp = (void *)(sec + DOSPARTOFF);
|
||||
for (i = 0; i < NDOSPART; i++) {
|
||||
if (dp[i].dp_typ == DOSPTYP_386BSD)
|
||||
break;
|
||||
}
|
||||
if (i == NDOSPART)
|
||||
return -1;
|
||||
/*
|
||||
* Although dp_start is aligned within the disk
|
||||
* partition structure, DOSPARTOFF is 446, which is
|
||||
* only word (2) aligned, not longword (4) aligned.
|
||||
* Cope by using memcpy to fetch the start of this
|
||||
* partition.
|
||||
*/
|
||||
memcpy(&dsk_start, &dp[1].dp_start, 4);
|
||||
if (drvread(sec, dsk_start + LABELSECTOR, 1))
|
||||
return -1;
|
||||
d = (void *)(sec + LABELOFFSET);
|
||||
if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
|
||||
printf("Invalid %s\n", "label");
|
||||
return -1;
|
||||
}
|
||||
if (!d->d_partitions[0].p_size) {
|
||||
printf("Invalid %s\n", "partition");
|
||||
return -1;
|
||||
}
|
||||
dsk_start += d->d_partitions[0].p_offset;
|
||||
dsk_start -= d->d_partitions[RAW_PART].p_offset;
|
||||
dsk_meta++;
|
||||
}
|
||||
if (i == NDOSPART)
|
||||
return -1;
|
||||
// Although dp_start is aligned within the disk partition structure,
|
||||
// DOSPARTOFF is 446, which is only word (2) aligned, not longword (4)
|
||||
// aligned. Cope by using memcpy to fetch the start of this partition.
|
||||
memcpy(&dsk_start, &dp[1].dp_start, 4);
|
||||
if (drvread(sec, dsk_start + LABELSECTOR, 1))
|
||||
return -1;
|
||||
d = (void *)(sec + LABELOFFSET);
|
||||
if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
|
||||
printf("Invalid %s\n", "label");
|
||||
return -1;
|
||||
}
|
||||
if (!d->d_partitions[0].p_size) {
|
||||
printf("Invalid %s\n", "partition");
|
||||
return -1;
|
||||
}
|
||||
dsk_start += d->d_partitions[0].p_offset;
|
||||
dsk_start -= d->d_partitions[RAW_PART].p_offset;
|
||||
dsk_meta++;
|
||||
}
|
||||
return drvread(buf, dsk_start + lba, nblk);
|
||||
return drvread(buf, dsk_start + lba, nblk);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user