1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11 
12 #include <l4/re/l4aux.h>
13 
14 #include <l4/libloader/loader>
15 #include <l4/libloader/remote_app_model>
16 #include "remote_mem.h"
17 #include "app_task.h"
18 #include "debug.h"
19 #include <l4/cxx/string>
20 
21 struct Moe_app_model : public Ldr::Base_app_model<Moe::Stack>
22 {
23   enum Prios
24   {
25     Default_base_prio = 0x00,
26     Default_max_prio  = 0xff,
27   };
28 
29   typedef Moe::Dataspace const *Const_dataspace;
30   typedef Moe::Dataspace *Dataspace;
31   typedef Region_map *Rm;
32 
33   App_task *_task;
34   cxx::String _prog;
35   cxx::String _args;
36 
37   Moe_app_model(App_task *t, cxx::String const &prog, cxx::String const &args);
38 
39   Dataspace alloc_ds(unsigned long size) const;
40 
41   static Const_dataspace open_file(char const *name);
42 
43   void prog_attach_ds(l4_addr_t addr, unsigned long size,
44                       Const_dataspace ds, unsigned long offset,
45                       L4Re::Rm::Flags flags, char const *what);
46 
47   l4_cap_idx_t push_initial_caps(l4_cap_idx_t s);
48   void map_initial_caps(L4::Cap<L4::Task>, l4_cap_idx_t);
49 
50   static void copy_ds(Dataspace dst, unsigned long dst_offs,
51                       Const_dataspace src, unsigned long src_offs,
52                       unsigned long size);
53 
all_segs_cowMoe_app_model54   static bool all_segs_cow() { return false; }
55 
56   l4_addr_t local_attach_ds(Const_dataspace ds, unsigned long size,
57                             unsigned long offset) const;
58 
59   void local_detach_ds(l4_addr_t addr, unsigned long size) const;
60 
61   int prog_reserve_area(l4_addr_t *start, unsigned long size,
62                         L4Re::Rm::Flags flags, unsigned char align);
63 
64   Dataspace alloc_app_stack();
65 
66   void init_prog();
67 
reserved_areaMoe_app_model68   static Const_dataspace reserved_area()
69   { return 0; }
70 
local_kip_dsMoe_app_model71   static Dataspace local_kip_ds()
72   {
73     return kip_ds;
74   }
75 
local_kip_capMoe_app_model76   static L4::Cap<void> local_kip_cap()
77   { return kip_ds->obj_cap(); }
78 
79   void get_task_caps(L4::Cap<L4::Factory> *factory,
80                      L4::Cap<L4::Task> *task,
81                      L4::Cap<L4::Thread> *thread);
82 
run_threadMoe_app_model83   l4_msgtag_t run_thread(L4::Cap<L4::Thread> thread,
84                          l4_sched_param_t const &sp)
85   { return L4Re::Env::env()->scheduler()->run_thread(thread, sp); }
86 };
87 
88 typedef Ldr::Remote_app_model<Moe_app_model> Moe_x_app_model;
89 
90 class Loader
91 {
92 public:
93 
94 
95   virtual bool check_file_type(Moe::Dataspace const *file) const = 0;
96   bool start(cxx::String const &init_prog, cxx::String const &args);
97   virtual bool launch(App_task *, cxx::String const &, cxx::String const &) = 0;
~Loader()98   virtual ~Loader() {}
99 };
100