Deleted Added
full compact
boot2.c (40320) boot2.c (40323)
1/*
2 * Copyright (c) 1998 Robert Nordier
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are freely
6 * permitted provided that the above copyright notice and this
7 * paragraph and the following disclaimer are duplicated in all
8 * such forms.
9 *
10 * This software is provided "AS IS" and without any express or
11 * implied warranties, including, without limitation, the implied
12 * warranties of merchantability and fitness for a particular
13 * purpose.
14 */
15
16/*
1/*
2 * Copyright (c) 1998 Robert Nordier
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are freely
6 * permitted provided that the above copyright notice and this
7 * paragraph and the following disclaimer are duplicated in all
8 * such forms.
9 *
10 * This software is provided "AS IS" and without any express or
11 * implied warranties, including, without limitation, the implied
12 * warranties of merchantability and fitness for a particular
13 * purpose.
14 */
15
16/*
17 * $Id: boot2.c,v 1.3 1998/10/13 21:35:42 rnordier Exp $
17 * $Id: boot2.c,v 1.4 1998/10/13 22:17:05 rnordier Exp $
18 */
19
20#include <sys/param.h>
21#include <sys/reboot.h>
22#include <sys/diskslice.h>
23#include <sys/disklabel.h>
24#include <sys/dirent.h>
25#include <machine/bootinfo.h>

--- 74 unchanged lines hidden (view full) ---

100static uint32_t fs_off;
101
102void exit(int);
103static void load(const char *);
104static int parse(char *);
105static void readfile(const char *, void *, size_t);
106static ino_t lookup(const char *);
107static int fsfind(const char *, ino_t *);
18 */
19
20#include <sys/param.h>
21#include <sys/reboot.h>
22#include <sys/diskslice.h>
23#include <sys/disklabel.h>
24#include <sys/dirent.h>
25#include <machine/bootinfo.h>

--- 74 unchanged lines hidden (view full) ---

100static uint32_t fs_off;
101
102void exit(int);
103static void load(const char *);
104static int parse(char *);
105static void readfile(const char *, void *, size_t);
106static ino_t lookup(const char *);
107static int fsfind(const char *, ino_t *);
108static int xfsread(ino_t, void *, size_t);
108static ssize_t fsread(ino_t, void *, size_t);
109static int dskread(void *, unsigned, unsigned);
110static int printf(const char *,...);
111static void getstr(char *, int);
112static int putchar(int);
113static int getchar(void);
114static void *memcpy(void *, const void *, size_t);
115static int strcmp(const char *, const char *);

--- 5 unchanged lines hidden (view full) ---

