Provide support in loader for booting 64-bit PowerPC kernels. Like amd64,

64-bit PowerPC kernels are loaded by a 32-bit loader, since nearly all
powerpc64 firmwares execute in 32-bit mode.
This commit is contained in:
Nathan Whitehorn 2010-07-12 00:49:22 +00:00
parent 6bce5ae1c5
commit 67167531f0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=209920
17 changed files with 202 additions and 32 deletions

View file

@ -13,12 +13,12 @@ SUBDIR+= efi
.endif
# Build Open Firmware library.
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "sparc64"
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "sparc64"
SUBDIR+= ofw
.endif
# Build U-Boot library.
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm"
SUBDIR+= uboot
.endif
@ -31,7 +31,7 @@ SUBDIR+= fdt
.endif
# Pick the machine-dependent subdir based on the target architecture.
ADIR= ${MACHINE:S/amd64/i386/:S/sun4v/sparc64/}
ADIR= ${MACHINE:S/amd64/i386/:S/sun4v/sparc64/:S/powerpc64/powerpc/}
.if exists(${.CURDIR}/${ADIR}/.)
SUBDIR+= ${ADIR}
.endif

View file

@ -9,8 +9,11 @@ SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c
SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c
.elif ${MACHINE} == "pc98"
SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c
.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
.elif ${MACHINE_ARCH} == "arm"
SRCS+= load_elf32.c reloc_elf32.c
.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
SRCS+= load_elf32.c reloc_elf32.c
SRCS+= load_elf64.c reloc_elf64.c
.elif ${MACHINE_ARCH} == "sparc64" || ${MACHINE_ARCH} == "ia64"
SRCS+= load_elf64.c reloc_elf64.c
.endif

View file

@ -16,10 +16,14 @@ CFLAGS+= -I${.CURDIR}/../../contrib/libfdt/ -I${.CURDIR}/../common/ \
CFLAGS+= -ffreestanding
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
.if ${MACHINE_CPUARCH} == "powerpc" || ${MACHINE_CPUARCH} == "arm"
CFLAGS+= -msoft-float
.endif
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32
.endif
CFLAGS+= -Wformat -Wall
.include <bsd.lib.mk>

View file

@ -1,6 +1,6 @@
# $FreeBSD$
#
.PATH: ${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/}
.PATH: ${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/}
BASE_SRCS= dict.c ficl.c fileaccess.c float.c loader.c math64.c \
prefix.c search.c stack.c tools.c vm.c words.c
@ -14,7 +14,7 @@ CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2
.if ${MACHINE_ARCH} == "i386"
CFLAGS+= -mno-sse3
.endif
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm"
CFLAGS+= -msoft-float
.endif
.if ${MACHINE} == "pc98"
@ -45,7 +45,11 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr freebsd.fr ficllocal.fr \
CFLAGS+= -m32 -march=i386 -I.
.endif
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/} \
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32 -mcpu=powerpc -I.
.endif
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/} \
-I${.CURDIR}/../common
softcore.c: ${SOFTWORDS} softcore.awk

View file

@ -1,3 +1,8 @@
# $FreeBSD$
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32 -mcpu=powerpc
LDFLAGS+= -m elf32ppc
.endif
.include "../Makefile.inc"

View file

@ -13,8 +13,9 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/
CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
CFLAGS+= -ffreestanding
.if ${MACHINE_ARCH} == "powerpc"
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -msoft-float
SRCS+= ppc64_elf_freebsd.c
.endif
.ifdef(BOOT_DISK_DEBUG)

View file

@ -62,6 +62,9 @@ int ofw_elf_loadfile(char *, vm_offset_t, struct preloaded_file **);
int ofw_elf_exec(struct preloaded_file *);
extern struct file_format ofw_elf;
#ifdef __powerpc__
extern struct file_format ofw_elf64;
#endif
extern void reboot(void);

View file

