l4-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wortel patch: Move startup logic to a separate function


From: Niels Möller
Subject: wortel patch: Move startup logic to a separate function
Date: 19 Jan 2004 15:30:07 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

The following patch moves some code from start_components into a
separate function. The new function sends the startup message to the
main thread of a module, and then grants the new thread all the pages
corresponding to the binary image of the module.

The point of the change is that as far as I can see, the same code can
be reused for starting the other modules, in particular the task server.

Some other questions and comments:

1. Comments say that the choice for kip and utcb area for the new
   tasks is a hack. But why is wortel_start included in the equation?
   To me it would make more sense to use a fix arbitrary high address
   as the default, and then perhaps add some elf-magic or whatnot that
   a module can use to override it.

   But wortel_start seems very irrelevant, as the wortel image will
   never be present in the new address space. What am I missing?

   I'm aware that utcb location in *wortel's* address space isn't as
   well defined as one would like, but that shouldn't be an issue for
   new address spaces wortel creates.

2. The current plan is that the task server will live in its own
   address space, and use wortel as a proxy for the privileged system
   calls?

3. To me, it seems that the use of HURD_LOAD_ADDRESS in separate
   */config.m4 files makes it unnecessarily hard to get an overview of
   the address space and avoid conflicts. A series of
   HURD_LOAD_ADDRESS directly in configure.ac would aid the
   readability, imho.

wortel/ChangeLog:

2004-01-19  Niels Möller  <address@hidden>

        * wortel.c (start_module): New function.
        (start_components): Use it.

diff -u -a -p -r1.19 wortel.c
--- wortel/wortel.c     2 Oct 2003 10:39:36 -0000       1.19
+++ wortel/wortel.c     19 Jan 2004 14:04:00 -0000
@@ -253,72 +253,23 @@ load_components (void)
   loader_remove_region ("physmem-mod");
 }
 
-
+/* Send startup message, and grant pages for the binary image. */
 static void
