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

📄 compat.asm

📁 X86 GX1 BOOTLOAD代码 ,支持WINCE操作系统!
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	mov	edx,eax			; data to edx
	pop	eax			; restore address
	ret
PCICfgRead32	endp

;**************************************************************************
;*
;*	PCICfgWrite32
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*	  EDX=32 bit value to write
;*
;*	Exit:
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgWrite32	PROC   NEAR PUBLIC
	push	eax			; save address
	push	edx			; save data
	and	al,0fch			; align address
	mov	dx, 0CF8h
	out	dx, eax			; set address
	mov	dx, 0CFCh
	pop	eax			; get data
	push	eax			; resave data
	out	dx,eax			; write data
	pop	edx			; restore data
	pop	eax			; restore address
	ret
PCICfgWrite32 endp	

;**************************************************************************
;*
;*	PCICfgRead8
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*
;*	Exit:
;*	  DL=8 bit value read
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgRead8	PROC   NEAR PUBLIC
	push	eax			; save address
	push	dx			; save dx
	push	ax			; save low of address
	and	al,0fch			; lsb 2 bits must be zero
	mov	dx, 0CF8h
	out	dx, eax			; set address
	mov	dx, 0CFCh
	pop	ax			; get address back
	and	ax, 03h			; offset
	or	dl,al			; point to register
	in	al, dx			; read data
	pop	dx			; restore dh
	mov	dl,al			; data to dl
	pop	eax			; restore address
	ret
PCICfgRead8	endp

;**************************************************************************
;*
;*	PCICfgRead16
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*
;*	Exit:
;*	  DX=16 bit value read
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgRead16	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
	pop	eax			; get address back
	push	eax			; re-save address
	and	ax, 02h			; offset
	or	dl,al			; point to register
	in	ax, dx			; read data
	mov	dx,ax			; data to dx
	pop	eax			; restore address
	ret
PCICfgRead16	endp

;**************************************************************************
;*
;*	PCICfgWrite8
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*	  DL=8 bit value to write
;*
;*	Exit:
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgWrite8	PROC   NEAR PUBLIC
	push	eax			; save address
	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, 03h			; offset
	or	dl,al			; point to register
	pop	ax			; get data
	push	ax			; resave data
	out	dx,al			; write data
	pop	dx			; restore data
	pop	eax			; restore address
	ret
PCICfgWrite8 endp

;**************************************************************************
;*
;*	PCICfgWrite16
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*	  DX=16 bit value to write
;*
;*	Exit:
;*
;*	Destroys:
;*
;**************************************************************************
PCICfgWrite16	PROC   NEAR PUBLIC
	push	eax			; save address
	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
	push	ax			; resave data
	out	dx,ax			; write data
	pop	dx			; restore data
	pop	eax			; restore address
	ret
PCICfgWrite16 endp

;**************************************************************************
;*
;*	PCIPointNext
;*	  returns PCI ID of next function or device 
;*	  Checks if multifunction device
;*		if so returns next function if there is one (0-7)
;*			if wraps from function 7 then returns device (as below)
;*		if not multifunction - returns next device
;*
;*	Entry:
;*	  EAX=80000000h + Func + Reg
;*
;*	Exit:
;*	  EAX=Next function or device
;*	  Carry clear if function 1-7
;*	  Carry set if new Device
;*
;*	Destroys:
;*
;**************************************************************************
PCIPointNext	PROC   NEAR PUBLIC
	push	edx
	test	ax,0700h		; in functions?
	jnz	nextfunction		; in functions - just next func
	mov	al,0			; register 0!
; on func 0 of device - see if valid device
	call	PCICfgRead32		; get register
	cmp	edx,0ffffffffh		; all f's
	je	nextdevice		; yes - next device
	push	ax			; save address
	mov	al,0ch			; header type
	call	PCICfgRead32		; read
	test 	edx,00800000h		; multifunction?
	pop	ax			; restore address
	jnz	nextfunction		; is multifunction
	
nextdevice:
	add	eax,00000800h		; next device
nextdevicecarry:
	stc
	jmp	short nextdone
	
nextfunction:
	add	eax,00000100h		; next function
	test	eax,00000700h		; see if now next device
	jz	nextdevicecarry		; yes - say new device
	clc				; say in func
	jmp	short nextdone
	
nextdone:
	pop	edx			; restore edx
	ret
PCIPointNext	endp

;**************************************************************************
;*
;*	setIBUs: set internal Bus Interface Unit Registers, display
;*	         controller registers, and Cx5530 regs to known-good
;*	         values
;*
;*	Entry:
;*	  None
;*
;*	Exit:
;*	  None
;*
;*	Destroys:
;*	  eax
;*
;**************************************************************************
setIBUs PROC NEAR PUBLIC
	EXTERN	CpuMemRegReadStack:NEAR
	EXTERN	CpuMemRegWriteStack:NEAR
	push	edx

