Home | History | Annotate | Line # | Download | only in common
prom.c revision 1.1
      1  1.1  cgd /*	$NetBSD: prom.c,v 1.1 1997/01/24 01:52:57 cgd 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.1  cgd 
     34  1.1  cgd int console;
     35  1.1  cgd 
     36  1.1  cgd void
     37  1.1  cgd init_prom_calls()
     38  1.1  cgd {
     39  1.1  cgd 	extern struct prom_vec prom_dispatch_v;
     40  1.1  cgd 	struct rpb *r;
     41  1.1  cgd 	struct crb *c;
     42  1.1  cgd 	char buf[4];
     43  1.1  cgd 
     44  1.1  cgd 	r = (struct rpb *)HWRPB_ADDR;
     45  1.1  cgd 	c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
     46  1.1  cgd 
     47  1.1  cgd 	prom_dispatch_v.routine_arg = c->crb_v_dispatch;
     48  1.1  cgd 	prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
     49  1.1  cgd 
     50  1.1  cgd 	/* Look for console tty. */
     51  1.1  cgd 	prom_getenv(PROM_E_TTY_DEV, buf, 4);
     52  1.1  cgd 	console = buf[0] - '0';
     53  1.1  cgd }
     54  1.1  cgd 
     55  1.1  cgd int
     56  1.1  cgd getchar()
     57  1.1  cgd {
     58  1.1  cgd 	prom_return_t ret;
     59  1.1  cgd 
     60  1.1  cgd 	for (;;) {
     61  1.1  cgd 		ret.bits = prom_dispatch(PROM_R_GETC, console);
     62  1.1  cgd 		if (ret.u.status == 0 || ret.u.status == 1)
     63  1.1  cgd 			return (ret.u.retval);
     64  1.1  cgd 	}
     65  1.1  cgd }
     66  1.1  cgd 
     67  1.1  cgd void
     68  1.1  cgd putchar(c)
     69  1.1  cgd 	int c;
     70  1.1  cgd {
     71  1.1  cgd 	prom_return_t ret;
     72  1.1  cgd 	char cbuf;
     73  1.1  cgd 
     74  1.1  cgd 	if (c == '\r' || c == '\n') {
     75  1.1  cgd 		cbuf = '\r';
     76  1.1  cgd 		do {
     77  1.1  cgd 			ret.bits = prom_dispatch(PROM_R_PUTS, console,
     78  1.1  cgd 			    &cbuf, 1);
     79  1.1  cgd 		} while ((ret.u.retval & 1) == 0);
     80  1.1  cgd 		cbuf = '\n';
     81  1.1  cgd 	} else
     82  1.1  cgd 		cbuf = c;
     83  1.1  cgd 	do {
     84  1.1  cgd 		ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
     85  1.1  cgd 	} while ((ret.u.retval & 1) == 0);
     86  1.1  cgd }
     87  1.1  cgd 
     88  1.1  cgd int
     89  1.1  cgd prom_getenv(id, buf, len)
     90  1.1  cgd 	int id, len;
     91  1.1  cgd 	char *buf;
     92  1.1  cgd {
     93  1.1  cgd 	prom_return_t ret;
     94  1.1  cgd 
     95  1.1  cgd 	ret.bits = prom_dispatch(PROM_R_GETENV, id, buf, len-1);
     96  1.1  cgd 	if (ret.u.status & 0x4)
     97  1.1  cgd 		ret.u.retval = 0;
     98  1.1  cgd 	buf[ret.u.retval] = '\0';
     99  1.1  cgd 
    100  1.1  cgd 	return (ret.u.retval);
    101  1.1  cgd }
    102  1.1  cgd 
    103  1.1  cgd int
    104  1.1  cgd prom_open(dev, len)
    105  1.1  cgd 	char *dev;
    106  1.1  cgd 	int len;
    107  1.1  cgd {
    108  1.1  cgd 	prom_return_t ret;
    109  1.1  cgd 
    110  1.1  cgd 	ret.bits = prom_dispatch(PROM_R_OPEN, dev, len);
    111  1.1  cgd 	if (ret.u.status & 0x4)
    112  1.1  cgd 		return (-1);
    113  1.1  cgd 	else
    114  1.1  cgd 		return (ret.u.retval);
    115  1.1  cgd }
    116