]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ned/server/src/app_model.h
cbdd894da890b4e6631f714f57d372241fc24276
[l4.git] / l4 / pkg / ned / server / src / app_model.h
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #pragma once
10
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
19 #if 0
20 namespace Ldr {
21 class Script;
22 };
23 #endif
24
25 struct App_model : public Ldr::Base_app_model<Stack>
26 {
27   enum
28   {
29     Task_cap               = 1,
30     Factory_cap            = 2,
31     Rm_thread_cap          = 3,
32     External_rm_cap        = 5,
33     Allocator_cap          = 7,
34     Names_cap,
35     Log_cap,
36     Parent_cap,
37     Kip_cap,
38     Scheduler_cap,
39     First_free,
40   };
41
42   enum Prios
43   {
44     Default_base_prio = 0x00,
45     Default_max_prio  = 0xff,
46   };
47
48   enum
49   {
50     Utcb_area_start        = 0xb3000000,
51     Default_max_threads    = 16,
52     Total_max_threads      = 256,
53     Kip_address            = 0xa0000000,
54   };
55
56   typedef L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap Const_dataspace;
57   typedef L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap Dataspace;
58   typedef L4Re::Util::Ref_cap<L4Re::Rm>::Cap Rm;
59 #if 0
60   typedef L4::Cap<L4Re::Dataspace> Const_dataspace;
61   typedef L4::Cap<L4Re::Dataspace> Dataspace;
62   typedef L4::Cap<L4Re::Rm> Rm;
63 #endif
64   App_task *_task;
65
66   explicit App_model();
67
68   Dataspace alloc_ds(unsigned long size) const;
69
70   static Const_dataspace open_file(char const *name);
71
72   virtual l4_cap_idx_t push_initial_caps(l4_cap_idx_t start) = 0;
73   virtual void map_initial_caps(L4::Cap<L4::Task> task, l4_cap_idx_t start) = 0;
74
75   void prog_attach_ds(l4_addr_t addr, unsigned long size,
76                       Const_dataspace ds, unsigned long offset,
77                       unsigned flags, char const *what);
78
79   static void copy_ds(Dataspace dst, unsigned long dst_offs,
80                       Const_dataspace src, unsigned long src_offs,
81                       unsigned long size);
82
83   static bool all_segs_cow() { return false; }
84
85   l4_addr_t local_attach_ds(Const_dataspace ds, unsigned long size,
86                             unsigned long offset) const;
87
88   void local_detach_ds(l4_addr_t addr, unsigned long size) const;
89
90   int prog_reserve_area(l4_addr_t *start, unsigned long size, unsigned flags, unsigned char align);
91
92   Dataspace alloc_app_stack();
93
94   void init_prog();
95
96   static Const_dataspace reserved_area()
97   { return Const_dataspace(); }
98
99   static Dataspace local_kip_ds()
100   {
101     extern l4re_aux_t* l4re_aux;
102     return L4::Cap<L4Re::Dataspace>(l4re_aux->kip_ds);
103   }
104
105
106   static L4::Cap<void> local_kip_cap()
107   { return local_kip_ds().get(); }
108 #if 0
109   static L4::Cap<void> prog_kip_ds()
110   { return L4::Cap<void>(Kip_cap << L4_CAP_SHIFT); }
111 #endif
112
113   void get_task_caps(L4::Cap<L4::Factory> *factory,
114                      L4::Cap<L4::Task> *task,
115                      L4::Cap<L4::Thread> *thread);
116
117   l4_msgtag_t run_thread(L4::Cap<L4::Thread> thread,
118                          l4_sched_param_t const &sp)
119   {
120     L4::Cap<L4::Scheduler> s(prog_info()->scheduler.raw & (~0UL << L4_FPAGE_ADDR_SHIFT));
121     return s->run_thread(thread, sp);
122   }
123
124   virtual void push_argv_strings() = 0;
125   virtual void push_env_strings() = 0;
126 #if 0
127 //private:
128   L4::Cap<L4Re::Log> _log;
129   L4::Cap<L4::Scheduler> _sched;
130   L4::Cap<L4Re::Namespace> _ns;
131   L4::Cap<L4Re::Mem_alloc> _ma;
132   L4::Cap<L4Re::Mem_alloc> _ma;
133   L4::Cap<L4::Factory> _factory;
134 #endif
135
136   virtual ~App_model() throw() {}
137
138 };
139
140 typedef Ldr::Remote_app_model<App_model> Rmt_app_model;
141
142