*BSD News Article 89773


Return to BSD News archive

Newsgroups: comp.unix.bsd.freebsd.misc
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.netspace.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!news.ececs.uc.edu!news.kei.com!news.mathworks.com!howland.erols.net!ix.netcom.com!squish
From: squish@netcom.com (Michael Almquist)
Subject: HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):
Message-ID: <squishE5xo2n.M2y@netcom.com>
Organization: Netcom
Date: Fri, 21 Feb 1997 03:23:11 GMT
Lines: 83
Sender: squish@netcom3.netcom.com
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:35846

I've checked all the faqs and tried a variety of things and I'm stuck!

I have a program orginally written in Microsoft C that I'm trying to translate
to netBSD 1.1.  I suspect that the porting issues involved are very similar if
I was porting to either BSDi, freeBSD, 386BSD, etc.

The original program makes various calles to "outp", as in:

  outp(BOARD,0); /* disable the timer */

netBSD (and I suspect other 386 unix flavors) don't have a "outp" command.
Digging through a Microsoft C manual I find that "outp" writes a single byte
to a specified I/O port address and is of the form:

  int outp(unsigned port, int byte);

Digging further I read that "outp" is essentially mapped to the assembly
language instruction "OUT".  Grabbing my 386 assembler book I see that "OUT"
is defined as "write to port".  Ah ha!  I'm on the right track - it all fits
together!

However, I am quickly stumped when gcc complains about not understanding the
asm call to "out".  Digging through the netBSD source code I find
"include/pio.h" with asm code for "outb", "outw", and "outl".  Digging further
into the netBSD code I find NUMEROUS calls throughout the kernel code to
"outb", etc.

I get excited and write/steal a simple little program:

#include <stdio.h>
#include <machine/pio.h>

/* from i8042reg.h */
#define KBCMDP          0x64    /* kbd controller port (O) */
#define KBC_PULSE0      0xfe    /* pulse output bit 0 */

main()
{
   /* from arch/i386/i386/machdep.c */
   /* Toggle the hardware reset line on the keyboard controller. */
   outb(KBCMDP, KBC_PULSE0);

}

The program compiles FINE but when I run it I get:
Program received signal SIGBUS (10), Bus error
0x178c in __outb (port=100, data=254 '~') at /usr/include/machine/pio.h:149
149             __asm __volatile("outb %0,%%dx" : : "a" (data), "d" (port));

Every single little program I write "outb (0xd6, 0xc1);" "outb(0x60,0xFF);"
etc crashes with the same error.

So I dig some more. I find microtime.s and use it as an example to write:

#include <machine/asm.h>
#include <dev/isa/isareg.h>
#include "/sys/arch/i386/isa/timerreg.h"

#define KBCMDP          0x64    /* kbd controller port (O) */
#define KBC_PULSE0      0xfe    /* pulse output bit 0 */

ENTRY(resetkbd)
        movb    $(KBCMDP),%al
        outb    %al,$KBC_PULSE0

It compiles fine with "cpp -DLOCORE kbd.s | as -o kbd.o".  I then write a
simple c program and link it to kbd.o:

#include <stdio.h>

main()
{
   resetkbd();
}

It compiles find.  And when I go to run it I get the same bus error!

PLEASE help me out!  I'm tearing my hair out and running out of ideas!  I know
it has to be possible for there is lots of similar code within the netBSD
kernel.  Any help would be greatly appreciated!  Thanks for reading my long
story of woe.

- Mike Almquist (squish@netcom.com)