Find the answer to your Linux question:
Results 1 to 3 of 3
I'm a super beginner when it comes to writing kernel drivers, but I'm trying to put a very simple one together for a single board computer that has a digital ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2012
    Posts
    2

    Calling interrupt from device driver


    I'm a super beginner when it comes to writing kernel drivers, but I'm trying to put a very simple one together for a single board computer that has a digital I/O header on the motherboard. I basically want to be able to echo -n '2' > /dev/dio and have the 4 output pins on the header set to 0010.

    Talking with the manufacturer, this can be accomplished via:

    Code:
    mov %0x0609,%ax
    mov <bits>, %bl
    int 15h
    So, accordingly, I've got a driver with a write function:

    Code:
    static char val;
    ssize_t dio_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) {
      if (count == 0) { return 0; }
    
      val = (buf[0]-48) & 0x3; // Map ASCII 0 to numeric zero
      asm("movw $0x6F09,%%ax;"
          "movb %[val],%%bl;"
          "int  $0x15;"
          : 
          : [val] "r" (val)
          : "%ax", "%bl");
      return 1;
    }
    Which compiles and loads into the kernel fine, and I echo -n 0 > /dev/dio and... my kernel barfs and the machine locks.

    Obviously I'm missing something, can someone lend a little help?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,639
    The int 15h instruction is probably for an operating system that is running in real mode (a bios call). what is the processor you are running on? An x86 I assume? If so, you need to determine what int 15hex is doing - there is probably a protected mode interrupt that will do the same thing, but you need to know what it is, and if there isn't then you need to figure out how to accomplish the same thing. Chances are it is doing some inp/outp instructions to read/write ports on the bus. Anyway, you might be able to get more information from the manufacturer, indicating to them that you are using Linux and not DOS/Windows.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Feb 2012
    Posts
    2
    Yeah looking into real vs protected a bit more (I'm not much of an assembly hacker, and a lot of this is before my time), I think that indeed it's a real mode call that I'm trying to use from protected mode, so it's doing something else besides what I think it should be. I'm running 64-bit on an i7 mobile CPU, so I'm not even sure if dropping to real mode to run the interrupt is an option. 15h is the miscellaneous bios call, which I presume the manufacturer extended the bios to provide a function (0x6F09) to twiddle the DIO port. It's possible to write a driver that talks to the chip directly, but then you have to know what board revision you're on to know what pins are connected to the DIO and it's just a bigger hassle, but maybe that's how I have to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •