/*-1* Copyright (c) 2001 Benno Rice <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <sys/param.h>27#include <sys/linker.h>2829#include <machine/metadata.h>30#include <machine/elf.h>31#if defined(__powerpc__)32#include <machine/md_var.h>33#endif3435#include <stand.h>3637#include "bootstrap.h"38#include "libofw.h"39#include "openfirm.h"40#include "modinfo.h"4142extern char end[];43extern vm_offset_t reloc; /* From <arch>/conf.c */4445int46__elfN(ofw_loadfile)(char *filename, uint64_t dest,47struct preloaded_file **result)48{49int r;5051r = __elfN(loadfile)(filename, dest, result);52if (r != 0)53return (r);5455#if defined(__powerpc__)56/*57* No need to sync the icache for modules: this will58* be done by the kernel after relocation.59*/60if (!strcmp((*result)->f_type, md_kerntype))61__syncicache((void *) (*result)->f_addr, (*result)->f_size);62#endif63return (0);64}6566int67__elfN(ofw_exec)(struct preloaded_file *fp)68{69struct file_metadata *fmp;70vm_offset_t mdp, dtbp;71Elf_Ehdr *e;72int error;73intptr_t entry;7475if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) {76return(EFTYPE);77}78e = (Elf_Ehdr *)&fmp->md_data;79entry = e->e_entry;8081if ((error = md_load(fp->f_args, &mdp, &dtbp)) != 0)82return (error);8384printf("Kernel entry at 0x%x ...\n", entry);8586dev_cleanup();87if (dtbp != 0) {88OF_quiesce();89((int (*)(u_long, u_long, u_long, void *, u_long))entry)(dtbp,900, 0, (void *)mdp, 0xfb5d104d);91} else {92OF_chain((void *)reloc, end - (char *)reloc, (void *)entry,93(void *)mdp, 0xfb5d104d);94}9596panic("exec returned");97}9899struct file_format ofw_elf =100{101__elfN(ofw_loadfile),102__elfN(ofw_exec)103};104105106