Chinaunix首页 | 论坛 | 博客
  • 博客访问: 569265
  • 博文数量: 137
  • 博客积分: 4040
  • 博客等级: 上校
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-08 13:05
文章分类

全部博文(137)

文章存档

2011年(10)

2010年(23)

2009年(104)

分类: LINUX

2009-08-11 18:20:38

/*
 * linux/kernel/console.c
 *
 * (C) 1991 Linus Torvalds
 */


/*
 *    console.c
 *
 * This module implements the console io functions
 *    'void con_init(void)'
 *    'void con_write(struct tty_queue * queue)'
 * Hopefully this will be a rather complete VT102 implementation.
 *
 * Beeping thanks to John T Kohl.
 */


/*
 * NOTE!!! We sometimes disable and enable interrupts for a short while
 * (to put a word in video IO), but this will work even for keyboard
 * interrupts. We know interrupts aren't enabled when getting a keyboard
 * interrupt, as we use trap-gates. Hopefully all is well.
 */


/*
 * Code to check for different video-cards mostly by Galen Hunt,
 *
 */


#include <linux/sched.h>
#include <linux/tty.h>
#include <asm/io.h>
#include <asm/system.h>

/*
 * These are set up by the setup-routine at boot-time:
 */

//这是setup程序在引导启动系统时设置的参数

#define ORIG_X            (*(unsigned char *)0x90000)//初始光标列号

#define ORIG_Y            (*(unsigned char *)0x90001)//初始光标行号

#define ORIG_VIDEO_PAGE        (*(unsigned short *)0x90004)//初始页面

#define ORIG_VIDEO_MODE        ((*(unsigned short *)0x90006) & 0xff)//显示模式

#define ORIG_VIDEO_COLS     (((*(unsigned short *)0x90006) & 0xff00) >> 8)//字符列数

#define ORIG_VIDEO_LINES    (25)//显示行数

#define ORIG_VIDEO_EGA_AX    (*(unsigned short *)0x90008)//??

#define ORIG_VIDEO_EGA_BX    (*(unsigned short *)0x9000a)//显示内存大小和色彩模式

#define ORIG_VIDEO_EGA_CX    (*(unsigned short *)0x9000c)//显示卡特性参数

//显示器单色彩色显示类型模式

#define VIDEO_TYPE_MDA        0x10    /* Monochrome Text Display    单色文本*/
#define VIDEO_TYPE_CGA        0x11    /* CGA Display             CGA显示器*/
#define VIDEO_TYPE_EGAM        0x20    /* EGA/VGA in Monochrome Mode    EGA/VGA单色*/
#define VIDEO_TYPE_EGAC        0x21    /* EGA/VGA in Color Mode    EGA/VGA彩色*/

#define NPAR 16//转义字符序列中最大参数个数


extern void keyboard_interrupt(void);//键盘中断处理函数keyboard.S

//本程序 中的全局变量

static unsigned char    video_type;        /* Type of display being used    *///使用的显示类型

static unsigned long    video_num_columns;    /* Number of text columns    *///最大屏幕文本列数

static unsigned long    video_size_row;        /* Bytes per row        *///每行使用的字节数

static unsigned long    video_num_lines;    /* Number of test lines        *///最大文本行数

static unsigned char    video_page;        /* Initial video page        *///初始显示页数

static unsigned long    video_mem_start;    /* Start of video RAM        *///显示内存起始位置

static unsigned long    video_mem_end;        /* End of video RAM (sort of)    *///显示内存结束位置

static unsigned short    video_port_reg;        /* Video register select port    *///显示控制索引寄存器端口

static unsigned short    video_port_val;        /* Video register value port    *///显示控制数据寄存器端口

static unsigned short    video_erase_char;    /* Char+Attrib to erase with    *///擦除字符属性与字符(0x0720)

//以下变量用于屏幕卷屏操作

static unsigned long    origin;        /* Used for EGA/VGA fast scroll    *///滚屏起始内存地址

static unsigned long    scr_end;    /* Used for EGA/VGA fast scroll    *///滚屏结束内存地址

static unsigned long    pos;// 当前光标对应的显示内存位置

static unsigned long    x,y;// 当前光标位置

static unsigned long    top,bottom;// 滚动时顶行行号;底行行号

static unsigned long    state=0;// ANSI 转义字符序列处理状态

static unsigned long    npar,par[NPAR];// ANSI 转义字符序列参数个数和参数数组,可以将字符属性值放入这个数组中

