汇编实现分页和异常处理

汇编实现分页和异常处理。

.386pStackSeg segment page
db              400h dup (0)
StackSeg endsStackSeg3 segment page
db		400h dup (0)
StackSeg3 endsInfoSeg segment page
ShowPos         dd      0b8000h
szEnterProtect  db      'Now Enter Paging Protect Mode 32.',0
szEnterPl3	db 	'Now Enter Protect Privilidge 3.',0
szErrorCode	db 	'The Page Exception Error Code is:',0
szFaultPbitZero db      'Page Fault of NO EXISTING PAGE! The CR2 Value is:',0
szFaultAccess	db	'Page Fault of ACCESSING VIOLATION! the CR2 Value is:',0szNotEnoughPage db      'Not enough valid page!',0
szPageOk        db      'Page Fault Process OK  !',0
szToDos		db	'Now Returning to DOS,Press Any Key to Continue...',0
InfoSeg endsGdtSeg segment page
NullDesc        dq      0
RmDesc          dq      000092000000ffffh
PmCode16Desc    dq      000098000000ffffh
PmCode32Desc    dq      00cf9a000000ffffh
PmData32Desc    dq      00cff2000000ffffh
PmStack32Desc   dq      00409200000003ffh
PageFaultDesc   dq      00409a000000ffffh
InfoDesc        dq      0040f2000000ffffh
MainTssDesc	dq	0000890000000067h
PmStack3Desc	dq	0040f200000003ffh
PmCode32Pl3Desc dq 	00cffa000000ffffh
CallGateDesc	dq	0000ec0000180000hMainTss		dd 0dd 200hdd 28hdd 22 dup (0)dw 0dw $+2db 0ffhalign           qword
GdtReg          df      00000000005fh
StackPointer    dd      0
GdtSeg endsIdtSeg segment pagedq      14 dup (0)
PageFault       dq      00008f0000300000h                dq      241 dup (0)align           qword
IdtReg          df      0000000007ffh
align           qword
OldIdt          df      0
IdtSeg endsRmCode16Seg segment page use16
assume cs:RmCode16Seg
start:mov ax,4f02h
mov bx,3
int 10hxor ebx,ebx                     ;段寄存器不能用MOVZX直接赋值给通用寄存器并清除寄存器高16位
mov bx,IdtSeg
mov es,bx
shl ebx,4
mov dword ptr es:[IdtReg+2],ebxxor eax,eax
mov ax,GdtSeg
mov ds,ax
shl eax,4
mov dword ptr ds:[GdtReg+2],eaxxor eax,eax
mov ax,PmCode16Seg
shl eax,4
mov word ptr ds:[PmCode16Desc+2],ax
shr eax,16
mov byte ptr ds:[PmCode16Desc+4],alxor eax,eax
mov ax,PmCode32Segshl eax,4
mov word ptr ds:[PmCode32Desc+2],ax
mov word ptr ds:[PmCode32Pl3Desc+2],ax
shr eax,16
mov byte ptr ds:[PmCode32Desc+4],al
mov byte ptr ds:[PmCode32Pl3Desc+4],al
xor ebx,ebx
mov bx,offset ReturnPl0
mov word ptr ds:[CallGateDesc],bx xor eax,eax
mov ax,StackSeg
shl eax,4
mov word ptr ds:[PmStack32Desc+2],ax
shr eax,16
mov byte ptr ds:[PmStack32Desc+4],alxor eax,eax
mov ax,PageDefaultSeg
shl eax,4
mov word ptr ds:[PageFaultDesc+2],ax
shr eax,16
mov byte ptr ds:[PageFaultDesc+4],alxor eax,eax
mov ax,InfoSeg
shl eax,4
mov word ptr ds:[InfoDesc+2],ax
shr eax,16
mov byte ptr ds:[InfoDesc+4],alxor eax,eax
mov ax,StackSeg3
shl eax,4
mov word ptr ds:[PmStack3Desc+2],ax
shr eax,16
mov byte ptr ds:[PmStack3Desc+4],alxor eax,eax
xor ebx,ebx
mov ax,ds
shl eax,4
mov bx,offset MainTss
add eax,ebx
mov word ptr ds:[MainTssDesc+2],ax
shr eax,16
mov byte ptr ds:[MainTssDesc+4],almov ax,ss
shl eax,16
mov ax,sp
mov dword ptr ds:[StackPointer],eaxcli
sidt qword ptr es:[OldIdt]
lidt qword ptr es:[IdtReg]
lgdt qword ptr ds:[GdtReg]
in al,92h
or al,2
out 92h,al
mov eax,cr0
or al,1
mov cr0,eaxdb 0eahdw offset PmCode16Startdw 10hComeBackDos:
mov ax,GdtSeg
mov ds,ax
mov ax,IdtSeg
mov es,ax
lidt qword ptr es:[OldIdt]
lss sp,dword ptr ds:[StackPointer]
mov ax,4f02h
mov bx,3
int 10h
mov ah,4ch
int 21h
RmCode16Seg endsPmCode16Seg segment para use16
assume cs:PmCode16Seg
PmCode16Start:db 0eahdw offset PmCode32Startdw 18h
ReturnDos:
mov ax,8
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov eax,cr0
and al,0feh
mov cr0,eax
jmp far ptr ComeBackDos
PmCode16Seg endsPmCode32Seg segment para use32
assume cs:PmCode32Seg
PmCode32Start:
mov ax,20h
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ax,28h
mov ss,ax
mov esp,200h
mov ax,40h
ltr axcld
mov ax,20h
mov ds,ax
mov es,ax
mov edi,00100000h
mov eax,00101007h
mov ecx,1024
InitPDE:
stosd
add eax,4096
loop InitPDEmov edi,00101000h
mov eax,00000001h
mov ecx,00100000h
InitPTE:
stosd
add eax,4096
loop InitPTEmov esi,00201000h
mov edi,00201000h
mov ecx,000c0000h
ClearP:
lodsd
and al,0feh
stosd
loop ClearPmov eax,00100000h
mov cr3,eaxmov eax,cr0
or eax,80000000h
mov cr0,eax
jmp PageEnable
PageEnable:mov ax,20h
mov es,ax
mov ax,38h
mov ds,ax
mov esi,offset szEnterProtect
mov edi,ds:[ShowPos]
add dword ptr ds:[ShowPos],160
mov ah,0fh
ShowInfo:
lodsb
cmp al,0
jz EndShowInfo
stosw
jmp ShowInfo
EndShowInfo:mov ax,20h
mov ds,ax
mov es,ax
mov esi,0c0000000h
mov edi,0c0000000h
mov ecx,1000000h
Change:
lodsd
mov eax,12345678h
stosd
loop Changemov ax,48h
add ax,3
movzx eax,ax
push eax
push dword ptr 200h
;pushfd		
mov ax,50h
add ax,3
movzx eax,ax
push eax
push offset PmCodePl3
;iretd			;is both iretd and ret could be using to ring3?
retfPmCodePl3:
mov ax,3bh
mov ds,ax
mov ax,23h
mov es,ax
mov edi,0b8000h
mov ecx,1000h
mov ax,720h
rep stosw
mov esi,offset szEnterPl3
mov dword ptr ds:[ShowPos],0b8000h
mov edi,ds:[ShowPos]
add dword ptr ds:[ShowPos],160
mov ah,6
ShowPl3:
lodsb
cmp al,0
jz ShowPl3End
stosw
jmp ShowPl3
ShowPl3End:db 09ahdw 0dw 0dw 58hReturnPl0:
mov ax,20h
mov es,ax
mov ax,38h
mov ds,ax
mov esi,offset szToDos
add dword ptr ds:[ShowPos],160
mov edi,ds:[ShowPos]
mov ah,8fh
ShowEnd:
lodsb
cmp al,0
jz EndShow
stosw
jmp ShowEnd
EndShow:
in al,60h
test al,80h
jnz EndShowPageClose:
mov eax,cr0
and eax,7fffffffh
mov cr0,eax
jmp PageDisable
PageDisable:db 0eahdw offset ReturnDosdw 0dw 10h
PmCode32Seg endsPageDefaultSeg  segment page use32
assume cs:PageDefaultSegpushad
push ds
push es
push fs
push gscld
mov ax,38h
mov ds,ax
mov ax,20h
mov es,ax
mov edi,ds:[ShowPos]
mov esi,offset szErrorCode
mov ah,0fh
ShowErrorCode:
lodsb
cmp al,0
jz ShowErrorCodeEnd
stosw
jmp ShowErrorCode
ShowErrorCodeEnd:
mov eax,ss:[esp+48]
call HexToDecimalmov eax,ss:[esp+48]
test eax,1
jz PbitZero
mov edi,ds:[ShowPos]
add edi,160
mov esi,offset szFaultAccess
mov ah,0fh
ShowAccess:
lodsb
cmp al,0
jz GoBackDos
stosw
jmp ShowAccessGoBackDos:
mov eax,cr2
call HexToDecimal
mov eax,0
WaitSlot:
inc eax
cmp eax,80000000h
jnz WaitSlot
add esp,48
add esp,4db 0eahdw offset PageClose dw 0dw 18hPbitZero:
mov edi,ds:[ShowPos]
add edi,160
mov esi,offset szFaultPbitZero
mov ah,0fh
ShowZero:
lodsb
cmp al,0
jz ShowFaultEnd
stosw
jmp ShowZeroShowFaultEnd:
mov eax,cr2
call HexToDecimalmov ax,20h
mov ds,ax
mov es,ax
mov esi,00105000h	
mov ecx,00040000h
FindPage:
lodsd
test eax,1
jz NotValidPage
test eax,60h
jz FindValidpage
NotValidPage:
loop FindPagemov ax,38h
mov ds,ax
mov ax,20h
mov es,ax
mov ah,0fh
mov edi,ds:[ShowPos]
add edi,320
mov esi,offset szNotEnoughPage
ShowNotEnoughPage:
lodsb
cmp al,0
jz GoBackDos
stosw
jmp ShowNotEnoughPageFindValidPage:
sub esi,4mov edi,cr2
mov ebx,edi
and ebx,003ff000h       ;Remeber to clear low 12 bits
shr ebx,12
shr edi,22
shl edi,2               ;Remeber the pure PDE is not offset 
shl ebx,2               ;Remeber the pure PTE is not offset
mov edx,cr3
and edx,0fffff000h      ;Remember to clear lower 12 bits
add edi,edx
mov edi,[edi]           ;this usage is ok,release youself to use it
and edi,0fffff000h      ;Remember to clear lower 12 bits
add edi,ebx
mov edx,[edi]
mov [edi],eax
mov [esi],edxmov ebx,eax
mov ecx,edi
mov ax,38h
mov ds,ax
mov ax,20h
mov es,axmov edi,ds:[ShowPos]
add edi,1600
mov eax,ebx
call HexToDecimaladd edi,20
mov eax,ecx
call HexToDecimaladd edi,20
mov eax,edx
call HexToDecimaladd edi,20
mov eax,esi
call HexToDecimalmov ah,0fh
mov esi,offset szPageOk
mov edi,ds:[ShowPos]
add edi,320
ShowOk:
lodsb
cmp al,0
jz ShowOkEnd
stosw
jmp ShowOk
ShowOkEnd:PageExceptionEnd:
pop gs
pop fs
pop es
pop ds
popad
add esp,4
iretdHexToDecimal:
pushadmov edx,eax
shr eax,28
and eax,0fh
cmp al,9
jbe High0
add al,7
High0:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,24
and eax,0fh
cmp al,9
jbe High1
add al,7
High1:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,20
and eax,0fh
cmp al,9
jbe High2
add al,7
High2:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,16
and eax,0fh
cmp al,9
jbe High3
add al,7
High3:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,12
and eax,0fh
cmp al,9
jbe High4
add al,7
High4:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,8
and eax,0fh
cmp al,9
jbe High5
add al,7
High5:
add al,30h
mov ah,24h
stoswmov eax,edx
shr eax,4
and eax,0fh
cmp al,9
jbe High6
add al,7
High6:
add al,30h
mov ah,24h
stoswmov eax,edx
and eax,0fh
cmp al,9
jbe High7
add al,7
High7:
add al,30h
mov ah,24h
stoswpopad
ret
PageDefaultSeg ends
end start

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/779193.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【微服务】Sentinel(流量控制)

