diff options
author | Simon Glass <sjg@chromium.org> | 2014-10-10 08:21:55 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-10-28 20:43:47 -0600 |
commit | 200182a748afd430da97b707dc5dff53c3147b5f (patch) | |
tree | 6552542960e3ed576811f85ba8431d1566542c32 /arch/x86/cpu/cpu.c | |
parent | 92cc94a1fe8e7a3ec78e993ea1ff1dd0bbaa5c36 (diff) | |
download | u-boot-imx-200182a748afd430da97b707dc5dff53c3147b5f.zip u-boot-imx-200182a748afd430da97b707dc5dff53c3147b5f.tar.gz u-boot-imx-200182a748afd430da97b707dc5dff53c3147b5f.tar.bz2 |
x86: Add support for starting 64-bit kernel
Add code to jump to a 64-bit Linux kernel. We need to set up a flat page
table structure, a new GDT and then go through a few hoops in the right
order.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/x86/cpu/cpu.c')
-rw-r--r-- | arch/x86/cpu/cpu.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index 8c1eacc..2e25253 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -18,7 +18,10 @@ #include <common.h> #include <command.h> +#include <errno.h> +#include <malloc.h> #include <asm/control_regs.h> +#include <asm/cpu.h> #include <asm/processor.h> #include <asm/processor-flags.h> #include <asm/interrupt.h> @@ -339,3 +342,45 @@ int print_cpuinfo(void) return 0; } + +#define PAGETABLE_SIZE (6 * 4096) + +/** + * build_pagetable() - build a flat 4GiB page table structure for 64-bti mode + * + * @pgtable: Pointer to a 24iKB block of memory + */ +static void build_pagetable(uint32_t *pgtable) +{ + uint i; + + memset(pgtable, '\0', PAGETABLE_SIZE); + + /* Level 4 needs a single entry */ + pgtable[0] = (uint32_t)&pgtable[1024] + 7; + + /* Level 3 has one 64-bit entry for each GiB of memory */ + for (i = 0; i < 4; i++) { + pgtable[1024 + i * 2] = (uint32_t)&pgtable[2048] + + 0x1000 * i + 7; + } + + /* Level 2 has 2048 64-bit entries, each repesenting 2MiB */ + for (i = 0; i < 2048; i++) + pgtable[2048 + i * 2] = 0x183 + (i << 21UL); +} + +int cpu_jump_to_64bit(ulong setup_base, ulong target) +{ + uint32_t *pgtable; + + pgtable = memalign(4096, PAGETABLE_SIZE); + if (!pgtable) + return -ENOMEM; + + build_pagetable(pgtable); + cpu_call64((ulong)pgtable, setup_base, target); + free(pgtable); + + return -EFAULT; +} |