Path: blob/main/stand/powerpc/ofw/ppc64_elf_freebsd.c
34860 views
/*-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#define __ELF_WORD_SIZE 642728#include <sys/param.h>29#include <sys/linker.h>3031#include <machine/metadata.h>32#include <machine/elf.h>33#include <machine/md_var.h>3435#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 */4445int46ppc64_ofw_elf_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/*56* No need to sync the icache for modules: this will57* be done by the kernel after relocation.58*/59if (!strcmp((*result)->f_type, md_kerntype))60__syncicache((void *) (*result)->f_addr, (*result)->f_size);61return (0);62}6364int65ppc64_ofw_elf_exec(struct preloaded_file *fp)66{67struct file_metadata *fmp;68vm_offset_t mdp, dtbp;69Elf_Ehdr *e;70int error;71intptr_t entry;7273if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) {74return(EFTYPE);75}76e = (Elf_Ehdr *)&fmp->md_data;7778/* Handle function descriptor for ELFv1 kernels */79if ((e->e_flags & 3) == 2)80entry = e->e_entry;81else82entry = *(uint64_t *)(intptr_t)e->e_entry;8384if ((error = md_load64(fp->f_args, &mdp, &dtbp)) != 0)85return (error);8687printf("Kernel entry at 0x%x ...\n", entry);8889dev_cleanup();9091if (dtbp != 0) {92OF_quiesce();93((int (*)(u_long, u_long, u_long, void *, u_long))entry)(dtbp,940, 0, (void *)mdp, 0xfb5d104d);95} else {96OF_chain((void *)reloc, end - (char *)reloc, (void *)entry,97(void *)mdp, 0xfb5d104d);98}99100panic("exec returned");101}102103struct file_format ofw_elf64 =104{105ppc64_ofw_elf_loadfile,106ppc64_ofw_elf_exec107};108109110