文章目录 1.基本介绍1.Sentinel是什么2.Sentinel主要特性3.Sentinel核心功能1.流量控制2.熔断降级3.消息削峰填谷 4.Sentinel两个组成部分 2.Sentinel控制台显示1.需求分析2.下载3.运行1.进入cmd2.输入java -jar sentinel-dashboard-1.8.0.jar3.查看默认端口8080 4.访问1.账号和…

【八股】泛型

泛型存在的意义&#xff1f; 为了使相同的代码适用于多种数据类型&#xff0c;也就是代码复用。 参数类型上下限限制 <?> 无限制 <? extends E> 声明了类型的上界&#xff0c;表示参数类型可以是他或他的子类。 <? super E> 声明了类型的下界&#xf…

C++多线程:创建多个线程与数据共享安全问题(四)

1、创建多个线程 多线程的调度由操作系统负责&#xff0c;线程执行的先后没有严格的顺序完全看操作系统和CPU的心情。 #include <iostream> #include <vector> #include <thread>void thread_print(int num) {std::cout << "线程编号 " &…

go、rust去掉了继承

为什么go、rust去掉了继承&#xff1f;只要你阅读过很多Java开源系统的源代码就明白。尤其是调试时&#xff0c;一层一层的进入基类&#xff0c;痛苦万分。一个类的功能只看它自己&#xff0c;是不知道有那些功能的&#xff0c;因为它老子、它爷爷的功能都是起作用的。在很多开…

