📄 init_r.asm
字号:
page 60,132
title REAL MODE INITIALIZATION MODULE
;******************************************************************************
;******************************************************************************
;** **
;** init_r.asm **
;** **
;** Copyright (C) 2005-2006 Universe Corporation **
;** **
;** All Rights Reserved **
;** **
;** Lanzhou University Of Tecnology **
;** **
;** (0931)-2975931 **
;** **
;******************************************************************************
;******************************************************************************
;+ includes +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
include asm\equates.inc
include asm\macros.inc
include asm\structs.inc
;+ code segment +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
startup group _init_r
_init_r segment word public use16 'CODE'
assume cs:startup
.486p
;------------------------------------------------------------------------------
public _INIT_R_STARTS
_INIT_R_STARTS label byte ; marks start of module
;------------------------------------------------------------------------------
; change the segment value of ds
mov ax,DS_INIT_R
mov ds,ax
; memory sizing
mov ax,0e801h
int 15h
.if ax >= 03c00h
xor eax,eax
mov ax,dx
add ax,0100h
.else
xor eax,eax
mov ax,cx
shr ax,6
.endif
; set bit mp / reset bit em
mov eax,cr0
bts eax,1 ; set bit mp of cr0
btr eax,2 ; reset bit em of cr0
mov cr0,eax
; prepare for switching to protected mode, no interrupt allowed
; disable INTR interrupt
cli
mov al,0fbh
out 21h,al ; mask all interrupt of 8259 #1 except ir2
io_delay
mov al,0ffh
out 0a1h,al ; mask all interrupt of 8259 #2
; disable NMI interrupt
in al,70h
io_delay
or al,80h
out 70h,al
; adjust gdt position, move it to address 0000:0800
mov si,offset ds:gdt_dummy
mov di,GDT_START
mov cx,6
cld
rep movsd
lgdt fword ptr ds:[gdt_pseudo_desc]
; enable gate a20
in al,92h
test al,02h
jnz gate_a20_enabled
or al,02h
io_delay
out 92h,al
gate_a20_enabled:
; switch to protected mode
mov eax,cr0
or eax,00000001h ; set bit PE of CR0
mov cr0,eax
; clear label / jump to init_p module
jmp_if CS_SEL,INIT_P_START
;- data -----------------------------------------------------------------------
; system gdt
gdt_dummy gdt_desc <0,0,0,0,0,0>
gdt_cs gdt_desc <1fffh,0000h,00h,9ah,0c0h,00h>
gdt_ds gdt_desc <1fffh,0000h,00h,92h,0c0h,00h>
; pseudo descripter
gdt_pseudo_desc pseudo_desc <0017h,00000800h>
org INIT_R_SECS_NR * 512 - 2
; setup module end signature
word 5a5ah
;------------------------------------------------------------------------------
public _INIT_R_ENDS
_INIT_R_ENDS label byte ; marks end of module
;------------------------------------------------------------------------------
_init_r ends
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -