📄 usbi13.asm
字号:
TITLE USBI13.ASM -- USB Mass Storage Devices INT13h Handler
;***************************************************************************;
;***************************************************************************;
;** **;
;** (C)Copyright 1985-2003, American Megatrends, Inc. **;
;** **;
;** All Rights Reserved. **;
;** **;
;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **;
;** **;
;** Phone (770)-246-8600 **;
;** **;
;***************************************************************************;
;***************************************************************************;
;***************************************************************************;
; $Header: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBI13.ASM 9 1/24/03 7:05p Sivagarn $
;
; $Revision: 9 $
;
; $Date: 1/24/03 7:05p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBI13.ASM $
;
; 9 1/24/03 7:05p Sivagarn
; BugFix
; - Building error when USB_VERBOSE_MODE set to 0 is corrected
; - Fixed the problem with Windows XP when USB floppy is selected as
; first drive (two drives are installed for USB) is corrected. INT13h
; function 15h returns wrong carry flag value
;
; 8 1/06/03 5:37p Sivagarn
; Bug in correctly displaying USB mass storage devices name in the setup
; when ATA_4CHANNEL token is enabled is fixed. The fix includes moving
; of compatibility code to USBFLAG.EQU (generated by USB.MAK) from
; USBI13.ASM
;
; 7 1/03/03 7:10p Sivagarn
; - Stack for USB INT13h handler is allocated in the USB data area. Stack
; allocated in the I13R_CSEG is removed
; - Bug in executing extended INT13h read/write calls is fixed (wrong
; register usage)
;
; 6 12/17/02 3:25p Sivagarn
; - Changed copyright message year to 2003
; - 'USBI13SetMiscInfoInStack' routine is modified to return timeout
; error if the USB drive geometry is invalid
; - The return code from 'USBI13SetMiscInfoInStack' routine is passed to
; the INT13h functions so that they can make decision what to do
; - Number of cylinders reported for the HDD emulated drives is changed
; to include the reserved cylinder defined by original IBM specification
; - FDD related INT13h function 15h and 20h are modified to return
; appropriate value
; - Last LBA returned is adjusted to the new requirement
;
; 5 11/27/02 6:20p Sivagarn
; - Old CDROM related boot code (which is present to support core
; versions 8.00.04 or before) is moved to the end of file for code
; clarity
;
; 4 10/29/02 6:43p Sivagarn
; - Support for slow mass storage devices is added
; - During BBS register call, get device information call is retried
;
; 3 10/14/02 8:58p Sivagarn
; * Code cleanup
; * Old boot block related code is removed
;
; 2 9/24/02 6:27p Sivagarn
; BugFix: Number of sectors read/write is return wrongly
;
; 1 9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
;
;***************************************************************************;
;----------------------------------------------------------------------------
; Global options are defined here
;----------------------------------------------------------------------------
OPTION PROC:PRIVATE
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Macro and equate files are included here
;----------------------------------------------------------------------------
INCLUDE equates.equ
INCLUDE usbflag.equ
INCLUDE usb.equ
INCLUDE rt.equ
INCLUDE int13pnp.equ
INCLUDE hdparam.equ
INCLUDE cdrom.equ
IFDEF MKF_CORE8_ID
IF (MKF_CORE8_ID GE 0005h)
ENABLE_OLD_CDROM_CODE EQU 0
ELSE ;; (MKF_CORE8_ID GE 0005h)
ENABLE_OLD_CDROM_CODE EQU 1
ENDIF ;; (MKF_CORE8_ID GE 0005h)
ELSE ; IFDEF MKF_CORE8_ID
ENABLE_OLD_CDROM_CODE EQU 1
ENDIF ; IFDEF MKF_CORE8_ID
;<AMI_SHDR_START>
;----------------------------------------------------------------------------
; Name: USBLocalStore
;
; Description: Structure defining the local (stack) storage structure of
; the USB INT13h local store. These fields can be accessed
; with reference to SS.
;
; Fields: Name Type Description
; ------------------------------------------------------------
; bUSBAddress BYTE USB address
; bNumHeads BYTE Number of heads for this drive
; bNumSecs BYTE Number of sectors/cylinder
; wNumCyls WORD Number of cylinders
; bLBANumHeads BYTE Number of heads w.r.t LBA
; bLBANumSecs BYTE Number of sectors/cylinder w.r.t LBA
; wLBANumCyls WORD Number of cylinders w.r.t LBA
; dLastLBA DWORD Last LBA in the drive
; bMediaChange BYTE Media change indicator
; wSecSize WORD Sector size
; bMediaType BYTE Media type byte
; dRegEDI DWORD EDI register value (PUSHAD)
; dRegESI DWORD ESI register value (PUSHAD)
; dRegEBP DWORD EBP register value (PUSHAD)
; dRegESP DWORD ESP register value (PUSHAD)
; dRegEBX DWORD EBX register value (PUSHAD)
; dRegEDX DWORD EDX register value (PUSHAD)
; dRegECX DWORD ECX register value (PUSHAD)
; dRegEAX DWORD EAX register value (PUSHAD)
; wRegDS WORD DS register value (PUSH DS)
; wRegES WORD ES register value (PUSH ES)
;
;----------------------------------------------------------------------------
;<AMI_SHDR_END>
USBLocalStore STRUC
bUSBAddress DB ?
bNumHeads DB ?
bNumSecs DB ?
wNumCyls DW ?
bLBANumHeads DB ?
bLBANumSecs DB ?
wLBANumCyls DW ?
dLastLBA DD ?
;; bMediaChange DB ?
wSecSize DW ?
bMediaType DB ?
dRegEDI DD ?
dRegESI DD ?
dRegEBP DD ?
dRegESP DD ?
dRegEBX DD ?
dRegEDX DD ?
dRegECX DD ?
dRegEAX DD ?
wRegDS DW ?
wRegES DW ?
USBLocalStore ENDS
EXTERN floppy_io_status:BYTE
EXTERN winch_status:BYTE
EXTERN strcat_drive_string:NEAR
;----------------------------------------------------------------------------
; Function prototype Int13 routines
FUNCINT13 TYPEDEF PROTO NEAR SYSCALL
PTRFUNCINT13 TYPEDEF PTR FUNCINT13
;----------------------------------------------------------------------------
; External function definitions are defined here
;----------------------------------------------------------------------------
get_ebda_far PROTO FAR SYSCALL
i13_BCV PROTO NEAR SYSCALL
CDR_BEV PROTO FAR SYSCALL
IF (MKF_USB_VERBOSE_MODE GT 0)
display_al_hex_FAR PROTO FAR SYSCALL
display_ax_hex_FAR PROTO FAR SYSCALL
display_0d0a_FAR PROTO FAR SYSCALL
display_token_message_FAR PROTO FAR SYSCALL
DisplayChar_FAR PROTO FAR SYSCALL
EXTERN _str$_USB_STOR_AUTO_DET:ABS
EXTERN _str$_USB_STOR_DEV_INFO:ABS
EXTERN _str$_USB_STOR_SPC_COLON_SPC:ABS
EXTERN _str$_USB_STOR_AUTO_DET_DONE:ABS
EXTERN _str$_USB_HISPEED:ABS
ENDIF
EXTERN Q_USB_LEGACY_ENABLE:ABS
EXTERN Q_USB_LEGACY_STORAGE:ABS
EXTERN check_cmos_data_far:FAR
EXTERN UI13OldSP:WORD
EXTERN UI13OldSS:WORD
EXTERN UI13Stack:NEAR
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Function prototype definitions are here
;----------------------------------------------------------------------------
USBI13SetMiscInfoInStack PROTO NEAR SYSCALL
IF MKF_USB_MODE GE 2
farUSBRT_InvokeAPI PROTO FAR SYSCALL
ELSE
farUSBWrap_ApiHandler PROTO FAR SYSCALL
ENDIF
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; D A T A S E G M E N T
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; M I S C S E G M E N T S
;----------------------------------------------------------------------------
BDA_DSEG SEGMENT PARA COMMON 'DATA'
BDA_DSEG ENDS
EBDA_DSEG SEGMENT PARA COMMON 'DATA'
EBDA_DSEG ENDS
USB_DSEG SEGMENT WORD PUBLIC 'DATA'
USB_DSEG ENDS
;----------------------------------------------------------------------------
; I N T 1 3 P O S T C O D E S E G M E N T
;----------------------------------------------------------------------------
I13P_CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:I13P_CSEG
.586p
PUBLIC _USBI13_ASM_I13P_START
_USBI13_ASM_I13P_START LABEL BYTE
;---------------------------------------------------------------;
; USB BBS related calls
;---------------------------------------------------------------;
IF (MKF_USB_VERBOSE_MODE GT 0)
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure: DisplayString
;
; Description: This routine displays the given null terminated string
;
; Input: ES:DI Pointer to the string.
; CX Number of characters (Max) to display
;
; Output: None.
;
; Modified: None.
;
; Referrals: DisplayChar_FAR.
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
DisplayString PROC NEAR
push ax
push di
DS_NextByte:
or cx, cx
jz DS_Exit
mov al, BYTE PTR ES:[di]
or al, al
jz DS_Exit
call DisplayChar_FAR
inc di
loop SHORT DS_NextByte
DS_Exit:
pop di
pop ax
ret
DisplayString ENDP
ENDIF
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: StuffUSBHeaders
;
; Description: This routine populates the expansion header for each
; USB drive with valid data as would a regular scsi option rom.
;
; Input: DS PnP_ATA_Data Segment
; BX Pointer to next header field of previous valid
; header
;
; Output: BX Pointer to NextHeader field that mush be filled by
; subsequent routines that will build headers for
; other drives
;
; Modified: Only the registers which needs to return value are modified
; rest restored
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
StuffUSBHeaders PROC FAR PUBLIC
push ax
push cx
push dx
push esi
push di
; Get pointer to the first USB header
mov di, OFFSET PnP_ATA_Data.USBheaders
; Check for valid USB header structure count
mov cx, USB_Header_count
or cx, cx
jz SUH_Exit
; Check the setup options for USB mass storage support
mov ax, Q_USB_LEGACY_ENABLE
call check_cmos_data_far
jz SUH_Exit
mov ax, Q_USB_LEGACY_STORAGE
call check_cmos_data_far
jz SUH_Exit
IF (MKF_USB_VERBOSE_MODE GT 0)
push bx
mov bx, _str$_USB_STOR_AUTO_DET
call display_token_message_FAR
call display_0d0a_FAR
pop bx
ENDIF
xor cx, cx
; CL - index of the following loop. Starts with 0
; CH - Number of usb mass device found
inc ch ; 1-based
SUH_GetNextUSBDrive:
mov si, di
; Get pointer to the headers BCV
add si, OFFSET FDDUSB_Exp_Header.movIMMjmpf
; Get pointer to the headers BEV
xor bp, bp
; Get the USB drive information
;-----------------------------------------------
; CL - USB device address of current mass device
; (0 or 0FFh if this is the first call)
; CH - USB mass device count
; DI - Pointer to the current USB expansion header
call USBMassGetDeviceInformation
; CL - USB mass device address
; CH - USB mass device count
; DH - Device type
; DL - USB INT13h handler target DL value
; CY - Set on error
jc SUH_EndDeviceScan ; No more USB drives present
cmp dh, BAID_TYPE_CDROM ; if a CD, we need a BEV
jnz stuff_usb ;
mov bp, OFFSET I13R_CSEG:CDR_BEV
xor si, si ; NOT a BCV
stuff_usb:
mov ds:(FDDUSB_Exp_Header PTR [di]).HanDLe, dl ; target DL
mov ds:(FDDUSB_Exp_Header PTR [di]).DevType, dh ; devtype
mov ds:(FDDUSB_Exp_Header PTR [di]).BCV, si ; BCV
mov ds:(FDDUSB_Exp_Header PTR [di]).BEV, bp ; BEV
mov ds:(FDDUSB_Exp_Header PTR [di]).HeaderPtr, di ; immediate
; value for
; mov di, imm
mov ds:(FDDUSB_Exp_Header PTR [di]).SysType, 1 ; 0/1 = legacy/usb
mov si, OFFSET I13P_CSEG:i13_BCV
rol esi, 16
push cs
pop si
rol esi, 16
mov ds:(FDDUSB_Exp_Header PTR [di]).i13BCVabs, esi ; imm value for
; for far jmp of
; this BCV
mov WORD PTR ds:[bx], di ; stuff previous header's next hdr
mov bx, di
add bx, OFFSET FDDUSB_Exp_Header.NextPtr ; set bx for next next header
add di, SIZE FDDUSB_Exp_Header
inc ch
test cl, 80h
jnz SUH_EndDeviceScan ; That was the last device
cmp ch, USB_Header_count
jb SUH_GetNextUSBDrive ; We have one more structure
SUH_EndDeviceScan:
IF (MKF_USB_VERBOSE_MODE GT 0)
push bx
mov al, ch
dec al
call display_al_hex_FAR
mov bx, _str$_USB_STOR_AUTO_DET_DONE
call display_token_message_FAR
call display_0d0a_FAR
pop bx
ENDIF
SUH_Exit:
pop di
pop esi
pop dx
pop cx
pop ax
ret
StuffUSBHeaders ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMassGetDeviceInformation
;
; Description: This function returns the USB mass device information
; according to the input provided
;
; Input: CL USB device address of current mass device
; (0FFh if this is the first call)
; CH USB mass device count (1 based)
; DI Pointer to the current USB expansion header
;
; Output: CL Current USB mass device address
; CH USB mass device count
; DH Device type
; DL USB INT13h handler target DL value
; CY Set on error
;
; Modified: DX, CX
;
; Notes: Initially the CL should be set to 0FFh as input. This
; function returns the information regarding the first mass
; storage device (if no device found it returns Bit7 of CL
; as one) indicating current information is valid but no more
; mass device found in the system. The caller can get the next
; device info if Bit7 of CL is not set
;
; Referrals: URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBI13Spaces BYTE 25 dup (' ')
BYTE 0
UsbMassGetDeviceInformation PROC NEAR PUBLIC
LOCAL stURP:URP_STRUC, bIteration:BYTE
push eax
push bx
push esi
push di
push es
push ds
push ds
pop es
IF (MKF_USB_VERBOSE_MODE GT 0)
push bx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -