Changeset View
Changeset View
Standalone View
Standalone View
stand/sparc64/boot1/boot1.c
Show All 18 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/dirent.h> | #include <sys/dirent.h> | ||||
#include <machine/elf.h> | #include <machine/elf.h> | ||||
#include <machine/stdarg.h> | #include <machine/stdarg.h> | ||||
#include <ufs/ffs/fs.h> | |||||
#include "paths.h" | #include "paths.h" | ||||
#include "ufsread.h" | |||||
#define READ_BUF_SIZE 8192 | #define READ_BUF_SIZE 8192 | ||||
typedef int putc_func_t(char c, void *arg); | typedef int putc_func_t(char c, void *arg); | ||||
typedef int32_t ofwh_t; | typedef int32_t ofwh_t; | ||||
struct sp_data { | struct sp_data { | ||||
char *sp_buf; | char *sp_buf; | ||||
u_int sp_len; | u_int sp_len; | ||||
u_int sp_size; | u_int sp_size; | ||||
}; | }; | ||||
static const char digits[] = "0123456789abcdef"; | static const char digits[] = "0123456789abcdef"; | ||||
static char bootpath[128]; | static char bootpath[128]; | ||||
static char bootargs[128]; | static char bootargs[128]; | ||||
static ofwh_t bootdev; | static ofwh_t bootdev; | ||||
static uint32_t fs_off; | |||||
int main(int ac, char **av); | 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 exit(int) __dead2; | ||||
static void usage(void); | static void usage(void); | ||||
#ifdef ZFSBOOT | #ifdef ZFSBOOT | ||||
static void loadzfs(void); | static void loadzfs(void); | ||||
static int zbread(char *buf, off_t off, size_t bytes); | static int zbread(char *buf, off_t off, size_t bytes); | ||||
#else | #else | ||||
static void load(const char *); | static void load(const char *); | ||||
#endif | #endif | ||||
static void bcopy(const void *src, void *dst, size_t len); | static void bcopy(const void *src, void *dst, size_t len); | ||||
static void bzero(void *b, size_t len); | static void bzero(void *b, size_t len); | ||||
static int domount(const char *device); | 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 void panic(const char *fmt, ...) __dead2; | ||||
static int printf(const char *fmt, ...); | |||||
static int putchar(char c, void *arg); | static int putchar(char c, void *arg); | ||||
static int vprintf(const char *fmt, va_list ap); | static int vprintf(const char *fmt, va_list ap); | ||||
static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); | static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); | ||||
static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap); | static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap); | ||||
static int __puts(const char *s, putc_func_t *putc, void *arg); | static int __puts(const char *s, putc_func_t *putc, void *arg); | ||||
static int __sputc(char c, void *arg); | static int __sputc(char c, void *arg); | ||||
static char *__uitoa(char *buf, u_int val, int base); | static char *__uitoa(char *buf, u_int val, int base); | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
const char *s = src; | const char *s = src; | ||||
char *d = dst; | char *d = dst; | ||||
while (len-- != 0) | while (len-- != 0) | ||||
*d++ = *s++; | *d++ = *s++; | ||||
} | } | ||||
static void | void | ||||
memcpy(void *dst, const void *src, size_t len) | memcpy(void *dst, const void *src, size_t len) | ||||
{ | { | ||||
bcopy(src, dst, len); | bcopy(src, dst, len); | ||||
} | } | ||||
static void | static void | ||||
bzero(void *b, size_t len) | bzero(void *b, size_t len) | ||||
{ | { | ||||
char *p = b; | char *p = b; | ||||
while (len-- != 0) | while (len-- != 0) | ||||
*p++ = 0; | *p++ = 0; | ||||
} | } | ||||
static int | int | ||||
strcmp(const char *s1, const char *s2) | strcmp(const char *s1, const char *s2) | ||||
{ | { | ||||
for (; *s1 == *s2 && *s1; s1++, s2++) | for (; *s1 == *s2 && *s1; s1++, s2++) | ||||
; | ; | ||||
return ((u_char)*s1 - (u_char)*s2); | return ((u_char)*s1 - (u_char)*s2); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | if (ph.p_filesz != ph.p_memsz) | ||||
bzero(p + ph.p_filesz, ph.p_memsz - ph.p_filesz); | bzero(p + ph.p_filesz, ph.p_memsz - ph.p_filesz); | ||||
} | } | ||||
ofw_close(bootdev); | ofw_close(bootdev); | ||||
(*(void (*)(int, int, int, int, ofwfp_t))eh.e_entry)(0, 0, 0, 0, ofw); | (*(void (*)(int, int, int, int, ofwfp_t))eh.e_entry)(0, 0, 0, 0, ofw); | ||||
} | } | ||||
#else | #else | ||||
#include "ufsread.c" | |||||
static struct dmadat __dmadat; | static struct dmadat __dmadat; | ||||
static void | static void | ||||
load(const char *fname) | load(const char *fname) | ||||
{ | { | ||||
Elf64_Ehdr eh; | Elf64_Ehdr eh; | ||||
Elf64_Phdr ph; | Elf64_Phdr ph; | ||||
caddr_t p; | caddr_t p; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | #ifndef ZFSBOOT | ||||
if (fsread(0, NULL, 0)) { | if (fsread(0, NULL, 0)) { | ||||
printf("domount: can't read superblock\n"); | printf("domount: can't read superblock\n"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
#endif | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | int | ||||
dskread(void *buf, u_int64_t lba, int nblk) | dskread(void *buf, u_int64_t lba, int nblk) | ||||
{ | { | ||||
/* | /* | ||||
* The Open Firmware should open the correct partition for us. | * The Open Firmware should open the correct partition for us. | ||||
* That means, if we read from offset zero on an open instance handle, | * That means, if we read from offset zero on an open instance handle, | ||||
* we should read from offset zero of that partition. | * we should read from offset zero of that partition. | ||||
*/ | */ | ||||
Show All 11 Lines | panic(const char *fmt, ...) | ||||
va_start(ap, fmt); | va_start(ap, fmt); | ||||
vsnprintf(buf, sizeof buf, fmt, ap); | vsnprintf(buf, sizeof buf, fmt, ap); | ||||
printf("panic: %s\n", buf); | printf("panic: %s\n", buf); | ||||
va_end(ap); | va_end(ap); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
static int | int | ||||
printf(const char *fmt, ...) | printf(const char *fmt, ...) | ||||
{ | { | ||||
va_list ap; | va_list ap; | ||||
int ret; | int ret; | ||||
va_start(ap, fmt); | va_start(ap, fmt); | ||||
ret = vprintf(fmt, ap); | ret = vprintf(fmt, ap); | ||||
va_end(ap); | va_end(ap); | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |