Device Register Access

This is a discussion on Device Register Access within the C Programming forums, part of the General Programming Boards category; It looks like you maybe don't need to, if this is working. (But I was envisioning reading in two bytes ...

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It looks like you maybe don't need to, if this is working. (But I was envisioning reading in two bytes and only keeping the low one, or something similar; surely there's an index register that you would increment if you needed to read two consecutive bytes with inb, or has MMIX messed with my head way too much?)

  2. #32
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    EDIT: I take back what I thought. I agree with you. I think that if I access it the way you suggested that would be right. Because I looked at device manager and saw the IO range for the bar I am r/w from is 9800 - 9807, so 4 bits * 8 = 32 bits. So if this is true then to r/w from bits 23:16 I should write to 9806 first four bits and 9805 last four bits to r/w bits 23:16? So I would just do:

    outb(0x9800+0x05, 0x3f&0xff); //write last four bits
    outb(0x9800+0x06,0x3f>>4); //write top 4 bits

    and it would be the relative same for inb:

    i=inb(0x9800+0x05); //write last four bits
    j=inb(0x9800+0x06); //write top 4 bits
    printf("9805: 0x%x", i&0xff); //read last four bits
    printf("9806: 0x%x",j>>4); //read top four bits

    something like that?
    Last edited by jacob12; 10-12-2008 at 01:03 AM.

  3. #33
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Erm. Usually each address has eight bits in it, not four? That is, addresses go by bytes, not nybbles. So 0x9805 would have eight bits in it, and those eight bits would be 23..16 of the whole 32-bit thing.

    (Remember, you said 9800 to 9804 was 32 bits; 32 divided by 4 is 8.)

  4. #34
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    How would those addresses work out then, would it work like so:

    9800+0x00 to 9800+0x03

    9800 - 31:24
    9801 - 23:16
    9802 - 15:8
    9803 - 7:0

    9800+0x04 to 9800+0x07

    9804 - 31:24
    9805 - 23:16
    9806 - 15:8
    9807 - 7:0

    thanks
    Last edited by jacob12; 10-12-2008 at 02:46 AM.

  5. #35
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Right. (There's nothing special about PCI here, except the numbers being really low -- the same thing would be true about 32-bit integers on the stack:
    Code:
    int main(void) {
        int foo = 0x64656d6f;
        char *bar = &foo;
        for (int i = 0; i < 4; i++) {
            printf("Address &#37;p is %x: %c\n", bar+i, bar[i], bar[i]);
        }
        return 0;
    }
    generally speaking, each address represents a byte.)

  6. #36
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    to pick up on our discussion about bit placement and ports. I have learned that in the x86 machine the smallest bits associate with the smallest ports, so what we have is actually the opposite of what we should have, so:

    9800 = 7:0
    9801 = 15:8

    etc...

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectInput Device Access (DirectX 10)
    By DarkMasterBosel in forum Game Programming
    Replies: 0
    Last Post: 12-27-2008, 10:41 PM
  2. logical and physical device access
    By pastitprogram in forum Windows Programming
    Replies: 9
    Last Post: 08-05-2008, 03:46 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Device Driver: sysfs confusion
    By filker0 in forum Linux Programming
    Replies: 0
    Last Post: 12-02-2005, 10:36 AM
  5. Replies: 4
    Last Post: 06-30-2004, 03:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21