Kali-Linux汉化教程

Kali Linux汉化教程如下&#xff1a; 打开终端。输入命令 sudo dpkg-reconfigure locales 并回车。在出现的界面中&#xff0c;使用空格键选中想要的语言选项&#xff0c;包括 en_US.UTF-8、zh_CN.GBK 和 zh_CN.UTF-8。选中 zh_CN.UTF-8 作为默认语言。按 “Tab” 键切换到 “…

视频无水印爬虫采集工具|抖音视频批量下载软件|可导出视频分享链接

全新视频无水印爬虫采集工具&#xff0c;助力您快速获取所需视频&#xff01; 视频无水印爬虫采集工具&#xff0c;为用户提供了强大的视频采集和下载功能。它可以批量提取关键词相关的视频&#xff0c;同时支持单独视频的提取和下载&#xff0c;操作简便&#xff0c;使用方便。…

大模型RAG性能提升路径

大模型相关目录 大模型&#xff0c;包括部署微调prompt/Agent应用开发、知识库增强、数据库增强、知识图谱增强、自然语言处理、多模态等大模型应用开发内容 从0起步&#xff0c;扬帆起航。 大模型应用向开发路径&#xff1a;AI代理工作流大模型应用开发实用开源项目汇总大模…

数字兆欧表操作规程你知道多少?南电电力来告诉你!

