/[pupa]/pupa/kern/main.c
ViewVC logotype

Diff of /pupa/kern/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by okuji, Thu Jan 2 23:46:21 2003 UTC revision 1.3 by okuji, Tue Jan 7 07:54:07 2003 UTC
# Line 1  Line 1 
1    /* main.c - the kernel main routine */
2  /*  /*
3   *  PUPA  --  Preliminary Universal Programming Architecture for GRUB   *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
4   *  Copyright (C) 2002  Yoshinori K. Okuji <okuji@enbug.org>   *  Copyright (C) 2002  Yoshinori K. Okuji <okuji@enbug.org>
# Line 56  pupa_add_unused_region (void) Line 57  pupa_add_unused_region (void)
57      pupa_mm_init_region ((void *) pupa_end_addr, pupa_total_module_size);      pupa_mm_init_region ((void *) pupa_end_addr, pupa_total_module_size);
58  }  }
59    
60    /* Set the root device according to the dl prefix.  */
61    static void
62    pupa_set_root_dev (void)
63    {
64      const char *prefix;
65    
66      prefix = pupa_dl_get_prefix ();
67      
68      if (prefix)
69        {
70          char *dev;
71    
72          dev = pupa_file_get_device_name (prefix);
73          if (dev)
74            {
75              pupa_device_set_root (dev);
76              pupa_free (dev);
77            }
78        }
79    }
80    
81    /* Load the normal mode module and execute the normal mode if possible.  */
82    static void
83    pupa_load_normal_mode (void)
84    {
85      if (pupa_dl_load ("normal"))
86        {
87          void (*normal_func) (const char *config);
88          
89          /* If the function pupa_enter_normal_mode is present, call it.  */
90          normal_func = pupa_dl_resolve_symbol ("pupa_enter_normal_mode");
91          if (normal_func)
92            {
93              char *config;
94              char *prefix;
95    
96              prefix = pupa_dl_get_prefix ();
97              if (! prefix)
98                pupa_fatal ("The dl prefix is not set!");
99              
100              config = pupa_malloc (pupa_strlen (prefix) + sizeof ("/pupa.cfg"));
101              if (! config)
102                pupa_fatal ("out of memory");
103    
104              pupa_sprintf (config, "%s/pupa.cfg", prefix);
105              (*normal_func) (config);
106              pupa_free (config);
107            }
108          else
109            pupa_printf ("No entrance routine in the normal mode!\n");
110        }
111      else
112        pupa_printf ("Failed to load the normal mode.\n");
113      
114      /* Ignore any error, because we have the rescue mode anyway.  */
115      pupa_errno = PUPA_ERR_NONE;
116    }
117    
118  /* The main routine.  */  /* The main routine.  */
119  void  void
120  pupa_main (void)  pupa_main (void)
121  {  {
   void (*normal_func) (void);  
     
122    /* First of all, initialize the machine.  */    /* First of all, initialize the machine.  */
123    pupa_machine_init ();    pupa_machine_init ();
124    
# Line 70  pupa_main (void) Line 127  pupa_main (void)
127    pupa_printf ("Welcome to PUPA!\n\n");    pupa_printf ("Welcome to PUPA!\n\n");
128    pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);    pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
129    
130      /* It is better to set the root device as soon as possible,
131         for convenience.  */
132      pupa_set_root_dev ();
133    
134      /* Load pre-loaded modules and free the space.  */
135    pupa_register_exported_symbols ();    pupa_register_exported_symbols ();
136    pupa_load_modules ();    pupa_load_modules ();
137    pupa_add_unused_region ();    pupa_add_unused_region ();
138    
139    /* If the function pupa_enter_normal_mode is present, call it.  */    /* Go to the real world.  */
140    normal_func = pupa_dl_resolve_symbol ("pupa_enter_normal_mode");    pupa_load_normal_mode ();
141    if (normal_func)    
     (*normal_func) ();  
   
142    /* If pupa_enter_normal_mode fails or doesn't exist, enter rescue mode.  */    /* If pupa_enter_normal_mode fails or doesn't exist, enter rescue mode.  */
143    pupa_printf ("Entering into rescue mode...\n");    pupa_printf ("Entering into rescue mode...\n");
144    pupa_enter_rescue_mode ();    pupa_enter_rescue_mode ();

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26