VirtualBox

Changeset 95 in vbox


Ignore:
Timestamp:
Jan 17, 2007 1:17:32 PM (18 years ago)
Author:
vboxsync
Message:

Get BIOS in sync with bochs (BIOS32 deactivated). Fixes E820 issue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/BIOS/rombios.c

    r89 r95  
    2323//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
    2424
    25 // ROM BIOS for use with Bochs/Plex x86 emulation environment
     25// ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
    2626
    2727
     
    125125#endif
    126126
     127#define BX_ROMBIOS32       0
    127128#define DEBUG_ROMBIOS      0
    128129
     
    172173#define BASE_MEM_IN_K   (640 - EBDA_SIZE)
    173174
     175#define ACPI_DATA_SIZE    0x00010000L
     176
    174177  // Define the application NAME
    175 #ifdef PLEX86
     178#if defined(BX_QEMU)
     179#  define BX_APPNAME "QEMU"
     180#elif defined(PLEX86)
    176181#  define BX_APPNAME "Plex86"
    177182#else
     
    11451150      {   none,   none,   none,   none, none },
    11461151      { 0x565c, 0x567c,   none,   none, none }, /* \| */
     1152#ifndef VBOX
     1153      { 0x5700, 0x5700,   none,   none, none }, /* F11 */
     1154      { 0x5800, 0x5800,   none,   none, none }  /* F12 */
     1155#else
    11471156      { 0x8500, 0x8700, 0x8900, 0x8b00, none }, /* F11 */
    11481157      { 0x8600, 0x8800, 0x8a00, 0x8c00, none }  /* F12 */
     1158#endif
    11491159      };
    11501160
     
    18421852    BIOS_BUILD_DATE, bios_cvs_version_string);
    18431853  printf(
    1844 #ifdef BX_APM
     1854#if BX_APM
    18451855  "apmbios "
    18461856#endif
    1847 #ifdef BX_PCIBIOS
     1857#if BX_PCIBIOS
    18481858  "pcibios "
    18491859#endif
    1850 #ifdef BX_ELTORITO_BOOT
     1860#if BX_ELTORITO_BOOT
    18511861  "eltorito "
     1862#endif
     1863#if BX_ROMBIOS32
     1864  "rombios32 "
    18521865#endif
    18531866  "\n\n");
     
    42974310            if(regs.u.r32.edx == 0x534D4150)
    42984311            {
     4312                extended_memory_size = inb_cmos(0x35);
     4313                extended_memory_size <<= 8;
     4314                extended_memory_size |= inb_cmos(0x34);
     4315                extended_memory_size *= 64;
     4316                // greater than EFF00000???
     4317                if(extended_memory_size > 0x3bc000) {
     4318                    extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
     4319                }
     4320                extended_memory_size *= 1024;
     4321                extended_memory_size += (16L * 1024 * 1024);
     4322               
     4323                if(extended_memory_size <= (16L * 1024 * 1024)) {
     4324                    extended_memory_size = inb_cmos(0x31);
     4325                    extended_memory_size <<= 8;
     4326                    extended_memory_size |= inb_cmos(0x30);
     4327                    extended_memory_size *= 1024;
     4328                }
     4329
    42994330                switch(regs.u.r16.bx)
    43004331                {
     
    43404371                        break;
    43414372                    case 3:
    4342                         extended_memory_size = inb_cmos(0x35);
    4343                         extended_memory_size <<= 8;
    4344                         extended_memory_size |= inb_cmos(0x34);
    4345                         extended_memory_size *= 64;
    4346                         if(extended_memory_size > 0x3bc000) // greater than EFF00000???
    4347                         {
    4348                             extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
    4349                         }
    4350                         extended_memory_size *= 1024;
    4351                         extended_memory_size += (16L * 1024 * 1024);
    4352 
    4353                         if(extended_memory_size <= (16L * 1024 * 1024))
    4354                         {
    4355                             extended_memory_size = inb_cmos(0x31);
    4356                             extended_memory_size <<= 8;
    4357                             extended_memory_size |= inb_cmos(0x30);
    4358                             extended_memory_size *= 1024;
    4359                         }
    4360 
    43614373                        set_e820_range(ES, regs.u.r16.di,
    4362                                        0x00100000L, extended_memory_size - 0x00010000, 1);
     4374                                       0x00100000L,
     4375                                       extended_memory_size - ACPI_DATA_SIZE, 1);
    43634376                        regs.u.r32.ebx = 4;
    43644377                        regs.u.r32.eax = 0x534D4150;
     
    43684381                        break;
    43694382                    case 4:
    4370 #ifdef VBOX
    4371                         /* ACPI area at the end of physical memory */
    4372                         extended_memory_size = inb_cmos(0x35);
    4373                         extended_memory_size <<= 8;
    4374                         extended_memory_size |= inb_cmos(0x34);
    4375                         extended_memory_size *= 64;
    4376                         if (extended_memory_size > 0x3bc000) // greater than EF000000???
    4377                         {
    4378                             extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
    4379                         }
    4380                         extended_memory_size *= 1024;
    4381                         extended_memory_size += (16L * 1024 * 1024);
    4382 
    4383                         if(extended_memory_size <= (16L * 1024 * 1024))
    4384                         {
    4385                             extended_memory_size = inb_cmos(0x31);
    4386                             extended_memory_size <<= 8;
    4387                             extended_memory_size |= inb_cmos(0x30);
    4388                             extended_memory_size *= 1024;
    4389                         }
    4390                         extended_memory_size -= 0x10000L;
    4391                         set_e820_range(ES, regs.u.r16.di,
    4392                                        extended_memory_size, extended_memory_size + 0x00010000L, 3);
     4383                        set_e820_range(ES, regs.u.r16.di,
     4384                                       extended_memory_size - ACPI_DATA_SIZE,
     4385                                       extended_memory_size, 3); // ACPI RAM
    43934386                        regs.u.r32.ebx = 5;
    43944387                        regs.u.r32.eax = 0x534D4150;
     
    43984391                        break;
    43994392                    case 5:
    4400 #endif /* VBOX */
    44014393                        /* 256KB BIOS area at the end of 4 GB */
    44024394                        set_e820_range(ES, regs.u.r16.di,
     
    50054997
    50064998  void
    5007 int13_harddisk(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
    5008   Bit16u DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS;
     4999int13_harddisk(EHAX, DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
     5000  Bit16u EHAX, DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS;
    50095001{
    50105002  Bit32u lba;
     
    60996091
    61006092  void
    6101 int13_harddisk(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
    6102   Bit16u DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS;
     6093int13_harddisk(EHAX, DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
     6094  Bit16u EHAX, DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS;
    61036095{
    61046096  Bit8u    drive, num_sectors, sector, head, status, mod;
     
    79147906    mov  bp, sp
    79157907
    7916     mov  ax, #0x0000
     7908    xor  ax, ax
    79177909    mov  _int19_function.status + 2[bp], ax
    79187910    mov  dl, _int19_function.bootdrv + 2[bp]
    79197911    mov  ax, _int19_function.bootseg + 2[bp]
    79207912    mov  es, ax         ;; segment
    7921     mov  bx, #0x0000    ;; offset
     7913    xor  bx, bx         ;; offset
    79227914    mov  ah, #0x02      ;; function 2, read diskette sector
    79237915    mov  al, #0x01      ;; read 1 sector
     
    81748166        BX_INFO("bad PCI vendor ID %04x\n", regs.u.r16.dx);
    81758167      } else if (regs.u.r8.bl == 0x86) {
     8168        if (regs.u.r8.al == 0x02) {
    81768169        BX_INFO("PCI device %04x:%04x not found at index %d\n", regs.u.r16.dx, regs.u.r16.cx, regs.u.r16.si);
     8170        } else {
     8171        BX_INFO("no PCI device with class code 0x%02x%04x found at index %d\n", regs.u.r8.cl, regs.u.r16.dx, regs.u.r16.si);
     8172        }
    81778173      }
    81788174      regs.u.r8.ah = regs.u.r8.bl;
     
    84328428
    84338429int13_disk:
     8430  ;; int13_harddisk modifies high word of EAX
     8431  shr   eax, #16
     8432  push  ax
    84348433  call  _int13_harddisk
     8434  pop   ax
     8435  shl   eax, #16
    84358436
    84368437int13_out:
     
    85348535;----------------------
    85358536floppy_drive_post:
    8536   mov  ax, #0x0000
     8537  xor  ax, ax
    85378538  mov  ds, ax
    85388539
     
    86168617  out  dx, al
    86178618
    8618   mov  ax, #0x0000
     8619  xor  ax, ax
    86198620  mov  ds, ax
    86208621  mov  0x0474, al /* hard disk status of last operation */
     
    90939094.align 16
    90949095bios32_entry_point:
    9095   pushf
     9096  pushfd
    90969097  cmp eax, #0x49435024 ;; "$PCI"
    90979098  jne unknown_service
     
    91179118  mov al, #0x80
    91189119bios32_end:
    9119   popf
     9120#ifdef BX_QEMU
     9121  and dword ptr[esp+8],0xfffffffc ;; reset CS.RPL for kqemu
     9122#endif
     9123  popfd
    91209124  retf
    91219125
    91229126.align 16
    91239127pcibios_protected:
    9124   pushf
     9128  pushfd
    91259129  cli
    91269130  push esi
     
    91359139pci_pro_f02: ;; find pci device
    91369140  cmp al, #0x02
    9137   jne pci_pro_f08
     9141  jne pci_pro_f03
    91389142  shl ecx, #16
    91399143  mov cx, dx
    9140   mov bx, #0x0000
     9144  xor bx, bx
    91419145  mov di, #0x00
    91429146pci_pro_devloop:
     
    91539157  cmp bx, #0x0100
    91549158  jne pci_pro_devloop
     9159  mov ah, #0x86
     9160  jmp pci_pro_fail
     9161pci_pro_f03: ;; find class code
     9162  cmp al, #0x03
     9163  jne pci_pro_f08
     9164  xor bx, bx
     9165  mov di, #0x08
     9166pci_pro_devloop2:
     9167  call pci_pro_select_reg
     9168  mov dx, #0x0cfc
     9169  in  eax, dx
     9170  shr eax, #8
     9171  cmp eax, ecx
     9172  jne pci_pro_nextdev2
     9173  cmp si, #0
     9174  je  pci_pro_ok
     9175  dec si
     9176pci_pro_nextdev2:
     9177  inc bx
     9178  cmp bx, #0x0100
     9179  jne pci_pro_devloop2
    91559180  mov ah, #0x86
    91569181  jmp pci_pro_fail
     
    92289253  pop edi
    92299254  pop esi
    9230   popf
     9255#ifdef BX_QEMU
     9256  and dword ptr[esp+8],0xfffffffc ;; reset CS.RPL for kqemu
     9257#endif
     9258  popfd
    92319259  stc
    92329260  retf
     
    92359263  pop edi
    92369264  pop esi
    9237   popf
     9265#ifdef BX_QEMU
     9266  and dword ptr[esp+8],0xfffffffc ;; reset CS.RPL for kqemu
     9267#endif
     9268  popfd
    92389269  clc
    92399270  retf
     
    92929323  push edi
    92939324  cmp al, #0x02
    9294   jne pci_real_f08
     9325  jne pci_real_f03
    92959326  shl ecx, #16
    92969327  mov cx, dx
    9297   mov bx, #0x0000
     9328  xor bx, bx
    92989329  mov di, #0x00
    92999330pci_real_devloop:
     
    93129343  mov dx, cx
    93139344  shr ecx, #16
    9314   mov ah, #0x86
     9345  mov ax, #0x8602
     9346  jmp pci_real_fail
     9347pci_real_f03: ;; find class code
     9348  cmp al, #0x03
     9349  jne pci_real_f08
     9350  xor bx, bx
     9351  mov di, #0x08
     9352pci_real_devloop2:
     9353  call pci_real_select_reg
     9354  mov dx, #0x0cfc
     9355  in  eax, dx
     9356  shr eax, #8
     9357  cmp eax, ecx
     9358  jne pci_real_nextdev2
     9359  cmp si, #0
     9360  je  pci_real_ok
     9361  dec si
     9362pci_real_nextdev2:
     9363  inc bx
     9364  cmp bx, #0x0100
     9365  jne pci_real_devloop2
     9366  mov dx, cx
     9367  shr ecx, #16
     9368  mov ax, #0x8603
    93159369  jmp pci_real_fail
    93169370pci_real_f08: ;; read configuration byte
     
    96059659pci_routing_table_structure_end:
    96069660
     9661#if !BX_ROMBIOS32
    96079662pci_irq_list:
    96089663  db 11, 10, 9, 5;
     
    98259880  pop  ds
    98269881  ret
     9882#endif // BX_ROMBIOS32
    98279883#endif // BX_PCIBIOS
     9884
     9885#if BX_ROMBIOS32
     9886rombios32_init:
     9887  ;; save a20 and enable it
     9888  in al, 0x92
     9889  push ax
     9890  or al, #0x02
     9891  out 0x92, al
     9892
     9893  ;; save SS:SP to the BDA
     9894  xor ax, ax
     9895  mov ds, ax
     9896  mov 0x0469, ss
     9897  mov 0x0467, sp
     9898
     9899  SEG CS
     9900    lidt [pmode_IDT_info]
     9901  SEG CS
     9902    lgdt [rombios32_gdt_48]
     9903  ;; set PE bit in CR0
     9904  mov  eax, cr0
     9905  or   al, #0x01
     9906  mov  cr0, eax
     9907  ;; start protected mode code: ljmpl 0x10:rombios32_init1
     9908  db 0x66, 0xea
     9909  dw rombios32_05
     9910  dw 0x000f       ;; high 16 bit address
     9911  dw 0x0010
     9912
     9913use32 386
     9914rombios32_05:
     9915  ;; init data segments
     9916  mov eax, #0x18
     9917  mov ds, ax
     9918  mov es, ax
     9919  mov ss, ax
     9920  xor eax, eax
     9921  mov fs, ax
     9922  mov gs, ax
     9923  cld
     9924
     9925  ;; copy rombios32 code to ram (ram offset = 1MB)
     9926  mov esi, #0xfffe0000
     9927  mov edi, #0x00040000
     9928  mov ecx, #0x10000 / 4
     9929  rep
     9930    movsd
     9931
     9932  ;; init the stack pointer
     9933  mov esp, #0x00080000
     9934
     9935  ;; call rombios32 code
     9936  mov eax, #0x00040000
     9937  call eax
     9938
     9939  ;; return to 16 bit protected mode first
     9940  db 0xea
     9941  dd rombios32_10
     9942  dw 0x20
     9943
     9944use16 386
     9945rombios32_10:
     9946  ;; restore data segment limits to 0xffff
     9947  mov ax, #0x28
     9948  mov ds, ax
     9949  mov es, ax
     9950  mov ss, ax
     9951  mov fs, ax
     9952  mov gs, ax
     9953
     9954  ;; reset PE bit in CR0
     9955  mov  eax, cr0
     9956  and  al, #0xFE
     9957  mov  cr0, eax
     9958
     9959  ;; far jump to flush CPU queue after transition to real mode
     9960  JMP_AP(0xf000, rombios32_real_mode)
     9961
     9962rombios32_real_mode:
     9963  ;; restore IDT to normal real-mode defaults
     9964  SEG CS
     9965    lidt [rmode_IDT_info]
     9966
     9967  xor ax, ax
     9968  mov ds, ax
     9969  mov es, ax
     9970  mov fs, ax
     9971  mov gs, ax
     9972
     9973  ;; restore SS:SP from the BDA
     9974  mov ss, 0x0469
     9975  xor esp, esp
     9976  mov sp, 0x0467
     9977  ;; restore a20
     9978  pop ax
     9979  out 0x92, al
     9980  ret
     9981
     9982rombios32_gdt_48:
     9983  dw 0x30
     9984  dw rombios32_gdt                 
     9985  dw 0x000f
     9986
     9987rombios32_gdt:
     9988  dw 0, 0, 0, 0
     9989  dw 0, 0, 0, 0
     9990  dw 0xffff, 0, 0x9b00, 0x00cf ; 32 bit flat code segment (0x10)
     9991  dw 0xffff, 0, 0x9300, 0x00cf ; 32 bit flat data segment (0x18)
     9992  dw 0xffff, 0, 0x9b0f, 0x0000 ; 16 bit code segment base=0xf0000 limit=0xffff
     9993  dw 0xffff, 0, 0x9300, 0x0000 ; 16 bit data segment base=0x0 limit=0xffff
     9994#endif
     9995
    98289996
    98299997; parallel port detection: base address in DX, index in BX, timeout in CL
     
    995710125
    995810126
     10127;; the following area can be used to write dynamically generated tables
     10128  .align 16
     10129bios_table_area_start:
     10130  dd 0xaafb4442
     10131  dd bios_table_area_end - bios_table_area_start - 8;
     10132
    995910133;--------
    996010134;- POST -
    996110135;--------
    996210136.org 0xe05b ; POST Entry Point
     10137bios_table_area_end:
    996310138post:
    996410139
     
    1002910204  mov  ax, #0xfffe
    1003010205  mov  sp, ax
    10031   mov  ax, #0x0000
     10206  xor  ax, ax
    1003210207  mov  ds, ax
    1003310208  mov  ss, ax
     
    1004410219
    1004510220  ;; set all interrupts to default handler
    10046   mov  bx, #0x0000    ;; offset index
     10221  xor  bx, bx         ;; offset index
    1004710222  mov  cx, #0x0100    ;; counter (256 interrupts)
    1004810223  mov  ax, #dummy_iret_handler
     
    1022410399  out  0xa1, AL ;slave  pic: unmask IRQ 12, 13, 14
    1022510400
     10401#if BX_ROMBIOS32
     10402  call rombios32_init
     10403#else
    1022610404#if 0 /* This currently breaks restoring a previously saved state. */
    1022710405  call pcibios_init_iomem_bases
    1022810406#endif
    1022910407  call pcibios_init_irqs
    10230 
     10408#endif
    1023110409  call rom_scan
    1023210410
     
    1037910557  push ds
    1038010558  pusha
    10381   mov  ax, #0x0000
     10559  xor  ax, ax
    1038210560  mov  ds, ax
    1038310561  call _int14_function
     
    1057010748int0e_normal:
    1057110749  push ds
    10572   mov  ax, #0x0000 ;; segment 0000
     10750  xor  ax, ax ;; segment 0000
    1057310751  mov  ds, ax
    1057410752  call eoi_master_pic
     
    1060710785  push ds
    1060810786  pusha
    10609   mov  ax, #0x0000
     10787  xor  ax, ax
    1061010788  mov  ds, ax
    1061110789  call _int17_function
     
    1084111019
    1084211020.org 0xfef3 ; Initial Interrupt Vector Offsets Loaded by POST
     11021
    1084311022
    1084411023.org 0xff00
Note: See TracChangeset for help on using the changeset viewer.

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