rombios.c File Reference

Go to the source code of this file.

Data Structures

struct  bios_data_t
struct  chs_t
struct  dpte_t
struct  ata_channel_t
struct  ata_device_t
struct  ata_t
struct  ebda_data_t
struct  int13ext_t
struct  dpt_t
struct  pusha_regs_t
struct  pushad_regs_t
struct  flags_t
struct  iret_addr_t

Defines

#define DEBUG_ROMBIOS   1
#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
#define BX_APM   0
#define COREBOOT   1
#define BX_USE_ATADRV   1
#define BX_MAX_ATA_INTERFACES   4
#define BX_MAX_ATA_DEVICES   (BX_MAX_ATA_INTERFACES*2)
#define BX_VIRTUAL_PORTS   1
#define BX_DEBUG_SERIAL   1
#define SYS_MODEL_ID   0xFC
#define SYS_SUBMODEL_ID   0x00
#define BIOS_REVISION   1
#define BIOS_CONFIG_TABLE   0xe6f5
#define BIOS_BUILD_DATE   "06/23/99"
#define EBDA_SEG   0x9FC0
#define EBDA_SIZE   1
#define BASE_MEM_IN_K   (640 - EBDA_SIZE)
#define BX_APPNAME   "Bochs"
#define PANIC_PORT   0x400
#define PANIC_PORT2   0x401
#define INFO_PORT   0x402
#define DEBUG_PORT   0x403
#define PCI_FIXED_HOST_BRIDGE   0x12378086 ;; i440FX PCI bridge
#define ASM_START   #asm
#define ASM_END   #endasm
#define BiosData   ((bios_data_t *) 0)
#define EbdaData   ((ebda_data_t *) 0)
#define Int13Ext   ((int13ext_t *) 0)
#define Int13DPT   ((dpt_t *) 0)
#define SetCF(x)   x.u.r8.flagsl |= 0x01
#define SetZF(x)   x.u.r8.flagsl |= 0x40
#define ClearCF(x)   x.u.r8.flagsl &= 0xfe
#define ClearZF(x)   x.u.r8.flagsl &= 0xbf
#define GetCF(x)   (x.u.r8.flagsl & 0x01)
#define BIOS_COPYRIGHT_STRING   "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
#define BIOS_PRINTF_HALT   1
#define BIOS_PRINTF_SCREEN   2
#define BIOS_PRINTF_INFO   4
#define BIOS_PRINTF_DEBUG   8
#define BIOS_PRINTF_ALL   (BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO)
#define BIOS_PRINTF_DEBHALT   (BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO | BIOS_PRINTF_HALT)
#define printf(format, p...)   bios_printf(BIOS_PRINTF_SCREEN, format, ##p)
#define BX_DEBUG(format, p...)   bios_printf(BIOS_PRINTF_INFO, format, ##p)
#define BX_INFO(format, p...)   bios_printf(BIOS_PRINTF_INFO, format, ##p)
#define BX_PANIC(format, p...)   bios_printf(BIOS_PRINTF_DEBHALT, format, ##p)
#define BX_DEBUG_ATA(a...)
#define BX_DEBUG_INT13_HD(a...)
#define BX_DEBUG_INT13_CD(a...)
#define BX_DEBUG_INT13_ET(a...)
#define BX_DEBUG_INT13_FL(a...)
#define BX_DEBUG_INT15(a...)
#define BX_DEBUG_INT16(a...)
#define BX_DEBUG_INT1A(a...)
#define BX_DEBUG_INT74(a...)
#define SET_AL(val8)   AX = ((AX & 0xff00) | (val8))
#define SET_BL(val8)   BX = ((BX & 0xff00) | (val8))
#define SET_CL(val8)   CX = ((CX & 0xff00) | (val8))
#define SET_DL(val8)   DX = ((DX & 0xff00) | (val8))
#define SET_AH(val8)   AX = ((AX & 0x00ff) | ((val8) << 8))
#define SET_BH(val8)   BX = ((BX & 0x00ff) | ((val8) << 8))
#define SET_CH(val8)   CX = ((CX & 0x00ff) | ((val8) << 8))
#define SET_DH(val8)   DX = ((DX & 0x00ff) | ((val8) << 8))
#define GET_AL()   ( AX & 0x00ff )
#define GET_BL()   ( BX & 0x00ff )
#define GET_CL()   ( CX & 0x00ff )
#define GET_DL()   ( DX & 0x00ff )
#define GET_AH()   ( AX >> 8 )
#define GET_BH()   ( BX >> 8 )
#define GET_CH()   ( CX >> 8 )
#define GET_DH()   ( DX >> 8 )
#define GET_ELDL()   ( ELDX & 0x00ff )
#define GET_ELDH()   ( ELDX >> 8 )
#define SET_CF()   FLAGS |= 0x0001
#define CLEAR_CF()   FLAGS &= 0xfffe
#define GET_CF()   (FLAGS & 0x0001)
#define SET_ZF()   FLAGS |= 0x0040
#define CLEAR_ZF()   FLAGS &= 0xffbf
#define GET_ZF()   (FLAGS & 0x0040)
#define UNSUPPORTED_FUNCTION   0x86
#define none   0
#define MAX_SCAN_CODE   0x58
#define BX_DEBUG_PORT   0x03f8
#define UART_RBR   0x00
#define UART_THR   0x00
#define UART_IER   0x01
#define UART_IIR   0x02
#define UART_FCR   0x02
#define UART_LCR   0x03
#define UART_MCR   0x04
#define UART_DLL   0x00
#define UART_DLM   0x01
#define UART_LSR   0x05
#define UART_MSR   0x06
#define UART_SCR   0x07
#define ATA_CB_DATA   0
#define ATA_CB_ERR   1
#define ATA_CB_FR   1
#define ATA_CB_SC   2
#define ATA_CB_SN   3
#define ATA_CB_CL   4
#define ATA_CB_CH   5
#define ATA_CB_DH   6
#define ATA_CB_STAT   7
#define ATA_CB_CMD   7
#define ATA_CB_ASTAT   6
#define ATA_CB_DC   6
#define ATA_CB_DA   7
#define ATA_CB_ER_ICRC   0x80
#define ATA_CB_ER_BBK   0x80
#define ATA_CB_ER_UNC   0x40
#define ATA_CB_ER_MC   0x20
#define ATA_CB_ER_IDNF   0x10
#define ATA_CB_ER_MCR   0x08
#define ATA_CB_ER_ABRT   0x04
#define ATA_CB_ER_NTK0   0x02
#define ATA_CB_ER_NDAM   0x01
#define ATA_CB_ER_P_SNSKEY   0xf0
#define ATA_CB_ER_P_MCR   0x08
#define ATA_CB_ER_P_ABRT   0x04
#define ATA_CB_ER_P_EOM   0x02
#define ATA_CB_ER_P_ILI   0x01
#define ATA_CB_SC_P_TAG   0xf8
#define ATA_CB_SC_P_REL   0x04
#define ATA_CB_SC_P_IO   0x02
#define ATA_CB_SC_P_CD   0x01
#define ATA_CB_DH_DEV0   0xa0
#define ATA_CB_DH_DEV1   0xb0
#define ATA_CB_STAT_BSY   0x80
#define ATA_CB_STAT_RDY   0x40
#define ATA_CB_STAT_DF   0x20
#define ATA_CB_STAT_WFT   0x20
#define ATA_CB_STAT_SKC   0x10
#define ATA_CB_STAT_SERV   0x10
#define ATA_CB_STAT_DRQ   0x08
#define ATA_CB_STAT_CORR   0x04
#define ATA_CB_STAT_IDX   0x02
#define ATA_CB_STAT_ERR   0x01
#define ATA_CB_STAT_CHK   0x01
#define ATA_CB_DC_HD15   0x08
#define ATA_CB_DC_SRST   0x04
#define ATA_CB_DC_NIEN   0x02
#define ATA_CMD_CFA_ERASE_SECTORS   0xC0
#define ATA_CMD_CFA_REQUEST_EXT_ERR_CODE   0x03
#define ATA_CMD_CFA_TRANSLATE_SECTOR   0x87
#define ATA_CMD_CFA_WRITE_MULTIPLE_WO_ERASE   0xCD
#define ATA_CMD_CFA_WRITE_SECTORS_WO_ERASE   0x38
#define ATA_CMD_CHECK_POWER_MODE1   0xE5
#define ATA_CMD_CHECK_POWER_MODE2   0x98
#define ATA_CMD_DEVICE_RESET   0x08
#define ATA_CMD_EXECUTE_DEVICE_DIAGNOSTIC   0x90
#define ATA_CMD_FLUSH_CACHE   0xE7
#define ATA_CMD_FORMAT_TRACK   0x50
#define ATA_CMD_IDENTIFY_DEVICE   0xEC
#define ATA_CMD_IDENTIFY_DEVICE_PACKET   0xA1
#define ATA_CMD_IDENTIFY_PACKET_DEVICE   0xA1
#define ATA_CMD_IDLE1   0xE3
#define ATA_CMD_IDLE2   0x97
#define ATA_CMD_IDLE_IMMEDIATE1   0xE1
#define ATA_CMD_IDLE_IMMEDIATE2   0x95
#define ATA_CMD_INITIALIZE_DRIVE_PARAMETERS   0x91
#define ATA_CMD_INITIALIZE_DEVICE_PARAMETERS   0x91
#define ATA_CMD_NOP   0x00
#define ATA_CMD_PACKET   0xA0
#define ATA_CMD_READ_BUFFER   0xE4
#define ATA_CMD_READ_DMA   0xC8
#define ATA_CMD_READ_DMA_QUEUED   0xC7
#define ATA_CMD_READ_MULTIPLE   0xC4
#define ATA_CMD_READ_SECTORS   0x20
#define ATA_CMD_READ_VERIFY_SECTORS   0x40
#define ATA_CMD_RECALIBRATE   0x10
#define ATA_CMD_SEEK   0x70
#define ATA_CMD_SET_FEATURES   0xEF
#define ATA_CMD_SET_MULTIPLE_MODE   0xC6
#define ATA_CMD_SLEEP1   0xE6
#define ATA_CMD_SLEEP2   0x99
#define ATA_CMD_STANDBY1   0xE2
#define ATA_CMD_STANDBY2   0x96
#define ATA_CMD_STANDBY_IMMEDIATE1   0xE0
#define ATA_CMD_STANDBY_IMMEDIATE2   0x94
#define ATA_CMD_WRITE_BUFFER   0xE8
#define ATA_CMD_WRITE_DMA   0xCA
#define ATA_CMD_WRITE_DMA_QUEUED   0xCC
#define ATA_CMD_WRITE_MULTIPLE   0xC5
#define ATA_CMD_WRITE_SECTORS   0x30
#define ATA_CMD_WRITE_VERIFY   0x3C
#define ATA_IFACE_NONE   0x00
#define ATA_IFACE_ISA   0x00
#define ATA_IFACE_PCI   0x01
#define ATA_TYPE_NONE   0x00
#define ATA_TYPE_UNKNOWN   0x01
#define ATA_TYPE_ATA   0x02
#define ATA_TYPE_ATAPI   0x03
#define ATA_DEVICE_NONE   0x00
#define ATA_DEVICE_HD   0xFF
#define ATA_DEVICE_CDROM   0x05
#define ATA_MODE_NONE   0x00
#define ATA_MODE_PIO16   0x00
#define ATA_MODE_PIO32   0x01
#define ATA_MODE_ISADMA   0x02
#define ATA_MODE_PCIDMA   0x03
#define ATA_MODE_USEIRQ   0x10
#define ATA_TRANSLATION_NONE   0
#define ATA_TRANSLATION_LBA   1
#define ATA_TRANSLATION_LARGE   2
#define ATA_TRANSLATION_RECHS   3
#define ATA_DATA_NO   0x00
#define ATA_DATA_IN   0x01
#define ATA_DATA_OUT   0x02
#define SET_DISK_RET_STATUS(status)   write_byte(0x0040, 0x0074, status)

