Detecting hardware

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Detecting hardware

Post by Revelation »

I only get FFFF as return value. Are you sure the procedure is correct?
Now is the winter of my disk content.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Detecting hardware

Post by jal »

AJ wrote:On my i586-32 GCC Cross Compiler, char=8, short = 16, int = 32, long = 32, long long = 64.
On my x86-64 GCC Cross Compiler, char=8, short = 16, int = 32, long = 64, long long = 64.
I have also heard of compilers (M$?) that have int = 64, long = 32 for x64, but that was a while ago.


JAL
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Detecting hardware

Post by Revelation »

My compiler uses these settings: char=8, short = 16, int = 32, long = 32, long long = 64. So that should not be the problem.

These are my inl and outl functions:

Code: Select all

inline int inl(unsigned short port)
{
    unsigned long ret_val;
asm volatile("inl %1,%0" : "=a" (ret_val) : "dN" (port));
    return ret_val;
}

inline void outl(unsigned short port, unsigned long value)
{
asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port));
}
Now is the winter of my disk content.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Detecting hardware

Post by Brynet-Inc »

Masterkiller wrote:The "long" type is strict 32-bit in size. You should use it instead of int.
You're wrong.

http://en.wikipedia.org/wiki/64bit#64-bit_data_models

You should never assume that.. use Stdint types.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Detecting hardware

Post by Revelation »

I've changed my inl and outl to

Code: Select all

inline unsigned long inl(unsigned short port)
{
    unsigned long ret_val;
__asm__ __volatile__("inl %%dx, %%eax" : "=a" (ret_val) : "dN" (port));
    return ret_val;
}

inline void outl(unsigned short port, unsigned long value)
{
 __asm__ __volatile__("outl %%eax, %%dx" : : "d" (port), "a" (value));
}
But I still get FFFF as return value. I still haven't got a clue what could cause this. Should I initialize something before doing this scan procedure?
Now is the winter of my disk content.
User avatar
raistlinthewiz
Member
Member
Posts: 34
Joined: Wed Jun 29, 2005 11:00 pm
Contact:

Re: Detecting hardware

Post by raistlinthewiz »

0xFFFF as return means there is not pci peripheral on that bus/dev location.
check this thread http://forum.osdev.org/viewtopic.php?f=1&t=17339
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: Detecting hardware

Post by Masterkiller »

Brynet-Inc wrote:
Masterkiller wrote:The "long" type is strict 32-bit in size. You should use it instead of int.
You're wrong.

http://en.wikipedia.org/wiki/64bit#64-bit_data_models

You should never assume that.. use Stdint types.
OK, I'm wrong, but it depends on the compiler. Every compiler include documentation of size of types. Once you compile an application there is no more long and int, there is 32-bit pointer (dword).
Revelation wrote:But I still get FFFF as return value. I still haven't got a clue what could cause this. Should I initialize something before doing this scan procedure?
Another hardware device detection is done by BIOS just before loads the bootsector. If not clear the screen and hang the execution on the bootsector, you will see a table result of the PCI Scanning of the BIOS and other information. Last line contains the text "Verifying DMI Pool Data...". If you still get 0xFFFFFFFF value from reading BUS/DEVICE address listed in that table, you have an error in your program.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Detecting hardware

Post by Revelation »

Thanks for the help guys! I have found out that the problem lies with Bochs and not with my code, because when I did a real test, I got correct results. My guess at the moment is that I haven't compiled bochs with the enable-pci flag.
Now is the winter of my disk content.
Post Reply