-start_components (void)
+start_module (const struct wortel_module *mod)
 {
   l4_msg_t msg;
   l4_msg_tag_t tag;
   l4_word_t ret;
-  l4_word_t control;
-  unsigned int cap_id;
-  unsigned int i;
-  l4_word_t thread_no = l4_thread_no (l4_myself ()) + 1;
-  hurd_task_id_t task_id = 2;
-  l4_thread_id_t server;
-
-  for (i = 0; i < mods_count; i++)
-    {
-      /* FIXME: Should only be done for modules turned into tasks.  */
-      mods[i].main_thread = l4_global_id (thread_no++, task_id);
-      mods[i].server_thread = l4_global_id (thread_no++, task_id);
-      task_id++;
-    }
   
-  if (mods[MOD_PHYSMEM].start > mods[MOD_PHYSMEM].end)
-    panic ("physmem has invalid memory range");
-  if (mods[MOD_PHYSMEM].ip < mods[MOD_PHYSMEM].start
-      || mods[MOD_PHYSMEM].ip > mods[MOD_PHYSMEM].end)
-    panic ("physmem has invalid IP");
-
-  server = mods[MOD_PHYSMEM].main_thread;
-  /* FIXME: Pass cap_id to physmem.  */
-  cap_id = wortel_add_user (l4_version (server));
-  /* The UTCB location below is only a hack.  We also need a way to
-     specify the maximum number of threads (ie the size of the UTCB
-     area), for example via ELF symbols, or via the command line.
-     This can also be used to actually create these threads up
-     front.  */
-  ret = l4_thread_control (server, server, l4_myself (), l4_nilthread,
-                          (void *) -1);
-  if (!ret)
-    panic ("Creation of initial physmem thread failed");
-
-  /* The UTCB area must be controllable in some way, see above.  Same
-     for KIP area.  */
-  ret = l4_space_control (server, 0,
-                         l4_fpage_log2 (wortel_start,
-                                        l4_kip_area_size_log2 ()),
-                         l4_fpage_log2 (wortel_start + l4_kip_area_size (),
-                                        l4_utcb_area_size_log2 ()),
-                         l4_anythread, &control);
-  if (!ret)
-    panic ("Creation of physmem address space failed");
-
-  ret = l4_thread_control (server, server, l4_nilthread, l4_myself (),
-                          (void *) (wortel_start + l4_kip_area_size ()));
-  if (!ret) 
-    panic ("Activation of initial physmem thread failed");
-
   l4_msg_clear (&msg);
   l4_set_msg_label (&msg, 0);
-  l4_msg_append_word (&msg, mods[MOD_PHYSMEM].ip);
+  l4_msg_append_word (&msg, mod->ip);
   l4_msg_append_word (&msg, 0);
   l4_msg_load (&msg);
-  tag = l4_send (server);
+  tag = l4_send (mod->main_thread);
   if (l4_ipc_failed (tag))
-    panic ("Sending startup message to physmem thread failed: %u",
-          l4_error_code ());
+    panic ("Sending startup message to %s thread failed: %u",
+          mod->name, l4_error_code ());
 
   {
     l4_fpage_t fpages[MAX_FPAGES];
@@ -329,7 +280,7 @@ start_components (void)
        fpages.  So we first create a list of all fpages we need, then
        we serve one after another, providing the one containing the
        fault address last.  */
-    nr_fpages = make_fpages (mods[MOD_PHYSMEM].start, mods[MOD_PHYSMEM].end,
+    nr_fpages = make_fpages (mod->start, mod->end,
                             fpages);
 
     /* Now serve page requests.  */
@@ -340,19 +291,20 @@ start_components (void)
        l4_word_t addr;
        unsigned int i;
 
-       tag = l4_receive (server);
+       tag = l4_receive (mod->main_thread);
        if (l4_ipc_failed (tag))
-         panic ("Receiving messages from physmem thread failed: %u",
-                (l4_error_code () >> 1) & 0x7);
+         panic ("Receiving messages from %s thread failed: %u",
+                mod->name, (l4_error_code () >> 1) & 0x7);
        if ((l4_label (tag) >> 4) != 0xffe)
-         panic ("Message from physmem thread is not a page fault");
+         panic ("Message from %s thread is not a page fault",
+                mod->name);
        l4_msg_store (tag, &msg);
        if (l4_untyped_words (tag) != 2 || l4_typed_words (tag) != 0)
          panic ("Invalid format of page fault message");
        addr = l4_msg_word (&msg, 0);
-       if (addr != mods[MOD_PHYSMEM].ip)
+       if (addr != mod->ip)
          panic ("Page fault at unexpected address 0x%x (expected 0x%x)",
-                addr, mods[MOD_PHYSMEM].ip);
+                addr, mod->ip);
 
        if (nr_fpages == 1)
          i = 0;
@@ -371,8 +323,8 @@ start_components (void)
 
        /* The memory was already requested from sigma0 by
           load_components, so grant it right away.  */
-       debug ("Granting fpage: 0x%x/%u\n", l4_address (fpage),
-              l4_size_log2 (fpage));
+       debug ("Granting fpage: 0x%x/%u to %s\n", l4_address (fpage),
+              l4_size_log2 (fpage), mod->name);
        l4_msg_clear (&msg);
        l4_set_msg_label (&msg, 0);
        /* FIXME: Keep track of mappings already provided.  Possibly
@@ -380,15 +332,73 @@ start_components (void)
        grant_item = l4_grant_item (fpage, l4_address (fpage));
        l4_msg_append_grant_item (&msg, grant_item);
        l4_msg_load (&msg);
-       l4_reply (server);
+       l4_reply (mod->main_thread);
       }
   }
+}
+
+static void
+start_components (void)
+{
+  l4_msg_t msg;
+  l4_msg_tag_t tag;
+  l4_word_t ret;
+  l4_word_t control;
+  unsigned int cap_id;
+  unsigned int i;
+  l4_word_t thread_no = l4_thread_no (l4_myself ()) + 1;
+  hurd_task_id_t task_id = 2;
+  l4_thread_id_t server;
+
+  for (i = 0; i < mods_count; i++)
+    {
+      /* FIXME: Should only be done for modules turned into tasks.  */
+      mods[i].main_thread = l4_global_id (thread_no++, task_id);
+      mods[i].server_thread = l4_global_id (thread_no++, task_id);
+      task_id++;
+    }
+  
+  if (mods[MOD_PHYSMEM].start > mods[MOD_PHYSMEM].end)
+    panic ("physmem has invalid memory range");
+  if (mods[MOD_PHYSMEM].ip < mods[MOD_PHYSMEM].start
+      || mods[MOD_PHYSMEM].ip > mods[MOD_PHYSMEM].end)
+    panic ("physmem has invalid IP");
+
+  server = mods[MOD_PHYSMEM].main_thread;
+  /* FIXME: Pass cap_id to physmem.  */
+  cap_id = wortel_add_user (l4_version (server));
+  /* The UTCB location below is only a hack.  We also need a way to
+     specify the maximum number of threads (ie the size of the UTCB
+     area), for example via ELF symbols, or via the command line.
+     This can also be used to actually create these threads up
+     front.  */
+  ret = l4_thread_control (server, server, l4_myself (), l4_nilthread,
+                          (void *) -1);
+  if (!ret)
+    panic ("Creation of initial physmem thread failed");
+
+  /* The UTCB area must be controllable in some way, see above.  Same
+     for KIP area.  */
+  ret = l4_space_control (server, 0,
+                         l4_fpage_log2 (wortel_start,
+                                        l4_kip_area_size_log2 ()),
+                         l4_fpage_log2 (wortel_start + l4_kip_area_size (),
+                                        l4_utcb_area_size_log2 ()),
+                         l4_anythread, &control);
+  if (!ret)
+    panic ("Creation of physmem address space failed");
+
+  ret = l4_thread_control (server, server, l4_nilthread, l4_myself (),
+                          (void *) (wortel_start + l4_kip_area_size ()));
+  if (!ret) 
+    panic ("Activation of initial physmem thread failed");
+
+  start_module(&mods[MOD_PHYSMEM]);
 
   /* Now we have kicked off the boot process.  The rest will be done
      in the normal server loop.  */
 }
 
-
 /* Serve rootserver bootstrap requests.  We do everything within this
    loop, because this allows the other servers to print messages and
    panic while we are performing the bootstrap.  If we were to make
@@ -591,6 +601,7 @@ serve_bootstrap_requests (void)
     }
   while (1);
 }
+
 
 
 /* Serve rootserver requests.  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]