static unsigned long    ques=0;//收到问号字符标志

static unsigned char    attr=0x07;// 字符属性(黑底白字)。


static void sysbeep(void);//// 系统蜂鸣函数。


/*
 * this is what the terminal answers to a ESC-Z or csi0c
 * query (= vt100 response).
 */

#define RESPONSE "\033[?1;2c"

/* NOTE! gotoxy thinks x==video_num_columns is ok */
static inline void gotoxy(unsigned int new_x,unsigned int new_y)//跟踪当前光标位置

{
    if (new_x > video_num_columns || new_y >= video_num_lines)
        return;
    x=new_x;
    y=new_y;
    pos=origin + y*video_size_row + (x<<1);//当前位置=起始位置+行数*第行的字节数+最后一行的列数,一列等于2个字节

}

static inline void set_origin(void)//// 设置滚屏起始显示内存地址。

{
    cli();//关中断

    outb_p(12, video_port_reg);//选择数据寄存器R12,输出滚屏起始位置高字节

    outb_p(0xff&((origin-video_mem_start)>>9), video_port_val);//此时video_port_val对应于R12

    outb_p(13, video_port_reg);//选择数据寄存器R13,输出滚屏起始位置低字节

    outb_p(0xff&((origin-video_mem_start)>>1), video_port_val);//此时video_port_val对应于R13,所以video_port_val数据寄存器同一时间只能对应一个引寄存器

    sti();//开中断

}

static void scrup(void)//将整个屏幕的内容向上移一行,屏幕滚动窗口向上滚动一行,将屏幕滚动区的内容对应于显存中的地址向下移动一行(好接着显示以下的内容),并在区域顶出现的新行上添加空格字符

{
    if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_EGAM)//为EGA/VGA 单色或彩色

    {
        if (!top && bottom == video_num_lines) {//移动起始行TOP为0,结束行BOTTOM为最大行数,则表明整个屏幕窗口向下移动一行

            origin += video_size_row;//滚屏起始内存地址下移一行,video_size_row;每行使用的字节数

            pos += video_size_row;//调整当前位置对应于显示内存地址

            scr_end += video_size_row;//滚屏结束内存地址下移一行

            if (scr_end > video_mem_end) {//滚屏结束内存地址<显示内存结束位置

                __asm__("cld\n\t"
                    "rep\n\t"
                    "movsl\n\t"
                    "movl _video_num_columns,%1\n\t"
                    "rep\n\t"
                    "stosw"
                    ::"a" (video_erase_char),
                    "c" ((video_num_lines-1)*video_num_columns>>1),
                    "D" (video_mem_start),
                    "S" (origin)
                    :"cx","di","si");
                scr_end -= origin-video_mem_start;
                pos -= origin-video_mem_start;
                origin = video_mem_start;
            } else {
                __asm__("cld\n\t"
                    "rep\n\t"
                    "stosw"
                    ::"a" (video_erase_char),
                    "c" (video_num_columns),
                    "D" (scr_end-video_size_row)
                    :"cx","di");
            }
            set_origin();// 设置新的滚屏起始显示内存地址

        } else {//否则不是整个屏幕移动,从TOP 到BOTTOM一行

            __asm__("cld\n\t"
                "rep\n\t"
                "movsl\n\t"
                "movl _video_num_columns,%%ecx\n\t"
                "rep\n\t"
                "stosw"
                ::"a" (video_erase_char),
                "c" ((bottom-top-1)*video_num_columns>>1),
                "D" (origin+video_size_row*top),
                "S" (origin+video_size_row*(top+1))
                :"cx","di","si");
        }
    }
    else        /* Not EGA/VGA *///CGA显示器或单色文本

    {
        __asm__("cld\n\t"
            "rep\n\t"
            "movsl\n\t"
            "movl _video_num_columns,%%ecx\n\t"
            "rep\n\t"
            "stosw"
            ::"a" (video_erase_char),
            "c" ((bottom-top-1)*video_num_columns>>1),
            "D" (origin+video_size_row*top),
            "S" (origin+video_size_row*(top+1))
            :"cx","di","si");
    }
}

static void scrdown(void)//将整个屏幕的内容向下移一行,屏幕滚动窗口向下滚动一行,将屏幕滚动区的内容对应于显示内存中的地址向上移动一行(好接着显示以上的内容),

