delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/08/03:29:37

Message-ID: <37FD7C47.939D67BA@virtualis.com>
Date: Fri, 08 Oct 1999 15:08:24 +1000
From: Alex Mendes da Costa <alexmdc AT virtualis DOT com>
X-Mailer: Mozilla 4.51 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: More Interrupt Problems
NNTP-Posting-Host: a4-p16.syd.fl.net.au
X-Trace: 8 Oct 1999 15:12:15 +1000, a4-p16.syd.fl.net.au
Organization: Customer of First Link Internet Services, Sydney, Australia
Lines: 103
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello again.

I have written this interrupt handler in assembly which I want to set to
interrupt 9. I have enclosed the two files, one written in C and one in
NASM assembly.
This code compiles just fine, and it runs fine until I press a key,
which I am guessing calls my interrupt, then it stuffs up my computer
completely.
I am guessing the problem is in the regions I am trying to lock with
__dpmi_lock_linear_region, and I have read through loads of docs and FAQ
but for the life of me I can't figure out why it wont work!
If anyone can possibly look at my code and tell me where I have slipped
up I would greatly appreciate it.

Thanks heaps,
Alex

P.S. I originally had the interrupt accessing the keystatus array but I
removed this for simplicity. It still doesn't work!




========= INT.C - C code =========

#include <stdio.h>
#include <dpmi.h>

extern void keyboard_handler();
extern void keyboard_handler_end();

char keystatus[128];
unsigned long baseaddr;

__dpmi_paddr old_keyboard_handler, new_keyboard_handler;
__dpmi_meminfo region;

void main()
{

  /* Save the old interrupt vector */
  __dpmi_get_protected_mode_interrupt_vector(0x09,
&old_keyboard_handler);

  /* Lock the interrupt code */
  __dpmi_get_segment_base_address(_my_cs(), &baseaddr);
  region.handle = 0;
  region.size = (keyboard_handler_end - keyboard_handler);
  region.address = keyboard_handler + baseaddr;
  __dpmi_lock_linear_region(&region);

  /* Lock the keystatus array */
  __dpmi_get_segment_base_address(_my_ds(), &baseaddr);
  region.handle = 0;
  region.size = 128;
  region.address = keystatus + baseaddr;
  __dpmi_lock_linear_region(&region);

  /* Lock the stack */
  __dpmi_get_segment_base_address(_my_ss(), &baseaddr);
  region.handle = 0;
  region.size = 10;
  region.address = baseaddr;
  __dpmi_lock_linear_region(&region);

  /* Set the new interrupt handler */
  new_keyboard_handler.offset32 = (int)keyboard_handler;
  new_keyboard_handler.selector = _my_cs();
  __dpmi_set_protected_mode_interrupt_vector(0x09,
&new_keyboard_handler);
 
  i = 0;
  do {
    /* Endless loop? */
  } while (i == 0);

  /* Restore the old interrupt vector */
  __dpmi_set_protected_mode_interrupt_vector(0x09,
&old_keyboard_handler);
}


========= INT.ASM - NASM assembly code =========

[BITS 32]

global _keyboard_handler
global _keyboard_handler_end

extern _keystatus

[SECTION .text]

_keyboard_handler:
   push ax
   mov al, 20h
   out 20h, al
   pop ax
   sti
   iret

_keyboard_handler_end:
  ret

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019