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

« back to all changes in this revision

Viewing changes to roms/openbios/libopenbios/initprogram.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
 *   Creation Date: <2010/04/02 13:00:00 mcayland>
 
3
 *   Time-stamp: <2010/04/02 13:00:00 mcayland>
 
4
 *
 
5
 *      <initprogram.c>
 
6
 *
 
7
 *      C implementation of (init-program) word
 
8
 *
 
9
 *   Copyright (C) 2010 Mark Cave-Ayland (mark.cave-ayland@siriusit.co.uk)
 
10
 *
 
11
 *   This program is free software; you can redistribute it and/or
 
12
 *   modify it under the terms of the GNU General Public License
 
13
 *   version 2
 
14
 *
 
15
 */
 
16
 
 
17
#include "config.h"
 
18
#include "kernel/kernel.h"
 
19
#include "libopenbios/bindings.h"
 
20
#include "libopenbios/initprogram.h"
 
21
 
 
22
/* Because the a.out loader requires platform-specific headers */
 
23
#ifdef CONFIG_LOADER_AOUT
 
24
#include "libopenbios/aout_load.h"
 
25
#endif
 
26
 
 
27
#include "libopenbios/bootcode_load.h"
 
28
#include "libopenbios/bootinfo_load.h"
 
29
#include "libopenbios/elf_load.h"
 
30
#include "libopenbios/fcode_load.h"
 
31
#include "libopenbios/forth_load.h"
 
32
#include "libopenbios/xcoff_load.h"
 
33
 
 
34
 
 
35
void init_program(void)
 
36
{
 
37
        /* Get the value of load-base and use it to determine the correct loader
 
38
           to use */
 
39
        ucell addr;
 
40
 
 
41
        feval("load-base");
 
42
        addr = POP();
 
43
 
 
44
#ifdef CONFIG_LOADER_AOUT
 
45
        if (is_aout((struct exec *)cell2pointer(addr))) {
 
46
                aout_init_program();
 
47
                return;
 
48
        }
 
49
#endif
 
50
 
 
51
#ifdef CONFIG_LOADER_BOOTCODE
 
52
        if (is_bootcode((char *)cell2pointer(addr))) {
 
53
                bootcode_init_program();
 
54
                return;
 
55
        }
 
56
#endif
 
57
 
 
58
#ifdef CONFIG_LOADER_BOOTINFO
 
59
        if (is_bootinfo((char *)cell2pointer(addr))) {
 
60
                bootinfo_init_program();
 
61
                return;
 
62
        }
 
63
#endif
 
64
 
 
65
#ifdef CONFIG_LOADER_ELF
 
66
        if (is_elf((Elf_ehdr *)cell2pointer(addr))) {
 
67
                elf_init_program();
 
68
                return;
 
69
        }
 
70
#endif
 
71
 
 
72
#ifdef CONFIG_LOADER_FCODE
 
73
        if (is_fcode((unsigned char *)cell2pointer(addr))) {
 
74
                fcode_init_program();
 
75
                return;
 
76
        }
 
77
#endif
 
78
 
 
79
#ifdef CONFIG_LOADER_FORTH
 
80
        if (is_forth((char *)cell2pointer(addr))) {
 
81
                forth_init_program();
 
82
                return;
 
83
        }
 
84
#endif
 
85
 
 
86
#ifdef CONFIG_LOADER_XCOFF
 
87
        if (is_xcoff((COFF_filehdr_t *)cell2pointer(addr))) {
 
88
                xcoff_init_program();
 
89
                return;
 
90
        }
 
91
#endif
 
92
 
 
93
}
 
94
 
 
95
void init_fcode_context(void)
 
96
{
 
97
        /* Execute FCode payload */
 
98
        printk("Evaluating FCode...\n");
 
99
        fword("load-base");
 
100
        PUSH(1);
 
101
        fword("byte-load");
 
102
}
 
103
 
 
104
 
 
105
void init_forth_context(void)
 
106
{
 
107
        /* Execute Forth payload */
 
108
        printk("Evaluating Forth...\n");
 
109
        fword("load-base");
 
110
        feval("load-state >ls.file-size @");
 
111
        fword("eval2");
 
112
}
 
113
 
 
114
void go(void)
 
115
{
 
116
        /* Switch to the current context */
 
117
        start_elf();
 
118
}