{
    if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_EGAM)
    {
        __asm__("std\n\t"
            "rep\n\t"
            "movsl\n\t"
            "addl $2,%%edi\n\t"    /* %edi has been decremented by 4 */
            "movl _video_num_columns,%%ecx\n\t"
            "rep\n\t"
            "stosw"
            ::"a" (video_erase_char),
            "c" ((bottom-top-1)*video_num_columns>>1),
            "D" (origin+video_size_row*bottom-4),
            "S" (origin+video_size_row*(bottom-1)-4)
            :"ax","cx","di","si");
    }
    else        /* Not EGA/VGA */
    {
        __asm__("std\n\t"
            "rep\n\t"
            "movsl\n\t"
            "addl $2,%%edi\n\t"    /* %edi has been decremented by 4 */
            "movl _video_num_columns,%%ecx\n\t"
            "rep\n\t"
            "stosw"
            ::"a" (video_erase_char),
            "c" ((bottom-top-1)*video_num_columns>>1),
            "D" (origin+video_size_row*bottom-4),
            "S" (origin+video_size_row*(bottom-1)-4)
            :"ax","cx","di","si");
    }
}

static void lf(void)//光标位置下移一行

{
    if (y+1<bottom) {//如果光标没有最后一行上

        y++;
        pos += video_size_row;////调整当前位置对应于显示内存地址

        return;
    }
    scrup();//如果是,则将整个屏幕的内容向上移一行

}

static void ri(void)//光标位置上移一行

{
    if (y>top) {//如果光标没在最先一行上

        y--;
        pos -= video_size_row;//调整当前位置对应于显示内存地址

        return;
    }
    scrdown();//如果是,则将整个屏幕的内容向下移一行

}

static void cr(void)//光标回到第1列(0列)

{
    pos -= x<<1;//列号*2,即0 列到光标所在列对应的内存字节长度,

    x=0;
}

static void del(void)//删除光标前一个字符

{
    if (x) {//如果光标没有处在0 列,则将光标对应内存位置指针pos 后退2 字节(对应屏幕上一个字符),然后 将当前光标变量列值减1,并将光标所在位置字符擦除。

        pos -= 2;
        x--;
        *(unsigned short *)pos = video_erase_char;//删除当前位置的内容

    }
}

static void csi_J(int par)//删除屏幕上与光标位置相关的部分

{
    long count __asm__("cx");//// 设为寄存器变量

    long start __asm__("di");

    switch (par) {
        case 0:    /* erase from cursor to end of display *//* 擦除光标到屏幕底端 */
            count = (scr_end-pos)>>1;
            start = pos;
            break;
        case 1:    /* erase from start to cursor *//* 删除从屏幕开始到光标处的字符 */
            count = (pos-origin)>>1;
            start = origin;
            break;
        case 2: /* erase whole display *//* 删除整个屏幕上的字符 */
            count = video_num_columns * video_num_lines;
            start = origin;
            break;
        default:
            return;
    }
    __asm__("cld\n\t"
        "rep\n\t"
        "stosw\n\t"
        ::"c" (count),
        "D" (start),"a" (video_erase_char)
        :"cx","di");// 然后使用擦除字符填写删除字符的地方

}

static void csi_K(int par)//删除一行上与光标位置相关的部分

{
    long count __asm__("cx");// 设置寄存器变量。

    long start __asm__("di");

    switch (par) {
        case 0:    /* erase from cursor to end of line *//* 删除光标到行尾字符 */
            if (x>=video_num_columns)
                return;
            count = video_num_columns-x;
            start = pos;
            break;
        case 1:    /* erase from start of line to cursor *//* 删除从行开始到光标处 */
            start = pos - (x<<1);//x*2,是这样求的

            count = (x<video_num_columns)?x:video_num_columns;
            break;
        case 2: /* erase whole line *//* 将整行字符全删除 */
            start = pos - (x<<1);
            count = video_num_columns;
            break;
        default:
            return;
    }
    __asm__("cld\n\t"
        "rep\n\t"
        "stosw\n\t"
        ::"c" (count),
        "D" (start),"a" (video_erase_char)// 然后使用擦除字符填写删除字符的地方。

        :"cx","di");
}

void csi_m(void)//设置显示字符属性

{
    int i;

    for (i=0;i<=npar;i++)
        switch (par[i]) {
            case 0:attr=0x07;break;//黑底白字

            case 1:attr=0x0f;break;//加粗

            case 4:attr=0x0f;break;//加下划线

            case 7:attr=0x70;break;//反显

            case 27:attr=0x07;break;//正显

        }
}