; Set the high regions (XMAP_3)
	mov	eax, CPU_BC_XMAP_3
	call	CpuMemRegReadStack	; read current
	and	edx, 0000FFFFh		; clear top half
	or	edx, 99990000h		; place desired bits in top half
	call	CpuMemRegWriteStack

	pop	edx
	clc
	ret
setIBUs	endp

;**************************************************************************
;*
;*	pciScan: Find all PCI devices and nail-up their configuration regs
;*	         per the PCI_TABLE below.
;*
;*	Entry:
;*	  None - use PCI_TABLE to enter parameters to this routine
;*
;*	Exit:
;*	  None
;*
;*	Destroys:
;*	  None
;*
;**************************************************************************
pciScan PROC NEAR PUBLIC
	pushad

	EXTERN	unreal:NEAR
	NOSTACK	dx, UNREAL		; Setup unReal mode
	
	mov	eax, 080000000h		; Bus 0, device 0, function 0
findpcidevbus:	
	mov	ecx, 256/8		; 255 possible devices/8 func per device

findPCILoop:
	call	PCICfgRead32
	
	cmp	edx, 0ffffffffh		; valid?
	jne	foundPCIdevice		; jump if valid

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

; see if next bus
	ror	eax, 16			; get bus # to lower half
	cmp	al, 0			; did we wrap around?
	je	finishedFindingDevs	; yes
	cmp	al, numPciBusesInSystem	; see if > than max # buses
	ja	finishedFindingDevs	; gtr than max bus
; next bus
	ror	eax,16			; move back up to high of eax
	jmp	findpcidevbus		; go start again

foundPCIdevice:
if 0
	push	eax
	mov	eax, edx
	rol	eax, 8
	out	80h, al
	rol	eax, 8
	out	80h, al
	rol	eax, 8
	out	80h, al
	rol	eax, 8
	out	80h, al
	pop	eax
endif
	; Look through table to see if this device needs to get configured
	lea	si, PCI_TABLE
	mov	ebx, eax		; eax has bus/dev/function
	shr	ebx, 8			; shift dev/func to bottom
	
pci_loop:
	cmp	dword ptr cs:[si],0ffffffffh	; end of table?
	je	done			; yes
	cmp	edx, cs:[si]		; does device/vendor id match?
	jne	pci_next		; nope, move on to next table entry
        ;msg     'I found a map vender'
        ;push    ax
        ;push    bx
        ;mov     al,bl
        ;write_stdout
        ;pop     bx
        ;pop     ax
	cmp	bl, cs:[si+4]		; yes, so does the dev/func match too?
	je	setDevRegs		; if both match, go set regs

pci_next:
	add	si, sizeofPciTableEntry	; next entry
	jmp	short pci_loop
	
setDevRegs:
	push	eax
	push	ebx
	push	edx
	push	esi
        ; msg    'set regs'
	; Load the table of registers to set
	mov	si, cs:[si+5]

moreRegsToSet:
	cmp	byte ptr cs:[si], 0ffh	; end of table?
	je	doneSettingRegs
	add	al, cs:[si]
	mov	bl, cs:[si+1]
	mov	bh, 0			; bx is now the 1-byte size field

	cmp	bl, 1
	jne	switch2
	mov	dl, cs:[si+2]
	call	PCICfgWrite8
	jmp	endOfSwitch
switch2:
	cmp	bl, 2
	jne	switch4
	mov	dx, cs:[si+2]
	call	PCICfgWrite16
	jmp	endOfSwitch
switch4:
	cmp	bl, 4
	jne	sizeError
	mov	edx, cs:[si+2]
	call	PCICfgWrite32
	
endOfSwitch:
	sub	al, cs:[si]
	add	bx, 2			; take into account the other 2 bytes
	add	si, bx			; increment to next register
	jmp	moreRegsToSet


doneSettingRegs:
	pop	esi
	pop	edx
	pop	ebx
	pop	eax

done:
	jmp	nextpci			; go look for more

sizeError:
	mov	al, 0eeh
	out	80h, al
	hlt

finishedFindingDevs:
	popad
	clc
	ret
pciScan endp


;*******************************
; EAX = starting address to dump
; EDX = num dwords to dump
;*******************************
byteDumpToPort80 PROC NEAR PUBLIC
	push	eax
	push	esi
	mov	esi, 0
moreBytes:
	mov	eax, es:[ebx+esi]
	out	80h, al
	shr	eax, 8
	out	80h, al
	shr	eax, 8
	out	80h, al
	shr	eax, 8
	out	80h, al
	add	esi, 4
	loop	moreBytes
	pop	esi
	pop	eax
byteDumpToPort80 endp

_TEXT ENDS

END

⌨️ 快捷键说明

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