Index: stand/defs.mk =================================================================== --- stand/defs.mk +++ stand/defs.mk @@ -111,6 +111,7 @@ .if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1) CFLAGS+= -march=i386 CFLAGS.gcc+= -mpreferred-stack-boundary=2 +CFLAGS.clang+= -Oz -mstack-alignment=8 .endif .if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 CFLAGS+= -fPIC -mno-red-zone Index: stand/efi/boot1/ufs_module.c =================================================================== --- stand/efi/boot1/ufs_module.c +++ stand/efi/boot1/ufs_module.c @@ -38,12 +38,15 @@ #include #include +#include + #include "boot_module.h" +#include "ufsread.h" static dev_info_t *devinfo; static dev_info_t *devices; -static int +int dskread(void *buf, u_int64_t lba, int nblk) { int size; @@ -66,8 +69,6 @@ return (0); } -#include "ufsread.c" - static struct dmadat __dmadat; static int Index: stand/i386/boot2/Makefile =================================================================== --- stand/i386/boot2/Makefile +++ stand/i386/boot2/Makefile @@ -81,7 +81,7 @@ ${OBJCOPY} -S -O binary boot2.out ${.TARGET} boot2.out: ${BTXCRT} boot2.o sio.o - ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} + ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSA32} SRCS= boot2.c boot2.h Index: stand/i386/boot2/boot2.c =================================================================== --- stand/i386/boot2/boot2.c +++ stand/i386/boot2/boot2.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -35,6 +37,7 @@ #include "lib.h" #include "paths.h" #include "rbx.h" +#include "ufsread.h" /* Define to 0 to omit serial support */ #ifndef SERIAL @@ -109,21 +112,23 @@ static uint8_t ioctrl = IO_KEYBOARD; #endif -int main(void); -void exit(int); -static void load(void); -static int parse(void); -static int dskread(void *, unsigned, unsigned); -static void printf(const char *,...); -static void putchar(int); -static int drvread(void *, unsigned, unsigned); -static int keyhit(unsigned); -static int xputc(int); -static int xgetc(int); -static inline int getc(int); - -static void memcpy(void *, const void *, int); -static void +int main(void); +void exit(int); +void memcpy(void *, const void *, int); +void printf(const char *, ...); +int strcmp(const char *, const char *); +int dskread(void *, unsigned, unsigned); + +static void load(void); +static int parse(void); +static void putchar(int); +static int drvread(void *, unsigned, unsigned); +static int keyhit(unsigned); +static int xputc(int); +static int xgetc(int); +static inline int getc(int); + +void memcpy(void *dst, const void *src, int len) { const char *s = src; @@ -133,16 +138,13 @@ *d++ = *s++; } -static inline int +int strcmp(const char *s1, const char *s2) { for (; *s1 == *s2 && *s1; s1++, s2++); return (unsigned char)*s1 - (unsigned char)*s2; } -#define UFS_SMALL_CGBASE -#include "ufsread.c" - static int xfsread(ufs_ino_t inode, void *buf, size_t nbyte) { @@ -454,7 +456,7 @@ return 0; } -static int +int dskread(void *buf, unsigned lba, unsigned nblk) { struct dos_partition *dp; @@ -521,8 +523,8 @@ return -1; } -static void -printf(const char *fmt,...) +void +printf(const char *fmt, ...) { va_list ap; static char buf[10]; Index: stand/i386/gptboot/gptboot.c =================================================================== --- stand/i386/gptboot/gptboot.c +++ stand/i386/gptboot/gptboot.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -41,6 +43,7 @@ #include "cons.h" #include "gpt.h" #include "paths.h" +#include "ufsread.h" #define ARGS 0x900 #define NOPT 14 @@ -102,15 +105,15 @@ static char *heap_next; static char *heap_end; +int dskread(void *, daddr_t, unsigned); + static void load(void); static int parse_cmds(char *, int *); -static int dskread(void *, daddr_t, unsigned); #ifdef LOADER_GELI_SUPPORT static int vdev_read(void *vdev __unused, void *priv, off_t off, void *buf, size_t bytes); #endif -#include "ufsread.c" #include "gpt.c" #ifdef LOADER_GELI_SUPPORT #include "geliboot.c" @@ -574,7 +577,7 @@ return 0; } -static int +int dskread(void *buf, daddr_t lba, unsigned nblk) { int err; Index: stand/libsa/Makefile =================================================================== --- stand/libsa/Makefile +++ stand/libsa/Makefile @@ -145,6 +145,9 @@ .PATH: ${SRCTOP}/sys/ufs/ffs SRCS+=ffs_subr.c ffs_tables.c +# simple filesystem read support +SRCS+= ufsread.c + CFLAGS.bzipfs.c+= -I${SRCTOP}/contrib/bzip2 # explicit_bzero Index: stand/libsa/ufsread.h =================================================================== --- /dev/null +++ stand/libsa/ufsread.h @@ -0,0 +1,40 @@ +#ifndef UFSREAD_H +#define UFSREAD_H + +typedef uint32_t ufs_ino_t; + +/* + * We use 4k `virtual' blocks for filesystem data, whatever the actual + * filesystem block size. FFS blocks are always a multiple of 4k. + */ +#define VBLKSHIFT 12 +#define VBLKSIZE (1 << VBLKSHIFT) +#define VBLKMASK (VBLKSIZE - 1) +#define DBPERVBLK (VBLKSIZE / DEV_BSIZE) +#define INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define INO_TO_VBA(fs, ipervblk, x) \ + (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 { + char blkbuf[VBLKSIZE]; /* filesystem blocks */ + char indbuf[VBLKSIZE]; /* indir blocks */ + char sbbuf[SBLOCKSIZE]; /* superblock */ + char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ +}; +extern struct dmadat *dmadat; + +extern uint8_t ls, dsk_meta; +extern uint32_t fs_off; + +ufs_ino_t lookup(const char *); +ssize_t fsread(ufs_ino_t, void *, size_t); +ssize_t fsread_size(ufs_ino_t, void *, size_t, size_t *); + +#endif /* UFSREAD_H */ Index: stand/libsa/ufsread.c =================================================================== --- stand/libsa/ufsread.c +++ stand/libsa/ufsread.c @@ -46,10 +46,20 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include +#include "ufsread.h" + +/* These routines must be provided by other code. */ +void memcpy(void *, const void *, int); +void printf(const char *, ...); +int strcmp(const char *, const char *); +int dskread(void *, unsigned, unsigned); + #ifdef UFS_SMALL_CGBASE /* XXX: Revert to old (broken for over 1.5Tb filesystems) version of cgbase (see sys/ufs/ffs/fs.h rev 1.39) so that small boot loaders (e.g. boot2) can @@ -58,40 +68,10 @@ #define cgbase(fs, c) ((ufs2_daddr_t)((fs)->fs_fpg * (c))) #endif -typedef uint32_t ufs_ino_t; - -/* - * We use 4k `virtual' blocks for filesystem data, whatever the actual - * filesystem block size. FFS blocks are always a multiple of 4k. - */ -#define VBLKSHIFT 12 -#define VBLKSIZE (1 << VBLKSHIFT) -#define VBLKMASK (VBLKSIZE - 1) -#define DBPERVBLK (VBLKSIZE / DEV_BSIZE) -#define INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) -#define IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) -#define INO_TO_VBA(fs, ipervblk, x) \ - (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 { - char blkbuf[VBLKSIZE]; /* filesystem blocks */ - char indbuf[VBLKSIZE]; /* indir blocks */ - char sbbuf[SBLOCKSIZE]; /* superblock */ - char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ -}; -static struct dmadat *dmadat; - -static ufs_ino_t lookup(const char *); -static ssize_t fsread(ufs_ino_t, void *, size_t); +struct dmadat *dmadat; -static uint8_t ls, dsk_meta; -static uint32_t fs_off; +uint8_t ls, dsk_meta; +uint32_t fs_off; static __inline uint8_t fsfind(const char *name, ufs_ino_t * ino) @@ -118,7 +98,7 @@ return 0; } -static ufs_ino_t +ufs_ino_t lookup(const char *path) { static char name[UFS_MAXNAMLEN + 1]; @@ -164,7 +144,7 @@ #define DIP(field) fs.fs_magic == FS_UFS1_MAGIC ? dp1.field : dp2.field #endif -static ssize_t +ssize_t fsread_size(ufs_ino_t inode, void *buf, size_t nbyte, size_t *fsizep) { #ifndef UFS2_ONLY @@ -317,7 +297,7 @@ return nbyte; } -static ssize_t +ssize_t fsread(ufs_ino_t inode, void *buf, size_t nbyte) { Index: stand/mips/beri/boot2/Makefile =================================================================== --- stand/mips/beri/boot2/Makefile +++ stand/mips/beri/boot2/Makefile @@ -59,7 +59,8 @@ .PATH: ${BOOTSRC}/mips/beri/common CFLAGS+= -I${BOOTSRC}/mips/beri/common -flashboot.elf: relocate.o start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o +flashboot.elf: relocate.o start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o \ + ${LIBSA} ${CC} ${LDFLAGS} -T ${.CURDIR}/flashboot.ldscript -o ${.TARGET} \ ${.ALLSRC} ${LIBSA} flashboot: flashboot.elf @@ -67,7 +68,7 @@ flashboot.md5: flashboot md5 flashboot > flashboot.md5 -jtagboot: start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o +jtagboot: start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o ${LIBSA} ${CC} ${LDFLAGS} -T ${.CURDIR}/jtagboot.ldscript -o ${.TARGET} \ ${.ALLSRC} ${LIBSA} jtagboot.md5: jtagboot Index: stand/mips/beri/boot2/boot2.c =================================================================== --- stand/mips/beri/boot2/boot2.c +++ stand/mips/beri/boot2/boot2.c @@ -54,6 +54,8 @@ #include #include +#include + #include #include #include @@ -66,6 +68,7 @@ #include "paths.h" #include "rbx.h" +#include "ufsread.h" static int beri_argc; static const char **beri_argv, **beri_envv; @@ -138,17 +141,15 @@ static uint8_t ioctrl = IO_KEYBOARD; void putchar(int); +int dskread(void *, unsigned, unsigned); + static void boot_fromdram(void); static void boot_fromfs(void); static void load(void); static int parse(void); -static int dskread(void *, unsigned, unsigned); static int xputc(int); static int xgetc(int); -#define UFS_SMALL_CGBASE -#include "ufsread.c" - static struct dmadat __dmadat; static inline int @@ -543,7 +544,7 @@ } } -static int +int dskread(void *buf, unsigned lba, unsigned nblk) { #if 0 Index: stand/powerpc/boot1.chrp/Makefile =================================================================== --- stand/powerpc/boot1.chrp/Makefile +++ stand/powerpc/boot1.chrp/Makefile @@ -12,7 +12,10 @@ CFLAGS+=-I${LDRSRC} LDFLAGS=-nostdlib -static -Wl,-N -.PATH: ${SYSDIR}/libkern ${SRCTOP}/lib/libc/powerpc/gen ${.CURDIR} +DPADD+= ${LIBSA} +LDADD+= ${LIBSA} + +.PATH: ${SYSDIR}/libkern ${SRCTOP}/lib/libc/powerpc/gen ${.CURDIR} # The following inserts out objects into a template HFS # created by generate-hfs.sh Index: stand/powerpc/boot1.chrp/boot1.c =================================================================== --- stand/powerpc/boot1.chrp/boot1.c +++ stand/powerpc/boot1.chrp/boot1.c @@ -24,7 +24,10 @@ #include #include +#include + #include "paths.h" +#include "ufsread.h" #define BSIZEMAX 16384 @@ -48,13 +51,14 @@ static char blkbuf[BSIZEMAX]; static unsigned int fsblks; -static uint32_t fs_off; - int main(int ac, char **av); +int dskread(void *, u_int64_t, int); +void memcpy(void *dst, const void *src, size_t len); +int printf(const char *fmt, ...); +int strcmp(const char *s1, const char *s2); static void exit(int) __dead2; static void load(const char *); -static int dskread(void *, u_int64_t, int); static void usage(void); @@ -64,7 +68,6 @@ static int domount(const char *device, int quiet); static void panic(const char *fmt, ...) __dead2; -static int printf(const char *fmt, ...); static int putchar(char c, void *arg); static int vprintf(const char *fmt, va_list ap); static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); @@ -364,7 +367,7 @@ *d++ = *s++; } -static void +void memcpy(void *dst, const void *src, size_t len) { bcopy(src, dst, len); @@ -379,7 +382,7 @@ *p++ = 0; } -static int +int strcmp(const char *s1, const char *s2) { for (; *s1 == *s2 && *s1; s1++, s2++) @@ -387,8 +390,6 @@ return ((u_char)*s1 - (u_char)*s2); } -#include "ufsread.c" - int main(int ac, char **av) { @@ -540,7 +541,7 @@ ofw,NULL,0); } -static int +int dskread(void *buf, u_int64_t lba, int nblk) { /* @@ -567,7 +568,7 @@ exit(1); } -static int +int printf(const char *fmt, ...) { va_list ap; Index: stand/sparc64/boot1/Makefile =================================================================== --- stand/sparc64/boot1/Makefile +++ stand/sparc64/boot1/Makefile @@ -8,6 +8,9 @@ SRCS= _start.s boot1.c CLEANFILES+=${FILES} boot1.aout +DPADD+= ${LIBSA} +LDADD+= ${LIBSA} + BOOTBLOCKBASE= 0x4000 CFLAGS.clang+=-mcmodel=small Index: stand/sparc64/boot1/boot1.c =================================================================== --- stand/sparc64/boot1/boot1.c +++ stand/sparc64/boot1/boot1.c @@ -24,7 +24,10 @@ #include #include +#include + #include "paths.h" +#include "ufsread.h" #define READ_BUF_SIZE 8192 @@ -44,9 +47,12 @@ static ofwh_t bootdev; -static uint32_t fs_off; - int main(int ac, char **av); +int dskread(void *buf, u_int64_t lba, int nblk); +void memcpy(void *dst, const void *src, size_t len); +int printf(const char *fmt, ...); +int strcmp(const char *s1, const char *s2); + static void exit(int) __dead2; static void usage(void); @@ -61,10 +67,8 @@ static void bzero(void *b, size_t len); static int domount(const char *device); -static int dskread(void *buf, u_int64_t lba, int nblk); static void panic(const char *fmt, ...) __dead2; -static int printf(const char *fmt, ...); static int putchar(char c, void *arg); static int vprintf(const char *fmt, va_list ap); static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); @@ -293,7 +297,7 @@ *d++ = *s++; } -static void +void memcpy(void *dst, const void *src, size_t len) { @@ -309,7 +313,7 @@ *p++ = 0; } -static int +int strcmp(const char *s1, const char *s2) { @@ -448,8 +452,6 @@ #else -#include "ufsread.c" - static struct dmadat __dmadat; static void @@ -514,7 +516,7 @@ return (0); } -static int +int dskread(void *buf, u_int64_t lba, int nblk) { @@ -542,7 +544,7 @@ exit(1); } -static int +int printf(const char *fmt, ...) { va_list ap;