diff options
Diffstat (limited to 'sys/arch/sgi/stand')
27 files changed, 0 insertions, 2789 deletions
diff --git a/sys/arch/sgi/stand/Makefile b/sys/arch/sgi/stand/Makefile deleted file mode 100644 index d18503c5228..00000000000 --- a/sys/arch/sgi/stand/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $OpenBSD: Makefile,v 1.8 2012/03/28 20:44:23 miod Exp $ - -SUBDIR= sgivol - -.if ${MACHINE} == "sgi" -SUBDIR+= libsa libsa32 libz libz32 -SUBDIR+= boot64 boot32 bootecoff -.endif - -.include <bsd.subdir.mk> diff --git a/sys/arch/sgi/stand/Makefile.inc b/sys/arch/sgi/stand/Makefile.inc deleted file mode 100644 index b99376334ec..00000000000 --- a/sys/arch/sgi/stand/Makefile.inc +++ /dev/null @@ -1,46 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.10 2012/10/19 13:51:59 miod Exp $ -# $NetBSD: Makefile.inc,v 1.7 2000/08/20 14:57:16 mrg Exp $ - -.ifndef __INCLUDED_STAND_MAKEFILE_INC -__INCLUDED_STAND_MAKEFILE_INC= - -BINDIR= /usr/mdec - -STANDALONE?= -D_STANDALONE - -.if ${MACHINE} == "sgi" -CPPFLAGS+= ${STANDALONE} -CPPFLAGS+= -I. - -CFLAGS+= -fno-stack-protector -Wall -CFLAGS+= -fno-builtin-vprintf -fno-builtin-printf -fno-builtin-putchar -CFLAGS+= -fno-builtin-exit -SAABI?= -mips3 -mno-abicalls -D_NO_ABICALLS -G 0 -fno-pic -fno-common -AS?= as -LD?= ld -LIBSA_CPPFLAGS?= -DNEEDS_HEAP_H -.endif - -### Figure out what to use for libsa -LIBSADIR?= ${.CURDIR}/../libsa - -.if exists(${LIBSADIR}/${__objdir}) -LIBSAOBJDIR= ${LIBSADIR}/${__objdir} -.else -LIBSAOBJDIR= ${LIBSADIR} -.endif - -LIBSA= ${LIBSAOBJDIR}/libsa.a - -### Figure out what to use for libz -LIBZDIR?= ${.CURDIR}/../libz - -.if exists(${LIBZDIR}/${__objdir}) -LIBZOBJDIR= ${LIBZDIR}/${__objdir} -.else -LIBZOBJDIR= ${LIBZDIR} -.endif - -LIBZ= ${LIBZOBJDIR}/libz.a - -.endif diff --git a/sys/arch/sgi/stand/Makefile32.inc b/sys/arch/sgi/stand/Makefile32.inc deleted file mode 100644 index 4b5e1977735..00000000000 --- a/sys/arch/sgi/stand/Makefile32.inc +++ /dev/null @@ -1,28 +0,0 @@ -# $OpenBSD: Makefile32.inc,v 1.6 2016/10/05 11:55:45 visa Exp $ - -.ifndef __INCLUDED_STAND_MAKEFILE32_INC -__INCLUDED_STAND_MAKEFILE32_INC= - -.if ${MACHINE} == "sgi" -# Silence warnings -CFLAGS+= -fno-builtin-snprintf -CFLAGS+= -fno-builtin-memcpy -CFLAGS+= -fno-builtin-memcmp -CFLAGS+= -fno-builtin-memset -CFLAGS+= -fno-builtin-strncpy -CFLAGS+= -fno-builtin-strncmp -# Override toolchain options to force 32 bit binaries -SAABI= -mno-abicalls -D_NO_ABICALLS -mabi=32 -mips2 -Wa,-G0 -AS?= as -AS+= -32 -LD?= ld -LD+= -m elf32btsmip -LIBSA_CPPFLAGS= -CFLAGS+= -DLIBSA_LONGLONG_PRINTF -.endif - -### Figure out what to use for libsa and libz -LIBSADIR= ${.CURDIR}/../libsa32 -LIBZDIR= ${.CURDIR}/../libz32 - -.endif diff --git a/sys/arch/sgi/stand/boot/Makefile b/sys/arch/sgi/stand/boot/Makefile deleted file mode 100644 index b9283f2d3b9..00000000000 --- a/sys/arch/sgi/stand/boot/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# $OpenBSD: Makefile,v 1.20 2019/10/29 02:55:52 deraadt Exp $ - -NOMAN= noman - -CFLAGS+= ${SAABI} -mno-abicalls -D_NO_ABICALLS -nostdinc -D__sgi__ \ - -I${.CURDIR}/../include -I${.CURDIR}/../../../.. \ - -I${.CURDIR}/../../../../lib/libsa \ - -I${.OBJDIR} -CFLAGS+= -D__INTERNAL_LIBSA_CREAD ${STANDALONE} -fno-pie -LDFLAGS+= -nopie -znorelro - -AFLAGS+= ${SAABI} - -S= ${.CURDIR}/../../../.. -SRCS= start.S arcbios.c boot.c conf.c diskio.c filesystem.c \ - netfs.c netio.c strstr.c - -.PATH: ${S}/lib/libsa -SRCS+= loadfile.c arc4.c - -.PATH: ${S}/lib/libkern/arch/mips64 ${S}/lib/libkern -SRCS+= memcpy.c memmove.c strchr.c strcmp.S strlcat.c strlcpy.c strlen.c \ - strncmp.c strrchr.c - -CLEANFILES+= machine mips64 - -.if !make(clean) && !make(cleandir) && !make(includes) && !make(libdep) && \ - !make(sadep) && !make(salibdir) && !make(obj) -.BEGIN: - @([ -h machine ] || ln -s ${.CURDIR}/../../include machine) - @([ -h mips64 ] || ln -s ${.CURDIR}/../../../mips64/include mips64) -.endif diff --git a/sys/arch/sgi/stand/boot/arcbios.c b/sys/arch/sgi/stand/boot/arcbios.c deleted file mode 100644 index e4196d7aff3..00000000000 --- a/sys/arch/sgi/stand/boot/arcbios.c +++ /dev/null @@ -1,408 +0,0 @@ -/* $OpenBSD: arcbios.c,v 1.20 2014/03/29 18:09:30 guenther Exp $ */ -/*- - * Copyright (c) 1996 M. Warner Losh. All rights reserved. - * Copyright (c) 1996-2004 Opsycon AB. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <lib/libkern/libkern.h> - -#include <mips64/arcbios.h> -#include <mips64/archtype.h> -#include <machine/autoconf.h> -#include <machine/cpu.h> -#include <machine/mnode.h> - -#include <stand.h> - -#ifdef __LP64__ -int bios_is_32bit; -#endif -void *bios_base; -#ifdef __LP64__ -u_int kl_n_shift = 32; -#endif - -int arcbios_init(void); -const char *boot_get_path_component(const char *, char *, int *); -const char *boot_getnr(const char *, int *); - -static const struct systypes { - char *sys_name; - int sys_ip; -} sys_types[] = { - { "SGI-IP20", 20 }, - { "SGI-IP22", 22 }, - { "SGI-IP26", 26 }, - { "SGI-IP28", 28 }, - { "SGI-IP30", 30 }, - { "SGI-IP32", 32 } -}; - -#define KNOWNSYSTEMS (nitems(sys_types)) - -/* - * ARCBios trampoline code. - */ -#ifdef __LP64__ -#define ARC_Call(Name,Offset) \ -__asm__("\n" \ -" .text\n" \ -" .ent " #Name "\n" \ -" .align 3\n" \ -" .set noreorder\n" \ -" .globl " #Name "\n" \ -#Name":\n" \ -" lw $3, bios_is_32bit\n"\ -" ld $2, bios_base\n"\ -" beqz $3, 1f\n" \ -" nop\n" \ -" lw $3, 0x20($2)\n" \ -" lw $2," #Offset "($3)\n"\ -" jr $2\n" \ -" nop\n" \ -"1:\n" \ -" ld $3, 2*0x20($2)\n"\ -" ld $2, 2*" #Offset "($3)\n"\ -" jr $2\n" \ -" nop\n" \ -" .end " #Name "\n" ); -#else -#define ARC_Call(Name,Offset) \ -__asm__("\n" \ -" .text\n" \ -" .ent " #Name "\n" \ -" .align 3\n" \ -" .set noreorder\n" \ -" .globl " #Name "\n" \ -#Name":\n" \ -" lw $2, bios_base\n"\ -" lw $3, 0x20($2)\n" \ -" lw $2," #Offset "($3)\n"\ -" jr $2\n" \ -" nop\n" \ -" .end " #Name "\n" ); -#endif - -#if 0 -ARC_Call(Bios_Load, 0x00); -ARC_Call(Bios_Invoke, 0x04); -ARC_Call(Bios_Execute, 0x08); -#endif -ARC_Call(Bios_Halt, 0x0c); -#if 0 -ARC_Call(Bios_PowerDown, 0x10); -ARC_Call(Bios_Restart, 0x14); -ARC_Call(Bios_Reboot, 0x18); -#endif -ARC_Call(Bios_EnterInteractiveMode, 0x1c); -#if 0 -ARC_Call(Bios_Unused1, 0x20); -#endif -ARC_Call(Bios_GetPeer, 0x24); -ARC_Call(Bios_GetChild, 0x28); -#if 0 -ARC_Call(Bios_GetParent, 0x2c); -ARC_Call(Bios_GetConfigurationData, 0x30); -ARC_Call(Bios_AddChild, 0x34); -ARC_Call(Bios_DeleteComponent, 0x38); -ARC_Call(Bios_GetComponent, 0x3c); -ARC_Call(Bios_SaveConfiguration, 0x40); -#endif -ARC_Call(Bios_GetSystemId, 0x44); -ARC_Call(Bios_GetMemoryDescriptor, 0x48); -#if 0 -ARC_Call(Bios_Unused2, 0x4c); -ARC_Call(Bios_GetTime, 0x50); -ARC_Call(Bios_GetRelativeTime, 0x54); -ARC_Call(Bios_GetDirectoryEntry, 0x58); -#endif -ARC_Call(Bios_Open, 0x5c); -ARC_Call(Bios_Close, 0x60); -ARC_Call(Bios_Read, 0x64); -#if 0 -ARC_Call(Bios_GetReadStatus, 0x68); -#endif -ARC_Call(Bios_Write, 0x6c); -ARC_Call(Bios_Seek, 0x70); -#if 0 -ARC_Call(Bios_Mount, 0x74); -ARC_Call(Bios_GetEnvironmentVariable, 0x78); -ARC_Call(Bios_SetEnvironmentVariable, 0x7c); -ARC_Call(Bios_GetFileInformation, 0x80); -ARC_Call(Bios_SetFileInformation, 0x84); -ARC_Call(Bios_FlushAllCaches, 0x88); -ARC_Call(Bios_TestUnicodeCharacter, 0x8c); -ARC_Call(Bios_GetDisplayStatus, 0x90); -#endif - -/* - * Simple getchar/putchar interface. - */ - -#if 0 -int -getchar() -{ - char buf[4]; - long cnt; - - if (Bios_Read(0, &buf[0], 1, &cnt) != 0) - return (-1); - - return (buf[0] & 255); -} -#endif - -void -putchar(int c) -{ - char buf[4]; - long cnt; - - if (c == '\n') { - buf[0] = '\r'; - buf[1] = c; - cnt = 2; - } else { - buf[0] = c; - cnt = 1; - } - - Bios_Write(1, &buf[0], cnt, &cnt); -} - -/* - * Identify ARCBios type. - */ -int -arcbios_init() -{ - arc_config_t *cf; - arc_sid_t *sid; -#ifdef __LP64__ - register_t prid; -#endif - char *sysid = NULL; - int sysid_len; - int i; - - /* - * Figure out where ARCBios can be addressed. On R8000, we can not - * use compatibility space, but on IP27/IP35, we can not blindly - * use XKPHYS due to subspacing, while compatibility space works. - * Fortunately we can get the processor ID to tell these apart, even - * though 32-bit coprocessor 0 instructions are not supposed to be - * supported on the R8000 (they probably misbehave somehow if the - * register has bits sets in the upper 32 bits, which is not the - * case of the R8000 PrId register). - */ -#ifdef __LP64__ - __asm__ volatile ("mfc0 %0, $15" /* COP_0_PRID */ : "=r" (prid)); - if ((prid & 0xff00) == (MIPS_R8000 << 8)) - bios_base = (void *)PHYS_TO_XKPHYS(ARCBIOS_BASE, CCA_CACHED); - else - bios_base = (void *)PHYS_TO_CKSEG0(ARCBIOS_BASE); -#else - bios_base = (void *)(int32_t)PHYS_TO_CKSEG0(ARCBIOS_BASE); -#endif - - /* - * Figure out if this is an ARCBios machine and if it is, see if we're - * dealing with a 32 or 64 bit version. - */ -#ifdef __LP64__ - if ((ArcBiosBase32->magic == ARC_PARAM_BLK_MAGIC) || - (ArcBiosBase32->magic == ARC_PARAM_BLK_MAGIC_BUG)) { - bios_is_32bit = 1; - } else if ((ArcBiosBase64->magic == ARC_PARAM_BLK_MAGIC) || - (ArcBiosBase64->magic == ARC_PARAM_BLK_MAGIC_BUG)) { - bios_is_32bit = 0; - } -#endif - - /* - * Minimal system identification. - */ - sid = (arc_sid_t *)Bios_GetSystemId(); - cf = (arc_config_t *)Bios_GetChild(NULL); - if (cf != NULL) { -#ifdef __LP64__ - if (bios_is_32bit) { - sysid = (char *)(long)cf->id; - sysid_len = cf->id_len; - } else { - sysid = (char *)((arc_config64_t *)cf)->id; - sysid_len = ((arc_config64_t *)cf)->id_len; - } -#else - sysid = (char *)(long)cf->id; - sysid_len = cf->id_len; -#endif - - if (sysid_len > 0 && sysid != NULL) { - sysid_len--; - for (i = 0; i < KNOWNSYSTEMS; i++) { - if (strlen(sys_types[i].sys_name) != sysid_len) - continue; - if (strncmp(sys_types[i].sys_name, sysid, - sysid_len) != 0) - continue; - return sys_types[i].sys_ip; /* Found it. */ - } - } - } else { -#ifdef __LP64__ - if (IP27_KLD_KLCONFIG(0)->magic == IP27_KLDIR_MAGIC) { - /* - * If we find a kldir assume IP27. Boot blocks - * do not need to tell IP27 and IP35 apart. - */ - return 27; - } -#endif - } - - printf("UNRECOGNIZED SYSTEM '%s' VENDOR '%s' PRODUCT '%s'\n", - cf == NULL || sysid == NULL ? "(null)" : sysid, - sid->vendor, sid->prodid); - printf("Halting system!\n"); - Bios_Halt(); - printf("Halting failed, use manual reset!\n"); - for (;;) ; -} - -/* - * Decompose the device pathname and find driver. - * Returns pointer to remaining filename path in file. - */ -int -devopen(struct open_file *f, const char *fname, char **file) -{ - const char *cp, *ncp, *ecp; - struct devsw *dp; - int partition = 0; - char namebuf[256]; - char devname[32]; - int rc, i, n, noopen = 0; - - ecp = cp = fname; - namebuf[0] = '\0'; - - /* - * Scan the component list and find device and partition. - */ - if (strncmp(cp, "bootp()", 7) == 0) { - strlcpy(devname, "bootp", sizeof(devname)); - strlcpy(namebuf, cp, sizeof(namebuf)); - noopen = 1; - } else if (strncmp(cp, "dksc(", 5) == 0) { - strncpy(devname, "scsi", sizeof(devname)); - cp += 5; - cp = boot_getnr(cp, &i); - /* i = controller number */ - if (*cp++ == ',') { - cp = boot_getnr(cp, &i); - /* i = target id */ - if (*cp++ == ',') { - memcpy(namebuf, fname, cp - fname); - namebuf[cp - fname] = '\0'; - strlcat(namebuf, "0)", sizeof namebuf); - - cp = boot_getnr(cp, &i); - partition = i; - cp++; /* skip final ) */ - } - } - } else { - ncp = boot_get_path_component(cp, namebuf, &i); - while (ncp != NULL) { - if (strcmp(namebuf, "partition") == 0) - partition = i; - ecp = ncp; - - /* XXX Do this with a table if more devs are added. */ - if (strcmp(namebuf, "scsi") == 0) - strncpy(devname, namebuf, sizeof(devname)); - - cp = ncp; - ncp = boot_get_path_component(cp, namebuf, &i); - } - - memcpy(namebuf, fname, ecp - fname); - namebuf[ecp - fname] = '\0'; - } - - /* - * Dig out the driver. - */ - dp = devsw; - n = ndevs; - while (n--) { - if (strcmp(devname, dp->dv_name) == 0) { - if (noopen) - rc = 0; - else - rc = (dp->dv_open)(f, namebuf, partition, 0); - if (rc == 0) { - f->f_dev = dp; - if (file && *cp != '\0') - *file = (char *)cp; - } - return (rc); - } - dp++; - } - return (ENXIO); -} - -const char * -boot_get_path_component(const char *p, char *comp, int *no) -{ - while (*p && *p != '(') - *comp++ = *p++; - *comp = '\0'; - - if (*p == '\0') - return (NULL); - - *no = 0; - p++; - while (*p && *p != ')') { - if (*p >= '0' && *p <= '9') - *no = *no * 10 + *p++ - '0'; - else - return (NULL); - } - return (++p); -} - -const char * -boot_getnr(const char *p, int *no) -{ - *no = 0; - while (*p >= '0' && *p <= '9') - *no = *no * 10 + *p++ - '0'; - return p; -} diff --git a/sys/arch/sgi/stand/boot/boot.c b/sys/arch/sgi/stand/boot/boot.c deleted file mode 100644 index cd3e104ab6b..00000000000 --- a/sys/arch/sgi/stand/boot/boot.c +++ /dev/null @@ -1,323 +0,0 @@ -/* $OpenBSD: boot.c,v 1.30 2020/06/06 10:53:09 visa Exp $ */ - -/* - * Copyright (c) 2004 Opsycon AB, www.opsycon.se. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include <sys/param.h> -#include <sys/stat.h> -#define _KERNEL -#include <sys/fcntl.h> -#undef _KERNEL - -#include <lib/libkern/libkern.h> -#include <lib/libsa/arc4.h> -#include <stand.h> - -#include <mips64/arcbios.h> -#include <mips64/cpu.h> - -#include <sys/exec_elf.h> -#undef ELFSIZE -#include "loadfile.h" - -void dobootopts(int, char **); -int loadrandom(const char *, const char *, void *, size_t); -char *strstr(char *, const char *); /* strstr.c */ - -enum { - AUTO_NONE, - AUTO_YES, - AUTO_NO, - AUTO_MINI, - AUTO_DEBUG -} bootauto = AUTO_NONE; -char *OSLoadPartition = NULL; -char *OSLoadFilename = NULL; - -int IP; - -char rnddata[BOOTRANDOM_MAX]; -struct rc4_ctx randomctx; - -/* - * OpenBSD/sgi Boot Loader. - */ -void -boot_main(int argc, char *argv[]) -{ - uint64_t marks[MARK_MAX]; - u_int64_t *esym; - char line[1024]; - u_long entry; - int fd; - extern int arcbios_init(void); - extern char version[]; - - IP = arcbios_init(); - printf("\nOpenBSD/sgi-IP%d ARCBios boot version %s\n", IP, version); - /* we want to print IP20 but load IP22 */ - if (IP == 20) - IP = 22; - - for (entry = 0; entry < argc; entry++) - printf("arg %d: %s\n", entry, argv[entry]); - - dobootopts(argc, argv); - if (OSLoadPartition == NULL) { - /* - * Things are probably horribly wrong, or user has no idea - * what's he's doing. Be nice lads and try to provide - * working defaults, which ought to work on all systems. - */ - OSLoadPartition = "disk(0)part(0)"; - } - strlcpy(line, OSLoadPartition, sizeof(line)); - if (OSLoadFilename != NULL) - strlcat(line, OSLoadFilename, sizeof(line)); - - printf("Boot: %s\n", line); - - /* - * Try and load randomness if booting from a disk. - */ - - if (bootauto != AUTO_MINI && - strstr(OSLoadPartition, "bootp(") == NULL && - strstr(OSLoadPartition, "cdrom(") == NULL) { - /* XXX set RB_GOODRANDOM in boothowto */ - loadrandom(OSLoadPartition, BOOTRANDOM, rnddata, - sizeof(rnddata)); - } - - rc4_keysetup(&randomctx, rnddata, sizeof rnddata); - rc4_skip(&randomctx, 1536); - - /* - * Load the kernel and symbol table. - */ - - marks[MARK_START] = 0; - if ((fd = loadfile(line, marks, LOAD_KERNEL | COUNT_KERNEL)) != -1) { - (void)close(fd); - - entry = marks[MARK_ENTRY]; -#ifdef __LP64__ - esym = (u_int64_t *)marks[MARK_END]; -#else -#undef CKSEG0_BASE -#define CKSEG0_BASE 0xffffffff80000000ULL - esym = (u_int64_t *)(uint32_t)PHYS_TO_CKSEG0(marks[MARK_END]); -#endif - - if (entry != 0) - ((void (*)())entry)(argc, argv, esym); - } - - /* We failed to load the kernel. */ - panic("Boot FAILED!"); - /* NOTREACHED */ -} - -__dead void -_rtt() -{ - Bios_EnterInteractiveMode(); - for (;;) ; -} - -/* - * Decode boot options. - */ -void -dobootopts(int argc, char **argv) -{ - static char filenamebuf[1 + 32]; - char *SystemPartition = NULL; - char *cp, *sep; - int i; - char *writein = NULL; - - for (i = 1; i < argc; i++) { - cp = argv[i]; - if (cp == NULL) - continue; - if (strncmp(cp, "OSLoadOptions=", 14) == 0) { - if (strcmp(&cp[14], "auto") == 0) - bootauto = AUTO_YES; - else if (strcmp(&cp[14], "single") == 0) - bootauto = AUTO_NO; - else if (strcmp(&cp[14], "mini") == 0) - bootauto = AUTO_MINI; - else if (strcmp(&cp[14], "debug") == 0) - bootauto = AUTO_DEBUG; - } else if (strncmp(cp, "OSLoadPartition=", 16) == 0) - OSLoadPartition = &cp[16]; - else if (strncmp(cp, "OSLoadFilename=", 15) == 0) - OSLoadFilename = &cp[15]; - else if (strncmp(cp, "SystemPartition=", 16) == 0) - SystemPartition = &cp[16]; - else { - /* - * Either a boot-related environment variable, or - * a boot write-in (boot path or options to the - * program being loaded). - */ - if (*cp == '-') - continue; /* options */ - if (strchr(cp, '=') != NULL) - continue; /* variable (or bad choice */ - /* of filename) */ - if (writein == NULL) - writein = cp; - } - } - - switch (bootauto) { - case AUTO_NONE: - /* If "OSLoadOptions=" is missing, use boot path if given. */ - if (writein != NULL) { - /* check for a possible path component */ - sep = strchr(writein, '('); - if (sep != NULL && strchr(sep, ')') != NULL) { - /* looks like this is a full path */ - OSLoadPartition = ""; - } else { - /* relative path, keep OSLoadPartition */ - } - OSLoadFilename = writein; - } - break; - case AUTO_MINI: - { - static char loadpart[64]; - char *p; - - strlcpy(loadpart, argv[0], sizeof loadpart); - if ((p = strstr(loadpart, "partition(8)")) != NULL) { - p += strlen("partition("); - } else if (strncmp(loadpart, "dksc(", 5) == 0) { - p = strstr(loadpart, ",8)"); - if (p != NULL) - p++; - } else - p = NULL; - - if (p != NULL) { - p[0] = '0'; - p[2] = '\0'; - snprintf(filenamebuf, sizeof filenamebuf, - "/bsd.rd.IP%d", IP); - OSLoadPartition = loadpart; - OSLoadFilename = filenamebuf; - } - } - break; - default: - break; - } -} - -/* - * Prevent loading a wrong kernel. - */ -int -check_phdr(void *v) -{ - Elf64_Phdr *phdr = (Elf64_Phdr *)v; - uint64_t addr; - - switch (IP) { - case 22: - addr = 0xffffffff88000000ULL >> 24; - break; - case 26: - addr = 0xa800000008000000ULL >> 24; - break; - case 27: - addr = 0xa800000000000000ULL >> 24; - break; - case 28: - case 30: - addr = 0xa800000020000000ULL >> 24; - break; - case 32: - addr = 0xffffffff80000000ULL >> 24; - break; - default: - /* - * If the system could not be identified, accept any - * address and hope the user knows what's he's doing. - */ - return 0; - } - - if ((phdr->p_vaddr >> 24) != addr) { - /* I'm sorry Dave, I can't let you do that. */ - printf("This kernel does not seem to be compiled for this" - " machine type.\nYou need to boot an IP%d kernel.\n", IP); - return 1; - } - - return 0; -} - -/* - * Load the saved randomness file. - */ -int -loadrandom(const char *partition, const char *name, void *buf, size_t buflen) -{ - char path[MAXPATHLEN]; - struct stat sb; - int fd, error = 0; - - strlcpy(path, partition, sizeof path); - strlcat(path, name, sizeof path); - - fd = open(path, O_RDONLY); - if (fd == -1) { - if (errno != EPERM) - printf("cannot open %s: %s\n", path, strerror(errno)); - return (-1); - } - if (fstat(fd, &sb) == -1) { - error = -1; - goto done; - } - if (read(fd, buf, buflen) != buflen) { - error = -1; - goto done; - } - if (sb.st_mode & S_ISTXT) { - printf("NOTE: random seed is being reused.\n"); - error = -1; - goto done; - } - fchmod(fd, sb.st_mode | S_ISTXT); -done: - close(fd); - return (error); -} diff --git a/sys/arch/sgi/stand/boot/conf.c b/sys/arch/sgi/stand/boot/conf.c deleted file mode 100644 index 98699afd778..00000000000 --- a/sys/arch/sgi/stand/boot/conf.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: conf.c,v 1.9 2020/12/09 18:10:19 krw Exp $ */ - -/* - * Copyright (c) 1997 Per Fogelstrom - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include <stand.h> - -const char version[] = "1.13"; - -extern void nullsys(); -extern int nodev(); -extern int noioctl(); - -int diostrategy(void *, int, daddr_t, size_t, void *, size_t *); -int dioopen(struct open_file *, ...); -int dioclose(struct open_file *); -#define dioioctl noioctl - -int netstrategy(void *, int, daddr_t, size_t, void *, size_t *); -int netopen(struct open_file *, ...); -int netclose(struct open_file *); -#define netioctl noioctl - -struct devsw devsw[] = { - { "scsi", diostrategy, dioopen, dioclose, dioioctl }, - { "bootp", netstrategy, netopen, netclose, netioctl } -}; - -int ndevs = (sizeof(devsw)/sizeof(devsw[0])); diff --git a/sys/arch/sgi/stand/boot/diskio.c b/sys/arch/sgi/stand/boot/diskio.c deleted file mode 100644 index 48104ca11ac..00000000000 --- a/sys/arch/sgi/stand/boot/diskio.c +++ /dev/null @@ -1,252 +0,0 @@ -/* $OpenBSD: diskio.c,v 1.14 2020/12/09 18:10:19 krw Exp $ */ - -/* - * Copyright (c) 2016 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Copyright (c) 2000 Opsycon AB (www.opsycon.se) - * Copyright (c) 2000 Rtmx, Inc (www.rtmx.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for Rtmx, Inc by - * Opsycon Open System Consulting AB, Sweden. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include <sys/param.h> -#include <lib/libkern/libkern.h> -#include <stand.h> - -#include <sys/disklabel.h> -#include <mips64/arcbios.h> - -char *strstr(char *, const char *); /* strstr.c */ - -struct dio_softc { - int sc_fd; /* PROM file ID */ - int sc_part; /* Disk partition number. */ - struct disklabel sc_label; /* Disk label for this disk. */ -}; - -int -diostrategy(void *devdata, int rw, daddr_t bn, size_t reqcnt, void *addr, - size_t *cnt) -{ - struct dio_softc *sc = (struct dio_softc *)devdata; - struct partition *pp = &sc->sc_label.d_partitions[sc->sc_part]; - uint64_t blkoffset; - arc_quad_t offset; - long result; - - if (rw != F_READ) - return EOPNOTSUPP; - - blkoffset = - (DL_SECTOBLK(&sc->sc_label, DL_GETPOFFSET(pp)) + bn) * DEV_BSIZE; - offset.hi = blkoffset >> 32; - offset.lo = blkoffset; - - if (Bios_Seek(sc->sc_fd, &offset, 0) < 0 || - Bios_Read(sc->sc_fd, addr, reqcnt, &result) < 0) - return EIO; - - if (cnt != NULL) - *cnt = result; - return 0; -} - -int -dioopen(struct open_file *f, ...) -{ - char *ctlr; - int partition; - struct dio_softc *sc; - struct disklabel *lp; - struct sgilabel *sl; - long fd; - /* XXX getdisklabel() assumes DEV_BSIZE bytes available */ - char buf[DEV_BSIZE + LABELOFFSET]; - arc_quad_t offset; - daddr_t native_offset; - long result; - va_list ap; - char rawctlr[1 + MAXPATHLEN]; - char *partptr; - - va_start(ap, f); - ctlr = va_arg(ap, char *); - partition = va_arg(ap, int); - va_end(ap); - - if (partition >= MAXPARTITIONS) - return ENXIO; - - /* - * If booting from disk, `ctlr` is something like - * whatever()partition(0) - * or - * dksc(whatever,0) - * where 0 is the volume header #0 partition, which is the - * OpenBSD area, where the OpenBSD disklabel can be found. - * - * However, the OpenBSD `a' partition, where the kernel is to be - * found, may not start at the same offset. - * - * In order to be able to correctly load any file from the OpenBSD - * partitions, we need to access the volume header partition table - * and the OpenBSD label. - * - * Therefore, make sure we replace `partition(*)' with `partition(10)' - * before reaching ARCBios, in order to access the raw disk. - * - * We could use partition #8 and use the value of SystemPartition in - * the environment to avoid doing this, but this would prevent us - * from being able to boot from a different disk than the one - * pointed to by SystemPartition. - */ - - strlcpy(rawctlr, ctlr, sizeof rawctlr); - partptr = strstr(rawctlr, "partition("); - if (partptr != NULL) { - strlcpy(partptr, "partition(10)", - sizeof rawctlr - (partptr - rawctlr)); - } else { - if ((partptr = strstr(rawctlr, "dksc(")) != NULL) { - partptr = strstr(partptr, ",0)"); - if (partptr != NULL && partptr[3] == '\0') - strlcpy(partptr, ",10)", - sizeof rawctlr - (partptr - rawctlr)); - } - } - - sl = NULL; /* no volume header found yet */ - if (partptr != NULL) { - if (Bios_Open(rawctlr, 0, &fd) < 0) - return ENXIO; - - /* - * Read the volume header. - */ - offset.hi = offset.lo = 0; - if (Bios_Seek(fd, &offset, 0) < 0 || - Bios_Read(fd, buf, DEV_BSIZE, &result) < 0 || - result != DEV_BSIZE) - return EIO; - - sl = (struct sgilabel *)buf; - if (sl->magic != SGILABEL_MAGIC) { -#ifdef DEBUG - printf("Invalid volume header magic %x\n", sl->magic); -#endif - Bios_Close(fd); - sl = NULL; - } - } - - if (sl == NULL) { - if (Bios_Open(ctlr, 0, &fd) < 0) - return ENXIO; - } - - sc = alloc(sizeof(struct dio_softc)); - bzero(sc, sizeof(struct dio_softc)); - f->f_devdata = (void *)sc; - lp = &sc->sc_label; - - sc->sc_fd = fd; - sc->sc_part = partition; - - if (sl != NULL) { - native_offset = sl->partitions[0].first; - } else { - /* - * We could not read the volume header, or there isn't any. - * Stick to the device we were given, and assume the - * OpenBSD disklabel can be found at the beginning. - */ - native_offset = 0; - } - - /* - * Read the native OpenBSD label. - */ -#ifdef DEBUG - printf("OpenBSD label @%lld\n", native_offset + LABELSECTOR); -#endif - offset.hi = ((native_offset + LABELSECTOR) * DEV_BSIZE) >> 32; - offset.lo = (native_offset + LABELSECTOR) * DEV_BSIZE; - - if (Bios_Seek(fd, &offset, 0) < 0 || - Bios_Read(fd, buf, DEV_BSIZE, &result) < 0 || - result != DEV_BSIZE) - return EIO; - - if (getdisklabel(buf + LABELOFFSET, lp) == NULL) { -#ifdef DEBUG - printf("Found native disklabel, " - "partition %c starts at %lld\n", - 'a' + partition, - DL_GETPOFFSET(&lp->d_partitions[partition])); -#endif - } else { - /* - * Assume the OpenBSD partition spans the whole device. - */ - lp->d_secsize = DEV_BSIZE; - lp->d_secpercyl = 1; - lp->d_npartitions = MAXPARTITIONS; - DL_SETPOFFSET(&lp->d_partitions[partition], native_offset); - DL_SETPSIZE(&lp->d_partitions[partition], -1ULL); -#ifdef DEBUG - printf("No native disklabel found, " - "assuming partition %c starts at %lld\n", - 'a' + partition, native_offset); -#endif - } - - return 0; -} - -int -dioclose(struct open_file *f) -{ - Bios_Close(((struct dio_softc *)f->f_devdata)->sc_fd); - free(f->f_devdata, sizeof(struct dio_softc)); - f->f_devdata = NULL; - return (0); -} diff --git a/sys/arch/sgi/stand/boot/filesystem.c b/sys/arch/sgi/stand/boot/filesystem.c deleted file mode 100644 index a9ae8b301a9..00000000000 --- a/sys/arch/sgi/stand/boot/filesystem.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $NetBSD: filesystem.c,v 1.2 1995/02/16 02:33:05 cgd Exp $ */ - -/* - * Copyright (c) 1993 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * filesystem.c - */ - -#include <stand.h> -#include <ufs.h> -#include <ufs2.h> -#include "netfs.h" - -struct fs_ops file_system[] = { - { netfs_open, netfs_close, netfs_read, netfs_write, netfs_seek, - netfs_stat }, - { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, - ufs_stat, ufs_readdir, ufs_fchmod }, - { ufs2_open, ufs2_close, ufs2_read, ufs2_write, ufs2_seek, - ufs2_stat, ufs2_readdir, ufs2_fchmod }, -}; - -int nfsys = sizeof(file_system)/sizeof(struct fs_ops); diff --git a/sys/arch/sgi/stand/boot/netfs.c b/sys/arch/sgi/stand/boot/netfs.c deleted file mode 100644 index 76bed9a4a6d..00000000000 --- a/sys/arch/sgi/stand/boot/netfs.c +++ /dev/null @@ -1,291 +0,0 @@ -/* $OpenBSD: netfs.c,v 1.3 2020/12/09 18:10:19 krw Exp $ */ - -/*- - * Copyright (c) 2001 Steve Murphree, Jr. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * TFTP file system. - */ - -#include <sys/param.h> -#include <lib/libkern/libkern.h> -#include <stand.h> - -#include <sys/stat.h> - -#include "netfs.h" - -/* - * In-core open file. - */ -struct tftp_file { - char filename[128]; - off_t f_seekp; /* seek pointer */ - char *f_buf; /* buffer for data block */ - off_t f_off; /* index into buffer for data block */ - daddr32_t f_buf_blkno; /* block number of data block */ - size_t f_buf_size; -}; - -#define TFTP_BLOCK_SHIFT 9 -#define TFTP_BLOCK_SIZE (1<<TFTP_BLOCK_SHIFT) /* 512 by tftp convention */ -#define TFTP_BLOCK_NO(x) ((x >> TFTP_BLOCK_SHIFT) + 1) -#define TFTP_BLOCK_OFF(x) (x % TFTP_BLOCK_SIZE) - -static int tftp_read_file(struct open_file *, char **, size_t *); - -/* - * Read a portion of a file into an internal buffer. Return - * the location in the buffer and the amount in the buffer. - */ - -char tftp_buf[TFTP_BLOCK_SIZE]; /* static */ -struct tftp_file tftp_ctrl; - -static int -tftp_read_file(f, buf_p, size_p) - struct open_file *f; - char **buf_p; /* out */ - size_t *size_p; /* out */ -{ - struct tftp_file *fp = (struct tftp_file *)f->f_fsdata; - long off; - daddr32_t file_block; - size_t block_size; - int i, rc; - - off = TFTP_BLOCK_OFF(fp->f_seekp); - file_block = TFTP_BLOCK_NO(fp->f_seekp); - block_size = TFTP_BLOCK_SIZE; - - if (file_block == fp->f_buf_blkno + 1) { - /* - * Normal, incremental block transfer. - */ - rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, - file_block, block_size, fp->f_buf, &fp->f_buf_size); - if (rc) - return (rc); - if (!(file_block % 4)) /* twiddle every 4 blocks */ - twiddle(); - fp->f_buf_blkno = file_block; - } else if (file_block > fp->f_buf_blkno + 1) { - /* - * Read ahead to the requested block; If we need - * those we skipped, see below. - */ - for (i = (fp->f_buf_blkno + 1); i <= file_block; i++) { - rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, - i, block_size, fp->f_buf, &fp->f_buf_size); - if (rc) - return (rc); - } - fp->f_buf_blkno = file_block; - } else if (file_block < fp->f_buf_blkno) { - /* - * Uh oh... We can't rewind. Reopen the file - * and start again. - */ - char filename[128]; - - strlcpy(filename, fp->filename, sizeof filename); - netfs_close(f); - netfs_open(filename, f); - - /* restore f_seekp reset by netfs_open() */ - fp->f_seekp = (file_block - 1) * TFTP_BLOCK_SIZE + off; - for (i = 1; i <= file_block; i++) { - rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, - i, block_size, fp->f_buf, &fp->f_buf_size); - if (rc) - return (rc); - } - fp->f_buf_blkno = file_block; - } - - /* - * Return address of byte in buffer corresponding to - * offset, and size of remainder of buffer after that - * byte. - */ - *buf_p = fp->f_buf + off; - *size_p = fp->f_buf_size - off; - - /* - * But truncate buffer at end of file. - */ - if (fp->f_buf_size > block_size){ - twiddle(); - return(EIO); - } - - - return (0); -} - -/* - * Open a file. - */ -int -netfs_open(path, f) - char *path; - struct open_file *f; -{ - struct tftp_file *fp; - int rc = 0; -extern int netstrategy(void *, int, daddr_t, size_t, void *, size_t *); - - if (f->f_dev->dv_strategy != netstrategy) - return EINVAL; - - /* locate file system specific data structure and zero it.*/ - fp = &tftp_ctrl; - bzero(fp, sizeof(struct tftp_file)); - f->f_fsdata = (void *)fp; - fp->f_seekp = 0; - fp->f_buf = tftp_buf; - bzero(fp->f_buf, TFTP_BLOCK_SIZE); - fp->f_buf_size = 0; - - strlcpy(fp->filename, path, sizeof fp->filename); - - twiddle(); - rc = (f->f_dev->dv_open)(f, path); - return (rc); -} - -int -netfs_close(f) - struct open_file *f; -{ - struct tftp_file *fp = (struct tftp_file *)f->f_fsdata; - - fp->f_buf = NULL; - f->f_fsdata = NULL; - (f->f_dev->dv_close)(f); - return (0); -} - -/* - * Copy a portion of a file into kernel memory. - * Cross block boundaries when necessary. - */ -int -netfs_read(f, start, size, resid) - struct open_file *f; - void *start; - size_t size; - size_t *resid; /* out */ -{ - struct tftp_file *fp = (struct tftp_file *)f->f_fsdata; - size_t csize; - char *buf; - size_t buf_size; - int rc = 0; - char *addr = start; - - while (size != 0) { - rc = tftp_read_file(f, &buf, &buf_size); - if (rc) - break; - - csize = size; - if (csize > buf_size) - csize = buf_size; - - bcopy(buf, addr, csize); - - fp->f_seekp += csize; - addr += csize; - size -= csize; - } - if (resid) - *resid = size; - return (rc); -} - -/* - * Not implemented. - */ -int -netfs_write(f, start, size, resid) - struct open_file *f; - void *start; - size_t size; - size_t *resid; /* out */ -{ - - return (EROFS); -} - -/* - * We only see forward. We can't rewind. - */ -off_t -netfs_seek(f, offset, where) - struct open_file *f; - off_t offset; - int where; -{ - struct tftp_file *fp = (struct tftp_file *)f->f_fsdata; - - switch (where) { - case SEEK_SET: - fp->f_seekp = offset; - break; - case SEEK_CUR: - fp->f_seekp += offset; - break; - case SEEK_END: - errno = EIO; - return (-1); - break; - default: - return (-1); - } - return (fp->f_seekp); -} - -int -netfs_stat(f, sb) - struct open_file *f; - struct stat *sb; -{ - return EIO; -} - -#ifndef NO_READDIR -int -netfs_readdir (struct open_file *f, char *name) -{ - return EIO; -} -#endif - diff --git a/sys/arch/sgi/stand/boot/netfs.h b/sys/arch/sgi/stand/boot/netfs.h deleted file mode 100644 index f6e1c4b44da..00000000000 --- a/sys/arch/sgi/stand/boot/netfs.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD: netfs.h,v 1.1 2012/03/19 17:38:31 miod Exp $ */ - -/*- - * Copyright (c) 2001 Steve Murphree, Jr. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -int netfs_open(char *path, struct open_file *f); -int netfs_close(struct open_file *f); -int netfs_read(struct open_file *f, void *buf, - size_t size, size_t *resid); -int netfs_write(struct open_file *f, void *buf, - size_t size, size_t *resid); -off_t netfs_seek(struct open_file *f, off_t offset, int where); -int netfs_stat(struct open_file *f, struct stat *sb); -#ifndef NO_READDIR -int netfs_readdir(struct open_file *f, char *name); -#endif diff --git a/sys/arch/sgi/stand/boot/netio.c b/sys/arch/sgi/stand/boot/netio.c deleted file mode 100644 index 2595e56566c..00000000000 --- a/sys/arch/sgi/stand/boot/netio.c +++ /dev/null @@ -1,88 +0,0 @@ -/* $OpenBSD: netio.c,v 1.3 2020/12/09 18:10:19 krw Exp $ */ - -/* - * Copyright (c) 2012 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include <sys/param.h> -#include <lib/libkern/libkern.h> -#include <stand.h> - -#include <mips64/arcbios.h> - -int -netstrategy(void *devdata, int rw, daddr_t bn, size_t reqcnt, void *addr, - size_t *cnt) -{ - long fd = (long)devdata; - long result; - int rc; - - if (rw != F_READ) - return EOPNOTSUPP; - - rc = Bios_Read(fd, addr, reqcnt, &result); - if (rc != 0) - return (EIO); - - if (cnt != NULL) - *cnt = result; - return 0; -} - -int -netopen(struct open_file *f, ...) -{ - char *path; - long fd; - int rc; - va_list ap; - - va_start(ap, f); - path = va_arg(ap, char *); - va_end(ap); - - /* to match netfs.c filename buffers... */ - if (strlen(path) > 128 - 1) - return ENAMETOOLONG; - - rc = Bios_Open(path, 0, &fd); - if (rc != 0) { - switch (rc) { - case arc_EACCES: - return EACCES; - case arc_EISDIR: - return EISDIR; - case arc_ENOENT: - return ENOENT; - default: - return ENXIO; - } - } - - f->f_devdata = (void *)fd; - - return 0; -} - -int -netclose(struct open_file *f) -{ - long fd = (long)f->f_devdata; - - (void)Bios_Close(fd); - return 0; -} diff --git a/sys/arch/sgi/stand/boot/start.S b/sys/arch/sgi/stand/boot/start.S deleted file mode 100644 index 31c64793f9f..00000000000 --- a/sys/arch/sgi/stand/boot/start.S +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: start.S,v 1.4 2012/09/29 21:40:48 miod Exp $ */ - -/* - * Copyright (c) 2001 Opsycon AB (www.opsycon.se) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed under OpenBSD by - * Opsycon AB, Sweden (www.opsycon.com). - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#define ABICALLS - -#include <machine/regdef.h> -#include <machine/asm.h> - -/* - * Frame required for the debugger (if we have any). - */ -#define START_FRAME ((4 * 4) + 4 + 4) - - .globl __start -__start: -#ifndef __LP64__ /* LP64 code is compiled without gp support */ - LA gp, _gp -#endif - - jal boot_main - -1: - b 1b - diff --git a/sys/arch/sgi/stand/boot/strstr.c b/sys/arch/sgi/stand/boot/strstr.c deleted file mode 100644 index 95832a656b8..00000000000 --- a/sys/arch/sgi/stand/boot/strstr.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <lib/libkern/libkern.h> - -/* - * Find the first occurrence of find in s. - */ -char * -strstr(char *s, const char *find) -{ - char c, sc; - size_t len; - - if ((c = *find++) != 0) { - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while (sc != c); - } while (strncmp(s, find, len) != 0); - s--; - } - return s; -} diff --git a/sys/arch/sgi/stand/boot32/Makefile b/sys/arch/sgi/stand/boot32/Makefile deleted file mode 100644 index e319a1ed942..00000000000 --- a/sys/arch/sgi/stand/boot32/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2020/04/06 02:10:33 visa Exp $ - -.include "${.CURDIR}/../Makefile32.inc" -LDSCRIPT= ${.CURDIR}/ld.script -LDFLAGS+= ${SALDFLAGS} -T ${LDSCRIPT} -e __start -s -PROG= boot32 -.PATH: ${.CURDIR}/../boot -.include "${.CURDIR}/../boot/Makefile" - -SRCS+= ashrdi3.c divdi3.c moddi3.c udivdi3.c umoddi3.c qdivrem.c - -${PROG}: $(OBJS) $(LDADD) - $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) -L${LIBSADIR} ${LIBSA} \ - -L${LIBZDIR} ${LIBZ} - -LINKS= ${BINDIR}/${PROG} ${BINDIR}/boot-IP32 - -.include <bsd.prog.mk> diff --git a/sys/arch/sgi/stand/boot32/ld.script b/sys/arch/sgi/stand/boot32/ld.script deleted file mode 100644 index 5ca7826d883..00000000000 --- a/sys/arch/sgi/stand/boot32/ld.script +++ /dev/null @@ -1,75 +0,0 @@ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips", - "elf32-tradlittlemips") -OUTPUT_ARCH(mips) -ENTRY(_start) -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - . = 0x80010000 + SIZEOF_HEADERS; - .text : - { - _ftext = . ; - *(.text) - *(.rodata) - *(.rodata1) - *(.rodata.str1.4) - *(.reginfo) - *(.init) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - } =0 - _etext = .; - PROVIDE (etext = .); - .fini : { *(.fini) } =0 - .data : - { - _fdata = . ; - *(.data) - CONSTRUCTORS - } - .data1 : { *(.data1) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - _gp = ALIGN(16) + 0x7ff0; - .got : - { - *(.got.plt) *(.got) - } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : { *(.sdata) } - .lit8 : { *(.lit8) } - .lit4 : { *(.lit4) } - _edata = .; - PROVIDE (edata = .); - __bss_start = .; - _fbss = .; - .sbss : { *(.sbss) *(.scommon) } - .bss : - { - *(.dynbss) - *(.bss) - *(COMMON) - } - _end = . ; - PROVIDE (end = .); - /* These are needed for ELF backends which have not yet been - converted to the new style linker. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - /* DWARF debug sections. - Symbols in the .debug DWARF section are relative to the beginning of the - section so we begin .debug at 0. It's not clear yet what needs to happen - for the others. */ - .debug 0 : { *(.debug) } - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - .debug_sfnames 0 : { *(.debug_sfnames) } - .line 0 : { *(.line) } - /* These must appear regardless of . */ - .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) } - .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) } -} diff --git a/sys/arch/sgi/stand/boot64/Makefile b/sys/arch/sgi/stand/boot64/Makefile deleted file mode 100644 index b25ac6ef318..00000000000 --- a/sys/arch/sgi/stand/boot64/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# $OpenBSD: Makefile,v 1.4 2015/09/27 19:11:37 miod Exp $ - -LDFLAGS+= ${SALDFLAGS} --oformat=elf64-tradbigmips -e __start -STRIP= strip -INSTALL_STRIP= - -PROG= boot64 -.PATH: ${.CURDIR}/../boot -.include "${.CURDIR}/../boot/Makefile" - -${PROG}: $(OBJS) $(LDADD) - @# Link first as self-contained binary to enforce there are no - @# unresolved symbols - $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) -L${LIBSADIR} ${LIBSA} \ - -L${LIBZDIR} ${LIBZ} - @# then link as a relocatable binary - $(LD) $(LDFLAGS) -r -o ${PROG} $(OBJS) -L${LIBSADIR} ${LIBSA} \ - -L${LIBZDIR} ${LIBZ} - $(STRIP) --strip-unneeded ${PROG} - -LINKS= ${BINDIR}/${PROG} ${BINDIR}/boot-IP26 -LINKS+= ${BINDIR}/${PROG} ${BINDIR}/boot-IP27 -LINKS+= ${BINDIR}/${PROG} ${BINDIR}/boot-IP28 -LINKS+= ${BINDIR}/${PROG} ${BINDIR}/boot-IP30 - -.include <bsd.prog.mk> diff --git a/sys/arch/sgi/stand/bootecoff/Makefile b/sys/arch/sgi/stand/bootecoff/Makefile deleted file mode 100644 index ff2505cbed2..00000000000 --- a/sys/arch/sgi/stand/bootecoff/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2020/04/06 16:23:44 visa Exp $ - -.include "${.CURDIR}/../Makefile32.inc" -STRIP?= strip -LDSCRIPT= ${.CURDIR}/ld.script -LDFLAGS+= ${SALDFLAGS} -T ${LDSCRIPT} -e __start -N -s -PROG= bootecoff -.PATH: ${.CURDIR}/../boot -.include "${.CURDIR}/../boot/Makefile" - -SRCS+= ashrdi3.c divdi3.c moddi3.c udivdi3.c umoddi3.c qdivrem.c - -${PROG}: $(OBJS) $(LDADD) - $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) -L${LIBSADIR} ${LIBSA} \ - -L${LIBZDIR} ${LIBZ} - -LINKS= ${BINDIR}/${PROG} ${BINDIR}/boot-IP22 - -.include <bsd.prog.mk> diff --git a/sys/arch/sgi/stand/bootecoff/ld.script b/sys/arch/sgi/stand/bootecoff/ld.script deleted file mode 100644 index deee3ac2bf1..00000000000 --- a/sys/arch/sgi/stand/bootecoff/ld.script +++ /dev/null @@ -1,71 +0,0 @@ -OUTPUT_FORMAT("ecoff-bigmips", "ecoff-bigmips", - "ecoff-littlemips") -OUTPUT_ARCH(mips) -ENTRY(_start) -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - . = 0x88002000 + SIZEOF_HEADERS; - .text : - { - _ftext = . ; - *(.text) - *(.rodata) - *(.rodata1) - *(.rodata.str1.4) - *(.reginfo) - *(.init) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - } =0 - _etext = .; - PROVIDE (etext = .); - .fini : { *(.fini) } =0 - .data : - { - _fdata = . ; - *(.data) - CONSTRUCTORS - } - .data1 : { *(.data1) } - .ctors : { *(.ctors) } - .dtors : { *(.dtors) } - _gp = ALIGN(16) + 0x7ff0; - .got : - { - *(.got.plt) *(.got) - } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : { *(.sdata) } - .lit8 : { *(.lit8) } - .lit4 : { *(.lit4) } - _edata = .; - PROVIDE (edata = .); - __bss_start = .; - _fbss = .; - .sbss : { *(.sbss) *(.scommon) } - .bss : - { - *(.dynbss) - *(.bss) - *(COMMON) - } - _end = . ; - PROVIDE (end = .); - /DISCARD/ : { - *(.pdr) - *(.mdebug.abi32) - *(.comment) - *(.stab) - *(.stabstr) - *(.debug) - *(.debug_srcinfo) - *(.debug_aranges) - *(.debug_pubnames) - *(.debug_sfnames) - *(.line) - } -} diff --git a/sys/arch/sgi/stand/libsa/Makefile b/sys/arch/sgi/stand/libsa/Makefile deleted file mode 100644 index 6eccda49388..00000000000 --- a/sys/arch/sgi/stand/libsa/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -# $OpenBSD: Makefile,v 1.14 2020/05/25 16:27:05 deraadt Exp $ - -LIB= sa - -.PATH: ${.CURDIR}/../../../../lib/libsa - -CLEANFILES += machine mips64 - -CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdinc -mno-abicalls -D_NO_ABICALLS \ - -fno-pie \ - -I${.CURDIR} -I${.CURDIR}/../include -I${.CURDIR}/../.. \ - -I${.CURDIR}/../../.. -I${.CURDIR}/../../../.. \ - -I${.CURDIR}/../../../../lib/libsa \ - -I${.OBJDIR} - -CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD ${STANDALONE} -CPPFLAGS+= ${LIBSA_CPPFLAGS} - -# stand routines -SRCS= alloc.c exit.c getfile.c getln.c globals.c \ - memcmp.c memcpy.c memmove.c memset.c printf.c snprintf.c strerror.c strncpy.c - -# io routines -SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fchmod.c \ - fstat.c fchmod.c ioctl.c lseek.c open.c read.c stat.c write.c cread.c - -# boot filesystems -SRCS+= ufs.c ufs2.c nfs.c cd9660.c - -${OBJS}: ${.CURDIR}/../Makefile.inc - -NOPROFILE= -NOPIC= - -.if !make(clean) && !make(cleandir) && !make(includes) && !make(libdep) && \ - !make(sadep) && !make(salibdir) && !make(obj) -.BEGIN: - @([ -h machine ] || ln -s ${.CURDIR}/../../include machine) - @([ -h mips64 ] || ln -s ${.CURDIR}/../../../mips64/include mips64) -.endif - -install: - -.include <bsd.lib.mk> diff --git a/sys/arch/sgi/stand/libsa/heap.h b/sys/arch/sgi/stand/libsa/heap.h deleted file mode 100644 index da42d8b5e22..00000000000 --- a/sys/arch/sgi/stand/libsa/heap.h +++ /dev/null @@ -1,35 +0,0 @@ -/* $OpenBSD: heap.h,v 1.1 2009/05/14 18:57:43 miod Exp $ */ -/* public domain */ - -/* - * Declarations for the libsa heap allocator. - * - * Relocatable 64 bit bootblocks use memory below the load address and - * can not use the `end' symbol. - */ - -#ifdef __LP64__ -#define NEEDS_HEAP_INIT - -#define HEAP_LIMIT heap_limit -#define HEAP_SIZE (1UL << 20) /* 1MB */ -#define HEAP_START heap_start - -static unsigned long heap_start; -static unsigned long heap_limit; -static char *top; /* no longer declared in alloc.c */ - -static inline void heap_init(void); -static inline void -heap_init() -{ - extern char __start[]; - - if (top == NULL) { - heap_limit = (unsigned long)&__start; - heap_start = heap_limit - HEAP_SIZE; - top = (char *)heap_start; - } -} - -#endif diff --git a/sys/arch/sgi/stand/libsa32/Makefile b/sys/arch/sgi/stand/libsa32/Makefile deleted file mode 100644 index c22a59bb067..00000000000 --- a/sys/arch/sgi/stand/libsa32/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# $OpenBSD: Makefile,v 1.1 2009/05/14 18:57:43 miod Exp $ - -.include "${.CURDIR}/../Makefile32.inc" -.include "${.CURDIR}/../libsa/Makefile" diff --git a/sys/arch/sgi/stand/libz/Makefile b/sys/arch/sgi/stand/libz/Makefile deleted file mode 100644 index c6911a3fadc..00000000000 --- a/sys/arch/sgi/stand/libz/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $OpenBSD: Makefile,v 1.5 2012/08/31 08:14:08 pascal Exp $ - -S=${.CURDIR}/../../../.. -ZDST=${.OBJDIR} - -.PATH: ${S}/lib/libz - -.include "${S}/lib/libz/Makefile" -CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -mno-abicalls -D_NO_ABICALLS \ - ${AFLAGS} -fno-pie -I${S} diff --git a/sys/arch/sgi/stand/libz32/Makefile b/sys/arch/sgi/stand/libz32/Makefile deleted file mode 100644 index d217799d624..00000000000 --- a/sys/arch/sgi/stand/libz32/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# $OpenBSD: Makefile,v 1.1 2009/05/14 18:57:43 miod Exp $ - -.include "${.CURDIR}/../Makefile32.inc" -.include "${.CURDIR}/../libz/Makefile" diff --git a/sys/arch/sgi/stand/sgivol/Makefile b/sys/arch/sgi/stand/sgivol/Makefile deleted file mode 100644 index e6fc37cdbf3..00000000000 --- a/sys/arch/sgi/stand/sgivol/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2005/04/27 18:02:16 deraadt Exp $ -# $NetBSD: Makefile,v 1.5 2002/12/13 02:36:37 lukem Exp $ - -MAN= sgivol.8 -MANSUBDIR=sgi - -.if ${MACHINE} == "sgi" -PROG= sgivol -LDADD+= -lutil -LDSTATIC=-static - -.else -NOPROG= -.endif - -.include <bsd.prog.mk> diff --git a/sys/arch/sgi/stand/sgivol/sgivol.8 b/sys/arch/sgi/stand/sgivol/sgivol.8 deleted file mode 100644 index 877c0704646..00000000000 --- a/sys/arch/sgi/stand/sgivol/sgivol.8 +++ /dev/null @@ -1,127 +0,0 @@ -.\" $OpenBSD: sgivol.8,v 1.7 2020/04/23 21:28:10 jmc Exp $ -.\" -.\" Copyright (c) 2005 Theo de Raadt -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" -.Dd $Mdocdate: April 23 2020 $ -.Dt SGIVOL 8 sgi -.Os -.Sh NAME -.Nm sgivol -.Nd initialise and manipulate SGI disk volume headers -.Sh SYNOPSIS -.Nm sgivol -.Op Fl q -.Ar disk -.Nm sgivol -.Op Fl q -.Fl d Ar vhfilename -.Ar disk -.Nm sgivol -.Op Fl q -.Fl i -.Op Fl h Ar vhsize -.Ar disk -.Nm sgivol -.Op Fl q -.Fl l Ar vhfilename1 Ar vhfilename2 -.Ar disk -.Nm sgivol -.Op Fl q -.Fl r Ar vhfilename diskfilename -.Ar disk -.Nm sgivol -.Op Fl q -.Fl w Ar vhfilename diskfilename -.Ar disk -.Sh DESCRIPTION -.Nm -is used to initialise and manipulate SGI disk volume headers. -.Pp -The SGI volume header is a disklabel-like structure located at the -start of a disk. -It is typically 3135 (512-byte) blocks in size, and can store a -variety of files inside it, typically boot programs. -.Pp -The options are as follows: -.Bl -tag -width flag_opt -.It Fl d Ar vhfilename -Delete the file -.Ar vhfilename -from the filesystem storage space in the volume header. -.It Fl h Ar vhsize -Choose an alternate volume header size, in (512-byte) disk blocks. -The default is 3135 blocks. -.It Fl i -Initialise a volume header on the supplied device. -.It Fl l Ar vhfilename1 Ar vhfilename2 -Link the file -.Ar vhfilename1 -to the file -.Ar vhfilename2 -within the filesystem storage space in the volume header. -.It Fl q -Be quiet about various diagnostic issues. -.It Fl r Ar vhfilename diskfilename -Locate the file -.Ar vhfilename -in the storage space of the volume header, and copy it to the -standard file -.Ar diskfilename . -.It Fl w Ar vhfilename diskfilename -Copy the standard file -.Ar diskfilename -to the filesystem storage space in the volume header, placing -it there with the name -.Ar vhfilename . -.It Ar disk -The name of the disk containing the partition in which the second-stage -boot program resides and the first-stage boot program is to be installed. -This can either be specified in short form (e.g., -.Sq sd0 -or as the explicit device node, such as -.Pa /dev/rsd0c ) . -.Pp -Note that you must be in single-user mode or have your kernel in -insecure mode (see the -.Xr sysctl 8 -.Va kern.securelevel -variable or -.Pa /etc/rc.securelevel ) -to enable access to the raw partition of a mounted disk. -.El -.Pp -If no special flags are supplied, -.Nm -will display the current volume header information. -.Sh EXAMPLES -The typical use is -.Bd -literal -offset indent -# /usr/mdec/sgivol -i sd0 -# /usr/mdec/sgivol -w boot /usr/mdec/boot sd0 -.Ed -.Sh SEE ALSO -.Xr disklabel 8 , -.Xr init 8 diff --git a/sys/arch/sgi/stand/sgivol/sgivol.c b/sys/arch/sgi/stand/sgivol/sgivol.c deleted file mode 100644 index 1066bf00eab..00000000000 --- a/sys/arch/sgi/stand/sgivol/sgivol.c +++ /dev/null @@ -1,607 +0,0 @@ -/* $OpenBSD: sgivol.c,v 1.24 2017/09/08 05:36:52 deraadt Exp $ */ -/* $NetBSD: sgivol.c,v 1.8 2003/11/08 04:59:00 sekiya Exp $ */ - -/*- - * Copyright (c) 2001 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Michael Hitch and Hubert Feyrer. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <util.h> - -#include <sys/disklabel.h> -#include <sys/endian.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/dkio.h> - -/* - * Some IRIX man pages refer to the size being a multiple of whole cylinders. - * Later ones only refer to the size being "typically" 2MB. IRIX fx(1) - * uses a default drive geometry if one can't be determined, suggesting - * that "whole cylinder" multiples are not required. - */ - -#define SGI_SIZE_VOLHDR 3135 /* Can be overridden via -h parameter. */ - -/* - * Mode of operation can be one of: - * -i Initialise volume header. - * -r Read a file from volume header. - * -w Write a file to volume header. - * -l Link a file into the volume header. - * -d Delete a file from the volume header. - * -p Modify a partition. - */ - -char mode; -int quiet; -int fd; -int partno, partfirst, partblocks, parttype; -struct sgilabel *volhdr; -int32_t checksum; - -/* Volume header size in sectors. */ -u_int32_t volhdr_size = SGI_SIZE_VOLHDR; - -const char *vfilename = ""; -const char *ufilename = ""; - -struct disklabel lbl; - -unsigned char *buf; -unsigned int bufsize; - -const char *sgi_types[] = { - "Volume Header", - "Repl Trks", - "Repl Secs", - "Raw", - "BSD4.2", - "SysV", - "Volume", - "EFS", - "LVol", - "RLVol", - "XFS", - "XSFLog", - "XLV", - "XVM" -}; - -void display_vol(void); -void init_volhdr(void); -void read_file(void); -void write_file(void); -void link_file(void); -void delete_file(void); -void modify_partition(void); -void write_volhdr(void); -int allocate_space(int); -void checksum_vol(void); -void usage(void); - -int -main(int argc, char *argv[]) -{ - int ch, oflags; - char fname[FILENAME_MAX]; - char *endp; - - quiet = 0; - mode = ' '; - - while ((ch = getopt(argc, argv, "irwlpdqfh:")) != -1) { - switch (ch) { - case 'q': - quiet = 1; - break; - case 'f': - /* Legacy. Do nothing. */ - break; - case 'i': - mode = 'i'; - break; - case 'h': - volhdr_size = strtol(optarg, &endp, 0); - if (*endp != '\0' || errno != 0) - errx(1, "incorrect volume header size: %s", - optarg); - break; - case 'r': - mode = 'r'; - break; - case 'w': - mode = 'w'; - break; - case 'l': - mode = 'l'; - break; - case 'd': - mode = 'd'; - break; - case 'p': - mode = 'p'; - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (mode == 'r' || mode == 'w' || mode == 'l') { - if (argc != 3) - usage(); - vfilename = argv[0]; - ufilename = argv[1]; - argc -= 2; - argv += 2; - } else if (mode == 'd') { - if (argc != 2) - usage(); - vfilename = argv[0]; - argc--; - argv++; - } else if (mode == 'p') { - if (argc != 5) - usage(); - partno = strtol(argv[0], &endp, 0); - if (*endp != '\0' || errno != 0 || - partno < 0 || partno > SGI_SIZE_VOLDIR) - errx(1, "invalid partition number: %s", argv[0]); - partfirst = strtol(argv[1], &endp, 0); - if (*endp != '\0' || errno != 0) - errx(1, "invalid partition start: %s", argv[1]); - partblocks = strtol(argv[2], &endp, 0); - if (*endp != '\0' || errno != 0) - errx(1, "invalid partition size: %s", argv[2]); - parttype = strtol(argv[3], &endp, 0); - if (*endp != '\0' || errno != 0) - errx(1, "invalid partition type: %s", argv[3]); - argc -= 4; - argv += 4; - } - if (argc != 1) - usage(); - - oflags = ((mode == 'i' || mode == 'w' || mode == 'l' || mode == 'd' - || mode == 'p') ? O_RDWR : O_RDONLY); - - /* Open raw device. */ - if ((fd = open(argv[0], oflags)) < 0) { - snprintf(fname, sizeof(fname), "/dev/r%s%c", - argv[0], 'a' + getrawpartition()); - if ((fd = open(fname, oflags)) < 0) - err(1, "open %s", fname); - } - - /* Get disklabel for device. */ - if (ioctl(fd, DIOCGDINFO, &lbl) == -1) - err(1, "ioctl DIOCGDINFO"); - - /* Allocate a buffer that matches the device sector size. */ - bufsize = lbl.d_secsize; - if (bufsize < sizeof(struct sgilabel)) - errx(1, "sector size is smaller than SGI volume header!\n"); - if ((buf = malloc(bufsize)) == NULL) - err(1, "failed to allocate buffer"); - - /* Read SGI volume header. */ - if (read(fd, buf, bufsize) != bufsize) - err(1, "read volhdr"); - volhdr = (struct sgilabel *)buf; - - if (mode == 'i') { - init_volhdr(); - exit(0); - } - - if (betoh32(volhdr->magic) != SGILABEL_MAGIC) - errx(2, "no Volume Header found, magic=%x. Use -i first.", - betoh32(volhdr->magic)); - - if (mode == 'r') - read_file(); - else if (mode == 'w') - write_file(); - else if (mode == 'l') - link_file(); - else if (mode == 'd') - delete_file(); - else if (mode == 'p') - modify_partition(); - else if (!quiet) - display_vol(); - - exit (0); -} - -void -display_vol(void) -{ - int32_t *l; - int i; - - l = (int32_t *)buf; - checksum = 0; - for (i = 0; i < sizeof(struct sgilabel) / sizeof(int32_t); ++i) - checksum += betoh32(l[i]); - - printf("disklabel shows %llu sectors with %u bytes per sector\n", - DL_GETDSIZE(&lbl), lbl.d_secsize); - printf("checksum: %08x%s\n", checksum, checksum == 0 ? "" : " *ERROR*"); - printf("root part: %d\n", betoh32(volhdr->root)); - printf("swap part: %d\n", betoh32(volhdr->swap)); - printf("bootfile: %s\n", volhdr->bootfile); - - /* volhdr->devparams[0..47] */ - printf("\nVolume header files:\n"); - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (volhdr->voldir[i].name[0] != '\0') { - printf("%-8s offset %4d blocks, " - "length %8d bytes (%d blocks)\n", - volhdr->voldir[i].name, - betoh32(volhdr->voldir[i].block), - betoh32(volhdr->voldir[i].bytes), - howmany(betoh32(volhdr->voldir[i].bytes), - DEV_BSIZE)); - } - } - - printf("\nSGI partitions:\n"); - for (i = 0; i < MAXPARTITIONS; ++i) { - if (betoh32(volhdr->partitions[i].blocks) != 0) { - printf("%2d:%c blocks %8d first %8d type %2d (%s)\n", - i, i + 'a', betoh32(volhdr->partitions[i].blocks), - betoh32(volhdr->partitions[i].first), - betoh32(volhdr->partitions[i].type), - betoh32(volhdr->partitions[i].type) > - (sizeof(sgi_types) / sizeof(sgi_types[0])) ? - "???" : - sgi_types[betoh32(volhdr->partitions[i].type)]); - } - } -} - -void -init_volhdr(void) -{ - memset(volhdr, 0, sizeof(struct sgilabel)); - volhdr->magic = htobe32(SGILABEL_MAGIC); - volhdr->root = htobe16(0); - volhdr->swap = htobe16(1); - strlcpy(volhdr->bootfile, "/bsd", sizeof(volhdr->bootfile)); - volhdr->dp.dp_skew = 1; /* XXX */ - volhdr->dp.dp_gap1 = 1; /* XXX */ - volhdr->dp.dp_gap2 = 1; /* XXX */ - volhdr->dp.dp_cyls = htobe16(lbl.d_ncylinders); - volhdr->dp.dp_shd0 = 0; - volhdr->dp.dp_trks0 = htobe16(lbl.d_ntracks); - volhdr->dp.dp_secs = htobe16(lbl.d_nsectors); - volhdr->dp.dp_secbytes = htobe16(lbl.d_secsize); - volhdr->dp.dp_interleave = 1; - volhdr->dp.dp_nretries = htobe32(22); - volhdr->partitions[10].blocks = - htobe32(DL_SECTOBLK(&lbl, DL_GETDSIZE(&lbl))); - volhdr->partitions[10].first = 0; - volhdr->partitions[10].type = htobe32(SGI_PTYPE_VOLUME); - volhdr->partitions[8].blocks = htobe32(DL_SECTOBLK(&lbl, volhdr_size)); - volhdr->partitions[8].first = 0; - volhdr->partitions[8].type = htobe32(SGI_PTYPE_VOLHDR); - volhdr->partitions[0].blocks = - htobe32(DL_SECTOBLK(&lbl, DL_GETDSIZE(&lbl) - volhdr_size)); - volhdr->partitions[0].first = htobe32(DL_SECTOBLK(&lbl, volhdr_size)); - volhdr->partitions[0].type = htobe32(SGI_PTYPE_BSD); - write_volhdr(); -} - -void -read_file(void) -{ - FILE *fp; - int i; - - if (!quiet) - printf("Reading file %s\n", vfilename); - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (strncmp(vfilename, volhdr->voldir[i].name, - strlen(volhdr->voldir[i].name)) == 0) - break; - } - if (i >= SGI_SIZE_VOLDIR) - errx(1, "%s: file not found", vfilename); - /* XXX assumes volume header starts at 0? */ - lseek(fd, betoh32(volhdr->voldir[i].block) * DEV_BSIZE, SEEK_SET); - if ((fp = fopen(ufilename, "w")) == NULL) - err(1, "open %s", ufilename); - i = betoh32(volhdr->voldir[i].bytes); - while (i > 0) { - if (read(fd, buf, bufsize) != bufsize) - err(1, "read file"); - fwrite(buf, 1, i > bufsize ? bufsize : i, fp); - i -= i > bufsize ? bufsize : i; - } - fclose(fp); -} - -void -write_file(void) -{ - FILE *fp; - int slot; - int block, i, fsize, fbufsize; - struct stat st; - char *fbuf; - - if (!quiet) - printf("Writing file %s\n", ufilename); - - if (stat(ufilename, &st) != 0) - err(1, "stat %s", ufilename); - if (st.st_size == 0) - errx(1, "%s: file is empty", vfilename); - - if (!quiet) - printf("File %s has %lld bytes\n", ufilename, st.st_size); - slot = -1; - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (volhdr->voldir[i].name[0] == '\0' && slot < 0) - slot = i; - if (strcmp(vfilename, volhdr->voldir[i].name) == 0) { - slot = i; - break; - } - } - if (slot == -1) - errx(1, "no more directory entries available"); - if (betoh32(volhdr->voldir[slot].block) > 0) { - if (!quiet) - printf("File %s exists, removing old file\n", - vfilename); - volhdr->voldir[slot].name[0] = 0; - volhdr->voldir[slot].block = volhdr->voldir[slot].bytes = 0; - } - /* XXX assumes volume header starts at 0? */ - block = allocate_space((int)st.st_size); - if (block < 0) - errx(1, "no more space available"); - - /* - * Make sure the name in the volume header is max. 8 chars, - * NOT including NUL. - */ - if (strlen(vfilename) > sizeof(volhdr->voldir[slot].name)) - warnx("%s: filename is too long and will be truncated", - vfilename); - strncpy(volhdr->voldir[slot].name, vfilename, - sizeof(volhdr->voldir[slot].name)); - - volhdr->voldir[slot].block = htobe32(block); - volhdr->voldir[slot].bytes = htobe32(st.st_size); - - write_volhdr(); - - /* Write the file itself. */ - if (lseek(fd, block * DEV_BSIZE, SEEK_SET) == -1) - err(1, "lseek write"); - fbufsize = volhdr->dp.dp_secbytes; - if ((fbuf = malloc(fbufsize)) == NULL) - err(1, "failed to allocate buffer"); - i = st.st_size; - fp = fopen(ufilename, "r"); - while (i > 0) { - bzero(fbuf, fbufsize); - fsize = i > fbufsize ? fbufsize : i; - if (fread(fbuf, 1, fsize, fp) != fsize) - err(1, "reading file from disk"); - if (write(fd, fbuf, fbufsize) != fbufsize) - err(1, "writing file to SGI volume header"); - i -= fsize; - } - fclose(fp); - free(fbuf); -} - -void -link_file(void) -{ - int slot, i; - int32_t block, bytes; - - if (!quiet) - printf("Linking file %s to %s\n", vfilename, ufilename); - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (strncmp(vfilename, volhdr->voldir[i].name, - strlen(volhdr->voldir[i].name)) == 0) - break; - } - if (i >= SGI_SIZE_VOLDIR) - errx(1, "%s: file not found", vfilename); - - block = volhdr->voldir[i].block; - bytes = volhdr->voldir[i].bytes; - - slot = -1; - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (volhdr->voldir[i].name[0] == '\0' && slot < 0) - slot = i; - if (strcmp(ufilename, volhdr->voldir[i].name) == 0) { - slot = i; - break; - } - } - if (slot == -1) - errx(1, "no more directory entries available"); - - /* - * Make sure the name in the volume header is max. 8 chars, - * NOT including NUL. - */ - if (strlen(ufilename) > sizeof(volhdr->voldir[slot].name)) - warnx("%s: filename is too long and will be truncated", - ufilename); - strncpy(volhdr->voldir[slot].name, ufilename, - sizeof(volhdr->voldir[slot].name)); - - volhdr->voldir[slot].block = block; - volhdr->voldir[slot].bytes = bytes; - write_volhdr(); -} - -void -delete_file(void) -{ - int i; - - for (i = 0; i < SGI_SIZE_VOLDIR; ++i) { - if (strcmp(vfilename, volhdr->voldir[i].name) == 0) { - break; - } - } - if (i >= SGI_SIZE_VOLDIR) - errx(1, "%s: file not found", vfilename); - - /* XXX: we don't compact the file space, so get fragmentation */ - volhdr->voldir[i].name[0] = '\0'; - volhdr->voldir[i].block = volhdr->voldir[i].bytes = 0; - write_volhdr(); -} - -void -modify_partition(void) -{ - if (!quiet) - printf("Modify partition %d start %d length %d\n", - partno, partfirst, partblocks); - volhdr->partitions[partno].blocks = htobe32(partblocks); - volhdr->partitions[partno].first = htobe32(partfirst); - volhdr->partitions[partno].type = htobe32(parttype); - write_volhdr(); -} - -void -write_volhdr(void) -{ - checksum_vol(); - - if (!quiet) - display_vol(); - if (lseek(fd, 0, SEEK_SET) == -1) - err(1, "lseek 0"); - if (write(fd, buf, bufsize) != bufsize) - err(1, "write volhdr"); -} - -int -allocate_space(int size) -{ - int n, blocks; - int first; - - blocks = howmany(size, DEV_BSIZE); - first = roundup(2 * DEV_BSIZE, volhdr->dp.dp_secbytes) / DEV_BSIZE; - - for (n = 0; n < SGI_SIZE_VOLDIR;) { - if (volhdr->voldir[n].name[0]) { - if (first < (betoh32(volhdr->voldir[n].block) + - howmany(betoh32(volhdr->voldir[n].bytes), - DEV_BSIZE)) && - (first + blocks) > - betoh32(volhdr->voldir[n].block)) { - - first = roundup( - betoh32(volhdr->voldir[n].block) + - howmany(betoh32(volhdr->voldir[n].bytes), - DEV_BSIZE), - volhdr->dp.dp_secbytes / DEV_BSIZE); -#if DEBUG - printf("allocate: " - "n=%d first=%d blocks=%d size=%d\n", - n, first, blocks, size); - printf("%s %d %d\n", volhdr->voldir[n].name, - volhdr->voldir[n].block, - volhdr->voldir[n].bytes); - printf("first=%d block=%d last=%d end=%d\n", - first, volhdr->voldir[n].block, - first + blocks - 1, - volhdr->voldir[n].block + - howmany(volhdr->voldir[n].bytes, - DEV_BSIZE)); -#endif - n = 0; - continue; - } - } - ++n; - } - if (first + blocks > DL_GETDSIZE(&lbl)) - first = -1; - /* XXX assumes volume header is partition 8 */ - /* XXX assumes volume header starts at 0? */ - if (first + blocks >= betoh32(volhdr->partitions[8].blocks)) - first = -1; - return (first); -} - -void -checksum_vol(void) -{ - int32_t *l; - int i; - - volhdr->checksum = checksum = 0; - l = (int32_t *)buf; - for (i = 0; i < sizeof(struct sgilabel) / sizeof(int32_t); ++i) - checksum += betoh32(l[i]); - volhdr->checksum = htobe32(-checksum); -} - -void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, - "usage: %s [-q] disk\n" - " %s [-q] -d vhfilename disk\n" - " %s [-q] -i [-h vhsize] disk\n" - " %s [-q] -l vhfilename1 vhfilename2 disk\n" - " %s [-q] -r vhfilename diskfilename disk\n" - " %s [-q] -w vhfilename diskfilename disk\n", - __progname, __progname, __progname, __progname, __progname, - __progname); - - exit(1); -} |