flat assembler
Message board for the users of flat assembler.

Index > OS Construction > PCI devices check

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 02 Aug 2011, 10:11
Hi everyone!
I tried to write procedure that collects data about pci devices
Here is it:
Code:
        ;_________________________________________________
        FIND_DEVICES:   ;[ds:edi] - buffer
        mov word [ds:edi], 0h
        xor esi, esi
        inc esi
        xor ecx, ecx                       ;preparing:[ds:edi]-counter, esi = 1(so, it doesnt overwrites counter), cx = 0 (ch = bus, cl = device & function)

        FD_LOOP:
        mov eax, ecx
        shl eax, 8d                        ;eax = address of device
        bts eax, 31d
        push eax
        call PCI_READ                      ;read pci config space with address in eax
        cmp eax,  0FFFFFFFFh               ;if eax is not FFFFFFFFh
        jne NEXT_DEV                       ;save device address and class,else error
        pop eax                            ;
        mov al, cl
        shl al, 5h
        cmp al, 0h                         ;if function number =! 0,
        jnz INCREM                         ;increment device and xor function
        mov al, cl
        shr al, 3h
        cmp al, 0h
        jnz NBUS                           ;if device number == 0, then no more devices here
        jz RETURN_FD                       ;else next buss
        RT_PT_:
        jmp FD_LOOP

        RETURN_FD:
        ret            ;[ds:edi] - filled buffer

        NBUS:            
        xor cl, cl
        inc ch
        jmp RT_PT_

        INCREM:
        and cl, 11111000b
        add cl, 8h
        jmp RT_PT_

        NEXT_DEV:
        pop eax
        mov [ds:edi+(esi*4)], eax
        inc esi
        mov al, 8h
        call PCI_READ
        mov [ds:edi+(esi*4)], eax
        inc word [ds:edi]
        inc esi
        inc cx
        jmp RT_PT_
        ;______________________________________





        ;_________________________________________
        PCI_READ:     ;eax - address
        push dx
        mov dx, 0CF8h
        out dx, eax
        mov dx, 0CFCh
        in eax, dx
        pop dx
        ret           ;eax - data
        ;_________________________________________
        
    

But I get only empty buffer Crying or Very sad
Whats wrong with code???

_________________
_______________________________
NSOS


Last edited by BOTOKILLER on 02 Aug 2011, 14:49; edited 2 times in total
Post 02 Aug 2011, 10:11
View user's profile Send private message Reply with quote
qandrew



Joined: 21 Jan 2010
Posts: 3
qandrew 02 Aug 2011, 14:17
BOTOKILLER wrote:

Code:
        xor esi, esi
        inc esi
        xor ecx, ecx                       ;preparing:[ds:edi]-counter, esi = 0(so, it doesnt overwrites counter), cx = 0 (ch = bus, cl = device & function)

    


ESI = 1 in this code. Not 0. Try removing
Code:
inc esi    
, not sure it helps though.
Post 02 Aug 2011, 14:17
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 02 Aug 2011, 14:28
qandrew wrote:
BOTOKILLER wrote:

Code:
        xor esi, esi
        inc esi
        xor ecx, ecx                       ;[b]preparing:[ds:edi]-counter, esi = 1(so, it doesnt overwrites counter), cx = 0 (ch = bus, cl = device & function)[/b]

    


ESI = 1 in this code. Not 0. Try removing
Code:
inc esi    
, not sure it helps though.

ESI = 1
ds:edi counter
ds:edi+4 table starts

address = [ds:edi+(esi*4)]
esi=1 -> [ds:edi+(esi*4)] == ds:edi+4

_________________
_______________________________
NSOS


Last edited by BOTOKILLER on 02 Aug 2011, 14:39; edited 1 time in total
Post 02 Aug 2011, 14:28
View user's profile Send private message Reply with quote
qandrew



Joined: 21 Jan 2010
Posts: 3
qandrew 02 Aug 2011, 14:36
BOTOKILLER wrote:
esi = 0

Then fix the comment in your code which says ESI is equal to 0.
Post 02 Aug 2011, 14:36
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 02 Aug 2011, 14:39
qandrew wrote:
BOTOKILLER wrote:
esi = 0

Then fix the comment in your code which says ESI is equal to 0.

yeah, missed that one Smile
Why that code returns empty buffer???

_________________
_______________________________
NSOS
Post 02 Aug 2011, 14:39
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 03 Aug 2011, 16:42
I debugged this code in virtual box - the only problem is that it always returns 0FFFFFFFFh in eax after PCI_READ call, but why???
Post 03 Aug 2011, 16:42
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 03 Aug 2011, 18:12
Quote:
I debugged this code in virtual box - the only problem is that it always returns 0FFFFFFFFh in eax after PCI_READ call, but why???


Because the address of bus device function is wrong,
try again to rewrite the code, after learn the spec Wink

_________________
Nil Volentibus Arduum Razz
Post 03 Aug 2011, 18:12
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 04 Aug 2011, 06:25
I calculated device like it is said on Osdev Wiki bits
bit 31 -must be set to make it work
bits 16-23 - bus
bits 15-11 - device
bits 8-10 - function
bits 2-7 - register

_________________
_______________________________
NSOS
Post 04 Aug 2011, 06:25
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 04 Aug 2011, 06:26
DJ Mauretto wrote:

