1 /* 2 * Support for initialising programs in new tasks and threads. 3 * 4 * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/re/env.h> 25 #include <l4/re/l4aux.h> 26 #include <l4/sys/factory.h> 27 #include <l4/sys/task.h> 28 #include <l4/sys/thread.h> 29 30 #include <exec/stack.h> 31 32 33 34 /* UTCB properties. 35 See: moe/server/src/loader.cc */ 36 37 enum exec_utcb 38 { 39 Default_max_threads = 16, 40 #ifdef ARCH_mips 41 Utcb_area_start = 0x73000000, 42 #else 43 Utcb_area_start = 0xb3000000, 44 #endif 45 }; 46 47 48 49 /* Capability index definitions. */ 50 51 enum exec_task_caps 52 { 53 L4_EXEC_PAGER_CAP = 0x10UL << L4_CAP_SHIFT, 54 L4_EXEC_RM_CAP = 0x11UL << L4_CAP_SHIFT, 55 L4_EXEC_MA_CAP = 0x12UL << L4_CAP_SHIFT, 56 L4_EXEC_KIP_CAP = 0x14UL << L4_CAP_SHIFT, 57 }; 58 59 /* The default first free capability index must follow those above. Any 60 additional initial capabilities must elevate the index below. */ 61 62 enum exec_task_cap_indexes 63 { 64 L4_EXEC_FIRST_FREE_CAP_INDEX = 0x15UL, 65 }; 66 67 68 69 /* A process abstraction. */ 70 71 class Process 72 { 73 protected: 74 l4_cap_idx_t _task = L4_INVALID_CAP; 75 unsigned int _thread_number; 76 77 /* Common and thread environment details. */ 78 79 l4re_aux_t _aux; 80 l4re_env_t _env; 81 82 /* Task and thread initialisation. */ 83 84 long create_task(); 85 86 long create_thread(l4_cap_idx_t *thread); 87 88 public: 89 explicit Process(int reserved_threads = 1); 90 91 l4_cap_idx_t allocate_cap(); 92 93 long configure_task(); 94 95 long configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap = L4_INVALID_CAP); 96 97 long map_capabilities(struct ipc_mapped_cap mapped_caps[], 98 bool to_count = true); 99 100 long thread_start(l4_addr_t program_start, Stack &st); 101 }; 102 103 /* vim: tabstop=2 expandtab shiftwidth=2 104 */