1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
/*
* Procedures for interfacing to the Open Firmware PROM on
* Power Macintosh computers.
*
* Paul Mackerras October 1996.
* Copyright (C) 1996 Paul Mackerras.
*/
#include <stdarg.h>
#include "prom.h"
#include "quik.h"
#define getpromprop(node, name, buf, len) \
((int)call_prom("getprop", 4, 1, (node), (name), (buf), (len)))
ihandle prom_stdin;
ihandle prom_stdout;
ihandle prom_chosen;
ihandle prom_options;
ihandle prom_mmu;
struct prom_args {
char *service;
int nargs;
int nret;
void *args[10];
} prom_args;
void (*prom_entry)(void *);
void
prom_exit()
{
struct prom_args args;
args.service = "exit";
args.nargs = 0;
args.nret = 0;
prom_entry(&args);
for (;;) /* should never get here */
;
}
void *
call_prom(char *service, int nargs, int nret, ...)
{
va_list list;
int i;
prom_args.service = service;
prom_args.nargs = nargs;
prom_args.nret = nret;
va_start(list, nret);
for (i = 0; i < nargs; ++i)
prom_args.args[i] = va_arg(list, void *);
va_end(list);
for (i = 0; i < nret; ++i)
prom_args.args[i + nargs] = 0;
prom_entry(&prom_args);
return prom_args.args[nargs];
}
void
prom_print(char *msg)
{
char *p, *q;
char *crlf = "\r\n";
for (p = msg; *p != 0; p = q) {
for (q = p; *q != 0 && *q != '\n'; ++q)
;
if (q > p)
call_prom("write", 3, 1, prom_stdout, p, q - p);
if (*q != 0) {
++q;
call_prom("write", 3, 1, prom_stdout, crlf, 2);
}
}
}
int
prom_map(unsigned int phys, unsigned int virt, unsigned int size)
{
struct prom_args {
char *service;
int nargs;
int nret;
char *method;
ihandle mmu_ihandle;
int misc;
unsigned int size;
unsigned int virt;
unsigned int phys;
int ret0;
} args;
if (prom_mmu == 0) {
qprintf("map() called, no MMU found\n");
return -1;
}
args.service = "call-method";
args.nargs = 6;
args.nret = 1;
args.method = "map";
args.mmu_ihandle = prom_mmu;
args.misc = 0;
args.phys = phys;
args.virt = virt;
args.size = size;
prom_entry(&args);
return (int)args.ret0;
}
int
putchar(int c)
{
char ch = c;
if (c == '\n')
putchar('\r');
return (int) call_prom("write", 3, 1, prom_stdout, &ch, 1);
}
int
getchar()
{
char ch;
int r;
while ((r = (int) call_prom("read", 3, 1, prom_stdin, &ch, 1)) == 0)
;
return r > 0? ch: -1;
}
int
nbgetchar()
{
char ch;
return (int) call_prom("read", 3, 1, prom_stdin, &ch, 1) > 0? ch: -1;
}
void
prom_init(void (*pp)(void *))
{
prom_entry = pp;
/* First get a handle for the stdout device */
prom_chosen = call_prom("finddevice", 1, 1, "/chosen");
if (prom_chosen == (void *)-1)
prom_exit();
getpromprop(prom_chosen, "stdout", &prom_stdout, sizeof(prom_stdout));
getpromprop(prom_chosen, "stdin", &prom_stdin, sizeof(prom_stdin));
getpromprop(prom_chosen, "mmu", &prom_mmu, sizeof(prom_mmu));
prom_options = call_prom("finddevice", 1, 1, "/options");
}
void
prom_get_chosen(char *name, char *buf, int buflen)
{
buf[0] = 0;
getpromprop(prom_chosen, name, buf, buflen);
}
void
prom_get_options(char *name, char *buf, int buflen)
{
buf[0] = 0;
if (prom_options != (void *) -1)
getpromprop(prom_options, name, buf, buflen);
}
int
get_ms()
{
return (int) call_prom("milliseconds", 0, 1);
}
void
prom_pause()
{
call_prom("enter", 0, 0);
}
void
set_bootargs(char *params)
{
call_prom("setprop", 4, 1, prom_chosen, "bootargs", params,
qstrlen(params) + 1);
}
|