ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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 *
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..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.