? common/ufsread.c.lite ? common/ufsread.c.x ? i386/boot2/ldscript.i386 Index: common/ufsread.c =================================================================== RCS file: /home/ncvs/src/sys/boot/common/ufsread.c,v retrieving revision 1.9 diff -u -r1.9 ufsread.c --- common/ufsread.c 14 Dec 2002 19:39:44 -0000 1.9 +++ common/ufsread.c 15 Dec 2002 22:48:17 -0000 @@ -43,9 +43,6 @@ (fsbtodb(fs, cgimin(fs, ino_to_cg(fs, x))) + \ (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK)) #define INO_TO_VBO(ipervblk, x) ((x) % ipervblk) -#define FS_TO_VBA(fs, fsb, off) (fsbtodb(fs, fsb) + \ - ((off) / VBLKSIZE) * DBPERVBLK) -#define FS_TO_VBO(fs, fsb, off) ((off) & VBLKMASK) /* Buffers that must not span a 64k boundary. */ struct dmadat { @@ -62,49 +59,33 @@ static int ls, dsk_meta; static uint32_t fs_off; -static __inline__ int -fsfind(const char *name, ino_t * ino) -{ - char buf[DEV_BSIZE]; - struct dirent *d; - char *s; - ssize_t n; - - fs_off = 0; - while ((n = fsread(*ino, buf, DEV_BSIZE)) > 0) - for (s = buf; s < buf + DEV_BSIZE;) { - d = (void *)s; - if (ls) - printf("%s ", d->d_name); - else if (!strcmp(name, d->d_name)) { - *ino = d->d_fileno; - return d->d_type; - } - s += d->d_reclen; - } - if (n != -1 && ls) - printf("\n"); - return 0; -} - static ino_t lookup(const char *path) { - char name[MAXNAMLEN + 1]; + static char name[MAXNAMLEN + 1]; + static char buf[DEV_BSIZE]; + struct dirent *d; const char *s; + char *p; ino_t ino; ssize_t n; int dt; ino = ROOTINO; dt = DT_DIR; + fs_off = 0; +#ifdef __i386__ /* take advantage of little endian */ + *(uint16_t *)&name[0] = '/'; +#else name[0] = '/'; name[1] = '\0'; +#endif + /* XXX I'm pretty sure I've broken this */ for (;;) { if (*path == '/') path++; if (!*path) - break; + return 0; for (s = path; *s && *s != '/'; s++); if ((n = s - path) > MAXNAMLEN) return 0; @@ -112,14 +93,27 @@ memcpy(name, path, n); name[n] = 0; if (dt != DT_DIR) { - printf("%s: not a directory.\n", name); + printf("not dir\n"); return (0); } - if ((dt = fsfind(name, &ino)) <= 0) - break; + while ((n = fsread(ino, buf, DEV_BSIZE)) > 0) { + for (p = buf; p < buf + DEV_BSIZE;) { + d = (struct dirent *)p; + if (ls) + printf("%s ", d->d_name); + else if (!strcmp(name, d->d_name)) { + ino = d->d_fileno; + dt = d->d_type; + if (dt == DT_REG) + return ino; + } + p += d->d_reclen; + } + } + if (n != -1 && ls) + printf("\n"); path = s; } - return dt == DT_REG ? ino : 0; } /* Index: i386/boot2/Makefile =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/boot2/Makefile,v retrieving revision 1.41 diff -u -r1.41 Makefile --- i386/boot2/Makefile 14 Dec 2002 19:44:13 -0000 1.41 +++ i386/boot2/Makefile 15 Dec 2002 22:48:17 -0000 @@ -31,10 +31,10 @@ # Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit. # BOOT2_UFS?= UFS2_ONLY -# BOOT2_UFS?= UFS1_AND_UFS2 -BOOT2_UFS?= UFS1_ONLY +BOOT2_UFS?= UFS1_AND_UFS2 +# BOOT2_UFS?= UFS1_ONLY -CFLAGS= -elf -ffreestanding -Os -fno-builtin \ +CFLAGS= -elf -ffreestanding -Os -fno-builtin -fomit-frame-pointer \ -fno-guess-branch-probability \ -mrtd \ -D${BOOT2_UFS} \ @@ -44,7 +44,7 @@ -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \ -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings -LDFLAGS=-nostdlib -static -N +LDFLAGS=-nostdlib -static -N --gc-sections all: boot1 boot2 Index: i386/boot2/boot2.c =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/boot2/boot2.c,v retrieving revision 1.56 diff -u -r1.56 boot2.c --- i386/boot2/boot2.c 14 Dec 2002 19:40:35 -0000 1.56 +++ i386/boot2/boot2.c 15 Dec 2002 22:48:17 -0000 @@ -43,8 +43,6 @@ #define RBX_ASKNAME 0x0 /* -a */ #define RBX_SINGLE 0x1 /* -s */ #define RBX_DFLTROOT 0x5 /* -r */ -#define RBX_KDB 0x6 /* -d */ -#define RBX_CONFIG 0xa /* -c */ #define RBX_VERBOSE 0xb /* -v */ #define RBX_SERIAL 0xc /* -h */ #define RBX_CDROM 0xd /* -C */ @@ -62,7 +60,7 @@ #define PATH_KERNEL "/kernel" #define ARGS 0x900 -#define NOPT 14 +#define NOPT 12 #define NDEV 5 #define MEM_BASE 0x12 #define MEM_EXT 0x15 @@ -79,14 +77,12 @@ extern uint32_t _end; -static const char optstr[NOPT] = "DhaCcdgmnPprsv"; -static const unsigned char flags[NOPT] = { +static const char optstr[NOPT] = "DhaCgmnPprsv"; +static const char flags[NOPT] = { RBX_DUAL, RBX_SERIAL, RBX_ASKNAME, RBX_CDROM, - RBX_CONFIG, - RBX_KDB, RBX_GDB, RBX_MUTE, RBX_NOINTR, @@ -115,14 +111,12 @@ static struct bootinfo bootinfo; static uint8_t ioctrl = IO_KEYBOARD; -void exit(int); -static void load(const char *); -static int parse(char *); +static void load(void); +static int parse(void); static int xfsread(ino_t, void *, size_t); static int dskread(void *, unsigned, unsigned); static void printf(const char *,...); static void putchar(int); -static uint32_t memsize(int); static int drvread(void *, unsigned, unsigned); static int keyhit(unsigned); static int xputc(int); @@ -150,37 +144,43 @@ return 0; } +static inline uint32_t +memsize(int type) +{ + v86.addr = type; + v86.eax = 0x8800; + v86int(); + return v86.eax; +} + static inline void -getstr(char *str, int size) +getcmd(void) { char *s; int c; - s = str; + s = cmd; for (;;) { switch (c = xgetc(0)) { case 0: break; case '\177': - c = '\b'; case '\b': - if (s > str) { + if (s > cmd) { s--; - putchar('\b'); - putchar(' '); - } else - c = 0; + printf("\b \b"); + } break; case '\n': case '\r': *s = 0; return; default: - if (s - str < size - 1) + if (s - cmd < sizeof(cmd) - 1) *s++ = c; - } - if (c) putchar(c); + break; + } } } @@ -220,7 +220,7 @@ if (*cmd) { printf("%s: %s", PATH_CONFIG, cmd); - if (parse(cmd)) + if (parse()) autoboot = 0; /* Do not process this command twice */ *cmd = 0; @@ -234,7 +234,7 @@ if (autoboot && !*kname) { memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3)); if (!keyhit(3*SECOND)) { - load(kname); + load(); memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL)); } } @@ -242,11 +242,7 @@ /* Present the user with the boot2 prompt. */ for (;;) { -#ifdef UFS1_ONLY - printf(" \n>> FreeBSD/i386/UFS1 BOOT\n" -#else - printf(" \n>> FreeBSD/i386/UFS[12] BOOT\n" -#endif + printf(" \nFreeBSD/i386 BOOT\n" "Default: %u:%s(%u,%c)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, @@ -254,25 +250,19 @@ if (ioctrl & IO_SERIAL) sio_flush(); if (!autoboot || keyhit(5*SECOND)) - getstr(cmd, sizeof(cmd)); + getcmd(); else putchar('\n'); autoboot = 0; - if (parse(cmd)) + if (parse()) putchar('\a'); else - load(kname); + load(); } } -/* XXX - Needed for btxld to link the boot2 binary; do not remove. */ -void -exit(int x) -{ -} - static void -load(const char *fname) +load(void) { union { struct exec ex; @@ -285,9 +275,9 @@ uint32_t addr, x; int fmt, i, j; - if (!(ino = lookup(fname))) { + if (!(ino = lookup(kname))) { if (!ls) - printf("No %s\n", fname); + printf("No %s\n", kname); return; } if (xfsread(ino, &hdr, sizeof(hdr))) @@ -311,7 +301,7 @@ return; p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE); bootinfo.bi_symtab = VTOP(p); - memcpy(p, (char *)&hdr.ex.a_syms, sizeof(hdr.ex.a_syms)); + memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms)); p += sizeof(hdr.ex.a_syms); if (hdr.ex.a_syms) { if (xfsread(ino, p, hdr.ex.a_syms)) @@ -348,7 +338,7 @@ if (xfsread(ino, &es, sizeof(es))) return; for (i = 0; i < 2; i++) { - memcpy(p, (char *)&es[i].sh_size, sizeof(es[i].sh_size)); + memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size)); p += sizeof(es[i].sh_size); fs_off = es[i].sh_offset; if (xfsread(ino, p, es[i].sh_size)) @@ -359,7 +349,7 @@ addr = hdr.eh.e_entry & 0xffffff; } bootinfo.bi_esymtab = VTOP(p); - bootinfo.bi_kernelname = VTOP(fname); + bootinfo.bi_kernelname = VTOP(kname); bootinfo.bi_bios_dev = dsk.drive; __exec((caddr_t)addr, opts & RBX_MASK, MAKEBOOTDEV(dev_maj[dsk.type], 0, dsk.slice, dsk.unit, dsk.part), @@ -367,11 +357,13 @@ } static int -parse(char *arg) +parse(void) { - char *p, *q; - int drv, c, i; + char *arg, *p, *q; + int c, i; + unsigned int drv; + arg = cmd; while ((c = *arg++)) { if (c == ' ' || c == '\t' || c == '\n') continue; @@ -387,9 +379,10 @@ } if (opts & 1 << RBX_PROBEKBD) { i = *(uint8_t *)PTOV(0x496) & 0x10; - /* printf("Keyboard: %s\n", i ? "yes" : "no"); */ - if (!i) + if (!i) { + printf("No keyboard\n"); opts |= 1 << RBX_DUAL | 1 << RBX_SERIAL; + } opts &= ~(1 << RBX_PROBEKBD); } ioctrl = opts & 1 << RBX_DUAL ? (IO_SERIAL|IO_KEYBOARD) : @@ -401,9 +394,9 @@ if (*q) { drv = -1; if (arg[1] == ':') { - if (*arg < '0' || *arg > '9') - return -1; drv = *arg - '0'; + if (drv > 9) + return -1; arg += 2; } if (q - arg != 2) @@ -414,21 +407,22 @@ return -1; dsk.type = i; arg += 3; - if (arg[1] != ',' || *arg < '0' || *arg > '9') - return -1; dsk.unit = *arg - '0'; + if (arg[1] != ',' || dsk.unit > 9) + return -1; arg += 2; dsk.slice = WHOLE_DISK_SLICE; if (arg[1] == ',') { - if (*arg < '0' || *arg > '0' + NDOSPART) + dsk.slice = *arg - '0' + 1; + if (dsk.slice > NDOSPART) return -1; - if ((dsk.slice = *arg - '0')) - dsk.slice++; arg += 2; } - if (arg[1] != ')' || *arg < 'a' || *arg > 'p') + if (arg[1] != ')') return -1; dsk.part = *arg - 'a'; + if (dsk.part > 7) + return -1; arg += 2; if (drv == -1) drv = dsk.unit; @@ -512,11 +506,10 @@ static void printf(const char *fmt,...) { - static const char digits[16] = "0123456789abcdef"; va_list ap; char buf[10]; char *s; - unsigned r, u; + unsigned u; int c; va_start(ap, fmt); @@ -532,13 +525,11 @@ putchar(*s); continue; case 'u': - case 'x': - r = c == 'u' ? 10U : 16U; u = va_arg(ap, unsigned); s = buf; do - *s++ = digits[u % r]; - while (u /= r); + *s++ = u % 10; + while (u /= 10); while (--s >= buf) putchar(*s); continue; @@ -558,15 +549,6 @@ xputc(c); } -static uint32_t -memsize(int type) -{ - v86.addr = type; - v86.eax = 0x8800; - v86int(); - return v86.eax; -} - static int drvread(void *buf, unsigned lba, unsigned nblk) { @@ -583,7 +565,7 @@ v86int(); v86.ctl = V86_FLAGS; if (V86_CY(v86.efl)) { - printf("Disk error 0x%x lba 0x%x\n", v86.eax >> 8 & 0xff, lba); + printf("Error %u lba %u\n", v86.eax >> 8 & 0xff, lba); return -1; } return 0; @@ -633,7 +615,7 @@ } } -static int +static inline int getc(int fn) { v86.addr = 0x16; Index: i386/btx/lib/Makefile =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/btx/lib/Makefile,v retrieving revision 1.10 diff -u -r1.10 Makefile --- i386/btx/lib/Makefile 17 Sep 2002 01:48:55 -0000 1.10 +++ i386/btx/lib/Makefile 15 Dec 2002 22:48:17 -0000 @@ -1,5 +1,6 @@ # $FreeBSD: src/sys/boot/i386/btx/lib/Makefile,v 1.10 2002/09/17 01:48:55 peter Exp $ +# btxsys.o must follow btxcsu.o due to a fallthrough OBJS= btxcsu.o btxsys.o btxv86.o CLEANFILES+= crt0.o ${OBJS} Index: i386/btx/lib/btxcsu.s =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/btx/lib/btxcsu.s,v retrieving revision 1.3 diff -u -r1.3 btxcsu.s --- i386/btx/lib/btxcsu.s 28 Aug 1999 00:40:07 -0000 1.3 +++ i386/btx/lib/btxcsu.s 15 Dec 2002 22:48:17 -0000 @@ -35,9 +35,11 @@ addl $ARGADJ,%eax # argument movl %eax,__args # pointer call main # Invoke client main() - call exit # Invoke client exit() + # The code for __exit follows immediately, fallthrough # # Data. # - .comm __base,4 # Client base address - .comm __args,4 # Client arguments + .bss + .globl __base, __args +__base: .space 4 # Client base address +__args: .space 4 # Client arguments Index: i386/btx/lib/btxv86.s =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/btx/lib/btxv86.s,v retrieving revision 1.3 diff -u -r1.3 btxv86.s --- i386/btx/lib/btxv86.s 28 Aug 1999 00:40:08 -0000 1.3 +++ i386/btx/lib/btxv86.s 15 Dec 2002 22:48:17 -0000 @@ -81,5 +81,7 @@ # # V86 interface structure. # - .comm __v86,SIZ_V86 - .comm __v86ret,4 + .bss + .globl __v86, __v86ret +__v86: .space SIZ_V86 +__v86ret: .space 4 Index: i386/mbr/mbr.s =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/mbr/mbr.s,v retrieving revision 1.6 diff -u -r1.6 mbr.s --- i386/mbr/mbr.s 27 Jun 2000 20:04:10 -0000 1.6 +++ i386/mbr/mbr.s 15 Dec 2002 22:48:17 -0000 @@ -88,10 +88,10 @@ movb 0x1(%si),%dh # Load head movw 0x2(%si),%cx # Load cylinder:sector movw $LOAD,%bx # Transfer buffer - cmpb $0xff,%dh # Might we need to use LBA? - jnz main.7 # No. - cmpw $0xffff,%cx # Do we need to use LBA? - jnz main.7 # No. +# cmpb $0xff,%dh # Might we need to use LBA? +# jnz main.7 # No. +# cmpw $0xffff,%cx # Do we need to use LBA? +# jnz main.7 # No. pushw %cx # Save %cx pushw %bx # Save %bx movw $0x55aa,%bx # Magic