Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / unix / boot.c
1 /*
2  *
3  */
4 #undef BOOTSTRAP
5 #include "config.h"
6 #include "libopenbios/bindings.h"
7 #include "libopenbios/elf_load.h"
8 #include "arch/common/nvram.h"
9 #include "libc/diskio.h"
10
11 void boot(void);
12 void *load_elf(char *spec);
13
14 void
15 *load_elf(char *spec)
16 {
17 #if 0
18         int fd;
19         void *entry=NULL;
20         int i, lszz_offs, elf_offs;
21         char buf[128]; // , *addr;
22         Elf_ehdr ehdr;
23         Elf_phdr *phdr;
24         size_t s;
25
26         if( (fd=open_io(spec)) == -1 )
27                 return NULL;
28
29         if( (elf_offs=find_elf(fd)) < 0 ) {
30                 printk("----> %s is not an ELF image\n", buf );
31                 return NULL;
32         }
33
34         if( !(phdr=elf_readhdrs(fd, 0, &ehdr)) ) {
35                 printk("elf32_readhdrs failed\n");
36                 return NULL;
37         }
38
39         (unsigned long long *)entry = ehdr.e_entry;
40
41         lszz_offs = elf_offs;
42         for( i=0; i<ehdr.e_phnum; i++ ) {
43                 s = MIN( phdr[i].p_filesz, phdr[i].p_memsz );
44                 seek_io( fd, elf_offs + phdr[i].p_offset );
45                 /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n",
46                    phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset,
47                    phdr[i].p_vaddr ); */
48                 if( phdr[i].p_vaddr != phdr[i].p_paddr )
49                         printk("WARNING: ELF segment virtual addr != physical addr\n");
50                 lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz );
51                 if( !s )
52                         continue;
53
54                  printk("ELF ROM-section loaded at %08lX (size %08lX)\n",
55                                  (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz);
56         }
57         free( phdr );
58         return entry;
59 #else
60         return NULL;
61 #endif
62 }
63
64 void
65 boot( void )
66 {
67         char *path;
68         void *entry;
69
70         /* Copy the incoming path */
71         fword("2dup");
72         path = pop_fstr_copy();
73
74         if(!path) {
75                 printk("[unix] Booting default not supported.\n");
76                 return;
77         }
78         printk("[unix] Booting '%s'\n",path);
79         entry=load_elf(path);
80         if(entry)
81                 printk("successfully loaded client at %llx.\n", (unsigned long long)(ucell)entry);
82         else
83                 printk("failed.\n");
84 }