www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/13/15:59:22

From: "Paolo Gava" <pgava AT etrone DOT com DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: critical section again
Lines: 209
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Message-ID: <Tf%M3.174$Po4.5800@nsw.nnrp.telstra.net>
Date: Wed, 13 Oct 1999 22:58:00 +1000
NNTP-Posting-Host: 203.41.169.57
X-Complaints-To: abuse AT telstra DOT net
X-Trace: nsw.nnrp.telstra.net 939819123 203.41.169.57 (Wed, 13 Oct 1999 22:52:03 EST)
NNTP-Posting-Date: Wed, 13 Oct 1999 22:52:03 EST
Organization: Customer of Telstra Big Pond Direct
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

I still have problem to implement a critical section.
I wrote here some code that I'm using, hope someone can find what it is
wrong...

I'm using DJGPP version 2.02 withWindows98

Here is the code:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/* irq_wrapper.s
*/
.text

.globl _irq_wrapper
   .align 4
_irq_wrapper:

   pushw %ds
   pushw %es
   pushw %fs
   pushw %gs
   pushal

   movb $0x0C, %al
   outb %al, $0x70
   inb $0x71, %al
   movb $0x20, %al
   outb %al, $0xA0
   outb %al, $0x20


   .byte 0x2E
   movw ___djgpp_ds_alias, %ax
   movw %ax, %ds
   movw %ax, %es
   movw %ax, %fs
   movw %ax, %gs

   leal _irq_stack, %ebx
   movl %esp, %ecx
   movw %ss, %dx

   movl (%ebx), %esp
   movw %ax, %ss

   pushl %edx
   pushl %ecx
   pushl %ebx

   cld

   call _MyHandler

   cli

   nop
   popl %ebx
   popl %ecx
   popl %edx
   movl %esp, (%ebx)
   movw %dx, %ss
   movl %ecx, %esp

   popal
   popw %gs
   popw %fs
   popw %es
   popw %ds
   ljmp %cs:_old_timer_irq

   popal
   popw %gs
   popw %fs
   popw %es
   popw %ds

   sti
   iret


.globl _irq_wrapper_end
   .align 4
_irq_wrapper_end:
   ret




/*    main.c
*/

#include <stdlib.h>
#include <stdio.h>
#include <dos.h>

#include <signal.h>
#include <go32.h>
#include <dpmi.h>

#include <allegro.h>



extern void irq_wrapper(void);
extern void irq_wrapper_end(void);
void MyHandler(void);
void MyHandler_end(void);

__dpmi_paddr  old_timer_irq;
unsigned char *irq_stack;
unsigned ulCount=0;
#define STACK_SIZE   8*1024

#define END_OF_FUNCTION(x)    void x##_end(void) { }
#define LOCK_DATA(d,s)        _go32_dpmi_lock_data((d), (s))
#define LOCK_CODE(c,s)        _go32_dpmi_lock_code((c), (s))
#define UNLOCK_DATA(d,s)      _unlock_dpmi_data((d), (s))

#define LOCK_VARIABLE(x)      LOCK_DATA((void *)&x, sizeof(x))
#define LOCK_FUNCTION(x)      LOCK_CODE(x, (long)x##_end - (long)x)


void install_irq(int num,
                 void (*handler)(void),
                 __dpmi_paddr *old_irq)
{
    __dpmi_paddr addr;


 addr.selector = _my_cs();
 addr.offset32 = (long)handler;

 __dpmi_get_protected_mode_interrupt_vector(num, old_irq);

 __dpmi_set_protected_mode_interrupt_vector(num, &addr);

}


void remove_irq(int num, __dpmi_paddr old_irq)
{

    __dpmi_set_protected_mode_interrupt_vector(num, &old_irq);

}


void sys_call(void)
{
    long l;

    for (l=0; l<50000; l++)
        printf("%ld, %ld\n", ulCount);
}

void MyHandler(void)
{

    ulCount += 1;

}
END_OF_FUNCTION(MyHandler);



int main(void)
{

    LOCK_VARIABLE(irq_stack);
    LOCK_VARIABLE(ulCount);
    LOCK_VARIABLE(old_timer_irq);
    LOCK_FUNCTION(irq_wrapper);
    LOCK_FUNCTION(MyHandler);

    irq_stack = malloc(STACK_SIZE);
    if (irq_stack)
    {
        LOCK_DATA(irq_stack, STACK_SIZE);
         irq_stack += STACK_SIZE - 32;
     }

    install_irq(0x8, irq_wrapper, &old_timer_irq);

    disable();

    sys_call();

    enable();

    remove_irq(0x8, old_timer_irq);

}

As you can see this code install the function irq_wrapper to the interrupt
number 0x8 that is the timer interrupt. irq_wrapper is an assembler routine
that call my interrupt timer handler  (MyHandler). Actually this handler
just increase a counter (ulCount).
When I call sys_call() the interrupt should be disable, but when I print
ulCount, I see that it is increased.

By the way most of this code comes from Allegro...

Paolo




- Raw text -


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