delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/11/19/08:23:59

Xref: news-dnh.mv.net comp.os.msdos.djgpp:3327
Path: news-dnh.mv.net!mv!news.sprintlink.net!news.texas.net!news.kei.com!simtel!oleane!plug.news.pipex.net!pipex!dish.news.pipex.net!pipex!bt!btnet!demon!sunsite.doc.ic.ac.uk!yama.mcc.ac.uk!news.york.ac.uk!tower.york.ac.uk!slh100
From: Shawn Hargreaves <slh100 AT york DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Locking memory used by an interrupt handler
Date: Sun, 19 Nov 1995 00:31:57 +0000
Organization: The University of York, UK
Lines: 103
Nntp-Posting-Host: tower.york.ac.uk
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

I'm having some problems with my interrupt handler code (under djgpp v2 
beta 3). I have the interrupts working fine, but as soon as cwsdpmi swaps 
anything to disk, the system hangs. I assume that this is because it is 
trying to swap out my interrupt handler, so I need to lock the memory 
used in the interrupt. The problem is, I have tried various ways of doing 
them and none seem to work.

The code below demonstrates the problem: it installs a handler for int 8 
and then sits in a loop allocating memory. It attempts to lock just the 
memory that is used by the isr, but I have also tried locking all the 
physical memory in the machine and that doesn't work either.

Please, somebody tell me what I am doing wrong!


Shawn Hargreaves                        If God is omnipotent, can he make a
http://www.york.ac.uk/~slh100/          rock so heavy that he cannot lift it?


----------------------- cut here ------------------------

#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <dpmi.h>
#include <go32.h>


static int top_of_data = 0;

volatile int timer_tick = 0;

__dpmi_paddr old_handler;
__dpmi_paddr new_handler;
_go32_dpmi_seginfo wrapper;

static int bottom_of_data = 0;


static void top_of_code() { }

void timer_handler()            /* int 8 timer routine */
{
    timer_tick++;
    outportb(0x20, 0x20);
}

static void bottom_of_code() { }


void lock_memory(void *ptr, unsigned long bytes)
{
    unsigned long base;

    if (__dpmi_get_segment_base_address(_my_ds(), &base) == 0) {
	__dpmi_meminfo mem;
	mem.handle = 0;
	mem.size = bytes;
	mem.address = (unsigned long)ptr+base;
	if (__dpmi_lock_linear_region(&mem) != 0)
	    cputs("\r\n__dpmi_lock_linear_region failed\r\n");
    }
    else
	cputs("\r\n__dpmi_get_segment_base_address failed\r\n");
}


void main()
{
    char tmp[80];

    /* allocate iret wrapper */
    __dpmi_get_protected_mode_interrupt_vector(8, &old_handler);
    wrapper.pm_offset = (unsigned long)timer_handler;
    wrapper.pm_selector = _my_cs();
    _go32_dpmi_allocate_iret_wrapper(&wrapper);

    /* install timer routine */
    new_handler.offset32 = wrapper.pm_offset;
    new_handler.selector = wrapper.pm_selector;
    __dpmi_set_protected_mode_interrupt_vector(8, &new_handler);

    /* lock the memory: why doesn't this work? */
    lock_memory(&top_of_data, &bottom_of_data - &top_of_data);
    lock_memory(top_of_code, bottom_of_code - top_of_code);
    lock_memory((void *)wrapper.pm_offset, 256);

    cputs("\r\nTesting...\r\n");

    while (!kbhit()) {
	sprintf(tmp, "\rtimer_tick = %d", timer_tick);
	cputs(tmp);
	if (!calloc(1024, 1))           /* allocate some memory */
	    cputs(" - out of memory!");
    }

    cputs("\r\nFinished!\r\n");

    /* remove timer routine */
    __dpmi_set_protected_mode_interrupt_vector(8, &old_handler);
    _go32_dpmi_free_iret_wrapper(&wrapper);
}

- Raw text -


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