2 /* 2006.1 yhlu add mptable cross 0x467 processing */
4 #include <console/console.h>
6 #include <boot/tables.h>
7 #include <boot/linuxbios_tables.h>
8 #include <arch/pirq_routing.h>
9 #include <arch/smp/mpspec.h>
10 #include <arch/acpi.h>
12 #include "linuxbios_table.h"
14 // Global Descriptor Table, defined in c_start.S
16 extern uint8_t gdt_end;
18 /* i386 lgdt argument */
22 } __attribute__((packed));
24 // Copy GDT to new location and reload it
25 // 2003-07 by SONE Takeshi
26 // Ported from Etherboot to LinuxBIOS 2005-08 by Steve Magnani
27 void move_gdt(unsigned long newgdt)
29 uint16_t num_gdt_bytes = &gdt_end - &gdt;
32 printk_debug("Moving GDT to %#lx...", newgdt);
33 memcpy((void*)newgdt, &gdt, num_gdt_bytes);
35 gdtarg.limit = num_gdt_bytes - 1;
36 __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
40 struct lb_memory *write_tables(void)
42 unsigned long low_table_start, low_table_end, new_low_table_end;
43 unsigned long rom_table_start, rom_table_end;
45 rom_table_start = 0xf0000;
46 rom_table_end = 0xf0000;
47 /* Start low addr at 16 bytes instead of 0 because of a buglet
48 * in the generic linux unzip code, as it tests for the a20 line.
55 /* This table must be betweeen 0xf0000 & 0x100000 */
56 rom_table_end = write_pirq_routing_table(rom_table_end);
57 rom_table_end = (rom_table_end + 1023) & ~1023;
59 /* Write ACPI tables */
60 /* write them in the rom area because DSDT can be large (8K on epia-m) which
61 * pushes linuxbios table out of first 4K if set up in low table area
63 rom_table_end = write_acpi_tables(rom_table_end);
64 rom_table_end = (rom_table_end+1023) & ~1023;
66 /* copy the smp block to address 0 */
69 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
70 new_low_table_end = write_smp_table(low_table_end); // low_table_end is 0x10 at this point
73 /* Don't write anything in the traditional x86 BIOS data segment,
74 * for example the linux kernel smp need to use 0x467 to pass reset vector
76 if(new_low_table_end>0x467){
77 unsigned mptable_size;
79 low_table_end += SMP_FLOATING_TABLE_LEN; /* keep the mpf in 1k low, so kernel can find it */
80 mptable_size = new_low_table_end - low_table_end;
81 /* We can not put mptable low, we need to copy them to somewhere else*/
82 if((rom_table_end+mptable_size)<0x100000) {
83 /* We can copy mptable on rom_table */
84 mpc_start = rom_table_end;
85 rom_table_end += mptable_size;
86 rom_table_end = (rom_table_end+1023) & ~1023;
88 /* We can need to put mptable before rom_table */
89 mpc_start = rom_table_start - mptable_size;
91 rom_table_start = mpc_start;
93 printk_debug("move mptable from 0x%0x to 0x%0x, size 0x%0x\n", low_table_end, mpc_start, mptable_size);
94 memcpy((unsigned char *)mpc_start, (unsigned char *)low_table_end, mptable_size);
95 smp_write_floating_table_physaddr(low_table_end - SMP_FLOATING_TABLE_LEN, mpc_start);
96 memset((unsigned char *)low_table_end, '\0', mptable_size);
100 if (low_table_end < 0x500) {
101 low_table_end = 0x500;
104 // Relocate the GDT to reserved memory, so it won't get clobbered
105 move_gdt(low_table_end);
106 low_table_end += &gdt_end - &gdt;
108 /* The linuxbios table must be in 0-4K or 960K-1M */
109 write_linuxbios_table(low_table_start, low_table_end,
110 rom_table_start, rom_table_end);