2 #include <linux/memblock.h>
4 #include <asm/cacheflush.h>
5 #include <asm/pgtable.h>
6 #include <asm/realmode.h>
8 unsigned char *real_mode_base;
9 struct real_mode_header real_mode_header;
11 void __init setup_real_mode(void)
21 struct real_mode_header *header =
22 (struct real_mode_header *) real_mode_blob;
24 size_t size = PAGE_ALIGN(header->end);
26 /* Has to be in very low memory so we can execute real-mode AP code. */
27 mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE);
29 panic("Cannot allocate trampoline\n");
31 real_mode_base = __va(mem);
32 memblock_reserve(mem, size);
34 printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
35 real_mode_base, (unsigned long long)mem, size);
37 memcpy(real_mode_base, real_mode_blob, size);
39 real_mode_seg = __pa(real_mode_base) >> 4;
40 rel = (u32 *) real_mode_relocs;
42 /* 16-bit segment relocations. */
45 for (i = 0; i < count; i++) {
46 seg = (u16 *) (real_mode_base + rel[i]);
50 /* 32-bit linear relocations. */
53 for (i = 0; i < count; i++) {
54 ptr = (u32 *) (real_mode_base + rel[i]);
55 *ptr += __pa(real_mode_base);
58 /* Copied header will contain relocated physical addresses. */
59 memcpy(&real_mode_header, real_mode_base,
60 sizeof(struct real_mode_header));
64 * set_real_mode_permissions() gets called very early, to guarantee the
65 * availability of low memory. This is before the proper kernel page
66 * tables are set up, so we cannot set page permissions in that
67 * function. Thus, we use an arch_initcall instead.
69 static int __init set_real_mode_permissions(void)
72 PAGE_ALIGN(real_mode_header.end) -
75 set_memory_x((unsigned long) real_mode_base, all_size >> PAGE_SHIFT);
79 arch_initcall(set_real_mode_permissions);