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