blob: b425ade59d60f65150f2171add1d6b342f739352 [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>
Myles Watson58170782009-10-28 16:13:28 +000023#include <lib.h>
Stefan Reinauer3b314022009-10-26 17:04:28 +000024#include <console/console.h>
25
26// Global Descriptor Table, defined in c_start.S
27extern char gdt;
28extern char gdt_end;
29
30/* i386 lgdt argument */
31struct gdtarg {
32 u16 limit;
33 u32 base;
34} __attribute__((packed));
35
36// Copy GDT to new location and reload it
Stefan Reinauer3b314022009-10-26 17:04:28 +000037void move_gdt(void)
38{
39 void *newgdt;
40 u16 num_gdt_bytes = &gdt_end - &gdt;
41 struct gdtarg gdtarg;
42
43 newgdt = cbmem_find(CBMEM_ID_GDT);
44 if (!newgdt) {
45 newgdt = cbmem_add(CBMEM_ID_GDT, ALIGN(num_gdt_bytes, 512));
46 if (!newgdt) {
47 printk(BIOS_ERR, "Error: Could not relocate GDT.\n");
48 return;
49 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000050 printk(BIOS_DEBUG, "Moving GDT to %p...", newgdt);
Stefan Reinauer3b314022009-10-26 17:04:28 +000051 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
52 }
53
Uwe Hermann312673c2009-10-27 21:49:33 +000054 gdtarg.base = (u32)newgdt;
Stefan Reinauer3b314022009-10-26 17:04:28 +000055 gdtarg.limit = num_gdt_bytes - 1;
56
57 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000058 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer3b314022009-10-26 17:04:28 +000059}
60