Switch SPARC32 page tables over to use OFMEM's ofmem_posix_memalign() rather than...
[openbios.git] / arch / unix / boot.c
blobf4a29428bbdddde3043b633f978d409becdd8818
1 /*
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"
11 void boot(void);
12 void *load_elf(char *spec);
14 void
15 *load_elf(char *spec)
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;
26 if( (fd=open_io(spec)) == -1 )
27 return NULL;
29 if( (elf_offs=find_elf(fd)) < 0 ) {
30 printk("----> %s is not an ELF image\n", buf );
31 return NULL;
34 if( !(phdr=elf_readhdrs(fd, 0, &ehdr)) ) {
35 printk("elf32_readhdrs failed\n");
36 return NULL;
39 (unsigned long long *)entry = ehdr.e_entry;
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;
54 printk("ELF ROM-section loaded at %08lX (size %08lX)\n",
55 (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz);
57 free( phdr );
58 return entry;
59 #else
60 return NULL;
61 #endif
64 void
65 boot( void )
67 char *path;
68 void *entry;
70 /* Copy the incoming path */
71 fword("2dup");
72 path = pop_fstr_copy();
74 if(!path) {
75 printk("[unix] Booting default not supported.\n");
76 return;
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");