VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/print.c@ 45401

Last change on this file since 45401 was 45401, checked in by vboxsync, 12 years ago

BIOS: Removed panic port references.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/*
2 * Copyright (C) 2006-2011 Oracle Corporation
3 *
4 * This file is part of VirtualBox Open Source Edition (OSE), as
5 * available from http://www.virtualbox.org. This file is free software;
6 * you can redistribute it and/or modify it under the terms of the GNU
7 * General Public License (GPL) as published by the Free Software
8 * Foundation, in version 2 as it comes in the "COPYING" file of the
9 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11 * --------------------------------------------------------------------
12 *
13 * This code is based on:
14 *
15 * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
16 *
17 * Copyright (C) 2002 MandrakeSoft S.A.
18 *
19 * MandrakeSoft S.A.
20 * 43, rue d'Aboukir
21 * 75002 Paris - France
22 * http://www.linux-mandrake.com/
23 * http://www.mandrakesoft.com/
24 *
25 * This library is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU Lesser General Public
27 * License as published by the Free Software Foundation; either
28 * version 2 of the License, or (at your option) any later version.
29 *
30 * This library is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 * Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public
36 * License along with this library; if not, write to the Free Software
37 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38 *
39 */
40
41
42#include <stdint.h>
43#include <stdarg.h>
44#include "inlines.h"
45#include "biosint.h"
46
47// Debug printf support
48
49/* Redirect INFO output to backdoor logging port. */
50#define INFO_PORT 0x504
51#define DEBUG_PORT 0x403
52
53const char bios_prefix_string[] = "BIOS: ";
54
55void wrch(uint8_t c);
56#pragma aux wrch = "mov ah, 0eh" "int 10h" parm [al] modify exact [ax bx];
57
58void send(uint16_t action, uint8_t c)
59{
60#if BX_DEBUG_SERIAL
61 if (c == '\n')
62 uart_tx_byte(BX_DEBUG_PORT, '\r');
63 uart_tx_byte(BX_DEBUG_PORT, c);
64#endif
65#if BX_VIRTUAL_PORTS
66 if (action & BIOS_PRINTF_DEBUG)
67 outb(DEBUG_PORT, c);
68 if (action & BIOS_PRINTF_INFO)
69 outb(INFO_PORT, c);
70#endif
71 if (action & BIOS_PRINTF_SCREEN) {
72 if (c == '\n')
73 wrch('\r');
74 wrch(c);
75 }
76}
77
78void put_int(uint16_t action, short val, short width, bx_bool neg)
79{
80 short nval = val / 10;
81 if (nval)
82 put_int(action, nval, width - 1, neg);
83 else {
84 while (--width > 0)
85 send(action, ' ');
86 if (neg)
87 send(action, '-');
88 }
89 send(action, val - (nval * 10) + '0');
90}
91
92void put_uint(uint16_t action, unsigned short val, short width, bx_bool neg)
93{
94 unsigned short nval = val / 10;
95 if (nval)
96 put_uint(action, nval, width - 1, neg);
97 else {
98 while (--width > 0)
99 send(action, ' ');
100 if (neg)
101 send(action, '-');
102 }
103 send(action, val - (nval * 10) + '0');
104}
105
106void put_luint(uint16_t action, unsigned long val, short width, bx_bool neg)
107{
108 unsigned long nval = val / 10;
109 if (nval)
110 put_luint(action, nval, width - 1, neg);
111 else {
112 while (--width > 0)
113 send(action, ' ');
114 if (neg)
115 send(action, '-');
116 }
117 send(action, val - (nval * 10) + '0');
118}
119
120void put_str(uint16_t action, const char __far *s)
121{
122 uint8_t c;
123
124 while (c = *s) {
125 send(action, c);
126 s++;
127 }
128}
129
130void put_str_near(uint16_t action, const char __near *s)
131{
132 uint8_t c;
133
134 while (c = *s) {
135 send(action, c);
136 s++;
137 }
138}
139
140
141//--------------------------------------------------------------------------
142// bios_printf()
143// A compact variable argument printf function.
144//
145// Supports %[format_width][length]format
146// where format can be x,X,u,d,s,S,c
147// and the optional length modifier is l (ell)
148//--------------------------------------------------------------------------
149void bios_printf(uint16_t action, const char *s, ...)
150{
151 uint8_t c;
152 bx_bool in_format;
153 int i;
154 uint16_t arg, nibble, hibyte, format_width, hexadd;
155 va_list args;
156
157 va_start( args, s );
158
159 in_format = 0;
160 format_width = 0;
161
162 if ((action & BIOS_PRINTF_DEBHALT) == BIOS_PRINTF_DEBHALT) {
163 bios_printf (BIOS_PRINTF_SCREEN, "FATAL: ");
164 }
165
166 while (c = *s) {
167 if ( c == '%' ) {
168 in_format = 1;
169 format_width = 0;
170 }
171 else if (in_format) {
172 if ( (c>='0') && (c<='9') ) {
173 format_width = (format_width * 10) + (c - '0');
174 }
175 else {
176 arg = va_arg( args, uint16_t );
177 if (c == 'x' || c == 'X') {
178 if (format_width == 0)
179 format_width = 4;
180 if (c == 'x')
181 hexadd = 'a';
182 else
183 hexadd = 'A';
184 for (i=format_width-1; i>=0; i--) {
185 nibble = (arg >> (4 * i)) & 0x000f;
186 send (action, (nibble<=9)? (nibble+'0') : (nibble-10+hexadd));
187 }
188 }
189 else if (c == 'u') {
190 put_uint(action, arg, format_width, 0);
191 }
192 else if (c == 'l') {
193 s++;
194 c = *s; /* is it ld,lx,lu? */
195 hibyte = va_arg( args, uint16_t );
196 if (c == 'd') {
197 if (hibyte & 0x8000)
198 put_luint(action, 0L-(((uint32_t) hibyte << 16) | arg), format_width-1, 1);
199 else
200 put_luint(action, ((uint32_t) hibyte << 16) | arg, format_width, 0);
201 }
202 else if (c == 'u') {
203 put_luint(action, ((uint32_t) hibyte << 16) | arg, format_width, 0);
204 }
205 else if (c == 'x' || c == 'X')
206 {
207 if (format_width == 0)
208 format_width = 8;
209 if (c == 'x')
210 hexadd = 'a';
211 else
212 hexadd = 'A';
213 for (i=format_width-1; i>=0; i--) {
214 nibble = ((((uint32_t)hibyte << 16) | arg) >> (4 * i)) & 0x000f;
215 send (action, (nibble<=9)? (nibble+'0') : (nibble-10+hexadd));
216 }
217 }
218 }
219 else if (c == 'd') {
220 if (arg & 0x8000)
221 put_int(action, -arg, format_width - 1, 1);
222 else
223 put_int(action, arg, format_width, 0);
224 }
225 else if (c == 's') {
226 put_str(action, (char *)arg);
227 }
228 else if (c == 'S') {
229 hibyte = arg;
230 arg = va_arg( args, uint16_t );
231 put_str(action, hibyte :> (char *)arg);
232 }
233 else if (c == 'c') {
234 send(action, arg);
235 }
236 else
237 BX_PANIC("bios_printf: unknown format\n");
238 in_format = 0;
239 }
240 }
241 else {
242 send(action, c);
243 }
244 ++s;
245 }
246 va_end( args );
247 if (action & BIOS_PRINTF_HALT) {
248 // freeze in a busy loop.
249 int_disable();
250 halt_forever();
251 }
252}
253
254// End of printf support
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette