保护模式编程

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1cpu!!386CPU,386,!!!1.1l1NASMMasmCOMl2VirtualPC(Windows,,)WMWarve(WIndows)Bochs(WindowsLinuxRPM)Windows,VirtualPC.l3:Nasmbinimga.bina.img!.VirtualPC1.21.2.1ComComCpuCom64KB.8086CPU20,20fffffh(1MB)16,5FCS()*16:IP()!8038632!Cpu32IA32386cpu:!!!!,,1.2.2,Bios,Bios001512Byte,aa55h()bios512byte7c00BiosCpu.1.2.3:1boot.asm(nasm);-----------------------,100hcom-------------------------------------------%define_BOOT_DEBUG_;100h%ifdef_BOOT_DEBUG_org0100h%elseorg07c00h;07c00h%endifmovax,cs;COM.movds,axmoves,axcall_HelloWorld;HelloWorldjmp$;$_HelloWorld:movax,strHello;movbp,ax;movcx,strLenmovax,1301H;ahmovbx,000ch;0(BH=0)(BL=0Ch,movdx,0001h;int10h;bios10hretstrHello:dbHelloWorldstrLenequ$-strHellotimes510-($-$$)db0;times510-($-$$)$$dw0xAA55,nasmboot.asm-oa.com.%define_DEBUG_BOOT_nasmboot.asm-oa.bina.bin.2808680386,803868086!!803868086:808680386!!!64KB,4GB3862032(324GB).,,.EIP324GB!CPU386.:2.1GDT()GDT,386GDTR..8.LDTR(12):3220,12.%macroDescriptor3;dw%2&0FFFFh;1(2)dw%1&0FFFFh;1(2)db(%116)&0FFh;1(1)dw((%28)&0F00h)|(%3&0F0FFh);1+2+2(2)db(%124)&0FFh;2(1)%endmacro;8!Descriptor8112(word)[],dw%2&0FFFFh;162345[],dw%1&0FFFFh;()WORD35,db(%116)&0FFh34.467:6:7(p)6(DPL)5(DPL)4(S)3(Type)2(Type)1(Type)0(Type)0-3[]4,S=15-6DPLRing0-3;7P:(Present);P=1.;P=07:7(G)6(D)5(0)4(AVL)3()2()1()0()0-3[]480386Intel8038650;Intel6SS(),17(Granularity)G=0G=14Kdw((%28)&0F00h)|(%3&0F0FFh):[]164,[]812-15(AVL)1+2+28[]db(%124)&0FFh8Descriptor.2.2%include386.inc;Descriptor;%define_DEBUG_BOOT_%ifdef_DEBUG_BOOT_org0100h%elseorg07c00h%endifjmpLABEL_BEGIN[SECTION.gdt];;,,LABEL_GDT:Descriptor0,0,0;LABEL_DESC_CODE32:Descriptor0,SegCode32Len-1,DA_CR|DA_32;LABEL_DESC_DATA:Descriptor0,SegDataLen-1,DA_DRW;LABEL_DESC_VIDEO:Descriptor0B8000h,0FFFFh,DA_DRW;DOS;GDTGdtLenequ$-1GdtPtrdwGdtLen-1;GDT,dd0;GDT;GDTSelectorCode32equLABEL_DESC_CODE32-LABEL_GDT;EASelectorDataequLABEL_DESC_DATA-LABEL_GDT;SelectorVideoequLABEL_DESC_VIDEO-LABEL_GDT;[SECTION.s16];16[BITS16];BITS16LABEL_BEGIN:movax,csmovds,axmoves,axmovss,ax;;moveax,strHellomovword[LABEL_DESC_DATA+2],axmovbyte[LABEL_DESC_DATA+4],alshreax,16movbyte[LABEL_DESC_DATA+7],ah;32moveax,LABEL_CODE32;movword[LABEL_DESC_CODE32+2],ax;axshreax,16movbyte[LABEL_DESC_CODE32+4],almovbyte[LABEL_DESC_CODE32+7],ah;GDTRmoveax,LABEL_GDTmovdword[GdtPtr+2],eax;GDT;GDTRlgdt[GdtPtr]CA20;A20;CROPE01386moveax,cr0oreax,1movcr0,eaxjmpdwordSelectorCode32:0;;SelectorCode32cs,Code32Selector:0;,LABEL_DESC_CODE328;SelectorCode32LABEL_DESC_CODE32Code32Selector:00LABEL_DESC_CODE32+0;cr0PE,JMP;;GDTRCS,+[SECTION.s32];32..[BITS32]LABEL_CODE32:;movax,SelectorVideomovgs,ax;()movedi,(80*10+9)*2;10,0movah,1Ch;0000:1100:movesi,0movds,SelectDatamovecx,11vi:lodsbmov[gs:edi],axincediLOOPNZvi;jmp$SegCode32Lenequ$-LABEL_CODE32[SECTION.data];strHello:dbHelloWorldSegDataLenequ$-strHello2.33861GDT2lgdt[gdtPtr]gdtPtr6.3A20IO,4CR0PE015JMP[]:[]!!!3386!!!386:386,.:3.1386.inc();---------------------------------386.inc-----------------------------------------------------DA_32EQU4000h;32DA_DPL0EQU00h;DPL=0DA_DPL1EQU20h;DPL=1(Ring0-Ring3)DA_DPL2EQU40h;DPL=2DA_DPL3EQU60h;DPL=3;----------------------------------------------------------------------------;;----------------------------------------------------------------------------DA_DREQU90h;DA_DRWEQU92h;DA_DRWAEQU93h;DA_CEQU98h;DA_CREQU9Ah;DA_CCOEQU9Ch;DA_CCOREQU9Eh;;----------------------------------------------------------------------------%macroDescriptor3;33%1dw%2&0FFFFh;1(2)dw%1&0FFFFh;1(2)db(%116)&0FFh;2(1)dw((%28)&0F00h)|(%3&0F0FFh);1+2+2(2)db(%124)&0FFh;3(1)%endmacro;8%macroCA200;A20inal,92horal,00000010bout92h,al%endmacro%macroDA200;inal,92handal,11111101bout92h,al%endmacro3.2;21GDT{1DescriptorDescriptor2GdtPtrgdtr3}2{1(3863862386}3.318086386(ProtectMode)23861MB38086RealMode,!!!386.asm(!!!);========================386.asm===============================%include386.inc;,,%define_DEBUG_B0OT_%ifdef_DEBUG_B0OT_org0100h%elseorg07c00h%endifjmpLABEL_BEGIN;===========================;GDT==============================[SECTION.gdt]LABEL_GDTDescriptor0,0,0;;8086,,00FFFFH,8086,8086CPU,!,LABEL_DESC_NORMALDescriptor0,0ffffh,DA_DRWLABEL_DESC_DATADescriptor0,SegDataLen-1,DA_DRW|DA_32;32LABEL_DESC_STACKDescriptor0,TopOfStack-1,DA_DRWA|DA_32;32stackCallLABEL_DESC_CODE32Descriptor0,SegCode32Len-1,DA_C|DA_32;Protectmode32;16808632808616168086Normal,8086,CS80868086,:80868086LABEL_DESC_CODE16Descriptor0,0ffffh,DA_C;;LABEL_DESC_TESTDescriptor0500000h,0ffffh,DA_DRW;LABEL_DESC_VIDEODescriptor0B8000h,0ffffh,DA_DRW;GdtLenequ$-LABEL_GDTGdtPtrdwGdtLen-1;dd0;-------------------------------------SelectorNormalequLABEL_DESC_NORMAL-LABEL_GDTSelectorDataequLABEL_DESC_DATA-LABEL_GDTSelectorStackequLABEL_DESC_STACK-LABEL_GDTSelectorCode32equLABEL_DESC_CODE32-LABEL_GDTSelectorCode16equLABEL_DESC_CODE16-LABEL_GDTSelectorTestequLABEL_DESC_TEST-LABEL_GDTSelectorVideoequLABEL_DESC_VIDEO-LABEL_GDT;16:();=============================-808616============================[SECTION.s16];16[BITS16];BITS16LABEL_BEGIN:;100hmovax,csmovds,axmoves,axmovss,axmovs

1 / 41
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功