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

📄 usb.asm

📁 AMI 主板的BIOS源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	xor	ecx, ecx

	cmp	si, MAX_CONTROL_DATA_SIZE
	jae	ReadBufferDone		;Br if caller's offset is too big

	add	si, di			;SI = ptr into ApiDataBuffer
	mov	ebx, dword ptr [si]
	mov	ecx, dword ptr [si+4]

ReadBufferDone:
	clc
	pop	si
	ret
UsbBiosReadApiDataBuffer	endp


;---------------------------------------;
; UsbBiosWriteApiDataBuffer             ;
;---------------------------------------;--------------------------------------;
; This function allows USB BIOS API callers to write 8 bytes of data to the    ;
; ApiDataBuffer starting at a given offset.                                    ;
;                                                                              ;
; Input: SI = Offset within buffer to write                                    ;
;        DS:DI = Segment:Offset ApiDataBuffer                                  ;
;        EBX = Data bytes 0 - 3 to write to ApiDataBuffer                      ;
;        ECX = Data bytes 4 - 7 to write to ApiDataBuffer                      ;
;                                                                              ;
; Output: CF = Clear (USB BIOS is present)                                     ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosWriteApiDataBuffer	proc near
	push	si

	cmp	si, MAX_CONTROL_DATA_SIZE
	jae	WriteBufferDone		;Br if caller's offset is too big

	add	si, di			;SI = ptr into ApiDataBuffer
	mov	dword ptr [si], ebx
	mov	dword ptr [si+4], ecx

WriteBufferDone:
	clc
	pop	si
	ret
UsbBiosWriteApiDataBuffer	endp


;---------------------------------------;
; UsbBiosGetDeviceTableEntry            ;
;---------------------------------------;--------------------------------------;
; This function is used by USB BIOS API callers to transfer one DeviceTable    ;
; entry into the ApiDataBuffer so that it can be read using the function       ;
; UsbBiosReadApiDataBuffer.                                                    ;
;                                                                              ;
; Input: BL = Index into array of DeviceTable entries                          ;
;        DS:DI = Segment:Offset ApiDataBuffer                                  ;
;                                                                              ;
; Output: CF = Clear if DeviceTable entry successfully copied, set otherwise   ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosGetDeviceTableEntry	proc near
	pusha

	cmp	bl, MAX_DEVICES		;There are MAX_DEVICES+1 entries
	cmc
	jb	GetEntryDone		;Br if index is too big

	mov	al, size DeviceTableEntry
	mul	bl			;AX = Offset into DeviceTable
	mov	si, ax			;SI = Offset into DeviceTable
	add	si, offset DeviceTable	;SI = Offset of DeviceTable entry
	mov	cx, size DeviceTableEntry
	rep	movsb			;Copy the DeviceTable entry

	clc				;Indicate success

GetEntryDone:
	popa
	ret
UsbBiosGetDeviceTableEntry	endp


;---------------------------------------;
; UsbBiosSetDeviceTableEntry            ;
;---------------------------------------;--------------------------------------;
; This function is used by USB BIOS API callers to set the contents of one     ;
; DeviceTable entry from the ApiDataBuffer.                                    ;
;                                                                              ;
; Input: BL = Index into array of DeviceTable entries                          ;
;        DS:DI = Segment:Offset ApiDataBuffer                                  ;
;                                                                              ;
; Output: CF = Clear if DeviceTable entry successfully copied, set otherwise   ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosSetDeviceTableEntry	proc near
	pusha

	cmp	bl, MAX_DEVICES		;There are MAX_DEVICES+1 entries
	cmc
	jb	SetEntryDone		;Br if index is too big

	mov	al, size DeviceTableEntry
	mul	bl			;AX = Offset into DeviceTable
	mov	si, ax			;SI = Offset into DeviceTable
	add	si, offset DeviceTable	;SI = Offset of DeviceTable entry
	mov	cx, size DeviceTableEntry
	xchg	si, di
	rep	movsb			;Copy the DeviceTable entry

	clc				;Indicate success

SetEntryDone:
	popa
	ret
UsbBiosSetDeviceTableEntry	endp


;---------------------------------------;
; UsbBiosCheckDeviceTypePresent         ;
;---------------------------------------;--------------------------------------;
; This function is used by USB BIOS API callers to check for the presence of   ;
; a given type of USB device.                                                  ;
;                                                                              ;
; Input: BL = Type of device to check for:                                     ;
;               00h = Reserved                                                 ;
;               01h = Keyboard                                                 ;
;               02h = Mouse                                                    ;
;               03h = Hub                                                      ;
;               04h = Floppy                                                   ;
;               05h-FFh = Reserved                                             ;
;        DS = ES = usbdseg                                                     ;
;                                                                              ;
; Output: CF = Clear if a USB device of the given type is present, set         ;
;              otherwise                                                       ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosCheckDeviceTypePresent	proc near
	pusha

	mov	cx, MAX_DEVICES		;There are MAX_DEVICES+1 entries
	mov	si, offset DeviceTable	;SI = Offset of DeviceTable entry