static inline void set_cursor(void)//(与set_origin设置的值相同,)根据设置显示光标,根据显示内存光标对应位置pos,设置显示控制器光标的显示位置。

{
    cli();//关中断

    outb_p(14, video_port_reg);//选择数据寄存器R14,输出光标当前位置高字节

    outb_p(0xff&((pos-video_mem_start)>>9), video_port_val);
    outb_p(15, video_port_reg);//选择数据寄存器R15,输出光标当前位置低字节

    outb_p(0xff&((pos-video_mem_start)>>1), video_port_val);
    sti();//开中断

}

static void respond(struct tty_struct * tty)//发送对终端VT100 的响应序列。即,为响应主机请求终端向主机发送设备属性

{
    char * p = RESPONSE;//line 85


    cli();//关

    while (*p) {
        PUTCH(*p,tty->read_q);//将应答队列放入此设备的读缓冲区队列

        p++;
    }
    sti();//开

    copy_to_cooked(tty);//复制成规范模式字符序列,从缓冲区读队列取数据 ,处理完后放入辅助队列中,有必要还要放写队列中

}

static void insert_char(void)//在光标处插入一空格字符。将光标开始处的所有字符右移一格,将擦除字符插入在光标所 在处,我感觉这个程序写的有问题

{
    int i=x;
    unsigned short tmp, old = video_erase_char;
    unsigned short * p = (unsigned short *) pos;

    while (i++<video_num_columns) {//这个算法是不是有点问题

        tmp=*p;
        *p=old;
        old=tmp;
        p++;
    }
}

static void insert_line(void)//在光标处插入一行,先保存top和bottom,最后再恢复他们

{
    int oldtop,oldbottom;

    oldtop=top;
    oldbottom=bottom;
    top=y;
    bottom = video_num_lines;
    scrdown();//从top 到bottom 整体向下滚一行,则相应的在前面插入一行

    top=oldtop;
    bottom=oldbottom;
}

static void delete_char(void)//删除光标处的一个字符,光标右边的所有字符左移一格

{
    int i;
    unsigned short * p = (unsigned short *) pos;//pos,为当前光标在显存中的地址


    if (x>=video_num_columns)// 如果光标超出屏幕最右列,则返回。

        return;
    i = x;
    while (++i < video_num_columns) {// 从光标右一个字符开始到行末所有字符左移一格。

        *p = *(p+1);
        p++;
    }
    *p = video_erase_char;// 最后一个字符处填入擦除字符(空格字符)。

}

static void delete_line(void)//删除光标所在的行,原理同insert_line

{
    int oldtop,oldbottom;

    oldtop=top;
    oldbottom=bottom;
    top=y;
    bottom = video_num_lines;
    scrup();//从top 到bottom 整体向上滚一行,则相应的在前面删除了一行

    top=oldtop;
    bottom=oldbottom;
}

static void csi_at(unsigned int nr)//在光标处插入nr 个字符。

{
    if (nr > video_num_columns)
        nr = video_num_columns;
    else if (!nr)
        nr = 1;
    while (nr--)
        insert_char();
}

static void csi_L(unsigned int nr)//在光标位置处插入nr 行。

{
    if (nr > video_num_lines)
        nr = video_num_lines;
    else if (!nr)
        nr = 1;
    while (nr--)
        insert_line();
}

static void csi_P(unsigned int nr)//删除光标处的nr 个字符。

{
    if (nr > video_num_columns)
        nr = video_num_columns;
    else if (!nr)
        nr = 1;
    while (nr--)
        delete_char();
}

static void csi_M(unsigned int nr)//删除光标处的nr 行。

{
    if (nr > video_num_lines)
        nr = video_num_lines;
    else if (!nr)
        nr=1;
    while (nr--)
        delete_line();
}

static int saved_x=0;//保存的光标列数

static int saved_y=0;//保存的光标行数


static void save_cur(void)//// 保存当前光标位置。

{
    saved_x=x;
    saved_y=y;
}

static void restore_cur(void)//// 恢复保存的光标位置。

{
    gotoxy(saved_x, saved_y);
}

void con_write(struct tty_struct * tty)//控制台写函数,从终端对应的tty 写缓冲队列中取字符,并显示在屏幕上

