亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hd.c

?? linux的內核源碼
?? C
字號:
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/hdreg.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/segment.h>

/*
 * This code handles all hd-interrupts, and read/write requests to
 * the hard-disk. It is relatively straigthforward (not obvious maybe,
 * but interrupts never are), while still being efficient, and never
 * disabling interrupts (except to overcome possible race-condition).
 * The elevator block-seek algorithm doesn't need to disable interrupts
 * due to clever programming.
 */

/* Max read/write errors/sector */
#define MAX_ERRORS	5
#define MAX_HD		2
#define NR_REQUEST	32

/*
 *  This struct defines the HD's and their types.
 *  Currently defined for CP3044's, ie a modified
 *  type 17.
 */
static struct hd_i_struct{
	int head,sect,cyl,wpcom,lzone,ctl;
	} hd_info[]= { HD_TYPE };

#define NR_HD ((sizeof (hd_info))/(sizeof (struct hd_i_struct)))

static struct hd_struct {
	long start_sect;
	long nr_sects;
} hd[5*MAX_HD]={{0,0},};			//一個硬盤可分5個區,共有2個硬盤

static struct hd_request {
	int hd;		/* -1 if no request */
	int nsector;
	int sector;
	int head;
	int cyl;
	int cmd;
	int errors;
	struct buffer_head * bh;
	struct hd_request * next;
} request[NR_REQUEST];

#define IN_ORDER(s1,s2) \
((s1)->hd<(s2)->hd || (s1)->hd==(s2)->hd && \
((s1)->cyl<(s2)->cyl || (s1)->cyl==(s2)->cyl && \
((s1)->head<(s2)->head || (s1)->head==(s2)->head && \
((s1)->sector<(s2)->sector))))

static struct hd_request * this_request = NULL;

static int sorting=0;

static void do_request(void);
static void reset_controller(void);
static void rw_abs_hd(int rw,unsigned int nr,unsigned int sec,unsigned int head,
	unsigned int cyl,struct buffer_head * bh);
void hd_init(void);

#define port_read(port,buf,nr) \
//下面的內嵌匯編的意思是:
//	movl	port	%edx
//	movl	buf	%edi
//	movl	nr	%ecx
//	cld
//	rep	insw		//從edx指定的port傳送字到es:edi指定的buf中
__asm__("cld;rep;insw"::"d" (port),"D" (buf),"c" (nr):"cx","di")

#define port_write(port,buf,nr) \
__asm__("cld;rep;outsw"::"d" (port),"S" (buf),"c" (nr):"cx","si")	//其中outsw是從ds:si指定的buf中傳送字到edx指定的port

extern void hd_interrupt(void);			//在system_call.S中定義

static struct task_struct * wait_for_request=NULL;

static inline void lock_buffer(struct buffer_head * bh)
{
	if (bh->b_lock)				//此緩沖區是否上鎖
		printk("hd.c: buffer multiply locked\n");
	bh->b_lock=1;
}

static inline void unlock_buffer(struct buffer_head * bh)
{
	if (!bh->b_lock)
		printk("hd.c: free buffer being unlocked\n");
	bh->b_lock=0;
	wake_up(&bh->b_wait);
}

static inline void wait_on_buffer(struct buffer_head * bh)
{
	cli();
	while (bh->b_lock)
		sleep_on(&bh->b_wait);		//進入等待對列
	sti();
}

void rw_hd(int rw, struct buffer_head * bh)	//緩沖區和磁盤之間交換數據
{
	unsigned int block,dev;
	unsigned int sec,head,cyl;

	block = bh->b_blocknr << 1;			//默認1塊=1024字節,二個扇區
	dev = MINOR(bh->b_dev);
	if (dev >= 5*NR_HD || block+2 > hd[dev].nr_sects)	//是否超過了分區,此分區是否滿了
		return;
	block += hd[dev].start_sect;		//此分區的開始扇區+block,即在硬盤中定開始的位置
	dev /= 5;					//看看是哪個硬盤
	__asm__("divl %4":"=a" (block),"=d" (sec):"0" (block),"1" (0),	
		"r" (hd_info[dev].sect));					//確定扇區號
	__asm__("divl %4":"=a" (cyl),"=d" (head):"0" (block),"1" (0),
		"r" (hd_info[dev].head));					//確定光頭號
	rw_abs_hd(rw,dev,sec+1,head,cyl,bh);	//實際寫盤函數
}

