Home | History | Annotate | Line # | Download | only in common
prom.c revision 1.3
      1  1.3  drochner /* $NetBSD: prom.c,v 1.3 1997/09/06 14:03:58 drochner Exp $ */
      2  1.1       cgd 
      3  1.1       cgd /*
      4  1.1       cgd  * Mach Operating System
      5  1.1       cgd  * Copyright (c) 1992 Carnegie Mellon University
      6  1.1       cgd  * All Rights Reserved.
      7  1.1       cgd  *
      8  1.1       cgd  * Permission to use, copy, modify and distribute this software and its
      9  1.1       cgd  * documentation is hereby granted, provided that both the copyright
     10  1.1       cgd  * notice and this permission notice appear in all copies of the
     11  1.1       cgd  * software, derivative works or modified versions, and any portions
     12  1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     13  1.1       cgd  *
     14  1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     16  1.1       cgd  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  1.1       cgd  *
     18  1.1       cgd  * Carnegie Mellon requests users of this software to return to
     19  1.1       cgd  *
     20  1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  1.1       cgd  *  School of Computer Science
     22  1.1       cgd  *  Carnegie Mellon University
     23  1.1       cgd  *  Pittsburgh PA 15213-3890
     24  1.1       cgd  *
     25  1.1       cgd  * any improvements or extensions that they make and grant Carnegie Mellon
     26  1.1       cgd  * the rights to redistribute these changes.
     27  1.1       cgd  */
     28  1.1       cgd 
     29  1.1       cgd #include <sys/types.h>
     30  1.1       cgd 
     31  1.1       cgd #include <machine/prom.h>
     32  1.1       cgd #include <machine/rpb.h>
     33  1.3  drochner 
     34  1.3  drochner #include "common.h"
     35  1.1       cgd 
     36  1.1       cgd int console;
     37  1.1       cgd 
     38  1.1       cgd void
     39  1.1       cgd init_prom_calls()
     40  1.1       cgd {
     41  1.1       cgd 	extern struct prom_vec prom_dispatch_v;
     42  1.1       cgd 	struct rpb *r;
     43  1.1       cgd 	struct crb *c;
     44  1.1       cgd 	char buf[4];
     45  1.1       cgd 
     46  1.1       cgd 	r = (struct rpb *)HWRPB_ADDR;
     47  1.1       cgd 	c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
     48  1.1       cgd 
     49  1.1       cgd 	prom_dispatch_v.routine_arg = c->crb_v_dispatch;
     50  1.1       cgd 	prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
     51  1.1       cgd 
     52  1.1       cgd 	/* Look for console tty. */
     53  1.1       cgd 	prom_getenv(PROM_E_TTY_DEV, buf, 4);
     54  1.1       cgd 	console = buf[0] - '0';
     55  1.1       cgd }
     56  1.1       cgd 
     57  1.1       cgd int
     58  1.1       cgd getchar()
     59  1.1       cgd {
     60  1.1       cgd 	prom_return_t ret;
     61  1.1       cgd 
     62  1.1       cgd 	for (;;) {
     63  1.1       cgd 		ret.bits = prom_dispatch(PROM_R_GETC, console);
     64  1.1       cgd 		if (ret.u.status == 0 || ret.u.status == 1)
     65  1.1       cgd 			return (ret.u.retval);
     66  1.1       cgd 	}
     67  1.1       cgd }
     68  1.1       cgd 
     69  1.1       cgd void
     70  1.1       cgd putchar(c)
     71  1.1       cgd 	int c;
     72  1.1       cgd {
     73  1.1       cgd 	prom_return_t ret;
     74  1.1       cgd 	char cbuf;
     75  1.1       cgd 
     76  1.1       cgd 	if (c == '\r' || c == '\n') {
     77  1.1       cgd 		cbuf = '\r';
     78  1.1       cgd 		do {
     79  1.1       cgd 			ret.bits = prom_dispatch(PROM_R_PUTS, console,
     80  1.1       cgd 			    &cbuf, 1);
     81  1.1       cgd 		} while ((ret.u.retval & 1) == 0);
     82  1.1       cgd 		cbuf = '\n';
     83  1.1       cgd 	} else
     84  1.1       cgd 		cbuf = c;
     85  1.1       cgd 	do {
     86  1.1       cgd 		ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
     87  1.1       cgd 	} while ((ret.u.retval & 1) == 0);
     88  1.1       cgd }
     89  1.1       cgd 
     90  1.1       cgd int
     91  1.1       cgd prom_getenv(id, buf, len)
     92  1.1       cgd 	int id, len;
     93  1.1       cgd 	char *buf;
     94  1.1       cgd {
     95  1.1       cgd 	prom_return_t ret;
     96  1.1       cgd 
     97  1.1       cgd 	ret.bits = prom_dispatch(PROM_R_GETENV, id, buf, len-1);
     98  1.1       cgd 	if (ret.u.status & 0x4)
     99  1.1       cgd 		ret.u.retval = 0;
    100  1.1       cgd 	buf[ret.u.retval] = '\0';
    101  1.1       cgd 
    102  1.1       cgd 	return (ret.u.retval);
    103  1.1       cgd }
    104  1.1       cgd 
    105  1.1       cgd int
    106  1.1       cgd prom_open(dev, len)
    107  1.1       cgd 	char *dev;
    108  1.1       cgd 	int len;
    109  1.1       cgd {
    110  1.1       cgd 	prom_return_t ret;
    111  1.1       cgd 
    112  1.1       cgd 	ret.bits = prom_dispatch(PROM_R_OPEN, dev, len);
    113  1.1       cgd 	if (ret.u.status & 0x4)
    114  1.1       cgd 		return (-1);
    115  1.1       cgd 	else
    116  1.1       cgd 		return (ret.u.retval);
    117  1.1       cgd }
    118