OS -->USB ?
Re: OS -->USB ?
yep , that made since to me.
How ever is their any examples of doing the host controller (ie, OHCI and UHCI) stuff.
I am find this a little confusing what to write to and where?
After that I would think the mass storage spec would just be send a certain packet to the
host controller which sends it to the usb device. And the usb device recoginze a read / write by the packet it is sent. The mass storage spec's should have a diagram of what a packet for reading/writing should look like ...etc etc
How ever is their any examples of doing the host controller (ie, OHCI and UHCI) stuff.
I am find this a little confusing what to write to and where?
After that I would think the mass storage spec would just be send a certain packet to the
host controller which sends it to the usb device. And the usb device recoginze a read / write by the packet it is sent. The mass storage spec's should have a diagram of what a packet for reading/writing should look like ...etc etc
-
- Member
- Posts: 116
- Joined: Wed Oct 22, 2008 2:21 am
- Location: Roma,Italy
Re: OS -->USB ?
Ciao,
it seems that you did not want to seek, request the code without understanding it is not good, even for me it was hard
to understand USB, then after having studied and tested for a month has become more user friendly and fun 
it seems that you did not want to seek, request the code without understanding it is not good, even for me it was hard


Re: OS -->USB ?
This is some very basic code, to run on DexOS.
You will also need these.
PS: rename Dex.asm to Dex.inc
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
PS: rename Dex.asm to Dex.inc
- Attachments
-
- VendorID.txt
- (1.38 KiB) Downloaded 268 times
-
- Dex.asm
- (20.07 KiB) Downloaded 257 times
Re: OS -->USB ?
Thanks for the help. It will take me along time. To understand it.
But My main question is how do you test things like this.
Bochs , If you are how do you test these thing like in/out port stuff to see if it is working correctly. (without having to blindly write the whole thing and pray that it works or you can find the bug.) Basically can I test my in/out port read/writes under a windows os and then when I know their working move them to my kernal.
I am thinking about using inline asm in a c file to test if it is working under windows. But I am afraid that windows will restrict me from doing something.
Do you guys have any suggestions about the easiest way to test your device driver programs (in/out port commands ) without having to keep updating the kernel and runing bochs each time.
Bochs worked great for learning bootloader and GDT LDT pmode ,..etc
But I havn't found an easy way to test in/out commands.
What would be nice is if I could just have a c file that I use inline asm to test the in/out commands are working. However I am afraid that if I am under an os while testing the in/out commands their may be restriction setup by the os I am under thus preventing me from getting the whole picture.
But My main question is how do you test things like this.
Bochs , If you are how do you test these thing like in/out port stuff to see if it is working correctly. (without having to blindly write the whole thing and pray that it works or you can find the bug.) Basically can I test my in/out port read/writes under a windows os and then when I know their working move them to my kernal.
I am thinking about using inline asm in a c file to test if it is working under windows. But I am afraid that windows will restrict me from doing something.
Do you guys have any suggestions about the easiest way to test your device driver programs (in/out port commands ) without having to keep updating the kernel and runing bochs each time.
Bochs worked great for learning bootloader and GDT LDT pmode ,..etc
But I havn't found an easy way to test in/out commands.
What would be nice is if I could just have a c file that I use inline asm to test the in/out commands are working. However I am afraid that if I am under an os while testing the in/out commands their may be restriction setup by the os I am under thus preventing me from getting the whole picture.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: OS -->USB ?
Welcome to the real world of OS development, I hope you enjoy the challenge 
Seriously, it is a better idea to find a good way to test applications under your own OS. No real OS in its right mind would let you access I/O ports directly. And even if you could it would cause more trouble than its worth.

