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?