accessing the network card

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.
montrom
Member
Member
Posts: 86
Joined: Thu May 13, 2010 1:45 pm

Re: accessing the network card

Post by montrom »

aloktiagi wrote: Yes true it shud be 32 bit and inl and outl need to be used but when i had used them the result of my BAR0 was empty.

Code: Select all

__asm__ volatile ("in %%dx,%%eax" : "=a" (ret_val) : "d"(port));
So, you were using that inportl function and you weren't returning anything, and you don't know why?
Visit the Montrom user page for more info.
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: accessing the network card

Post by aloktiagi »

I'm returning a value right!!!

Code: Select all

int inportl(int port)
{
    int ret_val;
    __asm__ volatile ("in %%dx,%%eax" : "=a" (ret_val) : "d"(port));
    return ret_val;
}
montrom
Member
Member
Posts: 86
Joined: Thu May 13, 2010 1:45 pm

Re: accessing the network card

Post by montrom »

Visit the Montrom user page for more info.
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: accessing the network card

Post by eddyb »

aloktiagi wrote:Hi,

inl and outl look like this

Code: Select all

int inportl(int port)
{
    int ret_val;
    __asm__ volatile ("in %%dx,%%eax" : "=a" (ret_val) : "d"(port));
    return ret_val;
}


void outportl(int port, int val)
{
    __asm__ volatile ("outl %%eax,%%dx" : : "a"(val), "d"(port));
}

You realize int is signed 32-bit, do you?
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: accessing the network card

Post by aloktiagi »

@eddyb:my return value should be unsigned int 16bit

and

@montrom : my return value should be of unsigned char type

:?: :?: :?:
montrom
Member
Member
Posts: 86
Joined: Thu May 13, 2010 1:45 pm

Re: accessing the network card

Post by montrom »

This is a waste of time. Here: Use unsigned and inl. Now, I hope you know what to do with that. And, please make a better effort to form proper sentences. I have no idea if you are telling me or asking me those things you wrote in your last reply. It would also be helpful if you would step back and take a moment to better understand what it is you are doing. And, better yet, discover why it is you are in such a hurry to complete something most likely meaningless beyond your own personal desire. Oh, and it wouldn't hurt to spend some time in a C forum.
Visit the Montrom user page for more info.
aloktiagi
Member
Member
Posts: 52
Joined: Fri Apr 23, 2010 11:03 am

Re: accessing the network card

Post by aloktiagi »

You see when i had put unsigned int and inl i was getting the device id and all the registers after it till BAR0. But the value for BAR0 is empty.

So my only question is that how is BAR0 different from all the other registers before it, in terms of reading its value??
montrom
Member
Member
Posts: 86
Joined: Thu May 13, 2010 1:45 pm

Re: accessing the network card

Post by montrom »

Does the specification state that there is supposed to be a value in each BAR?
Visit the Montrom user page for more info.
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: accessing the network card

Post by ehenkes »

PrettyOS, util.c:

Code: Select all

uint8_t inportb(uint16_t port)
{
    uint8_t ret_val;
    __asm__ volatile ("in %%dx,%%al" : "=a"(ret_val) : "d"(port));
    return ret_val;
}

uint16_t inportw(uint16_t port)
{
    uint16_t ret_val;
    __asm__ volatile ("in %%dx,%%ax" : "=a" (ret_val) : "d"(port));
    return ret_val;
}

uint32_t inportl(uint16_t port)
{
    uint32_t ret_val;
    __asm__ volatile ("in %%dx,%%eax" : "=a" (ret_val) : "d"(port));
    return ret_val;
}

void outportb(uint16_t port, uint8_t val)
{
    __asm__ volatile ("out %%al,%%dx" :: "a"(val), "d"(port));
}

void outportw(uint16_t port, uint16_t val)
{
    __asm__ volatile ("out %%ax,%%dx" :: "a"(val), "d"(port));
}

void outportl(uint16_t port, uint32_t val)
{
    __asm__ volatile ("outl %%eax,%%dx" : : "a"(val), "d"(port));
}
look at pci.c how we manage this.
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: accessing the network card

Post by ehenkes »

@aloktiagi: how are things going on? :D
Post Reply