为了提高自己,不知不觉踏上了linux源码分析之路了!
我选择linux源码版本是linux 0.11,为什么选择它?因为它代码量少且资料多。
针对它的分析是建立于网上资料之上(快捷、效果好)。
项目如图:
该项目是网上某某已经编译好了,并且对它进行了分析。笔者只是学习他的皮毛。
首先进入项目的是bootsect:这个程序是linuxkernel的第一个程序,包括了linux自己的bootstrap程序,但是在 说明这个程序前,必须先说明一般IBMPC开机时的动作(此处的开机是指"打开PC的电源" )。它是第一个被读入内存中并执行的程序,现在,我们可以开始来看看到底它做了什么。
第一步 :bootsect将它"自己"从被ROMBIOS载入的绝对地址0x7C00处搬到0x90000处, 然后利用一个jmpi(jumpindirectly)的指令,跳到新位置的jmpi的下一行去执行…
表示将跳到CS为0x9000,IP为offset"go"的位置(CS:IP=0x9000:offsetgo),其中I NITSEC=0x9000定义于程序开头的部份,而go这个label则恰好是下一行指令所在的位置。
第二步:接着,将其它segmentregisters包括DS,ES,SS都指向0x9000这个位置,与CS看齐 。
第叁步:接着利用BIOS中断服务int13h的第0号功能,重置磁盘控制器,使得刚才的设定发挥功能。
第四步:完成重置磁盘控制器之后,bootsect就从磁盘上读入紧邻着bootsect的setup程序, 也就是以后将会介绍的setup.S,此读入动作是利用BIOS中断服务int13h的第2号功能。
第五步:再来,就要读入真正linux的kernel了,也就是你可以在linux的根目录下看到的"v mlinuz"。
第六步:接下来做的事是检查root device,之后就仿照一开始的方法,利用indirect jump跳到刚刚已读入的setup部份。
- ;
- ;
- ;
- ;
- ;
-
- .model tiny
- .386p
- ;
- ;
- SYSSIZE = 3000h ;
- ;
-
- SETUPLEN = 4 ;
- BOOTSEG = 07c0h ;
- INITSEG = 9000h ;
- SETUPSEG = 9020h ;
- SYSSEG = 1000h ;
- ENDSEG = SYSSEG + SYSSIZE ;
-
- ;
- ;
- ROOT_DEV = 301h;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
-
- ;
-
-
-
-
-
-
-
-
-
-
-
-
- code segment ;
- assume cs:code
- start: ;
- ;
- ;
- mov ax,BYTE PTR BOOTSEG ;
- mov ds,ax
- mov ax,BYTE PTR INITSEG ;
- mov es,ax
- mov cx,256 ;
- sub si,si ;
- sub di,di ;
- rep movsw ;
- ; jmp INITSEG:[go] ;
- db 0eah ;
- dw go
- dw INITSEG
- go: mov ax,cs ;
- mov ds,ax ;
- mov es,ax
- ;
- mov ss,ax
- mov sp,0FF00h ;
-
-
-
-
-
- ;
- ;
-
- load_setup:
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- mov dx,0000h ;
- mov cx,0002h ;
- mov bx,0200h ;
- mov ax,0200h+SETUPLEN ;
- int 13h ;
- jnc ok_load_setup ;
- mov dx,0000h
- mov ax,0000h ;
- int 13h
- jmp load_setup
-
- ok_load_setup:
- ;
-
-
-
-
-
-
-
-
- mov dl,00h
- mov ax,0800h ;
- int 13h
- mov ch,00h
- ;
- mov cs:sectors,cx ;
- mov ax,INITSEG
- mov es,ax ;
-
- ;
-
- mov ah,03h ;
- xor bh,bh ;
- int 10h
-
- mov cx,27 ;
- mov bx,0007h ;
- mov bp,offset msg1 ;
- mov ax,1301h ;
- int 10h ;
-
- ;
- ;
-
- mov ax,SYSSEG
- mov es,ax ;
- call read_it ;
- call kill_motor ;
-
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
-
- ;
- mov ax,cs:root_dev
- cmp ax,0
- jne root_defined ;
- ;
- mov bx,cs:sectors ;
- ;
- ;
- mov ax,0208h ;
- cmp bx,15 ;
- je root_defined ;
- mov ax,021ch ;
- cmp bx,18
- je root_defined
- undef_root: ;
- jmp undef_root
- root_defined:
- ;
- mov cs:root_dev,ax ;
-
- ;
- ;
-
- ; jmp SETUPSEG:[0] ;
- db 0eah
- dw 0
- dw SETUPSEG
-
- ;
-
- ;
-
- ;
- ;
- ;
- ;
- ;
- sread dw 1+SETUPLEN ;
- head dw 0 ;
- track dw 0 ;
-
- read_it: ;
- mov ax,es ;
- test ax,0fffh
- die:
- jne die ;
- xor bx,bx ;
-
- rp_read:
- ;
- ;
- mov ax,es
- cmp ax,ENDSEG ;
- jb ok1_read
- ret
- ok1_read:
- ;
- ;
- ;
- ;
- ;
- mov ax,cs:sectors ;
- sub ax,sread ;
- mov dx,ax ;
- mov cl,9
- shl dx,cl ;
- add dx,bx ;
- ;
- jnc ok2_read ;
- je ok2_read
- xor ax,ax ;
- sub ax,bx ;
- shr ax,cl ;
- ok2_read:
- call read_track
- mov dx,ax ;
- add ax,sread ;
- ;
- cmp ax,cs:sectors ;
- jne ok3_read
- ;
- mov ax,1
- sub ax,head ;
- jne ok4_read ;
- inc track ;
- ok4_read:
- mov head,ax ;
- xor ax,ax ;
- ok3_read:
- mov sread,ax ;
- shl dx,cl ;
- add bx,dx ;
- jnc rp_read ;
- ;
- mov ax,es
- add ax,1000h ;
- mov es,ax
- xor bx,bx
- jmp rp_read
-
- ;
- ;
- read_track:
- push ax
- push bx
- push cx
- push dx
- mov dx,track ;
- mov cx,sread ;
- inc cx ;
- mov ch,dl ;
- mov dx,head ;
- mov dh,dl ;
- mov dl,0 ;
- and dx,0100h ;
- mov ah,2 ;
- int 13h
- jc bad_rt ;
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- ;
- bad_rt:
- mov ax,0
- mov dx,0
- int 13h
- pop dx
- pop cx
- pop bx
- pop ax
- jmp read_track
-
- ;
- ;
- ;
- ;
- kill_motor:
- push dx
- mov dx,3f2h ;
- mov al,0 ;
- out dx,al ;
- pop dx
- ret
-
- sectors dw 0 ;
-
- msg1 db 13,10 ;
- db "Loading my system ..." ;
- db 13,10,13,10 ;
-
- org 508 ;
- ;
- root_dev dw ROOT_DEV ;
- boot_flag dw 0AA55h ;
-
- code ends
- end
第二个项目是build,他是在windows下分析Linux编译好的文件pe结构信息。该项目就一个目标文件,源码如下:
- #include
- #include
- #include
-
- DWORD g_dwFileHeader[1024] = {0};
-
- typedef struct __tagFILE_HEADER{
- unsigned char ucNop[4];
- DWORD dwJmpAddr;
- }__FILL_HEADER;
-
- __FILL_HEADER g_FillHeader = {0x90,0x90,0x90,0xe9,0x00000000};
-
- char* g_lpszTargetPath = "E:\\book\\Temp\\linux011VC\\VC\\Release\\system";
-
- void main(int argc,char argv[])
- {
- IMAGE_DOS_HEADER* ImageDosHeader = NULL;
- IMAGE_NT_HEADERS* ImageNtHeader = NULL;
- IMAGE_OPTIONAL_HEADER* ImageOptionalHeader = NULL;
- HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD dwReadBytes = 0L;
- BOOL bResult = FALSE;
- DWORD dwActualBytes = 0L;
- DWORD dwOffset = 0L;
- UCHAR* lpucSource = NULL;
- UCHAR* lpucDes = NULL;
- DWORD dwLoop = 0;
-
- hFile = CreateFile(
- g_lpszTargetPath,
- GENERIC_READ | GENERIC_WRITE,
- 0L,
- NULL,
- OPEN_ALWAYS,
- 0L,
- NULL);
- if(INVALID_HANDLE_VALUE == hFile)
- {
- printf("Can not open the target file to read.");
- goto __TERMINAL;
- }
-
- dwReadBytes = 4096;
- bResult = ReadFile(hFile,g_dwFileHeader,dwReadBytes,&dwActualBytes,NULL);
- if(!bResult)
- goto __TERMINAL;
-
- CloseHandle(hFile);
- hFile = INVALID_HANDLE_VALUE;
-
-
-
-
- ImageDosHeader = (IMAGE_DOS_HEADER*)&g_dwFileHeader[0];
- dwOffset = ImageDosHeader->e_lfanew;
-
- ImageNtHeader = (IMAGE_NT_HEADERS*)((UCHAR*)&g_dwFileHeader[0] + dwOffset);
- ImageOptionalHeader = &(ImageNtHeader->OptionalHeader);
-
- g_FillHeader.dwJmpAddr = ImageOptionalHeader->AddressOfEntryPoint;
- printf(" Entry Point : %d\r\n",ImageOptionalHeader->AddressOfEntryPoint);
- g_FillHeader.dwJmpAddr -= sizeof(__FILL_HEADER);
-
- lpucSource = (UCHAR*)&g_FillHeader.ucNop[0];
- lpucDes = (UCHAR*)&g_dwFileHeader[0];
-
- for(dwLoop = 0;dwLoop < sizeof(__FILL_HEADER);dwLoop ++)
- {
- *lpucDes = *lpucSource;
- lpucDes ++;
- lpucSource ++;
- }
-
- hFile = CreateFile(
- g_lpszTargetPath,
- GENERIC_READ | GENERIC_WRITE,
- 0L,
- NULL,
- OPEN_ALWAYS,
- 0L,
- NULL);
- if(INVALID_HANDLE_VALUE == hFile)
- {
- printf("Can not open the target file to write.");
- goto __TERMINAL;
- }
-
- WriteFile(hFile,(LPVOID)&g_dwFileHeader[0],sizeof(__FILL_HEADER),&dwActualBytes,
- NULL);
-
- printf("SectionAligment : %d\r\n",ImageOptionalHeader->SectionAlignment);
- printf(" FileAligment : %d\r\n",ImageOptionalHeader->FileAlignment);
-
- __TERMINAL:
- if(INVALID_HANDLE_VALUE != hFile)
- CloseHandle(hFile);
- }
第三个项目是Documents,其实是一些文档,具体如下:
- 附:PC I/O地址分配
-
- PC只用了10位地址线(A0-A9)进行译码,其寻址的范围为0H-3FFH,共有1024个I/O地址。
- 这1024个地址中前半段(A9=0,范围为0H-1FFH)是属于主机板I/O译码,
- 后半段(A9=1,范围为200H-3FFH)则是用来扩展插槽上的I/O译码用。
- I/O端口功能表
- ———————————————————————————
- I/O地址 功能、用途
- ———————————————————————————
- 0 DMA通道0,内存地址寄存器(DMA控制器1(8237))
- 1 DMA通道0, 传输计数寄存器
- 2 DMA通道1,内存地址寄存器
- 3 DMA通道1, 传输计数寄存器
- 4 DMA通道2,内存地址寄存器
- 5 DMA通道2, 传输计数寄存器
- 6 DMA通道3,内存地址寄存器
- 7 DMA通道3, 传输计数寄存器
- 8 DMA通道0-3的状态寄存器
- 0AH DMA通道0-3的屏蔽寄存器
- 0BH DMA通道0-3的方式寄存器
- 0CH DMA清除字节指针
- 0DH DMA主清除字节
- 0EH DMA通道0-3的清屏蔽寄存器
- 0FH DMA通道0-3的写屏蔽寄存器
- 19H DMA起始寄存器
- 20H-3FH 可编程中断控制器1(8259)使用
- 40H 可编程中断计时器(8253)使用,读/写计数器0
- 41H 可编程中断计时器寄存器
- 42H 可编程中断计时器杂项寄存器
- 43H 可编程中断计时器,控制字寄存器
- 44H 可编程中断计时器,杂项寄存器(AT)
- 47H 可编程中断计时器,计数器0的控制字寄存器
- 48H-5FH 可编程中断计时器使用
- 60H-61H 键盘输入数据缓冲区
- 61H AT:8042键盘控制寄存器/XT:8255输出寄存器
- 62H 8255输入寄存器
- 63H 8255命令方式寄存器
- 64H 8042键盘输入缓冲区/8042状态
- 65H-6FH 8255/8042专用
- 70H CMOS RAM地址寄存器
- 71H CMOS RAM数据寄存器
- 80H 生产测试端口
- 81H DMA通道2,页表地址寄存器
- 82H DMA通道3,页表地址寄存器
- 83H DMA通道1,页表地址寄存器
- 87H DMA通道0,页表地址寄存器
- 89H DMA通道6,页表地址寄存器
- 8AH DMA通道7,页表地址寄存器
- 8BH DMA通道5,页表地址寄存器
- 8FH DMA通道4,页表地址寄存器
- 93H-9FH DMA控制器专用
- 0A0H NM1屏蔽寄存器/可编程中断控制器2
- 0A1H 可编程中断控制器2屏蔽
- 0C0H DMA通道0,内存地址寄存器(DMA控制器2(8237))
- 0C2H DMA通道0, 传输计数寄存器
- 0C4H DMA通道1,内存地址寄存器
- 0C6H DMA通道1, 传输计数寄存器
- 0C8H DMA通道2,内存地址寄存器
- 0CAH DMA通道2, 传输计数寄存器
- 0CCH DMA通道3,内存地址寄存器
- 0CEH DMA通道3, 传输计数寄存器
- 0D0H DMA状态寄存器
- 0D2H DMA写请求寄存器
- 0D4H DMA屏蔽寄存器
- 0D6H DMA方式寄存器
- 0D8H DMA清除字节指针
- 0DAH DMA主清
- 0DCH DMA清屏蔽寄存器
- 0DEH DMA写屏蔽寄存器
- 0DFH-0EFH 保留
- 0F0H-0FFH 协处理器使用
- 100H-16FH保留
- 170H 1号硬盘数据寄存器
- 171H 1号硬盘错误寄存器
- 172H 1号硬盘数据扇区计数
- 173H 1号硬盘扇区数
- 174H 1号硬盘柱面(低字节)
- 175H 1号硬盘柱面(高字节)
- 176H 1号硬盘驱动器/磁头寄存器
- 177H 1号硬盘状态寄存器
- 1F0H 0号硬盘数据寄存器
- 1F1H 0号硬盘错误寄存器
- 1F2H 0号硬盘数据扇区计数
- 1F3H 0号硬盘扇区数
- 1F4H 0号硬盘柱面(低字节)
- 1F5H 0号硬盘柱面(高字节)
- 1F6H 0号硬盘驱动器/磁头寄存器
- 1F7H 0号硬盘状态寄存器
- 1F9H-1FFH保留
- 200H-20FH游戏控制端口
- 210H-21FH扩展单元
- 278H 3号并行口,数据端口
- 279H 3号并行口,状态端口
- 27AH 3号并行口,控制端口
- 2B0H-2DFH保留
- 2E0H EGA/VGA使用
- 2E1H GPIP(0号适配器)
- 2E2H 数据获取(0号适配器)
- 2E3H 数据获取(1号适配器)
- 2E4H-2F7H保留
- 2F8H 2号串行口,发送/保持寄存器(RS232接口卡2)
- 2F9H 2号串行口,中断有效寄存器
- 2FAH 2号串行口,中断ID寄存器
- 2FBH 2号串行口,线控制寄存器
- 2FCH 2号串行口,调制解调控制寄存器
- 2FDH 2号串行口,线状态寄存器
- 2FEH 2号串行口,调制解调状态寄存器
- 2FFH 保留
- 300H-31FH原形卡
- 320H 硬盘适配器寄存器
- 322H 硬盘适配器控制/状态寄存器
- 324H 硬盘适配器提示/中断状态寄存器
- 325H-347H保留
- 348H-357H DCA3278
- 366H-36FH PC网络
- 372H 软盘适配器数据输出/状态寄存器
- 375H-376H 软盘适配器数据寄存器
- 377H 软盘适配器数据输入寄存器
- 378H 2号并行口,数据端口
- 379H 2号并行口,状态端口
- 37AH 2号并行口,控制端口
- 380H-38FH SDLC及BSC通讯
- 390H-393H Cluster适配器0
- 3A0H-3AFH BSC通讯
- 3B0H-3B H MDA视频寄存器
- 3BCH 1号并行口,数据端口
- 3BDH 1号并行口,状态端口
- 3BEH 1号并行口,控制端口
- 3C0H-3CFH EGA/VGA视频寄存器
- 3D0H-3D7H CGA视频寄存器
- 3F0H-3F7H 软盘控制器寄存器
- 3F8H 1号串行口,发送/保持寄存器(RS232接口卡1)
- 3F9H 1号串行口,中断有效寄存器
- 3FAH 1号串行口,中断ID寄存器
- 3FBH 1号串行口,线控制寄存器
- 3FCH 1号串行口,调制解调控制寄存器
- 3FDH 1号串行口,线状态寄存器
- 3FEH 1号串行口,调制解调状态寄存器
- 3FFH 保留
第四个项目是setup.s。
setup负责从BIOS获取系统数据,并存储在适当的内存位置。主要步骤如下:
1、利用ROM BIOS 中断读取机器系统数据,并将这些数据保存到0x90000 开始的位置(覆盖掉了bootsect 程序所在的地方),所取得的参数和保留的内存位置见下表3.1 所示。这些参数将被内核中相关程序使用,例如字符设备驱动程序集中的ttyio.c 程序等。
2、然后setup程序将system模块从0x10000-0x8ffff(512K) (当时认为内核系统模块system的长度不会超过此值:512KB)整块向下移动到内存绝对地址0x00000 处。
3、接下来加载中断描述符表寄存器(idtr)和全局描述符表寄存器(gdtr)。
4、开启A20 地址线,重新设置两个中断控制芯片8259A,将硬件中断号重新设置为0x20 - 0x2f。
5、最后设置CPU 的控制寄存器CR0(也称机器状态字),从而进入32 位保护模式运行,并跳转到位于system模块最前面部分的head.s 程序继续运行。
源码如下:
- .model tiny
- .386p
-
- ;
- ;
- ;
- ;
- ;
-
- ;
- INITSEG = 9000h ;
- SYSSEG = 1000h ;
- SETUPSEG = 9020h ;
-
-
- code segment
- start:
-
- ;
-
- mov ax,INITSEG ;
- mov ds,ax ;
- ;
- mov ah,03h ;
- xor bh,bh ;
- int 10h ;
- mov ds:[0],dx ;
- ;
- mov ah,88h ;
- int 15h ;
- mov ds:[2],ax ;
- ;
-
- ;
- ;
- ;
- ;
- mov ah,0fh
- int 10h
- mov ds:[4],bx ;
- mov ds:[6],ax ;
-
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- mov ah,12h
- mov bl,10h
- int 10h
- mov ds:[8],ax ;
- mov ds:[10],bx ;
- mov ds:[12],cx ;
-
- ;
- ;
- ;
- ;
- ;
- ;
- mov ax,0000h
- mov ds,ax
- lds si,ds:[4*41h] ;
- mov ax,INITSEG
- mov es,ax
- mov di,0080h ;
- mov cx,10h ;
- rep movsb
-
- ;
-
- mov ax,0000h
- mov ds,ax
- lds si,ds:[4*46h] ;
- mov ax,INITSEG
- mov es,ax
- mov di,0090h ;
- mov cx,10h
- rep movsb
-
-
- ;
- ;
- ;
- ;
- ;
- ;
- mov ax,1500h
- mov dl,81h
- int 13h
- jc no_disk1
- cmp ah,3 ;
- je is_disk1
- no_disk1:
- mov ax,INITSEG ;
- mov es,ax
- mov di,0090h
- mov cx,10h
- mov ax,00h
- rep stosb
-
- is_disk1:
-
- ;
-
- cli ;
-
- ;
- ;
- ;
- ;
- ;
- ;
-
- mov ax,0000h
- cld ;
- do_move:
- mov es,ax ;
- add ax,1000h
- cmp ax,9000h ;
- jz end_move
- mov ds,ax ;
- sub di,di
- sub si,si
- mov cx,8000h ;
- rep movsw
- jmp do_move
-
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
-
- end_move:
- mov ax,SETUPSEG ;
- mov ds,ax ;
-
- lidt fword ptr idt_48 ;
- ;
-
- lgdt fword ptr gdt_48 ;
-
- ;
-
- call empty_8042 ;
- ;
- mov al,0D1h ;
- out 64h,al ;
-
- call empty_8042 ;
- mov al,0DFh ;
- out 60h,al
- call empty_8042 ;
-
- ;
- ;
- ;
- ;
- ;
-
- mov al,11h ;
- ;
- out 20h,al ;
- dw 00ebh,00ebh ;
- ;
- out 0A0h,al ;
- dw 00ebh,00ebh
- mov al,20h ;
- out 21h,al ;
- dw 00ebh,00ebh
- mov al,28h ;
- out 0A1h,al ;
- dw 00ebh,00ebh
- mov al,04h ;
- out 21h,al ;
- dw 00ebh,00ebh ;
- mov al,02h ;
- out 0A1h,al ;
- ;
- dw 00ebh,00ebh
- mov al,01h ;
- out 21h,al ;
- ;
- dw 00ebh,00ebh
- out 0A1h,al ;
- dw 00ebh,00ebh
- mov al,0FFh ;
- out 21h,al ;
- dw 00ebh,00ebh
- out 0A1h,al ;
-
- ;
- ;
- ;
-
- ;
- ;
-
- mov ax,0001h ;
- lmsw ax ;
- ; jmp 8:0 ;
- db 0eah
- dw 0
- dw 8
- ;
- ;
- ;
- ;
- ;
- ;
- ;
-
-
- ;
- ;
- ;
- empty_8042:
- dw 00ebh,00ebh ;
- ;
- in al,64h ;
- test al,2 ;
- jnz empty_8042 ;
- ret
-
- ;
- ;
- ;
- ;
- gdt:
- dw 0,0,0,0 ;
- ;
- dw 07FFh ;
- dw 0000h ;
- dw 9A00h ;
- dw 00C0h ;
- ;
- dw 07FFh ;
- dw 0000h ;
- dw 9200h ;
- dw 00C0h ;
-
- idt_48:
- dw 0 ;
- dw 0,0 ;
-
- gdt_48:
- dw 800h ;
- ;
- dw 512+gdt,9h ;
- ;
-
- code ends
- end
最后一个项目是system,关键核心源码。由于其的重要性,笔者认真总结每个文件。
boot/head.s
源码如下:
- ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- .586p
- .model flat
- ;
-
-
-
-
-
-
- extrn _stack_start:far ptr,_main_rename:proc,_printk:proc
- public _idt,_gdt,_pg_dir,_tmp_floppy_area
- .code
- _pg_dir: ;
- _startup_32: ;
- mov eax,10h
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- mov ds,ax
- mov es,ax
- mov fs,ax
- mov gs,ax
- lss esp,_stack_start ;
- ;
- call setup_idt ;
- call setup_gdt ;
- mov eax,10h ;
- mov ds,ax ;
- mov es,ax ;
- mov fs,ax ;
- mov gs,ax ;
- lss esp,_stack_start
- ;
- ;
- ;
- xor eax,eax
- l1: inc eax ;
- mov ds:[0],eax ;
- cmp ds:[100000h],eax
- je l1 ;
- ;
- ;
-
-
-
-
- ;
- ;
- ;
- mov eax,cr0 ;
- and eax,80000011h ;
- ;
- or eax,2 ;
- mov cr0,eax
- call check_x87
- jmp after_page_tables
-
- ;
-
-
- check_x87:
- fninit
- fstsw ax
- cmp al,0
- je l2 ;
- mov eax,cr0 ;
- xor eax,6 ;
- mov cr0,eax
- ret
- align 2 ;
- l2: ;
- db 0DBh,0E4h ;
- ret
-
- ;
-
-
-
-
-
-
- setup_idt:
- lea edx,ignore_int ;
- mov eax,00080000h ;
- mov ax,dx ;
- ;
- ;
- mov dx,8E00h ;
- ;
- lea edi,_idt
- mov ecx,256
- rp_sidt:
- mov [edi],eax ;
- mov [edi+4],edx
- add edi,8 ;
- dec ecx
- jne rp_sidt
- lidt fword ptr idt_descr ;
- ret
-
- ;
-
-
-
-
-
- setup_gdt:
- lgdt fword ptr gdt_descr ;
- ret
-
- ;
-
-
-
- ;
- ;
- ;
- ;
- ;
- org 1000h ;
- pg0:
-
- org 2000h
- pg1:
-
- org 3000h
- pg2:
-
- org 4000h
- pg3:
-
- org 5000h ;
- ;
-
-
-
- _tmp_floppy_area:
- db 1024 dup(0) ;
-
- ;
- ;
- ;
- ;
- ;
- ;
- after_page_tables:
- push 0 ;
- push 0 ;
- push 0
- push L6 ;
- push _main_rename ;
- jmp setup_paging
- L6:
- jmp L6 ;
- ;
-
- ;
- int_msg:
- db "Unknown interrupt\n\r" ;
- align 2 ;
- ignore_int:
- push eax
- push ecx
- push edx
- push ds ;
- push es ;
- push fs
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov fs,ax
- push int_msg ;
- call _printk ;
- ;
- pop eax
- pop fs
- pop es
- pop ds
- pop edx
- pop ecx
- pop eax
- iretd ;
-
-
- ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- align 2 ;
- setup_paging: ;
- mov ecx,1024*5 ;
- xor eax,eax
- xor edi,edi ;
- ;
- pushf ;
- cld
- rep stosd
- ;
- ;
- ;
- ;
- ;
- mov eax,_pg_dir
- mov [eax],pg0+7 ;
- mov [eax+4],pg1+7 ;
- mov [eax+8],pg2+7 ;
- mov [eax+12],pg3+7 ;
- ;
- ;
- ;
- ;
- ;
- mov edi,pg3+4092 ;
- mov eax,00fff007h ;
- ;
- ;
- std ;
- L3: stosd ;
- sub eax,00001000h ;
- jge L3 ;
- popf
- ;
- xor eax,eax ;
- mov cr3,eax ;
- ;
- mov eax,cr0
- or eax,80000000h ;
- mov cr0,eax ;
- ret ;
- ;
- ;
- ;
-
- align 2 ;
- dw 0
- ;
- idt_descr:
- dw 256*8-1
- dd _idt ;
- align 2
- dw 0
- ;
- gdt_descr:
- dw 256*8-1 ;
- dd _gdt ;
-
- align 4 ;
- _idt:
- DQ 256 dup(0) ;
-
- ;
- ;
- ;
- ;
- _gdt:
- DQ 0000000000000000h ;
- DQ 00c09a0000000fffh ;
- DQ 00c0920000000fffh ;
- DQ 0000000000000000h ;
- DQ 252 dup(0) ;
- end
fs/bitmap.c
-
-
- extern _inline void clear_block(char *addr)
- {_asm{
- pushf
- mov edi,addr
- mov ecx,BLOCK_SIZE/4
- xor eax,eax
- cld
- rep stosd
- popf
- }}
-
-
-
-
-
-
-
-
- extern _inline int set_bit(unsigned long nr,char* addr)
- {
-
- _asm{
- xor eax,eax
- mov ebx,nr
- mov edx,addr
- bts [edx],ebx
- setb al
-
- }
-
- }
-
-
-
-
-
-
-
-
- extern _inline int clear_bit(unsigned long nr,char* addr)
- {
-
- _asm{
- xor eax,eax
- mov ebx,nr
- mov edx,addr
- btr [edx],ebx
- setnb al
-
- }
-
- }
-
-
-
-
-
-
-
-
-
- extern _inline int find_first_zero(char *addr)
- {
-
- _asm{
- pushf
- xor ecx,ecx
- mov esi,addr
- cld
- l1: lodsd
- not eax
- bsf edx,eax
- je l2
- add ecx,edx
- jmp l3
- l2: add ecx,32
- cmp ecx,8192
- jl l1
-
- l3: mov eax,ecx
- popf
- }
-
- }
-
-
-
- void free_block(int dev, int block)
-
-
- void free_inode(struct m_inode * inode)
-
-
- struct m_inode * new_inode(int dev)
fs/block_dev.c
block_dev.c 程序属于块设备文件数据访问操作类程序。该文件包括block_read()和block_write()两个块设备读写函数。这两个函数是供系统调用函数read()和write()调用的,其它地方没有引用。
-
-
-
-
-
-
-
- int block_write(int dev, long * pos, char * buf, int count)
-
- int block_read(int dev, unsigned long * pos, char * buf, int count)
fs/buffer.c
用于实现缓冲区高速缓存功能。通过不让中断过程改变缓冲区,而是让调用者来执行,避免了竞争条件(当然除改变数据以外)。注意!由于中断可以唤醒一个调用者,因此就需要开关中断指令(cli-sti)序列来检测等待调用返回。但需要非常地快(希望是这样)。
-
- static _inline void wait_on_buffer(struct buffer_head * bh)
-
-
- void _inline invalidate_buffers(int dev)
-
-
-
-
-
-
-
-
-
-
- void check_disk_change(int dev)
-
- static _inline void remove_from_queues(struct buffer_head * bh)
-
- static _inline void insert_into_queues(struct buffer_head * bh)
-
-
- static struct buffer_head * find_buffer(int dev, int block)
-
-
-
-
-
-
- struct buffer_head * get_hash_table(int dev, int block)
-
-
-
- struct buffer_head * getblk(int dev,int block)
-
-
- void brelse(struct buffer_head * buf)
-
-
-
-
-
- struct buffer_head * bread(int dev,int block)
-
-
- extern __inline void COPYBLK(char* from, char* to)
-
-
-
-
-
- void bread_page(unsigned long address,int dev,int b[4])
-
-
-
-
-
-
- struct buffer_head * breada(int dev,int first, ...)
-
-
-
- void buffer_init(long buffer_end)
fs/char_dev.c
-
- typedef (*crw_ptr)(int rw,unsigned minor,char * buf,int count,off_t * pos);
-
-
-
-
- static int rw_ttyx(int rw,unsigned minor,char * buf,int count,off_t * pos)
-
-
- static int rw_tty(int rw,unsigned minor,char * buf,int count, off_t * pos)
-
- static int rw_ram(int rw,char * buf, int count, off_t *pos)
-
- static int rw_mem(int rw,char * buf, int count, off_t * pos)
-
- static int rw_kmem(int rw,char * buf, int count, off_t * pos)
-
-
-
- static int rw_port(int rw,char * buf, int count, off_t * pos)
-
- static int rw_memory(int rw, unsigned minor, char * buf, int count, off_t * pos)
-
-
-
- int rw_char(int rw,int dev, char * buf, int count, off_t * pos)
fs/exec.c
-
-
-
-
-
-
-
- static unsigned long * create_tables(char * p,int argc,int envc)
-
-
-
-
-
-
- static int count(char ** argv)
-
-
-
-
-
-
- static unsigned long copy_strings(int argc,char ** argv,unsigned long *page,
- unsigned long p, int from_kmem)
-
-
-
-
- static unsigned long change_ldt(unsigned long text_size,unsigned long * page)
-
-
-
-
-
-
-
-
-
-
- int do_execve(unsigned long * eip,long tmp,char * filename,
- char ** argv, char ** envp)
fs/fcntl.c
-
-
-
- static int dupfd(unsigned int fd, unsigned int arg)
-
-
- int sys_dup2(unsigned int oldfd, unsigned int newfd)
-
-
- int sys_dup(unsigned int fildes)
-
-
- int sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg)
fs/file_dev.c
-
-
-
- int file_read(struct m_inode * inode, struct file * filp, char * buf, int count)
-
-
-
- int file_write(struct m_inode * inode, struct file * filp, char * buf, int count)
fs/inode.c
-
-
- static _inline void wait_on_inode(struct m_inode * inode)
-
-
-
- static _inline void lock_inode(struct m_inode * inode)
-
-
- static _inline void unlock_inode(struct m_inode * inode)
-
-
- void invalidate_inodes(int dev)
-
-
-
-
- static int _bmap(struct m_inode * inode,int block,int create)
-
- int bmap(struct m_inode * inode,int block)
-
- int create_block(struct m_inode * inode, int block)
-
- void iput(struct m_inode * inode)
-
-
- struct m_inode * get_empty_inode(void)
-
-
-
- struct m_inode * get_pipe_inode(void)
-
-
- struct m_inode * iget(int dev,int nr)
-
- static void read_inode(struct m_inode * inode)
-
- static void write_inode(struct m_inode * inode)
fs/ioctl.c
-
-
-
- int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
fs/ioctl.c
-
-
-
-
-
-
-
-
-
- static int permission(struct m_inode * inode,int mask)
-
-
-
-
-
-
-
-
-
- static int match(int len,const char * name,struct dir_entry * de)
-
-
-
-
-
-
-
-
-
-
-
-
-
- static struct buffer_head * find_entry(struct m_inode ** dir,
- const char * name, int namelen, struct dir_entry ** res_dir)
-
-
-
-
-
-
-
-
-
-
-
-
-
- static struct buffer_head * add_entry(struct m_inode * dir,
- const char * name, int namelen, struct dir_entry ** res_dir)
-
-
-
-
-
-
-
-
-
- static struct m_inode * get_dir(const char * pathname)
-
-
-
-
-
-
-
- static struct m_inode * dir_namei(const char * pathname,
- int * namelen, const char ** name)
-
-
-
-
-
-
-
-
-
- struct m_inode * namei(const char * pathname)
-
-
-
-
-
-
-
-
- int open_namei(const char * pathname, int flag, int mode,
- struct m_inode ** res_inode)
-
-
-
-
- int sys_mknod(const char * filename, int mode, int dev)
-
-
-
- int sys_mkdir(const char * pathname, int mode)
-
-
-
-
-
-
- static int empty_dir(struct m_inode * inode)
-
-
-
- int sys_rmdir(const char * name)
-
-
-
-
-
- int sys_unlink(const char * name)
-
-
-
-
- int sys_link(const char * oldname, const char * newname)
fs/open.c
-
- int sys_ustat(int dev, struct ustat * ubuf)
-
-
-
-
- int sys_utime(char * filename, struct utimbuf * times)
-
-
-
-
-
-
-
- int sys_access(const char * filename,int mode)
-
-
-
- int sys_chdir(const char * filename)
-
-
-
- int sys_chroot(const char * filename)
-
-
-
- int sys_chmod(const char * filename,int mode)
-
-
-
- int sys_chown(const char * filename,int uid,int gid)
-
-
-
-
-
-
-
- int sys_open(const char * filename,int flag,int mode)
-
-
-
- int sys_creat(const char * pathname, int mode)
-
-
-
- int sys_close(unsigned int fd)
fs/pipe.c
-
-
- int read_pipe(struct m_inode * inode, char * buf, int count)
-
-
- int write_pipe(struct m_inode * inode, char * buf, int count)
-
-
-
-
- int sys_pipe(unsigned long * fildes)
fs/read_write.c
-
-
-
- int sys_lseek (unsigned int fd, off_t offset, int origin)
-
-
- int sys_read (unsigned int fd, char *buf, int count)
fs/stat.c
-
-
- static void
- cp_stat (struct m_inode *inode, struct stat *statbuf)
-
-
-
- int
- sys_stat (char *filename, struct stat *statbuf)
-
-
-
- int
- sys_fstat (unsigned int fd, struct stat *statbuf)
fs/super.c
-
-
-
-
-
-
-
-
- extern _inline int set_bit(int bitnr,char* addr)
-
- static void
- lock_super (struct super_block *sb)
-
- static void
- free_super (struct super_block *sb)
-
- static void
- wait_on_super (struct super_block *sb)
-
- struct super_block *
- get_super (int dev)
-
-
- static struct super_block *
- read_super (int dev)
-
-
- int
- sys_umount (char *dev_name)
-
-
-
- int
- sys_mount (char *dev_name, char *dir_name, int rw_flag)
fs/truncate.c
-
- static void free_ind (int dev, int block)
-
- static void
- free_dind (int dev, int block)
-
- void
- truncate (struct m_inode *inode)
lib/_exit.c
-
-
-
-
- void _exit(int exit_code)
lib/close.c
-
-
-
- _syscall1(int,close,int,fd)
lib/dup.c
-
-
-
- _syscall1(int,dup,int,fd)
lib/execve.c
-
-
-
-
- _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
lib/malloc.c
-
-
-
-
-
- static _inline void init_bucket_desc()
-
-
-
- void *malloc(unsigned int len)
-
-
-
-
-
-
-
-
- void free_s(void *obj, int size)
lib/open.c
-
-
-
-
- int open(const char * filename, int flag, ...)
lib/setsid.c
lib/wait.c
-
-
-
-
-
- _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
-
-
- pid_t wait(int * wait_stat)
lib/write.c
-
-
-
-
- _syscall3(int,write,int,fd,const char *,buf,off_t,count)
mm/memory.c
- void do_exit(long code);
-
-
- static _inline void oom(void)
-
-
-
- #define copy_page(from,to) _copy_page((void *)(from),(void *)(to))
- _inline void _copy_page(void *from, void *to)
-
-
-
-
-
-
-
-
-
-
-
- unsigned long get_free_page(void)
-
-
-
-
-
- void free_page(unsigned long addr)
-
-
-
-
-
-
-
-
-
- int free_page_tables(unsigned long from,unsigned long size)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int copy_page_tables(unsigned long from,unsigned long to,long size)
-
-
-
-
-
-
- unsigned long put_page(unsigned long page,unsigned long address)
-
-
-
- void un_wp_page(unsigned long * table_entry)
-
-
-
-
-
-
-
-
-
- void do_wp_page(unsigned long error_code,unsigned long address)
-
-
- void write_verify(unsigned long address)
-
-
-
-
- void get_empty_page(unsigned long address)
-
-
-
-
-
-
-
-
-
- static int try_to_share(unsigned long address, struct task_struct * p)
-
-
-
-
-
-
-
-
-
- static int share_page(unsigned long address)
-
-
- void do_no_page(unsigned long error_code,unsigned long address)
-
-
-
-
-
- void mem_init(long start_mem, long end_mem)
mm/page.s
- ;
-
-
-
-
-
-
- .586p
- .model flat
- ;
-
-
- extrn _do_no_page:proc,_do_wp_page:proc
- public _page_fault
-
- .code
- _page_fault:
- xchg ss:[esp],eax ;
- push ecx
- push edx
- push ds
- push es
- push fs
- mov edx,10h ;
- mov ds,dx
- mov es,dx
- mov fs,dx
- mov edx,cr2 ;
- push edx ;
- push eax
- test eax,1 ;
- jne l1
- call _do_no_page ;
- jmp l2
- l1: call _do_wp_page ;
- l2: add esp,8 ;
- pop fs
- pop es
- pop ds
- pop edx
- pop ecx
- pop eax
- iretd
- end
- ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
kernel/asm.s
- ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ;
-
-
-
-
-
- ;
- ;
- extrn _do_divide_error:far, _do_int3:far, _do_nmi:far, _do_overflow:far
- extrn _do_bounds:far, _do_invalid_op:far, _do_coprocessor_segment_overrun:far
- extrn _do_reserved:far, _coprocessor_error:far ptr, _do_double_fault:far
- extrn _do_invalid_TSS:far, _do_segment_not_present:far
- extrn _do_stack_segment:far, _do_general_protection:far
-
- public _divide_error,_debug,_nmi,_int3,_overflow,_bounds,_invalid_op
- public _double_fault,_coprocessor_segment_overrun
- public _invalid_TSS,_segment_not_present,_stack_segment
- public _general_protection,_irq13,_reserved
-
- ;
- ;
- ;
- .code
- _divide_error:
- push dword ptr _do_divide_error ;
- no_error_code: ;
- xchg [esp],eax ;
- push ebx
- push ecx
- push edx
- push edi
- push esi
- push ebp
- push ds ;
- push es
- push fs
- push 0 ;
- lea edx,[esp+44] ;
- push edx
- mov edx,10h ;
- mov ds,dx
- mov es,dx
- mov fs,dx
- call eax ;
- add esp,8 ;
- pop fs
- pop es
- pop ds
- pop ebp
- pop esi
- pop edi
- pop edx
- pop ecx
- pop ebx
- pop eax ;
- iretd
-
- ;
- _debug:
- push _do_int3 ;
- jmp no_error_code
-
- ;
- _nmi:
- push _do_nmi
- jmp no_error_code
-
- ;
- _int3:
- push _do_int3
- jmp no_error_code
-
- ;
- _overflow:
- push _do_overflow
- jmp no_error_code
-
- ;
- _bounds:
- push _do_bounds
- jmp no_error_code
-
- ;
- _invalid_op:
- push _do_invalid_op
- jmp no_error_code
-
- ;
- _coprocessor_segment_overrun:
- push _do_coprocessor_segment_overrun
- jmp no_error_code
-
- ;
- _reserved:
- push _do_reserved
- jmp no_error_code
-
- ;
- ;
- _irq13:
- push eax
- xor al,al ;
- out 0F0h,al ;
- ;
- ;
- mov al,20h
- out 20h,al ;
- jmp l1 ;
- l1: jmp l2
- l2: out 0A0h,al ;
- pop eax
- jmp _coprocessor_error ;
- ;
-
- ;
- ;
- _double_fault:
- push _do_double_fault ;
- error_code:
- xchg [esp+4],eax ;
- xchg [esp],ebx ;
- push ecx
- push edx
- push edi
- push esi
- push ebp
- push ds
- push es
- push fs
- push eax ;
- lea eax,[esp+44] ;
- push eax
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov fs,ax
- call ebx ;
- add esp,8 ;
- pop fs
- pop es
- pop ds
- pop ebp
- pop esi
- pop edi
- pop edx
- pop ecx
- pop ebx
- pop eax
- iretd
-
- ;
- _invalid_TSS:
- push _do_invalid_TSS
- jmp error_code
-
- ;
- _segment_not_present:
- push _do_segment_not_present
- jmp error_code
-
- ;
- _stack_segment:
- push _do_stack_segment
- jmp error_code
-
- ;
- _general_protection:
- push _do_general_protection
- jmp error_code
-
- ;
- ;
- ;
- ;
- ;
- end
kernel/exit.c
-
- void release (struct task_struct *p)
-
- static _inline int
- send_sig (long sig, struct task_struct *p, int priv)
-
- static void kill_session (void)
-
-
-
-
-
-
-
-
-
- int sys_kill (int pid, int sig)
-
-
- static void tell_father (int pid)
-
- int sys_exit (int error_code)
-
-
-
-
-
-
-
-
-
-
- int sys_waitpid (pid_t pid, unsigned long *stat_addr, int options)
kernel/fork.c
-
-
-
- void verify_area (void *addr, int size)
-
-
- int copy_mem (int nr, struct task_struct *p)
-
-
-
-
-
- int copy_process (int nr, long ebp, long edi, long esi, long gs, long none,
- long ebx, long ecx, long edx,
- long fs, long es, long ds,
- long eip, long cs, long eflags, long esp, long ss)
-
- int find_empty_process (void)
kernel/mktime.c
-
- long
- kernel_mktime (struct tm *tm)
kernel/panic.c
-
-
- void panic (const char *s)
kernel/printk.c
-
- int printk (const char *fmt, ...)
kernel/sched.c
-
- void show_task (int nr, struct task_struct *p)
-
-
-
-
-
-
- void math_state_restore ()
-
-
-
- void sleep_on (struct task_struct **p)
-
- void interruptible_sleep_on (struct task_struct **p)
-
- void wake_up (struct task_struct **p)
-
-
- int ticks_to_floppy_on (unsigned int nr)
-
- void floppy_on (unsigned int nr)
-
- void floppy_off (unsigned int nr)
-
-
-
- void do_floppy_timer (void)
-
-
- void add_timer (long jiffies, void (*fn) ())
-
-
- int sys_alarm (long seconds)
-
-
- int sys_nice (long increment)
kernel/signal.c
- volatile void do_exit (int error_code);
-
-
- int sys_sgetmask ()
-
- int sys_ssetmask (int newmask)
-
- static _inline void save_old (char *from, char *to)
-
- static _inline void get_new (char *from, char *to)
-
-
-
-
- int sys_signal (int signum, long handler, long restorer)
-
-
-
- int sys_sigaction (int signum, const struct sigaction *action,
- struct sigaction *oldaction)
-
-
-
- void do_signal (long signr, long eax, long ebx, long ecx, long edx,
- long fs, long es, long ds,
- long eip, long cs, long eflags, unsigned long *esp, long ss)
kernel/sys.c
-
-
-
- int sys_setregid (int rgid, int egid)
-
-
- int sys_time (long *tloc)
-
-
-
-
-
-
- int sys_setreuid (int ruid, int euid)
-
-
- int sys_stime (long *tptr)
-
-
-
-
- int sys_brk (unsigned long end_data_seg)
-
-
-
-
-
-
-
-
- int sys_setpgid (int pid, int pgid)
-
-
- int sys_uname (struct utsname *name)
kernel/system_call.s
- ;
-
-
-
-
-
-
-
-
- SIG_CHLD = 17 ;
-
- R_EAX = 00h ;
- R_EBX = 04h
- R_ECX = 08h
- R_EDX = 0Ch
- R_FS = 10h
- R_ES = 14h
- R_DS = 18h
- R_EIP = 1Ch
- R_CS = 20h
- EFLAGS = 24h
- OLDR_ESP = 28h ;
- OLR_DSS = 2Ch
-
- ;
- state = 0 ;
- counter = 4 ;
- priority = 8 ;
- signal = 12 ;
- sigaction = 16 ;
- ;
- blocked = (33*16) ;
-
- ;
- ;
- sa_handler = 0 ;
- sa_mask = 4 ;
- sa_flags = 8 ;
- sa_restorer = 12 ;
-
- nr_system_calls = 72 ;
-
- ;
-
-
-
- ;
-
-
- ;
- extrn _schedule:proc,_do_signal:proc,_math_error:proc
- extrn _math_state_restore:proc,_math_emulate:proc,_jiffies:proc
- extrn _do_timer:proc,_do_execve:proc
- extrn _find_empty_process:proc,_copy_process:proc
- extrn _do_floppy:proc,_unexpected_floppy_interrupt:proc
- extrn _do_hd:proc,_unexpected_hd_interrupt:proc
-
- extrn _current:dword,_task:dword,_sys_call_table:dword
-
- public _system_call,_sys_fork,_timer_interrupt,_sys_execve
- public _hd_interrupt,_floppy_interrupt,_parallel_interrupt
- public _device_not_available, _coprocessor_error
-
- .code
-
- ;
- align 4 ;
- bad_sys_call:
- mov eax,-1 ;
- iretd
- ;
- align 4
- reschedule:
- push ret_from_sys_call ;
- jmp _schedule
- ;
- align 4
- _system_call:
- cmp eax,nr_system_calls-1 ;
- ja bad_sys_call
- push ds ;
- push es
- push fs
- push edx ;
- push ecx ;
- push ebx ;
- mov edx,10h ;
- mov ds,dx ;
- mov es,dx
- mov edx,17h ;
- mov fs,dx ;
- ;
- ;
- ;
- call [_sys_call_table+eax*4]
- push eax ;
- mov eax,_current ;
- ;
- ;
- cmp dword ptr [state+eax],0 ;
- jne reschedule
- cmp dword ptr [counter+eax],0 ;
- je reschedule
- ;
- ret_from_sys_call:
- ;
- ;
- mov eax,_current ;
- cmp eax,_task
- je l1 ;
- ;
- ;
- ;
- cmp word ptr [R_CS+esp],0fh ;
- jne l1
- ;
- cmp word ptr [OLR_DSS+esp],17h ;
- jne l1
- ;
- ;
- ;
- ;
- mov ebx,[signal+eax] ;
- mov ecx,[blocked+eax] ;
- not ecx ;
- and ecx,ebx ;
- bsf ecx,ecx ;
- ;
- je l1 ;
- btr ebx,ecx ;
- mov dword ptr [signal+eax],ebx ;
- inc ecx ;
- push ecx ;
- call _do_signal ;
- pop eax ;
- l1: pop eax
- pop ebx
- pop ecx
- pop edx
- pop fs
- pop es
- pop ds
- iretd
-
- ;
- ;
- align 4
- _coprocessor_error:
- push ds
- push es
- push fs
- push edx
- push ecx
- push ebx
- push eax
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov eax,17h ;
- mov fs,ax
- push ret_from_sys_call ;
- jmp _math_error ;
-
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- align 4
- _device_not_available:
- push ds
- push es
- push fs
- push edx
- push ecx
- push ebx
- push eax
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov eax,17h ;
- mov fs,ax
- push ret_from_sys_call ;
- clts ;
- mov eax,cr0
- test eax,4h ;
- ;
- je goto_math_state_restore;
- push ebp
- push esi
- push edi
- call _math_emulate ;
- pop edi
- pop esi
- pop ebp
- ret ;
- goto_math_state_restore:
- jmp _math_state_restore
-
- ;
- ;
- ;
- ;
- align 4
- _timer_interrupt:
- push ds ;
- push es ;
- push fs
- push edx ;
- push ecx ;
- push ebx ;
- push eax
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov eax,17h ;
- mov fs,ax
- inc dword ptr _jiffies
- ;
- mov al,20h ;
- out 20h,al ;
- ;
- mov eax,dword ptr [R_CS+esp]
- and eax,3 ;
- push eax
- ;
- call _do_timer ;
- add esp,4 ;
- jmp ret_from_sys_call
-
- ;
- ;
- align 4
- _sys_execve:
- lea eax,[R_EIP+esp]
- push eax
- call _do_execve
- add esp,4 ;
- ret
-
- ;
- ;
- ;
- align 4
- _sys_fork:
- call _find_empty_process ;
- test eax,eax
- js l2
- push gs
- push esi
- push edi
- push ebp
- push eax
- call _copy_process ;
- add esp,20 ;
- l2: ret
-
- ;
- ;
- ;
- ;
- ;
- ;
- _hd_interrupt:
- push eax
- push ecx
- push edx
- push ds
- push es
- push fs
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov eax,17h ;
- mov fs,ax
- ;
- mov al,20h
- out 0A0h,al ;
- jmp l3 ;
- l3: jmp l4 ;
- l4: xor edx,edx
- xchg edx,dword ptr _do_hd ;
- ;
- ;
- test edx,edx ;
- jne l5 ;
- mov edx,dword ptr _unexpected_hd_interrupt ;
- l5: out 20h,al ;
- call edx ;
- pop fs ;
- pop es
- pop ds
- pop edx
- pop ecx
- pop eax
- iretd
-
- ;
- ;
- ;
- ;
- ;
- ;
- _floppy_interrupt:
- push eax
- push ecx
- push edx
- push ds
- push es
- push fs
- mov eax,10h ;
- mov ds,ax
- mov es,ax
- mov eax,17h ;
- mov fs,ax
- mov al,20h ;
- out 20h,al ;
- xor eax,eax
- xchg eax,dword ptr _do_floppy ;
- ;
- test eax,eax ;
- jne l6 ;
- mov eax,dword ptr _unexpected_floppy_interrupt
- l6: call eax ;
- pop fs ;
- pop es
- pop ds
- pop edx
- pop ecx
- pop eax
- iretd
-
- ;
- ;
- _parallel_interrupt:
- push eax
- mov al,20h
- out 20h,al
- pop eax
- iretd
- end
kernel/traps.c
-
-
-
-
-
-
-
- _inline char get_seg_byte(unsigned short segm, void *addr)
-
- _inline long
- get_seg_long(unsigned short segm,long *addr)
-
- _inline unsigned short _fs()
-
-
-
- static void die(char * str,long esp_ptr,long nr)
-
- void do_double_fault(long esp, long error_code)
kernel/vsprintf.c
-
- static int skip_atoi (const char **s)
-
-
- #define do_div(n,base) _do_div(&(n),base)
- extern _inline int _do_div(int *n,int base)
-
-
-
- static char *
- number (char *str, int num, int base, int size, int precision, int type)
-
-
-
-
- int
- vsprintf (char *buf, const char *fmt, va_list args)
kernel/blk_drv/floppy.c
-
-
-
- void _inline immoutb_p(unsigned char val,unsigned short port)
-
-
- void
- floppy_deselect (unsigned int nr)
-
-
-
-
-
-
- int
- floppy_change (unsigned int nr)
-
-
-
-
-
- void _inline copy_buffer(void* from, void* to)
-
- static void
- setup_DMA (void)
-
- static void
- output_byte (char byte)
-
- static void
- bad_flp_intr (void)
-
-
-
-
-
- static void
- rw_interrupt (void)
-
- _inline void
- setup_rw_floppy (void)
-
-
-
-
-
-
-
-
- static void
- seek_interrupt (void)
-
-
-
-
-
- static void
- transfer (void)
-
-
-
-
-
-
- static void
- recal_interrupt (void)
-
-
-
- void
- unexpected_floppy_interrupt (void)
-
-
- static void
- recalibrate_floppy (void)
-
-
-
- static void
- reset_interrupt (void)
-
-
- static void
- reset_floppy (void)
-
-
-
- static void
- floppy_on_interrupt (void)
-
- void
- do_fd_request (void)
kernel/blk_drv/hd.c
-
-
-
- _inline void port_read(unsigned short port, void* buf,unsigned long nr)
-
-
-
- _inline void port_write(unsigned short port, void* buf,unsigned long nr)
-
-
-
-
-
- int sys_setup (unsigned char *BIOS)
-
-
- static int controller_ready (void)
-
-
-
- static int win_result (void)
-
-
-
-
-
- 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))
-
-
- static int drive_busy (void)
-
- static void reset_controller (void)
-
-
- static void reset_hd (int nr)
-
-
-
- void unexpected_hd_interrupt (void)
-
- static void bad_rw_intr (void)
-
- static void read_intr (void)
-
-
-
- static void write_intr (void)
-
-
- static void recal_intr (void)
-
- void do_hd_request (void)
kernel/blk_drv/ll_rw_blk.c
-
-
- static _inline void
- lock_buffer (struct buffer_head *bh)
-
- static _inline void
- unlock_buffer (struct buffer_head *bh)
-
-
-
-
-
- static void
- add_request (struct blk_dev_struct *dev, struct request *req)
-
- static void
- make_request (int major, int rw, struct buffer_head *bh)
-
-
-
- void ll_rw_block (int rw, struct buffer_head *bh)
kernel/blk_drv/ramdisk.c
-
- void
- do_rd_request (void)
-
-
- long
- rd_init (long mem_start, int length)
kernel/blk_drv/math_emulate.c
-
-
- void
- math_emulate (long edi, long esi, long ebp, long sys_call_ret,
- long eax, long ebx, long ecx, long edx,
- unsigned short fs, unsigned short es, unsigned short ds,
- unsigned long eip, unsigned short cs, unsigned long eflags,
- unsigned short ss, unsigned long esp)
学习的目标是成熟!~~
转载自:http://blog.csdn.net/banketree/article/details/8363962