Two hda_verb.h files: Add more comments.
[coreboot.git] / src / arch / i386 / boot / gdt.c
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
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 <lib.h>
24 #include <console/console.h>
25
26 // Global Descriptor Table, defined in c_start.S
27 extern char gdt;
28 extern char gdt_end;
29
30 /* i386 lgdt argument */
31 struct gdtarg {
32         u16 limit;
33         u32 base;
34 } __attribute__((packed));
35
36 // Copy GDT to new location and reload it
37 void 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                 }
50                 printk(BIOS_DEBUG, "Moving GDT to %p...", newgdt);
51                 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
52         }
53
54         gdtarg.base = (u32)newgdt;
55         gdtarg.limit = num_gdt_bytes - 1;
56
57         __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
58         printk(BIOS_DEBUG, "ok\n");
59 }
60