/* This may be used only once, enforced by 'static int callable' */
int sys_setup(void)
{
	static int callable = 1;
	int i,drive;
	struct partition *p;

	if (!callable)
		return -1;
	callable = 0;
	for (drive=0 ; drive<NR_HD ; drive++) {
		rw_abs_hd(READ,drive,1,0,0,(struct buffer_head *) start_buffer);	//讀取引導扇區512字節到start_buffer中
		if (!start_buffer->b_uptodate) {
			printk("Unable to read partition table of drive %d\n\r",
				drive);
			panic("");
		}
		if (start_buffer->b_data[510] != 0x55 || (unsigned char)
		    start_buffer->b_data[511] != 0xAA) {				//分析引導扇區是否合法,合法應為55AA
			printk("Bad partition table on drive %d\n\r",drive);
			panic("");
		}
		p = 0x1BE + (void *)start_buffer->b_data;		//指針指向分區信息的開始位置
		for (i=1;i<5;i++,p++) {				//保存分區信息
			hd[i+5*drive].start_sect = p->start_sect;
			hd[i+5*drive].nr_sects = p->nr_sects;
		}
	}
	printk("Partition table%s ok.\n\r",(NR_HD>1)?"s":"");
	mount_root();				//在super.c中定義
	return (0);
}

/*
 * This is the pointer to a routine to be executed at every hd-interrupt.
 * Interesting way of doing things, but should be rather practical.
 */
void (*do_hd)(void) = NULL;

static int controller_ready(void)
{
	int retries=1000;

	while (--retries && (inb(HD_STATUS)&0xc0)!=0x40);	//0x40是第六個位置1為驅動器準備好,0x1f7端口是讀取硬盤狀態
	return (retries);
}

static int win_result(void)
{
	int i=inb(HD_STATUS);	//讀取硬盤狀態

	if ((i & (BUSY_STAT | READY_STAT | WRERR_STAT | SEEK_STAT | ERR_STAT))
		== (READY_STAT | SEEK_STAT))
		return(0); /* ok */
	if (i&1) i=inb(HD_ERROR);	//0x1f1是硬盤錯誤寄存器,檢查上一個命令是否出錯
	return (1);
}

static void hd_out(unsigned int drive,unsigned int nsect,unsigned int sect,
		unsigned int head,unsigned int cyl,unsigned int cmd,
		void (*intr_addr)(void))
{
	register int port asm("dx");

	if (drive>1 || head>15)	//只支持1個硬盤和14個頭
		panic("Trying to write bad sector");
	if (!controller_ready())
		panic("HD controller not ready");
	do_hd = intr_addr;		//硬盤寫或讀操作指針
	outb(_CTL,HD_CMD);		//0x3f6是硬盤控制寄存器,置0為控制器為普通操作
	port=HD_DATA;			//0x1f0硬盤數據寄存器
	outb_p(_WPCOM,++port);	//0x1f1,寫預補償,在從磁柱300X4處開始寫
	outb_p(nsect,++port);	//0x1f2是硬盤扇區記數寄存器,將要傳送的扇區數放入該寄存器
	outb_p(sect,++port);		//0x1f3是硬盤扇區號寄存器,記錄當前的扇區號
	outb_p(cyl,++port);		//0x1f4硬盤磁柱低寄存器,保存起始磁柱號的低8字節
	outb_p(cyl>>8,++port);	//0x1f5硬盤磁柱高寄存器
	outb_p(0xA0|(drive<<4)|head,++port);	//0x1f6硬盤驅動器和磁頭寄存器,這里選擇主盤(高4位為1010),低4位為磁頭號
	outb(cmd,++port);		//0x1f7硬盤命令輸出寄存器,主要向硬盤發出命令
}

static int drive_busy(void)
{
	unsigned int i;

	for (i = 0; i < 100000; i++)	//循環,直到驅動器為READY_STAT或超時
		if (READY_STAT == (inb(HD_STATUS) & (BUSY_STAT | READY_STAT)))
			break;
	i = inb(HD_STATUS);			//再讀硬盤狀態
	i &= BUSY_STAT | READY_STAT | SEEK_STAT;
	if (i == READY_STAT | SEEK_STAT)	//如果處于讀狀態或尋找狀態,OK
		return(0);
	printk("HD controller times out\n\r");
	return(1);
}

