This is some very basic code, to run on DexOS.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Project : DexOS ;;
;; Ver : 00.01 ;;
;; Author : Dex ;;
;; ; From info at http://www.frontiernet.net/~fys/newbasic.htm ;;
;; Website : www.dex4u.com ;;
;; Forum : http://jas2o.forthworks.com/dexforum/ ;;
;; wiki : http://tonymac.asmhackers.net/Wiki/pmwiki.php ;;
;; Date : October 10, 2006 ;;
;; Filename : USB.ASM ;;
;; Assembler Command: FASM usb.asm usb.dex ;;
;; Copy Right Owners: Team DexOS (c)2002-2008 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Team DexOS : 0x4e71, bubach, crc, Dex, hidnplayr, jas2o, roboman ;;
;; : Solidus, smiddy, tony(mac), viki. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Disclaimer : ;;
;; This software is provided "AS IS" without warranty of any kind, either ;;
;; expressed or implied, including, but not limited to, the implied ;;
;; warranties of merchantability and fitness for a particular purpose. The ;;
;; entire risk as to the quality and performance of this software is with ;;
;; you. ;;
;; In no event will the author's, distributor or any other party be liable to ;;
;; you for damages, including any general, special, incidental or ;;
;; consequential damages arising out of the use, misuse or inability to use ;;
;; this software (including but not limited to loss of data or losses ;;
;; sustained by you or third parties or a failure of this software to operate ;;
;; with any other software), even if such party has been advised of the ;;
;; possibility of such damages. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use32
ORG 0x400000 ; where our program is loaded to
jmp start ; jump to the start of program.
db 'DEX2' ; We check for this, to make shore it a valid Dex4u file.
;----------------------------------------------------;
; Start of program. ;
;----------------------------------------------------;
start: ;
mov ax,18h ; set ax to nonlinear base
mov ds,ax ; add them to ds
mov es,ax ; and es.
;----------------------------------------------------;
; Get calltable address. ;
;----------------------------------------------------;
mov edi,Functions ; this is the interrupt
mov al,0 ; we use to load the DexFunction.inc
mov ah,0x0a ; with the address to dex4u functions.
int 40h ;
;----------------------------------------------------;
; Get base add on. ;
;----------------------------------------------------;
call [GetBaseAddOn] ;
mov dword[BaseAddOn],eax ;
mov [UHCIframes1],0xd00000
sub [UHCIframes1],eax
;----------------------------------------------------;
; Print detect string. ;
;----------------------------------------------------;
mov esi,DetectS ; this point's to our string.
call [PrintString] ; this call the print function.
call [DetectPciBus] ;
jnc FoundPCI ;
mov esi,PCIBoisNS ; not found, so post
call [PrintString] ; this call the print function.
jmp usb_done ; And exit
;----------------------------------------------------;
; Found PCI BIOS ;
;----------------------------------------------------;
FoundPCI: ;
mov esi,PCIBoisFS ; found it, cont.
call [PrintString] ; this call the print function.
;----------------------------------------------------;
; Find USB devices ;
;----------------------------------------------------;
mov word[index],00h ; start with 0
FindUSBL: ;
call FindUSB ;
or ah,ah ; if ah = !0, then no more
jnz justatest ; usb_done
mov eax,[EbxsSave] ;
add eax,40h
mov edx,0x00051000
call [PciRegWrite32]
mov eax,[EbxsSave] ;
add eax,44h
mov edx,0x24220002
call [PciRegWrite32]
;----------------------------------------------------;
; Try to enable current PCI port found ;
;----------------------------------------------------;
mov esi,EnableS ;
call [PrintString] ; this call the print function.
call pci_enable ; enable PCI->USB port
jnc pci_enable_good ;
mov esi,e_bad_s ; print bad_enable string
call [PrintString] ; this call the print function.
jmp usb_done ; and exit to DexOS
pci_enable_good: ;
mov esi,e_good_s ;
call [PrintString] ; this call the print function.
;----------------------------------------------------;
; Allocate Frame List Buffer ;
;----------------------------------------------------;
xor edx,edx
mov dx,[IOAddr] ; dx -> IOaddr space
call alloc_f_list ;
; jnc frame_ok ;
; mov esi,no_memory_s ;
; call [PrintString] ; this call the print function.
jmp usb_get_next ;
frame_ok:
jmp justatest
;----------------------------------------------------;
; Try to enable all USB ports on current hub ;
;----------------------------------------------------;
; mov dx,[IOAddr] ; dx -> IOaddr space
; call usb_enable ; enable USB ports
usb_get_next:
;-------------------------------------------
mov esi,nextline ;
call [PrintString] ; this call the print function.
inc [index] ;
cmp [index],256 ;
jb FindUSBL ;
usb_done: ;
call [WaitForKeyPress]
mov esi,nextline ;
call [PrintString] ; this call the print function.
ret
;-------temp
justatest:
call [GetTextPos]
mov [SaveXY],ax
call [SetCursorPos]
mov esi,UsbNo
call [PrintString] ; this call the print function.
loop1:
mov dx,[IOAddr]
add dl,10h ; Port 1 status
jmp @f
.loop:
mov [yesNo],0
@@:
in ax,dx ; Read port
bt eax,7 ; Port present?
jnc .endirq
lea edx,[edx+2] ; Next port
bt eax,0
jnc .loop
mov [yesNo],1
.endirq:
cmp [yesNo],bl
je NoChange
cmp [yesNo],1
je YES
NO:
mov bl,[yesNo]
mov ax,[SaveXY]
call [SetCursorPos]
mov esi,UsbNo
call [PrintString] ; this call the print function.
call Beep2
jmp NoChange
;;;;
YES:
mov bl,[yesNo]
mov ax,[SaveXY]
call [SetCursorPos]
mov esi,UsbYes
call [PrintString] ; this call the print function.
call Beep1
;;;;
NoChange:
call [KeyPressedNoWait]
cmp al,0
je loop1
;;;;;;
; mov edi,[UHCIframes1]
; add edi,64h
; mov byte[es:edi],0
; mov esi,[UHCIframes1]
; call [PrintString]
;;;;;;
mov esi,nextline ;
call [PrintString] ; this call the print function.
ret
;-------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; on entry
; dx = io space start (base)
; on exit
; carry = status
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alloc_f_list: ;
pushad ;
mov edi,UHCIframes ;
mov eax,UHCIframes ;
add eax,dword[BaseAddOn] ;
mov eax,0xd00000 ;
mov edi,[UHCIframes1] ;
push eax ;
mov al, 1 ; write 1's (terminate)
mov ecx,1024*4 ; 1024 bytes
rep ;
stosb ;
;----------------------------------------------------;
; Global reset ;
;----------------------------------------------------;
mov ax,4 ; Stop HC and reset
out dx,ax ;
mov ax,2 ; Global reset must be kept for 10ms at least
call [SetDelay] ;
xor eax,eax ; End global reset
out dx,ax ;
mov ax,2 ;
call [SetDelay] ;
.wait: ;
in eax,dx ; Read Command/Status
bt eax,10101b ;5+16 ; test HChalted bit
jnc .wait ;
mov ax,2 ;
out dx,ax ; Reset host controller
.wait2: ;
in ax,dx ;
bt eax,1 ;
jc .wait2 ;
;--------------------
;;;
xor eax,eax
mov dx,[IOAddr] ; dx -> IOaddr space
add dx,04 ; dx = io space from caller
out dx,ax
;;;
pop eax ; restore physical address
mov dx,[IOAddr] ; dx -> IOaddr space
add dx,08 ; dx = io space from caller
out dx,eax ; store it
dec dx ; make dx = 06h
dec dx ;
xor ax,ax ; write a zero
out dx,ax ; to frame number register
;;;;;;;;;
; mov dx,[IOAddr] ; dx -> IOaddr space
; call usb_enable
;;;;;;;;;
;-------
; mov dx,[IOAddr] ; dx -> IOaddr space
; mov ax,0081h ; MaxPacket=64,Run
; out dx,ax ; Execute schedule
;-------
popad ;
clc ; frame is set okay
ret ;
alloc_f_err: ;
popad ;
stc ;
ret ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Enable the PCI->USB hardware
; on entry
; nothing
; on exit
; carry = status
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pci_enable: ;
mov eax,[EbxsSave] ;
add eax,4 ; read word at 0004h (command reg)
call [PciRegRead16] ; read it (returns in DX)
jc no_enable ;
push dx ; save it
and dx,0000000101b ; bus master enable/io access enable
cmp dx,0000000101b ; are they both already set?
pop dx ; restore ax
je good_enable ; yes, so don't toggle them
or dx,0000000101b ; no, so set bits 0 and 2, then
mov eax,[EbxsSave] ;
add eax,4 ; Write word at 0004h (command reg)
call [PciRegWrite16] ; write it
jc no_enable ;
;;; ??? do we need to check to see if enabled as wanted;;;
good_enable: ;
clc ; else, good enable
ret ;
no_enable:
stc ; enable failed
ret ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
; NAME: FindPciClass
;
; DESCRIPTION: Write a 32-bit register
;
; PARAMETERS: BH Class
; BL Sub class
; CH Interface
; AX Device number
;
; RETURNS: NC Success
; BH Bus
; BL Device
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FindPciClass: ; uses ebx ecx
push eax ;
push edx ;
push esi ;
mov esi,eax ;
movzx eax,bx ;
shl eax,16 ;
mov ah,ch ;
mov ebx,eax ;
mov ecx,80000008h ;
FindPciClassLoop: ;
mov eax,ecx ;
cli ;
mov dx,0CF8h ;
out dx,eax ; send our request out
mov dx,0CFCh ;
in eax,dx ; read back 32bit value.
sti ;
xor al,al ;
cmp eax,ebx ;
jne FindPciClassNext ;
or esi,esi ;
jz FindPciClassOk ;
sub esi,1 ;
FindPciClassNext: ;
add ecx,100h ;
cmp ecx,81000008h ;
jne FindPciClassLoop ;
stc ;
jmp FindPciClassDone ;
FindPciClassOk: ;
pushf ;
xor ecx,80000000h ;
mov ebx,ecx ;
popf ;
shr ecx,8 ;
clc ;
;
FindPciClassDone: ;
pop esi ;
pop edx ;
pop eax ;
ret ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; finds a USB card/hub on given PCI index
; on entry:
; dev_index = index
; on exit:
; ah = 00h if card found
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FindUSB: ; uses ebx ecx edx esi edi
mov bh,0x0c ; (USB = base=C, sub=3)
mov bl,0x03 ;
mov ch,00 ;
xor eax,eax ;
mov ax,word[index] ; Move index into ax
call FindPciClass ;
jnc UFoundOne ; on return: bh = bus
mov ah,01 ; bl = dev num/func num
ret ;
;----------------------------------------------------;
; print found USB controller. ;
;----------------------------------------------------;
UFoundOne:
mov esi,FoundUSBTS ; print found USB controller
call [PrintString] ; this call the print function.
mov [bus_num],ch ; save bus/dev/function
mov [dev_func],cl ;
shr bl,4 ;
mov dword[EbxsSave],ebx ;
mov eax,[EbxsSave] ; read word at 0000h (Vendor ID)
call [PciRegRead16] ; read it (returns in DX)
mov word[VendorID],dx ; save it
mov ax,dx ;
call HexToAscii ;
mov dword[VendorASCIIid],eax ;
mov eax,[EbxsSave] ;
add eax,2 ; read word at 0002h (Device ID)
call [PciRegRead16] ; read it (returns in DX)
mov word[DeviceID],dx ; save it
mov ax,dx ;
call HexToAscii ;
mov dword[DeviceASCIIid],eax ;
call dev_names ; get vendor and device names
mov esi,VendorIDS ;
call [PrintString] ; this call the print function.
mov ax,[VendorID] ;
call [WriteHex16] ; print VendorID
mov esi,Vendor_N ; print vendor name
call [PrintString] ; this call the print function.
mov esi,DeviceIDS ; print device type
call [PrintString] ; this call the print function.
mov ax,[DeviceID] ;
call [WriteHex16] ; print VendorID
mov esi,Device_N ; print device name
call [PrintString] ; this call the print function.
mov esi,BusNumberS ;
call [PrintString] ; this call the print function.
mov al,[bus_num] ; bh = Bus Number
xor ah,ah ;
call [WriteHex16] ; print Bus Number
mov al,'/' ; print a slash
call [PrintChar] ;
mov al,[dev_func] ; bl = Dev Number
shr al,03 ; (bits 7-3)
xor ah,ah ;
call [WriteHex16] ; print Dev Number
mov al,'/' ; print a slash
call [PrintChar] ;
mov al,[dev_func] ; bl = Func Number
and al,00000111b ; (bits 2-0)
xor ah,ah ;
call [WriteHex16] ; print Func Number
mov esi,CommandRS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,4 ; read word at 0004h (Command Reg)
call [PciRegRead16] ; read it (returns in DX)
mov ax,dx ;
call [WriteHex16] ;
mov esi,StatusRS
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,06h ; read word at 0006h (Status Reg)
call [PciRegRead16] ; read it (returns in DX)
mov ax,dx ;
call [WriteHex16] ;
mov esi,RevisionS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,08h ; read byte at 0008h (Revision Byte)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,ClassCodeS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,0Bh ; read byte at 000Bh (Class)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov al,'/' ; print a slash
call [PrintChar] ;
mov eax,[EbxsSave] ;
mov al,0Ah ; read byte at 000Ah (Sub Class)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov al,'/' ; print a slash
call [PrintChar] ;
mov eax,[EbxsSave] ;
mov al,09h ; read byte at 0009h (Program Inter.)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,CacheS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,0Ch ; read byte at 000Ch (Cache Line Size)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,BusLatS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,0Dh ; read byte at 000Dh (Bus Latency)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,HeaderS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,0Eh ; read byte at 000Eh (Header Type)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,SelfTestS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,0Fh ; read byte at 000Fh (Self Test)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,IOPortsS ;
call [PrintString] ; this call the print function.
; don't do high word???
;mov eax,[EbxsSave] ;
;mov al,22h ; read word at 0022h (base address 4)
;call [PciRegRead16] ; read it (returns in DX)
;mov ax,dx ;
;call [WriteHex16] ;
mov eax,[EbxsSave] ;
mov al,20h ; read word at 0020h (base address 4)
call [PciRegRead16] ; read it (returns in DX)
and dx,0FFFEh ; clear bit 0 ???
mov [IOAddr],dx ; save if for testing the devices
mov ax,dx ;
call [WriteHex16] ;
push ax ; save address space start
mov al,'-' ;
call [PrintChar] ;
pop ax ;
add ax,31 ; print address space end
call [WriteHex16] ;
mov esi,IRQNumS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,3Ch ; read byte at 000Fh (IRQ #)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
call [WriteHex8] ;
mov esi,IntNumS ;
call [PrintString] ; this call the print function.
mov eax,[EbxsSave] ;
mov al,3Dh ; read byte at 000Fh (INT #)
call [PciRegRead8] ; read it (returns in DL)
mov al,dl ;
add al,09h ; (A-D)
call [WriteHex8] ;
mov ah,00 ; found one, continue
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; opens 'devnums.bin' and finds a line starting with 'V xxxx'
; where xxxx = VendorID.
; once found, copys the string found after 'V xxxx ' to Vendor_N+3
; then continues to find 'D xxxx ' where xxxx = DeviceID.
; if 'V xxxx' found before device number is found, then error.
; if number is found, then copies to Device_N+3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dev_names: ; uses all es
pushad ;
mov [BFPointer],buffer ;
CommandsLoop: ;
mov esi,[BFPointer] ;
cmp byte[esi],13 ; check for a ret
jne No_Ret ;
inc esi ; inc past
mov [BFPointer],esi ;
jmp CommandsLoop ; in case of more then one
No_Ret: ;
cmp byte[esi],10 ; check for line feed
jne Commands ;
inc esi ; inc past
mov [BFPointer],esi ;
jmp CommandsLoop ; in case of more then one
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Commands. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Commands: ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test for 'END' ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov esi,[BFPointer] ; Check for 'end'
mov ecx,3 ; Number of letters to check
mov edi,cEND1 ;
repe cmpsb ;
je dev_names_d ; it's a match / jump to exit
mov esi,[BFPointer] ; Check for 'END'
mov ecx,3 ;
mov edi,cEND ;
repe cmpsb ;
je dev_names_d ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test for 'DEVICE' ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov esi,[BFPointer] ; Check for 'DEVICE'
mov ecx,6 ;
mov edi,cDEVICE ; LOAD
repe cmpsb ;
je ItIsDEVICE ;
mov esi,[BFPointer] ; Check for 'LOAD'
mov ecx,6 ;
mov edi,cDEVICE1 ;
repe cmpsb ;
je ItIsDEVICE ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test for 'VENDOR' ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov esi,[BFPointer] ; Check for 'load'
mov ecx,6 ;
mov edi,cVENDOR ;
repe cmpsb ;
je ItIsVENDOR ;
mov esi,[BFPointer] ; Check for 'LOAD'
mov ecx,6 ;
mov edi,cVENDOR1 ;
repe cmpsb ;
je ItIsVENDOR ;
jmp dev_names_d ;
ItIsVENDOR: ;
mov esi,[BFPointer] ;
add esi,7 ;
mov eax,dword[ds:esi] ;
cmp eax,[VendorASCIIid] ;
je VendorFound ;
ItIsDEVICE: ;
mov esi,[BFPointer] ;
add esi,7 ;
mov eax,dword[ds:esi] ;
cmp eax,[DeviceASCIIid] ;
je DeviceFound ;
NoDeviceFound: ;
add esi,4 ;
mov ecx,52 ;
DeviceFoundLoop1: ;
lodsb ;
cmp al,13 ;
je DeviceFoundExit ;
cmp al,10 ;
je DeviceFoundExit ;
loop DeviceFoundLoop1 ;
jmp dev_names_d ;
VendorFound: ;
mov edi,Vendor_N1 ;
jmp VendorFound1 ;
DeviceFound: ;
mov edi,Device_N1 ;
VendorFound1: ;
add esi,4 ;
mov ecx,52 ;
DeviceFoundLoop: ;
lodsb ;
cmp al,13 ;
je DeviceFoundExit ;
cmp al,10 ;
je DeviceFoundExit ;
stosb ;
loop DeviceFoundLoop ;
jmp dev_names_d ;
DeviceFoundExit: ;
inc esi ; inc pointer
mov [BFPointer],esi ;
DeviceFoundExit1: ;
mov esi,[BFPointer] ;
cmp byte[esi],13 ; check for a ret
jne No_Ret1 ;
inc esi ; inc pointer
mov [BFPointer],esi ;
jmp DeviceFoundExit1 ; in case of more then one
No_Ret1: ;
cmp byte[esi],10 ; check for line feed
jne Commands ;
inc esi ; inc past
mov [BFPointer],esi ;
jmp DeviceFoundExit1 ; in case of more then one
dev_names_d: ;
popad ;
ret ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Enable the current USB port
; on entry
; dx = io space start (base)
; on exit
; carry = status
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
usb_enable: ;
call get_port_zero ; returns bits in ax
mov bx,ax ;
and bx,0001000000000100b ;
cmp bx,0001000000000100b ;
je usb_e_zero ;
or ax,0001000000000100b ;
call put_port_zero ; write ax to port_zero status
usb_e_zero:
call get_port_one ; returns bits in ax
mov bx,ax ;
and bx,0001000000000100b ;
cmp bx,0001000000000100b ;
je usb_e_one ;
or ax,0001000000000100b ;
call put_port_one ; write ax to port_one status
usb_e_one:
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; on entry
; dx = io starting address (base)
; on exit
; ax = port 1 (of 2) status/control register contents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_port_zero: ;
add dx,10h ; USB port 1 register (base+10h)
in ax,dx ; word sized
and ax,0001111111111111b ; bits 15-13 reserved
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; on entry
; dx = io starting address (base)
; ax = port 1 (of 2) status/control register contents
; on exit
; ax = port 1 (of 2) status/control register contents after write
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
put_port_zero: ;
add dx,10h ; USB port 1 register (base+10h)
and ax,0001111111111111b ; bits 15-13 reserved
out dx,ax ; put it
mov ax,2 ; Global reset must be kept for 10ms at least
call [SetDelay] ;
in ax,dx ; word sized
and ax,0001111111111111b ; bits 15-13 reserved
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; on entry
; dx = io starting address (base)
; on exit
; ax = port 2 (of 2) status/control register contents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_port_one: ;
add dx,12h ; USB port 2 register (base+12h)
in ax,dx ; word sized
and ax,0001111111111111b ; bits 15-13 reserved
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; on entry
; dx = io starting address (base)
; ax = port 2 (of 2) status/control register contents
; on exit
; ax = port 2 (of 2) status/control register contents after write
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
put_port_one:
add dx,12h ; USB port 2 register (base+12h)
and ax,0001111111111111b ; bits 15-13 reserved
out dx,ax ; put it
mov ax,2 ; Global reset must be kept for 10ms at least
call [SetDelay] ;
in ax,dx ; word sized
and ax,0001111111111111b ; bits 15-13 reserved
ret
;--------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HexToAscii16 ; convert word hex, to ascii hex
;
; Input:
; hex_val
;
; Output:
; inbuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
HexToAscii: ;
push esi ;
push ecx ;
push ebx ;
mov word[hex_val],ax ;
HexToAsciiHex32: ;
mov ecx,4 ;
mov bx,[hex_val] ;
mov esi,inbuff ;
loop_digit: ;
rol bx,4 ;
mov al,bl ;
and al,0Fh ;
add al,90h ;
daa ;
adc al,40h ;
daa ;
mov byte[esi],al ;
inc esi ;
dec ecx ;
jnz loop_digit ;
;----------------------------------------------------;
; terminator ;
;----------------------------------------------------;
mov esi,inbuff ;
mov eax,[esi] ;
pop ebx ;
pop ecx ;
pop esi ;
ret ;
;----------------------------------------------------;
; Beep ;
;----------------------------------------------------;
Beep1: ;
pushad ;
mov [Hz],0x200 ;
call Sound ;
mov ax,5 ;
call [SetDelay] ;
call NoSound ;
popad ;
ret ;
Beep2: ;
pushad ;
mov [Hz],0x100 ;
call Sound ;
mov ax,5 ;
call [SetDelay] ;
call NoSound ;
popad ;
ret ;
;----------------------------------------------------;
; Sound ;
;----------------------------------------------------;
Sound: ;
mov bx,[Hz] ;
mov ax,0x34dd ;
mov dx,0x0012 ;
cmp dx,bx ;
jnc Done1 ;
div bx ;
mov bx,ax ;
in al,0x61 ;
test al,3 ;
jnz A99 ;
or al,3 ;
out 0x61,al ;
mov al,0xb6 ;
out 0x43,al ;
A99: ;
mov al,bl ;
out 0x42,al ;
mov al,bh ;
out 0x42,al ;
Done1: ;
ret ;
;----------------------------------------------------;
; NoSound ;
;----------------------------------------------------;
NoSound: ;
in al,0x61 ;
and al,11111100b ;
out 0x61,al ;
ret ;
;----------------------------------------------------;
; Data. ;
;----------------------------------------------------;
;---------------;
; Commands. ;
;---------------;
cDEVICE db 'DEVICE ',0
cDEVICE1 db 'device ',0
cVENDOR db 'VENDOR ',0
cVENDOR1 db 'vendor ',0
cEND db 'END ',0
cEND1 db 'end ',0
Hz dw 0
yesNo db 0
SaveXY dw 0
UHCIframes1 dd 0
BaseAddOn dd 0
inbuff dd 0
hex_val dw 0
DeviceASCIIid dd 0
VendorASCIIid dd 0
BFPointer dd 0
VendorID dw 0
DeviceID dw 0
bus_num db 0
dev_func db 0
EbxsSave dd 0
index dw 0
UsbYes db 13,13,'USB Device Pluged in. ',0
UsbNo db 13,13,'No USB Device Pluged in.',0
e_good_s db 'Successful.',0
e_bad_s db 'Error!',0
no_memory_s db 13,'Out of memory',0
DetectS: db 13,'Detecting PCI BIOS ... ',0
EnableS: db 13,13,'Enabling PCI bus...',0
PCIBoisFS: db ' found. ',0
PCIBoisNS: db ' NOT found!',13,0
FoundUSBTS: db 13,13,'Found USB Controller: ',0
VendorIDS: db 13,' Vendor ID: ',0
DeviceIDS: db 13,' Device ID: ',0
BusNumberS: db 13,' Bus #/Dev #/Func #: ',0
CommandRS: db 13,' Command Register: ',0
StatusRS: db 13,' Status Register: ',0
RevisionS: db 13,' Revision Code: ',0
ClassCodeS: db 13,' Class/Sub/Interface: ',0
CacheS: db 13,' Cache Line Size: ',0
BusLatS: db 13,' Bus Latency: ',0
HeaderS: db 13,' Header Type: ',0
SelfTestS: db 13,' Self Test Byte: ',0
IOPortsS: db 13,' Address Space: ',0
IRQNumS: db 13,' IRQ Number: ',0
IntNumS: db 13,' INT Number: ',0
Vendor_N: db ' - '
Vendor_N1: times 52 db ' '
Vendor_N2: db ' ',0
Device_N: db ' - '
Device_N1: times 52 db ' '
Device_N2: db ' ', 0
nextline: db ' ',13,0
IOAddr dw ? ; Address space of port (32 bytes)
buffer:
file 'VendorID.txt'
include 'Dex.inc' ; Here is where we includ our "DexFunctions.inc" file
UHCIframes rb 1024
You will also need these.