🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #306

Re: TSR's with no assembly language

#306
From: Joseph H Allen
Date: Wed, 11 Apr 1990 23:40
107 lines
3250 bytes
In article <11433@wpi.wpi.edu> jhallen@wpi.wpi.edu (Joseph H Allen) writes:
>In article <28050@siemens.siemens.com> jrv@demon.siemens.com writes:
>>If there is anyone who can show me the method to use a local stack when my
>>MSC "all C" interrupt is called I would be most appreciative.

>I don't know about MSC but in TC:

>#include <dos.h>

>unsigned osp;		/* Place to save old stack */
>unsigned oss;

>unsiged localstack[1024];

>interrupt foo()		/* The interrupt call itself changes CS:PC,

>{
>osp=_SP;
>oss=_SS;
>disable();
>_SS=_DS;
>_SP=(unsigned)localstack+1024;
>enable();
>func();			/* Call to your code */
>disable();
>_SS=oss;
>_SP=osp;
>enable();
>}

>Notes:

>This is for small & tiny model.  You'll need to do different things for larger
>memory models:  You'll have to set SS to a different value.  

>You absolutely MUST NOT define any local variables in the interrupt handler-
>instead define them in the subfunction 'func()'.  This is because if you
>define any local variables they will go on the old stack.

>This does put 18 bytes on the old stack for saving the registers (access these
>indirectly through osp and oss).  This should be much safer than not changing
>the stack at all.

>Instead of allocating space for a stack, a better way is to have the TSR
>install code remember where the original stack was.

>It is probably possible to remove the 'disable()' and 'enable()'s.  This is
>because the 8088 keeps interrupts off for the next intruction after loading
>SS.  But check that the SP load is only a single instruction first before
>doing this (Note that in TC enable() and disable() are inline functions if you
>include dos.h). 

Oops, that's the non-reentrant version.  You can use it but you have to be
very carefull.  A better one is this:

#include <dos.h>
unsigned osp;		/* Place to save old stack */
unsigned oss;
unsiged localstack[1024];

interrupt foo()		/* The interrupt call itself changes CS:PC,
			   the function handler changes DS */
{
if(_SS==_DS) func();
else
 {
 osp=_SP;
 oss=_SS;
 disable();
 _SS=_DS;
 _SP=(unsigned)localstack+1024;
 enable();
 func();			/* Call to your code */
 disable();
 _SS=oss;
 _SP=osp;
 enable();
 }
}

Ok, so who's going to make a multi-tasking OS (in C only) now that we have
context switching code?



















Someday I'm going to write a new non-braindamaged news system.
-- 
             ~ COMPLETELY FUNCTIONAL SIGNATURE - NO FRIVOLITY HERE ~
REPLIES/FOLLOWUPS SHOULD BE SENT TO: jhallen@wpi.wpi.edu (130.215.24.1)
DISCLAIMER: I'm personally resposible for everything I say.  So, if you have
	    a problem feel free to sue me.
Technical Details
Message-ID: <11437@wpi.wpi.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!husc6!m2c!wpi!jhallen
References: <27810@siemens.siemens.com> <127@demott.COM> <28050@siemens.siemens.com> <11433@wpi.wpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!husc6!m2c!wpi!jhallen
From: jhallen@wpi.wpi.edu (Joseph H Allen)
Newsgroups: comp.sys.ibm.pc.programmer
Subject: Re: TSR's with no assembly language
Message-ID: <11437@wpi.wpi.edu>
Date: 11 Apr 90 23:40:10 GMT
References: <27810@siemens.siemens.com> <127@demott.COM> <28050@siemens.siemens.com> <11433@wpi.wpi.edu>
Reply-To: jhallen@wpi.wpi.edu (Joseph H Allen)
Organization: Worcester Polytechnic Institute, Worcester ,MA
Lines: 107