1 /* $NetBSD: Locore.c,v 1.22 2006/08/05 21:26:48 sanjayl Exp $ */
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <lib/libsa/stand.h>
36 #include <machine/cpu.h>
37 #include <machine/stdarg.h>
41 static int (*openfirmware
)(void *);
43 static void startup(void *, int, int (*)(void *), char *, int)
44 __attribute__((__used__
));
45 static void setup(void);
47 static int stack
[8192/4 + 4] __attribute__((__used__
));
54 " .long _start,0,0 \n"
56 #endif /* XCOFF_GLUE */
64 " lis %r1,stack@ha \n"
65 " addi %r1,%r1,stack@l \n"
66 " addi %r1,%r1,8192 \n"
82 " li %r9,0x12 \n" /* BATL(0, BAT_M, BAT_PP_RW) */
85 " li %r9,0x1ffe \n" /* BATU(0, BAT_BL_256M, BAT_Vs) */
94 * Make sure that .bss is zeroed
98 " lis %r8,_edata@ha \n"
99 " addi %r8,%r8,_edata@l\n"
100 " lis %r9,_end@ha \n"
101 " addi %r9,%r9,_end@l \n"
103 "5: cmpw 0,%r8,%r9 \n"
114 openfirmware(void *arg
)
117 __asm
volatile ("sync; isync");
118 openfirmware_entry(arg
);
119 __asm
volatile ("sync; isync");
124 startup(void *vpd
, int res
, int (*openfirm
)(void *), char *arg
, int argl
)
127 openfirmware
= openfirm
;
147 for (;;); /* just in case */
151 OF_finddevice(const char *name
)
166 if (openfirmware(&args
) == -1)
172 OF_instance_to_package(int ihandle
)
181 "instance-to-package",
186 args
.ihandle
= ihandle
;
187 if (openfirmware(&args
) == -1)
193 OF_getprop(int handle
, const char *prop
, void *buf
, int buflen
)
210 args
.phandle
= handle
;
213 args
.buflen
= buflen
;
214 if (openfirmware(&args
) == -1)
219 #ifdef __notyet__ /* Has a bug on FirePower */
221 OF_setprop(int handle
, const char *prop
, void *buf
, int len
)
238 args
.phandle
= handle
;
242 if (openfirmware(&args
) == -1)
249 OF_open(const char *dname
)
264 printf("OF_open(%s) -> ", dname
);
267 if (openfirmware(&args
) == -1 ||
275 printf("%d\n", args
.handle
);
295 printf("OF_close(%d)\n", handle
);
297 args
.handle
= handle
;
302 OF_write(int handle
, void *addr
, int len
)
320 printf("OF_write(%d, %p, %x) -> ", handle
, addr
, len
);
322 args
.ihandle
= handle
;
325 if (openfirmware(&args
) == -1) {
333 printf("%x\n", args
.actual
);
339 OF_read(int handle
, void *addr
, int len
)
357 printf("OF_read(%d, %p, %x) -> ", handle
, addr
, len
);
359 args
.ihandle
= handle
;
362 if (openfirmware(&args
) == -1) {
370 printf("%x\n", args
.actual
);
376 OF_seek(int handle
, u_quad_t pos
)
393 printf("OF_seek(%d, %x, %x) -> ", handle
, (int)(pos
>> 32), (int)pos
);
395 args
.handle
= handle
;
396 args
.poshi
= (int)(pos
>> 32);
397 args
.poslo
= (int)pos
;
398 if (openfirmware(&args
) == -1) {
405 printf("%d\n", args
.status
);
411 OF_claim(void *virt
, u_int size
, u_int align
)
428 printf("OF_claim(%p, %x, %x) -> ", virt
, size
, align
);
433 if (openfirmware(&args
) == -1) {
440 printf("%p\n", args
.baseaddr
);
442 return args
.baseaddr
;
446 OF_release(void *virt
, u_int size
)
461 printf("OF_release(%p, %x)\n", virt
, size
);
469 OF_milliseconds(void)
488 OF_chain(void *virt
, u_int size
, void (*entry
)(), void *arg
, u_int len
)
514 OF_chain(void *virt
, u_int size
, boot_entry_t entry
, void *arg
, u_int len
)
517 * This is a REALLY dirty hack till the firmware gets this going
520 OF_release(virt
, size
);
522 entry(0, 0, openfirmware
, arg
, len
);
527 OF_call_method(const char *method
, int ihandle
, int nargs
, int nreturns
, ...)
536 int args_n_results
[12];
546 args
.nargs
= nargs
+ 2;
547 args
.nreturns
= nreturns
+ 1;
548 args
.method
= method
;
549 args
.ihandle
= ihandle
;
550 va_start(ap
, nreturns
);
551 for (ip
= args
.args_n_results
+ (n
= nargs
); --n
>= 0;)
552 *--ip
= va_arg(ap
, int);
554 if (openfirmware(&args
) == -1) {
558 if (args
.args_n_results
[nargs
]) {
560 return args
.args_n_results
[nargs
];
562 for (ip
= args
.args_n_results
+ nargs
+ (n
= args
.nreturns
); --n
> 0;)
563 *va_arg(ap
, int *) = *--ip
;
576 if ((chosen
= OF_finddevice("/chosen")) == -1)
578 if (OF_getprop(chosen
, "stdin", &stdin
, sizeof(stdin
)) !=
580 OF_getprop(chosen
, "stdout", &stdout
, sizeof(stdout
)) !=
592 OF_write(stdout
, &ch
, 1);
598 unsigned char ch
= '\0';
601 while ((l
= OF_read(stdin
, &ch
, 1)) != 1)
602 if (l
!= -2 && l
!= 0)