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

📄 compat.asm

📁 X86 GX1 BOOTLOAD代码 ,支持WINCE操作系统!
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;.MODEL TINY
.486P

	INCLUDE MACROS.INC
	INCLUDE DEF.INC
	INCLUDE 5530.INC
	INCLUDE OPTIONS.INC
	INCLUDE BDA.INC
	INCLUDE userfunc.inc
	INCLUDE STRINGS.INC


_TEXT SEGMENT PUBLIC use16 'CODE'



;**************************************************************************
;*
;*	genericInt15
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
genericInt15	PROC NEAR PUBLIC
	cmp	ah, 0BFh
	jne	NotForCyrix

	pusha
	mov	bp, sp
	extern	GeodeInt15Handler : near
	call	GeodeInt15Handler
	mov	sp, bp
	popa
	sti
	retf	02
	
NotForCyrix:
	mov	ah, 86h		; 86 = unsupported fucntion
	stc			; set carry flag

	sti
	retf	02
genericInt15	ENDP

;**************************************************************************
;*
;*	Delay_100_mSec
;*
;*	Granular 1 msec port61 delay loop.
;*	NOTE:  Needs AT-Compatible REF_BIT in port 61h (bit-4)
;*
;*	Entry:
;*	  None
;*
;*	Exit:
;*	  None
;*
;*	Destroys:
;*	  None
;*
;**************************************************************************
Delay_100_mSec PROC NEAR PUBLIC
	pushf
	pushad
	cli

	mov	ebx, 6630		; Magic Number
	xor	ax, ax

Wait_Safe:
	mov	dx, 200

wait_flip:
	in	al, PORT61H
	and	al, REF_BIT
	cmp	al, ah
	jne	flip_occurred

	dec	dx
	jnz	wait_flip

flip_occurred:
	mov	ah, al
	dec	ebx
	jnz	Wait_Safe

	popad
	popf
	ret
Delay_100_mSec ENDP




;**************************************************************************
;*
;*	int1AB1
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
int1AB1	PROC NEAR PUBLIC

PUBLIC int1AB1ViaVectorSeg
int1AB1ViaVectorSeg::

	sti
	retf	02
int1AB1	ENDP

;**************************************************************************
;*
;*	pcATjunk
;*
;*	Entry:
;*	Exit
;*	Destroys:
;*
;**************************************************************************
pcATjunk	proc near public

	mov	al, 056h		;
	out	043h, al		; 
	mov	al, 012h		; 
	out	041h, al		; Start TIMER 1

;; Init DMA Controller to AT Compatible mode
	mov	al, 0FFh
	out	DMA1_MASTERCLR, al
	out	DMA2_MASTERCLR, al

	mov	al, 0
	out	DMA1_CMDSTAT, al
	out	DMA2_CMDSTAT, al

	mov	al, 040h	
	out	DMA1_MODE, al		; set channel 0 to single inc mode
	mov	al, 041h	
	out	DMA1_MODE, al		; set channel 1 to single inc mode
	mov	al, 042h	
	out	DMA1_MODE, al		; set channel 2 to single inc mode
	mov	al, 043h	
	out	DMA1_MODE, al		; set channel 3 to single inc mode

	mov	al, 0C0h		; Cascade
	out	DMA2_MODE, al
	mov	al, 041h
	out	DMA2_MODE, al
	mov	al, 042h
	out	DMA2_MODE, al
	mov	al, 043h
	out	DMA2_MODE, al

	mov	al, 0
	out	DMA2_DREQ, al
	out	DMA2_MASK, al
;; End DMA Init

;; Clear First 640k of Memory, makes DOS happy.  Note that this clears
;; all of low memory, including the stack defined earlier in 
;; memSetUpStack.  If someone has left something on the stack, this will
;; exhibit the bad behaviour.

	mov	al, 0
	mov	ecx, 0A0000h
	mov	edi,0
	cld
	db	66h
	rep stosb es:[edi]

;; Clear 2nd Meg of Memory, makes DOS happy

	mov	al, 0
	mov	ecx, 0100000h		; For 1mb
	mov	edi, ecx		; Start at 1mb
	cld
	db	66h
	rep stosb es:[edi]

	jmp	bx
pcATjunk	ENDP

;**************************************************************************
;*
;*	Delay_1_mSec
;*
;*	Granular 1 msec port61 delay loop.
;*	NOTE:  Needs AT-Compatible REF_BIT in port 61h (bit-4)
;*
;*	Entry:
;*	  None
;*
;*	Exit:
;*	  None
;*
;*	Destroys:
;*	  None
;*
;**************************************************************************
Delay_1_mSec PROC NEAR PUBLIC
	pushf
	push	ax
	push	bx
	push	dx
	cli

	mov	bx, 67			; Magic Number
	xor	ax, ax

