*BSD News Article 1876


Return to BSD News archive

Path: sserve!manuel!munnari.oz.au!uunet!mcsun!Germany.EU.net!unido!adagio!grog
From: grog@adagio.UUCP (Greg Lehey)
Newsgroups: comp.unix.bsd
Subject: Re: How to port some functions to BSDI386
Keywords: driver
Message-ID: <1808@adagio.UUCP>
Date: 11 Jul 92 18:37:57 GMT
References: <1992Jul11.122433.9274@rz.uni-karlsruhe.de>
Organization: LEMIS, Schellnhausen 2, W-6324 Feldatal, Germany
Lines: 91

In article <1992Jul11.122433.9274@rz.uni-karlsruhe.de> walter@etec.uni-karlsruhe.de (Reiner Walter) writes:
>
>I have to port a device driver from INTERACTIVE to BSDI386.
>
>There are some functions where I don't know how to port them.
>
>1) the driver from INTERACTIVE uses the kernel functions
>   inb(addr),outb(addr,data) - read/write 8 bit data from/to device
>   inw(addr),outw(addr,data) - read/write 16 bit data from/to device
>
>   BSDI386 knows only inb and outb but not inw,outw or in,out  
>   But it must be possible to read/write 16 bit data from/to a device.
> 
>   Which function can I use to port inw and outw.

inb, outb, inw and outw are all 386 machine instructions. If you look
at the code for inb (in locore.s),

_inb:	movl	4(%esp),%edx
	# inb	$0x84,%al	# Compaq SystemPro 
	subl	%eax,%eax	# clr eax
	NOP
	inb	%dx,%al
	NOP
	ret

it should be pretty trivial to change the inb to inw, etc.

>2) In the driver's read routine there is:
>
> driverread(dev,uio,flag)
> dev_t dev;
> struct uio *uio;
> int flag; 
> {
>    ...
>    ...
> 
>    timeout(func,arg,time);   /* calls function func after time clock impulses
>                                with the argument arg */
>    if(...)
>    {
>       untimeout(func,arg);  /* cancels the timeout() function */ 
>       longjmp(u.u_qsav,1);  /* How can I port this function */
>    }
> 
>    ...
>    ...
> }
>    u_qsav is a member from the user structure 'u.'
>    BSDI uses the 'uio' structure. But I could not find a equivalent in the uio
>    structure for u.u_qsav.
>    So, how can I port longjmp(u.u_qsav,1).

Well, you're out of luck here. setjmp () and longjmp () do exist, but
they are not used in this way: in System V, systrap () does a
setjmp (u.u_qsav) to provide system calls with a quick exit function of
the nature you show.  This is not done in BSD - I gather it's
considered bad practice.  Porting a driver definitely should not
involve changing the kernel, so you are going to need to find a
different way to do this.

>3)  The driver uses some macros to calculate the physical and virtual pages
>    like svtop,kvtophys,svtopde,ptosv ... which are defined in 
>    /usr/include/sys/immu.h from INTERACTIVE.
>    
>    The driver uses also a command 'vtop' .( it probably calculates virtual
>    to physical pages)                                           
>    I could not find a macro vtop, so I think it must be a kernel function from
>    INTERACTIVE.
>    Can anybody describe this function and how can I port this function.
>    The function is unknown for BSDI386. 

As you have seen, there are significant differences between System V
and BSD. Memory management is another; don't assume that anything maps
one-to-one. I would strongly recommend that you examine the memory
management schemes of BSD/386 (not BSDI386) and, if possible, System V
before proceeding. Note in particular that BSD/386 does not use the
same memory management scheme that 4.3BSD uses, so reading the daemon
book won't help much.  Assuming that vtop () really does do address
translation, you need to understand what the complete code does before
you can even think of a BSD equivalent.  *Then* you need to work out
how to achieve the same result with BSD/386.

If you want you can call me up and I will see if I can do any more to
help.
-- 
-------------------------------------------------------------------------------
Greg Lehey                       | Tel: +49-6637-1488              
LEMIS                            | Fax: +49-6637-1489
*** NOTE ***: Headers are mangled - reply to grog%lemis@Germany.EU.net