www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/07/06:41:52

From: Michael Bukin <bukinm AT inp DOT nsk DOT su>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: LONG: My INT31 handler isn't feeling too swell
Date: 07 Apr 1999 09:10:35 +0700
Organization: Budker Institute of Nuclear Physics
Lines: 96
Message-ID: <20aewlb2p0.fsf@Sky.inp.nsk.su>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 990404093438 DOT 19395L-100000 AT is> <7e7j4e$cr4$4 AT news DOT luth DOT se> <20vhfc47t7 DOT fsf AT Sky DOT inp DOT nsk DOT su> <7edsj2$agf$1 AT news DOT luth DOT se>
NNTP-Posting-Host: sky.inp.nsk.su
X-Newsreader: Gnus v5.5/Emacs 19.34
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

ams AT ludd DOT luth DOT se (Martin Str|mberg) writes:

> Michael Bukin (M DOT A DOT Bukin AT inp DOT nsk DOT su) wrote:
> : One other thing I noted is that you are trying to reuse any selector
> : freed with %ax=0x0001.  But this interrupt is used to free selectors
> : allocated by other DPMI functions too, not just %ax=0x0000.  Also, you
> 
> Yes, but so what? Can't I reuse them as if originally allocated by 
> %ax=0x0001? If they are freed (sp?), I thought I should be free (pun
> intended) to reuse them, shouldn't I?

According to dpmi specs which I have here:

             8.7 Set Segment Base Address

                 This function changes the 32-bit linear base address of
                 the specified selector.

                 AX = 0007h
...
                 o    Your program  should only  modify descriptors that
                      were   allocated    through   the   Allocate   LDT
                      Descriptors function.

Likewise for 0x0008 and 0x0009.

> 
> : are not changing C flag, because when you are using iret, flags are
> : taken from stack.  IMHO, you should change flags on stack before using
> : iret.
> 
> Hmm. Yes that seems like a correct diagnose. At what offset of %esp
> are the flags upon the entry of my interrupt handler (%esp+x, what is
> x)?

You will need to calculate it yourself, for example, if you push the
following registers in stack in your interrupt handler

push %%eax
push %%ebx
push %%ecx

Then stack will look like this

%flags
selector
offset
%eax
%ebx
%ecx

And %esp will point to %ecx, now you can find offsets to each entity

20 %flags
16 selector
12 offset
8  %eax
4  %ebx
0  %ecx

And clear C flag in flags on stack

movl 20(%%esp), %%ecx
andb $~1, %%cl
movl %%ecx, 20(%%esp)

Set C flags with

orb $1, %%cl

BTW, you can use selector from stack to determine DPL or anything
else necessary for allocated selector (though all allocated selectors
will usually have the same DPL as your interrupt handler DPL).

>
> :        Also, I think you should not use sti/cli in your interrupt
> : handler.
> 
> Why not?
> 
> My thought there was that I was trying to issue an int, hence I must
> enable interrupts otherwise they would be blocked.

Processor only blocks hardware interrupts (it does not pay attention
to the interrupt request line), but you can generate software
interrupts even if interrupts are disabled.  I don't know restrictions
of DPMI environment (libc reference for
__dpmi_set_protected_mode_interrupt_vector says to use sti before
iret), but it is generally advisable to not enable interrupts inside
interrupt handler, because then interrupts might pile up and trash
stack. According to some documentation on i486, it is safe to do sti
right before iret, it says that processor reacts on external
interrupts after executing next instruction after sti.

-- 
Michael Bukin

- Raw text -


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