Fix Unix target build
[openbios.git] / arch / sparc32 / boot.c
blob12516fd2fae3c226a8b69138ce81f539ee3107b1
1 /*
3 */
4 #undef BOOTSTRAP
5 #include "config.h"
6 #include "libopenbios/bindings.h"
7 #include "arch/common/nvram.h"
8 #include "drivers/drivers.h"
9 #include "libc/diskio.h"
10 #include "libc/vsprintf.h"
11 #include "libopenbios/sys_info.h"
12 #include "openprom.h"
13 #include "boot.h"
14 #include "context.h"
16 uint32_t kernel_image;
17 uint32_t kernel_size;
18 uint32_t qemu_cmdline;
19 uint32_t cmdline_size;
20 char boot_device;
21 const void *romvec;
23 void go(void)
25 ucell address, type, size;
26 int image_retval = 0, proplen, unit, part;
27 phandle_t chosen;
28 char *prop, *id, bootid;
29 static char bootpathbuf[128], bootargsbuf[128], buf[128];
31 /* Get the entry point and the type (see forth/debugging/client.fs) */
32 feval("saved-program-state >sps.entry @");
33 address = POP();
34 feval("saved-program-state >sps.file-type @");
35 type = POP();
36 feval("saved-program-state >sps.file-size @");
37 size = POP();
39 /* SPARC32 is slightly unusual in that before invoking any loaders, a romvec array
40 needs to be set up to pass certain parameters using a C struct. Hence this section
41 extracts the relevant boot information and places it in obp_arg. */
43 /* Get the name of the selected boot device, along with the device and unit number */
44 chosen = find_dev("/chosen");
45 prop = get_property(chosen, "bootpath", &proplen);
46 strncpy(bootpathbuf, prop, proplen);
47 prop = get_property(chosen, "bootargs", &proplen);
48 strncpy(bootargsbuf, prop, proplen);
50 /* Set bootpath pointer used in romvec table to the bootpath */
51 bootpath = bootpathbuf;
53 if (!strcmp(bootpathbuf, "cdrom") || !strcmp(bootpathbuf, "disk")) {
55 /* Controller currently always 0 */
56 obp_arg.boot_dev_ctrl = 0;
58 /* Grab the device and unit number string (in form unit,partition) */
59 push_str(bootpathbuf);
60 feval("pathres-resolve-aliases ascii @ right-split 2drop");
61 id = pop_fstr_copy();
63 /* A bit hacky, but we have no atoi() function */
64 unit = id[0] - '0';
65 part = id[2] - '0';
67 obp_arg.boot_dev_unit = unit;
68 obp_arg.dev_partition = part;
70 /* Generate the "oldpath"
71 FIXME: hardcoding this looks almost definitely wrong.
72 With sd(0,2,0):b we get to see the solaris kernel though */
73 if (!strcmp(bootpathbuf, "disk"))
74 bootid = 'd';
75 else
76 bootid = 'b';
78 snprintf(buf, sizeof(buf), "sd(0,%d,%d):%c", unit, part, bootid);
80 obp_arg.boot_dev[0] = buf[0];
81 obp_arg.boot_dev[1] = buf[1];
82 obp_arg.argv[0] = buf;
83 obp_arg.argv[1] = bootargsbuf;
85 } else if (!strcmp(bootpathbuf, "floppy")) {
87 obp_arg.boot_dev_ctrl = 0;
88 obp_arg.boot_dev_unit = 0;
89 obp_arg.dev_partition = 0;
91 strcpy(buf, "fd()");
93 obp_arg.boot_dev[0] = buf[0];
94 obp_arg.boot_dev[1] = buf[1];
95 obp_arg.argv[0] = buf;
96 obp_arg.argv[1] = bootargsbuf;
98 } else if (!strcmp(bootpathbuf, "net")) {
100 obp_arg.boot_dev_ctrl = 0;
101 obp_arg.boot_dev_unit = 0;
102 obp_arg.dev_partition = 0;
104 strcpy(buf, "le()");
106 obp_arg.boot_dev[0] = buf[0];
107 obp_arg.boot_dev[1] = buf[1];
108 obp_arg.argv[0] = buf;
109 obp_arg.argv[1] = bootargsbuf;
113 printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type);
115 switch (type) {
116 case 0x0:
117 /* Start ELF boot image */
118 image_retval = start_elf((unsigned long)address,
119 (unsigned long)romvec);
121 break;
123 case 0x1:
124 /* Start ELF image */
125 image_retval = start_elf((unsigned long)address,
126 (unsigned long)romvec);
128 break;
130 case 0x5:
131 /* Start a.out image */
132 image_retval = start_elf((unsigned long)address,
133 (unsigned long)romvec);
135 break;
137 case 0x10:
138 /* Start Fcode image */
139 printk("Evaluating FCode...\n");
140 PUSH(address);
141 PUSH(1);
142 fword("byte-load");
143 image_retval = 0;
144 break;
146 case 0x11:
147 /* Start Forth image */
148 PUSH(address);
149 PUSH(size);
150 fword("eval2");
151 image_retval = 0;
152 break;
155 printk("Image returned with return value %#x\n", image_retval);
159 void boot(void)
161 /* Boot preloaded kernel */
162 if (kernel_size) {
163 printk("[sparc] Kernel already loaded\n");
164 start_elf(kernel_image, (unsigned long)romvec);