2 * Copyright (C) 2010 Nathan Whitehorn
3 * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
34 #include <machine/cpufunc.h>
36 #include "bootstrap.h"
39 #include "ps3devdesc.h"
41 struct arch_switch archsw;
44 extern char bootprog_info[];
46 int ps3_getdev(void **vdev, const char *devspec, const char **path);
47 ssize_t ps3_copyin(const void *src, vm_offset_t dest, const size_t len);
48 ssize_t ps3_copyout(vm_offset_t src, void *dest, const size_t len);
49 ssize_t ps3_readin(const int fd, vm_offset_t dest, const size_t len);
50 int ps3_autoload(void);
51 int ps3_setcurrdev(struct env_var *ev, int flags, const void *value);
53 static uint64_t basetb;
61 struct ps3_devdesc currdev;
64 lv1_get_physmem(&maxmem);
74 * Set the heap to one page after the end of the loader.
76 heapbase = (void *)(maxmem - 0x80000);
77 setheap(heapbase, maxmem);
80 * March through the device switch probing for things.
82 for (i = 0; devsw[i] != NULL; i++) {
83 if (devsw[i]->dv_init != NULL) {
84 err = (devsw[i]->dv_init)();
86 printf("\n%s: initialization failed err=%d\n",
87 devsw[i]->dv_name, err);
92 currdev.d_dev = devsw[i];
93 currdev.d_type = currdev.d_dev->dv_type;
95 if (strcmp(devsw[i]->dv_name, "cd") == 0) {
96 f.f_devdata = &currdev;
99 if (devsw[i]->dv_open(&f, &currdev) == 0)
103 if (strcmp(devsw[i]->dv_name, "disk") == 0) {
104 f.f_devdata = &currdev;
106 currdev.d_disk.pnum = 1;
107 currdev.d_disk.ptype = PTYPE_GPT;
109 if (devsw[i]->dv_open(&f, &currdev) == 0)
113 if (strcmp(devsw[i]->dv_name, "net") == 0)
117 if (devsw[i] == NULL)
118 panic("No boot device found!");
120 printf("Boot device: %s\n", devsw[i]->dv_name);
123 * Get timebase at boot.
127 archsw.arch_getdev = ps3_getdev;
128 archsw.arch_copyin = ps3_copyin;
129 archsw.arch_copyout = ps3_copyout;
130 archsw.arch_readin = ps3_readin;
131 archsw.arch_autoload = ps3_autoload;
133 printf("\n%s", bootprog_info);
134 printf("Memory: %lldKB\n", maxmem / 1024);
136 env_setenv("currdev", EV_VOLATILE, ps3_fmtdev(&currdev),
137 ps3_setcurrdev, env_nounset);
138 env_setenv("loaddev", EV_VOLATILE, ps3_fmtdev(&currdev), env_noset,
140 setenv("LINES", "24", 1);
141 setenv("hw.platform", "ps3", 1);
143 interact(NULL); /* doesn't return */
149 ppc_exception(int code, vm_offset_t where, register_t msr)
151 mtmsr(PSL_IR | PSL_DR | PSL_RI);
152 printf("Exception %x at %#lx!\n", code, where);
153 printf("Rebooting in 5 seconds...\n");
158 const u_int ns_per_tick = 12;
172 ttb = tb + howmany(usecs * 1000, ns_per_tick);
180 return ((time_t)((mftb() - basetb)*ns_per_tick/1000000000));
196 ps3_copyin(const void *src, vm_offset_t dest, const size_t len)
198 bcopy(src, (void *)dest, len);
203 ps3_copyout(vm_offset_t src, void *dest, const size_t len)
205 bcopy((void *)src, dest, len);
210 ps3_readin(const int fd, vm_offset_t dest, const size_t len)
213 size_t resid, chunk, get;
219 chunk = min(PAGE_SIZE, len);
222 printf("ps3_readin: buf malloc failed\n");
226 for (resid = len; resid > 0; resid -= got, p += got) {
227 get = min(chunk, resid);
228 got = read(fd, buf, get);
231 printf("ps3_readin: read failed\n");
235 bcopy(buf, (void *)p, got);
239 return (len - resid);