@ -0,0 +1,101 @@
/*-
* Copyright (c) 2001 Benno Rice <benno@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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#define __ELF_WORD_SIZE 64
#include <sys/param.h>
#include <sys/linker.h>
#include <machine/metadata.h>
#include <machine/elf.h>
#include <stand.h>
#include "bootstrap.h"
#include "libofw.h"
#include "openfirm.h"
extern char end[];
extern vm_offset_t reloc; /* From <arch>/conf.c */
int
ppc64_ofw_elf_loadfile(char *filename, u_int64_t dest,
struct preloaded_file **result)
{
int r;
r = __elfN(loadfile)(filename, dest, result);
if (r != 0)
return (r);
/*
* No need to sync the icache for modules: this will
* be done by the kernel after relocation.
*/
if (!strcmp((*result)->f_type, "elf kernel"))
__syncicache((void *) (*result)->f_addr, (*result)->f_size);
return (0);
}
int
ppc64_ofw_elf_exec(struct preloaded_file *fp)
{
struct file_metadata *fmp;
vm_offset_t mdp;
Elf_Ehdr *e;
int error;
intptr_t entry;
if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) {
return(EFTYPE);
}
e = (Elf_Ehdr *)&fmp->md_data;
/* Handle function descriptor */
entry = *(uint64_t *)e->e_entry;
if ((error = md_load64(fp->f_args, &mdp)) != 0)
return (error);
printf("Kernel entry at 0x%lx ...\n", entry);
dev_cleanup();
ofw_release_heap();
OF_chain((void *)reloc, end - (char *)reloc, (void *)entry,
(void *)mdp, sizeof(mdp));
panic("exec returned");
}
struct file_format ofw_elf64 =
{
ppc64_ofw_elf_loadfile,
ppc64_ofw_elf_exec
};

View file

@ -1,3 +1,8 @@
# $FreeBSD$
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32 -mcpu=powerpc
LDFLAGS+= -m elf32ppc
.endif
.include "../Makefile.inc"

View file

@ -13,7 +13,7 @@ SRCS= boot1.c ashldi3.c
INTERNALPROG=
NO_MAN=
CFLAGS= -ffreestanding -msoft-float -Os -D_KERNEL \
CFLAGS= -ffreestanding -msoft-float -Os \
-I${.CURDIR}/../../common -I${.CURDIR}/../../../
LDFLAGS=-nostdlib -static -N

View file