Typedefs

typedef unsigned short Bit16u
typedef unsigned short bx_bool
typedef unsigned long Bit32u

Functions

void memsetb (seg, offset, value, count)
void memcpyb (dseg, doffset, sseg, soffset, count)
void memcpyd (dseg, doffset, sseg, soffset, count)
void memsetb (Bit16u seg, Bit16u offset, Bit16u value, Bit16u count)
static Bit32u read_dword ()
static void write_dword ()
Bit32u read_dword (Bit16u seg, Bit16u offset)
void write_dword (Bit16u seg, Bit16u offset, Bit32u data)
static Bit8u inb ()
static Bit8u inb_cmos ()
static void outb ()
static void outb_cmos ()
static Bit16u inw ()
static void outw ()
static void init_rtc ()
static bx_bool rtc_updating ()
static Bit8u read_byte ()
static Bit16u read_word ()
static void write_byte ()
static void write_word ()
static void bios_printf ()
static Bit8u inhibit_mouse_int_and_events ()
static void enable_mouse_int_and_events ()
static Bit8u send_to_mouse_ctrl ()
static Bit8u get_mouse_data ()
static void set_kbd_command_byte ()
static void int09_function ()
static void int13_harddisk ()
static void int13_cdrom ()
static void int13_cdemu ()
static void int13_eltorito ()
static void int13_diskette_function ()
static void int14_function ()
static void int15_function ()
static void int16_function ()
static void int17_function ()
static Bit32u int19_function ()
static void int1a_function ()
static void int70_function ()
static void int74_function ()
static Bit16u get_CS ()
static Bit16u get_SS ()
static unsigned int enqueue_key ()
static unsigned int dequeue_key ()
static void get_hd_geometry ()
static void set_diskette_ret_status ()
static void set_diskette_current_cyl ()
static void determine_floppy_media ()
static bx_bool floppy_drive_exists ()
static bx_bool floppy_drive_recal ()
static bx_bool floppy_media_known ()
static bx_bool floppy_media_sense ()
static bx_bool set_enable_a20 ()
static void debugger_on ()
static void debugger_off ()
static void keyboard_init ()
static void keyboard_panic ()
static void shutdown_status_panic ()
static void nmi_handler_msg ()
static void print_bios_banner ()
static void print_boot_device ()
static void print_boot_failure ()
static void print_cdromboot_failure ()
void ata_init ()
void ata_detect ()
void ata_reset ()
Bit16u ata_cmd_non_data ()
Bit16u ata_cmd_data_in ()
Bit16u ata_cmd_data_out ()
Bit16u ata_cmd_packet ()
Bit16u atapi_get_sense ()
Bit16u atapi_is_ready ()
Bit16u atapi_is_cdrom ()
Bit8u inb (Bit16u port)
Bit16u inw (Bit16u port)
void outb (Bit16u port, Bit8u val)
void outw (Bit16u port, Bit16u val)
void outb_cmos (Bit8u cmos_reg, Bit8u val)
Bit8u inb_cmos (Bit8u cmos_reg)
Bit8u read_byte (Bit16u seg, Bit16u offset)
Bit16u read_word (Bit16u seg, Bit16u offset)
void write_byte (Bit16u seg, Bit16u offset, Bit8u data)
void write_word (Bit16u seg, Bit16u offset, Bit16u data)
int uart_can_tx_byte (Bit16u base_port)
void uart_wait_to_tx_byte (Bit16u base_port)
void uart_wait_until_sent (Bit16u base_port)
void uart_tx_byte (Bit16u base_port, Bit8u data)
void wrch (Bit8u c)
void send (Bit16u action, Bit8u c)
void put_int (Bit16u action, short val, short width, bx_bool neg)
void put_uint (Bit16u action, unsigned short val, short width, bx_bool neg)
void put_luint (Bit16u action, unsigned long val, short width, bx_bool neg)
void bios_printf (Bit16u action, Bit8u *s)
void keyboard_panic (Bit16u status)
void shutdown_status_panic (Bit16u status)
void print_boot_device (Bit8u cdboot, Bit16u drive)
void print_boot_failure (Bit8u cdboot, Bit8u drive, reason, Bit8u lastdrive)
void print_cdromboot_failure (Bit16u code)
void int18_panic_msg ()
void log_bios_start ()
bx_bool set_enable_a20 (bx_bool val)
void ata_reset (Bit16u device)
Bit16u ata_cmd_data_in (Bit16u device, Bit16u command, Bit16u count, Bit16u cylinder, Bit16u head, Bit16u sector, Bit32u lba, Bit16u segment, Bit16u offset)
Bit16u ata_cmd_data_out (Bit16u device, Bit16u command, Bit16u count, Bit16u cylinder, Bit16u head, Bit16u sector, Bit32u lba, Bit16u segment, Bit16u offset)
Bit16u ata_cmd_packet (Bit16u device, Bit8u cmdlen, Bit16u cmdseg, Bit16u cmdoff, Bit16u header, Bit32u length, Bit8u inout, Bit16u bufseg, Bit16u bufoff)
Bit16u atapi_get_sense (Bit16u device)
Bit16u atapi_is_ready (Bit16u device)
Bit16u atapi_is_cdrom (Bit8u device)
void int14_function (pusha_regs_t regs, Bit16u ds, iret_addr_t iret_addr)
void int15_function (pusha_regs_t regs, Bit16u ES, Bit16u DS, Bit16u FLAGS)
void int15_function_mouse (pusha_regs_t regs, Bit16u ES, Bit16u DS, Bit16u FLAGS)
void set_e820_range (Bit16u ES, Bit16u DI, Bit32u start, Bit32u end, Bit16u type)
void int15_function32 (pushad_regs_t regs, Bit16u ES, Bit16u DS, Bit16u FLAGS)
void int16_function (Bit16u DI, Bit16u SI, Bit16u BP, Bit16u SP, Bit16u BX, Bit16u DX, Bit16u CX, Bit16u AX, Bit16u FLAGS)
unsigned int dequeue_key (Bit8u *scan_code, Bit8u *ascii_code, unsigned int incr)
Bit8u send_to_mouse_ctrl (Bit8u sendbyte)
Bit8u get_mouse_data (Bit8u *data)
void set_kbd_command_byte (Bit8u command_byte)
void int09_function (Bit16u DI, Bit16u SI, Bit16u BP, Bit16u SP, Bit16u BX, Bit16u DX, Bit16u CX, Bit16u AX)
unsigned int enqueue_key (Bit8u scan_code, Bit8u ascii_code)
void int74_function (Bit16u make_farcall, Bit16u Z, Bit16u Y, Bit16u X, Bit16u status)
void int13_harddisk (Bit16u DS, Bit16u ES, Bit16u DI, Bit16u SI, Bit16u BP, Bit16u ELDX, Bit16u BX, Bit16u DX, Bit16u CX, Bit16u AX, Bit16u IP, Bit16u CS, Bit16u FLAGS)
void int13_cdrom (Bit16u EHBX, Bit16u DS, Bit16u ES, Bit16u DI, Bit16u SI, Bit16u BP, Bit16u ELDX, Bit16u BX, Bit16u DX, Bit16u CX, Bit16u AX, Bit16u IP, Bit16u CS, Bit16u FLAGS)
void floppy_reset_controller ()
void floppy_prepare_controller (Bit16u drive)
bx_bool floppy_media_known (Bit16u drive)
bx_bool floppy_media_sense (Bit16u drive)
bx_bool floppy_drive_recal (Bit16u drive)
bx_bool floppy_drive_exists (Bit16u drive)
void int13_diskette_function (Bit16u DS, Bit16u ES, Bit16u DI, Bit16u SI, Bit16u BP, Bit16u ELDX, Bit16u BX, Bit16u DX, Bit16u CX, Bit16u AX, Bit16u IP, Bit16u CS, Bit16u FLAGS)
void set_diskette_ret_status (Bit8u value)
void set_diskette_current_cyl (Bit8u drive, Bit8u cyl)
void determine_floppy_media (Bit16u drive)
void int17_function (pusha_regs_t regs, Bit16u ds, iret_addr_t iret_addr)
Bit32u int19_function (Bit8u bseqnr)
void int1a_function (pusha_regs_t regs, Bit16u ds, iret_addr_t iret_addr)
void int70_function (pusha_regs_t regs, Bit16u ds, iret_addr_t iret_addr)
 INT13h (relocated)-
put new val in BDA (diskette controller information)
diskette current cylinder mov out SET_INT_VECTOR (0x0E,#0xF000,#int0e_handler)
move disk geometry data from
CMOS to EBDA disk parameter 
table (s)

Variables

ASM_START rom org use16 MACRO HALT
the HALT macro is called with
the line number of the HALT 
call
The line number is then sent to the PANIC_PORT
The line number is then sent
to the 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
with a message such as BIOS
panic at rombios 
line
 However
users can choose to make
panics non fatal and continue
mov 
dx
users can choose to make
panics non fatal and continue
mov mov 
ax
users can choose to make
panics non fatal and continue
mov mov out ax MEND MACRO
JMP_AP db dw dw MEND MACRO
SET_INT_VECTOR mov mov ax mov
mov ax MEND ASM_END typedef
unsigned char 
Bit8u
 ASM_START
and function landl
and function SEG SS and bx
and function SEG SS and ret
add function laddl
cmp function lcmpl
cmp function shl ebx
cmp function shl add eax
sub