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
25 #include "ps2port.h" // ps2port_setup
26 #include "virtio-blk.h" // virtio_blk_setup
29 __set_irq(int vector, void *loc)
31 SET_IVT(vector, SEGOFF(SEG_BIOS, (u32)loc - BUILD_BIOS_ADDR));
34 #define set_irq(vector, func) do { \
35 extern void func (void); \
36 __set_irq(vector, func); \
42 dprintf(3, "init ivt\n");
44 // Initialize all vectors to the default handler.
47 set_irq(i, entry_iret_official);
49 // Initialize all hw vectors to a default hw handler.
50 for (i=0x08; i<=0x0f; i++)
51 set_irq(i, entry_hwpic1);
52 for (i=0x70; i<=0x77; i++)
53 set_irq(i, entry_hwpic2);
55 // Initialize software handlers.
56 set_irq(0x02, entry_02);
57 set_irq(0x10, entry_10);
58 set_irq(0x11, entry_11);
59 set_irq(0x12, entry_12);
60 set_irq(0x13, entry_13_official);
61 set_irq(0x14, entry_14);
62 set_irq(0x15, entry_15);
63 set_irq(0x16, entry_16);
64 set_irq(0x17, entry_17);
65 set_irq(0x18, entry_18);
66 set_irq(0x19, entry_19_official);
67 set_irq(0x1a, entry_1a);
68 set_irq(0x40, entry_40);
70 // INT 60h-66h reserved for user interrupt
71 for (i=0x60; i<=0x66; i++)
72 SET_IVT(i, SEGOFF(0, 0));
74 // set vector 0x79 to zero
75 // this is used by 'gardian angel' protection system
76 SET_IVT(0x79, SEGOFF(0, 0));
78 __set_irq(0x1E, &diskette_param_table2);
84 dprintf(3, "init bda\n");
86 struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0);
87 memset(bda, 0, sizeof(*bda));
89 int esize = EBDA_SIZE_START;
90 SET_BDA(mem_size_kb, BUILD_LOWRAM_END/1024 - esize);
91 u16 eseg = EBDA_SEGMENT_START;
92 SET_BDA(ebda_seg, eseg);
95 struct extended_bios_data_area_s *ebda = get_ebda_ptr();
96 memset(ebda, 0, sizeof(*ebda));
103 dprintf(3, "Find memory size\n");
104 if (CONFIG_COREBOOT) {
107 // On emulators, get memory size from nvram.
108 u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
109 | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24));
111 rs += 16 * 1024 * 1024;
113 rs = (((inb_cmos(CMOS_MEM_EXTMEM_LOW) << 10)
114 | (inb_cmos(CMOS_MEM_EXTMEM_HIGH) << 18))
117 add_e820(0, rs, E820_RAM);
119 // Check for memory over 4Gig
120 u64 high = ((inb_cmos(CMOS_MEM_HIGHMEM_LOW) << 16)
121 | ((u32)inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24)
122 | ((u64)inb_cmos(CMOS_MEM_HIGHMEM_HIGH) << 32));
123 RamSizeOver4G = high;
124 add_e820(0x100000000ull, high, E820_RAM);
126 /* reserve 256KB BIOS area at the end of 4 GB */
127 add_e820(0xfffc0000, 256*1024, E820_RESERVED);
130 // Don't declare any memory between 0xa0000 and 0x100000
131 add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE);
133 // Mark known areas as reserved.
134 u16 ebda_seg = get_ebda_seg();
135 add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024
137 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
139 u32 count = qemu_cfg_e820_entries();
141 struct e820_reservation entry;
144 for (i = 0; i < count; i++) {
145 qemu_cfg_e820_load_next(&entry);
146 add_e820(entry.address, entry.length, entry.type);
148 } else if (kvm_para_available()) {
149 // Backwards compatibility - provide hard coded range.
150 // 4 pages before the bios, 3 pages for vmx tss pages, the
151 // other page for EPT real mode pagetable
152 add_e820(0xfffbc000, 4*4096, E820_RESERVED);
155 dprintf(1, "Ram Size=0x%08x (0x%08x%08x high)\n"
156 , RamSize, (u32)(RamSizeOver4G >> 32), (u32)RamSizeOver4G);
160 init_bios_tables(void)
162 if (CONFIG_COREBOOT) {
163 coreboot_copy_biostable();
176 // Initialize hardware devices
195 // Detect and init ram.
199 qemu_cfg_port_probe();
204 // Init base pc hardware.
217 // Initialize internal tables
222 // Start hardware initialization (if optionrom threading)
223 if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS)
226 // Find and initialize other cpus
229 // Setup interfaces that option roms may need
237 // Run vga option rom
240 // Do hardware initialization (if running synchronously)
241 if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) {
249 // Run BCVs and show optional boot menu
252 // Finalize data structures before boot
258 // 32-bit entry point.
264 debug_serial_setup();
265 dprintf(1, "Start bios (version %s)\n", VERSION);
267 // Allow writes to modify bios area (0xf0000)
268 make_bios_writable();
270 // Perform main setup code.
273 // Setup bios checksum.
274 BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE);
276 // Write protect bios memory.
277 make_bios_readonly();
279 // Invoke int 19 to start boot process.
280 dprintf(3, "Jump to int19\n");
282 memset(&br, 0, sizeof(br));
284 call16_int(0x19, &br);