Page 2 of 2

Re: Detecting hardware

Posted: Thu Jul 17, 2008 3:44 am
by Revelation
I only get FFFF as return value. Are you sure the procedure is correct?

Re: Detecting hardware

Posted: Thu Jul 17, 2008 5:06 am
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

Re: Detecting hardware

Posted: Thu Jul 17, 2008 5:37 am
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));
}

Re: Detecting hardware

Posted: Thu Jul 17, 2008 5:01 pm
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.

Re: Detecting hardware

Posted: Fri Jul 18, 2008 4:19 am
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?

Re: Detecting hardware

Posted: Fri Jul 18, 2008 7:54 am
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

Re: Detecting hardware

Posted: Fri Jul 18, 2008 8:13 am
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.

Re: Detecting hardware

Posted: Fri Jul 18, 2008 9:36 am
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.