⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unreal.asm

📁 X86 GX1 BOOTLOAD代码 ,支持WINCE操作系统!
💻 ASM
字号:
;**************************************************************************
;*
;*  UNREAL.ASM
;*
;*  Copyright (c) 1999 National Semiconductor Corporation.
;*  All Rights Reserved.
;*
;*  Function:
;*    Routines to enter and exit unReal mode.
;*
;*  $Revision:: 2   $
;*
;**************************************************************************

	.486P

	INCLUDE MACROS.INC
	INCLUDE DEF.INC

_TEXT SEGMENT PUBLIC use16 'CODE'

;**************************************************************************
;* MEM_DESCRIPTOR:  8-Byte Intel-Defined Structure Used To
;*   Load A Selector Register (e.g. DS, ES) For Protected
;*   Mode Use.
;**************************************************************************
MEM_DESCRIPTOR	STRUCT 1
	Lim_0_15	DW	0
	Base_0_15	DW	0
	Base_16_23	DB	0
	Access		DB	0
	Granularity	DB	0
	Base_24_31	DB	0
MEM_DESCRIPTOR	ENDS

;**************************************************************************
;* Global Descriptor Table For Initializing Selectors
;* Note:  Selectors Not Used For Real-Big Mode MUST Be Set
;*  Back To 64K Limits Before Re-Entering Real Mode.
;**************************************************************************

PROT_GDT_TABLE LABEL FWORD

NULL_SEG_DESC	MEM_DESCRIPTOR	<    0h, 0h, 00h, 00H, 000H, 0>
FLAT_SEG_DESC	MEM_DESCRIPTOR	<0FFFFh, 0h, 00h, 93H, 08FH, 0>
CODE_SEG_DESC	MEM_DESCRIPTOR	<0FFFFh, 0h, 00h, 9AH, 000H, 0>
REAL_64K_DESC	MEM_DESCRIPTOR	<0FFFFh, 0h, 00h, 92H, 000H, 0>

PROT_GDT_TABLE_END   LABEL   BYTE

;**************************************************************************
;* GDT_REG:  Intel-Defined Structure Defining Value To Load
;*   Into The GDTR (Global Descriptor Table Register) Inside
;*   The CPU.  The GDTR Points The CPU To The Current Protected
;*   Mode Descriptor Table.  The LGDT Op-Code Loads This Reg.
;**************************************************************************

GDT_REG  STRUCT 1
	TABLE_SIZE	DW	0		; Size Of GDT_TABLE In BYTES
	TABLE_ADDR_LOW	DW	0		; Bits [15:0] Of GDT_TABLE Phys Address
	TABLE_ADDR_HIGH	DW	0		; Bits [31:16] Of GDT_TABLE Phys Address
	UNUSED		DW	0
GDT_REG  ENDS

PROT_MODE_GDTR LABEL FWORD

	GDT_REG < PROT_GDT_TABLE_END - PROT_GDT_TABLE - 1, OFFSET PROT_GDT_TABLE , 0Fh , 0 >

PROT_MODE_GDTR_DOC LABEL FWORD

	GDT_REG < PROT_GDT_TABLE_END - PROT_GDT_TABLE - 1, OFFSET PROT_GDT_TABLE , 07h , 0 >

REAL_MODE_GDTR LABEL FWORD

	GDT_REG < 0FFFFH, 0, 0, 0 >

;**************************************************************************
;*
;*	unReal
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
unReal	PROC NEAR PUBLIC
	shl	edx, 16

	NOSTACK	dx, MAKE_ES_BIG
	shr	edx, 16

	jmp	dx
unReal ENDP

;**************************************************************************
;*
;*	MAKE_ES_BIG
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
MAKE_ES_BIG PROC NEAR
	; save CS (will be F000 if booting from real flash, or 7000 if
	; booting directly from the DOC)
	mov	cx, cs
	test	ch, 80h			; Bit15=1 if ROM'd, 0 if DOC'd
	jz	useDOCsegment

	lgdt	FWORD PTR PROT_MODE_GDTR
	jmp	useF000segment

useDOCsegment:
	lgdt	FWORD PTR PROT_MODE_GDTR_DOC

useF000segment:

	mov	eax, CR0
	or	al, 1
	and	al, 01fh
	mov	CR0, eax

	jmp	ProtModeEntry
ProtModeEntry:

	mov	ax, (OFFSET FLAT_SEG_DESC - OFFSET PROT_GDT_TABLE)
	mov	es, ax			; ES will be our flat descriptor
	mov	fs, ax			; and so will FS
	mov	eax, CR0
	and	ax, NOT 1
	mov	CR0, eax

	; This Code Forces CS Back To The A Real Mode Segment In A
	; Single Operation.  It Is Equivalent To The JUMP_FAR Macro.
	test	ch, 80h			; Bit15=1 if ROM'd, 0 if DOC'd
	jz	jumpInDOCsegment

	db	0EAH
	dw	offset RealModeEntry
	DW 	0F000h			; needed to get back into real mode
	
jumpInDOCsegment:
	db	0EAH
	dw	offset RealModeEntry
	DW 	07000h			; needed to get back into real mode

RealModeEntry:

	lgdt	cs:REAL_MODE_GDTR

	jmp	dx
MAKE_ES_BIG ENDP

;**************************************************************************
;*
;*	ResetLimits
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
ResetLimits PROC NEAR PUBLIC
	lgdt	FWORD PTR MY_GDT	; Reset Limits
	ret
ResetLimits ENDP

MY_GDT LABEL FWORD
	DW -1, 0 ,0 ,0

_TEXT ENDS

	END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -