4 * Copyright (C) 2013, 2014 Red Hat, Inc.
5 * Author: Mark Salter <msalter@redhat.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/linkage.h>
13 #include <linux/init.h>
15 #include <asm/assembler.h>
17 #define EFI_LOAD_ERROR 0x8000000000000001
22 * We arrive here from the EFI boot manager with:
24 * * CPU in little-endian mode
25 * * MMU on with identity-mapped RAM
26 * * Icache and Dcache on
28 * We will most likely be running from some place other than where
29 * we want to be. The kernel image wants to be placed at TEXT_OFFSET
34 * Create a stack frame to save FP/LR with extra space
35 * for image_addr variable passed to efi_entry().
37 stp x29, x30, [sp, #-32]!
40 * Call efi_entry to do the real work.
41 * x0 and x1 are already set up by firmware. Current runtime
42 * address of image is calculated and passed via *image_addr.
44 * unsigned long efi_entry(void *handle,
45 * efi_system_table_t *sys_table,
46 * unsigned long *image_addr) ;
49 add x8, x8, #:lo12:_text
57 * efi_entry() will have copied the kernel image if necessary and we
58 * return here with device tree address in x0 and the kernel entry
59 * point stored at *image_addr. Save those values in registers which
60 * are callee preserved.
62 mov x20, x0 // DTB address
63 ldr x0, [sp, #16] // relocated _text address
64 ldr x21, =stext_offset
68 * Calculate size of the kernel Image (same for original and copy).
71 add x1, x1, #:lo12:_text
73 add x2, x2, #:lo12:_edata
77 * Flush the copied Image to the PoC, and ensure it is not shadowed by
78 * stale icache entries from before relocation.
80 bl __flush_dcache_area
84 * Ensure that the rest of this function (in the original Image) is
85 * visible when the caches are disabled. The I-cache can't have stale
86 * entries for the VA range of the current image, so no maintenance is
92 bl __flush_dcache_area
94 /* Turn off Dcache and MMU */
96 cmp x0, #CurrentEL_EL2
99 bic x0, x0, #1 << 0 // clear SCTLR.M
100 bic x0, x0, #1 << 2 // clear SCTLR.C
106 bic x0, x0, #1 << 0 // clear SCTLR.M
107 bic x0, x0, #1 << 2 // clear SCTLR.C
111 /* Jump to kernel entry point */
119 mov x0, #EFI_LOAD_ERROR
120 ldp x29, x30, [sp], #32