⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ata.h

📁 c语言编的网络操作系统。具备网络操作系统基本功能。
💻 H
字号:
/*
nexOS: nexos generic ata driver - generic ata driver
Copyright 2004 nexOS development team

This file is part of nexOS.

nexOS 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.1 of the License, or
(at your option) any later version.

nexOS 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 nexOS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ 

#ifndef __ATA_H__
#define __ATA_H__

#include <types.h>
#include "../../../irq/trap.h"

/* controller base ports */
#define ATA_PRIM_CONT   0x01F0
#define ATA_SEC_CONT    0x0170

/* registers */
#define ATA_DATA_REG    0x0000
#define ATA_ERR_REG     0x0001
#define ATA_SECTCNT_REG 0x0002
#define ATA_SECTNUM_REG 0x0003
#define ATA_CYLLOW_REG  0x0004
#define ATA_CYLHI_REG   0x0005
#define ATA_DRVHD_REG   0x0006
#define ATA_CMD_REG     0x0007

/* errors */
#define ATA_ERR_NONE    0x0000
#define ATA_ERR_TIMEOUT 0x0001
#define ATA_ERR_NOTSUPP 0x0002

/* portmask for ata_command() */
#define ATA_PMSK_DATA   0x01
#define ATA_PMSK_FEAT   0x02
#define ATA_PMSK_SCNT   0x04
#define ATA_PMSK_SNUM   0x08
#define ATA_PMSK_CLOW   0x10
#define ATA_PMSK_CHI    0x20
#define ATA_PMSK_DRVHD  0x40
#define ATA_PMSK_CMD    0x80
/* alternate names (portmask) */
#define ATA_PMSK_LBAL   ATA_PMSK_SNUM
#define ATA_PMSK_LBAM   ATA_PMSK_CLOW
#define ATA_PMSK_LBAH   ATA_PMSK_CHI

/* commands */
#define ATA_CMD_IDENTIFY  0xEC
#define ATA_CMD_READSECTS 0x20

/* capsfields bits */
#define ATA_CAPS_DMA    0x0100
#define ATA_CAPS_LBA    0x0200
#define ATA_CAPS_IORDY  0x0800

typedef struct ata_drive_t {
    int controller;
    int drive;
    WORD caps[2];
}ATA_DRIVE;

typedef struct block_t {
    DWORD highnum;
    DWORD lownum;
    DWORD len;
    void *buf;
}BLOCK;

typedef struct devnode_t {
    WORD usedirqs;
    WORD portstart;
    WORD portend;
    WORD dmachannel;
    char* vendor;
    char* idstring;
    DWORD rev;
    char* devname;
    void* funcarray;
    void* exdata;
}DEVNODE;


typedef int (*DRVENUMFN)(ATA_DRIVE *driverinfo, DEVNODE node);

int ata_irq[2];

unsigned int ata_irqhandler(struct trap_state_t *state);

void ata_loadsectors(ATA_DRIVE *drive, void *buf, int n);
void ata_simplecmd(ATA_DRIVE *drive, BYTE cmd);
void ata_command(ATA_DRIVE *drive, BYTE cmdseq[], int portmask);

void ata_string_swap(char *string, int chars);

int ata_select(ATA_DRIVE *drive);
int ata_identify(ATA_DRIVE *drive, void* buf);

/* these functions will be exported to nexos */
int ata_enumdrives(DRVENUMFN enumfn);
int ata_readblocks(ATA_DRIVE *drive, BLOCK block);
int ata_writeblocks(ATA_DRIVE *drive, BLOCK block);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -