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

📄 usbi13.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	mov	bx, _str$_USB_STOR_DEV_INFO
	call	display_token_message_FAR
	mov	al, ch
	call	display_al_hex_far
	mov	bx, _str$_USB_STOR_SPC_COLON_SPC
	call	display_token_message_FAR
	pop	bx
ENDIF

; Fill URP with proper values
	lea	bx, stURP
	push	ss
	pop	es

	mov	bIteration, 0

	cmp	cl, 0FFh
	jne	UNGDI_DevAddrReady
	xor	cl, cl

UNGDI_DevAddrReady:
	mov	(URP_STRUC PTR es:[bx]).bFuncNumber, \
					USB_API_MASS_DEVICE_REQUEST
; Sub-function - USB_MASS_GET_DEVICE_INFO
	mov	(URP_STRUC PTR es:[bx]).bSubFunc, \
					USB_MASSAPI_GET_DEVICE_INFO
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassGetDevInfo.bDevAddr, cl
	INVOKE_USB_API_HANDLER

; Load URP pointer again
	lea	bx, stURP
	push	ss
	pop	es

	mov	al, (URP_STRUC PTR es:[bx]).bRetValue
	or	al, al
	je	UNGDI_ProceedFurther

	inc	bIteration
	cmp	bIteration, 3
	jb	UNGDI_DevAddrReady

;; Error
	stc
	jmp	UMGDI_Exit

UNGDI_ProceedFurther:
	mov	cl, (URP_STRUC PTR es:[bx]).ApiData.MassGetDevInfo.bDevAddr
	cmp	cl, 0FFH
	stc
	je	UMGDI_Exit		; No more USB mass device

	mov	al, (URP_STRUC PTR es:[bx]).ApiData.MassGetDevInfo.bDevType
	mov	ah, (URP_STRUC PTR es:[bx]).ApiData.MassGetDevInfo.bEmuType
	mov	esi, (URP_STRUC PTR es:[bx]).ApiData.MassGetDevInfo.fpDevId

; CL = Bits 0..6 - USB device address
;      Bit7 set - no USB Mass Storage devices found
; ESI = 00h No String Available (use default type)
;     <> 00h Absolute address of pointer to Device ID String
; AL = Usb Mass Storage Device Type
;            00 = Reserved
;	     01 = Hard Disk
;            02 = CD-ROM
;            03 = Removable Device (Floppy)
;               AH = Emulation Type
;                  00 No Emulation or (Not Applicable)
;                  01 Floppy Only
;                  02 Hard Disk Only
;                  03 Floppy or Hard Disk (Only for CDROM)
;		   04 Forced floppy (Force HDD as FDD)

	xor	dl, dl

; Assume floppy
	mov	dh, BAID_TYPE_FDD
	cmp	al, USB_MASS_DEV_ARMD	; Is this a floppy ?
	je	UMGDI_USBString		; Yes !

; Assume as CDROM
	mov	dh, BAID_TYPE_CDROM
	cmp	al, USB_MASS_DEV_CDROM	; Is this a CDROM ?
	je	UMGDI_USBString		; Yes !

; If not, leave it as HDD
	mov	dh, BAID_TYPE_HDD	;make it type HDD
	or	dl, 80h			;make it an HDD handle

UMGDI_USBString:

	push	ds
	pop	es

	cmp	esi, 0			;if esi is null, no string was available
	jz	UMGDI_USBStringNotValid	;from drive

	push	edi			;else, set up edi for strcat
	mov	edi, esi
	and	si, 0fh
	shr	edi, 4
	mov	ds, di
	pop	edi
	jmp	SHORT UMGDI_DoString

UMGDI_USBStringNotValid:		;no valid string so use generic one
	push	cs			;below
	pop	ds
	mov	si, OFFSET str_usb

UMGDI_DoString:

; ES:DI = Pointer to current exp header
; DS:SI = Pointer to Device ASCIIz String
	call	strcat_drive_string

	mov	al, cl
	and	al, 07Fh
	or	dl, al			; Bit7 is set for HDD
	mov	bh, dl			; Logical drive number
	mov	bl, al			; USB Device Number

IF	(MKF_USB_VERBOSE_MODE GT 0)
; Display the vendor id
	push	di
	push	cx
	mov	cx, 22			; # of max characters to display
	add	di, offset FDDUSB_Exp_Header.BigEndian
	call	DisplayString
	pop	cx
	pop	di
ENDIF

	call	UsbMassRegisterDriveNumber	;now register the drive with

IF	(MKF_USB_VERBOSE_MODE GT 0)
	call	display_0d0a_FAR
ENDIF


	clc					;USB i13 so it can map handle

UMGDI_Exit:

IF	(MKF_USB_VERBOSE_MODE GT 0)
	pushf
	jnc	UMGDI_RealExit

; Clear the current line
	push	cx
	mov	al, 0dh
	call	DisplayChar_FAR
	push	cs
	pop	es
	mov	di, OFFSET USBI13Spaces
	mov	cx, 25
	call	DisplayString
	mov	al, 0dh
	call	DisplayChar_FAR
	pop	cx

UMGDI_RealExit:
	popf
ENDIF

	pop	ds
	pop	es
	pop	di
	pop	esi
	pop	bx
	pop	eax
	ret
UsbMassGetDeviceInformation	ENDP

str_usb		db	'USB Disk Drive',0

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassRegisterDriveNumber
;
; Description:	This function maps the USB device number with the drive
;		number. Device number and drive number are same except that
;		HDD emulated devices have their drive number bit 7 set.
;
; Input: 	BL	USB device address of current mass device
;		BH	INT13h drive number assigned for this device
;
; Output: 	CY	Set on error
;
; Modified:	None
;
; Referrals:	URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

UsbMassRegisterDriveNumber 	PROC NEAR PUBLIC
	LOCAL	stURP:URP_STRUC

	push	di
	push	es
	push	bx

; Fill URP with proper values
	lea	di, stURP
	push	ss
	pop	es

	mov	(URP_STRUC PTR es:[di]).bFuncNumber, \
					USB_API_MASS_DEVICE_REQUEST
	mov	(URP_STRUC PTR es:[di]).bSubFunc, \
					USB_MASSAPI_ASSIGN_DRIVE_NUMBER
; BL = USB device number in order
; BH = Int-13 Drive Number assigned by the BIOS
	mov	(URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bDevAddr, bl
	mov	(URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bLogDevNum, bh

	mov	bx, di
	INVOKE_USB_API_HANDLER

IF	(MKF_USB_VERBOSE_MODE EQ 2)
	mov	al, '('
	call	DisplayChar_FAR
	mov	al, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bHeads
	call	display_al_hex_far
	mov	al, ','
	call	DisplayChar_FAR
	mov	ax, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.wCylinders
	call	display_ax_hex_far
	mov	al, ','
	call	DisplayChar_FAR
	mov	al, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bSectors
	call	display_al_hex_far
	mov	al, ','
	call	DisplayChar_FAR
	mov	ax, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.wBlockSize
	call	display_ax_hex_far
	mov	al, ','
	call	DisplayChar_FAR
	mov	al, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bLUN
	call	display_al_hex_far
	mov	al, ')'
	call	DisplayChar_FAR

	mov	al, (URP_STRUC PTR es:[di]).ApiData.MassAssignNum.bSpeed
	or	al, al
	jz	UMRDN_SpeedDone

	mov	bx, _str$_USB_HISPEED
	call	display_token_message_FAR
UMRDN_SpeedDone:
ENDIF

	cmp	(URP_STRUC PTR es:[di]).bRetValue, USB_SUCCESS
	je	UMRDN_ExitSuccess
	stc
	jmp	SHORT UMRDN_Exit

UMRDN_ExitSuccess:
	clc

UMRDN_Exit:

	pop	bx
	pop	es
	pop	di

	ret
UsbMassRegisterDriveNumber ENDP

	PUBLIC	_USBI13_ASM_I13P_END
_USBI13_ASM_I13P_END		LABEL		BYTE

I13P_CSEG	ENDS

;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;	I N T   1 3   R U N T I M E    C O D E   S E G M E N T
;----------------------------------------------------------------------------
I13R_CSEG	SEGMENT PARA PUBLIC 'CODE'
	ASSUME	CS:I13R_CSEG
.586p
		PUBLIC	USBI13_CODE_STARTS
USBI13_CODE_STARTS	LABEL BYTE

;----------------------------------------------------------------------------
;				USB CDROM Support
;----------------------------------------------------------------------------

; Structure definition for the temp area used

; This area is limited to 3 bytes right now !
USBCDDataArea	STRUC
	bUSBCDHandle	DB	?
	wUSBRsrvd	DW	?
USBCDDataArea	ENDS

USBCdromAPIHeader	LABEL	BYTE
	CDROM_API_HDR < \
		OFFSET CS:USBCDGetGenStatus, \
		OFFSET CS:USBCDResetDevice, \
		OFFSET CS:USBCDReadDevice, \
		OFFSET CS:USBCDGetBootRecLBA >

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure:	farCheckForUSBCdrom
;
; Description:	This routine checks whether the current CDROM that BIOS
;		tries to boot is a USB CDROM drive.  If so, it will 
;		return the USB CDROM API header pointer for the BIOS
;		to handle this drive
;
; Input:	NC	If the owner of the CDROM is not yet found
;		CY	If the owner had been already identified
;		DL	Drive handle for this CDROM reported by 
;			corresponding technology module while registering 
;			this drive with the BBS
;		FS:SI	Temp data pointer in EBDA
;
; Output:	NC	If this drive does not belong to USB
;		CY	If this drive is indeed an USB CDROM drive
;		  ES:DI	Pointer to the CDROM API header structure
;		  FS:SI	Temp data area filled with relevant info
;
; Modified:	ES, DI
;
; Notes:	The CDROM drive is assumed to be an USB drive if the 
;		drive handle is less than 80h
;
; Referrals:	USBCDDataArea, CDROM_API_HDR
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

farCheckForUSBCdrom		PROC	FAR	PUBLIC

	push	bx
; Check the carry flag to determine whether somebody took owner ship
; for this drive
	jc	FCFUC_Exit

; Compare DL to find out whether it falls into ATAPI CDROM range
	cmp	dl, 80h
	jae	FCFUC_Exit

; Yes. It is indeed an USB CDROM drive. Get relevant information from
; the CD init code and place it in the temp area provided

; Save the handle
	mov	(USBCDDataArea PTR FS:[si]).bUSBCDHandle, dl

; Return the CDROM API header for USB CDROM
	push	cs
	pop	es
	mov	di, OFFSET CS:USBCdromAPIHeader

; Set the carry flag indicating we are supporting this drive
	stc
FCFUC_Exit:
	pop	bx
	ret
farCheckForUSBCdrom		ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure:	USBCDGetGenStatus
;
; Description:	This routine is a part of USB CDROM API routines. This
;		routine general information regarding the USB CDROM
;		depending on the input parameters
;
; Input:	AX	Type of operation to perform
;		  CDROM_STAT_GET_DELAY_STATUS	Return delay needed before
;						accessing the CDROM
;		FS:SI	Pointer to USBCDDataArea
;
; Output:	NC	Function supported
;			AX	Return value depending on input param
;		CY	Function not supported (nothing changed)
;
; Modified:	AX
;
; Notes:	The CDROM drive is assumed to be an ATAPI drive if the 
;		drive handle is between the ranges 80h - 8Fh.
;
; Referrals:	USBCDDataArea, CDROM_API_HDR
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBCDGetGenStatus	PROC	NEAR	PUBLIC

; No delay
	jmp	SHORT UCGGS_RetError

; Check for appropriate function number
	cmp	ax, CDROM_STAT_GET_DELAY_STATUS
	jne	UCGGS_RetError

; Return delay value (10 seconds)
	mov	ax, 10

UCGGS_Return:
	clc
	ret

UCGGS_RetError:
	stc
	ret
USBCDGetGenStatus	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure:	USBCDResetDevice
;
; Description:	This routine is a part of ATAPI CDROM API routines. This
;		routine resets the CDROM device
;
; Input:	FS:SI	Pointer to ATACDDataArea
;
; Output:	NC	Successful
;			AH	0
;		CY	Error
;			Ah	<> 0
;
; Modified:	AX
;
; Referrals:	USBCDDataArea, CDROM_API_HDR, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBCDResetDevice		PROC	NEAR	PUBLIC

	LOCAL	sURP:URP_STRUC

	push	bx
	push	dx
	push	es

	push	ax

	lea	bx, sURP
	push	ss
	pop	es

	mov	al, (USBCDDataArea PTR FS:[si]).bUSBCDHandle
	mov	(URP_STRUC PTR ES:[bx]).ApiData.MassRead.bDevAddr, al

	mov	(URP_STRUC PTR ES:[bx]).bFuncNumber, \
					USB_API_MASS_DEVICE_REQUEST
	mov	(URP_STRUC PTR ES:[bx]).bSubFunc, \
					USB_MASSAPI_RESET_DEVICE
	INVOKE_USB_API_HANDLER

	pop	ax

	mov	ah, (URP_STRUC PTR ES:[bx]).bRetValue
	clc

	pop	es
	pop	dx
	pop	bx
	ret
USBCDResetDevice		ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure:	USBCDReadDevice
;
; Description:	This routine is a part of USB CDROM API routines. This
;		routine reads the El Torito format device as per the
;		input parameters provided
;
; Input:	FS:SI	Pointer to USBCDDataArea
;		CX	Number of blocks (2K) to read

⌨️ 快捷键说明

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