VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/system.c@ 70775

Last change on this file since 70775 was 69501, checked in by vboxsync, 7 years ago

PC/BIOS: Added LGPL disclaimer text where appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.8 KB
Line 
1/* $Id: system.c 69501 2017-10-28 16:12:47Z vboxsync $ */
2/** @file
3 * PC BIOS - ???
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 "biosint.h"
58#include "inlines.h"
59
60#if DEBUG_INT15
61# define BX_DEBUG_INT15(...) BX_DEBUG(__VA_ARGS__)
62#else
63# define BX_DEBUG_INT15(...)
64#endif
65
66
67#define UNSUPPORTED_FUNCTION 0x86 /* Specific to INT 15h. */
68
69#define BIOS_CONFIG_TABLE 0xe6f5 /** @todo configurable? put elsewhere? */
70
71#define ACPI_DATA_SIZE 0x00010000L /** @todo configurable? put elsewhere? */
72
73#define BX_CPU 3
74
75extern int pmode_IDT;
76extern int rmode_IDT;
77
78uint16_t read_ss(void);
79#pragma aux read_ss = "mov ax, ss" modify exact [ax] nomemory;
80
81#if VBOX_BIOS_CPU >= 80386
82
83/* The 386+ code uses CR0 to switch to/from protected mode.
84 * Quite straightforward.
85 */
86
87void pm_stack_save(uint16_t cx, uint16_t es, uint16_t si, uint16_t frame);
88#pragma aux pm_stack_save = \
89 ".386" \
90 "push ds" \
91 "push eax" \
92 "xor eax, eax" \
93 "mov ds, ax" \
94 "mov ds:[467h], sp" \
95 "mov ds:[469h], ss" \
96 parm [cx] [es] [si] [ax] modify nomemory;
97
98/* Uses position independent code... because it was too hard to figure
99 * out how to code the far call in inline assembler.
100 */
101void pm_enter(void);
102#pragma aux pm_enter = \
103 ".386p" \
104 "call pentry" \
105 "pentry:" \
106 "pop di" \
107 "add di, 1Bh" \
108 "push 20h" \
109 "push di" \
110 "lgdt fword ptr es:[si+8]" \
111 "lidt fword ptr cs:pmode_IDT" \
112 "mov eax, cr0" \
113 "or al, 1" \
114 "mov cr0, eax" \
115 "retf" \
116 "pm_pm:" \
117 "mov ax, 28h" \
118 "mov ss, ax" \
119 "mov ax, 10h" \
120 "mov ds, ax" \
121 "mov ax, 18h" \
122 "mov es, ax" \
123 modify nomemory;
124
125/* Restore segment limits to real mode compatible values and
126 * return to real mode.
127 */
128void pm_exit(void);
129#pragma aux pm_exit = \
130 ".386p" \
131 "call pexit" \
132 "pexit:" \
133 "pop ax" \
134 "push 0F000h" \
135 "add ax, 18h" \
136 "push ax" \
137 "mov ax, 28h" \
138 "mov ds, ax" \
139 "mov es, ax" \
140 "mov eax, cr0" \
141 "and al, 0FEh" \
142 "mov cr0, eax" \
143 "retf" \
144 "real_mode:" \
145 "lidt fword ptr cs:rmode_IDT" \
146 modify nomemory;
147
148/* Restore stack and reload segment registers in real mode to ensure
149 * real mode compatible selector+base.
150 */
151void pm_stack_restore(void);
152#pragma aux pm_stack_restore = \
153 ".386" \
154 "xor ax, ax" \
155 "mov ds, ax" \
156 "mov es, ax" \
157 "lss sp, ds:[467h]" \
158 "pop eax" \
159 "pop ds" \
160 modify nomemory;
161
162#elif VBOX_BIOS_CPU >= 80286
163
164/* The 286 code uses LMSW to switch to protected mode but it has to reset
165 * the CPU to get back to real mode. Ugly! See return_blkmove in orgs.asm
166 * for the other matching half.
167 */
168void pm_stack_save(uint16_t cx, uint16_t es, uint16_t si, uint16_t frame);
169#pragma aux pm_stack_save = \
170 "xor ax, ax" \
171 "mov ds, ax" \
172 "mov ds:[467h], bx" \
173 "mov ds:[469h], ss" \
174 parm [cx] [es] [si] [bx] modify nomemory;
175
176/* Uses position independent code... because it was too hard to figure
177 * out how to code the far call in inline assembler.
178 * NB: Trashes MSW bits but the CPU will be reset anyway.
179 */
180void pm_enter(void);
181#pragma aux pm_enter = \
182 ".286p" \
183 "call pentry" \
184 "pentry:" \
185 "pop di" \
186 "add di, 18h" \
187 "push 20h" \
188 "push di" \
189 "lgdt fword ptr es:[si+8]" \
190 "lidt fword ptr cs:pmode_IDT" \
191 "or al, 1" \
192 "lmsw ax" \
193 "retf" \
194 "pm_pm:" \
195 "mov ax, 28h" \
196 "mov ss, ax" \
197 "mov ax, 10h" \
198 "mov ds, ax" \
199 "mov ax, 18h" \
200 "mov es, ax" \
201 modify nomemory;
202
203/* Set up shutdown status and reset the CPU. The POST code
204 * will regain control. Port 80h is written with status.
205 * Code 9 is written to CMOS shutdown status byte (0Fh).
206 * CPU is triple faulted. .
207 */
208void pm_exit(void);
209#pragma aux pm_exit = \
210 "xor ax, ax" \
211 "out 80h, al" \
212 "mov al, 0Fh" \
213 "out 70h, al" \
214 "mov al, 09h" \
215 "out 71h, al" \
216 ".286p" \
217 "lidt fword ptr cs:pmode_IDT" \
218 "int 3" \
219 modify nomemory;
220
221/* Dummy. Actually done in return_blkmove. */
222void pm_stack_restore(void);
223#pragma aux pm_stack_restore = \
224 "rm_return:" \
225 modify nomemory;
226
227#endif
228
229void pm_copy(void);
230#pragma aux pm_copy = \
231 "xor si, si" \
232 "xor di, di" \
233 "cld" \
234 "rep movsw" \
235 modify nomemory;
236
237/* The pm_switch has a few crucial differences from pm_enter, hence
238 * it is replicated here. Uses LMSW to avoid trashing high word of eax.
239 */
240void pm_switch(uint16_t reg_si);
241#pragma aux pm_switch = \
242 ".286p" \
243 "call pentry" \
244 "pentry:" \
245 "pop di" \
246 "add di, 18h" \
247 "push 38h" \
248 "push di" \
249 "lgdt fword ptr es:[si+08h]" \
250 "lidt fword ptr es:[si+10h]" \
251 "mov ax, 1" \
252 "lmsw ax" \
253 "retf" \
254 "pm_pm:" \
255 "mov ax, 28h" \
256 "mov ss, ax" \
257 "mov ax, 18h" \
258 "mov ds, ax" \
259 "mov ax, 20h" \
260 "mov es, ax" \
261 parm [si] modify nomemory;
262
263/* Return to caller - we do not use IRET because we should not enable
264 * interrupts. Note that AH must be zero on exit.
265 * WARNING: Needs to be adapted if calling sequence is modified!
266 */
267void pm_unwind(uint16_t args);
268#pragma aux pm_unwind = \
269 ".286" \
270 "mov sp, ax" \
271 "popa" \
272 "add sp, 6" \
273 "pop cx" \
274 "pop ax" \
275 "pop ax" \
276 "mov ax, 30h" \
277 "push ax" \
278 "push cx" \
279 "retf" \
280 parm [ax] modify nomemory aborts;
281
282/// @todo This method is silly. The RTC should be programmed to fire an interrupt
283// instead of hogging the CPU with inaccurate code.
284void timer_wait(uint32_t usec_wait)
285{
286 uint32_t cycles;
287 uint8_t old_val;
288 uint8_t cur_val;
289
290 /* We wait in 15 usec increments. */
291 cycles = usec_wait / 15;
292
293 old_val = inp(0x61) & 0x10;
294 while (cycles--) {
295 /* Wait 15us. */
296 do {
297 cur_val = inp(0x61) & 0x10;
298 } while (cur_val != old_val);
299 old_val = cur_val;
300 }
301}
302
303bx_bool set_enable_a20(bx_bool val)
304{
305 uint8_t oldval;
306
307 // Use PS/2 System Control port A to set A20 enable
308
309 // get current setting first
310 oldval = inb(0x92);
311
312 // change A20 status
313 if (val)
314 outb(0x92, oldval | 0x02);
315 else
316 outb(0x92, oldval & 0xfd);
317
318 return((oldval & 0x02) != 0);
319}
320
321typedef struct {
322 uint32_t start;
323 uint32_t xstart;
324 uint32_t len;
325 uint32_t xlen;
326 uint32_t type;
327} mem_range_t;
328
329void set_e820_range(uint16_t ES, uint16_t DI, uint32_t start, uint32_t end,
330 uint8_t extra_start, uint8_t extra_end, uint16_t type)
331{
332 mem_range_t __far *range;
333
334 range = ES :> (mem_range_t *)DI;
335 range->start = start;
336 range->xstart = extra_start;
337 end -= start;
338 extra_end -= extra_start;
339 range->len = end;
340 range->xlen = extra_end;
341 range->type = type;
342}
343
344/// @todo move elsewhere?
345#define AX r.gr.u.r16.ax
346#define BX r.gr.u.r16.bx
347#define CX r.gr.u.r16.cx
348#define DX r.gr.u.r16.dx
349#define SI r.gr.u.r16.si
350#define DI r.gr.u.r16.di
351#define BP r.gr.u.r16.bp
352#define SP r.gr.u.r16.sp
353#define FLAGS r.fl.u.r16.flags
354#define EAX r.gr.u.r32.eax
355#define EBX r.gr.u.r32.ebx
356#define ECX r.gr.u.r32.ecx
357#define EDX r.gr.u.r32.edx
358#define ESI r.gr.u.r32.esi
359#define EDI r.gr.u.r32.edi
360#define ES r.es
361
362
363void BIOSCALL int15_function(sys_regs_t r)
364{
365 uint16_t bRegister;
366 uint8_t irqDisable;
367
368 BX_DEBUG_INT15("int15 AX=%04x\n",AX);
369
370 switch (GET_AH()) {
371 case 0x00: /* assorted functions */
372 if (GET_AL() != 0xc0)
373 goto undecoded;
374 /* GRUB calls int15 with ax=0x00c0 to get the ROM configuration table,
375 * which we don't support, but logging that event is annoying. In fact
376 * it is likely that they just misread some specs, because there is a
377 * int15 BIOS function AH=0xc0 which sounds quite similar to what GRUB
378 * wants to achieve. */
379 SET_CF();
380 SET_AH(UNSUPPORTED_FUNCTION);
381 break;
382 case 0x24: /* A20 Control */
383 switch (GET_AL()) {
384 case 0x00:
385 set_enable_a20(0);
386 CLEAR_CF();
387 SET_AH(0);
388 break;
389 case 0x01:
390 set_enable_a20(1);
391 CLEAR_CF();
392 SET_AH(0);
393 break;
394 case 0x02:
395 SET_AL( (inb(0x92) >> 1) & 0x01 );
396 CLEAR_CF();
397 SET_AH(0);
398 break;
399 case 0x03:
400 CLEAR_CF();
401 SET_AH(0);
402 BX = 3;
403 break;
404 default:
405 BX_INFO("int15: Func 24h, subfunc %02xh, A20 gate control not supported\n", (unsigned) GET_AL());
406 SET_CF();
407 SET_AH(UNSUPPORTED_FUNCTION);
408 }
409 break;
410
411 case 0x41:
412 SET_CF();
413 SET_AH(UNSUPPORTED_FUNCTION);
414 break;
415
416 /// @todo Why does this need special handling? All we need is to set CF
417 // but not handle this as an unknown function (regardless of CPU type).
418 case 0x4f:
419 /* keyboard intercept */
420#if BX_CPU < 2
421 SET_AH(UNSUPPORTED_FUNCTION);
422#else
423 // nop
424#endif
425 SET_CF();
426 break;
427
428 case 0x52: // removable media eject
429 CLEAR_CF();
430 SET_AH(0); // "ok ejection may proceed"
431 break;
432
433 case 0x83: {
434 if( GET_AL() == 0 ) {
435 // Set Interval requested.
436 if( ( read_byte( 0x40, 0xA0 ) & 1 ) == 0 ) {
437 // Interval not already set.
438 write_byte( 0x40, 0xA0, 1 ); // Set status byte.
439 write_word( 0x40, 0x98, ES ); // Byte location, segment
440 write_word( 0x40, 0x9A, BX ); // Byte location, offset
441 write_word( 0x40, 0x9C, DX ); // Low word, delay
442 write_word( 0x40, 0x9E, CX ); // High word, delay.
443 CLEAR_CF( );
444 irqDisable = inb( 0xA1 );
445 outb( 0xA1, irqDisable & 0xFE );
446 bRegister = inb_cmos( 0xB ); // Unmask IRQ8 so INT70 will get through.
447 outb_cmos( 0xB, bRegister | 0x40 ); // Turn on the Periodic Interrupt timer
448 } else {
449 // Interval already set.
450 BX_DEBUG_INT15("int15: Func 83h, failed, already waiting.\n" );
451 SET_CF();
452 SET_AH(UNSUPPORTED_FUNCTION);
453 }
454 } else if( GET_AL() == 1 ) {
455 // Clear Interval requested
456 write_byte( 0x40, 0xA0, 0 ); // Clear status byte
457 CLEAR_CF( );
458 bRegister = inb_cmos( 0xB );
459 outb_cmos( 0xB, bRegister & ~0x40 ); // Turn off the Periodic Interrupt timer
460 } else {
461 BX_DEBUG_INT15("int15: Func 83h, failed.\n" );
462 SET_CF();
463 SET_AH(UNSUPPORTED_FUNCTION);
464 SET_AL(GET_AL() - 1);
465 }
466
467 break;
468 }
469
470 case 0x88:
471 // Get the amount of extended memory (above 1M)
472#if BX_CPU < 2
473 SET_AH(UNSUPPORTED_FUNCTION);
474 SET_CF();
475#else
476 AX = (inb_cmos(0x31) << 8) | inb_cmos(0x30);
477
478 // According to Ralf Brown's interrupt the limit should be 15M,
479 // but real machines mostly return max. 63M.
480 if(AX > 0xffc0)
481 AX = 0xffc0;
482
483 CLEAR_CF();
484#endif
485 break;
486
487 case 0x89:
488 // Switch to Protected Mode.
489 // ES:DI points to user-supplied GDT
490 // BH/BL contains starting interrupt numbers for PIC0/PIC1
491 // This subfunction does not return!
492
493 // turn off interrupts
494 int_disable(); /// @todo aren't they off already?
495
496 set_enable_a20(1); // enable A20 line; we're supposed to fail if that fails
497
498 // Initialize CS descriptor for BIOS
499 write_word(ES, SI+0x38+0, 0xffff);// limit 15:00 = normal 64K limit
500 write_word(ES, SI+0x38+2, 0x0000);// base 15:00
501 write_byte(ES, SI+0x38+4, 0x000f);// base 23:16 (hardcoded to f000:0000)
502 write_byte(ES, SI+0x38+5, 0x9b); // access
503 write_word(ES, SI+0x38+6, 0x0000);// base 31:24/reserved/limit 19:16
504
505 /* Reprogram the PICs. */
506 outb(PIC_MASTER, PIC_CMD_INIT);
507 outb(PIC_SLAVE, PIC_CMD_INIT);
508 outb(PIC_MASTER + 1, GET_BH());
509 outb(PIC_SLAVE + 1, GET_BL());
510 outb(PIC_MASTER + 1, 4);
511 outb(PIC_SLAVE + 1, 2);
512 outb(PIC_MASTER + 1, 1);
513 outb(PIC_SLAVE + 1, 1);
514 /* Mask all IRQs, user must re-enable. */
515 outb(PIC_MASTER_MASK, 0xff);
516 outb(PIC_SLAVE_MASK, 0xff);
517
518 pm_switch(SI);
519 pm_unwind((uint16_t)&r);
520
521 break;
522
523 case 0x90:
524 /* Device busy interrupt. Called by Int 16h when no key available */
525 break;
526
527 case 0x91:
528 /* Interrupt complete. Called by Int 16h when key becomes available */
529 break;
530
531 case 0xbf:
532 BX_INFO("*** int 15h function AH=bf not yet supported!\n");
533 SET_CF();
534 SET_AH(UNSUPPORTED_FUNCTION);
535 break;
536
537 case 0xC0:
538 CLEAR_CF();
539 SET_AH(0);
540 BX = BIOS_CONFIG_TABLE;
541 ES = 0xF000;
542 break;
543
544 case 0xc1:
545 ES = read_word(0x0040, 0x000E);
546 CLEAR_CF();
547 break;
548
549 case 0xd8:
550 bios_printf(BIOS_PRINTF_DEBUG, "EISA BIOS not present\n");
551 SET_CF();
552 SET_AH(UNSUPPORTED_FUNCTION);
553 break;
554
555 /* Make the BIOS warning for pretty much every Linux kernel start
556 * disappear - it calls with ax=0xe980 to figure out SMI info. */
557 case 0xe9: /* SMI functions (SpeedStep and similar things) */
558 SET_CF();
559 SET_AH(UNSUPPORTED_FUNCTION);
560 break;
561 case 0xec: /* AMD64 target operating mode callback */
562 if (GET_AL() != 0)
563 goto undecoded;
564 SET_AH(0);
565 if (GET_BL() >= 1 && GET_BL() <= 3)
566 CLEAR_CF(); /* Accepted value. */
567 else
568 SET_CF(); /* Reserved, error. */
569 break;
570undecoded:
571 default:
572 BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
573 (unsigned) AX, (unsigned) BX);
574 SET_CF();
575 SET_AH(UNSUPPORTED_FUNCTION);
576 break;
577 }
578}
579
580void BIOSCALL int15_function32(sys32_regs_t r)
581{
582 uint32_t extended_memory_size=0; // 64bits long
583 uint32_t extra_lowbits_memory_size=0;
584 uint8_t extra_highbits_memory_size=0;
585 uint32_t mcfgStart, mcfgSize;
586
587 BX_DEBUG_INT15("int15 AX=%04x\n",AX);
588
589 switch (GET_AH()) {
590 case 0x86:
591 // Wait for CX:DX microseconds. currently using the
592 // refresh request port 0x61 bit4, toggling every 15usec
593 int_enable();
594 timer_wait(((uint32_t)CX << 16) | DX);
595 break;
596
597 case 0xd0:
598 if (GET_AL() != 0x4f)
599 goto int15_unimplemented;
600 if (EBX == 0x50524f43 && ECX == 0x4d4f4445 && ESI == 0 && EDI == 0)
601 {
602 CLEAR_CF();
603 ESI = EBX;
604 EDI = ECX;
605 EAX = 0x49413332;
606 }
607 else
608 goto int15_unimplemented;
609 break;
610
611 case 0xe8:
612 switch(GET_AL()) {
613 case 0x20: // coded by osmaker aka K.J.
614 if(EDX == 0x534D4150) {
615 extended_memory_size = inb_cmos(0x35);
616 extended_memory_size <<= 8;
617 extended_memory_size |= inb_cmos(0x34);
618 extended_memory_size *= 64;
619#ifndef VBOX /* The following excludes 0xf0000000 thru 0xffffffff. Trust DevPcBios.cpp to get this right. */
620 // greater than EFF00000???
621 if(extended_memory_size > 0x3bc000) {
622 extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
623 }
624#endif /* !VBOX */
625 extended_memory_size *= 1024;
626 extended_memory_size += (16L * 1024 * 1024);
627
628 if(extended_memory_size <= (16L * 1024 * 1024)) {
629 extended_memory_size = inb_cmos(0x31);
630 extended_memory_size <<= 8;
631 extended_memory_size |= inb_cmos(0x30);
632 extended_memory_size *= 1024;
633 extended_memory_size += (1L * 1024 * 1024);
634 }
635
636#ifdef VBOX /* We've already used the CMOS entries for SATA.
637 BTW. This is the amount of memory above 4GB measured in 64KB units. */
638 extra_lowbits_memory_size = inb_cmos(0x62);
639 extra_lowbits_memory_size <<= 8;
640 extra_lowbits_memory_size |= inb_cmos(0x61);
641 extra_lowbits_memory_size <<= 16;
642 extra_highbits_memory_size = inb_cmos(0x63);
643 /* 0x64 and 0x65 can be used if we need to dig 1 TB or more at a later point. */
644#else
645 extra_lowbits_memory_size = inb_cmos(0x5c);
646 extra_lowbits_memory_size <<= 8;
647 extra_lowbits_memory_size |= inb_cmos(0x5b);
648 extra_lowbits_memory_size *= 64;
649 extra_lowbits_memory_size *= 1024;
650 extra_highbits_memory_size = inb_cmos(0x5d);
651#endif /* !VBOX */
652
653 mcfgStart = 0;
654 mcfgSize = 0;
655
656 switch(BX)
657 {
658 case 0:
659 set_e820_range(ES, DI,
660#ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
661 0x0000000L, 0x0009f000L, 0, 0, 1);
662#else
663 0x0000000L, 0x0009fc00L, 0, 0, 1);
664#endif
665 EBX = 1;
666 break;
667 case 1:
668 set_e820_range(ES, DI,
669#ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
670 0x0009f000L, 0x000a0000L, 0, 0, 2);
671#else
672 0x0009fc00L, 0x000a0000L, 0, 0, 2);
673#endif
674 EBX = 2;
675 break;
676 case 2:
677#ifdef VBOX
678 /* Mark the BIOS as reserved. VBox doesn't currently
679 * use the 0xe0000-0xeffff area. It does use the
680 * 0xd0000-0xdffff area for the BIOS logo, but it's
681 * not worth marking it as reserved. (this is not
682 * true anymore because the VGA adapter handles the logo stuff)
683 * The whole 0xe0000-0xfffff can be used for the BIOS.
684 * Note that various
685 * Windows versions don't accept (read: in debug builds
686 * they trigger the "Too many similar traps" assertion)
687 * a single reserved range from 0xd0000 to 0xffffff.
688 * A 128K area starting from 0xd0000 works. */
689 set_e820_range(ES, DI,
690 0x000f0000L, 0x00100000L, 0, 0, 2);
691#else /* !VBOX */
692 set_e820_range(ES, DI,
693 0x000e8000L, 0x00100000L, 0, 0, 2);
694#endif /* !VBOX */
695 EBX = 3;
696 break;
697 case 3:
698#if BX_ROMBIOS32 || defined(VBOX)
699 set_e820_range(ES, DI,
700 0x00100000L,
701 extended_memory_size - ACPI_DATA_SIZE, 0, 0, 1);
702 EBX = 4;
703#else
704 set_e820_range(ES, DI,
705 0x00100000L,
706 extended_memory_size, 1);
707 EBX = 5;
708#endif
709 break;
710 case 4:
711 set_e820_range(ES, DI,
712 extended_memory_size - ACPI_DATA_SIZE,
713 extended_memory_size, 0, 0, 3); // ACPI RAM
714 EBX = 5;
715 break;
716 case 5:
717 set_e820_range(ES, DI,
718 0xfec00000,
719 0xfec00000 + 0x1000, 0, 0, 2); // I/O APIC
720 EBX = 6;
721 break;
722 case 6:
723 set_e820_range(ES, DI,
724 0xfee00000,
725 0xfee00000 + 0x1000, 0, 0, 2); // Local APIC
726 EBX = 7;
727 break;
728 case 7:
729 /* 256KB BIOS area at the end of 4 GB */
730#ifdef VBOX
731 /* We don't set the end to 1GB here and rely on the 32-bit
732 unsigned wrap around effect (0-0xfffc0000L). */
733#endif
734 set_e820_range(ES, DI,
735 0xfffc0000L, 0x00000000L, 0, 0, 2);
736 if (mcfgStart != 0)
737 EBX = 8;
738 else
739 {
740 if (extra_highbits_memory_size || extra_lowbits_memory_size)
741 EBX = 9;
742 else
743 EBX = 0;
744 }
745 break;
746 case 8:
747 /* PCI MMIO config space (MCFG) */
748 set_e820_range(ES, DI,
749 mcfgStart, mcfgStart + mcfgSize, 0, 0, 2);
750
751 if (extra_highbits_memory_size || extra_lowbits_memory_size)
752 EBX = 9;
753 else
754 EBX = 0;
755 break;
756 case 9:
757#ifdef VBOX /* Don't succeeded if no memory above 4 GB. */
758 /* Mapping of memory above 4 GB if present.
759 Note1: set_e820_range needs do no borrowing in the
760 subtraction because of the nice numbers.
761 Note2* works only up to 1TB because of uint8_t for
762 the upper bits!*/
763 if (extra_highbits_memory_size || extra_lowbits_memory_size)
764 {
765 set_e820_range(ES, DI,
766 0x00000000L, extra_lowbits_memory_size,
767 1 /*x4GB*/, extra_highbits_memory_size + 1 /*x4GB*/, 1);
768 EBX = 0;
769 }
770 break;
771 /* fall thru */
772#else /* !VBOX */
773 /* Mapping of memory above 4 GB */
774 set_e820_range(ES, DI, 0x00000000L,
775 extra_lowbits_memory_size, 1, extra_highbits_memory_size
776 + 1, 1);
777 EBX = 0;
778 break;
779#endif /* !VBOX */
780 default: /* AX=E820, DX=534D4150, BX unrecognized */
781 goto int15_unimplemented;
782 break;
783 }
784 EAX = 0x534D4150;
785 ECX = 0x14;
786 CLEAR_CF();
787 } else {
788 // if DX != 0x534D4150)
789 goto int15_unimplemented;
790 }
791 break;
792
793 case 0x01:
794 // do we have any reason to fail here ?
795 CLEAR_CF();
796
797 // my real system sets ax and bx to 0
798 // this is confirmed by Ralph Brown list
799 // but syslinux v1.48 is known to behave
800 // strangely if ax is set to 0
801 // regs.u.r16.ax = 0;
802 // regs.u.r16.bx = 0;
803
804 // Get the amount of extended memory (above 1M)
805 CX = (inb_cmos(0x31) << 8) | inb_cmos(0x30);
806
807 // limit to 15M
808 if(CX > 0x3c00)
809 CX = 0x3c00;
810
811 // Get the amount of extended memory above 16M in 64k blocks
812 DX = (inb_cmos(0x35) << 8) | inb_cmos(0x34);
813
814 // Set configured memory equal to extended memory
815 AX = CX;
816 BX = DX;
817 break;
818 default: /* AH=0xE8?? but not implemented */
819 goto int15_unimplemented;
820 }
821 break;
822 int15_unimplemented:
823 // fall into the default case
824 default:
825 BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
826 (unsigned) AX, (unsigned) BX);
827 SET_CF();
828 SET_AL(UNSUPPORTED_FUNCTION);
829 break;
830 }
831}
832
833#if VBOX_BIOS_CPU >= 80286
834
835#undef FLAGS
836#define FLAGS r.ra.flags.u.r16.flags
837
838/* Function 0x87 handled separately due to specific stack layout requirements. */
839void BIOSCALL int15_blkmove(disk_regs_t r)
840{
841 bx_bool prev_a20_enable;
842 uint16_t base15_00;
843 uint8_t base23_16;
844 uint16_t ss;
845
846 // +++ should probably have descriptor checks
847 // +++ should have exception handlers
848
849 // turn off interrupts
850 int_disable(); /// @todo aren't they disabled already?
851
852 prev_a20_enable = set_enable_a20(1); // enable A20 line
853
854 // 128K max of transfer on 386+ ???
855 // source == destination ???
856
857 // ES:SI points to descriptor table
858 // offset use initially comments
859 // ==============================================
860 // 00..07 Unused zeros Null descriptor
861 // 08..0f GDT zeros filled in by BIOS
862 // 10..17 source ssssssss source of data
863 // 18..1f dest dddddddd destination of data
864 // 20..27 CS zeros filled in by BIOS
865 // 28..2f SS zeros filled in by BIOS
866
867 //es:si
868 //eeee0
869 //0ssss
870 //-----
871
872 // check for access rights of source & dest here
873
874 // Initialize GDT descriptor
875 base15_00 = (ES << 4) + SI;
876 base23_16 = ES >> 12;
877 if (base15_00 < (ES<<4))
878 base23_16++;
879 write_word(ES, SI+0x08+0, 47); // limit 15:00 = 6 * 8bytes/descriptor
880 write_word(ES, SI+0x08+2, base15_00);// base 15:00
881 write_byte(ES, SI+0x08+4, base23_16);// base 23:16
882 write_byte(ES, SI+0x08+5, 0x93); // access
883 write_word(ES, SI+0x08+6, 0x0000); // base 31:24/reserved/limit 19:16
884
885 // Initialize CS descriptor
886 write_word(ES, SI+0x20+0, 0xffff);// limit 15:00 = normal 64K limit
887 write_word(ES, SI+0x20+2, 0x0000);// base 15:00
888 write_byte(ES, SI+0x20+4, 0x000f);// base 23:16
889 write_byte(ES, SI+0x20+5, 0x9b); // access
890 write_word(ES, SI+0x20+6, 0x0000);// base 31:24/reserved/limit 19:16
891
892 // Initialize SS descriptor
893 ss = read_ss();
894 base15_00 = ss << 4;
895 base23_16 = ss >> 12;
896 write_word(ES, SI+0x28+0, 0xffff); // limit 15:00 = normal 64K limit
897 write_word(ES, SI+0x28+2, base15_00);// base 15:00
898 write_byte(ES, SI+0x28+4, base23_16);// base 23:16
899 write_byte(ES, SI+0x28+5, 0x93); // access
900 write_word(ES, SI+0x28+6, 0x0000); // base 31:24/reserved/limit 19:16
901
902 pm_stack_save(CX, ES, SI, FP_OFF(&r));
903 pm_enter();
904 pm_copy();
905 pm_exit();
906 pm_stack_restore();
907
908 set_enable_a20(prev_a20_enable);
909
910 // turn interrupts back on
911 int_enable();
912
913 SET_AH(0);
914 CLEAR_CF();
915}
916#endif
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