@ -10,6 +10,7 @@ INSTALLFLAGS= -b
# Architecture-specific loader code
SRCS= conf.c metadata.c vers.c start.c
SRCS+= ucmpdi2.c
LOADER_DISK_SUPPORT?= yes
LOADER_UFS_SUPPORT?= yes
@ -62,9 +63,9 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a
CFLAGS+= -DNETIF_OPEN_CLOSE_ONCE
# Always add MI sources
.PATH: ${.CURDIR}/../../common
.PATH: ${.CURDIR}/../../common ${.CURDIR}/../../../libkern
.include "${.CURDIR}/../../common/Makefile.inc"
CFLAGS+= -I${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../..
CFLAGS+= -I.
CLEANFILES+= vers.c loader.help

View file

@ -96,6 +96,7 @@ struct netif_driver *netif_drivers[] = {
struct file_format *file_formats[] = {
&ofw_elf,
&ofw_elf64,
NULL
};

View file

@ -1,7 +1,7 @@
/* $FreeBSD$ */
OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc")
OUTPUT_ARCH(powerpc)
OUTPUT_ARCH(powerpc:common)
ENTRY(_start)
SEARCH_DIR(/usr/lib);
/* Do we need any of these for elf?

View file

@ -175,6 +175,9 @@ md_copyenv(vm_offset_t addr)
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
static int align;
#define COPY32(v, a, c) { \
u_int32_t x = (v); \
if (c) \
@ -187,7 +190,7 @@ md_copyenv(vm_offset_t addr)
COPY32(strlen(s) + 1, a, c) \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1);\
a += roundup(strlen(s) + 1, sizeof(u_long));\
a += roundup(strlen(s) + 1, align); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@ -199,7 +202,7 @@ md_copyenv(vm_offset_t addr)
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
a += roundup(sizeof(s), sizeof(u_long)); \
a += roundup(sizeof(s), align); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@ -210,7 +213,7 @@ md_copyenv(vm_offset_t addr)
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size);\
a += roundup(mm->md_size, sizeof(u_long)); \
a += roundup(mm->md_size, align); \
}
#define MOD_END(a, c) { \
@ -219,10 +222,11 @@ md_copyenv(vm_offset_t addr)
}
vm_offset_t
md_copymodules(vm_offset_t addr)
md_copymodules(vm_offset_t addr, int kern64)
{
struct preloaded_file *fp;
struct file_metadata *md;
uint64_t scratch64;
int c;
c = addr != 0;
@ -233,8 +237,15 @@ md_copymodules(vm_offset_t addr)
MOD_TYPE(addr, fp->f_type, c);
if (fp->f_args)
MOD_ARGS(addr, fp->f_args, c);
MOD_ADDR(addr, fp->f_addr, c);
MOD_SIZE(addr, fp->f_size, c);
if (kern64) {
scratch64 = fp->f_addr;
MOD_ADDR(addr, scratch64, c);
scratch64 = fp->f_size;
MOD_SIZE(addr, scratch64, c);
} else {
MOD_ADDR(addr, fp->f_addr, c);
MOD_SIZE(addr, fp->f_size, c);
}
for (md = fp->f_metadata; md != NULL; md = md->md_next) {
if (!(md->md_type & MODINFOMD_NOCOPY)) {
MOD_METADATA(addr, md, c);
@ -254,7 +265,7 @@ md_copymodules(vm_offset_t addr)
* - Module metadata are formatted and placed in kernel space.
*/
int
md_load(char *args, vm_offset_t *modulep)
md_load_dual(char *args, vm_offset_t *modulep, int kern64)
{
struct preloaded_file *kfp;
struct preloaded_file *xp;
@ -263,11 +274,11 @@ md_load(char *args, vm_offset_t *modulep)
vm_offset_t addr;
vm_offset_t envp;
vm_offset_t size;
uint64_t scratch64;
char *rootdevname;
int howto;
int dtlb_slots;
int itlb_slots;
align = kern64 ? 8 : 4;
howto = md_getboothowto(args);
/*
@ -298,23 +309,48 @@ md_load(char *args, vm_offset_t *modulep)
addr = roundup(addr, PAGE_SIZE);
kernend = 0;
kfp = file_findfile(NULL, "elf32 kernel");
kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
panic("can't find kernel file");
file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
if (kern64) {
scratch64 = envp;
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof scratch64, &scratch64);
scratch64 = kernend;
file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof scratch64, &scratch64);
} else {
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
}
*modulep = addr;
size = md_copymodules(0);
size = md_copymodules(0, kern64);
kernend = roundup(addr + size, PAGE_SIZE);
md = file_findmetadata(kfp, MODINFOMD_KERNEND);
bcopy(&kernend, md->md_data, sizeof kernend);
(void)md_copymodules(addr);
if (kern64) {
scratch64 = kernend;
bcopy(&scratch64, md->md_data, sizeof scratch64);
} else {
bcopy(&kernend, md->md_data, sizeof kernend);
}
(void)md_copymodules(addr, kern64);
return(0);
}
int
md_load(char *args, vm_offset_t *modulep)
{
return (md_load_dual(args, modulep, 0));
}
int
md_load64(char *args, vm_offset_t *modulep)
{
return (md_load_dual(args, modulep, 1));
}

View file

@ -10,6 +10,7 @@ NO_MAN=
# Architecture-specific loader code
SRCS= start.S conf.c vers.c
SRCS+= ucmpdi2.c
LOADER_DISK_SUPPORT?= yes
LOADER_UFS_SUPPORT?= yes
@ -68,9 +69,9 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a
.endif
# Always add MI sources
.PATH: ${.CURDIR}/../../common
.PATH: ${.CURDIR}/../../common ${.CURDIR}/../../../libkern
.include "${.CURDIR}/../../common/Makefile.inc"
CFLAGS+= -I${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../..
CFLAGS+= -I.
CLEANFILES+= vers.c ${PROG}.help

View file

@ -1,7 +1,7 @@
/* $FreeBSD$ */
OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc")
OUTPUT_ARCH(powerpc)
OUTPUT_ARCH(powerpc:common)
ENTRY(_start)
SEARCH_DIR(/usr/lib);
PROVIDE (__stack = 0);

View file

@ -1,3 +1,8 @@
# $FreeBSD$
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32 -mcpu=powerpc
LDFLAGS+= -m elf32ppc
.endif
.include "../Makefile.inc"