try again to rewrite the code, after learn the spec Wink

Also specs arent free))))
And its easier to seek knowledge from osdev)

_________________
_______________________________
NSOS
Post 04 Aug 2011, 06:26
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 04 Aug 2011, 08:02
When you get FFFFFFFFH means that to the address there are no device..

I don't know Virtual box, anyway you first of all must check the presence
of the controller, then start with
Bus 0
Device 0
Function 0
Register 0

Now if you get FFFFFFFFH or 00000000H then there is no device
at that address.
Change Device with 1 ( max device = 31 ) and so on..
When you get the device you must checK Header Type to verify
if the device is a Multifunction.
If the Device is a Multifunction Device you must increment
Function to 1 ( max function = 7) and check for other device

Wink

Your algorithm is Bug....
plese make another attempt Razz

_________________
Nil Volentibus Arduum Razz


Last edited by DJ Mauretto on 05 Aug 2011, 06:18; edited 2 times in total
Post 04 Aug 2011, 08:02
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 04 Aug 2011, 11:38
DJ Mauretto wrote:

Your algorithm is Bug....
plese make another attempt Razz


Yeah, maybe youre right Razz
I should rethink algorithm.
When I wrote this piece of code i thought that if there isnt device № 10, then there isnt device № 11, it turned out not that simple)))

_________________
_______________________________
NSOS
Post 04 Aug 2011, 11:38
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 04 Aug 2011, 16:59
Yeah, I made it - I didnt have to rewrite it comletely, I had to just wipe a few lines. The only thing I need now is how to get highest bus number to stop loop
Also I'll need to increase buffer to 2048d bytes, cuz I'm getting veeeeeeery long list Very Happy Very Happy Very Happy
Code:
        ;dont mind comments - they may not match improoved code 
        ;_________________________________________________
        FIND_DEVICES:   ;[ds:edi] - buffer
        mov word [ds:edi], 0h
        xor esi, esi
        inc esi
        mov ecx, 0h                       ;preparing:[ds:edi]-counter, esi = 0(so, it doesnt overwrites counter), cx = 0 (ch = bus, cl = device & function)


        FD_LOOP:
        mov eax, ecx
        shl eax, 8d                        ;eax = address of device
        bts eax, 31d
        push eax
        call PCI_READ                      ;read pci config space with address in eax
        cmp ax,  0FFFFh                    ;if eax is not FFFFFFFFh
        jne NEXT_DEV                       ;save device address and class,else error
        pop eax                            ;
        jmp INCREM                         ;increment device and xor function
        RT_PT_:
        jmp FD_LOOP

        RETURN_FD:
        ret            ;[ds:edi] - filled buffer


        INCREM:
        and cl, 11111000b
        add cx, 8h
        jmp RT_PT_

        NEXT_DEV:
        pop eax
        mov [ds:edi+(esi*4)], eax
        inc esi
        mov al, 8h
        call PCI_READ
        mov [ds:edi+(esi*4)], eax
        inc word [ds:edi]
        inc esi
        inc cx
        jmp RT_PT_
        ;______________________________________
                   

_________________
_______________________________
NSOS
Post 04 Aug 2011, 16:59
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 04 Aug 2011, 17:05
Quote:
Yeah, I made it - I didnt have to rewrite it comletely, I had to just wipe a few lines. The only thing I need now is how to get highest bus number to stop loop
Also I'll need to increase buffer to 2048d bytes, cuz I'm getting veeeeeeery long list


You have serious problem with yourself Laughing

_________________
Nil Volentibus Arduum Razz
Post 04 Aug 2011, 17:05
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 04 Aug 2011, 17:24
DJ Mauretto wrote:
Quote:
Yeah, I made it - I didnt have to rewrite it comletely, I had to just wipe a few lines. The only thing I need now is how to get highest bus number to stop loop
Also I'll need to increase buffer to 2048d bytes, cuz I'm getting veeeeeeery long list


You have serious problem with yourself Laughing

I know Very Happy Smile
P.S. I ve been mistaken about buffer - it looks so big just because function is relatively fast and isnt stopped - it just writes same values many times)))

_________________
_______________________________
NSOS


Last edited by BOTOKILLER on 04 Aug 2011, 17:36; edited 1 time in total
Post 04 Aug 2011, 17:24
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 04 Aug 2011, 17:35
I believe if you scan the _MP_ tables this will tell you how many PCI busses there are (but I cannot confirm this). Another way is to simply probe them all or I think there is a "PCIR" table (which I have never tried).

Here's what I get on VirtualBox http://dl.dropbox.com/u/729869/os_vb.png (note this changes according to the controllers you enable)
Post 04 Aug 2011, 17:35
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 05 Aug 2011, 05:55
cod3b453 wrote:
I believe if you scan the _MP_ tables this will tell you how many PCI busses there are (but I cannot confirm this). Another way is to simply probe them all or I think there is a "PCIR" table (which I have never tried).

Here's what I get on VirtualBox http://dl.dropbox.com/u/729869/os_vb.png (note this changes according to the controllers you enable)

Yeah, I also get 9 devices
As for number of busses - function is pretty fast so I better just check everything until 255 bus
Code:
cmp ch, 0FFh
je RETURN_FD
    

It works absolutely perfect!

_________________
_______________________________
NSOS
Post 05 Aug 2011, 05:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.