delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/04/04/13:30:08

Date: Mon, 4 Apr 1994 18:48:30 +0200
From: Stefan Eckart <S_Eckart AT lis DOT e-technik DOT tu-muenchen DOT de>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: strange behavior of inportb(0x21)

While trying to implement a Soundblaster interface to one of my programs
I found the following program to behave in an unexpected manner:

-------------------------------------------------------------------------
#include <stdio.h>
#include <pc.h>

main()
{
  int i;
  outportb(0x21,0x30);
  for(i=0;inportb(0x21)==0x30 && i<1000000;i++)
    ;
  printf("%d, %x\n",i,inportb(0x21));
}
-------------------------------------------------------------------------
Compiling and running this program as

  gcc -o test test.c -lpc
  go32 test

(conditions: 386DX, no DPMI, no VCPI, with or w/o XMS handler)
produces output similar to

  go32 version 1.11.maint4 Copyright (C) 1993 DJ Delorie
  6021, 0

where the first number varies but is always lower than about 20000.
The expected output would of course have been

  go32 version 1.11.maint4 Copyright (C) 1993 DJ Delorie
  1000000, 30

If I run the same program (without recompiling) with go32 v1.10a or v1.10u
(BTW, I was surprised that v1.10 already knows about COFF files) the result
is correct. Compiling with version 1.10 gave the same result (running
with go32 v1.10 is ok, v1.11 fails). Version 1.11 and 1.11.maint4
behave identical.

What's going on? The interrupt mask seems to be mangled by the extender
somehow. It obviously is related to the imask1 handling in
go32/mswitch.asm. The instructions

	in	al,21h
	mov	cs:imask1,al

under certain conditions seem to store 0 into imask1. I don't know enough
about the 8259 PIC, but maybe 'in al,21h' doesn't always return the current
interrupt mask?

The handling of the PIC interrupt mask is currently broken anyway. If I
change the interrupt mask with an outportb(0x21,mask) from inside protected
mode it is restored to the previous value the next time a switch back into
real mode occurs (via the

	mov	al,cs:imask1
	out	21h,al

instructions). Maybe it would be best to have independent interrupt masks
for real and protected mode (similar to the independence of the interrupt
vectors) and a convenient method to change the real mode interrupt mask
from inside the 32 bit code.

Any comments?

Stefan.
--
stefan AT lis DOT e-technik DOT tu-muenchen DOT de

- Raw text -


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