static void reset_controller(void)
{
	int	i;

	outb(4,HD_CMD);		//0x3f6是硬盤適配器控制寄存器,第二位置1為重啟控制器
	for(i = 0; i < 1000; i++) nop();	//等待一會兒
	outb(0,HD_CMD);		//使驅動器處于普通狀態
	for(i = 0; i < 10000 && drive_busy(); i++) /* nothing */;
	if (drive_busy())
		printk("HD-controller still busy\n\r");
	if((i = inb(ERR_STAT)) != 1)
		printk("HD-controller reset failed: %02x\n\r",i);
}

static void reset_hd(int nr)
{
	reset_controller();
	hd_out(nr,_SECT,_SECT,_HEAD-1,_CYL,WIN_SPECIFY,&do_request);	//do_request是重新處理請求隊列
}

void unexpected_hd_interrupt(void)
{
	panic("Unexpected HD interrupt\n\r");
}

static void bad_rw_intr(void)
{
	int i = this_request->hd;

	if (this_request->errors++ >= MAX_ERRORS) {	//如果錯誤超過有效的最大錯誤數,放棄這次請求
		this_request->bh->b_uptodate = 0;
		unlock_buffer(this_request->bh);
		wake_up(&wait_for_request);
		this_request->hd = -1;
		this_request=this_request->next;
	}
	reset_hd(i);
}

static void read_intr(void)
{
	if (win_result()) {
		bad_rw_intr();
		return;
	}
	port_read(HD_DATA,this_request->bh->b_data+
		512*(this_request->nsector&1),256);	//是從b_data指定位置讀512字節
	this_request->errors = 0;
	if (--this_request->nsector)		//如果還有要傳的數據,直接返回,不從請求隊列中刪除該請求
		return;
//以下6行代碼是指數據傳送完畢,就從請求隊列中刪除該請求
	this_request->bh->b_uptodate = 1;
	this_request->bh->b_dirt = 0;
	wake_up(&wait_for_request);
	unlock_buffer(this_request->bh);
	this_request->hd = -1;
	this_request=this_request->next;
	do_request();				//處理其他請求
}

static void write_intr(void)
{
	if (win_result()) {
		bad_rw_intr();		//如果有錯誤,重啟驅動器,再繼續處理請求
		return;
	}
	if (--this_request->nsector) {
		port_write(HD_DATA,this_request->bh->b_data+512,256);	//向硬盤數據寄存器寫數據
		return;
	}
	this_request->bh->b_uptodate = 1;
	this_request->bh->b_dirt = 0;
	wake_up(&wait_for_request);
	unlock_buffer(this_request->bh);
	this_request->hd = -1;
	this_request=this_request->next;
	do_request();				//處理下一個請求
}

static void do_request(void)
{
	int i,r;

	if (sorting)
		return;
	if (!this_request) {
		do_hd=NULL;
		return;
	}
	if (this_request->cmd == WIN_WRITE) {
		hd_out(this_request->hd,this_request->nsector,this_request->
			sector,this_request->head,this_request->cyl,
			this_request->cmd,&write_intr);
		for(i=0 ; i<3000 && !(r=inb_p(HD_STATUS)&DRQ_STAT) ; i++)	//循環,直到控制器指示準備好
			/* nothing */ ;
		if (!r) {					//如果超時驅動器仍未準備好,重設該驅動器
			reset_hd(this_request->hd);
			return;
		}
		port_write(HD_DATA,this_request->bh->b_data+
			512*(this_request->nsector&1),256);		//傳送數據
	} else if (this_request->cmd == WIN_READ) {
		hd_out(this_request->hd,this_request->nsector,this_request->
			sector,this_request->head,this_request->cyl,
			this_request->cmd,&read_intr);
	} else
		panic("unknown hd-command");
}

/*
 * add-request adds a request to the linked list.
 * It sets the 'sorting'-variable when doing something
 * that interrupts shouldn't touch.
 */
static void add_request(struct hd_request * req)
{
	struct hd_request * tmp;

	if (req->nsector != 2)
		panic("nsector!=2 not implemented");
/*
 * Not to mess up the linked lists, we never touch the two first
 * entries (not this_request, as it is used by current interrups,
 * and not this_request->next, as it can be assigned to this_request).
 * This is not too high a price to pay for the ability of not
 * disabling interrupts.
 */
	sorting=1;
	if (!(tmp=this_request))
		this_request=req;
	else {
		if (!(tmp->next))
			tmp->next=req;
		else {
			tmp=tmp->next;
			for ( ; tmp->next ; tmp=tmp->next)
				if ((IN_ORDER(tmp,req) ||
				    !IN_ORDER(tmp,tmp->next)) &&
				    IN_ORDER(req,tmp->next))
					break;
			req->next=tmp->next;
			tmp->next=req;
		}
	}
	sorting=0;
/*
 * NOTE! As a result of sorting, the interrupts may have died down,
 * as they aren't redone due to locking with sorting=1. They might
 * also never have started, if this is the first request in the queue,
 * so we restart them if necessary.
 */
	if (!do_hd)
		do_request();
}