{
    int nr;
    char c;

    nr = CHARS(tty->write_q);//首先取得写缓冲队列中现有字符数nr

    while (nr--) {
        GETCH(tty->write_q,c);//从写队列中取一个字符存入 c 中

        switch(state) {
            case 0://state = 0:初始状态;或者原是状态4;或者原是状态1,但字符不是'[';

                if (c>31 && c<127) {
                    if (x>=video_num_columns) {
                        x -= video_num_columns;
                        pos -= video_size_row;
                        lf();
                    }
                    __asm__("movb _attr,%%ah\n\t"
                        "movw %%ax,%1\n\t"
                        ::"a" (c),"m" (*(short *)pos)
                        :"ax");
                    pos += 2;
                    x++;
                } else if (c==27)
                    state=1;
                else if (c==10 || c==11 || c==12)
                    lf();
                else if (c==13)
                    cr();
                else if (c==ERASE_CHAR(tty))
                    del();
                else if (c==8) {
                    if (x) {
                        x--;
                        pos -= 2;
                    }
                } else if (c==9) {
                    c=8-(x&7);
                    x += c;
                    pos += c<<1;
                    if (x>video_num_columns) {
                        x -= video_num_columns;
                        pos -= video_size_row;
                        lf();
                    }
                    c=9;
                } else if (c==7)
                    sysbeep();
                break;
            case 1://is1:原是状态0,并且字符是转义字符ESC(0x1b = 033 = 27);

                state=0;
                if (c=='[')
                    state=2;
                else if (c=='E')
                    gotoxy(0,y+1);
                else if (c=='M')
                    ri();
                else if (c=='D')
                    lf();
                else if (c=='Z')
                    respond(tty);
                else if (x=='7')
                    save_cur();
                else if (x=='8')
                    restore_cur();
                break;
            case 2://is2:原是状态1,并且字符是'[';

                for(npar=0;npar<NPAR;npar++)
                    par[npar]=0;
                npar=0;
                state=3;
                if (ques=(c=='?'))
                    break;
            case 3://is3:原是状态2;或者原是状态3,并且字符是';'或数字。

                if (c==';' && npar<NPAR-1) {
                    npar++;
                    break;
                } else if (c>='0' && c<='9') {
                    par[npar]=10*par[npar]+c-'0';
                    break;
                } else state=4;
            case 4://is4:原是状态3,并且字符不是';'或数字;

                state=0;
                switch(c) {
                    case 'G': case '`':
                        if (par[0]) par[0]--;
                        gotoxy(par[0],y);
                        break;
                    case 'A':
                        if (!par[0]) par[0]++;
                        gotoxy(x,y-par[0]);
                        break;
                    case 'B': case 'e':
                        if (!par[0]) par[0]++;
                        gotoxy(x,y+par[0]);
                        break;
                    case 'C': case 'a':
                        if (!par[0]) par[0]++;
                        gotoxy(x+par[0],y);
                        break;
                    case 'D':
                        if (!par[0]) par[0]++;
                        gotoxy(x-par[0],y);
                        break;
                    case 'E':
                        if (!par[0]) par[0]++;
                        gotoxy(0,y+par[0]);
                        break;
                    case 'F':
                        if (!par[0]) par[0]++;
                        gotoxy(0,y-par[0]);
                        break;
                    case 'd':
                        if (par[0]) par[0]--;
                        gotoxy(x,par[0]);
                        break;
                    case 'H': case 'f':
                        if (par[0]) par[0]--;
                        if (par[1]) par[1]--;
                        gotoxy(par[1],par[0]);
                        break;
                    case 'J':
                        csi_J(par[0]);
                        break;
                    case 'K':
                        csi_K(par[0]);
                        break;
                    case 'L':
                        csi_L(par[0]);
                        break;
                    case 'M':
                        csi_M(par[0]);
                        break;
                    case 'P':
                        csi_P(par[0]);
                        break;
                    case '@':
                        csi_at(par[0]);
                        break;
                    case 'm':
                        csi_m();
                        break;
                    case 'r':
                        if (par[0]) par[0]--;
                        if (!par[1]) par[1] = video_num_lines;
                        if (par[0] < par[1] &&
                         par[1] <= video_num_lines) {
                            top=par[0];
                            bottom=par[1];
                        }
                        break;
                    case 's':
                        save_cur();
                        break;
                    case 'u':
                        restore_cur();
                        break;
                }
        }
    }
    set_cursor();
}

/*
 * void con_init(void);
 *
 * This routine initalizes console interrupts, and does nothing
 * else. If you want the screen to clear, call tty_write with
 * the appropriate escape-sequece.
 *
 * Reads the information preserved by setup.s to determine the current display
 * type and sets everything accordingly.
 */