121static int putch(int);
122static int getch(void);
123
124int
125main(void)
126{
127 int autoboot, helpon, i;
128
109static ssize_t fsread(ino_t, void *, size_t);
110static int dskread(void *, unsigned, unsigned);
111static int printf(const char *,...);
112static void getstr(char *, int);
113static int putchar(int);
114static int getchar(void);
115static void *memcpy(void *, const void *, size_t);
116static int strcmp(const char *, const char *);

--- 5 unchanged lines hidden (view full) ---

122static int putch(int);
123static int getch(void);
124
125int
126main(void)
127{
128 int autoboot, helpon, i;
129
130 v86.ctl = V86_FLAGS;
129 dsk.drive = *(uint8_t *)PTOV(ARGS);
130 dsk.type = dsk.drive & DRV_HARD ? MAJ_WD : MAJ_FD;
131 dsk.unit = dsk.drive & DRV_MASK;
132 dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
133 bootinfo.bi_version = BOOTINFO_VERSION;
134 bootinfo.bi_size = sizeof(bootinfo);
135 bootinfo.bi_basemem = memsize(MEM_BASE);
136 bootinfo.bi_extmem = memsize(MEM_EXT);

--- 52 unchanged lines hidden (view full) ---

189 ino_t ino;
190 uint32_t addr, x;
191 int fmt, i, j;
192
193 if (!(ino = lookup(fname)) && !ls) {
194 printf("No `%s'\n", fname);
195 return;
196 }
131 dsk.drive = *(uint8_t *)PTOV(ARGS);
132 dsk.type = dsk.drive & DRV_HARD ? MAJ_WD : MAJ_FD;
133 dsk.unit = dsk.drive & DRV_MASK;
134 dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
135 bootinfo.bi_version = BOOTINFO_VERSION;
136 bootinfo.bi_size = sizeof(bootinfo);
137 bootinfo.bi_basemem = memsize(MEM_BASE);
138 bootinfo.bi_extmem = memsize(MEM_EXT);

--- 52 unchanged lines hidden (view full) ---

191 ino_t ino;
192 uint32_t addr, x;
193 int fmt, i, j;
194
195 if (!(ino = lookup(fname)) && !ls) {
196 printf("No `%s'\n", fname);
197 return;
198 }
197 if (fsread(ino, &hdr, sizeof(hdr)) != sizeof(hdr))
199 if (xfsread(ino, &hdr, sizeof(hdr)))
198 return;
199 if (N_GETMAGIC(hdr.ex) == ZMAGIC)
200 fmt = 0;
201 else if (IS_ELF(hdr.eh))
202 fmt = 1;
203 else {
204 printf("Invalid %s\n", "format");
205 return;
206 }
207 if (fmt == 0) {
208 addr = hdr.ex.a_entry & 0xffffff;
209 p = PTOV(addr);
210 printf("%s=0x%x ", "text", (unsigned)hdr.ex.a_text);
211 fs_off = PAGE_SIZE;
200 return;
201 if (N_GETMAGIC(hdr.ex) == ZMAGIC)
202 fmt = 0;
203 else if (IS_ELF(hdr.eh))
204 fmt = 1;
205 else {
206 printf("Invalid %s\n", "format");
207 return;
208 }
209 if (fmt == 0) {
210 addr = hdr.ex.a_entry & 0xffffff;
211 p = PTOV(addr);
212 printf("%s=0x%x ", "text", (unsigned)hdr.ex.a_text);
213 fs_off = PAGE_SIZE;
212 if (fsread(ino, p, hdr.ex.a_text) != hdr.ex.a_text)
214 if (xfsread(ino, p, hdr.ex.a_text))
213 return;
214 p += roundup2(hdr.ex.a_text, PAGE_SIZE);
215 printf("%s=0x%x ", "data", (unsigned)hdr.ex.a_data);
215 return;
216 p += roundup2(hdr.ex.a_text, PAGE_SIZE);
217 printf("%s=0x%x ", "data", (unsigned)hdr.ex.a_data);
216 if (fsread(ino, p, hdr.ex.a_data) != hdr.ex.a_data)
218 if (xfsread(ino, p, hdr.ex.a_data))
217 return;
218 p += hdr.ex.a_data;
219 printf("%s=0x%x ", "bss", (unsigned)hdr.ex.a_bss);
220 p += roundup2(hdr.ex.a_bss, PAGE_SIZE);
221 bootinfo.bi_symtab = VTOP(p);
222 memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
223 p += sizeof(hdr.ex.a_syms);
224 printf("symbols=[");
225 printf("+0x%x", (unsigned)hdr.ex.a_syms);
226 if (hdr.ex.a_syms) {
219 return;
220 p += hdr.ex.a_data;
221 printf("%s=0x%x ", "bss", (unsigned)hdr.ex.a_bss);
222 p += roundup2(hdr.ex.a_bss, PAGE_SIZE);
223 bootinfo.bi_symtab = VTOP(p);
224 memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
225 p += sizeof(hdr.ex.a_syms);
226 printf("symbols=[");
227 printf("+0x%x", (unsigned)hdr.ex.a_syms);
228 if (hdr.ex.a_syms) {
227 if (fsread(ino, p, hdr.ex.a_syms) != hdr.ex.a_syms)
229 if (xfsread(ino, p, hdr.ex.a_syms))
228 return;
229 p += hdr.ex.a_syms;
230 return;
231 p += hdr.ex.a_syms;
230 if (fsread(ino, p, sizeof(int)) != sizeof(int))
232 if (xfsread(ino, p, sizeof(int)))
231 return;
232 x = *(uint32_t *)p;
233 p += sizeof(int);
234 x -= sizeof(int);
235 printf("+0x%x", x);
233 return;
234 x = *(uint32_t *)p;
235 p += sizeof(int);
236 x -= sizeof(int);
237 printf("+0x%x", x);
236 if (fsread(ino, p, x) != x)
238 if (xfsread(ino, p, x))
237 return;
238 p += x;
239 }
240 } else {
241 fs_off = hdr.eh.e_phoff;
242 for (j = i = 0; i < hdr.eh.e_phoff && j < 2; i++) {
239 return;
240 p += x;
241 }
242 } else {
243 fs_off = hdr.eh.e_phoff;
244 for (j = i = 0; i < hdr.eh.e_phoff && j < 2; i++) {
243 if (fsread(ino, ep + j, sizeof(ep[0])) != sizeof(ep[0]))
245 if (xfsread(ino, ep + j, sizeof(ep[0])))
244 return;
245 if (ep[j].p_type == PT_LOAD)
246 j++;
247 }
248 for (i = 0; i < 2; i++) {
249 p = PTOV(ep[i].p_paddr & 0xffffff);
250 printf("%s=0x%x ", !i ? "text" : "data", ep[i].p_filesz);
251 fs_off = ep[i].p_offset;
246 return;
247 if (ep[j].p_type == PT_LOAD)
248 j++;
249 }
250 for (i = 0; i < 2; i++) {
251 p = PTOV(ep[i].p_paddr & 0xffffff);
252 printf("%s=0x%x ", !i ? "text" : "data", ep[i].p_filesz);
253 fs_off = ep[i].p_offset;
252 if (fsread(ino, p, ep[i].p_filesz) != ep[i].p_filesz)
254 if (xfsread(ino, p, ep[i].p_filesz))
253 return;
254 }
255 printf("%s=0x%x ", "bss", ep[1].p_memsz - ep[1].p_filesz);
256 p += roundup2(ep[1].p_memsz, PAGE_SIZE);
257 bootinfo.bi_symtab = VTOP(p);
258 printf("symbols=[");
259 if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
260 fs_off = hdr.eh.e_shoff + sizeof(es[0]) *
261 (hdr.eh.e_shstrndx + 1);
255 return;
256 }
257 printf("%s=0x%x ", "bss", ep[1].p_memsz - ep[1].p_filesz);
258 p += roundup2(ep[1].p_memsz, PAGE_SIZE);
259 bootinfo.bi_symtab = VTOP(p);
260 printf("symbols=[");
261 if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
262 fs_off = hdr.eh.e_shoff + sizeof(es[0]) *
263 (hdr.eh.e_shstrndx + 1);
262 if (fsread(ino, &es, sizeof(es)) != sizeof(es))
264 if (xfsread(ino, &es, sizeof(es)))
263 return;
264 for (i = 0; i < 2; i++) {
265 memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
266 p += sizeof(es[i].sh_size);
267 printf("+0x%x", es[i].sh_size);
268 fs_off = es[i].sh_offset;
265 return;
266 for (i = 0; i < 2; i++) {
267 memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
268 p += sizeof(es[i].sh_size);
269 printf("+0x%x", es[i].sh_size);
270 fs_off = es[i].sh_offset;
269 if (fsread(ino, p, es[i].sh_size) != es[i].sh_size)
271 if (xfsread(ino, p, es[i].sh_size))
270 return;
271 p += es[i].sh_size;
272 }
273 }
274 addr = hdr.eh.e_entry & 0xffffff;
275 }
276 bootinfo.bi_esymtab = VTOP(p);
277 printf("]\nentry=0x%x\n", addr);

--- 132 unchanged lines hidden (view full) ---

410 }
411 s += d->d_reclen;
412 }
413 if (n != -1 && ls)
414 putchar('\n');
415 return 0;
416}
417
272 return;
273 p += es[i].sh_size;
274 }
275 }
276 addr = hdr.eh.e_entry & 0xffffff;
277 }
278 bootinfo.bi_esymtab = VTOP(p);
279 printf("]\nentry=0x%x\n", addr);

