Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / ppc / mol / init.c
1 /*
2  *   Creation Date: <1999/11/16 00:49:26 samuel>
3  *   Time-stamp: <2004/04/12 16:26:50 samuel>
4  *
5  *      <init.c>
6  *
7  *      Initialization
8  *
9  *   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel & David Rydh
10  #      (samuel@ibrium.se, dary@lindesign.se)
11  *
12  *   This program is free software; you can redistribute it and/or
13  *   modify it under the terms of the GNU General Public License
14  *   as published by the Free Software Foundation
15  *
16  */
17
18 #include "config.h"
19 #include "libopenbios/openbios.h"
20 #include "libopenbios/bindings.h"
21 #include "arch/common/nvram.h"
22 #include "mol/mol.h"
23 #include "libopenbios/ofmem.h"
24 #include "mol/prom.h"
25 #include "openbios-version.h"
26 #include "osi_calls.h"
27 #include "boothelper_sh.h"
28
29 extern void unexpected_excep( int vector );
30
31 int
32 get_bool_res( const char *res )
33 {
34         char buf[8], *p;
35
36         p = BootHGetStrRes( res, buf, sizeof(buf) );
37         if( !p )
38                 return -1;
39         if( !strcasecmp(p,"true") || !strcasecmp(p,"yes") || !strcasecmp(p,"1") )
40                 return 1;
41         return 0;
42 }
43
44 void
45 unexpected_excep( int vector )
46 {
47         printk("MOL panic: Unexpected exception %x\n", vector );
48         for( ;; )
49                 ;
50 }
51
52 unsigned long isa_io_base;
53
54 void
55 entry( void )
56 {
57         isa_io_base = 0x80000000;
58
59         printk("\n");
60         printk("=============================================================\n");
61         printk(PROGRAM_NAME " " OPENBIOS_VERSION_STR " [%s]\n",
62                OPENBIOS_BUILD_DATE);
63
64         ofmem_init();
65         initialize_forth();
66         /* won't return */
67
68         printk("of_startup returned!\n");
69         for( ;; )
70                 ;
71 }
72
73 static void
74 setenv( char *env, char *value )
75 {
76         push_str( value );
77         push_str( env );
78         fword("$setenv");
79 }
80
81 void
82 arch_of_init( void )
83 {
84         mol_phandle_t ph;
85         int autoboot;
86
87         devtree_init();
88         node_methods_init();
89         nvram_init("/pci/mac-io/nvram");
90         openbios_init();
91         modules_init();
92         pseudodisk_init();
93         osiblk_init();
94         osiscsi_init();
95         init_video();
96
97         if( (ph=prom_find_device("/rtas")) == -1 )
98                 printk("Warning: No /rtas node\n");
99         else {
100                 unsigned long size = 0x1000;
101                 while( size < (unsigned long)of_rtas_end - (unsigned long)of_rtas_start )
102                         size *= 2;
103                 prom_set_prop( ph, "rtas-size", (char*)&size, sizeof(size) );
104         }
105
106         /* tweak boot settings */
107         autoboot = !!get_bool_res("autoboot");
108         if( !autoboot )
109                 printk("Autobooting disabled - dropping into OpenFirmware\n");
110         setenv("auto-boot?", autoboot ? "true" : "false" );
111         setenv("boot-command", "molboot");
112
113         if( get_bool_res("tty-interface") == 1 )
114                 fword("activate-tty-interface");
115
116         /* hack */
117         device_end();
118         bind_func("molboot", boot );
119 }