LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2006, 07:11 PM   #1
vicenterb
LQ Newbie
 
Registered: May 2005
Distribution: Ubuntu Feisty
Posts: 4

Rep: Reputation: 0
Unhappy C program using free_irq not compiling


Hi...

I'm writing a program in Intel ASM to demonstrate the basic of I/O programming, reading scancodes from the keyboard with inb and setting the NUM, CAPS and SCROLL leds with outb. I would like to deactivate the interrupt handler of the keyboard during the execution of the program, to prevent any interference.

The only way i've found to do that is using C function free_irq or disabling the IRQ using disable_irq (i would prefer the last one, because at the end of the program i could use enable_irq to go back). Anyway, i wrote a small program to try the function (i'm not sure of the headers included, i just copied them from an example i found):

#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/interrupt.h> /* We want an interrupt */
#include <asm/io.h>

int main()
{
free_irq(1,NULL);
}

But it can't get it to compile, each time a i solve one error a hundred more appears.

Somebody knows a simpler way to disable the keyboard interrupt handler? (and a way to restore it later)

What headers are needed for this program to compile? I tried installing the kernel-devel package but it didn't help.

I'm running Fedora Core 4, kernel 2.6.11-1.1369_FC4


Any help? Thanks in advance!
 
Old 10-13-2006, 04:34 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
If you want to do kernel work, you need to make your code part of the kernel. You can not write kernel-code just like a normal program. You need at least to adapt and compile you code as a kernel module. The load it with "insmod".

If instead you want to write a seperate program, forget about IRQ's. Only the kernel deals with IRQ's.
 
Old 10-13-2006, 04:53 AM   #3
ptlchetan
Member
 
Registered: Aug 2006
Posts: 35

Rep: Reputation: 15
here u need to specify that r u doing driver programing

if u r doing device driver programing then u have to code like module
s and refer some book like device driver thirrd edition rubini.

ok
enjoy
 
Old 10-14-2006, 08:42 AM   #4
vicenterb
LQ Newbie
 
Registered: May 2005
Distribution: Ubuntu Feisty
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks

Thanks to both of you for your help.

I checked the book you suggested, very interesting one, It'll be very useful for me, but not for this case. Let me explain you better my problem, any suggestion you have would be really appreciated. I'm a computer science teacher, and I’m writing a book for beginner students, actually it's for students of the 2nd and 3rd semester of the 10-semester career.

These students have little knowledge on Linux (our first lab practice is titled "Introduction to Linux), little knowledge on C (the second one is “Introduction to C programming"); actually they have little knowledge on everything. That's why recompiling the kernel or writing a module aren't valid solutions to my problem.

The objective of these little programs I'm writing is to show the basics concepts of programmed I/O (check for status register, write or read from the data register, etc), nothing too deep. Here's one of this little programs, it recognizes the scandcodes of the 'Q' to 'M' keys using xlat and a translation table:


.section .data
CAD: .asciz "%c\n"
ERROR: .asciz "Se ha denegado el permiso sobre los puertos del teclado\n"
table: .asciz "QWERTYUIOP****ASDFGHJKL*****ZXCVBNM"
.bss
SC: .space 1

.section .text
.globl _start

_start:
# Solicita permiso sobre los puertos del teclado
movl $101, %eax # Servicio 101 (ioperm)
movl $0x60, %ebx # Desde 0x60 (Registro de datos)
movl $5, %ecx # Hasta 0x64 (Registro de estado)
movl $1, %edx # Obtener permiso
int $0x80 # Llamada al SO

testl %eax,%eax # No se obtuvo el permiso
jne err


espera: inb $0x64, %al # Lee el registro de estado
andb $1, %al # Enmascara el bit 0
cmpb $0, %al # Si está apagado espera
je espera

xorl %eax, %eax # Limpia eax
inb $0x60,%al # Lee el scancode del registro de datos
cmpb $0x1C,%al # Si es ENTER (presionada) terminar
je fin

movb %al, SC
andb $0x80, %al # Ignora las teclas levantadas
jne espera

cmpb $0x10, SC # Si el scancode es menor al de la Q
jl noletra # No es una letra
cmpb $0x32, SC # Si el scancode es mayor al de la M
jg noletra # No es una letra

leal table, %ebx # Traduce el scancode a la letra
movb SC, %al
subb $0x10,%al
xlat
jmp mostrar

noletra:
movb $'*', %al # Si no es una letra imprime *

mostrar:
pushl %eax # Muestra la tecla presionada
pushl $CAD
call printf
addl $8, %esp
jmp espera

err: pushl $ERROR # Informa al usuario sobre el error
call printf
addl $4, %esp

fin: movl $101, %eax # Servicio 101 (ioperm)
movl $0x60, %ebx # Desde 0x60 (Registro de datos)
movl $5, %ecx # Hasta 0x64 (Registro de estado)
movl $0, %edx # Liberar permiso
int $0x80 # Llamada al SO

movl $1, %eax # Termina el programa
movl $0, %ebx
int $0x80

When running this program i found two problems:

1) I don't want the pressed key to be shown on the console mixing with the output of the program (that's why i wanted to disable the keyboard handler during program's execution). Is there a simpler way to prevent the keys to be shown? I've been running the program from a ssh session but i would like a better workaround using only one computer


2) The second problem it's that some of the pressed keys seem to be missing for my program. I realize that this could happen with programmed I/O if i press to keys to fast for the program to process them. What freaks me out it's that it just miss some of the keys even if i press it one every 3 or 4 seconds. I changed the keyboard rate but it didn't help. Since the keys are missed in the program but not in the output of the console (the one I want to prevent in problem #1), it ocurred to me that disabling the keyboard handler could resolve both of my problems (???). Maybe I also think I could unload the module that handles the keyboard and see what happens but it cant' figure out wich one is it..


Again, thanks for your help!!!

Last edited by vicenterb; 10-14-2006 at 09:07 PM.
 
  


Reply

Tags
hardware, io, irq, keyboard



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Free_IRQ Palak Shah Linux - Distributions 0 07-12-2006 07:53 AM
help compiling a program minm Linux - Newbie 3 10-10-2005 01:14 AM
Compiling a Program? dbzw Linux - Software 4 10-09-2005 01:31 PM
Compiling a program lintho Linux - Software 2 08-24-2004 07:41 AM
Compiling Program Star3132 Linux - General 8 06-29-2004 05:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration