Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / sparc64 / boot.c
1 /*
2  *
3  */
4 #undef BOOTSTRAP
5 #include "config.h"
6 #include "libopenbios/bindings.h"
7 #include "arch/common/nvram.h"
8 #include "libc/diskio.h"
9 #include "libc/vsprintf.h"
10 #include "libopenbios/sys_info.h"
11 #include "boot.h"
12
13 uint64_t kernel_image;
14 uint64_t kernel_size;
15 uint64_t qemu_cmdline;
16 uint64_t cmdline_size;
17 char boot_device;
18
19 extern int sparc64_of_client_interface( int *params );
20
21
22 void go(void)
23 {
24         ucell address, type, size;
25         int image_retval = 0;
26
27         /* Get the entry point and the type (see forth/debugging/client.fs) */
28         feval("saved-program-state >sps.entry @");
29         address = POP();
30         feval("saved-program-state >sps.file-type @");
31         type = POP();
32         feval("saved-program-state >sps.file-size @");
33         size = POP();
34
35         printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type);
36
37         switch (type) {
38                 case 0x0:
39                         /* Start ELF boot image */
40                         image_retval = start_elf(address, (uint64_t)&elf_boot_notes);
41                         break;
42
43                 case 0x1:
44                         /* Start ELF image */
45                         image_retval = start_client_image(address, (uint64_t)&sparc64_of_client_interface);
46                         break;
47
48                 case 0x5:
49                         /* Start a.out image */
50                         image_retval = start_client_image(address, (uint64_t)&sparc64_of_client_interface);
51                         break;
52
53                 case 0x10:
54                         /* Start Fcode image */
55                         printk("Evaluating FCode...\n");
56                         PUSH(address);
57                         PUSH(1);
58                         fword("byte-load");
59                         image_retval = 0;
60                         break;
61
62                 case 0x11:
63                         /* Start Forth image */
64                         PUSH(address);
65                         PUSH(size);
66                         fword("eval2");
67                         image_retval = 0;
68                         break;
69         }
70
71         printk("Image returned with return value %#x\n", image_retval);
72 }
73
74 /* ( path len -- path len ) */
75
76 void boot(void)
77 {
78         char *path, *param;
79
80         /* Copy the incoming path */
81         fword("2dup");
82         path = pop_fstr_copy();
83
84         /* Boot preloaded kernel */
85         if (kernel_size) {
86             void (*entry)(unsigned long p1, unsigned long p2, unsigned long p3,
87                           unsigned long p4, unsigned long p5);
88
89             printk("[sparc64] Kernel already loaded\n");
90             entry = (void *) (unsigned long)kernel_image;
91             entry(0, 0, 0, 0, (unsigned long)&sparc64_of_client_interface);
92         }
93
94         /* Invoke Linux directly -- probably not supported */
95         if(!path) {
96             /* No path specified, so grab defaults from /chosen */
97             push_str("bootpath");
98             push_str("/chosen");
99             fword("(find-dev)");
100             POP();
101             fword("get-package-property");
102             POP();
103             /* Update our local copy of path as well as the one on the stack */
104             fword("2dup");
105             path = pop_fstr_copy();
106         }
107
108         if (path) {
109             param = strchr(path, ' ');
110             if(param) {
111                 *param = '\0';
112                 param++;
113             } else if (cmdline_size) {
114                 param = (char *)qemu_cmdline;
115             } else {
116                 push_str("boot-args");
117                 push_str("/options");
118                 fword("(find-dev)");
119                 POP();
120                 fword("get-package-property");
121                 POP();
122                 param = pop_fstr_copy();
123             }
124
125             /* Invoke platform-specific Linux loader */
126             linux_load(&sys_info, path, param);
127
128             free(path);
129         }
130 }