1 // Main VGA bios initialization
3 // Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "biosvar.h" // SET_BDA
9 #include "bregs.h" // struct bregs
10 #include "hw/pci.h" // pci_config_readw
11 #include "hw/pci_regs.h" // PCI_VENDOR_ID
12 #include "hw/serialio.h" // serial_debug_preinit
13 #include "output.h" // dprintf
14 #include "std/optionrom.h" // struct pci_data
15 #include "std/pmm.h" // struct pmmheader
16 #include "string.h" // checksum_far
17 #include "util.h" // VERSION
18 #include "vgabios.h" // video_save_pointer_table
19 #include "vgahw.h" // vgahw_setup
21 struct video_save_pointer_s video_save_pointer_table VAR16;
23 struct video_param_s video_param_table[29] VAR16;
25 // Type of emulator platform - for dprintf with certain compile options.
26 int PlatformRunningOn VAR16;
29 /****************************************************************
31 ****************************************************************/
33 struct pci_data rom_pci_data VAR16 VISIBLE16 = {
34 .signature = PCI_ROM_SIGNATURE,
35 .vendor = CONFIG_VGA_VID,
36 .device = CONFIG_VGA_DID,
40 .type = PCIROM_CODETYPE_X86,
45 /****************************************************************
46 * PMM call and extra stack setup
47 ****************************************************************/
49 u16 ExtraStackSeg VAR16 VISIBLE16;
52 allocate_extra_stack(void)
54 if (!CONFIG_VGA_ALLOCATE_EXTRA_STACK)
57 for (pmmscan=0; pmmscan < BUILD_BIOS_SIZE; pmmscan+=16) {
58 struct pmmheader *pmm = (void*)pmmscan;
59 if (GET_FARVAR(SEG_BIOS, pmm->signature) != PMM_SIGNATURE)
61 if (checksum_far(SEG_BIOS, pmm, GET_FARVAR(SEG_BIOS, pmm->length)))
63 struct segoff_s entry = GET_FARVAR(SEG_BIOS, pmm->entry);
64 dprintf(1, "Attempting to allocate VGA stack via pmm call to %04x:%04x\n"
65 , entry.seg, entry.offset);
69 "pushw $(8|1)\n" // Permanent low memory request
70 "pushl $0xffffffff\n" // Anonymous handle
71 "pushl $" __stringify(CONFIG_VGA_EXTRA_STACK_SIZE/16) "\n"
72 "pushw $0x00\n" // PMM allocation request
77 : "+r" (entry.segoff), "=a" (res1), "=d" (res2) : : "cc", "memory");
78 u32 res = res1 | (res2 << 16);
79 if (!res || res == PMM_FUNCTION_NOT_SUPPORTED)
81 dprintf(1, "VGA stack allocated at %x\n", res);
82 SET_VGA(ExtraStackSeg, res >> 4);
83 extern void entry_10_extrastack(void);
84 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10_extrastack));
90 /****************************************************************
92 ****************************************************************/
94 struct segoff_s Timer_Hook_Resume VAR16 VISIBLE16;
97 handle_timer_hook(void)
99 if (!vga_emulate_text())
101 vgafb_set_swcursor(GET_BDA(timer_counter) % 18 < 9);
107 if (!CONFIG_VGA_EMULATE_TEXT)
109 extern void entry_timer_hook(void);
110 extern void entry_timer_hook_extrastack(void);
111 struct segoff_s oldirq = GET_IVT(0x08);
112 struct segoff_s newirq = SEGOFF(get_global_seg(), (u32)entry_timer_hook);
113 if (CONFIG_VGA_ALLOCATE_EXTRA_STACK && GET_GLOBAL(ExtraStackSeg))
114 newirq = SEGOFF(get_global_seg(), (u32)entry_timer_hook_extrastack);
115 dprintf(1, "Hooking hardware timer irq (old=%x new=%x)\n"
116 , oldirq.segoff, newirq.segoff);
117 SET_VGA(Timer_Hook_Resume, oldirq);
118 SET_IVT(0x08, newirq);
122 /****************************************************************
124 ****************************************************************/
129 // init detected hardware BIOS Area
130 // set 80x25 color (not clear from RBIL but usual)
131 set_equipment_flags(0x30, 0x20);
133 // Set the basic modeset options
134 SET_BDA(modeset_ctl, 0x51);
136 SET_BDA(dcc_index, CONFIG_VGA_STDVGA_PORTS ? 0x08 : 0xff);
137 SET_BDA(video_savetable
138 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
141 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
142 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
145 int VgaBDF VAR16 = -1;
146 int HaveRunInit VAR16;
149 vga_post(struct bregs *regs)
151 serial_debug_preinit();
152 dprintf(1, "Start SeaVGABIOS (version %s)\n", VERSION);
153 debug_enter(regs, DEBUG_VGA_POST);
155 if (CONFIG_VGA_PCI && !GET_GLOBAL(HaveRunInit)) {
157 if ((pci_config_readw(bdf, PCI_VENDOR_ID)
158 == GET_GLOBAL(rom_pci_data.vendor))
159 && (pci_config_readw(bdf, PCI_DEVICE_ID)
160 == GET_GLOBAL(rom_pci_data.device)))
161 SET_VGA(VgaBDF, bdf);
164 int ret = vgahw_setup();
166 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
170 if (GET_GLOBAL(HaveRunInit))
175 SET_VGA(video_save_pointer_table.videoparam
176 , SEGOFF(get_global_seg(), (u32)video_param_table));
177 if (CONFIG_VGA_STDVGA_PORTS)
178 stdvga_build_video_param();
180 extern void entry_10(void);
181 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
183 allocate_extra_stack();
187 SET_VGA(HaveRunInit, 1);
190 extern u8 _rom_header_size, _rom_header_checksum;
191 SET_VGA(_rom_header_checksum, 0);
192 u8 sum = -checksum_far(get_global_seg(), 0,
193 GET_GLOBAL(_rom_header_size) * 512);
194 SET_VGA(_rom_header_checksum, sum);