From owner-svn-src-head@freebsd.org Sat Mar 3 23:39:09 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5E7DF46769; Sat, 3 Mar 2018 23:39:08 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8F6747D3A3; Sat, 3 Mar 2018 23:39:08 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 88CDB5540; Sat, 3 Mar 2018 23:39:08 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w23Nd89B028464; Sat, 3 Mar 2018 23:39:08 GMT (envelope-from nwhitehorn@FreeBSD.org) Received: (from nwhitehorn@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w23Nd7aY028456; Sat, 3 Mar 2018 23:39:07 GMT (envelope-from nwhitehorn@FreeBSD.org) Message-Id: <201803032339.w23Nd7aY028456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: nwhitehorn set sender to nwhitehorn@FreeBSD.org using -f From: Nathan Whitehorn Date: Sat, 3 Mar 2018 23:39:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330365 - in head/stand: ofw/common ofw/libofw powerpc/ofw X-SVN-Group: head X-SVN-Commit-Author: nwhitehorn X-SVN-Commit-Paths: in head/stand: ofw/common ofw/libofw powerpc/ofw X-SVN-Commit-Revision: 330365 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Mar 2018 23:39:09 -0000 Author: nwhitehorn Date: Sat Mar 3 23:39:07 2018 New Revision: 330365 URL: https://svnweb.freebsd.org/changeset/base/330365 Log: Move "common" Open Firmware parts of the loader used only on PowerPC to the powerpc/ subdirectory. These have never used by SPARC and we have no other (and almost certainly will have no other) Open Firmware platforms. This makes the directory structure simpler and lets us avoid some cargo-cult MI patterns on code that is, and always was, architecture-specific. Added: head/stand/powerpc/ofw/elf_freebsd.c - copied, changed from r330364, head/stand/ofw/libofw/elf_freebsd.c head/stand/powerpc/ofw/main.c - copied unchanged from r330364, head/stand/ofw/common/main.c head/stand/powerpc/ofw/ppc64_elf_freebsd.c - copied unchanged from r330364, head/stand/ofw/libofw/ppc64_elf_freebsd.c Deleted: head/stand/ofw/common/ head/stand/ofw/libofw/elf_freebsd.c head/stand/ofw/libofw/ppc64_elf_freebsd.c Modified: head/stand/ofw/libofw/Makefile head/stand/ofw/libofw/libofw.h head/stand/powerpc/ofw/Makefile head/stand/powerpc/ofw/conf.c Modified: head/stand/ofw/libofw/Makefile ============================================================================== --- head/stand/ofw/libofw/Makefile Sat Mar 3 23:23:23 2018 (r330364) +++ head/stand/ofw/libofw/Makefile Sat Mar 3 23:39:07 2018 (r330365) @@ -4,7 +4,7 @@ LIB= ofw -SRCS= devicename.c elf_freebsd.c ofw_console.c ofw_copy.c ofw_disk.c \ +SRCS= devicename.c ofw_console.c ofw_copy.c ofw_disk.c \ ofw_memory.c ofw_module.c ofw_net.c ofw_reboot.c \ ofw_time.c openfirm.c .PATH: ${ZFSSRC} @@ -12,10 +12,6 @@ SRCS+= devicename_stubs.c # Pick up the bootstrap header for some interface items CFLAGS+= -I${LDRSRC} - -.if ${MACHINE_CPUARCH} == "powerpc" -SRCS+= ppc64_elf_freebsd.c -.endif .ifdef(BOOT_DISK_DEBUG) # Make the disk code more talkative Modified: head/stand/ofw/libofw/libofw.h ============================================================================== --- head/stand/ofw/libofw/libofw.h Sat Mar 3 23:23:23 2018 (r330364) +++ head/stand/ofw/libofw/libofw.h Sat Mar 3 23:39:07 2018 (r330365) @@ -62,17 +62,9 @@ void ofw_memmap(int); struct preloaded_file; struct file_format; -int ofw_elf_loadfile(char *, vm_offset_t, struct preloaded_file **); -int ofw_elf_exec(struct preloaded_file *); - /* MD code implementing MI interfaces */ vm_offset_t md_load(char *args, vm_offset_t *modulep, vm_offset_t *dtb); vm_offset_t md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtb); - -extern struct file_format ofw_elf; -#ifdef __powerpc__ -extern struct file_format ofw_elf64; -#endif extern void reboot(void); Modified: head/stand/powerpc/ofw/Makefile ============================================================================== --- head/stand/powerpc/ofw/Makefile Sat Mar 3 23:23:23 2018 (r330364) +++ head/stand/powerpc/ofw/Makefile Sat Mar 3 23:39:07 2018 (r330365) @@ -17,7 +17,7 @@ NEWVERSWHAT= "Open Firmware loader" ${MACHINE_ARCH} INSTALLFLAGS= -b # Architecture-specific loader code -SRCS= conf.c vers.c start.c +SRCS= conf.c vers.c main.c elf_freebsd.c ppc64_elf_freebsd.c start.c SRCS+= ucmpdi2.c .include "${BOOTSRC}/fdt.mk" @@ -37,10 +37,6 @@ RELOC?= 0x1C00000 CFLAGS+= -DRELOC=${RELOC} LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.powerpc - -# Pull in common loader code -.PATH: ${BOOTSRC}/ofw/common -.include "${BOOTSRC}/ofw/common/Makefile.inc" # Open Firmware standalone support library LIBOFW= ${BOOTOBJ}/ofw/libofw/libofw.a Modified: head/stand/powerpc/ofw/conf.c ============================================================================== --- head/stand/powerpc/ofw/conf.c Sat Mar 3 23:23:23 2018 (r330364) +++ head/stand/powerpc/ofw/conf.c Sat Mar 3 23:39:07 2018 (r330365) @@ -97,6 +97,9 @@ struct netif_driver *netif_drivers[] = { * rather than reading the file go first. */ +struct file_format ofw_elf; +struct file_format ofw_elf64; + struct file_format *file_formats[] = { &ofw_elf, &ofw_elf64, Copied and modified: head/stand/powerpc/ofw/elf_freebsd.c (from r330364, head/stand/ofw/libofw/elf_freebsd.c) ============================================================================== --- head/stand/ofw/libofw/elf_freebsd.c Sat Mar 3 23:23:23 2018 (r330364, copy source) +++ head/stand/powerpc/ofw/elf_freebsd.c Sat Mar 3 23:39:07 2018 (r330365) @@ -89,8 +89,8 @@ __elfN(ofw_exec)(struct preloaded_file *fp) dev_cleanup(); if (dtbp != 0) { OF_quiesce(); - ((int (*)(u_long, u_long, u_long, void *, u_long))entry)(dtbp, 0, 0, - (void *)mdp, sizeof(mdp)); + ((int (*)(u_long, u_long, u_long, void *, u_long))entry)(dtbp, + 0, 0, (void *)mdp, 0xfb5d104d); } else { OF_chain((void *)reloc, end - (char *)reloc, (void *)entry, (void *)mdp, 0xfb5d104d); Copied: head/stand/powerpc/ofw/main.c (from r330364, head/stand/ofw/common/main.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/powerpc/ofw/main.c Sat Mar 3 23:39:07 2018 (r330365, copy of r330364, head/stand/ofw/common/main.c) @@ -0,0 +1,179 @@ +/*- + * Copyright (c) 2000 Benno Rice + * Copyright (c) 2000 Stephane Potvin + * 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 AUTHORS 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 +__FBSDID("$FreeBSD$"); + +#include +#include "openfirm.h" +#include "libofw.h" +#include "bootstrap.h" + +struct arch_switch archsw; /* MI/MD interface boundary */ + +extern char end[]; +extern char bootprog_info[]; + +u_int32_t acells, scells; + +static char bootargs[128]; + +#define HEAP_SIZE 0x800000 +static char heap[HEAP_SIZE]; // In BSS, so uses no space + +#define OF_puts(fd, text) OF_write(fd, text, strlen(text)) + +void +init_heap(void) +{ + bzero(heap, HEAP_SIZE); + + setheap(heap, (void *)((int)heap + HEAP_SIZE)); +} + +uint64_t +memsize(void) +{ + phandle_t memoryp; + cell_t reg[24]; + int i, sz; + u_int64_t memsz; + + memsz = 0; + memoryp = OF_instance_to_package(memory); + + sz = OF_getprop(memoryp, "reg", ®, sizeof(reg)); + sz /= sizeof(reg[0]); + + for (i = 0; i < sz; i += (acells + scells)) { + if (scells > 1) + memsz += (uint64_t)reg[i + acells] << 32; + memsz += reg[i + acells + scells - 1]; + } + + return (memsz); +} + +int +main(int (*openfirm)(void *)) +{ + phandle_t root; + int i; + char bootpath[64]; + char *ch; + int bargc; + char **bargv; + + /* + * Initialise the Open Firmware routines by giving them the entry point. + */ + OF_init(openfirm); + + root = OF_finddevice("/"); + + scells = acells = 1; + OF_getprop(root, "#address-cells", &acells, sizeof(acells)); + OF_getprop(root, "#size-cells", &scells, sizeof(scells)); + + /* + * Initialise the heap as early as possible. Once this is done, + * alloc() is usable. The stack is buried inside us, so this is + * safe. + */ + init_heap(); + + /* + * Set up console. + */ + cons_probe(); + + /* + * 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%s", bootprog_info); + printf("Memory: %lldKB\n", memsize() / 1024); + + OF_getprop(chosen, "bootpath", bootpath, 64); + ch = strchr(bootpath, ':'); + *ch = '\0'; + printf("Booted from: %s\n", bootpath); + + printf("\n"); + + /* + * Only parse the first bootarg if present. It should + * be simple to handle extra arguments + */ + OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); + bargc = 0; + parse(&bargc, &bargv, bootargs); + if (bargc == 1) + env_setenv("currdev", EV_VOLATILE, bargv[0], ofw_setcurrdev, + env_nounset); + else + env_setenv("currdev", EV_VOLATILE, bootpath, + ofw_setcurrdev, env_nounset); + env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset, + env_nounset); + setenv("LINES", "24", 1); /* optional */ + + archsw.arch_getdev = ofw_getdev; + archsw.arch_copyin = ofw_copyin; + archsw.arch_copyout = ofw_copyout; + archsw.arch_readin = ofw_readin; + archsw.arch_autoload = ofw_autoload; + + interact(); /* doesn't return */ + + OF_exit(); + + return 0; +} + +COMMAND_SET(halt, "halt", "halt the system", command_halt); + +static int +command_halt(int argc, char *argv[]) +{ + + OF_exit(); + return (CMD_OK); +} + +COMMAND_SET(memmap, "memmap", "print memory map", command_memmap); + +int +command_memmap(int argc, char **argv) +{ + + ofw_memmap(acells); + return (CMD_OK); +} Copied: head/stand/powerpc/ofw/ppc64_elf_freebsd.c (from r330364, head/stand/ofw/libofw/ppc64_elf_freebsd.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/stand/powerpc/ofw/ppc64_elf_freebsd.c Sat Mar 3 23:39:07 2018 (r330365, copy of r330364, head/stand/ofw/libofw/ppc64_elf_freebsd.c) @@ -0,0 +1,110 @@ +/*- + * Copyright (c) 2001 Benno Rice + * 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 +__FBSDID("$FreeBSD$"); + +#define __ELF_WORD_SIZE 64 + +#include +#include + +#include +#include +#include + +#include + +#include "bootstrap.h" +#include "libofw.h" +#include "openfirm.h" + +extern char end[]; +extern vm_offset_t reloc; /* From /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, dtbp; + 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 for ELFv1 kernels */ + if ((e->e_flags & 3) == 2) + entry = e->e_entry; + else + entry = *(uint64_t *)(intptr_t)e->e_entry; + + if ((error = md_load64(fp->f_args, &mdp, &dtbp)) != 0) + return (error); + + printf("Kernel entry at 0x%lx ...\n", entry); + + dev_cleanup(); + + if (dtbp != 0) { + OF_quiesce(); + ((int (*)(u_long, u_long, u_long, void *, u_long))entry)(dtbp, + 0, 0, (void *)mdp, 0xfb5d104d); + } else { + OF_chain((void *)reloc, end - (char *)reloc, (void *)entry, + (void *)mdp, 0xfb5d104d); + } + + panic("exec returned"); +} + +struct file_format ofw_elf64 = +{ + ppc64_ofw_elf_loadfile, + ppc64_ofw_elf_exec +};