Seriously, it is a better idea to find a good way to test applications under your own OS. No real OS in its right mind would let you access I/O ports directly. And even if you could it would cause more trouble than its worth.
Re: OS -->USB ?
Ok so if I get this straight the only way to test a device driver (in/out port commands ) for devices like usb , cdrom ,...etc etc.
Is to create a interrupt function for the device in your kernel code
And in the interrupt function do the in/out testing port stuff.
Use bochs and grub to test the kernel with the new int function created.
If something goes wrong change/fix the kernel function recompile/relink the files.
Then use bochs and grub repeat until you final get it.
Also each time you have to remake the img file with the new compiled kernel on it for bochs. Gee
But if that's the only way to test so be it thanks.
Is to create a interrupt function for the device in your kernel code
And in the interrupt function do the in/out testing port stuff.
Use bochs and grub to test the kernel with the new int function created.
If something goes wrong change/fix the kernel function recompile/relink the files.
Then use bochs and grub repeat until you final get it.
Also each time you have to remake the img file with the new compiled kernel on it for bochs. Gee
But if that's the only way to test so be it thanks.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: OS -->USB ?
I don't know about anybody else, but I have to do that every time I test - which can be as many times as once a minute. I just have a Makefile which builds the images and things for me so I just run "make all", "make install", and finally "make test".Then use bochs and grub repeat until you final get it.
Also each time you have to remake the img file with the new compiled kernel on it for bochs.
I am also working to move it all into one big makefile which can also build my ramfs image, compile drivers, and compile the testsuite of applications to run under my OS.
Also,
You need to get out of this concept of "Creating interrupt functions". In protected mode your device driver generally doesn't provide an interrupt interface (because interrupts can be quite slow in some circumstances), but some other method to provide the functionality it needs. It may receive interrupts (ie, IRQs) though.Is to create a interrupt function for the device in your kernel code
Re: OS -->USB ?
Not sure if you got docs you need but having direct links will not hurt:
UHCI: http://developer.intel.com/technology/usb/uhci11d.htm
EHCI: http://www.intel.com/technology/usb/ehcispec.htm
1394 OHCI: http://storm.net.nz/static/files/ohci_11.pdf
USB OHCI ftp://ftp.compaq.com/pub/supportinforma ... ir1_0a.pdf
usb.org - it only has description of logic how usb works but you'll need it, and I think you have it already
here is some of my old code that I was able to find, it might help you to start:
EHCI
UHCI
UHCI: http://developer.intel.com/technology/usb/uhci11d.htm
EHCI: http://www.intel.com/technology/usb/ehcispec.htm
1394 OHCI: http://storm.net.nz/static/files/ohci_11.pdf
USB OHCI ftp://ftp.compaq.com/pub/supportinforma ... ir1_0a.pdf
usb.org - it only has description of logic how usb works but you'll need it, and I think you have it already
here is some of my old code that I was able to find, it might help you to start:
EHCI
Code: Select all
mov rsi, [rax] ;rax is mem mapped addr of EHCI regs
mov rcx, rsi
mov rdx, rsi
shr rcx, 32 ;ecx = HCSPARAMS
and esi, 0ffh ;esi = CAPLENGTH, lowest byte
shr rdx, 32+12 ;edx = HCSPARAMS, bit 12 = bit 0 of ecx
and ecx, 1111b ;ecx = N_PORTS
add esi, eax ;esi = beginning of Operational Registers
and edx, 0fh ;edx = N_CC, Number of Companion Cntrl
Code: Select all
;input: EAX-USBBASE
;function determmines if a device present on any of the 2 ports
usbu_detect_dev:
;read status from PORTSCx (PORT Status Command)
lea edx, [rax+10h] ;EDX = PORTSC1
mov esi, .portsc2
xor eax, eax
in ax, dx
test al, 1 ;check Current Connect Status
jnz .connected ;should be 1 if port present & used
.portsc2:
add edx, 2 ;EDX = PORTSC2
mov esi, .ret
in ax, dx
test al, 1 ;check Current Connect Status
jz .ret ;2nd port also 0 - exit
.connected:
;you could setup interrupts here, maybe temporary
;wait for power to become stable
xor eax, eax
;set reset
or eax, (1 shl 9) ;set bit 9, Port Reset
out dx, ax
;keep reset signal for 50ms
;you need separate DELAY function called here
;clear reset
;-------------------
in ax, dx
and eax, not (1 shl 9)
out dx, ax
;-------------------
;delay for resetrecovery 10ms
;required only if data transfer done shortly after reset
;you need separate DELAY function called here
;enable USB port - bit 2
in ax, dx
or eax, (1 shl 2)
out dx, ax
.enable_port:
;wait for bit 2 to be enabled, 300ms timeout
;you need separate DELAY function called here
;after 300ms following code executed
xor eax, eax
in ax, dx
test al, (1 shl 2)
jz .enable_port
;clear bits 1 & 3 by writing 1
;-----------------------
in ax, dx
or eax, 1010b
out dx, ax
;-----------------------
jmp rsi
.ret:
ret
Last edited by geppy on Wed Nov 05, 2008 9:06 pm, edited 1 time in total.
-
- Posts: 11
- Joined: Sun Nov 02, 2008 9:27 pm
Re: OS -->USB ?
Rambly post deleted 
Summary:
I wish we'd had USB 20 years ago when I was writing my first proper code projects. Now there is a lot of catching up to do... I grok the mindset of the OP. There is a lot of info out there but the right guide can be elusive!
Eddy

