Path: blob/main/stand/uboot/arch/powerpc/ppc64_elf_freebsd.c
34878 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 "libuboot.h"39#include "modinfo.h"4041int42ppc64_uboot_elf_loadfile(char *filename, uint64_t dest,43struct preloaded_file **result)44{45int r;4647r = __elfN(loadfile)(filename, dest, result);48if (r != 0)49return (r);5051/*52* No need to sync the icache for modules: this will53* be done by the kernel after relocation.54*/55if (!strcmp((*result)->f_type, md_kerntype))56__syncicache((void *) (*result)->f_addr, (*result)->f_size);57return (0);58}5960int61ppc64_uboot_elf_exec(struct preloaded_file *fp)62{63struct file_metadata *fmp;64vm_offset_t mdp, dtbp;65Elf_Ehdr *e;66int error;67void (*entry)(void *);6869if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) {70return(EFTYPE);71}72e = (Elf_Ehdr *)&fmp->md_data;7374/* Handle function descriptor for ELFv1 kernels */75if ((e->e_flags & 3) == 2)76entry = (void (*)(void*))(intptr_t)e->e_entry;77else78entry = *(void (*)(void*))(uint64_t *)(intptr_t)e->e_entry;7980if ((error = md_load64(fp->f_args, &mdp, &dtbp)) != 0)81return (error);8283dev_cleanup();84printf("Kernel args: %s\n", fp->f_args);8586(*entry)((void *)mdp);87panic("exec returned");88}8990struct file_format uboot_elf64 =91{92ppc64_uboot_elf_loadfile,93ppc64_uboot_elf_exec94};959697