summaryrefslogtreecommitdiffstats
path: root/sys/boot/ia64
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2003-02-01 22:50:09 +0000
committermarcel <marcel@FreeBSD.org>2003-02-01 22:50:09 +0000
commit389e4c3a2a331c3d7194d0a3252e266dd42daa80 (patch)
treeaeaa0efb42081601d640cc4f467d7de7fc56a1df /sys/boot/ia64
parent785fe397ccfcda0950251b71412f7936ad68b224 (diff)
downloadFreeBSD-src-389e4c3a2a331c3d7194d0a3252e266dd42daa80.zip
FreeBSD-src-389e4c3a2a331c3d7194d0a3252e266dd42daa80.tar.gz
Remove special casing for running in the simulator from the kernel
and instead add platform, firmware and EFI stubs to the loader. The net effect of this change is that besides a special console and disk driver, the kernel has no knowledge of the simulator. This has the following advantages: o Simulator support is much harder to break, o It's easier to make use of more feature complete simulators. This would only need a change in the simulator specific loader, o Running SMP kernels within the simulator. Note that ski at this time does not simulate IPIs, so there's no way to start APs. The platform, firmware and EFI stubs describe the following hardware: o 4 CPU Itanium, o 128 MB RAM within the 4GB address space, o 64 MB RAM above the 4GB address space. NOTE: The stubs in the skiloader describe a machine that should in parts be defined by the simulator. Things like processor interrupt block and AP wakeup vector cannot be choosen at random because they require interpretation by the simulator. Currently the simulator is ignorant of this. This change introduces an unofficial SSC call SSC_SAL_SET_VECTORS which is ignored by the simulator. Tested with: ski (version 0.943 for linux)
Diffstat (limited to 'sys/boot/ia64')
-rw-r--r--sys/boot/ia64/Makefile.inc2
-rw-r--r--sys/boot/ia64/libski/Makefile1
-rw-r--r--sys/boot/ia64/libski/acpi_stub.c193
-rw-r--r--sys/boot/ia64/libski/bootinfo.c26
-rw-r--r--sys/boot/ia64/libski/efi_stub.c267
-rw-r--r--sys/boot/ia64/libski/elf_freebsd.c4
-rw-r--r--sys/boot/ia64/libski/libski.h1
-rw-r--r--sys/boot/ia64/libski/pal_stub.S65
-rw-r--r--sys/boot/ia64/libski/pal_stub.s65
-rw-r--r--sys/boot/ia64/libski/sal_stub.c117
-rw-r--r--sys/boot/ia64/libski/ssc.c12
-rw-r--r--sys/boot/ia64/ski/acpi_stub.c193
-rw-r--r--sys/boot/ia64/ski/bootinfo.c26
-rw-r--r--sys/boot/ia64/ski/efi_stub.c267
-rw-r--r--sys/boot/ia64/ski/elf_freebsd.c4
-rw-r--r--sys/boot/ia64/ski/libski.h1
-rw-r--r--sys/boot/ia64/ski/pal_stub.S65
-rw-r--r--sys/boot/ia64/ski/sal_stub.c117
-rw-r--r--sys/boot/ia64/ski/ssc.c12
19 files changed, 1385 insertions, 53 deletions
diff --git a/sys/boot/ia64/Makefile.inc b/sys/boot/ia64/Makefile.inc
index 81a6d5a..3000e04 100644
--- a/sys/boot/ia64/Makefile.inc
+++ b/sys/boot/ia64/Makefile.inc
@@ -1,4 +1,4 @@
# $FreeBSD$
# Options used when building standalone components
-CFLAGS+= -ffreestanding
+CFLAGS+= -ffreestanding -fshort-wchar -Wformat
diff --git a/sys/boot/ia64/libski/Makefile b/sys/boot/ia64/libski/Makefile
index b6da2c8..92a70a0 100644
--- a/sys/boot/ia64/libski/Makefile
+++ b/sys/boot/ia64/libski/Makefile
@@ -5,6 +5,7 @@ INTERNALLIB= true
SRCS= skiconsole.c time.c copy.c devicename.c module.c exit.c
SRCS+= delay.c skifs.c elf_freebsd.c bootinfo.c ssc.c
+SRCS+= acpi_stub.c efi_stub.c pal_stub.s sal_stub.c
CFLAGS+= -ffreestanding -fpic -g
CFLAGS+= -I${.CURDIR}/../include
diff --git a/sys/boot/ia64/libski/acpi_stub.c b/sys/boot/ia64/libski/acpi_stub.c
new file mode 100644
index 0000000..3187925
--- /dev/null
+++ b/sys/boot/ia64/libski/acpi_stub.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <contrib/dev/acpica/acpi.h>
+
+#define APIC_IO_SAPIC 6
+#define APIC_LOCAL_SAPIC 7
+
+#pragma pack(1)
+
+typedef struct /* LOCAL SAPIC */
+{
+ APIC_HEADER Header;
+ UINT8 ProcessorId; /* ACPI processor id */
+ UINT8 LocalSapicId; /* Processor local SAPIC id */
+ UINT8 LocalSapicEid; /* Processor local SAPIC eid */
+ UINT8 Reserved[3];
+ UINT32 ProcessorEnabled: 1;
+ UINT32 FlagsReserved: 31;
+} LOCAL_SAPIC;
+
+typedef struct /* IO SAPIC */
+{
+ APIC_HEADER Header;
+ UINT8 IoSapicId; /* I/O SAPIC ID */
+ UINT8 Reserved; /* reserved - must be zero */
+ UINT32 Vector; /* interrupt base */
+ UINT64 IoSapicAddress; /* SAPIC's physical address */
+} IO_SAPIC;
+
+/*
+ */
+
+struct {
+ APIC_TABLE Header;
+ LOCAL_SAPIC cpu0;
+ LOCAL_SAPIC cpu1;
+ LOCAL_SAPIC cpu2;
+ LOCAL_SAPIC cpu3;
+ IO_SAPIC sapic;
+} apic = {
+ /* Header. */
+ {
+ {
+ APIC_SIG, /* Signature. */
+ sizeof(apic), /* Length of table. */
+ 0, /* ACPI minor revision. */
+ 0, /* XXX checksum. */
+ "FBSD", /* OEM Id. */
+ "SKI", /* OEM table Id. */
+ 0, /* OEM revision. */
+ "FBSD", /* ASL compiler Id. */
+ 0 /* ASL revision. */
+ },
+ 0xfee00000,
+ },
+ /* cpu0. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu0) /* Length. */
+ },
+ 0, /* ACPI processor id */
+ 0, /* Processor local SAPIC id */
+ 0, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 1, /* FL: Enabled. */
+ },
+ /* cpu1. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu1) /* Length. */
+ },
+ 1, /* ACPI processor id */
+ 0, /* Processor local SAPIC id */
+ 1, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 1, /* FL: Enabled. */
+ },
+ /* cpu2. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu2) /* Length. */
+ },
+ 2, /* ACPI processor id */
+ 1, /* Processor local SAPIC id */
+ 0, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 0, /* FL: Enabled. */
+ },
+ /* cpu3. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu3) /* Length. */
+ },
+ 3, /* ACPI processor id */
+ 1, /* Processor local SAPIC id */
+ 1, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 0, /* FL: Enabled. */
+ },
+ /* sapic. */
+ {
+ {
+ APIC_IO_SAPIC, /* Type. */
+ sizeof(apic.sapic) /* Length. */
+ },
+ 4, /* IO SAPIC id. */
+ 0,
+ 16, /* Interrupt base. */
+ 0xfec00000 /* IO SAPIC address. */
+ }
+};
+
+struct {
+ ACPI_TABLE_HEADER Header;
+ UINT64 apic_tbl;
+} xsdt = {
+ {
+ XSDT_SIG, /* Signature. */
+ sizeof(xsdt), /* Length of table. */
+ 0, /* ACPI minor revision. */
+ 0, /* XXX checksum. */
+ "FBSD", /* OEM Id. */
+ "SKI", /* OEM table Id. */
+ 0, /* OEM revision. */
+ "FBSD", /* ASL compiler Id. */
+ 0 /* ASL revision. */
+ },
+ NULL /* XXX APIC table address. */
+};
+
+RSDP_DESCRIPTOR acpi_root = {
+ RSDP_SIG,
+ 0, /* XXX checksum. */
+ "FBSD",
+ 2, /* ACPI Rev 2.0. */
+ NULL,
+ sizeof(xsdt), /* XSDT length. */
+ NULL, /* XXX PA of XSDT. */
+ 0, /* XXX Extended checksum. */
+};
+
+static void
+cksum(void *addr, int sz, UINT8 *sum)
+{
+ UINT8 *p, s;
+
+ p = addr;
+ s = 0;
+ while (sz--)
+ s += *p++;
+ *sum = -s;
+}
+
+void
+acpi_stub_init(void)
+{
+ acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
+ cksum(&acpi_root, 20, &acpi_root.Checksum);
+ cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
+
+ xsdt.apic_tbl = (UINT32)&apic;
+ cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
+}
diff --git a/sys/boot/ia64/libski/bootinfo.c b/sys/boot/ia64/libski/bootinfo.c
index 0a18ec7..91f691a 100644
--- a/sys/boot/ia64/libski/bootinfo.c
+++ b/sys/boot/ia64/libski/bootinfo.c
@@ -34,8 +34,6 @@
#include <machine/elf.h>
#include <machine/bootinfo.h>
-#include <efi.h>
-
#include "bootstrap.h"
/*
@@ -60,6 +58,7 @@ static struct
};
extern char *ski_fmtdev(void *vdev);
+extern int ski_init_stubs(struct bootinfo *);
int
bi_getboothowto(char *kargs)
@@ -250,7 +249,6 @@ bi_load(struct bootinfo *bi, struct preloaded_file *fp, char *args)
char *kernelname;
vm_offset_t ssym, esym;
struct file_metadata *md;
- EFI_MEMORY_DESCRIPTOR *memp;
/*
* Version 1 bootinfo.
@@ -320,25 +318,5 @@ bi_load(struct bootinfo *bi, struct preloaded_file *fp, char *args)
/* all done copying stuff in, save end of loaded object space */
bi->bi_kernend = addr;
- /* Describe the SKI memory map. */
- bi->bi_memmap = (u_int64_t)(bi + 1);
- bi->bi_memmap_size = 2 * sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_version = 1;
-
- memp = (EFI_MEMORY_DESCRIPTOR *) bi->bi_memmap;
-
- memp[0].Type = EfiConventionalMemory;
- memp[0].PhysicalStart = 2L*1024*1024;
- memp[0].VirtualStart = 0;
- memp[0].NumberOfPages = (64L*1024*1024)>>12;
- memp[0].Attribute = EFI_MEMORY_WB;
-
- memp[1].Type = EfiMemoryMappedIOPortSpace;
- memp[1].PhysicalStart = 0xffffc000000;
- memp[1].VirtualStart = 0;
- memp[1].NumberOfPages = (64L*1024*1024)>>12;
- memp[1].Attribute = EFI_MEMORY_UC;
-
- return(0);
+ return (ski_init_stubs(bi));
}
diff --git a/sys/boot/ia64/libski/efi_stub.c b/sys/boot/ia64/libski/efi_stub.c
new file mode 100644
index 0000000..36f72c3
--- /dev/null
+++ b/sys/boot/ia64/libski/efi_stub.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <machine/bootinfo.h>
+#include <efi.h>
+#include <stand.h>
+#include "libski.h"
+
+extern void acpi_root;
+extern void sal_systab;
+
+extern void acpi_stub_init(void);
+extern void sal_stub_init(void);
+
+EFI_CONFIGURATION_TABLE efi_cfgtab[] = {
+ { ACPI_20_TABLE_GUID, &acpi_root },
+ { SAL_SYSTEM_TABLE_GUID, &sal_systab }
+};
+
+
+static EFI_STATUS GetTime(EFI_TIME *, EFI_TIME_CAPABILITIES *);
+static EFI_STATUS SetTime(EFI_TIME *);
+static EFI_STATUS GetWakeupTime(BOOLEAN *, BOOLEAN *, EFI_TIME *);
+static EFI_STATUS SetWakeupTime(BOOLEAN, EFI_TIME *);
+
+static EFI_STATUS SetVirtualAddressMap(UINTN, UINTN, UINT32,
+ EFI_MEMORY_DESCRIPTOR*);
+static EFI_STATUS ConvertPointer(UINTN, VOID **);
+
+static EFI_STATUS GetVariable(CHAR16 *, EFI_GUID *, UINT32 *, UINTN *, VOID *);
+static EFI_STATUS GetNextVariableName(UINTN *, CHAR16 *, EFI_GUID *);
+static EFI_STATUS SetVariable(CHAR16 *, EFI_GUID *, UINT32, UINTN, VOID *);
+
+static EFI_STATUS GetNextHighMonotonicCount(UINT32 *);
+static EFI_STATUS ResetSystem(EFI_RESET_TYPE, EFI_STATUS, UINTN, CHAR16 *);
+
+EFI_RUNTIME_SERVICES efi_rttab = {
+ /* Header. */
+ { EFI_RUNTIME_SERVICES_SIGNATURE,
+ EFI_RUNTIME_SERVICES_REVISION,
+ 0, /* XXX HeaderSize */
+ 0, /* XXX CRC32 */
+ },
+
+ /* Time services */
+ GetTime,
+ SetTime,
+ GetWakeupTime,
+ SetWakeupTime,
+
+ /* Virtual memory services */
+ SetVirtualAddressMap,
+ ConvertPointer,
+
+ /* Variable services */
+ GetVariable,
+ GetNextVariableName,
+ SetVariable,
+
+ /* Misc */
+ GetNextHighMonotonicCount,
+ ResetSystem
+};
+
+EFI_SYSTEM_TABLE efi_systab = {
+ /* Header. */
+ { EFI_SYSTEM_TABLE_SIGNATURE,
+ EFI_SYSTEM_TABLE_REVISION,
+ 0, /* XXX HeaderSize */
+ 0, /* XXX CRC32 */
+ },
+
+ /* Firmware info. */
+ L"FreeBSD", 0,
+
+ /* Console stuff. */
+ NULL, NULL,
+ NULL, NULL,
+ NULL, NULL,
+
+ /* Services (runtime first). */
+ &efi_rttab,
+ NULL,
+
+ /* Configuration tables. */
+ sizeof(efi_cfgtab)/sizeof(EFI_CONFIGURATION_TABLE),
+ efi_cfgtab
+};
+
+static EFI_STATUS
+unsupported(const char *func)
+{
+ printf("EFI: %s not supported\n", func);
+ return (EFI_UNSUPPORTED);
+}
+
+static EFI_STATUS
+GetTime(EFI_TIME *time, EFI_TIME_CAPABILITIES *caps)
+{
+ UINT32 comps[8];
+
+ ssc((UINT64)comps, 0, 0, 0, SSC_GET_RTC);
+ time->Year = comps[0] + 1900;
+ time->Month = comps[1] + 1;
+ time->Day = comps[2];
+ time->Hour = comps[3];
+ time->Minute = comps[4];
+ time->Second = comps[5];
+ time->Pad1 = time->Pad2 = 0;
+ time->Nanosecond = 0;
+ time->TimeZone = 0;
+ time->Daylight = 0;
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+SetTime(EFI_TIME *time)
+{
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+GetWakeupTime(BOOLEAN *enabled, BOOLEAN *pending, EFI_TIME *time)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+SetWakeupTime(BOOLEAN enable, EFI_TIME *time)
+{
+ return (unsupported(__func__));
+}
+
+static void
+Reloc(void *addr, UINT64 delta)
+{
+ UINT64 **fpp = addr;
+
+ *fpp[0] += delta;
+ *fpp[1] += delta;
+ *fpp += delta >> 3;
+}
+
+static EFI_STATUS
+SetVirtualAddressMap(UINTN mapsz, UINTN descsz, UINT32 version,
+ EFI_MEMORY_DESCRIPTOR *memmap)
+{
+ UINT64 delta;
+
+ delta = memmap->VirtualStart - memmap->PhysicalStart;
+ Reloc(&efi_rttab.GetTime, delta);
+ Reloc(&efi_rttab.SetTime, delta);
+ return (EFI_SUCCESS); /* Hah... */
+}
+
+static EFI_STATUS
+ConvertPointer(UINTN debug, VOID **addr)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 *attrs, UINTN *datasz,
+ VOID *data)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetNextVariableName(UINTN *namesz, CHAR16 *name, EFI_GUID *vendor)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+SetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 attrs, UINTN datasz,
+ VOID *data)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetNextHighMonotonicCount(UINT32 *high)
+{
+ static UINT32 counter = 0;
+
+ *high = counter++;
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+ResetSystem(EFI_RESET_TYPE type, EFI_STATUS status, UINTN datasz,
+ CHAR16 *data)
+{
+ return (unsupported(__func__));
+}
+
+int
+ski_init_stubs(struct bootinfo *bi)
+{
+ EFI_MEMORY_DESCRIPTOR *memp;
+
+ /* Describe the SKI memory map. */
+ bi->bi_memmap = (u_int64_t)(bi + 1);
+ bi->bi_memmap_size = 4 * sizeof(EFI_MEMORY_DESCRIPTOR);
+ bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR);
+ bi->bi_memdesc_version = 1;
+
+ memp = (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap;
+
+ memp[0].Type = EfiPalCode;
+ memp[0].PhysicalStart = 0x100000;
+ memp[0].VirtualStart = 0;
+ memp[0].NumberOfPages = (4L*1024*1024)>>12;
+ memp[0].Attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME;
+
+ memp[1].Type = EfiConventionalMemory;
+ memp[1].PhysicalStart = 5L*1024*1024;
+ memp[1].VirtualStart = 0;
+ memp[1].NumberOfPages = (128L*1024*1024)>>12;
+ memp[1].Attribute = EFI_MEMORY_WB;
+
+ memp[2].Type = EfiConventionalMemory;
+ memp[2].PhysicalStart = 4L*1024*1024*1024;
+ memp[2].VirtualStart = 0;
+ memp[2].NumberOfPages = (64L*1024*1024)>>12;
+ memp[2].Attribute = EFI_MEMORY_WB;
+
+ memp[3].Type = EfiMemoryMappedIOPortSpace;
+ memp[3].PhysicalStart = 0xffffc000000;
+ memp[3].VirtualStart = 0;
+ memp[3].NumberOfPages = (64L*1024*1024)>>12;
+ memp[3].Attribute = EFI_MEMORY_UC;
+
+ bi->bi_systab = (u_int64_t)&efi_systab;
+
+ sal_stub_init();
+ acpi_stub_init();
+
+ return (0);
+}
diff --git a/sys/boot/ia64/libski/elf_freebsd.c b/sys/boot/ia64/libski/elf_freebsd.c
index 461ef12..e72a52d 100644
--- a/sys/boot/ia64/libski/elf_freebsd.c
+++ b/sys/boot/ia64/libski/elf_freebsd.c
@@ -130,6 +130,8 @@ struct ia64_pte {
u_int64_t pte_ig :11; /* bits 53..63 */
};
+static struct bootinfo bootinfo;
+
void
enter_kernel(const char* filename, u_int64_t start, struct bootinfo *bi)
{
@@ -167,7 +169,7 @@ elf_exec(struct preloaded_file *fp)
* Ugly hack, similar to linux. Dump the bootinfo into a
* special page reserved in the link map.
*/
- bi = (struct bootinfo *) 0x508000;
+ bi = &bootinfo;
bzero(bi, sizeof(struct bootinfo));
bi_load(bi, fp);
diff --git a/sys/boot/ia64/libski/libski.h b/sys/boot/ia64/libski/libski.h
index bb3f1dd..043177c 100644
--- a/sys/boot/ia64/libski/libski.h
+++ b/sys/boot/ia64/libski/libski.h
@@ -90,6 +90,7 @@ extern int bi_load(struct bootinfo *, struct preloaded_file *);
#define SSC_GET_RTC 65
#define SSC_EXIT 66
#define SSC_LOAD_SYMBOLS 69
+#define SSC_SAL_SET_VECTORS 120
u_int64_t ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3,
int which);
diff --git a/sys/boot/ia64/libski/pal_stub.S b/sys/boot/ia64/libski/pal_stub.S
new file mode 100644
index 0000000..e67204c
--- /dev/null
+++ b/sys/boot/ia64/libski/pal_stub.S
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * Copyright (c) 2001 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+
+ .text
+ENTRY(PalProc, 0)
+ cmp.eq p6,p0=6,r28 // PAL_PTCE_INFO
+(p6) br.cond.dptk pal_ptce_info
+ ;;
+ cmp.eq p6,p0=8,r28 // PAL_VM_SUMMARY
+(p6) br.cond.dptk pal_vm_summary
+ ;;
+ cmp.eq p6,p0=14,r28 // PAL_FREQ_RATIOS
+(p6) br.cond.dptk pal_freq_ratios
+ ;;
+ mov r15=66 // EXIT
+ break.i 0x80000 // SSC
+ ;;
+pal_ptce_info:
+ mov r8=0
+ mov r9=0 // base
+ movl r10=0x0000000100000001 // loop counts (outer|inner)
+ mov r11=0x0000000000000000 // loop strides (outer|inner)
+ br.sptk b0
+pal_vm_summary:
+ mov r8=0
+ movl r9=(8<<40)|(8<<32) // VM info 1
+ mov r10=(18<<8)|(41<<0) // VM info 2
+ mov r11=0
+ br.sptk b0
+pal_freq_ratios:
+ mov r8=0
+ movl r9=0x0000000B00000002 // processor ratio 11/2
+ movl r10=0x0000000100000001 // bus ratio 1/1
+ movl r11=0x0000000B00000002 // ITC ratio 11/2
+ br.sptk b0
+END(PalProc)
diff --git a/sys/boot/ia64/libski/pal_stub.s b/sys/boot/ia64/libski/pal_stub.s
new file mode 100644
index 0000000..e67204c
--- /dev/null
+++ b/sys/boot/ia64/libski/pal_stub.s
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * Copyright (c) 2001 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+
+ .text
+ENTRY(PalProc, 0)
+ cmp.eq p6,p0=6,r28 // PAL_PTCE_INFO
+(p6) br.cond.dptk pal_ptce_info
+ ;;
+ cmp.eq p6,p0=8,r28 // PAL_VM_SUMMARY
+(p6) br.cond.dptk pal_vm_summary
+ ;;
+ cmp.eq p6,p0=14,r28 // PAL_FREQ_RATIOS
+(p6) br.cond.dptk pal_freq_ratios
+ ;;
+ mov r15=66 // EXIT
+ break.i 0x80000 // SSC
+ ;;
+pal_ptce_info:
+ mov r8=0
+ mov r9=0 // base
+ movl r10=0x0000000100000001 // loop counts (outer|inner)
+ mov r11=0x0000000000000000 // loop strides (outer|inner)
+ br.sptk b0
+pal_vm_summary:
+ mov r8=0
+ movl r9=(8<<40)|(8<<32) // VM info 1
+ mov r10=(18<<8)|(41<<0) // VM info 2
+ mov r11=0
+ br.sptk b0
+pal_freq_ratios:
+ mov r8=0
+ movl r9=0x0000000B00000002 // processor ratio 11/2
+ movl r10=0x0000000100000001 // bus ratio 1/1
+ movl r11=0x0000000B00000002 // ITC ratio 11/2
+ br.sptk b0
+END(PalProc)
diff --git a/sys/boot/ia64/libski/sal_stub.c b/sys/boot/ia64/libski/sal_stub.c
new file mode 100644
index 0000000..caa6671
--- /dev/null
+++ b/sys/boot/ia64/libski/sal_stub.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <machine/md_var.h>
+#include <machine/sal.h>
+#include <stand.h>
+#include "libski.h"
+
+extern void PalProc(void);
+static sal_entry_t SalProc;
+
+struct {
+ struct sal_system_table header;
+ struct sal_entrypoint_descriptor entry;
+ struct sal_ap_wakeup_descriptor wakeup;
+} sal_systab = {
+ /* Header. */
+ {
+ SAL_SIGNATURE,
+ sizeof(sal_systab),
+ { 00, 03 }, /* Revision 3.0. */
+ 2, /* Number of decsriptors. */
+ 0, /* XXX checksum. */
+ { 0 },
+ { 00, 00 }, /* XXX SAL_A version. */
+ { 00, 00 }, /* XXX SAL_B version. */
+ "FreeBSD",
+ "Ski loader",
+ { 0 }
+ },
+ /* Entrypoint. */
+ {
+ 0, /* Type=entrypoint descr. */
+ { 0 },
+ 0, /* XXX PalProc. */
+ 0, /* XXX SalProc. */
+ 0, /* XXX SalProc GP. */
+ { 0 }
+ },
+ /* AP wakeup. */
+ {
+ 5, /* Type=AP wakeup descr. */
+ 0, /* External interrupt. */
+ { 0 },
+ 255 /* Wakeup vector. */
+ }
+};
+
+static inline void
+puts(const char *s)
+{
+ s = (const char *)((7UL << 61) | (u_long)s);
+ while (*s)
+ ski_cons_putchar(*s++);
+}
+
+static struct ia64_sal_result
+SalProc(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4, u_int64_t a5,
+ u_int64_t a6, u_int64_t a7, u_int64_t a8)
+{
+ struct ia64_sal_result res;
+
+ res.sal_status = -3;
+ res.sal_result[0] = 0;
+ res.sal_result[1] = 0;
+ res.sal_result[2] = 0;
+
+ if (a1 == SAL_FREQ_BASE) {
+ res.sal_status = 0;
+ res.sal_result[0] = 133338184;
+ } else if (a1 == SAL_SET_VECTORS) {
+ /* XXX unofficial SSC function. */
+ ssc(a2, a3, a4, a5, SSC_SAL_SET_VECTORS);
+ } else if (a1 != SAL_GET_STATE_INFO_SIZE) {
+ puts("SAL: unimplemented function called\n");
+ }
+
+ return (res);
+}
+
+void
+sal_stub_init(void)
+{
+ struct ia64_fdesc *fd;
+
+ fd = (void*)PalProc;
+ sal_systab.entry.sale_pal_proc = fd->func;
+ fd = (void*)SalProc;
+ sal_systab.entry.sale_sal_proc = fd->func;
+ sal_systab.entry.sale_sal_gp = fd->gp;
+}
diff --git a/sys/boot/ia64/libski/ssc.c b/sys/boot/ia64/libski/ssc.c
index 11a91c8..e3e9eb2 100644
--- a/sys/boot/ia64/libski/ssc.c
+++ b/sys/boot/ia64/libski/ssc.c
@@ -29,14 +29,24 @@
#include <stand.h>
#include "libski.h"
+/*
+ * Ugh... Work around a bug in the Linux version of ski for SSC_GET_RTC. The
+ * PSR.dt register is not preserved properly and causes further memory
+ * references to be done without translation. All we need to do is preserve
+ * PSR.dt across the SSC call. We do this by saving and restoring psr.l
+ * completely.
+ */
u_int64_t
ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which)
{
+ register u_int64_t psr;
register u_int64_t ret0 __asm("r8");
+ __asm __volatile("mov %0=psr;;" : "=r"(psr));
__asm __volatile("mov r15=%1\n\t"
- "break 0x80000"
+ "break 0x80000;;"
: "=r"(ret0)
: "r"(which), "r"(in0), "r"(in1), "r"(in2), "r"(in3));
+ __asm __volatile("mov psr.l=%0;; srlz.d" :: "r"(psr));
return ret0;
}
diff --git a/sys/boot/ia64/ski/acpi_stub.c b/sys/boot/ia64/ski/acpi_stub.c
new file mode 100644
index 0000000..3187925
--- /dev/null
+++ b/sys/boot/ia64/ski/acpi_stub.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <contrib/dev/acpica/acpi.h>
+
+#define APIC_IO_SAPIC 6
+#define APIC_LOCAL_SAPIC 7
+
+#pragma pack(1)
+
+typedef struct /* LOCAL SAPIC */
+{
+ APIC_HEADER Header;
+ UINT8 ProcessorId; /* ACPI processor id */
+ UINT8 LocalSapicId; /* Processor local SAPIC id */
+ UINT8 LocalSapicEid; /* Processor local SAPIC eid */
+ UINT8 Reserved[3];
+ UINT32 ProcessorEnabled: 1;
+ UINT32 FlagsReserved: 31;
+} LOCAL_SAPIC;
+
+typedef struct /* IO SAPIC */
+{
+ APIC_HEADER Header;
+ UINT8 IoSapicId; /* I/O SAPIC ID */
+ UINT8 Reserved; /* reserved - must be zero */
+ UINT32 Vector; /* interrupt base */
+ UINT64 IoSapicAddress; /* SAPIC's physical address */
+} IO_SAPIC;
+
+/*
+ */
+
+struct {
+ APIC_TABLE Header;
+ LOCAL_SAPIC cpu0;
+ LOCAL_SAPIC cpu1;
+ LOCAL_SAPIC cpu2;
+ LOCAL_SAPIC cpu3;
+ IO_SAPIC sapic;
+} apic = {
+ /* Header. */
+ {
+ {
+ APIC_SIG, /* Signature. */
+ sizeof(apic), /* Length of table. */
+ 0, /* ACPI minor revision. */
+ 0, /* XXX checksum. */
+ "FBSD", /* OEM Id. */
+ "SKI", /* OEM table Id. */
+ 0, /* OEM revision. */
+ "FBSD", /* ASL compiler Id. */
+ 0 /* ASL revision. */
+ },
+ 0xfee00000,
+ },
+ /* cpu0. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu0) /* Length. */
+ },
+ 0, /* ACPI processor id */
+ 0, /* Processor local SAPIC id */
+ 0, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 1, /* FL: Enabled. */
+ },
+ /* cpu1. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu1) /* Length. */
+ },
+ 1, /* ACPI processor id */
+ 0, /* Processor local SAPIC id */
+ 1, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 1, /* FL: Enabled. */
+ },
+ /* cpu2. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu2) /* Length. */
+ },
+ 2, /* ACPI processor id */
+ 1, /* Processor local SAPIC id */
+ 0, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 0, /* FL: Enabled. */
+ },
+ /* cpu3. */
+ {
+ {
+ APIC_LOCAL_SAPIC, /* Type. */
+ sizeof(apic.cpu3) /* Length. */
+ },
+ 3, /* ACPI processor id */
+ 1, /* Processor local SAPIC id */
+ 1, /* Processor local SAPIC eid */
+ { 0, 0, 0 },
+ 0, /* FL: Enabled. */
+ },
+ /* sapic. */
+ {
+ {
+ APIC_IO_SAPIC, /* Type. */
+ sizeof(apic.sapic) /* Length. */
+ },
+ 4, /* IO SAPIC id. */
+ 0,
+ 16, /* Interrupt base. */
+ 0xfec00000 /* IO SAPIC address. */
+ }
+};
+
+struct {
+ ACPI_TABLE_HEADER Header;
+ UINT64 apic_tbl;
+} xsdt = {
+ {
+ XSDT_SIG, /* Signature. */
+ sizeof(xsdt), /* Length of table. */
+ 0, /* ACPI minor revision. */
+ 0, /* XXX checksum. */
+ "FBSD", /* OEM Id. */
+ "SKI", /* OEM table Id. */
+ 0, /* OEM revision. */
+ "FBSD", /* ASL compiler Id. */
+ 0 /* ASL revision. */
+ },
+ NULL /* XXX APIC table address. */
+};
+
+RSDP_DESCRIPTOR acpi_root = {
+ RSDP_SIG,
+ 0, /* XXX checksum. */
+ "FBSD",
+ 2, /* ACPI Rev 2.0. */
+ NULL,
+ sizeof(xsdt), /* XSDT length. */
+ NULL, /* XXX PA of XSDT. */
+ 0, /* XXX Extended checksum. */
+};
+
+static void
+cksum(void *addr, int sz, UINT8 *sum)
+{
+ UINT8 *p, s;
+
+ p = addr;
+ s = 0;
+ while (sz--)
+ s += *p++;
+ *sum = -s;
+}
+
+void
+acpi_stub_init(void)
+{
+ acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
+ cksum(&acpi_root, 20, &acpi_root.Checksum);
+ cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
+
+ xsdt.apic_tbl = (UINT32)&apic;
+ cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
+}
diff --git a/sys/boot/ia64/ski/bootinfo.c b/sys/boot/ia64/ski/bootinfo.c
index 0a18ec7..91f691a 100644
--- a/sys/boot/ia64/ski/bootinfo.c
+++ b/sys/boot/ia64/ski/bootinfo.c
@@ -34,8 +34,6 @@
#include <machine/elf.h>
#include <machine/bootinfo.h>
-#include <efi.h>
-
#include "bootstrap.h"
/*
@@ -60,6 +58,7 @@ static struct
};
extern char *ski_fmtdev(void *vdev);
+extern int ski_init_stubs(struct bootinfo *);
int
bi_getboothowto(char *kargs)
@@ -250,7 +249,6 @@ bi_load(struct bootinfo *bi, struct preloaded_file *fp, char *args)
char *kernelname;
vm_offset_t ssym, esym;
struct file_metadata *md;
- EFI_MEMORY_DESCRIPTOR *memp;
/*
* Version 1 bootinfo.
@@ -320,25 +318,5 @@ bi_load(struct bootinfo *bi, struct preloaded_file *fp, char *args)
/* all done copying stuff in, save end of loaded object space */
bi->bi_kernend = addr;
- /* Describe the SKI memory map. */
- bi->bi_memmap = (u_int64_t)(bi + 1);
- bi->bi_memmap_size = 2 * sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR);
- bi->bi_memdesc_version = 1;
-
- memp = (EFI_MEMORY_DESCRIPTOR *) bi->bi_memmap;
-
- memp[0].Type = EfiConventionalMemory;
- memp[0].PhysicalStart = 2L*1024*1024;
- memp[0].VirtualStart = 0;
- memp[0].NumberOfPages = (64L*1024*1024)>>12;
- memp[0].Attribute = EFI_MEMORY_WB;
-
- memp[1].Type = EfiMemoryMappedIOPortSpace;
- memp[1].PhysicalStart = 0xffffc000000;
- memp[1].VirtualStart = 0;
- memp[1].NumberOfPages = (64L*1024*1024)>>12;
- memp[1].Attribute = EFI_MEMORY_UC;
-
- return(0);
+ return (ski_init_stubs(bi));
}
diff --git a/sys/boot/ia64/ski/efi_stub.c b/sys/boot/ia64/ski/efi_stub.c
new file mode 100644
index 0000000..36f72c3
--- /dev/null
+++ b/sys/boot/ia64/ski/efi_stub.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <machine/bootinfo.h>
+#include <efi.h>
+#include <stand.h>
+#include "libski.h"
+
+extern void acpi_root;
+extern void sal_systab;
+
+extern void acpi_stub_init(void);
+extern void sal_stub_init(void);
+
+EFI_CONFIGURATION_TABLE efi_cfgtab[] = {
+ { ACPI_20_TABLE_GUID, &acpi_root },
+ { SAL_SYSTEM_TABLE_GUID, &sal_systab }
+};
+
+
+static EFI_STATUS GetTime(EFI_TIME *, EFI_TIME_CAPABILITIES *);
+static EFI_STATUS SetTime(EFI_TIME *);
+static EFI_STATUS GetWakeupTime(BOOLEAN *, BOOLEAN *, EFI_TIME *);
+static EFI_STATUS SetWakeupTime(BOOLEAN, EFI_TIME *);
+
+static EFI_STATUS SetVirtualAddressMap(UINTN, UINTN, UINT32,
+ EFI_MEMORY_DESCRIPTOR*);
+static EFI_STATUS ConvertPointer(UINTN, VOID **);
+
+static EFI_STATUS GetVariable(CHAR16 *, EFI_GUID *, UINT32 *, UINTN *, VOID *);
+static EFI_STATUS GetNextVariableName(UINTN *, CHAR16 *, EFI_GUID *);
+static EFI_STATUS SetVariable(CHAR16 *, EFI_GUID *, UINT32, UINTN, VOID *);
+
+static EFI_STATUS GetNextHighMonotonicCount(UINT32 *);
+static EFI_STATUS ResetSystem(EFI_RESET_TYPE, EFI_STATUS, UINTN, CHAR16 *);
+
+EFI_RUNTIME_SERVICES efi_rttab = {
+ /* Header. */
+ { EFI_RUNTIME_SERVICES_SIGNATURE,
+ EFI_RUNTIME_SERVICES_REVISION,
+ 0, /* XXX HeaderSize */
+ 0, /* XXX CRC32 */
+ },
+
+ /* Time services */
+ GetTime,
+ SetTime,
+ GetWakeupTime,
+ SetWakeupTime,
+
+ /* Virtual memory services */
+ SetVirtualAddressMap,
+ ConvertPointer,
+
+ /* Variable services */
+ GetVariable,
+ GetNextVariableName,
+ SetVariable,
+
+ /* Misc */
+ GetNextHighMonotonicCount,
+ ResetSystem
+};
+
+EFI_SYSTEM_TABLE efi_systab = {
+ /* Header. */
+ { EFI_SYSTEM_TABLE_SIGNATURE,
+ EFI_SYSTEM_TABLE_REVISION,
+ 0, /* XXX HeaderSize */
+ 0, /* XXX CRC32 */
+ },
+
+ /* Firmware info. */
+ L"FreeBSD", 0,
+
+ /* Console stuff. */
+ NULL, NULL,
+ NULL, NULL,
+ NULL, NULL,
+
+ /* Services (runtime first). */
+ &efi_rttab,
+ NULL,
+
+ /* Configuration tables. */
+ sizeof(efi_cfgtab)/sizeof(EFI_CONFIGURATION_TABLE),
+ efi_cfgtab
+};
+
+static EFI_STATUS
+unsupported(const char *func)
+{
+ printf("EFI: %s not supported\n", func);
+ return (EFI_UNSUPPORTED);
+}
+
+static EFI_STATUS
+GetTime(EFI_TIME *time, EFI_TIME_CAPABILITIES *caps)
+{
+ UINT32 comps[8];
+
+ ssc((UINT64)comps, 0, 0, 0, SSC_GET_RTC);
+ time->Year = comps[0] + 1900;
+ time->Month = comps[1] + 1;
+ time->Day = comps[2];
+ time->Hour = comps[3];
+ time->Minute = comps[4];
+ time->Second = comps[5];
+ time->Pad1 = time->Pad2 = 0;
+ time->Nanosecond = 0;
+ time->TimeZone = 0;
+ time->Daylight = 0;
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+SetTime(EFI_TIME *time)
+{
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+GetWakeupTime(BOOLEAN *enabled, BOOLEAN *pending, EFI_TIME *time)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+SetWakeupTime(BOOLEAN enable, EFI_TIME *time)
+{
+ return (unsupported(__func__));
+}
+
+static void
+Reloc(void *addr, UINT64 delta)
+{
+ UINT64 **fpp = addr;
+
+ *fpp[0] += delta;
+ *fpp[1] += delta;
+ *fpp += delta >> 3;
+}
+
+static EFI_STATUS
+SetVirtualAddressMap(UINTN mapsz, UINTN descsz, UINT32 version,
+ EFI_MEMORY_DESCRIPTOR *memmap)
+{
+ UINT64 delta;
+
+ delta = memmap->VirtualStart - memmap->PhysicalStart;
+ Reloc(&efi_rttab.GetTime, delta);
+ Reloc(&efi_rttab.SetTime, delta);
+ return (EFI_SUCCESS); /* Hah... */
+}
+
+static EFI_STATUS
+ConvertPointer(UINTN debug, VOID **addr)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 *attrs, UINTN *datasz,
+ VOID *data)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetNextVariableName(UINTN *namesz, CHAR16 *name, EFI_GUID *vendor)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+SetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 attrs, UINTN datasz,
+ VOID *data)
+{
+ return (unsupported(__func__));
+}
+
+static EFI_STATUS
+GetNextHighMonotonicCount(UINT32 *high)
+{
+ static UINT32 counter = 0;
+
+ *high = counter++;
+ return (EFI_SUCCESS);
+}
+
+static EFI_STATUS
+ResetSystem(EFI_RESET_TYPE type, EFI_STATUS status, UINTN datasz,
+ CHAR16 *data)
+{
+ return (unsupported(__func__));
+}
+
+int
+ski_init_stubs(struct bootinfo *bi)
+{
+ EFI_MEMORY_DESCRIPTOR *memp;
+
+ /* Describe the SKI memory map. */
+ bi->bi_memmap = (u_int64_t)(bi + 1);
+ bi->bi_memmap_size = 4 * sizeof(EFI_MEMORY_DESCRIPTOR);
+ bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR);
+ bi->bi_memdesc_version = 1;
+
+ memp = (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap;
+
+ memp[0].Type = EfiPalCode;
+ memp[0].PhysicalStart = 0x100000;
+ memp[0].VirtualStart = 0;
+ memp[0].NumberOfPages = (4L*1024*1024)>>12;
+ memp[0].Attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME;
+
+ memp[1].Type = EfiConventionalMemory;
+ memp[1].PhysicalStart = 5L*1024*1024;
+ memp[1].VirtualStart = 0;
+ memp[1].NumberOfPages = (128L*1024*1024)>>12;
+ memp[1].Attribute = EFI_MEMORY_WB;
+
+ memp[2].Type = EfiConventionalMemory;
+ memp[2].PhysicalStart = 4L*1024*1024*1024;
+ memp[2].VirtualStart = 0;
+ memp[2].NumberOfPages = (64L*1024*1024)>>12;
+ memp[2].Attribute = EFI_MEMORY_WB;
+
+ memp[3].Type = EfiMemoryMappedIOPortSpace;
+ memp[3].PhysicalStart = 0xffffc000000;
+ memp[3].VirtualStart = 0;
+ memp[3].NumberOfPages = (64L*1024*1024)>>12;
+ memp[3].Attribute = EFI_MEMORY_UC;
+
+ bi->bi_systab = (u_int64_t)&efi_systab;
+
+ sal_stub_init();
+ acpi_stub_init();
+
+ return (0);
+}
diff --git a/sys/boot/ia64/ski/elf_freebsd.c b/sys/boot/ia64/ski/elf_freebsd.c
index 461ef12..e72a52d 100644
--- a/sys/boot/ia64/ski/elf_freebsd.c
+++ b/sys/boot/ia64/ski/elf_freebsd.c
@@ -130,6 +130,8 @@ struct ia64_pte {
u_int64_t pte_ig :11; /* bits 53..63 */
};
+static struct bootinfo bootinfo;
+
void
enter_kernel(const char* filename, u_int64_t start, struct bootinfo *bi)
{
@@ -167,7 +169,7 @@ elf_exec(struct preloaded_file *fp)
* Ugly hack, similar to linux. Dump the bootinfo into a
* special page reserved in the link map.
*/
- bi = (struct bootinfo *) 0x508000;
+ bi = &bootinfo;
bzero(bi, sizeof(struct bootinfo));
bi_load(bi, fp);
diff --git a/sys/boot/ia64/ski/libski.h b/sys/boot/ia64/ski/libski.h
index bb3f1dd..043177c 100644
--- a/sys/boot/ia64/ski/libski.h
+++ b/sys/boot/ia64/ski/libski.h
@@ -90,6 +90,7 @@ extern int bi_load(struct bootinfo *, struct preloaded_file *);
#define SSC_GET_RTC 65
#define SSC_EXIT 66
#define SSC_LOAD_SYMBOLS 69
+#define SSC_SAL_SET_VECTORS 120
u_int64_t ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3,
int which);
diff --git a/sys/boot/ia64/ski/pal_stub.S b/sys/boot/ia64/ski/pal_stub.S
new file mode 100644
index 0000000..e67204c
--- /dev/null
+++ b/sys/boot/ia64/ski/pal_stub.S
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * Copyright (c) 2001 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+
+ .text
+ENTRY(PalProc, 0)
+ cmp.eq p6,p0=6,r28 // PAL_PTCE_INFO
+(p6) br.cond.dptk pal_ptce_info
+ ;;
+ cmp.eq p6,p0=8,r28 // PAL_VM_SUMMARY
+(p6) br.cond.dptk pal_vm_summary
+ ;;
+ cmp.eq p6,p0=14,r28 // PAL_FREQ_RATIOS
+(p6) br.cond.dptk pal_freq_ratios
+ ;;
+ mov r15=66 // EXIT
+ break.i 0x80000 // SSC
+ ;;
+pal_ptce_info:
+ mov r8=0
+ mov r9=0 // base
+ movl r10=0x0000000100000001 // loop counts (outer|inner)
+ mov r11=0x0000000000000000 // loop strides (outer|inner)
+ br.sptk b0
+pal_vm_summary:
+ mov r8=0
+ movl r9=(8<<40)|(8<<32) // VM info 1
+ mov r10=(18<<8)|(41<<0) // VM info 2
+ mov r11=0
+ br.sptk b0
+pal_freq_ratios:
+ mov r8=0
+ movl r9=0x0000000B00000002 // processor ratio 11/2
+ movl r10=0x0000000100000001 // bus ratio 1/1
+ movl r11=0x0000000B00000002 // ITC ratio 11/2
+ br.sptk b0
+END(PalProc)
diff --git a/sys/boot/ia64/ski/sal_stub.c b/sys/boot/ia64/ski/sal_stub.c
new file mode 100644
index 0000000..caa6671
--- /dev/null
+++ b/sys/boot/ia64/ski/sal_stub.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <machine/md_var.h>
+#include <machine/sal.h>
+#include <stand.h>
+#include "libski.h"
+
+extern void PalProc(void);
+static sal_entry_t SalProc;
+
+struct {
+ struct sal_system_table header;
+ struct sal_entrypoint_descriptor entry;
+ struct sal_ap_wakeup_descriptor wakeup;
+} sal_systab = {
+ /* Header. */
+ {
+ SAL_SIGNATURE,
+ sizeof(sal_systab),
+ { 00, 03 }, /* Revision 3.0. */
+ 2, /* Number of decsriptors. */
+ 0, /* XXX checksum. */
+ { 0 },
+ { 00, 00 }, /* XXX SAL_A version. */
+ { 00, 00 }, /* XXX SAL_B version. */
+ "FreeBSD",
+ "Ski loader",
+ { 0 }
+ },
+ /* Entrypoint. */
+ {
+ 0, /* Type=entrypoint descr. */
+ { 0 },
+ 0, /* XXX PalProc. */
+ 0, /* XXX SalProc. */
+ 0, /* XXX SalProc GP. */
+ { 0 }
+ },
+ /* AP wakeup. */
+ {
+ 5, /* Type=AP wakeup descr. */
+ 0, /* External interrupt. */
+ { 0 },
+ 255 /* Wakeup vector. */
+ }
+};
+
+static inline void
+puts(const char *s)
+{
+ s = (const char *)((7UL << 61) | (u_long)s);
+ while (*s)
+ ski_cons_putchar(*s++);
+}
+
+static struct ia64_sal_result
+SalProc(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4, u_int64_t a5,
+ u_int64_t a6, u_int64_t a7, u_int64_t a8)
+{
+ struct ia64_sal_result res;
+
+ res.sal_status = -3;
+ res.sal_result[0] = 0;
+ res.sal_result[1] = 0;
+ res.sal_result[2] = 0;
+
+ if (a1 == SAL_FREQ_BASE) {
+ res.sal_status = 0;
+ res.sal_result[0] = 133338184;
+ } else if (a1 == SAL_SET_VECTORS) {
+ /* XXX unofficial SSC function. */
+ ssc(a2, a3, a4, a5, SSC_SAL_SET_VECTORS);
+ } else if (a1 != SAL_GET_STATE_INFO_SIZE) {
+ puts("SAL: unimplemented function called\n");
+ }
+
+ return (res);
+}
+
+void
+sal_stub_init(void)
+{
+ struct ia64_fdesc *fd;
+
+ fd = (void*)PalProc;
+ sal_systab.entry.sale_pal_proc = fd->func;
+ fd = (void*)SalProc;
+ sal_systab.entry.sale_sal_proc = fd->func;
+ sal_systab.entry.sale_sal_gp = fd->gp;
+}
diff --git a/sys/boot/ia64/ski/ssc.c b/sys/boot/ia64/ski/ssc.c
index 11a91c8..e3e9eb2 100644
--- a/sys/boot/ia64/ski/ssc.c
+++ b/sys/boot/ia64/ski/ssc.c
@@ -29,14 +29,24 @@
#include <stand.h>
#include "libski.h"
+/*
+ * Ugh... Work around a bug in the Linux version of ski for SSC_GET_RTC. The
+ * PSR.dt register is not preserved properly and causes further memory
+ * references to be done without translation. All we need to do is preserve
+ * PSR.dt across the SSC call. We do this by saving and restoring psr.l
+ * completely.
+ */
u_int64_t
ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which)
{
+ register u_int64_t psr;
register u_int64_t ret0 __asm("r8");
+ __asm __volatile("mov %0=psr;;" : "=r"(psr));
__asm __volatile("mov r15=%1\n\t"
- "break 0x80000"
+ "break 0x80000;;"
: "=r"(ret0)
: "r"(which), "r"(in0), "r"(in1), "r"(in2), "r"(in3));
+ __asm __volatile("mov psr.l=%0;; srlz.d" :: "r"(psr));
return ret0;
}
OpenPOWER on IntegriCloud