From: Ram Pai <linuxram@us.ibm.com>
To: grub-devel@gnu.org
Cc: tlfalcon@linux.vnet.ibm.com, tbberry@us.ibm.com,
anton@au1.ibm.com, linuxram@us.ibm.com, tonyb@au1.ibm.com,
Anton Blanchard <anton@samba.org>
Subject: [RFC PATCH 12/23] Add powerpc64 ieee1275 trampoline
Date: Wed, 26 Feb 2014 10:31:11 -0800 [thread overview]
Message-ID: <1393439482-20341-13-git-send-email-linuxram@us.ibm.com> (raw)
In-Reply-To: <1393439482-20341-1-git-send-email-linuxram@us.ibm.com>
From: Anton Blanchard <anton@samba.org>
Add a trampoline so a 64bit grub can call a 32 bit OF
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
From: Anton Blanchard <anton@samba.org>
---
grub-core/Makefile.core.def | 2 +
grub-core/kern/powerpc/ieee1275/entry.S | 150 +++++++++++++++++++++++++++++++
include/grub/powerpc/ieee1275/ieee1275.h | 6 ++
3 files changed, 158 insertions(+)
create mode 100644 grub-core/kern/powerpc/ieee1275/entry.S
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index c6e70bb..0c80fe4 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -256,9 +256,11 @@ kernel = {
powerpc_ieee1275 = kern/powerpc/cache.S;
powerpc_ieee1275 = kern/powerpc/dl.c;
+ powerpc_ieee1275 = kern/powerpc/ieee1275/entry.S;
powerpc64le_ieee1275 = kern/powerpc/cache.S;
powerpc64le_ieee1275 = kern/powerpc/dl.c;
+ powerpc64le_ieee1275 = kern/powerpc/ieee1275/entry.S;
sparc64_ieee1275 = kern/sparc64/cache.S;
sparc64_ieee1275 = kern/sparc64/dl.c;
diff --git a/grub-core/kern/powerpc/ieee1275/entry.S b/grub-core/kern/powerpc/ieee1275/entry.S
new file mode 100644
index 0000000..5d58149
--- /dev/null
+++ b/grub-core/kern/powerpc/ieee1275/entry.S
@@ -0,0 +1,150 @@
+/* entry.S - open firmware call entry and return */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004,2007,2010,2014 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 <ppc-asm.h>
+
+#define STACK_FRAME_SIZE (48 + 64 + 16 + 144)
+#define MSR_OFFSET (48 + 64)
+#define R13_OFFSET (MSR_OFFSET + 8)
+#define NVREG_OFFSET(i) (STACK_FRAME_SIZE - (32-(i))*8)
+#define SAVE_NVGPR(A) std (A),NVREG_OFFSET(A)(r1)
+#define REST_NVGPR(A) ld (A),NVREG_OFFSET(A)(r1)
+#define SPRN_SRR0 0x01A
+#define SPRN_SRR1 0x01B
+#define r1 sp
+
+
+#if defined(_CALL_ELF) && _CALL_ELF == 1 /* BIG ENDIAN */
+#define TOC_OFFSET 40
+#define r2 toc
+#endif
+
+/*
+ * OF runs in 32 bit mode so it clobbers the high 32 bits of all registers
+ * it saves. We save and restore all the non volatile registers to avoid
+ * this issue.
+ *
+ * unsigned int ieee1275_call_entry_fn(void *args, unsigned long entry);
+ */
+FUNC_START(ieee1275_call_entry_fn)
+ mflr r0
+ std r0,16(r1)
+ stdu r1,-STACK_FRAME_SIZE(r1)
+
+#if defined(_CALL_ELF) && _CALL_ELF == 1 /* BIG ENDIAN */
+ std r2,TOC_OFFSET(r1)
+#endif
+ std r13,R13_OFFSET(r1)
+
+ SAVE_NVGPR(r14)
+ SAVE_NVGPR(r15)
+ SAVE_NVGPR(r16)
+ SAVE_NVGPR(r17)
+ SAVE_NVGPR(r18)
+ SAVE_NVGPR(r19)
+ SAVE_NVGPR(r20)
+ SAVE_NVGPR(r21)
+ SAVE_NVGPR(r22)
+ SAVE_NVGPR(r23)
+ SAVE_NVGPR(r24)
+ SAVE_NVGPR(r25)
+ SAVE_NVGPR(r26)
+ SAVE_NVGPR(r27)
+ SAVE_NVGPR(r28)
+ SAVE_NVGPR(r29)
+ SAVE_NVGPR(r30)
+ SAVE_NVGPR(r31)
+
+ mfmsr r31
+ std r31, MSR_OFFSET(r1)
+
+ /* Clear 64bit mode */
+ rldicl r31,r31,0,1
+
+#if defined(_CALL_ELF) && _CALL_ELF == 2 /* LITTLE ENDIAN */
+ /* Clear LE mode */
+ rldicr r31,r31,0,62
+#endif
+
+ mtspr SPRN_SRR0,r4
+ mtspr SPRN_SRR1,r31
+
+ /* Point the LR at our return code */
+ bl 1f
+1: mflr r30
+ addi r30,r30,(2f - 1b)
+ mtlr r30
+
+ /* Call OF */
+ rfid
+
+#if defined(_CALL_ELF) && _CALL_ELF == 2 /* LITTLE ENDIAN */
+2: .long 0x05009f42 /* bcl 20,31,$+4 */
+ .long 0xa602487d /* mflr r10 */
+ .long 0x1c004a39 /* addi r10,r10,28 */
+ .long 0xa6035a7d /* mtsrr0 r10 */
+ .long 0xa600407d /* mfmsr r10 */
+ .long 0x01004a69 /* xori r10,r10,1 */
+ .long 0xa6035b7d /* mtsrr1 r10 */
+ .long 0x2400004c /* rfid */
+#endif
+
+ /* Clear the top 32 bits of r1, just in case */
+2: rldicl r1,r1,0,32
+
+ /* Reset our MSR */
+ ld r31,MSR_OFFSET(r1)
+ mtspr SPRN_SRR1,r31
+
+ bl 3f
+3: mflr r30
+ addi r30,r30,(4f - 3b)
+ mtspr SPRN_SRR0,r30
+
+ rfid
+
+#if defined(_CALL_ELF) && _CALL_ELF == 1 /* BIG ENDIAN */
+4: ld r2,TOC_OFFSET(r1)
+#endif
+4: ld r13,R13_OFFSET(r1)
+
+ REST_NVGPR(r14)
+ REST_NVGPR(r15)
+ REST_NVGPR(r16)
+ REST_NVGPR(r17)
+ REST_NVGPR(r18)
+ REST_NVGPR(r19)
+ REST_NVGPR(r20)
+ REST_NVGPR(r21)
+ REST_NVGPR(r22)
+ REST_NVGPR(r23)
+ REST_NVGPR(r24)
+ REST_NVGPR(r25)
+ REST_NVGPR(r26)
+ REST_NVGPR(r27)
+ REST_NVGPR(r28)
+ REST_NVGPR(r29)
+ REST_NVGPR(r30)
+ REST_NVGPR(r31)
+
+ addi r1,r1,STACK_FRAME_SIZE
+ ld r0,16(r1)
+ mtlr r0
+ blr
+FUNC_END(ieee1275_call_entry_fn)
diff --git a/include/grub/powerpc/ieee1275/ieee1275.h b/include/grub/powerpc/ieee1275/ieee1275.h
index 3c7683f..14bdc43 100644
--- a/include/grub/powerpc/ieee1275/ieee1275.h
+++ b/include/grub/powerpc/ieee1275/ieee1275.h
@@ -25,4 +25,10 @@
#define GRUB_IEEE1275_CELL_SIZEOF 4
typedef grub_uint32_t grub_ieee1275_cell_t;
+#ifdef __powerpc64__
+int EXPORT_FUNC(ieee1275_call_entry_fn)(void *args, void *entry);
+#define IEEE1275_CALL_ENTRY_FN(args) \
+ ieee1275_call_entry_fn((args), grub_ieee1275_entry_fn)
+#endif
+
#endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
--
1.8.5.3
next prev parent reply other threads:[~2014-02-26 18:32 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-26 18:30 [RFC PATCH 00/23] grub 64bit little-endian on power Ram Pai
2014-02-26 18:31 ` [RFC PATCH 01/23] Add a new architecture to the build process Ram Pai
2014-02-26 18:31 ` [RFC PATCH 02/23] Build LE grub as O1 Ram Pai
2014-02-26 18:31 ` [RFC PATCH 03/23] ignore .TOC. symbol Ram Pai
2014-04-01 16:52 ` Andrey Borzenkov
2014-02-26 18:31 ` [RFC PATCH 04/23] grub-install can now recognize and install a LE grub boot loader Ram Pai
2014-02-26 18:31 ` [RFC PATCH 05/23] set ABI version in e_flag of the PPC64LE ELF image Ram Pai
2014-02-26 18:31 ` [RFC PATCH 06/23] Add IEEE1275_ADDR helper Ram Pai
2014-04-01 17:11 ` Andrey Borzenkov
2014-02-26 18:31 ` [RFC PATCH 07/23] Fix some more warnings when casting Ram Pai
2014-02-26 18:31 ` [RFC PATCH 08/23] Add powerpc64 types Ram Pai
2014-04-01 17:15 ` Andrey Borzenkov
2014-04-02 17:02 ` Ram Pai
2014-02-26 18:31 ` [RFC PATCH 09/23] Fix warnings when building powerpc linux loader 64bit Ram Pai
2014-04-01 17:21 ` Andrey Borzenkov
2014-04-02 17:03 ` Ram Pai
2014-02-26 18:31 ` [RFC PATCH 10/23] GRUB_ELF_R_PPC_* processing is applicable only for 32 bit bootloader Ram Pai
2014-02-26 18:31 ` [RFC PATCH 11/23] Fix powerpc setjmp/longjmp 64bit issues Ram Pai
2014-04-01 17:27 ` Andrey Borzenkov
2014-04-02 17:06 ` Ram Pai
2014-04-02 17:19 ` Andrey Borzenkov
2014-04-02 17:48 ` Ram Pai
2014-04-02 17:56 ` Andrey Borzenkov
2014-04-02 18:55 ` Ram Pai
2014-02-26 18:31 ` Ram Pai [this message]
2014-02-26 18:31 ` [RFC PATCH 13/23] Add 64bit support to powerpc startup code Ram Pai
2014-02-26 18:31 ` [RFC PATCH 14/23] Add grub_dl_find_section_addr Ram Pai
2014-02-26 18:31 ` [RFC PATCH 15/23] Add ppc64 relocations Ram Pai
2014-02-26 18:31 ` [RFC PATCH 16/23] ppc64 doesn't need libgcc routines Ram Pai
2014-02-26 18:31 ` [RFC PATCH 17/23] Use FUNC_START/FUNC_END for powerpc function definitions Ram Pai
2014-02-26 18:31 ` [RFC PATCH 18/23] .TOC. symbol is special in ppc64le Ram Pai
2014-02-26 18:31 ` [RFC PATCH 19/23] align .toc section on 4byte boundary Ram Pai
2014-02-26 18:31 ` [RFC PATCH 20/23] fix parameter to firmware calls Ram Pai
2014-04-01 17:45 ` Andrey Borzenkov
2014-04-02 17:08 ` Ram Pai
2014-04-02 17:16 ` Andrey Borzenkov
2014-02-26 18:31 ` [RFC PATCH 21/23] powerpc64 is not necessarily BigEndian anymore! :) Ram Pai
2014-04-01 17:49 ` Andrey Borzenkov
2014-04-01 20:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-04-03 17:33 ` Ram Pai
2014-04-03 17:53 ` Andrey Borzenkov
2014-04-03 18:37 ` Ram Pai
2014-04-03 19:03 ` Andrey Borzenkov
2014-04-03 19:26 ` Ram Pai
2014-04-03 19:42 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-04-03 20:23 ` Ram Pai
2014-04-03 19:54 ` Andrey Borzenkov
2014-04-03 20:32 ` Ram Pai
2014-04-03 21:41 ` Vladimir 'phcoder' Serbinenko
2014-04-04 2:28 ` Andrey Borzenkov
2014-04-04 17:47 ` Ram Pai
2014-04-04 18:17 ` Andrey Borzenkov
2014-04-04 18:24 ` Dinar Valeev
2014-04-04 19:12 ` Andrey Borzenkov
2014-04-04 20:29 ` Dinar Valeev
2014-04-04 22:19 ` Ram Pai
[not found] ` <CAEaD8JN9SkqU9+BkU2MYub=aC3Wb143nMPgRWjVbFvgit90yBQ@mail.gmail.com>
2014-04-05 0:04 ` Fwd: " Vladimir 'phcoder' Serbinenko
2014-09-27 5:42 ` Andrei Borzenkov
2014-09-28 6:33 ` Andrei Borzenkov
2014-04-04 6:37 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-04-04 17:08 ` Andrey Borzenkov
2014-04-05 15:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-04-05 16:49 ` Andrey Borzenkov
2014-04-05 18:29 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-04-05 18:48 ` Andrey Borzenkov
2014-04-02 17:09 ` Ram Pai
2014-02-26 18:31 ` [RFC PATCH 22/23] fix segfaults if initrd Ram Pai
2014-02-26 18:31 ` [RFC PATCH 23/23] Optional: Power7 VSX instructions workaround Ram Pai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393439482-20341-13-git-send-email-linuxram@us.ibm.com \
--to=linuxram@us.ibm.com \
--cc=anton@au1.ibm.com \
--cc=anton@samba.org \
--cc=grub-devel@gnu.org \
--cc=tbberry@us.ibm.com \
--cc=tlfalcon@linux.vnet.ibm.com \
--cc=tonyb@au1.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).