diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:29:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:29:51 +0000 |
commit | 6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch) | |
tree | 32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /grub-core/kern/powerpc | |
parent | Initial commit. (diff) | |
download | grub2-upstream/2.06.tar.xz grub2-upstream/2.06.zip |
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | grub-core/kern/powerpc/cache.S | 26 | ||||
-rw-r--r-- | grub-core/kern/powerpc/cache_flush.S | 43 | ||||
-rw-r--r-- | grub-core/kern/powerpc/compiler-rt.S | 130 | ||||
-rw-r--r-- | grub-core/kern/powerpc/dl.c | 169 | ||||
-rw-r--r-- | grub-core/kern/powerpc/ieee1275/startup.S | 67 |
5 files changed, 435 insertions, 0 deletions
diff --git a/grub-core/kern/powerpc/cache.S b/grub-core/kern/powerpc/cache.S new file mode 100644 index 0000000..d85e68d --- /dev/null +++ b/grub-core/kern/powerpc/cache.S @@ -0,0 +1,26 @@ +/* cache.S - Flush the processor cache for a specific region. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007,2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + + .text + + .align 2 + .globl grub_arch_sync_caches +grub_arch_sync_caches: +#include "cache_flush.S" + blr diff --git a/grub-core/kern/powerpc/cache_flush.S b/grub-core/kern/powerpc/cache_flush.S new file mode 100644 index 0000000..1410f78 --- /dev/null +++ b/grub-core/kern/powerpc/cache_flush.S @@ -0,0 +1,43 @@ +/* cache.S - Flush the processor cache for a specific region. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007,2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#undef CACHE_LINE_BYTES +#define CACHE_LINE_BYTES 32 + + /* `address' may not be CACHE_LINE_BYTES-aligned. */ + andi. 6, 3, CACHE_LINE_BYTES - 1 /* Find the misalignment. */ + add 4, 4, 6 /* Adjust `size' to compensate. */ + + /* Force the dcache lines to memory. */ + li 5, 0 +1: dcbst 5, 3 + addi 5, 5, CACHE_LINE_BYTES + cmpw 5, 4 + blt 1b + sync /* Force all dcbsts to complete. */ + + /* Invalidate the icache lines. */ + li 5, 0 +1: icbi 5, 3 + addi 5, 5, CACHE_LINE_BYTES + cmpw 5, 4 + blt 1b + sync /* Force all icbis to complete. */ + isync /* Discard partially executed instructions that were + loaded from the invalid icache. */ diff --git a/grub-core/kern/powerpc/compiler-rt.S b/grub-core/kern/powerpc/compiler-rt.S new file mode 100644 index 0000000..b3b912d --- /dev/null +++ b/grub-core/kern/powerpc/compiler-rt.S @@ -0,0 +1,130 @@ +/* + * Special support for eabi and SVR4 + * + * Copyright (C) 1995-2014 Free Software Foundation, Inc. + * Written By Michael Meissner + * 64-bit support written by David Edelsohn + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 3, or (at your option) any + * later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * Under Section 7 of GPL version 3, you are granted additional + * permissions described in the GCC Runtime Library Exception, version + * 3.1, as published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License and + * a copy of the GCC Runtime Library Exception along with this program; + * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + * <http://www.gnu.org/licenses/>. + */ + +/* Do any initializations needed for the eabi environment */ + +#include <grub/symbol.h> +#include <grub/dl.h> + + .section ".text" + +#define CFI_RESTORE(reg) .cfi_restore reg +#define CFI_OFFSET(reg, off) .cfi_offset reg, off +#define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg +#define CFI_STARTPROC .cfi_startproc +#define CFI_ENDPROC .cfi_endproc + +/* Routines for restoring integer registers, called by the compiler. */ +/* Called with r11 pointing to the stack header word of the caller of the */ +/* function, just beyond the end of the integer restore area. */ + +CFI_STARTPROC +CFI_DEF_CFA_REGISTER (11) +CFI_OFFSET (65, 4) +CFI_OFFSET (14, -72) +CFI_OFFSET (15, -68) +CFI_OFFSET (16, -64) +CFI_OFFSET (17, -60) +CFI_OFFSET (18, -56) +CFI_OFFSET (19, -52) +CFI_OFFSET (20, -48) +CFI_OFFSET (21, -44) +CFI_OFFSET (22, -40) +CFI_OFFSET (23, -36) +CFI_OFFSET (24, -32) +CFI_OFFSET (25, -28) +CFI_OFFSET (26, -24) +CFI_OFFSET (27, -20) +CFI_OFFSET (28, -16) +CFI_OFFSET (29, -12) +CFI_OFFSET (30, -8) +CFI_OFFSET (31, -4) +FUNCTION(_restgpr_14_x) lwz 14,-72(11) /* restore gp registers */ +CFI_RESTORE (14) +FUNCTION(_restgpr_15_x) lwz 15,-68(11) +CFI_RESTORE (15) +FUNCTION(_restgpr_16_x) lwz 16,-64(11) +CFI_RESTORE (16) +FUNCTION(_restgpr_17_x) lwz 17,-60(11) +CFI_RESTORE (17) +FUNCTION(_restgpr_18_x) lwz 18,-56(11) +CFI_RESTORE (18) +FUNCTION(_restgpr_19_x) lwz 19,-52(11) +CFI_RESTORE (19) +FUNCTION(_restgpr_20_x) lwz 20,-48(11) +CFI_RESTORE (20) +FUNCTION(_restgpr_21_x) lwz 21,-44(11) +CFI_RESTORE (21) +FUNCTION(_restgpr_22_x) lwz 22,-40(11) +CFI_RESTORE (22) +FUNCTION(_restgpr_23_x) lwz 23,-36(11) +CFI_RESTORE (23) +FUNCTION(_restgpr_24_x) lwz 24,-32(11) +CFI_RESTORE (24) +FUNCTION(_restgpr_25_x) lwz 25,-28(11) +CFI_RESTORE (25) +FUNCTION(_restgpr_26_x) lwz 26,-24(11) +CFI_RESTORE (26) +FUNCTION(_restgpr_27_x) lwz 27,-20(11) +CFI_RESTORE (27) +FUNCTION(_restgpr_28_x) lwz 28,-16(11) +CFI_RESTORE (28) +FUNCTION(_restgpr_29_x) lwz 29,-12(11) +CFI_RESTORE (29) +FUNCTION(_restgpr_30_x) lwz 30,-8(11) +CFI_RESTORE (30) +FUNCTION(_restgpr_31_x) lwz 0,4(11) + lwz 31,-4(11) +CFI_RESTORE (31) + mtlr 0 +CFI_RESTORE (65) + mr 1,11 +CFI_DEF_CFA_REGISTER (1) + blr +CFI_ENDPROC + +CFI_STARTPROC +FUNCTION(_savegpr_14) stw 14,-72(11) /* save gp registers */ +FUNCTION(_savegpr_15) stw 15,-68(11) +FUNCTION(_savegpr_16) stw 16,-64(11) +FUNCTION(_savegpr_17) stw 17,-60(11) +FUNCTION(_savegpr_18) stw 18,-56(11) +FUNCTION(_savegpr_19) stw 19,-52(11) +FUNCTION(_savegpr_20) stw 20,-48(11) +FUNCTION(_savegpr_21) stw 21,-44(11) +FUNCTION(_savegpr_22) stw 22,-40(11) +FUNCTION(_savegpr_23) stw 23,-36(11) +FUNCTION(_savegpr_24) stw 24,-32(11) +FUNCTION(_savegpr_25) stw 25,-28(11) +FUNCTION(_savegpr_26) stw 26,-24(11) +FUNCTION(_savegpr_27) stw 27,-20(11) +FUNCTION(_savegpr_28) stw 28,-16(11) +FUNCTION(_savegpr_29) stw 29,-12(11) +FUNCTION(_savegpr_30) stw 30,-8(11) +FUNCTION(_savegpr_31) stw 31,-4(11) + blr +CFI_ENDPROC diff --git a/grub-core/kern/powerpc/dl.c b/grub-core/kern/powerpc/dl.c new file mode 100644 index 0000000..cdd61b3 --- /dev/null +++ b/grub-core/kern/powerpc/dl.c @@ -0,0 +1,169 @@ +/* dl.c - arch-dependent part of loadable module support */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <grub/dl.h> +#include <grub/elf.h> +#include <grub/misc.h> +#include <grub/err.h> +#include <grub/i18n.h> + +/* Check if EHDR is a valid ELF header. */ +grub_err_t +grub_arch_dl_check_header (void *ehdr) +{ + Elf_Ehdr *e = ehdr; + + /* Check the magic numbers. */ + if (e->e_ident[EI_CLASS] != ELFCLASS32 + || e->e_ident[EI_DATA] != ELFDATA2MSB + || e->e_machine != EM_PPC) + return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); + + return GRUB_ERR_NONE; +} + +/* For low-endian reverse lis and addr_high as well as ori and addr_low. */ +struct trampoline +{ + grub_uint32_t lis; + grub_uint32_t ori; + grub_uint32_t mtctr; + grub_uint32_t bctr; +}; + +static const struct trampoline trampoline_template = + { + 0x3d800000, + 0x618c0000, + 0x7d8903a6, + 0x4e800420, + }; + +#pragma GCC diagnostic ignored "-Wcast-align" + +grub_err_t +grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, + grub_size_t *got) +{ + const Elf_Ehdr *e = ehdr; + const Elf_Shdr *s; + unsigned i; + + *tramp = 0; + *got = 0; + + for (i = 0, s = (const Elf_Shdr *) ((const char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (const Elf_Shdr *) ((const char *) s + e->e_shentsize)) + if (s->sh_type == SHT_RELA) + { + const Elf_Rela *rel, *max; + + for (rel = (const Elf_Rela *) ((const char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) + if (ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_REL24 + || ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_PLTREL24) + (*tramp)++; + + } + + *tramp *= sizeof (struct trampoline); + + return GRUB_ERR_NONE; +} + +/* Relocate symbols. */ +grub_err_t +grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + Elf_Shdr *s, grub_dl_segment_t seg) +{ + Elf_Rela *rel, *max; + + for (rel = (Elf_Rela *) ((char *) ehdr + s->sh_offset), + max = (Elf_Rela *) ((char *) rel + s->sh_size); + rel < max; + rel = (Elf_Rela *) ((char *) rel + s->sh_entsize)) + { + Elf_Word *addr; + Elf_Sym *sym; + grub_uint32_t value; + + if (seg->size < rel->r_offset) + return grub_error (GRUB_ERR_BAD_MODULE, + "reloc offset is out of the segment"); + + addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset); + sym = (Elf_Sym *) ((char *) mod->symtab + + mod->symsize * ELF_R_SYM (rel->r_info)); + + /* On the PPC the value does not have an explicit + addend, add it. */ + value = sym->st_value + rel->r_addend; + switch (ELF_R_TYPE (rel->r_info)) + { + case GRUB_ELF_R_PPC_ADDR16_LO: + *(Elf_Half *) addr = value; + break; + + case GRUB_ELF_R_PPC_PLTREL24: + case GRUB_ELF_R_PPC_REL24: + { + Elf_Sword delta = value - (Elf_Word) addr; + + if (delta << 6 >> 6 != delta) + { + struct trampoline *tptr = mod->trampptr; + grub_memcpy (tptr, &trampoline_template, + sizeof (*tptr)); + delta = (grub_uint8_t *) tptr - (grub_uint8_t *) addr; + tptr->lis |= (((value) >> 16) & 0xffff); + tptr->ori |= ((value) & 0xffff); + mod->trampptr = tptr + 1; + } + + if (delta << 6 >> 6 != delta) + return grub_error (GRUB_ERR_BAD_MODULE, + "relocation overflow"); + *addr = (*addr & 0xfc000003) | (delta & 0x3fffffc); + break; + } + + case GRUB_ELF_R_PPC_ADDR16_HA: + *(Elf_Half *) addr = (value + 0x8000) >> 16; + break; + + case GRUB_ELF_R_PPC_ADDR32: + *addr = value; + break; + + case GRUB_ELF_R_PPC_REL32: + *addr = value - (Elf_Word) addr; + break; + + default: + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + N_("relocation 0x%x is not implemented yet"), + ELF_R_TYPE (rel->r_info)); + } + } + + return GRUB_ERR_NONE; +} diff --git a/grub-core/kern/powerpc/ieee1275/startup.S b/grub-core/kern/powerpc/ieee1275/startup.S new file mode 100644 index 0000000..21c884b --- /dev/null +++ b/grub-core/kern/powerpc/ieee1275/startup.S @@ -0,0 +1,67 @@ +/* startup.S - Startup code for the PowerPC. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <grub/symbol.h> +#include <grub/offsets.h> + +.extern __bss_start +.extern _end + + .text + .align 2 + .globl start, _start +start: +_start: + li 2, 0 + li 13, 0 + + /* Stage1 won't zero BSS for us. In other cases, why not do it again? */ + lis 6, (__bss_start - 4)@h + ori 6, 6, (__bss_start - 4)@l + +2: stb 2, 4(6) + addi 6, 6, 1 + andi. 7, 6, 3 + cmpi 0, 1, 7, 0 + bne 2b + + lis 7, (_end - 4)@h + ori 7, 7, (_end - 4)@l + subf 7, 6, 7 + subi 8, 7, 1 + andi. 8, 8, 3 + addi 8, 8, 1 + sub 7, 7, 8 + + srwi 7, 7, 2 /* We store 4 bytes at a time. */ + mtctr 7 +2: stwu 2, 4(6) /* We know r2 is already 0 from above. */ + bdnz 2b + + mtctr 8 +2: stb 2, 4(6) /* We know r2 is already 0 from above. */ + addi 6, 6, 1 + bdnz 2b + + /* Store r5 in grub_ieee1275_entry_fn. */ + lis 9, grub_ieee1275_entry_fn@ha + stw 5, grub_ieee1275_entry_fn@l(9) + + bl grub_main +1: b 1b |