Work on 32-bit cleanup.

This commit is contained in:
eeh 1998-08-23 15:52:43 +00:00
parent 41fb08c335
commit d395d34886
2 changed files with 529 additions and 678 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ofw_machdep.c,v 1.2 1998/08/13 02:10:47 eeh Exp $ */
/* $NetBSD: ofw_machdep.c,v 1.3 1998/08/23 15:52:43 eeh Exp $ */
/*
* Copyright (C) 1996 Wolfgang Solfrank.
@ -63,14 +63,14 @@ void dk_cleanup __P((void));
static int dk_match_ffs __P((void));
#endif
static int mmuh = -1, memh = -1;
static u_int mmuh = -1, memh = -1;
static int get_mmu_handle __P((void));
static int get_memory_handle __P((void));
static u_int get_mmu_handle __P((void));
static u_int get_memory_handle __P((void));
static int
static u_int
get_mmu_handle() {
int chosen;
u_int chosen;
if ((chosen = OF_finddevice("/chosen")) == -1) {
prom_printf("get_mmu_handle: cannot get /chosen\r\n");
return -1;
@ -82,9 +82,9 @@ get_mmu_handle() {
return mmuh;
}
static int
static u_int
get_memory_handle() {
int chosen;
u_int chosen;
if ((chosen = OF_finddevice("/chosen")) == -1) {
prom_printf("get_mmu_handle: cannot get /chosen\r\n");
return -1;
@ -104,19 +104,17 @@ int
prom_set_trap_table(tba)
vaddr_t tba;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
u_int64_t tba;
} args = {
0,"SUNW,set-trap-table",
1,
0,
NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t tba;
} args;
args.tba = tba;
args.name = ADR2CELL(&"SUNW,set-trap-table");
args.nargs = 1;
args.nreturns = 0;
args.tba = ADR2CELL(tba);
return openfirmware(&args);
}
@ -125,51 +123,43 @@ vaddr_t tba;
*
* Only works while the prom is actively mapping us.
*/
u_int64_t
paddr_t
prom_vtop(vaddr)
vaddr_t vaddr;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t vaddr;
int64_t status;
int64_t retaddr;
int64_t mode;
u_int64_t paddr_hi;
u_int64_t paddr_lo;
} args = {
0,"call-method",
3,
5,
0,"translate",
0, 0,
0, NULL,
0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t vaddr;
cell_t status;
cell_t retaddr;
cell_t mode;
cell_t phys_hi;
cell_t phys_lo;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_vtop: cannot get mmuh\r\n");
return 0LL;
return 0;
}
args.ihandle = mmuh;
args.vaddr = vaddr;
args.name = ADR2CELL(&"call-method");
args.nargs = 3;
args.nreturns = 5;
args.method = ADR2CELL(&"translate");
args.ihandle = HDL2CELL(mmuh);
args.vaddr = ADR2CELL(vaddr);
if(openfirmware(&args) != 0)
return 0LL;
return 0;
#if 0
prom_printf("Called \"translate\", mmuh=%x, vaddr=%x, status=%x %x,\r\n retaddr=%x %x, mode=%x %x, phys_hi=%x %x, phys_lo=%x %x\r\n",
mmuh, vaddr, (int)(args.status>>32), (int)args.status, (int)(args.retaddr>>32), (int)args.retaddr,
(int)(args.mode>>32), (int)args.mode, (int)(args.paddr_hi>>32), (int)args.paddr_hi,
(int)(args.paddr_lo>>32), (int)args.paddr_lo);
#endif
#ifdef INT_IS_64_BITS
return (u_int64_t)((((u_int64_t)args.paddr_hi)<<32)|(u_int64_t)args.paddr_lo);
#else
return args.paddr_lo; /* Kluge till we go 64-bit */
(int)(args.mode>>32), (int)args.mode, (int)(args.phys_hi>>32), (int)args.phys_hi,
(int)(args.phys_lo>>32), (int)args.phys_lo);
#endif
return (paddr_t)((((paddr_t)args.phys_hi)<<32)|(int)args.phys_lo);
}
/*
@ -182,40 +172,34 @@ prom_claim_virt(vaddr, len)
vaddr_t vaddr;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t align;
u_int64_t len;
u_int64_t vaddr;
int64_t status;
int64_t retaddr;
} args = {
0,"call-method",
5,
2,
0,"claim",
0, 0,
0,
0,
NULL,
0,
0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t align;
cell_t len;
cell_t vaddr;
cell_t status;
cell_t retaddr;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_claim_virt: cannot get mmuh\r\n");
return 0LL;
return 0;
}
args.ihandle = mmuh;
args.vaddr = vaddr;
args.name = ADR2CELL(&"call-method");
args.nargs = 5;
args.nreturns = 2;
args.method = ADR2CELL(&"claim");
args.ihandle = HDL2CELL(mmuh);
args.align = 0;
args.len = len;
args.vaddr = ADR2CELL(vaddr);
if(openfirmware(&args) != 0)
return 0LL;
return args.retaddr; /* Kluge till we go 64-bit */
return 0;
return (paddr_t)args.retaddr;
}
/*
@ -229,37 +213,32 @@ int len;
int align;
{
static int retaddr;
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t align;
u_int64_t len;
int64_t status;
int pad4; void* retaddr;
} args = {
0,"call-method",
4,
2,
0,"claim",
0, 0,
0,
0,
0,
0, &retaddr
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t align;
cell_t len;
cell_t status;
cell_t retaddr;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_alloc_virt: cannot get mmuh\r\n");
return -1LL;
}
args.ihandle = mmuh;
args.name = ADR2CELL(&"call-method");
args.nargs = 4;
args.nreturns = 2;
args.method = ADR2CELL(&"claim");
args.ihandle = HDL2CELL(mmuh);
args.align = align;
args.len = len;
args.retaddr = ADR2CELL(&retaddr);
if(openfirmware(&args) != 0)
return -1LL;
return -1;
return retaddr; /* Kluge till we go 64-bit */
}
@ -273,30 +252,26 @@ prom_free_virt(vaddr, len)
vaddr_t vaddr;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t len;
u_int64_t vaddr;
} args = {
0,"call-method",
4,
0,
0,"release",
0, 0,
0,
NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t len;
cell_t vaddr;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_claim_virt: cannot get mmuh\r\n");
return -1;
}
args.ihandle = mmuh;
args.vaddr = vaddr;
args.name = ADR2CELL(&"call-method");
args.nargs = 4;
args.nreturns = 0;
args.method = ADR2CELL(&"release");
args.ihandle = HDL2CELL(mmuh);
args.vaddr = ADR2CELL(vaddr);
args.len = len;
return openfirmware(&args);
}
@ -312,30 +287,26 @@ prom_unmap_virt(vaddr, len)
vaddr_t vaddr;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t len;
u_int64_t vaddr;
} args = {
0,"call-method",
4,
0,
0,"unmap",
0, 0,
0,
NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t len;
cell_t vaddr;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_claim_virt: cannot get mmuh\r\n");
return -1;
}
args.ihandle = mmuh;
args.vaddr = vaddr;
args.name = ADR2CELL(&"call-method");
args.nargs = 4;
args.nreturns = 0;
args.method = ADR2CELL(&"unmap");
args.ihandle = HDL2CELL(mmuh);
args.vaddr = ADR2CELL(vaddr);
args.len = len;
return openfirmware(&args);
}
@ -347,54 +318,41 @@ int len;
*/
int
prom_map_phys(paddr, size, vaddr, mode)
u_int64_t paddr;
paddr_t paddr;
off_t size;
vaddr_t vaddr;
int mode;
{
int phys_hi, phys_lo;
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
int64_t mode;
u_int64_t size;
u_int64_t vaddr;
int pad4; int paddr_hi;
int pad6; int paddr_lo;
int64_t status;
int64_t retaddr;
} args = {
0,"call-method",
7,
1,
0,"map",
0, 0,
0, 0,
0, NULL,
0, NULL,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t mode;
cell_t size;
cell_t vaddr;
cell_t phys_hi;
cell_t phys_lo;
cell_t status;
cell_t retaddr;
} args;
if (mmuh == -1 && ((mmuh = get_mmu_handle()) == -1)) {
prom_printf("prom_map_phys: cannot get mmuh\r\n");
return 0LL;
return 0;
}
#ifdef INT_IS_64_BITS
phys_hi = paddr>>32;
#else
phys_hi = 0; /* This is what Solaris does. We gotta fix this for 64-bits */
#endif
phys_lo = paddr;
args.ihandle = mmuh;
args.name = ADR2CELL(&"call-method");
args.nargs = 7;
args.nreturns = 1;
args.method = ADR2CELL(&"map");
args.ihandle = HDL2CELL(mmuh);
args.mode = mode;
args.size = size;
args.vaddr = vaddr;
args.paddr_hi = phys_hi;
args.paddr_lo = phys_lo;
args.vaddr = ADR2CELL(vaddr);
args.phys_hi = HDL2CELL(paddr>>32);
args.phys_lo = HDL2CELL(paddr);
if (openfirmware(&args) == -1)
return -1;
if (args.status)
@ -408,43 +366,38 @@ int mode;
*
* Only works while the prom is actively mapping us.
*/
u_int64_t
paddr_t
prom_alloc_phys(len, align)
int len;
int align;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t align;
u_int64_t len;
int64_t status;
u_int64_t phys_hi;
u_int64_t phys_lo;
} args = {
0,"call-method",
4,
3,
0,"claim",
0, 0,
0,
0,
0,
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t align;
cell_t len;
cell_t status;
cell_t phys_hi;
cell_t phys_lo;
} args;
if (memh == -1 && ((memh = get_memory_handle()) == -1)) {
prom_printf("prom_alloc_phys: cannot get memh\r\n");
return 0LL;
return 0;
}
args.ihandle = memh;
args.name = ADR2CELL(&"call-method");
args.nargs = 4;
args.nreturns = 3;
args.method = ADR2CELL(&"claim");
args.ihandle = HDL2CELL(memh);
args.align = align;
args.len = len;
if(openfirmware(&args) != 0)
return 0LL;
return args.phys_lo; /* Kluge till we go 64-bit */
return 0;
return (paddr_t)((((paddr_t)args.phys_hi)<<32)|(int)args.phys_lo);
}
/*
@ -452,48 +405,42 @@ int align;
*
* Only works while the prom is actively mapping us.
*/
u_int64_t
paddr_t
prom_claim_phys(phys, len)
paddr_t phys;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t align;
u_int64_t len;
int pad4; u_int32_t phys_hi;
int pad5; u_int32_t phys_lo;
int64_t status;
int64_t res;
u_int64_t rphys_hi;
u_int64_t rphys_lo;
} args = {
0,"call-method",
6,
4,
0,"claim",
0, 0,
0,
0,
0, NULL,
0, NULL,
0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t align;
cell_t len;
cell_t phys_hi;
cell_t phys_lo;
cell_t status;
cell_t res;
cell_t rphys_hi;
cell_t rphys_lo;
} args;
if (memh == -1 && ((memh = get_memory_handle()) == -1)) {
prom_printf("prom_alloc_phys: cannot get memh\r\n");
return 0LL;
return 0;
}
args.ihandle = memh;
args.name = ADR2CELL(&"call-method");
args.nargs = 6;
args.nreturns = 4;
args.method = ADR2CELL(&"claim");
args.ihandle = HDL2CELL(memh);
args.len = len;
args.phys_lo = phys;
args.phys_hi = HDL2CELL(phys>>32);
args.phys_lo = HDL2CELL(phys);
if(openfirmware(&args) != 0)
return 0LL;
return args.rphys_lo; /* Kluge till we go 64-bit */
return 0;
return (paddr_t)((((paddr_t)args.phys_hi)<<32)|(int)args.phys_lo);
}
/*
@ -506,33 +453,29 @@ prom_free_phys(phys, len)
paddr_t phys;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t len;
int pad4; u_int32_t phys_hi;
int pad5; u_int32_t phys_lo;
} args = {
0,"call-method",
5,
0,
0,"release",
0, 0,
0,
0, NULL,
0, NULL,
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t len;
cell_t phys_hi;
cell_t phys_lo;
} args;
if (memh == -1 && ((memh = get_memory_handle()) == -1)) {
prom_printf("prom_free_phys: cannot get memh\r\n");
return -1;
}
args.ihandle = memh;
args.name = ADR2CELL(&"call-method");
args.nargs = 5;
args.nreturns = 0;
args.method = ADR2CELL(&"release");
args.ihandle = HDL2CELL(memh);
args.len = len;
args.phys_lo = phys;
args.phys_hi = HDL2CELL(phys>>32);
args.phys_lo = HDL2CELL(phys);
return openfirmware(&args);
}
@ -541,58 +484,52 @@ int len;
*
* Only works while the prom is actively mapping us.
*/
u_int64_t
paddr_t
prom_get_msgbuf(len, align)
int len;
int align;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t align;
u_int64_t len;
int pad3; char *id;
int64_t status;
int pad4; u_int32_t phys_hi;
int pad5; u_int32_t phys_lo;
} args = {
0,"call-method",
5,
3,
0,"SUNW,retain",
0, 0,
0,
0,
0, "msgbuf",
-1,
0, 0,
0, 0
};
u_int64_t addr;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t align;
cell_t len;
cell_t id;
cell_t status;
cell_t phys_hi;
cell_t phys_lo;
} args;
paddr_t addr;
if (memh == -1 && ((memh = get_memory_handle()) == -1)) {
prom_printf("prom_get_msgbuf: cannot get memh\r\n");
return -1LL;
return -1;
}
args.ihandle = memh;
args.len = len;
args.align = align;
if (OF_test("test-method") == 0) {
if (OF_test_method(memh, "SUNW,retain") != 0) {
args.name = ADR2CELL(&"call-method");
args.nargs = 5;
args.nreturns = 3;
args.method = ADR2CELL(&"SUNW,retain");
args.id = ADR2CELL(&"msgbuf");
args.ihandle = HDL2CELL(memh);
args.len = len;
args.align = align;
args.status = -1;
if (openfirmware(&args) == 0 && args.status == 0) {
return (((u_int64_t)args.phys_hi<<32)|args.phys_lo);
return (((paddr_t)args.phys_hi<<32)|args.phys_lo);
} else prom_printf("prom_get_msgbuf: SUNW,retain failed\r\n");
} else prom_printf("prom_get_msgbuf: test-method failed\r\n");
} else prom_printf("prom_get_msgbuf: test failed\r\n");
/* Allocate random memory */
/* Allocate random memory -- page zero avail?*/
addr = prom_claim_phys(0x2000, len);
prom_printf("prom_get_msgbuf: allocated new buf at %08x\r\n", (int)addr);
if( !addr ) {
prom_printf("prom_get_msgbuf: cannot get allocate physmem\r\n");
return -1LL;
return -1;
}
prom_printf("prom_get_msgbuf: claiming new buf at %08x\r\n", (int)addr);
return addr; /* Kluge till we go 64-bit */
@ -602,14 +539,14 @@ int align;
* Low-level prom I/O routines.
*/
static int stdin = NULL;
static int stdout = NULL;
static u_int stdin = NULL;
static u_int stdout = NULL;
int
OF_stdin()
{
if( stdin == NULL ) {
int chosen;
u_int chosen;
chosen = OF_finddevice("/chosen");
OF_getprop(chosen, "stdout", &stdin, sizeof(stdin));
@ -621,7 +558,7 @@ int
OF_stdout()
{
if( stdout == NULL ) {
int chosen;
u_int chosen;
chosen = OF_finddevice("/chosen");
OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));

View File

@ -1,4 +1,4 @@
/* $NetBSD: openfirm.c,v 1.3 1998/08/13 02:10:47 eeh Exp $ */
/* $NetBSD: openfirm.c,v 1.4 1998/08/23 15:52:44 eeh Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -40,29 +40,23 @@
#define min(x,y) ((x<y)?(x):(y))
/* Prolly never used */
void ofbcopy __P((const void *src, void *dst, size_t len));
int
OF_peer(phandle)
int phandle;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; int sibling;
} args = {
0, "peer",
1,
1,
0, 0,
0, 0
};
args.phandle = phandle;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t sibling;
} args;
args.name = ADR2CELL(&"peer");
args.nargs = 1;
args.nreturns = 1;
args.phandle = HDL2CELL(phandle);
if (openfirmware(&args) == -1)
return 0;
return args.sibling;
@ -72,21 +66,18 @@ int
OF_child(phandle)
int phandle;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; int child;
} args = {
0, "child",
1,
1,
0, 0,
0, 0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t child;
} args;
args.phandle = phandle;
args.name = ADR2CELL(&"child");
args.nargs = 1;
args.nreturns = 1;
args.phandle = HDL2CELL(phandle);
if (openfirmware(&args) == -1)
return 0;
return args.child;
@ -96,21 +87,18 @@ int
OF_parent(phandle)
int phandle;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; int parent;
} args = {
0, "parent",
1,
1,
0, 0,
0, 0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t parent;
} args;
args.phandle = phandle;
args.name = ADR2CELL(&"parent");
args.nargs = 1;
args.nreturns = 1;
args.phandle = HDL2CELL(phandle);
if (openfirmware(&args) == -1)
return 0;
return args.parent;
@ -121,20 +109,17 @@ OF_instance_to_package(ihandle)
int ihandle;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int ihandle;
int pad2; int phandle;
} args = {
0, "instance-to-package",
1,
1,
0, 0,
0, 0
};
args.ihandle = ihandle;
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t ihandle;
cell_t phandle;
} args;
args.name = ADR2CELL(&"instance-to-package");
args.nargs = 1;
args.nreturns = 1;
args.ihandle = HDL2CELL(ihandle);
if (openfirmware(&args) == -1)
return -1;
return args.phandle;
@ -145,23 +130,20 @@ OF_getproplen(handle, prop)
int handle;
char *prop;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; char *prop;
int64_t size;
} args = {
0, "getproplen",
2,
1,
0, 0,
0, NULL
};
args.phandle = handle;
args.prop = prop;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t prop;
cell_t size;
} args;
args.name = ADR2CELL(&"getproplen");
args.nargs = 2;
args.nreturns = 1;
args.phandle = HDL2CELL(handle);
args.prop = ADR2CELL(prop);
if (openfirmware(&args) == -1)
return -1;
return args.size;
@ -174,29 +156,25 @@ OF_getprop(handle, prop, buf, buflen)
void *buf;
int buflen;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; char *prop;
int pad3; void *buf;
int64_t buflen;
int64_t size;
} args = {
0, "getprop",
4,
1,
0, 0,
0, NULL,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t prop;
cell_t buf;
cell_t buflen;
cell_t size;
} args;
if (buflen > NBPG)
return -1;
args.phandle = handle;
args.prop = prop;
args.buf = buf;
args.name = ADR2CELL(&"getprop");
args.nargs = 4;
args.nreturns = 1;
args.phandle = HDL2CELL(handle);
args.prop = ADR2CELL(prop);
args.buf = ADR2CELL(buf);
args.buflen = buflen;
if (openfirmware(&args) == -1)
return -1;
@ -207,22 +185,18 @@ int
OF_finddevice(name)
char *name;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *device;
int pad2; int phandle;
} args = {
0, "finddevice",
1,
1,
0, NULL,
0, 0
};
args.device = name;
args.phandle = -1;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t device;
cell_t phandle;
} args;
args.name = ADR2CELL(&"finddevice");
args.nargs = 1;
args.nreturns = 1;
args.device = ADR2CELL(name);
if (openfirmware(&args) == -1)
return -1;
return args.phandle;
@ -234,26 +208,23 @@ OF_instance_to_path(ihandle, buf, buflen)
char *buf;
int buflen;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int ihandle;
int pad2; char *buf;
int64_t buflen;
int64_t length;
} args = {
0,"instance-to-path",
3,
1,
0, 0,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t ihandle;
cell_t buf;
cell_t buflen;
cell_t length;
} args;
if (buflen > NBPG)
return -1;
args.ihandle = ihandle;
args.buf = buf;
args.name = ADR2CELL(&"instance-to-path");
args.nargs = 3;
args.nreturns = 1;
args.ihandle = HDL2CELL(ihandle);
args.buf = ADR2CELL(buf);
args.buflen = buflen;
if (openfirmware(&args) < 0)
return -1;
@ -266,32 +237,32 @@ OF_package_to_path(phandle, buf, buflen)
char *buf;
int buflen;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int phandle;
int pad2; char *buf;
int64_t buflen;
int64_t length;
} args = {
0,"package-to-path",
3,
1,
0, 0,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t phandle;
cell_t buf;
cell_t buflen;
cell_t length;
} args;
if (buflen > NBPG)
return -1;
args.phandle = phandle;
args.buf = buf;
args.name = ADR2CELL(&"package-to-path");
args.nargs = 3;
args.nreturns = 1;
args.phandle = HDL2CELL(phandle);
args.buf = ADR2CELL(buf);
args.buflen = buflen;
if (openfirmware(&args) < 0)
return -1;
return args.length;
}
/*
* The following two functions may need to be re-worked to be 64-bit clean.
*/
int
#ifdef __STDC__
OF_call_method(char *method, int ihandle, int nargs, int nreturns, ...)
@ -305,37 +276,32 @@ OF_call_method(method, ihandle, nargs, nreturns, va_alist)
#endif
{
va_list ap;
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t args_n_results[12];
} args = {
0, "call-method",
2,
1,
0, NULL,
0, 0
};
int *ip, n;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t args_n_results[12];
} args;
long *ip, n;
if (nargs > 6)
return -1;
args.name = ADR2CELL(&"call-method");
args.nargs = nargs + 2;
args.nreturns = nreturns + 1;
args.method = method;
args.ihandle = ihandle;
args.method = HDL2CELL(method);
args.ihandle = HDL2CELL(ihandle);
va_start(ap, nreturns);
for (ip = (int*)(args.args_n_results + (n = nargs)); --n >= 0;)
*--ip = va_arg(ap, int);
for (ip = (long*)(args.args_n_results + (n = nargs)); --n >= 0;)
*--ip = va_arg(ap, unsigned long);
if (openfirmware(&args) == -1)
return -1;
if (args.args_n_results[nargs])
return args.args_n_results[nargs];
for (ip = (int*)(args.args_n_results + nargs + (n = args.nreturns)); --n > 0;)
*va_arg(ap, int *) = *--ip;
for (ip = (long*)(args.args_n_results + nargs + (n = args.nreturns)); --n > 0;)
*va_arg(ap, unsigned long *) = *--ip;
va_end(ap);
return 0;
}
@ -352,30 +318,26 @@ OF_call_method_1(method, ihandle, nargs, va_alist)
#endif
{
va_list ap;
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *method;
int pad2; int ihandle;
u_int64_t args_n_results[16];
} args = {
0, "call-method",
2,
1,
0, NULL,
0, 0
};
int *ip, n;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t method;
cell_t ihandle;
cell_t args_n_results[16];
} args;
long *ip, n;
if (nargs > 6)
return -1;
args.name = ADR2CELL(&"call-method");
args.nargs = nargs + 2;
args.method = method;
args.ihandle = ihandle;
args.nreturns = 1;
args.method = HDL2CELL(method);
args.ihandle = HDL2CELL(ihandle);
va_start(ap, nargs);
for (ip = (int*)(args.args_n_results + (n = nargs)); --n >= 0;)
*--ip = va_arg(ap, int);
for (ip = (long*)(args.args_n_results + (n = nargs)); --n >= 0;)
*--ip = va_arg(ap, unsigned long);
va_end(ap);
if (openfirmware(&args) == -1)
return -1;
@ -388,24 +350,21 @@ int
OF_open(dname)
char *dname;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *dname;
int pad2; int handle;
} args = {
0, "open",
1,
1,
0, NULL,
0, 0
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t dname;
cell_t handle;
} args;
int l;
if ((l = strlen(dname)) >= NBPG)
return -1;
args.dname = dname;
args.name = ADR2CELL(&"open");
args.nargs = 1;
args.nreturns = 1;
args.dname = ADR2CELL(dname);
if (openfirmware(&args) == -1)
return -1;
return args.handle;
@ -415,19 +374,17 @@ void
OF_close(handle)
int handle;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int handle;
} args = {
0, "close",
1,
0,
0, 0
};
args.handle = handle;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t handle;
} args;
args.name = ADR2CELL(&"close");
args.nargs = 1;
args.nreturns = 0;
args.handle = HDL2CELL(handle);
openfirmware(&args);
}
@ -435,20 +392,18 @@ int
OF_test(service)
char* service;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *service;
int64_t status;
} args = {
0, "test",
1,
1,
0, NULL
};
args.service = service;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t service;
cell_t status;
} args;
args.name = ADR2CELL(&"test");
args.nargs = 1;
args.nreturns = 1;
args.service = ADR2CELL(service);
if (openfirmware(&args) == -1)
return -1;
return args.status;
@ -459,24 +414,20 @@ OF_test_method(service, method)
int service;
char* method;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int service;
int pad2; char *method;
int64_t status;
} args = {
0, "test-method",
2,
1,
0, 0,
0, 0,
-1
};
args.service = service;
args.method = method;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t service;
cell_t method;
cell_t status;
} args;
args.name = ADR2CELL(&"test-method");
args.nargs = 2;
args.nreturns = 1;
args.service = HDL2CELL(service);
args.method = ADR2CELL(method);
openfirmware(&args);
return args.status;
}
@ -491,25 +442,22 @@ OF_read(handle, addr, len)
void *addr;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int ihandle;
int pad2; void *addr;
int64_t len;
int64_t actual;
} args = {
0, "read",
3,
1,
0, 0,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t ihandle;
cell_t addr;
cell_t len;
cell_t actual;
} args;
int l, act = 0;
args.ihandle = handle;
args.addr = addr;
args.name = ADR2CELL(&"read");
args.nargs = 3;
args.nreturns = 1;
args.ihandle = HDL2CELL(handle);
args.addr = ADR2CELL(addr);
for (; len > 0; len -= l, addr += l) {
l = min(NBPG, len);
args.len = l;
@ -533,25 +481,22 @@ OF_write(handle, addr, len)
void *addr;
int len;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int ihandle;
int pad2; void *addr;
int64_t len;
int64_t actual;
} args = {
0, "write",
3,
1,
0, 0,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t ihandle;
cell_t addr;
cell_t len;
cell_t actual;
} args;
int l, act = 0;
args.ihandle = handle;
args.addr = addr;
args.name = ADR2CELL(&"write");
args.nargs = 3;
args.nreturns = 1;
args.ihandle = HDL2CELL(handle);
args.addr = ADR2CELL(addr);
for (; len > 0; len -= l, addr += l) {
l = min(NBPG, len);
args.len = l;
@ -569,24 +514,22 @@ OF_seek(handle, pos)
int handle;
u_quad_t pos;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; int handle;
u_int64_t poshi;
u_int64_t poslo;
int64_t status;
} args = {
0, "seek",
3,
1,
0, 0
};
args.handle = handle;
args.poshi = (unsigned int)(pos >> 32);
args.poslo = (unsigned int)pos;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t handle;
cell_t poshi;
cell_t poslo;
cell_t status;
} args;
args.name = ADR2CELL(&"seek");
args.nargs = 3;
args.nreturns = 1;
args.handle = HDL2CELL(handle);
args.poshi = HDL2CELL(pos >> 32);
args.poslo = HDL2CELL(pos);
if (openfirmware(&args) == -1)
return -1;
return args.status;
@ -596,22 +539,20 @@ void
OF_boot(bootspec)
char *bootspec;
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; char *bootspec;
} args = {
0, "boot",
1,
0,
0, NULL
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t bootspec;
} args;
int l;
if ((l = strlen(bootspec)) >= NBPG)
panic("OF_boot");
args.bootspec = bootspec;
args.name = ADR2CELL(&"boot");
args.nargs = 1;
args.nreturns = 0;
args.bootspec = ADR2CELL(bootspec);
openfirmware(&args);
panic("OF_boot failed");
}
@ -619,32 +560,30 @@ OF_boot(bootspec)
void
OF_enter()
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
} args = {
0, "enter",
0,
0,
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
} args;
args.name = ADR2CELL(&"enter");
args.nargs = 0;
args.nreturns = 0;
openfirmware(&args);
}
void
OF_exit()
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
} args = {
0, "exit",
0,
0,
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
} args;
args.name = ADR2CELL(&"exit");
args.nargs = 0;
args.nreturns = 0;
openfirmware(&args);
panic("OF_exit failed");
}
@ -652,16 +591,15 @@ OF_exit()
void
OF_poweroff()
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
} args = {
0, "SUNW,power-off",
0,
0,
};
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
} args;
args.name = ADR2CELL(&"SUNW,power-off");
args.nargs = 0;
args.nreturns = 0;
openfirmware(&args);
panic("OF_poweroff failed");
}
@ -670,44 +608,20 @@ void
(*OF_set_callback(newfunc))()
void (*newfunc)();
{
static struct {
int pad0; char *name;
int64_t nargs;
int64_t nreturns;
int pad1; void (*newfunc)();
int pad2; void (*oldfunc)();
} args = {
0, "set-callback",
1,
1,
0, NULL,
0, NULL,
};
args.newfunc = newfunc;
struct {
cell_t name;
cell_t nargs;
cell_t nreturns;
cell_t newfunc;
cell_t oldfunc;
} args;
args.name = ADR2CELL(&"set-callback");
args.nargs = 1;
args.nreturns = 1;
args.newfunc = ADR2CELL(newfunc);
if (openfirmware(&args) == -1)
return 0;
return args.oldfunc;
return (void*)(long)args.oldfunc;
}
/*
* This version of bcopy doesn't work for overlapping regions!
*/
void
ofbcopy(src, dst, len)
const void *src;
void *dst;
size_t len;
{
const char *sp = src;
char *dp = dst;
if (src == dst)
return;
/*
* Do some optimization? XXX
*/
while (len-- > 0)
*dp++ = *sp++;
}