📄 ide.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name: ide.h
Abstract: Boot loader IDE support code.
Functions: None.
Notes:
--*/
#ifndef _IDE_H_
#define _IDE_H_
#define DRIVE_NUM 0
//
// Configuration register for PCMCIA cards
//
#define CF_CONFIG (volatile unsigned char *)(PCMCIACARD_ATTRIBUTE + 0x200)
#define CONFIG_SRESET 0x80
#define CONFIG_LEVIRQ 0x40
#define CONFIG_INDEX_MASK 0x3F
#define IDE_DATA_REG 0
#define IDE_ERROR_REG 1
#define IDE_SECTCNT_REG 2
#define IDE_SECTNUM_REG 3
#define IDE_CYLL_REG 4
#define IDE_CYLH_REG 5
#define IDE_DRVHD_REG 6
#define IDE_CMD_REG 7
#define IDE_STAT_REG 7
#define IDE_ALT_CTRL_REG 14
#define IDE_ALT_STAT_REG 14
#define IDE_ALT_DRVADDR_REG 15
//
// IDE commands
//
#define IDE_DIAG_CMD 0x90
#define IDE_RDSECTY_CMD 0x20
#define IDE_RDSECT_CMD 0x21
#define IDE_RDBUFF_CMD 0xe4
#define IDE_IDDRIVE_CMD 0xec
#define IDE_ALT_CTRL_SRST 0x04 // Software reset
#define IDE_ALT_CTRL_DSBL_INTR 0x02 // Disable interrupt
//
// IDE head register values
//
#define IDE_HEAD_MUST_BE_ON 0xA0 // These 2 bits are always on
#define IDE_HEAD_DRIVE_1 (0x00 | IDE_HEAD_MUST_BE_ON)
#define IDE_HEAD_DRIVE_2 (0x10 | IDE_HEAD_MUST_BE_ON)
#define IDE_HEAD_LBA_MODE (0x40 | IDE_HEAD_MUST_BE_ON)
//
// IDE status register values
//
#define IDE_STATUS_IDLE 0x50
#define IDE_STATUS_DRQ 0x08
#define WAIT_IDE_BUSY while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x80) != 0)
#define WAIT_IDE_NOT_BUSY while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x80) == 0)
#define WAIT_IDE_DRQ while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x08) != 0)
#define WAIT_IDE_NOT_DRQ while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x08) == 0)
#define WAIT_IDE_DRDY while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x40) != 0)
#define WAIT_IDE_NOT_DRDY while((READ_IDE_UCHAR(IDE_STAT_REG) & 0x40) == 0)
#define IS_IDE_ERROR (READ_IDE_UCHAR(IDE_STAT_REG) & 0x1)
void WRITE_IDE_UCHAR (unsigned long, unsigned char );
void WRITE_IDE_USHORT(unsigned long, unsigned short);
void WRITE_IDE_ULONG (unsigned long, unsigned long );
unsigned char READ_IDE_UCHAR (unsigned long);
unsigned short READ_IDE_USHORT(unsigned long);
unsigned long READ_IDE_ULONG (unsigned long);
//
// Type definitions.
//
typedef struct // Drive ID header.
{
USHORT gen;
USHORT lcyls; // P-CHS cyls.
USHORT rsvd1;
USHORT lheads; // P-CHS heads.
USHORT bytptrk;
USHORT bytpsct;
USHORT lsctptrk; // P-CHS sect per track.
USHORT gap;
USHORT pll;
USHORT venstat;
UCHAR sn[20];
USHORT ctltype;
USHORT bufsz;
USHORT eccbyts;
UCHAR firmrev[8];
UCHAR mn[40];
USHORT rwmults;
USHORT dwio;
USHORT rsvd2;
USHORT rsvd3;
USHORT minpio;
USHORT mindma;
USHORT rsvd4;
USHORT curlcyls;
USHORT curlheads;
USHORT curlsctptrk;
ULONG cursectcap;
USHORT rsvd5;
ULONG ttladdrscts;
} drv_id_hdr, *pdrv_id_hdr;
//
// Wait type codes for WaitForDisc
//
#define WAIT_TYPE_BUSY 1
#define WAIT_TYPE_NOT_BUSY 2
#define WAIT_TYPE_READY 3
#define WAIT_TYPE_DRQ 4 // wait for data request
#define WAIT_TYPE_NOT_DRQ 5
#define WAIT_TYPE_ERROR 6
DWORD OEMHDDImageCheck(VOID);
int init_ide(void);
int id_drive(void);
int ide_reset(void);
#endif // _IDE_H_.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -