Kevin O'Connor | dab0a74 | 2013-12-03 11:50:49 -0500 | [diff] [blame] | 1 | // Main VGA bios initialization |
| 2 | // |
| 3 | // Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2001-2008 the LGPL VGABios developers Team |
| 5 | // |
| 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 7 | |
| 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 "output.h" // dprintf |
| 13 | #include "std/optionrom.h" // struct pci_data |
| 14 | #include "std/pmm.h" // struct pmmheader |
| 15 | #include "string.h" // checksum_far |
| 16 | #include "util.h" // VERSION |
| 17 | #include "vgabios.h" // struct VideoSavePointer_s |
| 18 | #include "vgahw.h" // vgahw_setup |
| 19 | |
| 20 | // Standard Video Save Pointer Table |
| 21 | struct VideoSavePointer_s { |
| 22 | struct segoff_s videoparam; |
| 23 | struct segoff_s paramdynamicsave; |
| 24 | struct segoff_s textcharset; |
| 25 | struct segoff_s graphcharset; |
| 26 | struct segoff_s secsavepointer; |
| 27 | u8 reserved[8]; |
| 28 | } PACKED; |
| 29 | |
| 30 | struct VideoSavePointer_s video_save_pointer_table VAR16; |
| 31 | |
| 32 | struct VideoParam_s video_param_table[29] VAR16; |
| 33 | |
| 34 | |
| 35 | /**************************************************************** |
| 36 | * PCI Data |
| 37 | ****************************************************************/ |
| 38 | |
| 39 | struct pci_data rom_pci_data VAR16 VISIBLE16 = { |
| 40 | .signature = PCI_ROM_SIGNATURE, |
| 41 | .vendor = CONFIG_VGA_VID, |
| 42 | .device = CONFIG_VGA_DID, |
| 43 | .dlen = 0x18, |
| 44 | .class_hi = 0x300, |
| 45 | .irevision = 1, |
| 46 | .type = PCIROM_CODETYPE_X86, |
| 47 | .indicator = 0x80, |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | /**************************************************************** |
| 52 | * PMM call and extra stack setup |
| 53 | ****************************************************************/ |
| 54 | |
| 55 | u16 ExtraStackSeg VAR16 VISIBLE16; |
| 56 | |
| 57 | static void |
| 58 | allocate_extra_stack(void) |
| 59 | { |
| 60 | if (!CONFIG_VGA_ALLOCATE_EXTRA_STACK) |
| 61 | return; |
| 62 | void *pmmscan = (void*)BUILD_BIOS_ADDR; |
| 63 | for (; pmmscan < (void*)BUILD_BIOS_ADDR+BUILD_BIOS_SIZE; pmmscan+=16) { |
| 64 | struct pmmheader *pmm = pmmscan; |
| 65 | if (pmm->signature != PMM_SIGNATURE) |
| 66 | continue; |
| 67 | if (checksum_far(0, pmm, pmm->length)) |
| 68 | continue; |
| 69 | struct segoff_s entry = pmm->entry; |
| 70 | dprintf(1, "Attempting to allocate VGA stack via pmm call to %04x:%04x\n" |
| 71 | , entry.seg, entry.offset); |
| 72 | u16 res1, res2; |
| 73 | asm volatile( |
| 74 | "pushl %0\n" |
| 75 | "pushw $(8|1)\n" // Permanent low memory request |
| 76 | "pushl $0xffffffff\n" // Anonymous handle |
| 77 | "pushl $" __stringify(CONFIG_VGA_EXTRA_STACK_SIZE) "\n" |
| 78 | "pushw $0x00\n" // PMM allocation request |
| 79 | "lcallw *12(%%esp)\n" |
| 80 | "addl $16, %%esp\n" |
| 81 | "cli\n" |
| 82 | "cld\n" |
| 83 | : "+r" (entry.segoff), "=a" (res1), "=d" (res2) : : "cc", "memory"); |
| 84 | u32 res = res1 | (res2 << 16); |
| 85 | if (!res || res == PMM_FUNCTION_NOT_SUPPORTED) |
| 86 | return; |
| 87 | dprintf(1, "VGA stack allocated at %x\n", res); |
| 88 | SET_VGA(ExtraStackSeg, res >> 4); |
| 89 | extern void entry_10_extrastack(void); |
| 90 | SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10_extrastack)); |
| 91 | return; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /**************************************************************** |
| 97 | * VGA post |
| 98 | ****************************************************************/ |
| 99 | |
| 100 | static void |
| 101 | init_bios_area(void) |
| 102 | { |
| 103 | // init detected hardware BIOS Area |
| 104 | // set 80x25 color (not clear from RBIL but usual) |
| 105 | set_equipment_flags(0x30, 0x20); |
| 106 | |
| 107 | // the default char height |
| 108 | SET_BDA(char_height, 0x10); |
| 109 | |
| 110 | // Clear the screen |
| 111 | SET_BDA(video_ctl, 0x60); |
| 112 | |
| 113 | // Set the basic screen we have |
| 114 | SET_BDA(video_switches, 0xf9); |
| 115 | |
| 116 | // Set the basic modeset options |
| 117 | SET_BDA(modeset_ctl, 0x51); |
| 118 | |
| 119 | // Set the default MSR |
| 120 | SET_BDA(video_msr, 0x09); |
| 121 | } |
| 122 | |
| 123 | int VgaBDF VAR16 = -1; |
| 124 | int HaveRunInit VAR16; |
| 125 | |
| 126 | void VISIBLE16 |
| 127 | vga_post(struct bregs *regs) |
| 128 | { |
| 129 | debug_preinit(); |
| 130 | dprintf(1, "Start SeaVGABIOS (version %s)\n", VERSION); |
| 131 | debug_enter(regs, DEBUG_VGA_POST); |
| 132 | |
| 133 | if (CONFIG_VGA_PCI && !GET_GLOBAL(HaveRunInit)) { |
| 134 | u16 bdf = regs->ax; |
| 135 | if ((pci_config_readw(bdf, PCI_VENDOR_ID) |
| 136 | == GET_GLOBAL(rom_pci_data.vendor)) |
| 137 | && (pci_config_readw(bdf, PCI_DEVICE_ID) |
| 138 | == GET_GLOBAL(rom_pci_data.device))) |
| 139 | SET_VGA(VgaBDF, bdf); |
| 140 | } |
| 141 | |
| 142 | int ret = vgahw_setup(); |
| 143 | if (ret) { |
| 144 | dprintf(1, "Failed to initialize VGA hardware. Exiting.\n"); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | if (GET_GLOBAL(HaveRunInit)) |
| 149 | return; |
| 150 | |
| 151 | init_bios_area(); |
| 152 | |
| 153 | SET_VGA(video_save_pointer_table.videoparam |
| 154 | , SEGOFF(get_global_seg(), (u32)video_param_table)); |
| 155 | stdvga_build_video_param(); |
| 156 | |
| 157 | extern void entry_10(void); |
| 158 | SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10)); |
| 159 | |
| 160 | allocate_extra_stack(); |
| 161 | |
| 162 | SET_VGA(HaveRunInit, 1); |
| 163 | |
| 164 | // Fixup checksum |
| 165 | extern u8 _rom_header_size, _rom_header_checksum; |
| 166 | SET_VGA(_rom_header_checksum, 0); |
| 167 | u8 sum = -checksum_far(get_global_seg(), 0, |
| 168 | GET_GLOBAL(_rom_header_size) * 512); |
| 169 | SET_VGA(_rom_header_checksum, sum); |
| 170 | } |