*BSD News Article 36407


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.uwa.edu.au!info.curtin.edu.au!maruthan
From: maruthan@cs.curtin.edu.au (Chandrasekaran Maruthanayakam)
Newsgroups: comp.os.386bsd.questions
Subject: Re: how to write a interrupt function in c?
Date: 1 Oct 94 18:03:09 GMT
Organization: Curtin University of Technology
Lines: 74
Message-ID: <maruthan.781034589@marsh>
References: <maruthan.780739386@marsh> <36c7o8$6ag@panix3.panix.com>
NNTP-Posting-Host: massif.mpl.cs.curtin.edu.au

wpaul@panix.com (Bill Paul) writes:

>Daring to challenge the will of the almighty Leviam00se,
>Chandrasekaran Maruthanayakam (maruthan@cs.curtin.edu.au)
>had the courage to say:

>: On DOS platform one can write interrupt functions in C using the standard
>: C compilers. Does any one know how write a interrupt function in C
>: on 386BSD platform?
>: Thanks
>: chandra

>If by 'interrupt functions' you mean BIOS interrupts (INT 21,
>INT 33, etc...), then the answer is: no, nobody knows.

>And you know why they don't know? Because you can't do it. 386BSD, NetBSD,
>FreeBSD, Linux and virtually all other PC UNIX operating systems run
>in 386 (32-bit) protected mode -- the BIOS code only runs in real mode. If
>you're the adventurous type, you could try to implement some sort of
>virtual 8086 support, but this is widely regarded as being a non-trivial
>task.

>Or, if you have time, you can wait for the DOS emulator for FreeBSD to
>be completed. Then you can call all the BIOS interrupts you want.

>Now, if you mean 'interrupt functions' as in hardware interrupts (which I
>don't think you do), then you can take a look at the BSD kernel source
>code and see how the device drivers are written. If you have some new
>or unusual device that isn't supported by BSD and you want to trap
>interrupts from it, then you have to write a driver for it. For devices
>that already have drivers (serial ports, mouses, disk drives) you
>probably shouldn't be trying to trap interrupts in the first place since
>the existing drivers are already handling them.

What I mean by 'interrupt functions' is that I want the C compiler to
generate interrupt return instruction of the processor -- iret -- instead
of return instruction -- ret -- for specified functions. I could do this
on DOS platform using 'interrupt' prefix keyword for a function in C.
I want this type of code generation by the compiler so that I could write
hardware interrupt handler in C itself. This is not useful, of course, if
I were to run such a program on UNIX platform itself. For my needs, 
I have written programs, some in C and some in assembly, and compile, assemble
and link on UNIX platform that I could run my module in protected mode in
stand alone environment with out UNIX or BIOS.  Now I want to see if I could
write hardware interrupt handler in C with out resorting to assembly.

I had a look at BSD kernel source code and came to know how to load global/
interrupt descriptor table register for 386+ intel processor in C iiself
without resorting to assembly. So far I could not see a piece of code which
tells the compiler to generate iret instruction instead of ret instruction.


>I would pick up a few good books on UNIX C programming. Trying to
>implement DOS coding techniques in UNIX is really a waste of time.
>If you can be specific about exactly what it is you want to do then
>I might be able to provide a better comparisson, and maybe an example
>or two.

>(And readers please note that tossing a couple of supposedly highbrow
>buzzwords into your postings and expecting them to help people instantly
>divine the exact nature of your problem/question/situation is *NOT*
>what is meant by being specific. Repeating the buzzwords doesnt do
>any good either. You want exact answers, ask exact questions.)


>-Bill

>--
> _      /\      _            Join the
>/ \_/\_/  \_/\_/ \  .----.   M00se Illuminati   Bill Paul 
>\_____/ () \_____/ (bl00p!)  Face it: wouldn't  <Big City M00se>
>     /      \       `----'   you feel much      wpaul@panix.com   -or-
>    /  \__/  \    --'        safer?             ghod@drycas.club.cc.cmu.edu
>   /__________\