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

📄 console.c

📁 全中文注释的Linux源代码
💻 C
字号:
/** 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.*//** 该模块实现控制台输入输出功能* 'void con_init(void)'* 'void con_write(struct tty_queue * queue)'* 希望这是一个非常完整的VT102 实现。** 感谢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.*//** 注意!!! 我们有时短暂地禁止和允许中断(在将一个字(word)放到视频IO),但即使* 对于键盘中断这也是可以工作的。因为我们使用陷阱门,所以我们知道在获得一个* 键盘中断时中断是不允许的。希望一切均正常。*//** Code to check for different video-cards mostly by Galen Hunt,* <g-hunt@ee.utah.edu>*//** 检测不同显示卡的代码大多数是Galen Hunt 编写的,* <g-hunt@ee.utah.edu>*/#include <linux/sched.h>	/* 调度程序头文件,定义了任务结构task_struct、初始任务0 的数据*/                                          // 还有一些有关描述符参数设置和获取的嵌入式汇编函数宏语句#include <linux/tty.h>		/* tty 头文件,定义了有关tty_io,串行通信方面的参数、常数。*/#include <asm/io.h>		/* io 头文件。定义硬件端口输入/输出宏汇编语句。*/#include <asm/system.h>   /* 系统头文件。定义了设置或修改描述符/中断门等的嵌入式汇编宏。*//** These are set up by the setup-routine at boot-time:*//** 这些是设置子程序setup 在引导启动系统时设置的参数:*/// 参见对boot/setup.s 的注释,和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 										/* 单色文本 */#define VIDEO_TYPE_CGA 0x11 										/* CGA 显示器 */#define VIDEO_TYPE_EGAM 0x20 										/* EGA/VGA 单色 */#define VIDEO_TYPE_EGAC 0x21 										/* EGA/VGA 彩色 */#define NPAR 16extern void keyboard_interrupt (void);								/* 键盘中断处理程序(keyboard.S)*/static unsigned char video_type;										/* 使用的显示类型 */static unsigned long video_num_columns;								/* 屏幕文本列数 */static unsigned long video_size_row;									/* 每行使用的字节数 */static unsigned long video_num_lines;									/* 屏幕文本行数 */static unsigned char video_page;										/* 初始显示页面 */static unsigned long video_mem_start;									/* 显示内存起始地址 */static unsigned long video_mem_end;									/* 显示内存结束(末端)地址 */static unsigned short video_port_reg;									/* 显示控制索引寄存器端口*/static unsigned short video_port_val;									/* 显示控制数据寄存器端口 */static unsigned short video_erase_char;									/* 擦除字符属性与字符(0x0720) */// 以下这些变量用于屏幕卷屏操作。static unsigned long origin;												/* 用于EGA/VGA 快速滚屏  滚屏起始内存地址*/static unsigned long scr_end;											/* 用于EGA/VGA 快速滚屏  滚屏末端内存地址*/static unsigned long pos;												/* 当前光标对应的显示内存位置*/static unsigned long x, y;												/* 当前光标位置*/static unsigned long top, bottom;										/* 滚动时顶行行号;底行行号*/// state 用于标明处理ESC 转义序列时的当前步骤。npar,par[]用于存放ESC 序列的中间处理参数。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).*//** 下面是终端回应ESC-Z 或csi0c 请求的应答(=vt100 响应)。*/// csi - 控制序列引导码(Control Sequence Introducer)。#define RESPONSE "\033[?1;2c"/* NOTE! gotoxy thinks x==video_num_columns is ok *//* 注意!gotoxy 函数认为x==video_num_columns,这是正确的 *///// 跟踪光标当前位置。// 参数:new_x - 光标所在列号;new_y - 光标所在行号。// 更新当前光标位置变量x,y,并修正pos 指向光标在显示内存中的对应位置。static inline void gotoxy (unsigned int new_x, unsigned int new_y){	// 如果输入的光标行号超出显示器列数,或者光标行号超出显示的最大行数,则退出。  	if (new_x > video_num_columns || new_y >= video_num_lines)    		return;	// 更新当前光标变量;更新光标位置对应的在显示内存中位置变量pos。  	x = new_x;  	y = new_y;  	pos = origin + y * video_size_row + (x << 1);}//// 设置滚屏起始显示内存地址。static inline void set_origin (void){	cli();		// 首先选择显示控制数据寄存器r12,然后写入卷屏起始地址高字节。向右移动9 位,表示向右移动	// 8 位,再除以2(2 字节代表屏幕上1 字符)。是相对于默认显示内存操作的

⌨️ 快捷键说明

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