Hi, I am having an issue where i do a pci scan(brute force). But i don't seem to find any storage devices/controllers.
When i use command -> lspci -vv <- in the linux "konsole".
From reading the devices that it has recognised, it shows that it detected a SATA controller on a
ISA bridge on function 2 of bus 0 device 0x1F.
But when i read the ISA bridge header common variables on function 0. The header type is 0x8D and from what i
have read in the PCI link on the Main Page there should be 3 types(0x80/0x81/0x82). Also when i read function 2
the common variables are all 0.
I have tested on both qemu and my own hardware and shows no storage controllers(class 0x01) even though i ignore the subclass.
So i am unsure how Linux detected this.
Any advice on how i should move forward would be appreciated.
PCI Scan Shows no storage controllers
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PCI Scan Shows no storage controllers
It sounds like your code to read the PCI configuration space doesn't work properly. The header type is not 0x8D, and function 2 should have nonzero values in its configuration space.
Re: PCI Scan Shows no storage controllers
Hi Octocontrabass, you were right i had some bugs in my code when bit shifting the function number into the register before using the out command and it resulted in reading function 0 with a masked offset:
faulty code:
; ecx is the device count --- ebx is the bus count --- edi is the offset --- edx is the function number
_PCIRead: xor eax,eax
or edi,0x80000000
and edi,0x800000FC
or al,bl
shl eax,8
shl ecx,3
or al,cl
shr ecx,3
shl eax,5
or al,dl ; this line is supposed to exchange positions with the line above it and then i can merge the two shl commands to shl eax,8
shl eax,3
or eax,edi
mov dx,0xCF8
out dx,eax
mov dx,0xCFC
in eax,dx
ret
I should have tested more thoroughly, I'm sorry.
This is my first topic. Do i close the topic or do the moderators?
faulty code:
; ecx is the device count --- ebx is the bus count --- edi is the offset --- edx is the function number
_PCIRead: xor eax,eax
or edi,0x80000000
and edi,0x800000FC
or al,bl
shl eax,8
shl ecx,3
or al,cl
shr ecx,3
shl eax,5
or al,dl ; this line is supposed to exchange positions with the line above it and then i can merge the two shl commands to shl eax,8
shl eax,3
or eax,edi
mov dx,0xCF8
out dx,eax
mov dx,0xCFC
in eax,dx
ret
I should have tested more thoroughly, I'm sorry.
This is my first topic. Do i close the topic or do the moderators?
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PCI Scan Shows no storage controllers
There's no need to close the topic.
Is there any particular reason why you chose to write this function in assembly? It's much easier to catch mistakes in higher-level languages.
Is there any particular reason why you chose to write this function in assembly? It's much easier to catch mistakes in higher-level languages.
Re: PCI Scan Shows no storage controllers
Even though this is my first time working through OS development, i am trying to do the whole thing(my software idea not a full OS) in assembly. I did try to look at how i could use c but was not sure how to set the origin point of the code as you can do in an assembler like nasm([org 0x7C00]). I am more interested in assembly anyway so i just gave up on c. Its a little crazy to do it in assembly but i am enjoying it so far.
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PCI Scan Shows no storage controllers
You can do that using a linker script. You probably wouldn't want to write a boot sector in C, though.Z3NT0N wrote:I did try to look at how i could use c but was not sure how to set the origin point of the code as you can do in an assembler like nasm([org 0x7C00]).
Re: PCI Scan Shows no storage controllers
The way i have been doing it so far is that I have been writing the code in "kate" on linux haha and then i assemble each file ("nasm -f bin name.asm -o name.img"), I have one file for the bootloader, one for the protected mode switch and then a third for my main code that runs after the PE switch. I then combine the binary outputs and then boot from that, its quite messy but seems to be working. Thank you for the link, I will have a look.