1 | /* $Id: bios.c 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PC BIOS - ???
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | * --------------------------------------------------------------------
|
---|
17 | *
|
---|
18 | * This code is based on:
|
---|
19 | *
|
---|
20 | * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
|
---|
21 | *
|
---|
22 | * Copyright (C) 2002 MandrakeSoft S.A.
|
---|
23 | *
|
---|
24 | * MandrakeSoft S.A.
|
---|
25 | * 43, rue d'Aboukir
|
---|
26 | * 75002 Paris - France
|
---|
27 | * http://www.linux-mandrake.com/
|
---|
28 | * http://www.mandrakesoft.com/
|
---|
29 | *
|
---|
30 | * This library is free software; you can redistribute it and/or
|
---|
31 | * modify it under the terms of the GNU Lesser General Public
|
---|
32 | * License as published by the Free Software Foundation; either
|
---|
33 | * version 2 of the License, or (at your option) any later version.
|
---|
34 | *
|
---|
35 | * This library is distributed in the hope that it will be useful,
|
---|
36 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
37 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
38 | * Lesser General Public License for more details.
|
---|
39 | *
|
---|
40 | * You should have received a copy of the GNU Lesser General Public
|
---|
41 | * License along with this library; if not, write to the Free Software
|
---|
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
43 | *
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
48 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
49 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
50 | * a choice of LGPL license versions is made available with the language indicating
|
---|
51 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
52 | * of the LGPL is applied is otherwise unspecified.
|
---|
53 | */
|
---|
54 |
|
---|
55 |
|
---|
56 | #include <stdint.h>
|
---|
57 | #include "inlines.h"
|
---|
58 | #include "biosint.h"
|
---|
59 | #ifndef VBOX_VERSION_STRING
|
---|
60 | #include <VBox/version.h>
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | static const char bios_cvs_version_string[] = "VirtualBox " VBOX_VERSION_STRING;
|
---|
64 |
|
---|
65 | uint8_t inb_cmos(uint8_t cmos_reg)
|
---|
66 | {
|
---|
67 | uint8_t cmos_port = 0x70;
|
---|
68 |
|
---|
69 | if (cmos_reg >= 0x80)
|
---|
70 | cmos_port += 2;
|
---|
71 | outb(cmos_port, cmos_reg);
|
---|
72 | return inb(cmos_port + 1);
|
---|
73 | }
|
---|
74 |
|
---|
75 | void outb_cmos(uint8_t cmos_reg, uint8_t val)
|
---|
76 | {
|
---|
77 | uint8_t cmos_port = 0x70;
|
---|
78 |
|
---|
79 | if (cmos_reg >= 0x80)
|
---|
80 | cmos_port += 2;
|
---|
81 | outb(cmos_port, cmos_reg);
|
---|
82 | outb(cmos_port + 1, val);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void BIOSCALL dummy_isr_function(pusha_regs_t regs, uint16_t es,
|
---|
86 | uint16_t ds, iret_addr_t iret_addr)
|
---|
87 | {
|
---|
88 | // Interrupt handler for unexpected hardware interrupts. We have to clear
|
---|
89 | // the PIC because if we don't, the next EOI will clear the wrong interrupt
|
---|
90 | // and all hell will break loose! This routine also masks the unexpected
|
---|
91 | // interrupt so it will generally be called only once for each unexpected
|
---|
92 | // interrupt level.
|
---|
93 | uint8_t isrA, isrB, imr, last_int = 0xFF;
|
---|
94 |
|
---|
95 | outb(PIC_MASTER, PIC_CMD_RD_ISR); // Read master ISR
|
---|
96 | isrA = inb(PIC_MASTER);
|
---|
97 | if (isrA) {
|
---|
98 | outb(PIC_SLAVE, PIC_CMD_RD_ISR); // Read slave ISR
|
---|
99 | isrB = inb(PIC_SLAVE);
|
---|
100 | if (isrB) {
|
---|
101 | imr = inb(PIC_SLAVE_MASK);
|
---|
102 | outb(PIC_SLAVE_MASK, imr | isrB ); // Mask this interrupt
|
---|
103 | outb(PIC_SLAVE, PIC_CMD_EOI); // Send EOI on slave PIC
|
---|
104 | } else {
|
---|
105 | imr = inb(PIC_MASTER_MASK);
|
---|
106 | isrA &= 0xFB; // Never mask the cascade interrupt
|
---|
107 | outb(PIC_MASTER_MASK, imr | isrA); // Mask this interrupt
|
---|
108 | }
|
---|
109 | outb(PIC_MASTER, PIC_CMD_EOI); // Send EOI on master PIC
|
---|
110 | last_int = isrA;
|
---|
111 | }
|
---|
112 | write_byte(0x40, 0x6B, last_int); // Write INTR_FLAG
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | void BIOSCALL nmi_handler_msg(void)
|
---|
117 | {
|
---|
118 | BX_PANIC("NMI Handler called\n");
|
---|
119 | }
|
---|
120 |
|
---|
121 | void BIOSCALL int18_panic_msg(void)
|
---|
122 | {
|
---|
123 | BX_PANIC("INT18: BOOT FAILURE\n");
|
---|
124 | }
|
---|
125 |
|
---|
126 | void BIOSCALL log_bios_start(void)
|
---|
127 | {
|
---|
128 | #if BX_DEBUG_SERIAL
|
---|
129 | outb(BX_DEBUG_PORT+UART_LCR, 0x03); /* setup for serial logging: 8N1 */
|
---|
130 | #endif
|
---|
131 | BX_INFO("%s\n", bios_cvs_version_string);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* Set video mode. */
|
---|
135 | void set_mode(uint8_t mode);
|
---|
136 | #pragma aux set_mode = \
|
---|
137 | "mov ah, 0" \
|
---|
138 | "int 10h" \
|
---|
139 | parm [al] modify [ax];
|
---|
140 |
|
---|
141 | /// @todo restore
|
---|
142 | //#undef VBOX
|
---|
143 |
|
---|
144 | #define BX_PCIBIOS 1
|
---|
145 | #define BX_APPNAME "VirtualBox"
|
---|
146 | #define BIOS_BUILD_DATE __DATE__
|
---|
147 | //--------------------------------------------------------------------------
|
---|
148 | // print_bios_banner
|
---|
149 | // displays a the bios version
|
---|
150 | //--------------------------------------------------------------------------
|
---|
151 | void BIOSCALL print_bios_banner(void)
|
---|
152 | {
|
---|
153 | #ifdef VBOX
|
---|
154 | // Skip the logo if a warm boot is requested.
|
---|
155 | uint16_t warm_boot = read_word(0x0040,0x0072);
|
---|
156 | write_word(0x0040,0x0072, 0);
|
---|
157 | if (warm_boot == 0x1234)
|
---|
158 | {
|
---|
159 | /* Only set text mode. */
|
---|
160 | set_mode(3);
|
---|
161 | return;
|
---|
162 | }
|
---|
163 | /* show graphical logo */
|
---|
164 | show_logo();
|
---|
165 | #else /* !VBOX */
|
---|
166 | char *bios_conf;
|
---|
167 |
|
---|
168 | /* Avoid using preprocessing directives within macro arguments. */
|
---|
169 | bios_conf =
|
---|
170 | #ifdef __WATCOMC__
|
---|
171 | "watcom "
|
---|
172 | #endif
|
---|
173 | #if BX_APM
|
---|
174 | "apmbios "
|
---|
175 | #endif
|
---|
176 | #if BX_PCIBIOS
|
---|
177 | "pcibios "
|
---|
178 | #endif
|
---|
179 | #if BX_ELTORITO_BOOT
|
---|
180 | "eltorito "
|
---|
181 | #endif
|
---|
182 | #if BX_ROMBIOS32
|
---|
183 | "rombios32 "
|
---|
184 | #endif
|
---|
185 | "\n\n";
|
---|
186 |
|
---|
187 | printf(BX_APPNAME" BIOS - build: %s\n%s\nOptions: ",
|
---|
188 | BIOS_BUILD_DATE, bios_cvs_version_string);
|
---|
189 | printf(bios_conf, 0);
|
---|
190 | #endif /* VBOX */
|
---|
191 | }
|
---|