blob: 232502753ff8b515045becba7a2f4390ee071a64 [file] [log] [blame]
Stefan Reinauer3b314022009-10-26 17:04:28 +00001/*
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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <types.h>
21#include <string.h>
22#include <cbmem.h>
23#include <console/console.h>
24
25// Global Descriptor Table, defined in c_start.S
26extern char gdt;
27extern char gdt_end;
28
29/* i386 lgdt argument */
30struct gdtarg {
31 u16 limit;
32 u32 base;
33} __attribute__((packed));
34
35// Copy GDT to new location and reload it
36void move_gdt(void)
37{
38 void *newgdt;
39 u16 num_gdt_bytes = &gdt_end - &gdt;
40 struct gdtarg gdtarg;
41
42 newgdt = cbmem_find(CBMEM_ID_GDT);
43 if (!newgdt) {
44 newgdt = cbmem_add(CBMEM_ID_GDT, ALIGN(num_gdt_bytes, 512));
45 if (!newgdt) {
46 printk(BIOS_ERR, "Error: Could not relocate GDT.\n");
47 return;
48 }
49 printk_debug("Moving GDT to %#lx...", newgdt);
50 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
51 }
52
53 gdtarg.base = newgdt;
54 gdtarg.limit = num_gdt_bytes - 1;
55
56 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
57 printk_debug("ok\n");
58}
59