CheckPresentNextDevice:
	add	si, size DeviceTableEntry ;Skip entry 0 / point to next entry
	cmp	(DeviceTableEntry ptr [si]).Present, TRUE
	jne	CheckPresentSkipDevice
	cmp	(DeviceTableEntry ptr [si]).BiosDeviceType, bl
	clc				;Indicate device present
	je	CheckPresentDone	;Br if given device type found

CheckPresentSkipDevice:
	loop	CheckPresentNextDevice
	stc				;Indicate device present

CheckPresentDone:
	popa
	ret
UsbBiosCheckDeviceTypePresent	endp


;---------------------------------------;
; UsbDataInit                           ;
;---------------------------------------;--------------------------------------;
; This function initializes the data structures in the usbdseg.                ;
;                                                                              ;
; Input: DS = ES = usbdseg                                                     ;
;                                                                              ;
; Output: Nothing                                                              ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbDataInit	proc near
	pushad

	xor	eax,eax
	push	ds
	pop	ax
	shl	eax,4
	mov	HcdDataArea, eax

; Setup entry 0 in the DeviceTable as used.

	mov	si, offset DeviceTable	;SI = ptr to entry for device address 0
	mov	(DeviceTableEntry ptr [si]).Present, TRUE

; Initialize remaining entries in device table to unused.

	add	si, size DeviceTableEntry ;SI = ptr to entry for device address 1
@@:
	mov	(DeviceTableEntry ptr [si]).Present, FALSE
	add	si, size DeviceTableEntry ;SI = ptr to next entry
	cmp	si, offset DeviceTableEnd
	jb	@b
	
; Initialize the USB keyboard scanner buffer

ifndef DOS_DEBUG
	call	InitUSBKbDataArea
endif

	popad
	ret
UsbDataInit	endp


;---------------------------------------;
; _UsbSetAddress                        ;
;---------------------------------------;--------------------------------------;
; This function sets the USB device address of device 0 to the given value.    ;
; After this call the USB device will respond at its new address.              ;
;                                                                              ;
; Input: AL = New USB device address to be assigned to device 0                ;
;                                                                              ;
; Output: CF = Clear if the set address command completed successfully         ;
;              Set if the set address command failed                           ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
_UsbSetAddress	proc near
	pusha
	push	es

	movzx	cx, al			;CX = wValue parameter = New device addr
	xor	ax, ax			;Dest is  device 0, endpoint 0
	mov	bx, USB_RQ_SET_ADDRESS	;Request type is "Set Address"
	xor	dx, dx			;DX = wIndex parameter = 0
	xor	si, si			;DX = wLength parameter = 0
	xor	di, di			;ES:DI = data buf ptr = NULL
	mov	es, di

	call	UsbDeviceRequest	;Execute the device request, returns CF

	pop	es
	popa
	ret
_UsbSetAddress	endp


;---------------------------------------;
; _UsbGetDescriptor                     ;
;---------------------------------------;--------------------------------------;
; This function executes a Get Descriptor command to the given USB device and  ;
; endpoint.                                                                    ;
;                                                                              ;
; Input: AL = USB device address of device to receive the command              ;
;        AH = Endpoint number within the USB device                            ;
;        CH = USB Descriptor type                                              ;
;        CL = Descriptor index                                                 ;
;        SI = Size of descriptor in bytes                                      ;
;                                                                              ;
; Output: ES:DI = Pointer to memory buffer containing the descriptor           ;
;         CF = Clear if the command completed successfully                     ;
;              Set if the command failed                                       ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
_UsbGetDescriptor proc near
	push	bx
	push	dx

	mov	bx, USB_RQ_GET_DESCRIPTOR ;Request type is "Get Descriptor"
	xor	dx, dx			;DX = wIndex parameter = 0
	mov	di, offset DeviceRequestDataBuf ;ES:DI = ptr DeviceRequestDataBuff
	call	UsbDeviceRequest	;Execute the device request, returns CF

	pop	dx
	pop	bx
	ret
_UsbGetDescriptor endp


;---------------------------------------;
; _UsbSetConfiguration                  ;
;---------------------------------------;--------------------------------------;
; This function executes a Set Configuration command to the given USB device   ;
; and endpoint.                                                                ;
;                                                                              ;
; Input: AL = USB device address of device to receive the command              ;
;        AH = Endpoint number within the USB device                            ;
;        CX = Configuration number to send to the USB device                   ;
;                                                                              ;
; Output: CF = Clear if the command completed successfully                     ;
;              Set if the command failed                                       ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
_UsbSetConfiguration proc near

⌨️ 快捷键说明

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