【PM复习】终结:中断和异常
来源:互联网 发布:简述矢量数据 编辑:程序博客网 时间:2024/05/16 14:45
直接上代码:
- %include "pm.inc"
- Page_Dir_Base1 equ 200000h
- Page_Tbl_Base1 equ 201000h
- Page_Dir_Base2 equ 210000h
- Page_Tbl_Base2 equ 211000h
- Proc_Paging_Demo equ 301000h
- Linear_Addr equ 401000h
- Proc_A equ 401000h
- Proc_B equ 501000h
- org 0100h
- jmp LABEL_BEGIN
- [section .gdt]
- LABEL_DESC_DUMMY:
- Descriptor 0,0,0
- LABEL_DESC_CODE32:
- Descriptor 0,GDT_Code32_Len - 1,DA_CR + DA_32
- LABEL_DESC_CODE16:
- Descriptor 0,GDT_Code16_Len - 1,DA_C
- LABEL_DESC_VIDEO:
- Descriptor 0b8000h,0ffffh,DA_DRW
- LABEL_DESC_DATA:
- Descriptor 0,Data_Len - 1,DA_DRW
- LABEL_DESC_STACK32:
- Descriptor 0,Stack_Len - 1,DA_DRW + DA_32
- LABEL_DESC_NORMAL:
- Descriptor 0,0ffffh,DA_DRW
- LABEL_DESC_FLAT_C:
- Descriptor 0,0fffffh,DA_C + DA_32 + DA_LIMIT4K
- LABEL_DESC_FLAT_RW:
- Descriptor 0,0fffffh,DA_DRW + DA_LIMIT4K
- GDT_Len equ $ - LABEL_DESC_DUMMY
- GDT_Ptr:
- dw GDT_Len - 1
- dd 0
- Selector_Code32 equ LABEL_DESC_CODE32 - LABEL_DESC_DUMMY
- Selector_Code16 equ LABEL_DESC_CODE16 - LABEL_DESC_DUMMY
- Selector_Video equ LABEL_DESC_VIDEO - LABEL_DESC_DUMMY
- Selector_Data equ LABEL_DESC_DATA - LABEL_DESC_DUMMY
- Selector_Stack32 equ LABEL_DESC_STACK32 - LABEL_DESC_DUMMY
- Selector_Normal equ LABEL_DESC_NORMAL - LABEL_DESC_DUMMY
- Selector_Flat_C equ LABEL_DESC_FLAT_C - LABEL_DESC_DUMMY
- Selector_Flat_RW equ LABEL_DESC_FLAT_RW - LABEL_DESC_DUMMY
- [section .idt]
- LABEL_IDT:
- %rep 32
- Gate Selector_Code32,General_Handler,0,DA_386IGate
- %endrep
- Gate Selector_Code32,Clock_Handler,0,DA_386IGate
- %rep 222
- Gate Selector_Code32,General_Handler,0,DA_386IGate
- %endrep
- _Real_Mode_IDT_Value:
- dw 0
- dd 0
- IDT_Len equ $ - $$
- IDT_Ptr:
- dw IDT_Len
- dd 0
- [section .stack32]
- [bits 32]
- LABEL_STACK32:
- times 512 db 0
- Stack_Len equ $ - $$
- [section .data]
- LABEL_DATA:
- _d_Disp_Pos dd 160 * 5
- d_Disp_Pos equ _d_Disp_Pos - $$
- _w_SP_Value_In_Real_Mode dw 0
- w_SP_Value_In_Real_Mode equ _w_SP_Value_In_Real_Mode - $$
- _sz_Memory_Info_Title db 'BaseAddrL BaseAddrH LengthLow LengthHigh Type',0
- sz_Memory_Info_Title equ _sz_Memory_Info_Title - $$
- _sz_Ram_Size db 'RAM SIZE:',0
- sz_Ram_Size equ _sz_Ram_Size - $$
- _sz_Return db 0ah,0
- sz_Return equ _sz_Return - $$
- _sz_Space db 20h,0
- sz_Space equ _sz_Space - $$
- _Memory_Info_Buffer times 256 db 0
- Memory_Info_Buffer equ _Memory_Info_Buffer - $$
- _d_Memory_Info_Num dd 0
- d_Memory_Info_Num equ _d_Memory_Info_Num - $$
- _ARDStruct:
- _d_Base_Addr_Low dd 0
- _d_Base_Addr_High dd 0
- _d_Length_Low dd 0
- _d_Length_High dd 0
- _d_Type dd 0
- ARDStruct equ _ARDStruct - $$
- d_Base_Addr_Low equ _d_Base_Addr_Low - $$
- d_Base_Addr_High equ _d_Base_Addr_High - $$
- d_Length_Low equ _d_Length_Low - $$
- d_Length_High equ _d_Length_High - $$
- d_Type equ _d_Type - $$
- _d_Ram_Size dd 0
- d_Ram_Size equ _d_Ram_Size - $$
- _d_Page_Table_Num dd 0
- d_Page_Table_Num equ _d_Page_Table_Num - $$
- _Real_Mode_IMR_Value db 0
- Real_Mode_IMR_Value equ _Real_Mode_IMR_Value - $$
- Data_Len equ $ - $$
- [section .s16]
- [bits 16]
- LABEL_BEGIN:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ax,ss
- mov sp,0100h
- mov [LABEL_GO_BACK_TO_REAL + 3],ax
- mov ebx,0
- mov di,_Memory_Info_Buffer
- mov ecx,20
- mov edx,0534d4150h
- .loop:
- mov eax,0e820h
- int 15h
- jc LABEL_MEMORY_CHK_FAIL
- inc dword [_d_Memory_Info_Num]
- add di,20
- cmp ebx,0
- jne .loop
- jmp LABEL_MEMORY_OK
- LABEL_MEMORY_CHK_FAIL:
- mov dword [_d_Memory_Info_Num],0
- LABEL_MEMORY_OK:
- Fill_Descriptor LABEL_DESC_CODE32,LABEL_CODE32
- Fill_Descriptor LABEL_DESC_CODE16,LABEL_BEGIN
- Fill_Descriptor LABEL_DESC_DATA,LABEL_DATA
- Fill_Descriptor LABEL_DESC_STACK32,LABEL_STACK32
- xor eax,eax
- mov ax,ds
- shl eax,4
- add eax,LABEL_DESC_DUMMY
- mov dword [GDT_Ptr + 2],eax
- xor eax,eax
- mov ax,ds
- shl eax,4
- add eax,LABEL_IDT
- mov dword [IDT_Ptr + 2],eax
- lgdt [GDT_Ptr]
- sidt [_Real_Mode_IDT_Value]
- in al,21h
- mov [_Real_Mode_IMR_Value],al
- lidt [IDT_Ptr]
- mov [w_SP_Value_In_Real_Mode],sp
- cli
- in al,92h
- or al,00000010b
- out 92h,al
- mov eax,cr0
- or al,1
- mov cr0,eax
- jmp dword Selector_Code32:0
- _LABEL_PREPARE_GO_BACK_TO_REAL:
- LABEL_PREPARE_GO_BACK_TO_REAL equ _LABEL_PREPARE_GO_BACK_TO_REAL - $$
- mov ax,Selector_Normal
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov gs,ax
- mov fs,ax
- mov eax,cr0
- and eax,7ffffffeh
- mov cr0,eax
- LABEL_GO_BACK_TO_REAL:
- jmp 0:LABEL_ALREADY_REAL
- LABEL_ALREADY_REAL:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,[w_SP_Value_In_Real_Mode]
- mov fs,ax
- mov gs,ax
- in al,92h
- and al,11111101b
- out 92h,al
- mov al,[_Real_Mode_IMR_Value]
- out 21h,al
- lidt [_Real_Mode_IDT_Value]
- sti
- mov ax,4c00h
- int 21h
- GDT_Code16_Len equ $ - $$
- [section .s32]
- [bits 32]
- LABEL_CODE32:
- mov ax,Selector_Stack32
- mov ss,ax
- mov esp,Stack_Len
- mov ax,Selector_Video
- mov gs,ax
- mov ax,Selector_Data
- mov ds,ax
- mov es,ax
- call Disp_Memory_Info
- call Paging_Demo
- call Init_8259A
- int 80h
- sti
- mov ecx,90000000h
- .1:
- dec ecx
- cmp ecx,0
- jne .1
- cli
- call Set_Real_Mode_8259A
- jmp Selector_Code16:LABEL_PREPARE_GO_BACK_TO_REAL
- Init_8259A:
- mov al,11h
- out 20h,al
- call Delay
- out 0a0h,al
- call Delay
- mov al,20h
- out 21h,al
- call Delay
- mov al,28h
- out 0a1h,al
- call Delay
- mov al,4
- out 21h,al
- call Delay
- mov al,2
- out 0a1h,al
- call Delay
- mov al,1
- out 21h,al
- call Delay
- out 0a1h,al
- call Delay
- mov al,11111110b
- out 21h,al
- call Delay
- mov al,11111111b
- out 0a1h,al
- call Delay
- ret
- Set_Real_Mode_8259A:
- mov al, 017h
- out 020h, al
- call Delay
- mov al, 008h
- out 021h, al
- call Delay
- mov al, 001h
- out 021h, al
- call Delay
- mov al, [ds:Real_Mode_IMR_Value]
- out 021h, al
- call Delay
- ret
- Delay:
- nop
- nop
- nop
- nop
- ret
- Paging_Demo:
- mov ax,Selector_Code32
- mov ds,ax
- mov ax,Selector_Flat_RW
- mov es,ax
- push Paging_Demo_Proc_Len
- push Proc_Paging_Demo
- push Paging_Demo_Proc
- call Memory_Copy
- add esp,12
- push A_Proc_Len
- push Proc_A
- push A_Proc
- call Memory_Copy
- add esp,12
- push B_Proc_Len
- push Proc_B
- push B_Proc
- call Memory_Copy
- add esp,12
- mov ax,Selector_Data
- mov ds,ax
- mov ax,Selector_Flat_RW
- mov es,ax
- call Setup_Paging
- call Selector_Flat_C:Proc_Paging_Demo
- call Page_Switch
- call Selector_Flat_C:Proc_Paging_Demo
- ret
- Disp_Memory_Info:
- push eax
- push ecx
- push edx
- push esi
- push edi
- push sz_Memory_Info_Title
- call Disp_Str
- add esp,4
- call Disp_Return
- mov ecx,[d_Memory_Info_Num]
- mov esi,Memory_Info_Buffer
- .1:
- mov edx,5
- mov edi,ARDStruct
- .2:
- push dword [esi]
- call Disp_Int
- pop eax
- stosd
- add esi,4
- call Disp_Space
- call Disp_Space
- dec edx
- cmp edx,0
- jne .2
- cmp dword [d_Type],1
- jne .3
- mov eax,[d_Base_Addr_Low]
- add eax,[d_Length_Low]
- cmp eax,[d_Ram_Size]
- jb .3
- mov [d_Ram_Size],eax
- .3:
- call Disp_Return
- loop .1
- push sz_Ram_Size
- call Disp_Str
- add esp,4
- push dword [d_Ram_Size]
- call Disp_Int
- add esp,4
- pop edi
- pop esi
- pop edx
- pop ecx
- pop eax
- ret
- Setup_Paging:
- push eax
- push ebx
- push ecx
- push edx
- push edi
- xor edx,edx
- mov eax,[d_Ram_Size]
- mov ebx,1024 * 1024 * 4
- div ebx
- test edx,edx
- jz .skip
- inc eax
- .skip:
- mov [d_Page_Table_Num],eax
- mov ecx,eax
- mov eax,Page_Tbl_Base1 + 7h
- mov edi,Page_Dir_Base1
- .1:
- stosd
- add eax,4096
- loop .1
- mov eax,[d_Page_Table_Num]
- mov ebx,1024
- mul ebx
- mov ecx,eax
- mov eax,7h
- mov edi,Page_Tbl_Base1
- .2:
- stosd
- add eax,4096
- loop .2
- mov eax,Page_Dir_Base1
- mov cr3,eax
- mov eax,cr0
- or eax,80000000h
- mov cr0,eax
- pop edi
- pop edx
- pop ecx
- pop ebx
- pop eax
- ret
- Page_Switch:
- push eax
- push ebx
- push ecx
- push edx
- push edi
- mov ecx,[d_Page_Table_Num]
- mov eax,Page_Tbl_Base2 + 7h
- mov edi,Page_Dir_Base2
- .1:
- stosd
- add eax,4096
- loop .1
- mov eax,[d_Page_Table_Num]
- mov bx,1024
- mul bx
- mov ecx,eax
- mov eax,7h
- mov edi,Page_Tbl_Base2
- .2:
- stosd
- add eax,4096
- loop .2
- mov eax,Linear_Addr
- shr eax,22
- and eax,3ffh
- mov bx,4
- mul bx
- mov ecx,eax
- mov ecx,[es:Page_Dir_Base2 + ecx]
- and ecx,0fffffc00h
- mov eax,Linear_Addr
- shr eax,12
- and eax,3ffh
- mov bx,4
- mul bx
- add ecx,eax
- mov dword [es:ecx],Proc_B + 7h
- mov edx,[es:ecx]
- mov eax,Page_Dir_Base2
- mov cr3,eax
- pop edi
- pop edx
- pop ecx
- pop ebx
- pop eax
- ret
- _Paging_Demo_Proc:
- Paging_Demo_Proc equ _Paging_Demo_Proc - $$
- mov eax,Linear_Addr
- call eax
- retf
- Paging_Demo_Proc_Len equ $ - _Paging_Demo_Proc
- _A_Proc:
- A_Proc equ _A_Proc - $$
- mov ah,0ch
- mov al,'A'
- mov [gs:160 * 16],ax
- ret
- A_Proc_Len equ $ - _A_Proc
- _B_Proc:
- B_Proc equ _B_Proc - $$
- mov ah,0ch
- mov al,'B'
- mov [gs:160 * 17],ax
- ret
- B_Proc_Len equ $ - _B_Proc
- _General_Handler:
- General_Handler equ _General_Handler - $$
- mov ah,0ch
- mov al,'I'
- mov [gs:(0 + 70) * 2],ax
- iretd
- _Clock_Handler:
- Clock_Handler equ _Clock_Handler - $$
- inc byte [gs:(0 + 70) * 2]
- mov al,20h
- out 20h,al
- iretd
- %include "lib.inc"
- GDT_Code32_Len equ $ - $$
运行结果略。
- 【PM复习】终结:中断和异常
- 中断和异常
- 陷阱,中断和异常
- 操作系统中断和异常
- 中断和异常
- 中断和异常小结
- 中断和异常
- 中断和异常
- 中断和异常
- 中断和异常
- 中断和异常(笔记
- 中断和异常
- 中断和异常
- 中断和异常
- 中断 和 异常
- 3中断和异常
- 陷阱,中断和异常
- 中断和异常
- 只为下载视频,谢谢
- 只为下载视频,谢谢
- 只为下载视频,谢谢
- 只为下载视频,谢谢
- 大学选课系统外网不能登录的问题-网络代理的实质
- 【PM复习】终结:中断和异常
- 一天一点做项目(1)
- 计算机专业的大学生课外该如何学习
- 游戏中常用的Animation类,这是一个较完美的实现
- OLAP是什么?
- BI是什么?
- 寒假在家
- 创建sql server 2005 作业,进行异地数据库操作
- PrintStream类和PrintWriter类(转)