1 // 32bit code to Power On Self Test (POST) a machine.
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "ioport.h" // PORT_*
9 #include "config.h" // CONFIG_*
10 #include "cmos.h" // CMOS_*
11 #include "util.h" // memset
12 #include "biosvar.h" // struct bios_data_area_s
13 #include "disk.h" // floppy_drive_setup
14 #include "ata.h" // ata_setup
15 #include "memmap.h" // add_e820
16 #include "pic.h" // pic_setup
17 #include "pci.h" // create_pirtable
18 #include "acpi.h" // acpi_bios_init
19 #include "bregs.h" // struct bregs
20 #include "mptable.h" // mptable_init
21 #include "boot.h" // IPL
22 #include "usb.h" // usb_setup
23 #include "smbios.h" // smbios_init
24 #include "paravirt.h" // qemu_cfg_port_probe
27 __set_irq(int vector, void *loc)
29 SET_IVT(vector, SEGOFF(SEG_BIOS, (u32)loc - BUILD_BIOS_ADDR));
32 #define set_irq(vector, func) do { \
33 extern void func (void); \
34 __set_irq(vector, func); \
40 dprintf(3, "init ivt\n");
42 // Initialize all vectors to the default handler.
45 set_irq(i, entry_iret_official);
47 // Initialize all hw vectors to a default hw handler.
48 for (i=0x08; i<=0x0f; i++)
49 set_irq(i, entry_hwpic1);
50 for (i=0x70; i<=0x77; i++)
51 set_irq(i, entry_hwpic2);
53 // Initialize software handlers.
54 set_irq(0x02, entry_02);
55 set_irq(0x10, entry_10);
56 set_irq(0x11, entry_11);
57 set_irq(0x12, entry_12);
58 set_irq(0x13, entry_13_official);
59 set_irq(0x14, entry_14);
60 set_irq(0x15, entry_15);
61 set_irq(0x16, entry_16);
62 set_irq(0x17, entry_17);
63 set_irq(0x18, entry_18);
64 set_irq(0x19, entry_19_official);
65 set_irq(0x1a, entry_1a);
66 set_irq(0x40, entry_40);
68 // set vector 0x79 to zero
69 // this is used by 'gardian angel' protection system
70 SET_IVT(0x79, SEGOFF(0, 0));
72 __set_irq(0x1E, &diskette_param_table2);
78 dprintf(3, "init bda\n");
80 struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0);
81 memset(bda, 0, sizeof(*bda));
83 int esize = EBDA_SIZE_START;
84 SET_BDA(mem_size_kb, BUILD_LOWRAM_END/1024 - esize);
85 u16 eseg = EBDA_SEGMENT_START;
86 SET_BDA(ebda_seg, eseg);
89 struct extended_bios_data_area_s *ebda = get_ebda_ptr();
90 memset(ebda, 0, sizeof(*ebda));
97 dprintf(3, "Find memory size\n");
98 if (CONFIG_COREBOOT) {
101 // On emulators, get memory size from nvram.
102 u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
103 | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24));
105 rs += 16 * 1024 * 1024;
107 rs = (((inb_cmos(CMOS_MEM_EXTMEM_LOW) << 10)
108 | (inb_cmos(CMOS_MEM_EXTMEM_HIGH) << 18))
111 add_e820(0, rs, E820_RAM);
113 // Check for memory over 4Gig
114 u64 high = ((inb_cmos(CMOS_MEM_HIGHMEM_LOW) << 16)
115 | (inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24)
116 | ((u64)inb_cmos(CMOS_MEM_HIGHMEM_HIGH) << 32));
117 RamSizeOver4G = high;
118 add_e820(0x100000000ull, high, E820_RAM);
120 /* reserve 256KB BIOS area at the end of 4 GB */
121 add_e820(0xfffc0000, 256*1024, E820_RESERVED);
124 // Don't declare any memory between 0xa0000 and 0x100000
125 add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE);
127 // Mark known areas as reserved.
128 u16 ebda_seg = get_ebda_seg();
129 add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024
131 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
133 if (kvm_para_available())
134 // 4 pages before the bios, 3 pages for vmx tss pages, the
135 // other page for EPT real mode pagetable
136 add_e820(0xfffbc000, 4*4096, E820_RESERVED);
138 dprintf(1, "Ram Size=0x%08x\n", RamSize);
142 init_bios_tables(void)
144 if (CONFIG_COREBOOT) {
145 coreboot_copy_biostable();
165 qemu_cfg_port_probe();
212 // 32-bit entry point.
218 debug_serial_setup();
219 dprintf(1, "Start bios (version %s)\n", VERSION);
221 // Allow writes to modify bios area (0xf0000)
222 make_bios_writable();
224 // Perform main setup code.
227 // Setup bios checksum.
228 BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE);
230 // Write protect bios memory.
231 make_bios_readonly();
233 // Invoke int 19 to start boot process.
234 dprintf(3, "Jump to int19\n");
236 memset(&br, 0, sizeof(br));
238 call16_int(0x19, &br);