~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/openbios/arch/unix/boot.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

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