Home | History | Annotate | Line # | Download | only in common
prom.c revision 1.10
      1  1.10       cgd /* $NetBSD: prom.c,v 1.10 1999/04/02 03:11: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.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.10       cgd #if !defined(NO_GETCHAR) || !defined(NO_PUTCHAR_HALT)
     39  1.10       cgd static int test_getchar(int *);
     40  1.10       cgd #endif
     41  1.10       cgd static void putonechar(int c);
     42   1.4      ross 
     43   1.1       cgd void
     44   1.1       cgd init_prom_calls()
     45   1.1       cgd {
     46   1.1       cgd 	extern struct prom_vec prom_dispatch_v;
     47   1.1       cgd 	struct rpb *r;
     48   1.1       cgd 	struct crb *c;
     49   1.1       cgd 	char buf[4];
     50   1.1       cgd 
     51   1.1       cgd 	r = (struct rpb *)HWRPB_ADDR;
     52   1.1       cgd 	c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
     53   1.1       cgd 
     54   1.1       cgd 	prom_dispatch_v.routine_arg = c->crb_v_dispatch;
     55   1.1       cgd 	prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
     56   1.1       cgd 
     57   1.1       cgd 	/* Look for console tty. */
     58   1.1       cgd 	prom_getenv(PROM_E_TTY_DEV, buf, 4);
     59   1.1       cgd 	console = buf[0] - '0';
     60   1.1       cgd }
     61   1.1       cgd 
     62  1.10       cgd #if !defined(NO_GETCHAR) || !defined(NO_PUTCHAR_HALT)
     63   1.4      ross static int
     64  1.10       cgd test_getchar(xc)
     65   1.4      ross 	int *xc;
     66   1.4      ross {
     67  1.10       cgd 	prom_return_t ret;
     68  1.10       cgd 
     69  1.10       cgd 	ret.bits = prom_dispatch(PROM_R_GETC, console);
     70  1.10       cgd 	*xc = ret.u.retval;
     71  1.10       cgd 	return ret.u.status == 0 || ret.u.status == 1;
     72   1.4      ross }
     73  1.10       cgd #endif
     74   1.4      ross 
     75  1.10       cgd #if !defined(NO_GETCHAR)
     76   1.1       cgd int
     77   1.1       cgd getchar()
     78   1.1       cgd {
     79   1.4      ross 	int c;
     80   1.1       cgd 
     81   1.1       cgd 	for (;;) {
     82  1.10       cgd 		if (test_getchar(&c)) {
     83   1.4      ross 			if (c == 3)
     84   1.4      ross 				halt();
     85   1.4      ross 			return c;
     86   1.4      ross 		}
     87   1.1       cgd 	}
     88   1.1       cgd }
     89  1.10       cgd #endif
     90  1.10       cgd 
     91  1.10       cgd static void
     92  1.10       cgd putonechar(c)
     93  1.10       cgd 	int c;
     94  1.10       cgd {
     95  1.10       cgd 	prom_return_t ret;
     96  1.10       cgd 	char cbuf = c;
     97  1.10       cgd 
     98  1.10       cgd 	do {
     99  1.10       cgd 		ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
    100  1.10       cgd 	} while ((ret.u.retval & 1) == 0);
    101  1.10       cgd }
    102   1.1       cgd 
    103   1.9      ross void
    104   1.9      ross putchar(c)
    105   1.6       cgd 	int c;
    106   1.6       cgd {
    107  1.10       cgd #if !defined(NO_PUTCHAR_HALT)
    108   1.9      ross 	int typed_c;
    109  1.10       cgd #endif
    110   1.6       cgd 
    111   1.9      ross 	if (c == '\r' || c == '\n') {
    112  1.10       cgd 		putonechar('\r');
    113  1.10       cgd 		c = '\n';
    114  1.10       cgd 	}
    115  1.10       cgd 	putonechar(c);
    116  1.10       cgd #if !defined(NO_PUTCHAR_HALT)
    117  1.10       cgd 	if (test_getchar(&typed_c))
    118   1.4      ross 		if (typed_c == 3)
    119   1.4      ross 			halt();
    120  1.10       cgd #endif
    121   1.1       cgd }
    122   1.1       cgd 
    123   1.1       cgd int
    124   1.1       cgd prom_getenv(id, buf, len)
    125   1.1       cgd 	int id, len;
    126   1.1       cgd 	char *buf;
    127   1.1       cgd {
    128   1.1       cgd 	prom_return_t ret;
    129   1.1       cgd 
    130   1.1       cgd 	ret.bits = prom_dispatch(PROM_R_GETENV, id, buf, len-1);
    131   1.1       cgd 	if (ret.u.status & 0x4)
    132   1.1       cgd 		ret.u.retval = 0;
    133   1.1       cgd 	buf[ret.u.retval] = '\0';
    134   1.1       cgd 
    135   1.1       cgd 	return (ret.u.retval);
    136   1.1       cgd }
    137