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 #include "debug.h" 19 20 #if 0 21 namespace Ldr { 22 class Script; 23 }; 24 #endif 25 26 struct App_model : public Ldr::Base_app_model<Stack> 27 { 28 enum Prios 29 { 30 Default_base_prio = 0x00, 31 Default_max_prio = 0xff, 32 }; 33 34 enum 35 { 36 #ifdef ARCH_mips 37 Utcb_area_start = 0x73000000, // this needs to be lower on MIPS 38 #else 39 Utcb_area_start = 0xb3000000, 40 #endif 41 }; 42 43 typedef L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap Const_dataspace; 44 typedef L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap Dataspace; 45 typedef L4Re::Util::Ref_cap<L4Re::Rm>::Cap Rm; 46 #if 0 47 typedef L4::Cap<L4Re::Dataspace> Const_dataspace; 48 typedef L4::Cap<L4Re::Dataspace> Dataspace; 49 typedef L4::Cap<L4Re::Rm> Rm; 50 #endif 51 App_task *_task; 52 53 explicit App_model(); 54 55 Dataspace alloc_ds(unsigned long size) const; 56 57 static Const_dataspace open_file(char const *name); 58 59 virtual l4_cap_idx_t push_initial_caps(l4_cap_idx_t start) = 0; 60 virtual void map_initial_caps(L4::Cap<L4::Task> task, l4_cap_idx_t start) = 0; 61 62 void prog_attach_ds(l4_addr_t addr, unsigned long size, 63 Const_dataspace ds, unsigned long offset, 64 L4Re::Rm::Flags flags, char const *what); 65 66 static void copy_ds(Dataspace dst, unsigned long dst_offs, 67 Const_dataspace src, unsigned long src_offs, 68 unsigned long size); 69 all_segs_cowApp_model70 static bool all_segs_cow() { return false; } 71 72 l4_addr_t local_attach_ds(Const_dataspace ds, unsigned long size, 73 unsigned long offset) const; 74 75 void local_detach_ds(l4_addr_t addr, unsigned long size) const; 76 77 int prog_reserve_area(l4_addr_t *start, unsigned long size, 78 L4Re::Rm::Flags flags, unsigned char align); 79 80 Dataspace alloc_app_stack(); 81 82 void init_prog(); 83 reserved_areaApp_model84 static Const_dataspace reserved_area() 85 { return Const_dataspace(); } 86 local_kip_dsApp_model87 static Dataspace local_kip_ds() 88 { 89 extern l4re_aux_t* l4re_aux; 90 return L4::Cap<L4Re::Dataspace>(l4re_aux->kip_ds); 91 } 92 93 local_kip_capApp_model94 static L4::Cap<void> local_kip_cap() 95 { return local_kip_ds().get(); } 96 #if 0 97 static L4::Cap<void> prog_kip_ds() 98 { return L4::Cap<void>(Kip_cap << L4_CAP_SHIFT); } 99 #endif 100 101 void get_task_caps(L4::Cap<L4::Factory> *factory, 102 L4::Cap<L4::Task> *task, 103 L4::Cap<L4::Thread> *thread); 104 run_threadApp_model105 l4_msgtag_t run_thread(L4::Cap<L4::Thread> thread, 106 l4_sched_param_t const &sp) 107 { 108 L4::Cap<L4::Scheduler> s(prog_info()->scheduler.raw & (~0UL << L4_FPAGE_ADDR_SHIFT)); 109 110 // test whether intersection between provided cpu set and online cpu set 111 // is empty, in that case warn that the thread _may_ never run 112 l4_umword_t cpu_max; 113 l4_sched_cpu_set_t cpus = sp.affinity; 114 l4_msgtag_t t = s->info(&cpu_max, &cpus); 115 if (l4_error(t)) 116 return t; 117 118 if (!(cpus.map & sp.affinity.map)) 119 Dbg(Dbg::Warn).printf("warning: Launching thread on offline CPU. Thread may never run!\n"); 120 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 ~App_modelApp_model136 virtual ~App_model() throw() {} 137 138 }; 139 140 typedef Ldr::Remote_app_model<App_model> Rmt_app_model; 141 142 143