Summary:
I wish we'd had USB 20 years ago when I was writing my first proper code projects. Now there is a lot of catching up to do... I grok the mindset of the OP. There is a lot of info out there but the right guide can be elusive!
Eddy
Re: OS -->USB ?
I know this is a little off the topic but I am working in visual studio's on my computer.
The skeleton files for some of the kernel will not compile. Mainly for 2 reason's
For example
is a GNU compiler specific setting
Do I really need this or can I take it out. Because when I take it out my error's drop from 7 to like 3. I think their is a pragma statment for packing in visual studio's 2005 but I don't want to use this stuff if I don't have to.
Does anybody know what this __attribute__((packed)) does I would think when you define a structure as above the varables are stored linearly right after one another kind of like an array.
Sorry for my ignorance about this.
My second error has to do with __asm__ __volatile__ this was working fine under gnu compiler's but now I have to find the equivalent to it in VS 2005.
I know I can use __asm { code ...} in VC but I am worried about the __ __volatile__ part.
Because I read that this prevents the compiler from trying to optimize it.
Don't know if their is an equivalent thing I can do or if I even need it?
I think their might be a switch to turn off compiler optimization though I don't know if this corrosponds to volatile.
Also My last few errors where intrinsic function, cannot be defined errors C2169
I get where it is coming from it is when I have functions defined like memcpy.
VS 2005 is getting screwed up from their memcpy and my memcpy I think this is the problem.
But I don't know how to resolve this one tried going into the property setting's and turning on
Enable Intrinsic Function doesn't work either way? I original setup an empty project and set to compile C in the project properties page. Then I started adding .c files to my source folder.
Normally I am working either with IDE Dev C++ mingw or gcc command line linux shell.
But I wanted to make everything work under visual studio's as I have alot of cool projects here .
The skeleton files for some of the kernel will not compile. Mainly for 2 reason's
For example
Code: Select all
struct gdt_entry
{
unsigned short limit_low;
unsigned short base_low;
unsigned char base_middle;
unsigned char access;
unsigned char granularity;
unsigned char base_high;
} __attribute__((packed));
Code: Select all
__attribute__((packed));
Do I really need this or can I take it out. Because when I take it out my error's drop from 7 to like 3. I think their is a pragma statment for packing in visual studio's 2005 but I don't want to use this stuff if I don't have to.
Does anybody know what this __attribute__((packed)) does I would think when you define a structure as above the varables are stored linearly right after one another kind of like an array.
Sorry for my ignorance about this.
My second error has to do with __asm__ __volatile__ this was working fine under gnu compiler's but now I have to find the equivalent to it in VS 2005.
I know I can use __asm { code ...} in VC but I am worried about the __ __volatile__ part.
Because I read that this prevents the compiler from trying to optimize it.
Don't know if their is an equivalent thing I can do or if I even need it?
I think their might be a switch to turn off compiler optimization though I don't know if this corrosponds to volatile.
Also My last few errors where intrinsic function, cannot be defined errors C2169
I get where it is coming from it is when I have functions defined like memcpy.
VS 2005 is getting screwed up from their memcpy and my memcpy I think this is the problem.
But I don't know how to resolve this one tried going into the property setting's and turning on
Enable Intrinsic Function doesn't work either way? I original setup an empty project and set to compile C in the project properties page. Then I started adding .c files to my source folder.
Normally I am working either with IDE Dev C++ mingw or gcc command line linux shell.
But I wanted to make everything work under visual studio's as I have alot of cool projects here .
Re: OS -->USB ?
For the msvc compilers, you need to useSam111 wrote:Does anybody know what this __attribute__((packed)) does I would think when you define a structure as above the varables are stored linearly right after one another kind of like an array.
Code: Select all
#pragma pack(push, 1)
typedef struct AlignedStruct
{
uint16 limit_low;
uint16 base_low;
uint8 base_middle;
// etc.
} AlignedStruct;
#pragma pack(pop)
I don't think there is an equivalent, but you can get around by using inline assembly. I would still recommend that all assembly code be in assembly files...Sam111 wrote: My second error has to do with __asm__ __volatile__ this was working fine under gnu compiler's but now I have to find the equivalent to it in VS 2005.
For some reason, under specific optimization options, msvc will replace copy loops with calls to memcpy, and try to link in one of its user-mode libraries - which is probably not what you want. You can force memcpy and memmove to always generate inline code bySam111 wrote: But I don't know how to resolve this one tried going into the property setting's and turning on
Enable Intrinsic Function doesn't work either way? I original setup an empty project and set to compile C in the project properties page. Then I started adding .c files to my source folder.
Code: Select all
extern "C" {
void memcpy(void* dest, const void* src, size_t length); // or similar
};
#pragma intrinsic(memcpy)
Re: OS -->USB ?
Ya , I agree but sometimes I have to do in/out asm commands in my c code for my device drivers. What I did is create a few functions that use the inline asm tags to do in/out asm command reads/writes.I don't think there is an equivalent, but you can get around by using inline assembly. I would still recommend that all assembly code be in assembly files...
I could write the whole kernel in asm but I chose's to use external c files exactly like some of the example kernel's in os dev.
I am just wondering if the lack of volatile key word will effect my kernel in a bad way?
About the #pragma pack(push, 1) . Is this the same stuff as setting the alignment option in my compiler setting?
I am just new to this kind of statement why do we even need it and what is the 1 , 2 ,4 ,..n for?
I have always wondered about the difference in extern "C" and setting the compiler to compile to C with /Td C. They don't seem to be the same?
Is their away to turn this on/off in the compiler or linker settings.For some reason, under specific optimization options, msvc will replace copy loops with calls to memcpy, and try to link in one of its user-mode libraries
Because I have a lot of previous code that I am using that gives these error's
I was wondering if their is a simple setting without having to do #pragma and extern "C" {} everytime. Maybe /Oi or /Ox option? I still don't get what the hell all this intrinisic stuff is thought memcpy is a function that would only be recongnized if the header file was include so if I define memcpy and never include their's I should have no problem?
Re: OS -->USB ?
Wait found this
or
Wonder if it's the function one i should use not the intrinisic one.
I have seen these setting's in the compiler like turn on/off intrinisic functions ...
But that didn't work I will try what you said above and see if it works tonight when I get home. Thanks again for all your help.
You guy's rock.
Code: Select all
// do not use strlen intrinsic
#pragma function(strlen)
Code: Select all
// use intrinsic forms of memset and strlen
#pragma intrinsic(memset, strlen)
I have seen these setting's in the compiler like turn on/off intrinisic functions ...
But that didn't work I will try what you said above and see if it works tonight when I get home. Thanks again for all your help.
You guy's rock.

