当前位置: 技术问答>linux和unix
自己动手写操作系统源代码
来源: 互联网 发布时间:2017-04-22
本文导语: %include "pm.inc" org 0100h jmp LABEL_BEGIN [SECTION .gdt] LABEL_GDT: Descriptor 0,0,0 LABEL_DESC_CODE32: Descriptor 0,SegCode32Len - 1,DA_C+DA_32 LABEL_DESC_VIDEO: Descriptor 0b8000h,0ffffh,DA_DRW LABEL_DESC_RING3: Descriptor 0, ...
%include "pm.inc"
org 0100h
jmp LABEL_BEGIN
[SECTION .gdt]
LABEL_GDT: Descriptor 0,0,0
LABEL_DESC_CODE32: Descriptor 0,SegCode32Len - 1,DA_C+DA_32
LABEL_DESC_VIDEO: Descriptor 0b8000h,0ffffh,DA_DRW
LABEL_DESC_RING3: Descriptor 0, CodeRing3Len - 1, DA_C + DA_32
GdtLen equ $ - LABEL_GDT
GdtPtr dw GdtLen
dd 0
SelectorCode32 equ LABEL_DESC_CODE32 - LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO - LABEL_GDT
SelectorRing3 equ LABEL_DESC_RING3 - LABEL_GDT
[SECTION .s16]
[BITS 16]
LABEL_BEGIN:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0100h
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_CODE32
mov word [LABEL_DESC_CODE32 + 2],ax
shr eax,16
mov byte [LABEL_DESC_CODE32 + 4],al
mov byte [LABEL_DESC_CODE32 + 7],ah
;初始化ring3的代码段描述符
xor eax, eax
mov ax, cs
shl eax, 4
add eax, LABEL_CODE_RING3
mov word [LABEL_DESC_RING3 + 2], ax
shr eax, 16
mov byte [LABEL_CODE_RING3 + 4], al
mov byte [LABEL_CODE_RING3 + 7], ah
xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_GDT
mov dword [GdtPtr + 2],eax
lgdt [GdtPtr]
cli
in al,92h
or al,00000010b
out 92h,al
mov eax,cr0
or eax,01b
mov cr0,eax
jmp dword SelectorCode32:0
[SECTION .s32]
[BITS 32]
LABEL_SEG_CODE32:
mov ax,SelectorVideo
mov gs,ax
mov edi,(80 * 10 + 0) * 2
mov ah,0ch
mov al,'p'
mov [gs:edi],ax
jmp SelectorRing3:0
jmp $
SegCode32Len equ $ - LABEL_SEG_CODE32
[SECTION .ring3]
ALIGN 32
[BITS 32]
LABEL_CODE_RING3:
ret
mov ax, SelectorVideo
mov gs, ax
mov edi, (80*14 + 0)*2
mov ah, 0ch
mov al, 'G'
mov [gs:edi], ax
jmp $
CodeRing3Len equ $ - LABEL_CODE_RING3
;end of [section .ring3]
为什么想Ring3代码段跳的时候,虚拟机崩溃 求解答
|
写源码,niuX
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。