一、数字兆欧表操作规程   数字兆欧表是一种现代化电子仪表&#xff0c;用于测量电气设备的绝缘电阻。其操作规程的目的是确保测量结果的准确性&#xff0c;并保证操作人员的安全。以下是主要的操作规程&#xff1a;   1.安全操作&#xff0c;断电与放电&#xff1a;在测量…

【MySQL探索之旅】MySQL数据表的增删查改——约束

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 | 《数据结构与算法》 | 《C生万物》 《MySQL探索之旅》 |《Web世界探险家》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更…

ctf-36C3解析

一、环境 unbentu 这道题给了docker环境&#xff0c;gethub上面自己找 一个好用的linux全局切换梯子proxychains 二、开始解析 2.1初始 2.2编译 docker build . 2.3代理设置完毕 我试了一下代理还是不行&#xff0c;我们换源尝试一下 RUN sed -i s/deb.debian.org/mirro…

论文复现3:Stable Diffusion v1

abstract: 通过将图像形成过程分解为去噪自动编码器的顺序应用,扩散模型 (DM) 在图像数据及其他方面实现了最先进的合成结果。此外,他们的公式允许一种指导机制来控制图像生成过程,而无需重新训练。然而,由于这些模型通常直接在像素空间中运行,因此强大的 DM 的优化通常会…