Re: OS -->USB ?
Sorry for the triple post but this was interesting
http://www.codemaestro.com/reviews/7
This clears what packing is and how to use it in both visual studio and gcc compilers.
Still have yet to try it and yet to figure out the virtual problem/intrinsic problem.
Later
http://www.codemaestro.com/reviews/7
This clears what packing is and how to use it in both visual studio and gcc compilers.
Still have yet to try it and yet to figure out the virtual problem/intrinsic problem.
Later
Re: OS -->USB ?
Sam111 wrote:Ya , I agree but sometimes I have to do in/out asm commands in my c code for my device drivers. What I did is create a few functions that use the inline asm tags to do in/out asm command reads/writes.
Code: Select all
extern "C" {
void outportbyte(uint port, uint8 value);
void outportword(...); // etc
}
#pragma intrinsic(outportbyte, ...)
#define IoPortWriteByte(port, value) outportbyte(port, value)
Yes, it's the same, except that its effect is local. The compiler option affects every file you compile.Sam111 wrote: About the #pragma pack(push, 1) . Is this the same stuff as setting the alignment option in my compiler setting?
You need n > 1 for performance reasons (aligned memory access is always faster than unaligned or misaligned memory access). You need n = 1 for interoperability with other code (assembly, GRUB, whatnot).Sam111 wrote: I am just new to this kind of statement why do we even need it and what is the 1 , 2 ,4 ,..n for?
Don't know the answer to that, I compile my kernel code as C++ (but actually use only the function overloading feature of C++).Sam111 wrote: I have always wondered about the difference in extern "C" and setting the compiler to compile to C with /Td C. They don't seem to be the same?
Move the intrinsics to a separate header file, and just include that header. Intrinsic means the compiler knows how to generate correct assembly code for a specific function (for example, outportbyte). This means that every time you call outportbyte, the compiler emits an "out dx, al" instruction instead of calling a function (which is usually written in assembly or linked in from a library). Intrinsics reduce execution time.Sam111 wrote: I was wondering if their is a simple setting without having to do #pragma and extern "C" {} everytime. Maybe /Oi or /Ox option? I still don't get what the hell all this intrinisic stuff is thought memcpy is a function that would only be recongnized if the header file was include so if I define memcpy and never include their's I should have no problem?