From: mpenacho AT tezcat DOT com (Mark Penacho) Newsgroups: comp.os.msdos.djgpp Subject: Re: Hooking interrupts Date: Sat, 18 Jan 97 07:39:12 GMT Organization: Tezcat.COM - Specialists in human interconnectivity. Lines: 78 Message-ID: <5bpun2$gv0@tepe.tezcat.com> References: <32E045B5 DOT 4680 AT mail DOT idt DOT net> <5bples$dql AT tepe DOT tezcat DOT com> NNTP-Posting-Host: mpenacho.tezcat.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <5bples$dql AT tepe DOT tezcat DOT com>, mpenacho AT tezcat DOT com (Mark Penacho) wrote: >In article <32E045B5 DOT 4680 AT mail DOT idt DOT net>, Joseph Turian > wrote: >>Is it possible to hook an interrupt while in protected mode? I wanted >>to write a keyboard handler, but I am new to djgpp and only know how >>it is done in 8086 assembly sorry about the incomplete last posting typedef unsigned long ADDRESS; #define KEYBOARD_INT 0x09; >#include >#include > >_go32_dpmi_seginfo old_keyboard_isr; >_go32_dpmi_seginfo keyboard_interrupt_holder; >int raw_scan_code; > >void init_keyboard(void) { > while(kbhit()) > getch(); > > _go32_dpmi_lock_code(keyboard_irq, (ADDRESS)end_keyboard_irq - \ > (ADDRESS)_keyboard_irq); > _go32_dpmi_lock_code(key_asm, 30); > _go32_dpmi_lock_data(&raw_scan_code,sizeof(raw_scan_code)); > _go32_dpmi_lock_data (ALL OTHER KEYBOARD IRQ VARIABLES) > > _go32_dpmi_get_protected_mode_interrupt_vector(KEYBOARD_INT, \ > &old_keyboard_isr) > keyboard_interrupt_holder.pm_offset = (ADDRESS)keyboard_irq; > _go32_dpmi_allocate_iret_wrapper(&keyboard_interrupt_holder); > _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, \ > &keyboard_interrupt_holder); >} > >void uninit_keyboard() { > _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, \ > &old_keyboard_isr); > _go32_dpmi_free_iret_wrapper(&keyboard_interrupt_holder); >} > >void keyboard_irq(void) { > key_asm(); > DO SOMETHING WITH raw_scan_code; >} > >int end_keyboard_irq(void) { // do something unique to guarantee \ > //optimization doesn't overrride > return(4); >} > > >assembly part (I use nasm, your code may vary) > >[BITS 32] >[GLOBAL _key_asm] >[EXTERN _raw_scan_code] >[SECTION .text] > >_key_asm: > sti > xor eax,eax > in al,60h > mov dword [_raw_scan_code],eax > in al,61h > or al,82h > out 61h,al > and al,7fh > out 61h,al > mov al,20h > out 20h,al > ret > > >