diff options
author | se <se@FreeBSD.org> | 1999-07-28 20:28:47 +0000 |
---|---|---|
committer | se <se@FreeBSD.org> | 1999-07-28 20:28:47 +0000 |
commit | e34ff91e6c62461bf2df88b64b48fd50e7426480 (patch) | |
tree | 8f89ccd8852f47725163079b9d18d5ecdfe8c0ce /sys/boot | |
parent | 0c579844562c4dba1b1623050a5731fcad5cc4b1 (diff) | |
parent | 159c5d3210cc7b4754b2ac86132b396383c26b24 (diff) | |
download | FreeBSD-src-e34ff91e6c62461bf2df88b64b48fd50e7426480.zip FreeBSD-src-e34ff91e6c62461bf2df88b64b48fd50e7426480.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r49187,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'sys/boot')
28 files changed, 3009 insertions, 0 deletions
diff --git a/sys/boot/arc/Makefile b/sys/boot/arc/Makefile new file mode 100644 index 0000000..4b04369 --- /dev/null +++ b/sys/boot/arc/Makefile @@ -0,0 +1,6 @@ +# $Id: Makefile,v 1.1.1.1 1998/08/21 03:17:41 msmith Exp $ + +SUBDIR= lib +SUBDIR+= loader + +.include <bsd.subdir.mk> diff --git a/sys/boot/arc/Makefile.inc b/sys/boot/arc/Makefile.inc new file mode 100644 index 0000000..4b2226c --- /dev/null +++ b/sys/boot/arc/Makefile.inc @@ -0,0 +1,6 @@ +# Options used when building app-specific libalpha components +LOAD_ADDRESS= 0xffffffff80900000 +DPADD+= ${DESTDIR}/${LIBDIR}/libstand.a +LIBSTANDDIR= ${.CURDIR}/../../../../lib/libstand +LIBSTAND= -lstand +LIBARC= ${.OBJDIR}/../lib/libarc.a diff --git a/sys/boot/arc/include/arcfuncs.h b/sys/boot/arc/include/arcfuncs.h new file mode 100644 index 0000000..cc4e48d --- /dev/null +++ b/sys/boot/arc/include/arcfuncs.h @@ -0,0 +1,199 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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. + * + * $Id$ + * + */ + +#ifdef __GNUC__ +#define INLINE inline +#else +#define INLINE /**/ +#endif + +/* System Parameter Block holding ARC and VENDOR function vector addresses */ + +#define SPBlock ((SPB *)0xffffffff806fe000ul) + +/* + * Convert between 32bit (ARC) and 64bit (Alpha) pointers + */ + +static INLINE void* +ptr(arcptr p) +{ + return (void*)(int64_t)p.adr; +} + +static INLINE arcptr +toarcptr(void *p) +{ + arcptr p32; + p32.adr = (int32_t)(int64_t) p; + return (p32); +} + +/* + * Return entry point for ARC BIOS function "funcno" + */ + +static INLINE void * +get_arc_vector(int funcno) +{ + arcptr (*arc_vector)[] = ptr(SPBlock->FirmwareVectorP); + return ptr((*arc_vector)[funcno -1]); +} + +/* + * Return entry point for VENDOR function "funcno" + */ + +static INLINE void * +get_vendor_vector(int funcno) +{ + arcptr (*arc_vector)[] = ptr(SPBlock->PrivateVectorP); + return ptr((*arc_vector)[funcno -1]); +} + +static INLINE int +get_vendor_vector_length(void) +{ + return SPBlock->PrivateVectorLength; +} + +/* + * Macros to create inline wrappers for ARCS BIOS functions + * + * Parameter: + * num function number (starting at 1) + * result result type + * fn function name + * param parameter list (types and formal args) + * args parameter list (formal args only) + */ + +#define ARC_FN(num,result,fn,param,args) \ +static inline result fn param { \ + typedef result _fn_t param; \ + _fn_t *p_ ## fn = get_arc_vector(num); \ + return p_ ## fn args; \ +} + +#define VND_FN(num,result,fn,param,args) \ +static INLINE result fn param { \ + typedef result _fn_t param; \ + _fn_t *p_ ## fn = get_vendor_vector(num); \ + return p_ ## fn args; \ +} + +/* function codes as defined in ARC Specification Version 1.2 */ + +ARC_FN(1, int32_t, Load, + (char *Path, u_int32_t TopAddr, u_int32_t *ExecAddr, u_int32_t *LowAddr), + (Path, TopAddr, ExecAddr, LowAddr)) +ARC_FN(2, int32_t, Invoke, + (u_int32_t ExecAddr, u_int32_t StackAddr, u_int32_t Argc, char *Argv[], char *Envp[]), + (ExecAddr, StackAddr, Argc, Argv, Envp)) +ARC_FN(3, int32_t, Execute, + (char *Path, u_int32_t Argc, char *Argv[], char *Envp[]), + (Path, Argc, Argv, Envp)) +ARC_FN(4, void, Halt, (void), ()) +ARC_FN(5, void, PowerDown, (void), ()) +ARC_FN(6, void, Restart, (void), ()) +ARC_FN(7, void, FwReboot, (void), ()) +ARC_FN(8, void, EnterInteractiveMode, (void), ()) +ARC_FN(10, CONFIGURATION_COMPONENT *, GetPeer, + (CONFIGURATION_COMPONENT *Current), + (Current)) +ARC_FN(11, CONFIGURATION_COMPONENT *, GetChild, + (CONFIGURATION_COMPONENT *Current), + (Current)) +ARC_FN(12, CONFIGURATION_COMPONENT *, GetParent, + (CONFIGURATION_COMPONENT *Current), + (Current)) +ARC_FN(13, CONFIGURATION_COMPONENT *, AddChild, + (CONFIGURATION_COMPONENT *Current, CONFIGURATION_COMPONENT *Template, + void *ConfigurationData), + (Current, Template, ConfigurationData)) +ARC_FN(14, int32_t, DeleteComponent, + (CONFIGURATION_COMPONENT *ComponentToDelete), + (ComponentToDelete)) +ARC_FN(15, CONFIGURATION_COMPONENT *, GetComponent, (char *Path), (Path)) +ARC_FN(16, int32_t, GetConfigurationData, + (void *ConfigurationData, CONFIGURATION_COMPONENT *Component), + (ConfigurationData, Component)) +ARC_FN(17, int32_t, SaveConfiguration, (void), ()) +ARC_FN(18, SYSTEM_ID *, GetSystemId, (void), ()) +ARC_FN(19, MEMORY_DESCRIPTOR *, GetMemoryDescriptor, + (MEMORY_DESCRIPTOR *Current), + (Current)) +ARC_FN(21, TIME_FIELDS *, GetTime, (void), ()) +ARC_FN(22, u_int32_t, GetRelativeTime, (void), ()) +ARC_FN(23, int32_t, GetDirectoryEntry, + (u_int32_t FileId, DIRECTORY_ENTRY *Buffer, u_int32_t Length, u_int32_t *Count), + (FileId, Buffer, Length, Count)) +ARC_FN(24, int32_t, Open, + (const char *Path, OPEN_MODE OpenMode, u_int32_t *FileId), + (Path, OpenMode, FileId)) +ARC_FN(25, int32_t, Close, (u_int32_t FileId), (FileId)) +ARC_FN(26, int32_t, Read, + (u_int32_t FileId, void *Buffer, u_int32_t N, u_int32_t *Count), + (FileId, Buffer, N, Count)) +ARC_FN(27, int32_t, GetReadStatus, (u_int32_t FileId), (FileId)) +ARC_FN(28, int32_t, Write, + (u_int32_t FileId, void const *Buffer, u_int32_t N, u_int32_t *Count), + (FileId, Buffer, N, Count)) +ARC_FN(29, int32_t, Seek, + (u_int32_t FileId, fpos_t *Position, SEEK_MODE SeekMode), + (FileId, Position, SeekMode)) +ARC_FN(30, int32_t, Mount, + (char *Path, MOUNT_OPERATION Operation), + (Path, Operation)) +ARC_FN(31, char *, GetEnvironmentVariable, (char *Name), (Name)) +ARC_FN(32, int32_t, SetEnvironmentVariable, + (char *Name, char *Value), + (Name, Value)) +ARC_FN(33, int32_t, GetFileInformation, + (u_int32_t FileId, FILE_INFORMATION *Information), + (FileId, Information)) +ARC_FN(34, int32_t, SetFileInformation, + (u_int32_t FileId, u_int32_t AttributeFlags, u_int32_t AttributeMask), + (FileId, AttributeFlags, AttributeMask)) +ARC_FN(35, void, FlushAllCaches, (void), ()) +ARC_FN(36, int32_t, TestUnicodeCharacter, + (u_int32_t FileId, WCHAR UnicodeCharacter), + (FileId, UnicodeCharacter)) +ARC_FN(37, ARC_DISPLAY_STATUS *, GetDisplayStatus, (u_int32_t FileId), (FileId)) + +/* Vendor specific function codes have not been verified beyond function 4 */ + +VND_FN(1, void *, AllocatePool, (u_int32_t NumberOfBytes), (NumberOfBytes)) +VND_FN(2, void, StallExecution, (u_int32_t Microseconds), (Microseconds)) +VND_FN(3, u_int32_t, Print, + (char *Format, int32_t Arg1, int32_t Arg2, int32_t Arg3), + (Format, Arg1, Arg2, Arg3)) +VND_FN(4, void, ReturnExtendedSystemInformation, + (EXTENDED_SYSTEM_INFORMATION *SystemInfo), + (SystemInfo)) diff --git a/sys/boot/arc/include/arctypes.h b/sys/boot/arc/include/arctypes.h new file mode 100644 index 0000000..e9c73d3 --- /dev/null +++ b/sys/boot/arc/include/arctypes.h @@ -0,0 +1,288 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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. + * + * $Id$ + * + */ + +#ifndef _ARC_TYPES_H_ +#define _ARC_TYPES_H_ + +#define ESUCCESS 0 + +typedef u_int8_t BOOLEAN; +typedef u_int16_t WCHAR; + +typedef int64_t fpos_t; + +/* XXX the following types are defined in ARC but are not currently used */ + +#if 0 + +typedef void VOID; + +typedef int8_t CHAR; +typedef int16_t SHORT; +typedef int32_t LONG; +typedef int64_t LONGLONG; + +typedef u_int8_t UCHAR; +typedef u_int16_t USHORT; +typedef u_int32_t ULONG; +typedef u_int64_t ULONGLONG; + +/* + * The following ARC types conflict with <sys/types.h> ! + * They are not used in the ARC wrapper functions or ARC structs + * currently, and thus may be left alone for now. In case the + * wrappers or structs are converted to use them, it is suggested + * to prefix them with "arc" to avoid type clashes (if linking + * against libstand.a which expects the FreeBSD declarations). + */ + +typedef u_int32_t size_t; +typedef int64_t clock_t; +typedef int64_t off_t; +typedef int32_t time_t; + +#endif /* 0 */ + +typedef struct { + int32_t adr; +} arcptr; + +typedef struct { + u_int32_t SPBSignature; + u_int32_t SPBLength; + u_int16_t Version; + u_int16_t Revision; + arcptr RestartBlockP; + arcptr DebugBlockP; + arcptr GEVectorP; + arcptr ULTBMissVectorP; + u_int32_t FirmwareVectorLength; + arcptr FirmwareVectorP; + u_int32_t PrivateVectorLength; + arcptr PrivateVectorP; + u_int32_t AdapterCount; + struct { + u_int32_t AdapterType; + u_int32_t AdapterVectorLength; + arcptr AdapterVectorP; + } Adapters[1]; +} SPB; + +/* ARC function specific data types */ + +typedef enum{ + SystemClass, + ProcessorClass, + CacheClass, + AdapterClass, + ControllerClass, + PeripheralClass, + MemoryClass, + MaximumClass +} CONFIGURATION_CLASS; + +typedef enum { + ArcSystem, + CentralProcessor, + FloatingPointProcessor, + PrimaryIcache, + PrimaryDcache, + SecondaryIcache, + SecondaryDcache, + SecondaryCache, + EisaAdapter, + TcAdapter, + ScsiAdapter, + DtiAdapter, + MultiFunctionAdapter, + DiskController, + TapeController, + CdromController, + WormController, + SerialController, + NetworkController, + DisplayController, + ParallelController, + PointerController, + KeyboardController, + AudioController, + OtherController, + DiskPeripheral, + FloppyDiskPeripheral, + TapePeripheral, + ModemPeripheral, + MonitorPeripheral, + PrinterPeripheral, + PointerPeripheral, + KeyboardPeripheral, + TerminalPeripheral, + OtherPeripheral, + LinePeripheral, + NetworkPeripheral, + SystemMemory, + MaximumType +} CONFIGURATION_TYPE, *PCONFIGURATION_TYPE; + +typedef enum { + Failed = 0x01, + ReadOnly = 0x02, + Removable = 0x04, + ConsoleIn = 0x08, + ConsoleOut = 0x10, + Input = 0x20, + Output = 0x40 +} IDENTIFIERFLAG; + +typedef struct { + CONFIGURATION_CLASS Class; + CONFIGURATION_TYPE Type; + IDENTIFIERFLAG Flags; + u_int16_t Version; + u_int16_t Revision; + u_int32_t Key; + u_int32_t AffinityMask; + u_int32_t ConfigurationDataLength; + u_int32_t IdentifierLength; + arcptr Identifier; +} CONFIGURATION_COMPONENT, *PCONFIGURATION_COMPONENT; + +typedef struct { + int8_t VendorId[8]; + int8_t ProductId[8]; +} SYSTEM_ID; + +typedef enum { + MemoryExceptionBlock, + MemorySystemBlock, + MemoryFree, + MemoryBad, + MemoryLoadedProgram, + MemoryFirmwareTemporary, + MemoryFirmwarePermanent, + MemoryFreeContiguous, + MemorySpecialMemory, + MemoryMaximum +} MEMORY_TYPE; + +typedef struct { + MEMORY_TYPE Type; + u_int32_t BasePage; + u_int32_t PageCount; +} MEMORY_DESCRIPTOR; + +typedef struct _TIME_FIELDS{ + u_int16_t Year; /* 1601 .. */ + u_int16_t Month; /* 1 .. 12 */ + u_int16_t Day; /* 1 .. 31 */ + u_int16_t Hour; /* 0 .. 23 */ + u_int16_t Minute; /* 0 .. 59 */ + u_int16_t Second; /* 0 .. 59 */ + u_int16_t Milliseconds; /* 0 .. 999 */ + u_int16_t Weekday; /* 0 .. 6 = Sunday .. Saturday */ +} TIME_FIELDS, *PTIME_FIELDS; + +#define StandardIn 0 +#define StandardOut 1 + +#define ReadOnlyFile 0x01 +#define HiddenFile 0x02 +#define SystemFile 0x04 +#define ArchiveFile 0x08 +#define DirectoryFile 0x10 +#define DeleteFile 0x20 + +typedef struct { + u_int32_t FileNameLength; + u_int8_t FileAttribute; + int8_t FileName[32]; +} DIRECTORY_ENTRY; + +typedef enum { + OpenReadOnly, + OpenWriteOnly, + OpenReadWrite, + CreateWriteOnly, + CreateReadWrite, + SupersedeWriteOnly, + SupersedeReadWrite, + OpenDirectory, + CreateDirectory, + OpenMaximumMode +} OPEN_MODE; + +typedef enum { + SeekAbsolute, + SeekRelative, + SeekMaximum +} SEEK_MODE; + +typedef enum { + MountLoadMedia, + MountUnloadMedia, + MountMaximum +} MOUNT_OPERATION; + +typedef struct { + fpos_t StartingAddress; + fpos_t EndingAddress; + fpos_t CurrentAddress; + CONFIGURATION_TYPE Type; + u_int32_t FileNameLength; + u_int8_t Attributes; + int8_t FileName[32]; +} FILE_INFORMATION; + +typedef struct { + u_int16_t CursorXPosition; + u_int16_t CursorYPosition; + u_int16_t CursorMaxXPosition; + u_int16_t CursorMaxYPosition; + u_int8_t ForegroundColor; + u_int8_t BackgroundColor; + BOOLEAN HighIntensity; + BOOLEAN Underscored; + BOOLEAN ReverseVideo; +} ARC_DISPLAY_STATUS; + +/* vendor function specific data types */ + +typedef struct { + u_int32_t ProcessorId; + u_int32_t ProcessorRevision; + u_int32_t ProcessorPageSize; + u_int32_t NumberOfPhysicalAddressBits; + u_int32_t MaximumAddressSpaceNumber; + u_int32_t ProcessorCycleCounterPeriod; + u_int32_t SystemRevision; + u_int8_t SystemSerialNumber[16]; + u_int8_t FirmwareVersion[16]; + u_int8_t FirmwareBuildTimeStamp[12]; +} EXTENDED_SYSTEM_INFORMATION, *PEXTENDED_SYSTEM_INFORMATION; + +#endif /* _ARC_TYPES_H_ */ diff --git a/sys/boot/arc/include/libarc.h b/sys/boot/arc/include/libarc.h new file mode 100644 index 0000000..7162159 --- /dev/null +++ b/sys/boot/arc/include/libarc.h @@ -0,0 +1,81 @@ +/* $Id$ */ + +/* + * Copyright (c) 1996 + * Matthias Drochner. 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 for the NetBSD Project + * by Matthias Drochner. + * 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. + * + */ + +/* + * ARC fully-qualified device descriptor + */ +struct arc_devdesc +{ + struct devsw *d_dev; + int d_type; +#define DEVT_NONE 0 +#define DEVT_DISK 1 +#define DEVT_NET 2 + union + { + struct + { + int unit; + int slice; + int partition; + } arcdisk; + struct + { + int unit; /* XXX net layer lives over these? */ + } netif; + } d_kind; +}; + +extern int arc_getdev(void **vdev, const char *devspec, const char **path); +extern char *arc_fmtdev(void *vdev); +extern int arc_setcurrdev(struct env_var *ev, int flags, void *value); + +#define MAXDEV 31 /* maximum number of distinct devices */ + +typedef unsigned long physaddr_t; + +/* exported devices XXX rename? */ +extern struct devsw arcdisk; +extern struct netif_driver arcnet; + +/* this is in startup code */ +extern void delay(int); +extern void reboot(void); + +extern int arc_copyin(void *src, vm_offset_t dest, size_t len); +extern int arc_copyout(vm_offset_t src, void *dest, size_t len); +extern int arc_readin(int fd, vm_offset_t dest, size_t len); + +extern int arc_boot(void); +extern int arc_autoload(void); diff --git a/sys/boot/arc/lib/Makefile b/sys/boot/arc/lib/Makefile new file mode 100644 index 0000000..57c7282 --- /dev/null +++ b/sys/boot/arc/lib/Makefile @@ -0,0 +1,38 @@ +# $Id: Makefile,v 1.6 1998/10/16 19:26:11 msmith Exp $ + +LIB= arc +NOPIC= true +NOPROFILE= true +INTERNALLIB= true + +.PATH: arch/${MACHINE} +# XXX hack to pick up stand.h +LIBSTANDDIR= ${.CURDIR}/../../../../lib/libstand +CFLAGS= -I${LIBSTANDDIR} +CFLAGS+= -DDEBUG + +# Pick up the bootstrap header for some interface items +CFLAGS+= -I${.CURDIR}/../../common -mno-fp-regs \ + -I${.CURDIR}/../../.. -I../include + +#CFLAGS+= -DDISK_DEBUG +#CPPFLAGS+= -DNO_DISKLABEL +#CPPFLAGS+= -DSAVE_MEMORY + +SRCS= delay.c time.c abort.c setjmperr.c copy.c devicename.c module.c \ + arcconsole.c arcdisk.c elf_freebsd.c bootinfo.c + +.if ${MACHINE} == "alpha" +SRCS+= rpb.c +.endif + +all: libarc.a + +CLEANFILES+= machine + +machine: + ln -sf ${.CURDIR}/../../../alpha/include machine + +.include <bsd.lib.mk> + +beforedepend ${OBJS}: machine diff --git a/sys/boot/arc/lib/abort.c b/sys/boot/arc/lib/abort.c new file mode 100644 index 0000000..0048061 --- /dev/null +++ b/sys/boot/arc/lib/abort.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +#include <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +abort() +{ + FwReboot(); +} diff --git a/sys/boot/arc/lib/arcconsole.c b/sys/boot/arc/lib/arcconsole.c new file mode 100644 index 0000000..e8ecb22 --- /dev/null +++ b/sys/boot/arc/lib/arcconsole.c @@ -0,0 +1,107 @@ +/* $Id$ */ +/* $NetBSD: prom.c,v 1.3 1997/09/06 14:03:58 drochner Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include <sys/types.h> + +#include "bootstrap.h" +#include "arctypes.h" +#include "arcfuncs.h" + +int console; + +static void arc_probe(struct console *cp); +static int arc_init(int); +static void arc_putchar(int); +static int arc_getchar(void); +static int arc_poll(void); + +struct console arcconsole = { + "arc", + "ARC firmware console", + 0, + arc_probe, + arc_init, + arc_putchar, + arc_getchar, + arc_poll, +}; + +static void +arc_probe(struct console *cp) +{ + cp->c_flags |= C_PRESENTIN|C_PRESENTOUT; +} + +static int +arc_init(int arg) +{ + return 0; +} + +static void +arc_putchar(int c) +{ + char cbuf = c; + u_int32_t count; + + Write(StandardOut, &cbuf, 1, &count); +} + +static int saved_char = -1; + +int +arc_getchar() +{ + char cbuf; + u_int32_t count; + + arc_putchar('_'); + arc_putchar('\b'); + Read(StandardIn, &cbuf, 1, &count); + arc_putchar(' '); + arc_putchar('\b'); + if (count == 1) + return cbuf; + else + return -1; +} + +int +arc_poll() +{ + return GetReadStatus(StandardIn) == ESUCCESS; +} + +int +arc_open(dev, len) + char *dev; + int len; +{ + return 0; +} diff --git a/sys/boot/arc/lib/arcdisk.c b/sys/boot/arc/lib/arcdisk.c new file mode 100644 index 0000000..5a6be39 --- /dev/null +++ b/sys/boot/arc/lib/arcdisk.c @@ -0,0 +1,357 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * Copyright (c) 1998 Doug Rabson <dfr@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +/* + * ARC disk device handling. + * + * Ideas and algorithms from: + * + * - NetBSD libi386/biosdisk.c + * - FreeBSD biosboot/disk.c + * + * XXX Todo: add bad144 support. + */ + +#include <stand.h> + +#include <sys/disklabel.h> +#include <sys/diskslice.h> + +#include <machine/stdarg.h> + +#include "bootstrap.h" +#include "libarc.h" +#include "arctypes.h" +#include "arcfuncs.h" + +#define ARCDISK_SECSIZE 512 + +#define BUFSIZE (1 * ARCDISK_SECSIZE) +#define MAXBDDEV MAXDEV + +#ifdef DISK_DEBUG +# define D(x) x +#else +# define D(x) +#endif + +static int bd_init(void); +static int bd_strategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize); +static int bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize); +static int bd_open(struct open_file *f, void *vdev); +static int bd_close(struct open_file *f); +static void bd_print(int verbose); + +struct open_disk { + int od_fd; + int od_unit; /* our unit number */ + int od_boff; /* block offset from beginning of ARC disk */ + int od_flags; +#define BD_FLOPPY (1<<2) + u_char od_buf[BUFSIZE]; /* transfer buffer (do we want/need this?) */ +}; + +struct devsw arcdisk = { + "disk", + DEVT_DISK, + bd_init, + bd_strategy, + bd_open, + bd_close, + noioctl, + bd_print +}; + +/* + * List of ARC devices, translation from disk unit number to + * ARC unit number. + */ +static struct +{ + char bd_name[64]; + int bd_unit; /* ARC unit number */ + int bd_namelen; + int bd_flags; +} bdinfo [MAXBDDEV]; +static int nbdinfo = 0; + +/* + * Quiz ARC for disk devices, save a little info about them. + */ +static int +bd_init(void) +{ + nbdinfo++; + + return (0); +} + +/* + * Print information about disks + */ +static void +bd_print(int verbose) +{ + int i; + char line[80]; + + for (i = 0; i < nbdinfo; i++) { + sprintf(line, " disk%d: ARC drive %s", i, bdinfo[i].bd_name); + pager_output(line); + /* XXX more detail? */ + pager_output("\n"); + } +} + +/* + * Attempt to open the disk described by (dev) for use by (f). + * + * Note that the philosophy here is "give them exactly what + * they ask for". This is necessary because being too "smart" + * about what the user might want leads to complications. + * (eg. given no slice or partition value, with a disk that is + * sliced - are they after the first BSD slice, or the DOS + * slice before it?) + */ +static int +bd_open(struct open_file *f, void *vdev) +{ + struct arc_devdesc *dev = vdev; + struct dos_partition *dptr; + struct open_disk *od; + struct disklabel *lp; + int sector, slice, i; + int error; + int unit; + u_int32_t fd; + + unit = dev->d_kind.arcdisk.unit; + if (unit >= nbdinfo) { + D(printf("attempt to open nonexistent disk\n")); + return(ENXIO); + } + + if (Open("scsi(0)disk(0)rdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + if (Open("scsi(0)disk(1)rdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + if (Open("multi(0)disk(0)fdisk(0)partition(0)", + OpenReadOnly, &fd) != ESUCCESS) + return(ENXIO); + + od = (struct open_disk *) malloc(sizeof(struct open_disk)); + if (!od) { + D(printf("arcdiskopen: no memory\n")); + return (ENOMEM); + } + + /* Look up ARC unit number, intialise open_disk structure */ + od->od_fd = fd; + od->od_unit = dev->d_kind.arcdisk.unit; + od->od_flags = bdinfo[od->od_unit].bd_flags; + od->od_boff = 0; + error = 0; + +#if 0 + /* Get geometry for this open (removable device may have changed) */ + if (set_geometry(&od->od_ll)) { + D(printf("bd_open: can't get geometry\n")); + error = ENXIO; + goto out; + } +#endif + + /* + * Following calculations attempt to determine the correct value + * for d->od_boff by looking for the slice and partition specified, + * or searching for reasonable defaults. + */ + +#if 0 + /* + * Find the slice in the DOS slice table. + */ + if (readsects(&od->od_ll, 0, 1, od->od_buf, 0)) { + D(printf("bd_open: error reading MBR\n")); + error = EIO; + goto out; + } + + /* + * Check the slice table magic. + */ + if ((od->od_buf[0x1fe] != 0xff) || (od->od_buf[0x1ff] != 0xaa)) { + /* If a slice number was explicitly supplied, this is an error */ + if (dev->d_kind.arcdisk.slice > 0) { + D(printf("bd_open: no slice table/MBR (no magic)\n")); + error = ENOENT; + goto out; + } + sector = 0; + goto unsliced; /* may be a floppy */ + } + dptr = (struct dos_partition *) & od->od_buf[DOSPARTOFF]; + + /* + * XXX No support here for 'extended' slices + */ + if (dev->d_kind.arcdisk.slice <= 0) { + /* + * Search for the first FreeBSD slice; this also works on "unsliced" + * disks, as they contain a "historically bogus" MBR. + */ + for (i = 0; i < NDOSPART; i++, dptr++) + if (dptr->dp_typ == DOSPTYP_386BSD) { + sector = dptr->dp_start; + break; + } + /* Did we find something? */ + if (sector == -1) { + error = ENOENT; + goto out; + } + } else { + /* + * Accept the supplied slice number unequivocally (we may be looking + * for a DOS partition) if we can handle it. + */ + if ((dev->d_kind.arcdisk.slice > NDOSPART) || (dev->d_kind.arcdisk.slice < 1)) { + error = ENOENT; + goto out; + } + dptr += (dev->d_kind.arcdisk.slice - 1); + sector = dptr->dp_start; + } + unsliced: + +#else + sector = 0; +#endif + /* + * Now we have the slice, look for the partition in the disklabel if we have + * a partition to start with. + */ + if (dev->d_kind.arcdisk.partition < 0) { + od->od_boff = sector; /* no partition, must be after the slice */ + } else { + if (bd_strategy(od, F_READ, sector + LABELSECTOR, 512, od->od_buf, 0)) { + D(printf("bd_open: error reading disklabel\n")); + error = EIO; + goto out; + } + lp = (struct disklabel *) (od->od_buf + LABELOFFSET); + if (lp->d_magic != DISKMAGIC) { + D(printf("bd_open: no disklabel\n")); + error = ENOENT; + goto out; + + } else if (dev->d_kind.arcdisk.partition >= lp->d_npartitions) { + + /* + * The partition supplied is out of bounds; this is fatal. + */ + D(printf("partition '%c' exceeds partitions in table (a-'%c')\n", + 'a' + dev->d_kind.arcdisk.partition, 'a' + lp->d_npartitions)); + error = EPART; + goto out; + + } else { + + /* + * Complain if the partition type is wrong and it shouldn't be, but + * regardless accept this partition. + */ + D(if ((lp->d_partitions[dev->d_kind.arcdisk.partition].p_fstype == FS_UNUSED) && + !(od->od_flags & BD_FLOPPY)) /* Floppies often have bogus fstype */ + printf("bd_open: warning, partition marked as unused\n");); + + od->od_boff = lp->d_partitions[dev->d_kind.arcdisk.partition].p_offset; + } + } + /* + * Save our context + */ + f->f_devdata = od; + + out: + if (error) + free(od); + return(error); +} + +static int +bd_close(struct open_file *f) +{ + struct open_disk *od = f->f_devdata; + + Close(od->od_fd); + + free(od); + f->f_devdata = NULL; + return(0); +} + +static int +bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize) +{ + struct bcache_devdata bcd; + + bcd.dv_strategy = bd_realstrategy; + bcd.dv_devdata = devdata; + return(bcache_strategy(&bcd, rw, dblk, size, buf, rsize)); +} + +static int +bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize) +{ + struct open_disk *od = (struct open_disk *)devdata; + fpos_t seek; + u_int32_t count; + + if (size % ARCDISK_SECSIZE) + panic("bd_strategy: I/O not block multiple"); + + if (flag != F_READ) + return(EROFS); + + if (rsize) + *rsize = 0; + + seek = 512 * (dblk + od->od_boff); + Seek(od->od_fd, &seek, SeekAbsolute); + if (Read(od->od_fd, buf, size, &count) != ESUCCESS) { + D(printf("read error\n")); + return (EIO); + } + + if (rsize) + *rsize = count; + return (0); +} + diff --git a/sys/boot/arc/lib/arch/alpha/copy.c b/sys/boot/arc/lib/arch/alpha/copy.c new file mode 100644 index 0000000..2ca1397 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/copy.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id: alpha_copy.c,v 1.3 1998/09/20 21:46:19 dfr Exp $ + */ +/* + * MD primitives supporting placement of module data + * + * XXX should check load address/size against memory top. + */ +#include <stand.h> +#include <machine/alpha_cpu.h> + +#include "libarc.h" + +/* + * Convert from a 64bit superpage address to a 32bit arc superpage address. + */ +static void * +convert_superpage(vm_offset_t p) +{ + if (p < ALPHA_K0SEG_BASE || p >= ALPHA_K0SEG_END) { + printf("stupid address %p\n", (void *)p); + panic("broken"); + } + return (void *) (0xffffffff80000000 + (p - ALPHA_K0SEG_BASE)); +} + +int +arc_copyin(void *src, vm_offset_t dest, size_t len) +{ + bcopy(src, convert_superpage(dest), len); + return(len); +} + +int +arc_copyout(vm_offset_t src, void *dest, size_t len) +{ + bcopy(convert_superpage(src), dest, len); + return(len); +} + +int +arc_readin(int fd, vm_offset_t dest, size_t len) +{ + return(read(fd, convert_superpage(dest), len)); +} + + diff --git a/sys/boot/arc/lib/arch/alpha/rpb.c b/sys/boot/arc/lib/arch/alpha/rpb.c new file mode 100644 index 0000000..ac56c82 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/rpb.c @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +#include <stand.h> +#include <machine/rpb.h> +#include "arctypes.h" +#include "arcfuncs.h" + +struct rpb RPB = { + 0, /* rpb_phys */ + {"HWRPB"}, /* rpb_magic */ + HWRPB_DSRDB_MINVERS, /* rpb_version */ + sizeof(struct rpb), /* rpb_size */ + 0, /* rpb_primary_cpu_id */ + 8192, /* rpb_page_size */ + 43, /* rpb_phys_addr_size */ + 0, /* rpb_max_asn */ + {0}, /* rpb_ssn */ + ST_EB164, /* rpb_type */ + SV_ST_ALPHAPC164LX_533, /* rpb_variation */ + {"0000"}, /* rpb_revision */ + 1024*4096, /* rpb_intr_freq */ + 533*1024*1024, /* rpb_cc_freq */ + 0, /* rpb_vptb */ + 0, /* rpb_reserved_arch */ + 0, /* rpb_tbhint_off */ + 0, /* rpb_pcs_cnt */ + 0, /* rpb_pcs_size */ + 0, /* rpb_pcs_off */ + 0, /* rpb_ctb_cnt */ + 0, /* rpb_ctb_size */ + 0, /* rpb_ctb_off */ + 0, /* rpb_crb_off */ + 0, /* rpb_memdat_off */ + 0, /* rpb_condat_off */ + 0, /* rpb_fru_off */ + 0, /* rpb_save_term */ + 0, /* rpb_save_term_val */ + 0, /* rpb_rest_term */ + 0, /* rpb_rest_term_val */ + 0, /* rpb_restart */ + 0, /* rpb_restart_val */ + 0, /* rpb_reserve_os */ + 0, /* rpb_reserve_hw */ + 0, /* rpb_checksum */ + 0, /* rpb_rxrdy */ + 0, /* rpb_txrdy */ + 0, /* rpb_dsrdb_off */ + {0}, /* rpb_rpb_tbhint */ +}; + +#define ROUNDUP(x) (((x) + sizeof(u_int64_t) - 1) \ + & ~(sizeof(u_int64_t) - 1)) + +u_int64_t +checksum(void *p, size_t size) +{ + u_int64_t sum = 0; + u_int64_t *lp = (u_int64_t *)p; + int i; + + printf("checksum(%p, %d)\n", p, size); + size = ROUNDUP(size) / sizeof(u_int64_t); + for (i = 0; i < size; i++) + sum += lp[i]; +} + +size_t +size_mddt() +{ + int count = 0; + MEMORY_DESCRIPTOR *desc; + + for (desc = GetMemoryDescriptor(NULL); desc; + desc = GetMemoryDescriptor(desc)) { + count++; + } + + return ROUNDUP(sizeof(struct mddt) + + (count - 1) * sizeof(struct mddt_cluster)); +} + +void +write_mddt(struct mddt *mddt, size_t size) +{ + int count = 0, i; + MEMORY_DESCRIPTOR *desc; + u_int64_t *p; + + memset(mddt, 0, sizeof(struct mddt)); + for (desc = GetMemoryDescriptor(NULL); desc; + desc = GetMemoryDescriptor(desc)) { + struct mddt_cluster *mc; + mc = &mddt->mddt_clusters[count]; + mc->mddt_pfn = desc->BasePage; + mc->mddt_pg_cnt = desc->PageCount; + mc->mddt_pg_test = 0; + mc->mddt_v_bitaddr = 0; + mc->mddt_p_bitaddr = 0; + mc->mddt_bit_cksum = 0; + + /* + * Not sure about the FirmwareTemporary bit but my 164LX has + * about 60Mb marked this way. + */ + if (desc->Type == MemoryFree || desc->Type == MemoryFirmwareTemporary) + mc->mddt_usage = MDDT_SYSTEM; + else if (desc->Type == MemorySpecialMemory) + mc->mddt_usage = MDDT_NONVOLATILE; /* ?? */ + else + mc->mddt_usage = MDDT_PALCODE; + count++; + } + mddt->mddt_cluster_cnt = count; + mddt->mddt_cksum = checksum(mddt, size); +} + +size_t +size_rpb() +{ + return sizeof(struct rpb) + size_mddt(); +} + +void +write_rpb(struct rpb *rpb) +{ + EXTENDED_SYSTEM_INFORMATION sysinfo; + SYSTEM_ID *sysid; + + ReturnExtendedSystemInformation(&sysinfo); + + memset(rpb, 0, sizeof(struct rpb)); + rpb->rpb_phys = 0; /* XXX */ + strcpy(rpb->rpb_magic, "HWRPB"); + rpb->rpb_version = HWRPB_DSRDB_MINVERS; + rpb->rpb_size = sizeof(struct rpb); + rpb->rpb_primary_cpu_id = 0; /* XXX */ + rpb->rpb_page_size = sysinfo.ProcessorPageSize; + rpb->rpb_phys_addr_size = sysinfo.NumberOfPhysicalAddressBits; + rpb->rpb_max_asn = sysinfo.MaximumAddressSpaceNumber; + rpb->rpb_type = ST_EB164; /* XXX */ + rpb->rpb_variation = SV_ST_ALPHAPC164LX_533; /* XXX */ + rpb->rpb_intr_freq = 1024*4096; /* XXX */ + rpb->rpb_cc_freq = 533000000; /* XXX */ + rpb->rpb_memdat_off = sizeof(struct rpb); + write_mddt((struct mddt *)((caddr_t) rpb + rpb->rpb_memdat_off), + size_mddt()); + rpb->rpb_checksum = checksum(rpb, 280); /* only sum first 280 bytes */ +} + +struct rpb * +make_rpb() +{ + EXTENDED_SYSTEM_INFORMATION sysinfo; + struct rpb *rpb; + + ReturnExtendedSystemInformation(&sysinfo); + printf("sysinfo.ProcessorId = %x\n", sysinfo.ProcessorId); + printf("sysinfo.ProcessorRevision = %d\n", sysinfo.ProcessorRevision); + printf("sysinfo.ProcessorPageSize = %d\n", sysinfo.ProcessorPageSize); + printf("sysinfo.NumberOfPhysicalAddressBits = %d\n", sysinfo.NumberOfPhysicalAddressBits); + printf("sysinfo.MaximumAddressSpaceNumber = %d\n", sysinfo.MaximumAddressSpaceNumber); + printf("sysinfo.ProcessorCycleCounterPeriod = %d\n", sysinfo.ProcessorCycleCounterPeriod); + printf("sysinfo.SystemRevision = %d\n", sysinfo.SystemRevision); + printf("sysinfo.SystemSerialNumber = %s\n", sysinfo.SystemSerialNumber); + printf("sysinfo.FirmwareVersion = %s\n", sysinfo.FirmwareVersion); + + rpb = malloc(size_rpb()); + write_rpb(rpb); + return rpb; +} diff --git a/sys/boot/arc/lib/arch/alpha/setjmp.S b/sys/boot/arc/lib/arch/alpha/setjmp.S new file mode 100644 index 0000000..24502a4 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/setjmp.S @@ -0,0 +1,95 @@ +/* $Id$ */ +/* + * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include <machine/asm.h> + + .text +/* + * Kernel setjmp and longjmp. Rather minimalist. + * + * longjmp(label_t *a) + * will generate a "return (1)" from the last call to + * setjmp(label_t *a) + * by restoring registers from the stack, + */ + + .set noreorder + +LEAF(setjmp, 1) + LDGP(pv) + + stq ra, (0 * 8)(a0) /* return address */ + stq s0, (1 * 8)(a0) /* callee-saved registers */ + stq s1, (2 * 8)(a0) + stq s2, (3 * 8)(a0) + stq s3, (4 * 8)(a0) + stq s4, (5 * 8)(a0) + stq s5, (6 * 8)(a0) + stq s6, (7 * 8)(a0) + stq sp, (8 * 8)(a0) + + ldiq t0, 0xbeeffedadeadbabe /* set magic number */ + stq t0, (9 * 8)(a0) + + mov zero, v0 /* return zero */ + RET +END(setjmp) + +LEAF(longjmp, 1) + LDGP(pv) + + ldiq t0, 0xbeeffedadeadbabe /* check magic number */ + ldq t1, (9 * 8)(a0) + cmpeq t0, t1, t0 + beq t0, longjmp_botch /* if bad, punt */ + + ldq ra, (0 * 8)(a0) /* return address */ + ldq s0, (1 * 8)(a0) /* callee-saved registers */ + ldq s1, (2 * 8)(a0) + ldq s2, (3 * 8)(a0) + ldq s3, (4 * 8)(a0) + ldq s4, (5 * 8)(a0) + ldq s5, (6 * 8)(a0) + ldq s6, (7 * 8)(a0) + ldq sp, (8 * 8)(a0) + + ldiq v0, 1 + RET + +longjmp_botch: + lda a0, longjmp_botchmsg + mov ra, a1 + CALL(panic) + call_pal PAL_bugchk + + .data +longjmp_botchmsg: + .asciz "longjmp botch from %p" + .text + +END(longjmp) diff --git a/sys/boot/arc/lib/arch/alpha/start.S b/sys/boot/arc/lib/arch/alpha/start.S new file mode 100644 index 0000000..af038e9 --- /dev/null +++ b/sys/boot/arc/lib/arch/alpha/start.S @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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. + * + * $Id$ + * + */ + +/* + * Based on /sys/boot/alpha/libalpha/start.S + * Copyright (c) 1992 Carnegie Mellon University + */ + +#include <machine/asm.h> + + .text + +#define ENTRY_FRAME 32 + +NESTED(_start, 1, ENTRY_FRAME, ra, 0, 0) + br pv,Lstartgp +Lstartgp: + LDGP(pv) + + lda a0,_edata + lda a1,_end + subq a1,a0,a1 + CALL(bzero) + + lda sp, -8(sp) + stq ra, 0(sp) + + CALL(main) /* transfer to C */ + + ldq ra, 0(sp) + lda sp, 8(sp) + RET /* XXX */ + +XLEAF(_rtt, 0) +XLEAF(halt, 0) + call_pal PAL_halt /* halt if we ever return */ +END(_start) diff --git a/sys/boot/arc/lib/bootinfo.c b/sys/boot/arc/lib/bootinfo.c new file mode 100644 index 0000000..949a93c --- /dev/null +++ b/sys/boot/arc/lib/bootinfo.c @@ -0,0 +1,204 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id: bootinfo.c,v 1.3 1998/10/15 21:55:58 dfr Exp $ + */ + +#include <stand.h> +#include <string.h> +#include <sys/param.h> +#include <sys/reboot.h> +#include <sys/linker.h> +#include <machine/elf.h> +#include <machine/prom.h> +#include <machine/rpb.h> +#include <machine/bootinfo.h> +#include "bootstrap.h" + +/* + * Copy the environment into the load area starting at (addr). + * Each variable is formatted as <name>=<value>, with a single nul + * separating each variable, and a double nul terminating the environment. + */ +vm_offset_t +bi_copyenv(vm_offset_t addr) +{ + struct env_var *ep; + + /* traverse the environment */ + for (ep = environ; ep != NULL; ep = ep->ev_next) { + alpha_copyin(ep->ev_name, addr, strlen(ep->ev_name)); + addr += strlen(ep->ev_name); + alpha_copyin("=", addr, 1); + addr++; + if (ep->ev_value != NULL) { + alpha_copyin(ep->ev_value, addr, strlen(ep->ev_value)); + addr += strlen(ep->ev_value); + } + alpha_copyin("", addr, 1); + addr++; + } + alpha_copyin("", addr, 1); + addr++; + return(addr); +} + +/* + * Copy module-related data into the load area, where it can be + * used as a directory for loaded modules. + * + * Module data is presented in a self-describing format. Each datum + * is preceeded by a 32-bit identifier and a 32-bit size field. + * + * Currently, the following data are saved: + * + * MOD_NAME (variable) module name (string) + * MOD_TYPE (variable) module type (string) + * MOD_ADDR sizeof(vm_offset_t) module load address + * MOD_SIZE sizeof(size_t) module size + * MOD_METADATA (variable) type-specific metadata + */ +#define COPY32(v, a) { \ + u_int32_t x = (v); \ + alpha_copyin(&x, a, sizeof(x)); \ + a += sizeof(x); \ +} + +#define MOD_STR(t, a, s) { \ + COPY32(t, a); \ + COPY32(strlen(s) + 1, a); \ + alpha_copyin(s, a, strlen(s) + 1); \ + a += roundup(strlen(s) + 1, sizeof(u_int64_t));\ +} + +#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s) +#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s) + +#define MOD_VAR(t, a, s) { \ + COPY32(t, a); \ + COPY32(sizeof(s), a); \ + alpha_copyin(&s, a, sizeof(s)); \ + a += roundup(sizeof(s), sizeof(u_int64_t)); \ +} + +#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s) +#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s) + +#define MOD_METADATA(a, mm) { \ + COPY32(MODINFO_METADATA | mm->md_type, a); \ + COPY32(mm->md_size, a); \ + alpha_copyin(mm->md_data, a, mm->md_size); \ + a += roundup(mm->md_size, sizeof(u_int64_t));\ +} + +#define MOD_END(a) { \ + COPY32(MODINFO_END, a); \ + COPY32(0, a); \ +} + +vm_offset_t +bi_copymodules(vm_offset_t addr) +{ + struct loaded_module *mp; + struct module_metadata *md; + + /* start with the first module on the list, should be the kernel */ + for (mp = mod_findmodule(NULL, NULL); mp != NULL; mp = mp->m_next) { + + MOD_NAME(addr, mp->m_name); /* this field must come first */ + MOD_TYPE(addr, mp->m_type); + MOD_ADDR(addr, mp->m_addr); + MOD_SIZE(addr, mp->m_size); + for (md = mp->m_metadata; md != NULL; md = md->md_next) + if (!(md->md_type & MODINFOMD_NOCOPY)) + MOD_METADATA(addr, md); + } + MOD_END(addr); + return(addr); +} + +/* + * Load the information expected by an alpha kernel. + * + * - The kernel environment is copied into kernel space. + * - Module metadata are formatted and placed in kernel space. + */ +int +bi_load(struct bootinfo_v1 *bi, vm_offset_t *ffp_save, + struct loaded_module *mp) +{ + struct loaded_module *xp; + vm_offset_t addr, bootinfo_addr; + u_int pad; + vm_offset_t ssym, esym; + struct module_metadata *md; + + ssym = esym = 0; + if ((md = mod_findmetadata(mp, MODINFOMD_SSYM)) != NULL) + ssym = *((vm_offset_t *)&(md->md_data)); + if ((md = mod_findmetadata(mp, MODINFOMD_ESYM)) != NULL) + esym = *((vm_offset_t *)&(md->md_data)); + if (ssym == 0 || esym == 0) + ssym = esym = 0; /* sanity */ + + bi->ssym = ssym; + bi->esym = esym; + + /* find the last module in the chain */ + addr = 0; + for (xp = mod_findmodule(NULL, NULL); xp != NULL; xp = xp->m_next) { + if (addr < (xp->m_addr + xp->m_size)) + addr = xp->m_addr + xp->m_size; + } + /* pad to a page boundary */ + pad = (u_int)addr & PAGE_MASK; + if (pad != 0) { + pad = PAGE_SIZE - pad; + addr += pad; + } + + /* copy our environment */ + bi->envp = (char *)addr; + addr = bi_copyenv(addr); + + /* pad to a page boundary */ + pad = (u_int)addr & PAGE_MASK; + if (pad != 0) { + pad = PAGE_SIZE - pad; + addr += pad; + } + /* copy module list and metadata */ + bi->modptr = addr; + addr = bi_copymodules(addr); + + /* all done copying stuff in, save end of loaded object space */ + bi->kernend = addr; + + *ffp_save = ALPHA_K0SEG_TO_PHYS((addr + PAGE_MASK) & ~PAGE_MASK) + >> PAGE_SHIFT; + *ffp_save += 2; /* XXX OSF/1 does this, no idea why. */ + + return(0); +} diff --git a/sys/boot/arc/lib/delay.c b/sys/boot/arc/lib/delay.c new file mode 100644 index 0000000..67b0bf6 --- /dev/null +++ b/sys/boot/arc/lib/delay.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +#include <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +delay(int usecs) +{ + StallExecution(usecs); +} diff --git a/sys/boot/arc/lib/devicename.c b/sys/boot/arc/lib/devicename.c new file mode 100644 index 0000000..595c7d2 --- /dev/null +++ b/sys/boot/arc/lib/devicename.c @@ -0,0 +1,236 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id: devicename.c,v 1.3 1998/09/26 10:51:37 dfr Exp $ + */ + +#include <stand.h> +#include <string.h> +#include <sys/disklabel.h> +#include "bootstrap.h" +#include "libarc.h" + +static int arc_parsedev(struct arc_devdesc **dev, const char *devspec, const char **path); + +/* + * Point (dev) at an allocated device specifier for the device matching the + * path in (devspec). If it contains an explicit device specification, + * use that. If not, use the default device. + */ +int +arc_getdev(void **vdev, const char *devspec, const char **path) +{ + struct arc_devdesc **dev = (struct arc_devdesc **)vdev; + int rv; + + /* + * If it looks like this is just a path and no + * device, go with the current device. + */ + if ((devspec == NULL) || + (devspec[0] == '/') || + (strchr(devspec, ':') == NULL)) { + + if (((rv = arc_parsedev(dev, getenv("currdev"), NULL)) == 0) && + (path != NULL)) + *path = devspec; + return(rv); + } + + /* + * Try to parse the device name off the beginning of the devspec + */ + return(arc_parsedev(dev, devspec, path)); +} + +/* + * Point (dev) at an allocated device specifier matching the string version + * at the beginning of (devspec). Return a pointer to the remaining + * text in (path). + * + * In all cases, the beginning of (devspec) is compared to the names + * of known devices in the device switch, and then any following text + * is parsed according to the rules applied to the device type. + * + * For disk-type devices, the syntax is: + * + * disk<unit>[s<slice>][<partition>]: + * + */ +static int +arc_parsedev(struct arc_devdesc **dev, const char *devspec, const char **path) +{ + struct arc_devdesc *idev; + struct devsw *dv; + int i, unit, slice, partition, err; + char *cp; + const char *np; + + /* minimum length check */ + if (strlen(devspec) < 2) + return(EINVAL); + + /* look for a device that matches */ + for (i = 0, dv = NULL; devsw[i] != NULL; i++) { + if (!strncmp(devspec, devsw[i]->dv_name, strlen(devsw[i]->dv_name))) { + dv = devsw[i]; + break; + } + } + + if (dv == NULL) + return(ENOENT); + idev = malloc(sizeof(struct arc_devdesc)); + err = 0; + np = (devspec + strlen(dv->dv_name)); + + switch(dv->dv_type) { + case DEVT_NONE: /* XXX what to do here? Do we care? */ + break; + + case DEVT_DISK: + unit = -1; + slice = -1; + partition = -1; + if (*np && (*np != ':')) { + unit = strtol(np, &cp, 10); /* next comes the unit number */ + if (cp == np) { + err = EUNIT; + goto fail; + } + if (*cp == 's') { /* got a slice number */ + np = cp + 1; + slice = strtol(np, &cp, 10); + if (cp == np) { + err = ESLICE; + goto fail; + } + } + if (*cp && (*cp != ':')) { + partition = *cp - 'a'; /* get a partition number */ + if ((partition < 0) || (partition >= MAXPARTITIONS)) { + err = EPART; + goto fail; + } + cp++; + } + } + if (*cp && (*cp != ':')) { + err = EINVAL; + goto fail; + } + + idev->d_kind.arcdisk.unit = unit; + idev->d_kind.arcdisk.slice = slice; + idev->d_kind.arcdisk.partition = partition; + if (path != NULL) + *path = (*cp == 0) ? cp : cp + 1; + break; + + case DEVT_NET: + unit = 0; + + if (*np && (*np != ':')) { + unit = strtol(np, &cp, 0); /* get unit number if present */ + if (cp == np) { + err = EUNIT; + goto fail; + } + } + if (*cp && (*cp != ':')) { + err = EINVAL; + goto fail; + } + + idev->d_kind.netif.unit = unit; + if (path != NULL) + *path = (*cp == 0) ? cp : cp + 1; + break; + + default: + err = EINVAL; + goto fail; + } + idev->d_dev = dv; + idev->d_type = dv->dv_type; + if (dev == NULL) { + free(idev); + } else { + *dev = idev; + } + return(0); + + fail: + free(idev); + return(err); +} + + +char * +arc_fmtdev(void *vdev) +{ + struct arc_devdesc *dev = (struct arc_devdesc *)vdev; + static char buf[128]; /* XXX device length constant? */ + char *cp; + + switch(dev->d_type) { + case DEVT_NONE: + strcpy(buf, "(no device)"); + break; + + case DEVT_DISK: + cp = buf; + cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.arcdisk.unit); + if (dev->d_kind.arcdisk.slice > 0) + cp += sprintf(cp, "s%d", dev->d_kind.arcdisk.slice); + if (dev->d_kind.arcdisk.partition >= 0) + cp += sprintf(cp, "%c", dev->d_kind.arcdisk.partition + 'a'); + strcat(cp, ":"); + break; + + case DEVT_NET: + sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit); + break; + } + return(buf); +} + + +/* + * Set currdev to suit the value being supplied in (value) + */ +int +arc_setcurrdev(struct env_var *ev, int flags, void *value) +{ + struct arc_devdesc *ncurr; + int rv; + + if ((rv = arc_parsedev(&ncurr, value, NULL)) != 0) + return(rv); + free(ncurr); + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + return(0); +} + diff --git a/sys/boot/arc/lib/elf_freebsd.c b/sys/boot/arc/lib/elf_freebsd.c new file mode 100644 index 0000000..8463759 --- /dev/null +++ b/sys/boot/arc/lib/elf_freebsd.c @@ -0,0 +1,143 @@ +/* $Id: elf_freebsd.c,v 1.6 1998/10/15 21:55:58 dfr Exp $ */ +/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * 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 the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 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. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * @(#)boot.c 8.1 (Berkeley) 6/10/93 + */ + +#include <stand.h> +#include <string.h> + +#include <sys/param.h> +#include <sys/linker.h> +#include <machine/elf.h> +#include <machine/prom.h> +#include <machine/rpb.h> +#include <machine/bootinfo.h> + +#include "bootstrap.h" + +#define _KERNEL + +static int elf_exec(struct loaded_module *amp); +int bi_load(struct bootinfo_v1 *, vm_offset_t *, + struct loaded_module *); + +struct module_format alpha_elf = { elf_loadmodule, elf_exec }; + +vm_offset_t ffp_save, ptbr_save; + +static int +elf_exec(struct loaded_module *mp) +{ +#if 0 + static struct bootinfo_v1 bootinfo_v1; + struct module_metadata *md; + Elf_Ehdr *hdr; + int err; + + if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL) + return(EFTYPE); /* XXX actually EFUCKUP */ + hdr = (Elf_Ehdr *)&(md->md_data); + + /* XXX ffp_save does not appear to be used in the kernel.. */ + bzero(&bootinfo_v1, sizeof(bootinfo_v1)); + err = bi_load(&bootinfo_v1, &ffp_save, mp); + if (err) + return(err); + + /* + * Fill in the bootinfo for the kernel. + */ + strncpy(bootinfo_v1.booted_kernel, mp->m_name, + sizeof(bootinfo_v1.booted_kernel)); + prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags, + sizeof(bootinfo_v1.boot_flags)); + bootinfo_v1.hwrpb = (void *)HWRPB_ADDR; + bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size; + bootinfo_v1.cngetc = NULL; + bootinfo_v1.cnputc = NULL; + bootinfo_v1.cnpollc = NULL; + + printf("Entering %s at 0x%lx...\n", mp->m_name, hdr->e_entry); + exit(0); + closeall(); + alpha_pal_imb(); + (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save, + BOOTINFO_MAGIC, &bootinfo_v1, 1, 0); +#endif +} + + + diff --git a/sys/boot/arc/lib/module.c b/sys/boot/arc/lib/module.c new file mode 100644 index 0000000..367bf0c --- /dev/null +++ b/sys/boot/arc/lib/module.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id: alpha_module.c,v 1.2 1998/08/31 21:10:40 msmith Exp $ + */ + +/* + * alpha-specific module functionality. + * + */ + +#include <stand.h> +#include <string.h> + +#include "bootstrap.h" +#include "libarc.h" + +/* + * Use voodoo to load modules required by current hardware. + */ +int +arc_autoload(void) +{ + /* XXX use PnP to locate stuff here */ + return(0); +} diff --git a/sys/boot/arc/lib/prom.c b/sys/boot/arc/lib/prom.c new file mode 100644 index 0000000..abf2d39 --- /dev/null +++ b/sys/boot/arc/lib/prom.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1999, Stefan Esser <se@freebsd.org> + * 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 unmodified, 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. + * + * $Id$ + * + */ + +#define PROM_E_BOOTED_DEV "XXX1" +#define PROM_E_BOOTED_FILE "XXX2" +#define PROM_E_BOOTED_OSFLAGS "XXX3" +#define PROM_E_TTY_DEV "XXX4" + +u_int64_t +prom_getenv(PROM_E_BOOTED_FILE, bootfile, sizeof(bootfile)) +{ + +} diff --git a/sys/boot/arc/lib/setjmperr.c b/sys/boot/arc/lib/setjmperr.c new file mode 100644 index 0000000..c68ca02 --- /dev/null +++ b/sys/boot/arc/lib/setjmperr.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +#include <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +void +longjmperror() +{ + panic("longjmp botch.\n"); +} diff --git a/sys/boot/arc/lib/time.c b/sys/boot/arc/lib/time.c new file mode 100644 index 0000000..8158970 --- /dev/null +++ b/sys/boot/arc/lib/time.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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 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 AUTHOR 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. + * + * $Id$ + */ + +#include <errno.h> +#include <sys/types.h> +#include "arctypes.h" +#include "arcfuncs.h" + +time_t +time(time_t *tloc) +{ + int secs = GetRelativeTime(); + if (tloc) + *tloc = secs; + return secs; +} diff --git a/sys/boot/arc/loader/Makefile b/sys/boot/arc/loader/Makefile new file mode 100644 index 0000000..8463b88 --- /dev/null +++ b/sys/boot/arc/loader/Makefile @@ -0,0 +1,90 @@ +# $NetBSD: Makefile,v 1.12 1998/02/19 14:18:36 drochner Exp $ + +BASE= loader +PROG= ${BASE} +NOMAN= +NEWVERSWHAT= "ARC disk boot" ${MACHINE_ARCH} + +.PATH: ${.CURDIR}/../common + +# i386-specific bootstrap sources +SRCS+= main.c conf.c + +# Always add MI sources +.PATH: ${.CURDIR}/../../common +.include <${.CURDIR}/../../common/Makefile.inc> +CFLAGS+= -mno-fp-regs +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR} +CFLAGS+= -I${.CURDIR}/../../.. -I. +CFLAGS+= -DLOADER + +CLEANFILES+= vers.c vers.o gensetdefs.o gensetdefs setdef0.o setdef1.o \ + setdefs.h start.o +CLEANFILES+= ${BASE} ${BASE}.sym ${BASE}.list + +CFLAGS+= -Wall + +CFLAGS+= -I${LIBSTANDDIR} +CFLAGS+= -I${.CURDIR}/../include +CRT= start.o +STRIP= +BINDIR?= /boot +LOAD_ADDRESS?= 0xffffffff80900000 + +all: ${BASE}.exe + +vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version + sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} + ${CC} -c vers.c + +${BASE}.exe: ${BASE} ${BASE}.help + elf2exe ${BASE}.sym ${BASE}.exe + +#${BASE}: ${OBJS} ${LIBSTAND} ${LIBARC} ${CRT} vers.o setdef0.o setdef1.o +# ${LD} -o ${BASE}.sym -M -e __start -N -Ttext ${LOAD_ADDRESS} \ +# ${CRT} setdef0.o ${OBJS} setdef1.o \ +# vers.o ${LIBSTAND} ${LIBARC} ${LIBSTAND} >${.OBJDIR}/${BASE}.list + +${BASE}: ${OBJS} ${LIBSTAND} ${LIBARC} ${CRT} vers.o setdef0.o setdef1.o + ${LD} -o ${BASE}.sym -M -N -Ttext ${LOAD_ADDRESS} \ + ${CRT} setdef0.o ${OBJS} setdef1.o \ + vers.o ${LIBSTAND} ${LIBARC} ${LIBSTAND} >${.OBJDIR}/${BASE}.list + +${BASE}.help: help.common help.alpha + cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} + +beforeinstall: +.if exists(${.OBJDIR}/loader.help) + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ + ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot +.else + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ + ${.CURDIR}/${BASE}.help ${DESTDIR}/boot +.endif + +# Other fragments still to be brought in from ../Makfile.booters? +start.o: ${.CURDIR}/../lib/arch/${MACHINE}/start.S + ${CC} -c ${CFLAGS} $< + +setdef0.o: setdefs.h + +setdef1.o: setdefs.h + +machine: + ln -sf ${.CURDIR}/../../../alpha/include machine + +CLEANFILES+= machine setdefs.h gensetdefs ${BASE} ${BASE}.exe loader.help + +.include <bsd.prog.mk> + +setdefs.h: gensetdefs ${OBJS} + @echo Generating linker sets + @./gensetdefs ${OBJS} >setdefs.h + +gensetdefs: gensetdefs.o + ${CC} -static gensetdefs.o -o $@ + +gensetdefs.o: gensetdefs.c + ${CC} -c $< + +beforedepend ${OBJS}: machine diff --git a/sys/boot/arc/loader/conf.c b/sys/boot/arc/loader/conf.c new file mode 100644 index 0000000..1b5384c --- /dev/null +++ b/sys/boot/arc/loader/conf.c @@ -0,0 +1,85 @@ +/* + * $Id: conf.c,v 1.2 1998/08/31 21:10:36 msmith Exp $ + * From $NetBSD: conf.c,v 1.2 1997/03/22 09:03:29 thorpej Exp $ + */ + +/* + * Copyright (c) 1997 + * Matthias Drochner. 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 for the NetBSD Project + * by Matthias Drochner. + * 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 <stand.h> +#include "libarc.h" + +/* + * We could use linker sets for some or all of these, but + * then we would have to control what ended up linked into + * the bootstrap. So it's easier to conditionalise things + * here. + * + * XXX rename these arrays to be consistent and less namespace-hostile + */ + +/* Exported for libstand */ +struct devsw *devsw[] = { + &arcdisk, + NULL +}; + +struct fs_ops *file_system[] = { + &ufs_fsops, + &zipfs_fsops, + NULL +}; + +/* Exported for alpha only */ +/* + * Sort formats so that those that can detect based on arguments + * rather than reading the file go first. + */ +extern struct module_format alpha_elf; + +struct module_format *module_formats[] = { + &alpha_elf, + NULL +}; + +/* + * Consoles + * + * We don't prototype these in libalpha.h because they require + * data structures from bootstrap.h as well. + */ +extern struct console arcconsole; + +struct console *consoles[] = { + &arcconsole, + NULL +}; diff --git a/sys/boot/arc/loader/help.alpha b/sys/boot/arc/loader/help.alpha new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sys/boot/arc/loader/help.alpha diff --git a/sys/boot/arc/loader/main.c b/sys/boot/arc/loader/main.c new file mode 100644 index 0000000..ea0165b --- /dev/null +++ b/sys/boot/arc/loader/main.c @@ -0,0 +1,405 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * Copyright (c) 1998 Doug Rabson <dfr@freebsd.org> + * 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 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 AUTHOR 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. + * + * $Id$ + */ + + +#include <stand.h> +#include <string.h> +#include <setjmp.h> + +#include <sys/param.h> +#include "bootstrap.h" +#include "libarc.h" +#include "arctypes.h" +#include "arcfuncs.h" + +extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[]; + +struct arc_devdesc currdev; /* our current device */ +struct arch_switch archsw; /* MI/MD interface boundary */ + +extern char end[]; +extern void halt(void); + +#define ARCENV_BOOTFILE "OSLoadFilename" + +static char *MemoryTypes[] = { + "MemoryExceptionBlock", + "MemorySystemBlock", + "MemoryFree", + "MemoryBad", + "MemoryLoadedProgram", + "MemoryFirmwareTemporary", + "MemoryFirmwarePermanent", + "MemoryFreeContiguous", + "MemorySpecialMemory", + "MemoryMaximum", +}; + +#ifdef __alpha__ +#define ptob(p) ((p) << 13) +#endif + +unsigned long +memsize() +{ + unsigned long amount = 0; + MEMORY_DESCRIPTOR *desc; + + for (desc = GetMemoryDescriptor(NULL); desc; + desc = GetMemoryDescriptor(desc)) { + printf("%s at %x-%x\n", MemoryTypes[desc->Type], + ptob(desc->BasePage), + ptob(desc->BasePage + desc->PageCount)); + if (desc->Type == MemoryFree + || desc->Type == MemoryFirmwareTemporary) + amount += (desc->PageCount << 13); /* XXX pagesize */ + } + + return amount; +} + +static char *ConfigurationClasses[] = { + "SystemClass", + "ProcessorClass", + "CacheClass", + "AdapterClass", + "ControllerClass", + "PeripheralClass", + "MemoryClass", + "MaximumClass", +}; + + +static char *ConfigurationTypes[] = { + "ArcSystem", + "CentralProcessor", + "FloatingPointProcessor", + "PrimaryIcache", + "PrimaryDcache", + "SecondaryIcache", + "SecondaryDcache", + "SecondaryCache", + "EisaAdapter", + "TcAdapter", + "ScsiAdapter", + "DtiAdapter", + "MultiFunctionAdapter", + "DiskController", + "TapeController", + "CdromController", + "WormController", + "SerialController", + "NetworkController", + "DisplayController", + "ParallelController", + "PointerController", + "KeyboardController", + "AudioController", + "OtherController", + "DiskPeripheral", + "FloppyDiskPeripheral", + "TapePeripheral", + "ModemPeripheral", + "MonitorPeripheral", + "PrinterPeripheral", + "PointerPeripheral", + "KeyboardPeripheral", + "TerminalPeripheral", + "OtherPeripheral", + "LinePeripheral", + "NetworkPeripheral", + "SystemMemory", + "MaximumType", +}; + +static char *ConfigurationTypeCodes[] = { + "ARC", + "CPU", + "FPC", + "PrimaryIcache", + "PrimaryDcache", + "SecondaryIcache", + "SecondaryDcache", + "SecondaryCache", + "eisa", + "TcAdapter", /* XXX ? */ + "scsi", + "DtiAdapter", /* XXX ? */ + "multi", + "disk", + "TapeController", /* XXX ? */ + "CdromController", /* XXX ? */ + "WormController", /* XXX ? */ + "serial", + "NetworkController", /* XXX ? */ + "video", + "par", + "PointerController", /* XXX ? */ + "key", + "AudioController", /* XXX ? */ + "OtherController", /* XXX ? */ + "rdisk", + "fdisk", + "TapePeripheral", /* XXX ? */ + "ModemPeripheral", /* XXX ? */ + "MonitorPeripheral", /* XXX ? */ + "PrinterPeripheral", /* XXX ? */ + "PointerPeripheral", /* XXX ? */ + "keyboard", + "TerminalPeripheral", /* XXX ? */ + "OtherPeripheral", /* XXX ? */ + "LinePeripheral", /* XXX ? */ + "NetworkPeripheral", /* XXX ? */ + "Memory", + "MaximumType" +}; + +static void +indent(int level) +{ + while (level--) + putchar(' '); +} + +void +printconfig(unsigned int level, CONFIGURATION_COMPONENT *component) +{ + CONFIGURATION_COMPONENT *child; + + indent(level); + printf("%s(%s,%d)", + ConfigurationClasses[component->Class], + ConfigurationTypes[component->Type], + component->Key); +#if 1 + if (component->IdentifierLength) + printf("=%d,%s\n", component->IdentifierLength, + ptr(component->Identifier)); + else + putchar('\n'); +#endif + getchar(); + + for (child = GetChild(component); child; child = GetPeer(child)) { + printconfig(level + 2, child); + } +} + +void +dumpdisk(const char *name) +{ + u_int32_t fd, count; + unsigned char buf[512]; + int i, j; + + printf("dump first sector of %s\n", name); + if (Open(name, OpenReadOnly, &fd) != ESUCCESS) { + printf("can't open disk\n"); + return; + } + if (Read(fd, buf, 512, &count) != ESUCCESS) { + printf("can't read from disk\n"); + Close(fd); + return; + } + for (i = 0; i < 16; i++) { + for (j = 0; j < 32; j++) + printf("%02x", buf[i*32 + j]); + putchar('\n'); + } + Close(fd); +} + +void +listdisks(char *path, CONFIGURATION_COMPONENT *component) +{ + CONFIGURATION_COMPONENT *child; + char newpath[80]; + char keybuf[20]; + + if (path == NULL) { + printf("\nARC disk devices:\n"); + newpath[0] = '\0'; + } else { + strcpy(newpath, path); + strcat(newpath, ConfigurationTypeCodes[component->Type]); + sprintf(keybuf, "(%d)", component->Key); + strcat(newpath, keybuf); + } + if (!strcmp(ConfigurationTypeCodes[component->Type], "rdisk") || + !strcmp(ConfigurationTypeCodes[component->Type], "fdisk")) { + printf("%s\n", newpath); + } + for (child = GetChild(component); child; child = GetPeer(child)) { + listdisks(newpath, child); + } +} + +static int exit_code = 0; +jmp_buf exit_env; + +void +exit(int code) +{ + exit_code = 0; + longjmp(exit_env, 1); +} + +int +main(int argc, int argv[], int envp[]) +{ + int i; + char *bootfile; + + if (setjmp(exit_env)) + return exit_code; + + /* + * Initialise the heap as early as possible. Once this is done, + * alloc() is usable. The stack is buried inside us, so this is + * safe. + */ + setheap((void *)end, (void *)(end + 512*1024)); + + /* + * XXX Chicken-and-egg problem; we want to have console output + * early, but some console attributes may depend on reading from + * eg. the boot device, which we can't do yet. We can use + * printf() etc. once this is done. + */ + cons_probe(); + +#if 0 + printconfig(0, GetChild(NULL)); + dumpdisk("scsi(0)disk(0)rdisk(0)partition(0)"); +#endif + listdisks(NULL, GetChild(NULL)); + printf("\n"); + + make_rpb(); + + /* + * Initialise the block cache + */ + bcache_init(32, 512); /* 16k XXX tune this */ + + /* + * March through the device switch probing for things. + */ + for (i = 0; devsw[i] != NULL; i++) + if (devsw[i]->dv_init != NULL) + (devsw[i]->dv_init)(); + + printf("\n"); + printf("%s, Revision %s\n", bootprog_name, bootprog_rev); + printf("(%s, %s)\n", bootprog_maker, bootprog_date); + printf("Memory: %ld k\n", memsize() / 1024); + + /* We're booting from an SRM disk, try to spiff this */ + /* XXX presumes that biosdisk is first in devsw */ + currdev.d_dev = devsw[0]; + currdev.d_type = currdev.d_dev->dv_type; + currdev.d_kind.arcdisk.unit = 0; + /* XXX should be able to detect this, default to autoprobe */ + currdev.d_kind.arcdisk.slice = -1; + /* default to 'a' */ + currdev.d_kind.arcdisk.partition = 0; + + /* Create arc-specific variables */ + bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE); + if (bootfile) + setenv("bootfile", bootfile, 1); + + env_setenv("currdev", EV_VOLATILE, + arc_fmtdev(&currdev), arc_setcurrdev, env_nounset); + env_setenv("loaddev", EV_VOLATILE, + arc_fmtdev(&currdev), env_noset, env_nounset); + setenv("LINES", "24", 1); /* optional */ + + archsw.arch_autoload = arc_autoload; + archsw.arch_getdev = arc_getdev; + archsw.arch_copyin = arc_copyin; + archsw.arch_copyout = arc_copyout; + archsw.arch_readin = arc_readin; + + interact(); /* doesn't return */ + + return 0; /* keep compiler happy */ +} + +COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); + +static int +command_reboot(int argc, char *argv[]) +{ + + printf("Rebooting...\n"); + delay(1000000); + FwReboot(); + /* Note: we shouldn't get to this point! */ + panic("Reboot failed!"); + exit(0); +} + +COMMAND_SET(quit, "quit", "exit the loader", command_quit); + +static int +command_quit(int argc, char *argv[]) +{ + exit(0); + return(CMD_OK); +} + +#if 0 + +COMMAND_SET(stack, "stack", "show stack usage", command_stack); + +static int +command_stack(int argc, char *argv[]) +{ + char *cp; + + for (cp = &stackbase; cp < &stacktop; cp++) + if (*cp != 0) + break; + + printf("%d bytes of stack used\n", &stacktop - cp); + return(CMD_OK); +} + +#endif + +COMMAND_SET(heap, "heap", "show heap usage", command_heap); + +static int +command_heap(int argc, char *argv[]) +{ + printf("heap base at %p, top at %p, used %ld\n", end, sbrk(0), sbrk(0) - end); + return(CMD_OK); +} diff --git a/sys/boot/arc/loader/setdef0.c b/sys/boot/arc/loader/setdef0.c new file mode 100644 index 0000000..79874ea --- /dev/null +++ b/sys/boot/arc/loader/setdef0.c @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 1997 John D. Polstra + * 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 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 AUTHOR 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. + * + * $Id: setdef0.c,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ + */ + +#ifdef __ELF__ + +#include <sys/param.h> +#include <sys/kernel.h> + +/* + * DEFINE_SET creates the section and label for a set, and emits the + * count word at the front of it. + */ +#define DEFINE_SET(set, count) \ + __asm__(".section .set." #set ",\"aw\""); \ + __asm__(".globl " #set); \ + __asm__(".type " #set ",@object"); \ + __asm__(".p2align 3"); \ + __asm__(#set ":"); \ + __asm__(".quad " #count); \ + __asm__(".previous") + +#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ + +#endif /* __ELF__ */ diff --git a/sys/boot/arc/loader/setdef1.c b/sys/boot/arc/loader/setdef1.c new file mode 100644 index 0000000..9fffaf7 --- /dev/null +++ b/sys/boot/arc/loader/setdef1.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 1997 John D. Polstra + * 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 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 AUTHOR 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. + * + * $Id: setdef1.c,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ + */ + +#ifdef __ELF__ + +/* + * DEFINE_SET emits the NULL terminator for a set. + */ +#define DEFINE_SET(set, count) \ + __asm__(".section .set." #set ",\"aw\""); \ + __asm__(".quad 0"); \ + __asm__(".previous") + +#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */ + +#endif /* __ELF__ */ diff --git a/sys/boot/arc/loader/version b/sys/boot/arc/loader/version new file mode 100644 index 0000000..23262b9 --- /dev/null +++ b/sys/boot/arc/loader/version @@ -0,0 +1,7 @@ +$Id: version,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ + +NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this +file is important. Make sure the current version number is on line 6. + +0.1: Initial i386 version, germinated from the NetBSD i386 + standalone, but enormously modified. |