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_name[];
45 extern char bootprog_rev[];
46 extern char bootprog_date[];
47 extern char bootprog_maker[];
49 int ps3_getdev(void **vdev, const char *devspec, const char **path);
50 ssize_t ps3_copyin(const void *src, vm_offset_t dest, const size_t len);
51 ssize_t ps3_copyout(vm_offset_t src, void *dest, const size_t len);
52 ssize_t ps3_readin(const int fd, vm_offset_t dest, const size_t len);
53 int ps3_autoload(void);
54 int ps3_setcurrdev(struct env_var *ev, int flags, const void *value);
56 static uint64_t basetb;
64 struct ps3_devdesc currdev;
67 lv1_get_physmem(&maxmem);
77 * Set the heap to one page after the end of the loader.
79 heapbase = (void *)(maxmem - 0x80000);
80 setheap(heapbase, maxmem);
83 * March through the device switch probing for things.
85 for (i = 0; devsw[i] != NULL; i++) {
86 if (devsw[i]->dv_init != NULL) {
87 err = (devsw[i]->dv_init)();
89 printf("\n%s: initialization failed err=%d\n",
90 devsw[i]->dv_name, err);
95 currdev.d_dev = devsw[i];
96 currdev.d_type = currdev.d_dev->dv_type;
98 if (strcmp(devsw[i]->dv_name, "cd") == 0) {
99 f.f_devdata = &currdev;
102 if (devsw[i]->dv_open(&f, &currdev) == 0)
106 if (strcmp(devsw[i]->dv_name, "disk") == 0) {
107 f.f_devdata = &currdev;
109 currdev.d_disk.pnum = 1;
110 currdev.d_disk.ptype = PTYPE_GPT;
112 if (devsw[i]->dv_open(&f, &currdev) == 0)
116 if (strcmp(devsw[i]->dv_name, "net") == 0)
120 if (devsw[i] == NULL)
121 panic("No boot device found!");
123 printf("Boot device: %s\n", devsw[i]->dv_name);
126 * Get timebase at boot.
130 archsw.arch_getdev = ps3_getdev;
131 archsw.arch_copyin = ps3_copyin;
132 archsw.arch_copyout = ps3_copyout;
133 archsw.arch_readin = ps3_readin;
134 archsw.arch_autoload = ps3_autoload;
137 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
138 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
139 printf("Memory: %lldKB\n", maxmem / 1024);
141 env_setenv("currdev", EV_VOLATILE, ps3_fmtdev(&currdev),
142 ps3_setcurrdev, env_nounset);
143 env_setenv("loaddev", EV_VOLATILE, ps3_fmtdev(&currdev), env_noset,
145 setenv("LINES", "24", 1);
146 setenv("hw.platform", "ps3", 1);
148 interact(); /* doesn't return */
154 ppc_exception(int code, vm_offset_t where, register_t msr)
156 mtmsr(PSL_IR | PSL_DR | PSL_RI);
157 printf("Exception %x at %#lx!\n", code, where);
158 printf("Rebooting in 5 seconds...\n");
163 const u_int ns_per_tick = 12;
177 ttb = tb + (usecs * 1000 + ns_per_tick - 1) / ns_per_tick;
185 return ((mftb() - basetb)*ns_per_tick/1000000000);
201 ps3_copyin(const void *src, vm_offset_t dest, const size_t len)
203 bcopy(src, (void *)dest, len);
208 ps3_copyout(vm_offset_t src, void *dest, const size_t len)
210 bcopy((void *)src, dest, len);
215 ps3_readin(const int fd, vm_offset_t dest, const size_t len)
218 size_t resid, chunk, get;
224 chunk = min(PAGE_SIZE, len);
227 printf("ps3_readin: buf malloc failed\n");
231 for (resid = len; resid > 0; resid -= got, p += got) {
232 get = min(chunk, resid);
233 got = read(fd, buf, get);
236 printf("ps3_readin: read failed\n");
240 bcopy(buf, (void *)p, got);
244 return (len - resid);