Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <types.h> |
| 21 | #include <string.h> |
| 22 | #include <cbmem.h> |
| 23 | #include <console/console.h> |
Kyösti Mälkki | bae775a | 2014-12-18 10:36:33 +0200 | [diff] [blame] | 24 | #include <cpu/x86/gdt.h> |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 25 | |
| 26 | /* i386 lgdt argument */ |
| 27 | struct gdtarg { |
| 28 | u16 limit; |
| 29 | u32 base; |
| 30 | } __attribute__((packed)); |
| 31 | |
Kyösti Mälkki | bae775a | 2014-12-18 10:36:33 +0200 | [diff] [blame] | 32 | /* Copy GDT to new location and reload it. |
| 33 | * FIXME: We only do this for BSP CPU. |
| 34 | */ |
Kyösti Mälkki | 4fbac46 | 2015-01-07 04:48:43 +0200 | [diff] [blame^] | 35 | static void move_gdt(void) |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 36 | { |
| 37 | void *newgdt; |
Kyösti Mälkki | bae775a | 2014-12-18 10:36:33 +0200 | [diff] [blame] | 38 | u16 num_gdt_bytes = (u32)&gdt_end - (u32)&gdt; |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 39 | struct gdtarg gdtarg; |
| 40 | |
| 41 | newgdt = cbmem_find(CBMEM_ID_GDT); |
| 42 | if (!newgdt) { |
| 43 | newgdt = cbmem_add(CBMEM_ID_GDT, ALIGN(num_gdt_bytes, 512)); |
| 44 | if (!newgdt) { |
| 45 | printk(BIOS_ERR, "Error: Could not relocate GDT.\n"); |
| 46 | return; |
| 47 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 48 | printk(BIOS_DEBUG, "Moving GDT to %p...", newgdt); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 49 | memcpy((void*)newgdt, &gdt, num_gdt_bytes); |
| 50 | } |
| 51 | |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 52 | gdtarg.base = (u32)newgdt; |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 53 | gdtarg.limit = num_gdt_bytes - 1; |
| 54 | |
| 55 | __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg)); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 56 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 57 | } |
Kyösti Mälkki | 4fbac46 | 2015-01-07 04:48:43 +0200 | [diff] [blame^] | 58 | RAMSTAGE_CBMEM_INIT_HOOK(move_gdt) |