void con_init(void)//被tty_init() 函数调用,tty_init()函数又被main.c程序调用

{
    register unsigned char a;
    char *display_desc = "????";
    char *display_ptr;

    video_num_columns = ORIG_VIDEO_COLS;//最大屏幕文本列数

    video_size_row = video_num_columns * 2;//每行使用的字节数

    video_num_lines = ORIG_VIDEO_LINES;//最大文本行数

    video_page = ORIG_VIDEO_PAGE;//初始显示页数

    video_erase_char = 0x0720;//擦除字符属性与字符(0x0720)

    
    if (ORIG_VIDEO_MODE == 7)            /* Is this a monochrome display? *///如果原始显示模式等于7,则表示是单色显示器。

    {
        video_mem_start = 0xb0000;//显示内存起始位置

        video_port_reg = 0x3b4;//显示控制索引寄存器端口

        video_port_val = 0x3b5;//显示控制数据寄存器端口

        if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
        {
            video_type = VIDEO_TYPE_EGAM;//使用的显示类型

            video_mem_end = 0xb8000;//显示内存结束位置

            display_desc = "EGAm";// 设置显示描述字符串。

        }
        else
        {
            video_type = VIDEO_TYPE_MDA;//使用的显示类型

            video_mem_end    = 0xb2000;//显示内存结束位置

            display_desc = "*MDA";// 设置显示描述字符串。

        }
    }
    else                                /* If not, it is color. */
    {
        video_mem_start = 0xb8000;//显示内存起始位置

        video_port_reg    = 0x3d4;//显示控制索引寄存器端口

        video_port_val    = 0x3d5;//显示控制数据寄存器端口

        if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
        {
            video_type = VIDEO_TYPE_EGAC;//使用的显示类型

            video_mem_end = 0xbc000;//显示内存结束位置

            display_desc = "EGAc";// 设置显示描述字符串。

        }
        else
        {
            video_type = VIDEO_TYPE_CGA;//使用的显示类型

            video_mem_end = 0xba000;//显示内存结束位置

            display_desc = "*CGA";// 设置显示描述字符串。

        }
    }

    /* Let the user known what kind of display driver we are using */
    
    display_ptr = ((char *)video_mem_start) + video_size_row - 8;// 在屏幕的右上角显示显示描述字符串。采用的方法是直接将字符串写到显示内存的相应位置处,如下所示

    while (*display_desc)
    {
        *display_ptr++ = *display_desc++;
        display_ptr++;
    }
    
    /* Initialize the variables used for scrolling (mostly EGA/VGA)    */
    
    origin    = video_mem_start;//滚屏起始内存地址

    scr_end    = video_mem_start + video_num_lines * video_size_row;//滚屏结束内存地址

    top    = 0;// 滚动时顶行行号

    bottom    = video_num_lines;// 滚动时底行行号


    gotoxy(ORIG_X,ORIG_Y);//跟踪当前光标位置、和对应的内存位置pos。

    set_trap_gate(0x21,&keyboard_interrupt);// 设置键盘中断陷阱门。

    outb_p(inb_p(0x21)&0xfd,0x21);// 取消8259A 中对键盘中断的屏蔽,允许IRQ1。

    a=inb_p(0x61);// 延迟读取键盘端口0x61(8255A 端口PB)。

    outb_p(a|0x80,0x61);// 设置禁止键盘工作(位7 置位),

    outb(a,0x61);// 再允许键盘工作,用以复位键盘操作。

}
/* from bsd-net-2: */

void sysbeepstop(void)//停止蜂鸣,复位8255A PB 端口的位1 和位0。

{
    /* disable counter 2 */
    outb(inb_p(0x61)&0xFC, 0x61);
}

int beepcount = 0;

static void sysbeep(void)//开通蜂鸣

{
    /* enable counter 2 */
    outb_p(inb_p(0x61)|3, 0x61);//* 开启定时器2

    /* set command for counter 2, 2 byte write */
    outb_p(0xB6, 0x43);//* 送设置定时器2 命令

    /* send 0x637 for 750 HZ */
    outb_p(0x37, 0x42);//* 设置频率为750HZ,因此送定时值0x637

    outb(0x06, 0x42);
    /* 1/8 second */
    beepcount = HZ/8;//* 蜂鸣时间为1/8 秒

}

阅读(901) | 评论(0) | 转发(0) |
0

上一篇:tty_io.c

下一篇:rs_io.s

给主人留下些什么吧!~~