Wait_Safe:
	mov	dx, 200

wait_flip:
	in	al, PORT61H
	and	al, REF_BIT
	cmp	al, ah
	jne	flip_occurred

	dec	dx
	jnz	wait_flip

flip_occurred:
	mov	ah, al
	dec	bx
	jnz	Wait_Safe

	pop	dx
	pop	bx
	pop	ax
	popf
	ret
Delay_1_mSec ENDP

;**************************************************************************
;*
;*	endPostSMI
;*
;*	Generates the end of post SMI.
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
endPostSMI PROC NEAR PUBLIC
	pusha

; look for 5530
	mov	ax, 0b102h
	mov	cx, 0100h		; device
	mov	dx, 01078h		; vendor
	mov	si, 0
	call	findPciDevice
	jnc	found_it		; found 5530
; not 5530 - look for Geode MPC
	mov	ax, 0b102h		; national
	mov	cx, 0500h		; mpc core
	mov	dx, 0100bh
	mov	si, 0
	call	findPciDevice

	jc	endPostSMIDone		; neither one!

found_it:
	mov	dx, 05000h
	mov	di, 00d0h

	mov	ah, 080h
	mov	al, bh
	shl	eax, 16
	mov	ax, di
	mov	ah, bl

	push	dx			; save data
	push	ax			; save low of address
	and	al,0fch			; lsb 2 bits must be zero
	mov	dx, 0CF8h
	out	dx, eax			; set address
	pop	ax			; get address back
	mov	dx, 0CFCh
	and	ax, 02h			; offset
	or	dl,al			; point to register
	pop	ax			; get data
	out	dx,ax			; write data

;	jmp	endPostSMIDone

endPostSMIDone:
	popa
	ret

endPostSMI ENDP




; PCI32 Return Codes
SUCCESSFUL		EQU	00h
FUNC_NOT_SUPPORTED	EQU	81h
BAD_VENDOR_ID		EQU	83h
DEVICE_NOT_FOUND	EQU	86h
BAD_REGISTER_NUMBER	EQU	87h
SET_FAILED		EQU	88h
BUFFER_TOO_SMALL	EQU	89h


;**************************************************************************
;*
;*	findPciDevice
;*
;*	Entry:
;*	Exit:
;*		BH = bus number
;*		BL = device/function number (bits 7-3 device, bits 2-0 func)
;*	Destroys:
;*
;**************************************************************************
findPciDevice PROC NEAR	PUBLIC

	cmp	dx, 0FFFFh	; Check for valid VENDOR ID.
	jne	VendorOK
	mov	ah, BAD_VENDOR_ID
	stc
	ret

VendorOK:
	push	eax
	push	ebx
	push	cx			; save input
	push	edx
	push	di
	push	si			; Save incoming index

	mov	bx, cx			; Store DEVICE ID in Ebx
	shl	ebx, 16

	mov	bx, dx			; Store VENDOR ID in bx

	mov	eax, 080000000h		; Bus 0, device 0, function 0
	mov	cx, 255/8		; 255 possible devices/8 func per device
	mov	di,0		; start at index 0

findPCILoop:
	call	PCICfgRead32
	
	cmp	edx,0ffffffffh		; valid?
	je	nextpci			; no

	cmp	edx, ebx		; this one?
	je	foundPCIdevice		; yes

nextpci:
	call	PCIPointNext		; point next device or function
	jnc	findPCILoop			; is function 
; only count if device	
	loop 	findPCILoop

failedFindPCIDevice:
	pop	si
	pop	di
	pop	edx
	pop	cx
	pop	ebx
	pop	eax
	mov	ah, DEVICE_NOT_FOUND
	stc
	ret

foundPCIdevice:
	cmp	si, di		; SI could have up to 8
	je	foundIt			; So we keep looking for a device
	inc	di		; That may be on the BUS Multiple 
	jmp	nextpci			; go look for more

foundIt:

	pop	si
	pop	di
	pop	edx
	pop	cx
	pop	ebx

	shr	eax, 8			; isolate  BUS/ DEVICE/FUNCTION into AX
	mov	bx, ax			; move it to return to caller

	pop	eax
	mov	ah, SUCCESSFUL
	clc
	ret

findPciDevice ENDP


;**************************************************************************
;*
;*	PCICfgRead32
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*
;*	Exit:
;*	  EDX=32 bit value read
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgRead32	PROC   NEAR PUBLIC
	push	eax			; save address
	and	al,0fch			; lsb 2 bits must be zero
	mov	dx, 0CF8h
	out	dx, eax			; set address
	mov	dx, 0CFCh
	in	eax, dx			; read data

⌨️ 快捷键说明

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