Go打造REST Server【二】:用路由的三方库来实现

前言 在之前的文章中&#xff0c;我们用Go的标准库来实现了服务器&#xff0c;JSON渲染重构为辅助函数&#xff0c;使特定的路由处理程序相当简洁。 我们剩下的问题是路径路由逻辑&#xff0c;这是所有编写无依赖HTTP服务器的人都会遇到的问题&#xff0c;除非服务器只处理一到…

Redis桌面客户端

3.4.Redis桌面客户端 安装完成Redis&#xff0c;我们就可以操作Redis&#xff0c;实现数据的CRUD了。这需要用到Redis客户端&#xff0c;包括&#xff1a; 命令行客户端图形化桌面客户端编程客户端 3.4.1.Redis命令行客户端 Redis安装完成后就自带了命令行客户端&#xff1…

描述堆数据结构及其用途

描述堆数据结构及其用途 堆数据结构是一种特殊的树形数据结构&#xff0c;它通常被实现为完全二叉树。堆具有两个重要的特性&#xff1a;堆序性和完全二叉树的结构性。堆序性指的是堆中任意节点的值都满足一定的条件&#xff0c;通常分为最大堆和最小堆两种。在最大堆中&#x…

面向对象特征一:封装性

9.1 为什么需要封装&#xff1f; 我要用洗衣机&#xff0c;只需要按一下开关和洗涤模式就可以了。有必要了解洗衣机内部的结构吗&#xff1f;有必要 碰电动机吗&#xff1f; 我要开车&#xff0c;我不需要懂离合、油门、制动等原理和维修也可以驾驶。 客观世界里每一个事物…

乐维更改IP地址

1.1 系统IP调整 vim /etc/sysconfig/network-scripts/ifcfg-ens1921.2 Web相关服务IP变更 1.2.1 编辑/itops/nginx/html/lwjkapp/.env文件,更改ZABBIXSERVER、ZABBIXRPCURL、DB_HOST中的IP 1.2.2 进入/itops/nginx/html/lwjk_app/目录下,执行php bin/manager process-conso…

(免费分享)基于微信小程序电影院购票系统带论文

基于小程序的电影院购票管理系统【含报告】&#xff1a;前端 vue、elementui、小程序&#xff0c;后端 maven、springboot、springmvc、spring、mybatis&#xff0c;角色分为管理员、用户&#xff1b;集成小程序浏览电影&#xff0c;购票等功能于一体的系统。 目录 摘要 I Ab…

AtCoder Regular Contest 140 C - ABS Permutation (LIS ver.)

C - ABS Permutation (LIS ver.) 目录 题意&#xff1a; 思路&#xff1a; 我没做出来的原因&#xff1a; 代码&#xff1a; 题意&#xff1a; p数组是permutation&#xff0c;n个数&#xff0c;所有连续两数之差的绝对值可以构成a数组。问a数组**严格**递增的最长长度是多…

关于Devc++调试的问题以及解决STL变量无法查看

目前Devc的调试主要有以下几点&#xff1a; 1.调试不能直接查看stl变量&#xff0c;会卡死不动 2.目前单步进入只能用鼠标键按 3.若想按下一步进入函数体内&#xff0c;要在函数体内打上断点才行 4.调试到return 0 ;上一句就停了&#xff0c;不会结束程序 5.目前F2跳至断点…

elasticsearch 8.12+kibana 8.12

准备工作&#xff1a;1.下载相关的安装包放到/usr/local/ES下面 elasticsearch下载地址:Download Elasticsearch | Elastic elasticsearch-head-master下载地址:https://github.com/mobz/elasticsearch-head/archive/master.zip node下载地址:Index of /dist/ kibana地址:Downl…