--- 132 unchanged lines hidden (view full) ---

412 }
413 s += d->d_reclen;
414 }
415 if (n != -1 && ls)
416 putchar('\n');
417 return 0;
418}
419
420static int
421xfsread(ino_t inode, void *buf, size_t nbyte)
422{
423 if (fsread(inode, buf, nbyte) != nbyte) {
424 printf("Invalid %s\n", "format");
425 return -1;
426 }
427 return 0;
428}
429
418static ssize_t
419fsread(ino_t inode, void *buf, size_t nbyte)
420{
421 static struct fs fs;
422 static struct dinode din;
423 static char *blkbuf;
424 static ufs_daddr_t *indbuf;
425 static ino_t inomap;

--- 239 unchanged lines hidden (view full) ---

665 p = (void *)next;
666 next += size;
667 return p;
668}
669
670static uint32_t
671memsize(int type)
672{
430static ssize_t
431fsread(ino_t inode, void *buf, size_t nbyte)
432{
433 static struct fs fs;
434 static struct dinode din;
435 static char *blkbuf;
436 static ufs_daddr_t *indbuf;
437 static ino_t inomap;

--- 239 unchanged lines hidden (view full) ---

677 p = (void *)next;
678 next += size;
679 return p;
680}
681
682static uint32_t
683memsize(int type)
684{
673 v86.ctl = V86_FLAGS;
674 v86.addr = type;
675 v86.eax = 0x8800;
676 v86int();
677 return v86.eax;
678}
679
680static uint32_t
681drvinfo(int drive)

--- 6 unchanged lines hidden (view full) ---

688 return 0x4f010f;
689 return ((v86.ecx & 0xc0) << 18) | ((v86.ecx & 0xff00) << 8) |
690 (v86.edx & 0xff00) | (v86.ecx & 0x3f);
691}
692
693static int
694drvread(void *buf, unsigned lba, unsigned nblk)
695{
685 v86.addr = type;
686 v86.eax = 0x8800;
687 v86int();
688 return v86.eax;
689}
690
691static uint32_t
692drvinfo(int drive)

--- 6 unchanged lines hidden (view full) ---

699 return 0x4f010f;
700 return ((v86.ecx & 0xc0) << 18) | ((v86.ecx & 0xff00) << 8) |
701 (v86.edx & 0xff00) | (v86.ecx & 0x3f);
702}
703
704static int
705drvread(void *buf, unsigned lba, unsigned nblk)
706{
707 static unsigned c = 0x2d5c7c2f;
708
709 printf("%c\b", c = c << 8 | c >> 24);
696 v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
697 v86.addr = 0x604;
698 v86.eax = nblk;
699 v86.ebx = VTOPSEG(buf) << 16 | VTOPOFF(buf);
700 v86.ecx = lba;
701 v86.edx = dsk.drive;
702 v86int();
703 v86.ctl = V86_FLAGS;

--- 46 unchanged lines hidden ---
710 v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
711 v86.addr = 0x604;
712 v86.eax = nblk;
713 v86.ebx = VTOPSEG(buf) << 16 | VTOPOFF(buf);
714 v86.ecx = lba;
715 v86.edx = dsk.drive;
716 v86int();
717 v86.ctl = V86_FLAGS;

--- 46 unchanged lines hidden ---