void rw_abs_hd(int rw,unsigned int nr,unsigned int sec,unsigned int head,
	unsigned int cyl,struct buffer_head * bh)					//根據硬盤參數做磁盤讀寫
{
	struct hd_request * req;

	if (rw!=READ && rw!=WRITE)
		panic("Bad hd command, must be R/W");
	lock_buffer(bh);
repeat:
	for (req=0+request ; req<NR_REQUEST+request ; req++)
		if (req->hd<0)					//hd=-1表示沒有請求
			break;
	if (req==NR_REQUEST+request) {				//不能超過最大的請求數
		sleep_on(&wait_for_request);
		goto repeat;
	}
	req->hd=nr;
	req->nsector=2;						//==1024字節
	req->sector=sec;
	req->head=head;
	req->cyl=cyl;
	req->cmd = ((rw==READ)?WIN_READ:WIN_WRITE);
	req->bh=bh;
	req->errors=0;
	req->next=NULL;
	add_request(req);
	wait_on_buffer(bh);						//進入等待
}

void hd_init(void)
{
	int i;

	for (i=0 ; i<NR_REQUEST ; i++) {				//初始化請求隊列
		request[i].hd = -1;
		request[i].next = NULL;
	}
	for (i=0 ; i<NR_HD ; i++) {					//初始化硬盤分區
		hd[i*5].start_sect = 0;
		hd[i*5].nr_sects = hd_info[i].head*
				hd_info[i].sect*hd_info[i].cyl;
	}
	set_trap_gate(0x2E,&hd_interrupt);				//登記硬盤中斷處理程序,中斷號為0x2E
	outb_p(inb_p(0x21)&0xfb,0x21);				//開放IRQ2(中斷控制器1)
	outb(inb_p(0xA1)&0xbf,0xA1);				//開放IRQ14,硬盤控制器
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本v片在线高清不卡在线观看| 色婷婷久久综合| 成人网男人的天堂| 在线观看欧美日本| 日韩亚洲欧美成人一区| 884aa四虎影成人精品一区| 久久噜噜亚洲综合| 亚洲另类在线制服丝袜| 免费成人性网站| av电影在线观看一区| 日韩视频一区二区三区| 国产精品灌醉下药二区| 免费人成网站在线观看欧美高清| 成人免费看黄yyy456| 欧美久久久久久久久| 精品国产乱码久久久久久免费| 亚洲视频在线一区观看| 久久精品免费观看| 色视频一区二区| 国产无人区一区二区三区| 亚洲午夜精品一区二区三区他趣| 国产伦精品一区二区三区免费迷| 色欧美88888久久久久久影院| 久久―日本道色综合久久| 国产精品传媒入口麻豆| 激情成人综合网| 欧美精选一区二区| 一区二区三区在线观看动漫| 精品一区二区三区在线播放视频 | 亚洲日本成人在线观看| 一片黄亚洲嫩模| 国产精品77777| 日韩亚洲欧美中文三级| 亚洲精品亚洲人成人网| 高清日韩电视剧大全免费| 欧美一级理论片| 天天色综合成人网| 欧美少妇一区二区| 亚洲欧美aⅴ...| 精品中文av资源站在线观看| 欧美日韩免费一区二区三区| 亚洲欧美怡红院| 成人免费毛片嘿嘿连载视频| 国产亚洲污的网站| 国产一区在线看| 精品乱人伦小说| 男人的天堂久久精品| 欧美日韩午夜精品| 亚洲天堂精品视频| 91小视频免费观看| 亚洲色图欧美偷拍| 色综合久久综合| 亚洲欧美日韩中文字幕一区二区三区 | 亚洲一区国产视频| 在线精品视频一区二区三四| 一区二区在线免费观看| 色综合久久久久久久久| 亚洲主播在线播放| 99精品热视频| 国产精品免费看片| 91蜜桃在线免费视频| 亚洲精品日日夜夜| 欧美日韩夫妻久久| 久久99最新地址| 欧美国产日韩一二三区| 99精品久久只有精品| 一区二区三区不卡在线观看 | 亚洲女同女同女同女同女同69| 92国产精品观看| 久久久精品一品道一区| 岛国一区二区三区| 亚洲精品精品亚洲| 欧美一区午夜精品| 狠狠色丁香久久婷婷综合丁香| 久久婷婷一区二区三区| 99久久精品免费看| 五月开心婷婷久久| 欧美videos大乳护士334| 午夜av一区二区| 日韩精品一区二区在线| 成人国产亚洲欧美成人综合网 | 精品久久国产老人久久综合| 国产美女视频91| 国产亚洲婷婷免费| 在线免费不卡视频| 久久99热狠狠色一区二区| 国产精品伦一区二区三级视频| 国产福利91精品一区二区三区| 亚洲色欲色欲www| 日本福利一区二区| 一二三区精品福利视频| 日韩精品一区二区三区老鸭窝| 成人动漫一区二区三区| 亚洲国产婷婷综合在线精品| 欧美色老头old∨ideo| 国内精品国产成人国产三级粉色| 国产精品毛片久久久久久| 7777精品伊人久久久大香线蕉超级流畅| 青草国产精品久久久久久| 日本一区二区视频在线观看| 欧美久久高跟鞋激| 99热这里都是精品| 久久精品国产999大香线蕉| 一区在线中文字幕| 欧美电影免费观看完整版 | 亚洲免费观看高清| 精品剧情v国产在线观看在线| 91免费观看国产| 国产精品一区二区三区四区| 视频一区二区中文字幕| 亚洲人妖av一区二区| 3751色影院一区二区三区| 91蝌蚪porny成人天涯| 国产资源精品在线观看| 亚洲高清在线视频| 一区二区三区在线观看欧美| 欧美经典三级视频一区二区三区| 色就色 综合激情| 成人av先锋影音| 国产精品一级黄| 捆绑调教一区二区三区| 亚洲成人精品在线观看| 亚洲精品你懂的| 国产肉丝袜一区二区| 久久色中文字幕| 欧美第一区第二区| 日韩久久久精品| 日韩女优电影在线观看| 日韩一区二区三区高清免费看看| 在线精品视频小说1| 色哟哟一区二区三区| 色综合视频一区二区三区高清| 99精品国产视频| 99国产精品久久| 97精品国产97久久久久久久久久久久 | 欧美成人官网二区| 欧美一级午夜免费电影| 久久免费的精品国产v∧| 中文字幕免费不卡| 亚洲一区精品在线| 经典一区二区三区| 99国产精品一区| 欧美夫妻性生活| 国产欧美日韩久久| 亚洲18影院在线观看| 国产麻豆精品视频| 在线观看国产日韩| 精品国产1区2区3区| 亚洲女同女同女同女同女同69| 日本视频中文字幕一区二区三区| 国产一区高清在线| 91国产福利在线| 久久午夜电影网| 午夜av电影一区| 成人福利电影精品一区二区在线观看| 欧美日韩一卡二卡三卡| 国产视频亚洲色图| 婷婷中文字幕一区三区| 丁香天五香天堂综合| 欧美电影影音先锋| 国产精品久久久久久户外露出| 日韩av中文字幕一区二区三区| eeuss国产一区二区三区| 国产精品久久久久久久久免费丝袜| 夜夜夜精品看看| 成人禁用看黄a在线| 欧美一级二级三级蜜桃| 亚洲欧美日韩精品久久久久| 久久99精品久久久| 欧美体内she精高潮| 欧美国产97人人爽人人喊| 麻豆精品在线观看| 欧美日韩精品一区二区天天拍小说| 日本一区二区三区dvd视频在线| 亚洲.国产.中文慕字在线| av成人免费在线观看| 久久九九久久九九| 久久精品国产一区二区三区免费看| 色域天天综合网| 日韩一区中文字幕| youjizz久久| 国产欧美日韩精品在线| 国产一区视频网站| 日韩情涩欧美日韩视频| 日韩影院精彩在线| 欧美日韩国产一二三| 一区二区欧美国产| 色就色 综合激情| 亚洲精品国产无套在线观| aaa亚洲精品一二三区| 国产精品久久免费看| 粉嫩av一区二区三区粉嫩 | 欧美一区二区三区四区久久 | 亚洲视频精选在线| 9i看片成人免费高清| 中文在线资源观看网站视频免费不卡| 国产一区二区三区在线观看免费| 日韩一区二区影院| 久久99精品国产麻豆婷婷| 欧美刺激午夜性久久久久久久 |