📄 rombios.c
字号:
/////////////////////////////////////////////////////////////////////////// $Id: rombios.c,v 1.138 2005/05/07 15:55:26 vruppert Exp $///////////////////////////////////////////////////////////////////////////// Copyright (C) 2002 MandrakeSoft S.A.//// MandrakeSoft S.A.// 43, rue d'Aboukir// 75002 Paris - France// http://www.linux-mandrake.com/// http://www.mandrakesoft.com///// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA// ROM BIOS for use with Bochs/Plex x86 emulation environment#define uint8_t unsigned char#define uint16_t unsigned short#define uint32_t unsigned long#include "../hvmloader/config.h"#define HVMASSIST#undef HVMTEST// Xen full virtualization does not handle unaligned IO with page crossing.// Disable 32-bit PIO as a workaround.#undef NO_PIO32// ROM BIOS compatability entry points:// ===================================// $e05b ; POST Entry Point// $e2c3 ; NMI Handler Entry Point// $e3fe ; INT 13h Fixed Disk Services Entry Point// $e401 ; Fixed Disk Parameter Table// $e6f2 ; INT 19h Boot Load Service Entry Point// $e6f5 ; Configuration Data Table// $e729 ; Baud Rate Generator Table// $e739 ; INT 14h Serial Communications Service Entry Point// $e82e ; INT 16h Keyboard Service Entry Point// $e987 ; INT 09h Keyboard Service Entry Point// $ec59 ; INT 13h Diskette Service Entry Point// $ef57 ; INT 0Eh Diskette Hardware ISR Entry Point// $efc7 ; Diskette Controller Parameter Table// $efd2 ; INT 17h Printer Service Entry Point// $f045 ; INT 10 Functions 0-Fh Entry Point// $f065 ; INT 10h Video Support Service Entry Point// $f0a4 ; MDA/CGA Video Parameter Table (INT 1Dh)// $f841 ; INT 12h Memory Size Service Entry Point// $f84d ; INT 11h Equipment List Service Entry Point// $f859 ; INT 15h System Services Entry Point// $fa6e ; Character Font for 320x200 & 640x200 Graphics (lower 128 characters)// $fe6e ; INT 1Ah Time-of-day Service Entry Point// $fea5 ; INT 08h System Timer ISR Entry Point// $fef3 ; Initial Interrupt Vector Offsets Loaded by POST// $ff53 ; IRET Instruction for Dummy Interrupt Handler// $ff54 ; INT 05h Print Screen Service Entry Point// $fff0 ; Power-up Entry Point// $fff5 ; ASCII Date ROM was built - 8 characters in MM/DD/YY// $fffe ; System Model ID// NOTES for ATA/ATAPI driver (cbbochs@free.fr)// Features// - supports up to 4 ATA interfaces// - device/geometry detection// - 16bits/32bits device access// - pchs/lba access// - datain/dataout/packet command support//// NOTES for El-Torito Boot (cbbochs@free.fr)// - CD-ROM booting is only available if ATA/ATAPI Driver is available// - Current code is only able to boot mono-session cds // - Current code can not boot and emulate a hard-disk// the bios will panic otherwise// - Current code also use memory in EBDA segement. // - I used cmos byte 0x3D to store extended information on boot-device// - Code has to be modified modified to handle multiple cdrom drives// - Here are the cdrom boot failure codes:// 1 : no atapi device found// 2 : no atapi cdrom found// 3 : can not read cd - BRVD// 4 : cd is not eltorito (BRVD)// 5 : cd is not eltorito (ISO TAG)// 6 : cd is not eltorito (ELTORITO TAG)// 7 : can not read cd - boot catalog// 8 : boot catalog : bad header// 9 : boot catalog : bad platform// 10 : boot catalog : bad signature// 11 : boot catalog : bootable flag not set// 12 : can not read cd - boot image//// ATA driver// - EBDA segment. // I used memory starting at 0x121 in the segment// - the translation policy is defined in cmos regs 0x39 & 0x3a//// TODO ://// int74 // - needs to be reworked. Uses direct [bp] offsets. (?)//// int13:// - f04 (verify sectors) isn't complete (?)// - f02/03/04 should set current cyl,etc in BDA (?)// - rewrite int13_relocated & clean up int13 entry code//// NOTES:// - NMI access (bit7 of addr written to 70h)//// ATA driver// - should handle the "don't detect" bit (cmos regs 0x3b & 0x3c)// - could send the multiple-sector read/write commands//// El-Torito// - Emulate a Hard-disk (currently only diskette can be emulated) see "FIXME ElTorito Harddisk"// - Implement remaining int13_cdemu functions (as defined by El-Torito specs)// - cdrom drive is hardcoded to ide 0 device 1 in several places. see "FIXME ElTorito Hardcoded"// - int13 Fix DL when emulating a cd. In that case DL is decremented before calling real int13.// This is ok. But DL should be reincremented afterwards. // - Fix all "FIXME ElTorito Various"// - should be able to boot any cdrom instead of the first one//// BCC Bug: find a generic way to handle the bug of #asm after an "if" (fixed in 0.16.7)#define DEBUG_ROMBIOS 0#define DEBUG_ATA 0#define DEBUG_INT13_HD 0#define DEBUG_INT13_CD 0#define DEBUG_INT13_ET 0#define DEBUG_INT13_FL 0#define DEBUG_INT15 0#define DEBUG_INT16 0#define DEBUG_INT1A 0#define DEBUG_INT74 0#define DEBUG_APM 0#define BX_CPU 3#define BX_USE_PS2_MOUSE 1#define BX_CALL_INT15_4F 1#define BX_USE_EBDA 1#define BX_SUPPORT_FLOPPY 1#define BX_FLOPPY_ON_CNT 37 /* 2 seconds */#define BX_PCIBIOS 1#define BX_APM 1#define BX_USE_ATADRV 1#define BX_ELTORITO_BOOT 1#define BX_TCGBIOS 0 /* main switch for TCG BIOS ext. */#define BX_MAX_ATA_INTERFACES 4#define BX_MAX_ATA_DEVICES (BX_MAX_ATA_INTERFACES*2)#define BX_VIRTUAL_PORTS 1 /* normal output to Bochs ports */#define BX_DEBUG_SERIAL 0 /* output to COM1 */ /* model byte 0xFC = AT */#define SYS_MODEL_ID 0xFC#define SYS_SUBMODEL_ID 0x00#define BIOS_REVISION 1#define BIOS_CONFIG_TABLE 0xe6f5#ifndef BIOS_BUILD_DATE# define BIOS_BUILD_DATE "06/23/99"#endif // 1K of base memory used for Extended Bios Data Area (EBDA) // EBDA is used for PS/2 mouse support, and IDE BIOS, etc.#define EBDA_SEG 0x9FC0#define EBDA_SIZE 1 // In KiB#define BASE_MEM_IN_K (640 - EBDA_SIZE) // Define the application NAME#ifdef HVMASSIST# define BX_APPNAME "HVMAssist"#elif PLEX86# define BX_APPNAME "Plex86"#else# define BX_APPNAME "Bochs"#endif // Sanity Checks#if BX_USE_ATADRV && BX_CPU<3# error The ATA/ATAPI Driver can only to be used with a 386+ cpu#endif#if BX_USE_ATADRV && !BX_USE_EBDA# error ATA/ATAPI Driver can only be used if EBDA is available#endif#if BX_ELTORITO_BOOT && !BX_USE_ATADRV# error El-Torito Boot can only be use if ATA/ATAPI Driver is available#endif#if BX_PCIBIOS && BX_CPU<3# error PCI BIOS can only be used with 386+ cpu#endif#if BX_APM && BX_CPU<3# error APM BIOS can only be used with 386+ cpu#endif#ifndef BX_SMP_PROCESSORS#define BX_SMP_PROCESSORS 1# warning BX_SMP_PROCESSORS not defined, defaulting to 1#endif #define PANIC_PORT 0x400#define PANIC_PORT2 0x401#define INFO_PORT 0x402#define DEBUG_PORT 0x403// #20 is dec 20// #$20 is hex 20 = 32// #0x20 is hex 20 = 32// LDA #$20// JSR $E820// LDD .i,S// JSR $C682// mov al, #$20// all hex literals should be prefixed with '0x'// grep "#[0-9a-fA-F][0-9a-fA-F]" rombios.c// no mov SEG-REG, #value, must mov register into seg-reg// grep -i "mov[ ]*.s" rombios.c// This is for compiling with gcc2 and gcc3#define ASM_START #asm#define ASM_END #endasmASM_START.rom.org 0x0000#if BX_CPU >= 3use16 386#elseuse16 286#endifMACRO HALT ;; the HALT macro is called with the line number of the HALT call. ;; The line number is then sent to the PANIC_PORT, causing Bochs/Plex ;; to print a BX_PANIC message. This will normally halt the simulation ;; with a message such as "BIOS panic at rombios.c, line 4091". ;; However, users can choose to make panics non-fatal and continue.#if BX_VIRTUAL_PORTS mov dx,#PANIC_PORT mov ax,#?1 out dx,ax#else mov dx,#0x80 mov ax,#?1 out dx,al#endifMENDMACRO JMP_AP db 0xea dw ?2 dw ?1MENDMACRO SET_INT_VECTOR mov ax, ?3 mov ?1*4, ax mov ax, ?2 mov ?1*4+2, axMENDASM_ENDtypedef unsigned char Bit8u;typedef unsigned short Bit16u;typedef unsigned short bx_bool;typedef unsigned long Bit32u; void memsetb(seg,offset,value,count); void memcpyb(dseg,doffset,sseg,soffset,count); void memcpyd(dseg,doffset,sseg,soffset,count); // memset of count bytes void memsetb(seg,offset,value,count) Bit16u seg; Bit16u offset; Bit16u value; Bit16u count; { ASM_START push bp mov bp, sp push ax push cx push es push di mov cx, 10[bp] ; count cmp cx, #0x00 je memsetb_end mov ax, 4[bp] ; segment mov es, ax mov ax, 6[bp] ; offset mov di, ax mov al, 8[bp] ; value cld rep stosb memsetb_end: pop di pop es pop cx pop ax pop bp ASM_END } // memcpy of count bytes void memcpyb(dseg,doffset,sseg,soffset,count) Bit16u dseg; Bit16u doffset; Bit16u sseg; Bit16u soffset; Bit16u count; { ASM_START push bp mov bp, sp push ax push cx push es push di push ds push si mov cx, 12[bp] ; count cmp cx, #0x0000 je memcpyb_end mov ax, 4[bp] ; dsegment mov es, ax mov ax, 6[bp] ; doffset mov di, ax mov ax, 8[bp] ; ssegment mov ds, ax mov ax, 10[bp] ; soffset mov si, ax cld rep movsb memcpyb_end: pop si pop ds pop di pop es pop cx pop ax pop bp ASM_END }#if 0 // memcpy of count dword void memcpyd(dseg,doffset,sseg,soffset,count) Bit16u dseg; Bit16u doffset; Bit16u sseg; Bit16u soffset; Bit16u count; { ASM_START push bp mov bp, sp push ax push cx push es push di push ds push si mov cx, 12[bp] ; count cmp cx, #0x0000 je memcpyd_end mov ax, 4[bp] ; dsegment mov es, ax mov ax, 6[bp] ; doffset mov di, ax mov ax, 8[bp] ; ssegment mov ds, ax mov ax, 10[bp] ; soffset mov si, ax cld rep movsd memcpyd_end: pop si pop ds pop di pop es pop cx pop ax pop bp ASM_END }#endif // read_dword and write_dword functions static Bit32u read_dword(); static void write_dword(); Bit32u read_dword(seg, offset) Bit16u seg; Bit16u offset; { ASM_START push bp mov bp, sp push bx push ds mov ax, 4[bp] ; segment mov ds, ax mov bx, 6[bp] ; offset mov ax, [bx] inc bx inc bx mov dx, [bx] ;; ax = return value (word) ;; dx = return value (word) pop ds pop bx pop bp ASM_END } void write_dword(seg, offset, data) Bit16u seg; Bit16u offset; Bit32u data; { ASM_START push bp mov bp, sp push ax push bx push ds mov ax, 4[bp] ; segment mov ds, ax mov bx, 6[bp] ; offset mov ax, 8[bp] ; data word mov [bx], ax ; write data word inc bx inc bx mov ax, 10[bp] ; data word mov [bx], ax ; write data word pop ds pop bx pop ax pop bp ASM_END } // Bit32u (unsigned long) and long helper functions ASM_START ;; and function landl: landul: SEG SS and ax,[di] SEG SS and bx,2[di] ret ;; add function laddl: laddul: SEG SS add ax,[di] SEG SS adc bx,2[di] ret ;; cmp function lcmpl: lcmpul:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -