1 /* 2 * Support for initialising programs in new tasks and threads. 3 * 4 * Copyright (C) 2022, 2023 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_PARENT_CAP = 0x13UL << L4_CAP_SHIFT, 57 L4_EXEC_KIP_CAP = 0x14UL << L4_CAP_SHIFT, 58 }; 59 60 /* The default first free capability index must follow those above. Any 61 additional initial capabilities must elevate the index below. */ 62 63 enum exec_task_cap_indexes 64 { 65 L4_EXEC_FIRST_FREE_CAP_INDEX = 0x15UL, 66 }; 67 68 69 70 /* A process abstraction. */ 71 72 class Process 73 { 74 protected: 75 l4_cap_idx_t _task = L4_INVALID_CAP; 76 unsigned int _thread_number; 77 78 /* Common and thread environment details. */ 79 80 l4re_aux_t _aux; 81 l4re_env_t _env; 82 83 /* Task and thread initialisation. */ 84 85 long create_task(unsigned int threads); 86 87 long create_thread(l4_cap_idx_t *thread); 88 89 public: 90 explicit Process(); 91 92 l4_cap_idx_t allocate_cap(); 93 94 long configure_task(l4_cap_idx_t *task, l4_cap_idx_t *mapped_task, 95 unsigned int threads = 2); 96 97 long configure_thread(l4_cap_idx_t rm, l4_cap_idx_t *mapped_rm = NULL); 98 99 long set_parent(l4_cap_idx_t parent, l4_cap_idx_t *mapped_parent); 100 101 long map_capabilities(struct ipc_mapped_cap mapped_caps[], 102 bool to_count = true); 103 104 long thread_start(l4_addr_t program_start, Stack &st, l4_cap_idx_t *thread, 105 l4_cap_idx_t *mapped_thread); 106 }; 107 108 /* vim: tabstop=2 expandtab shiftwidth=2 109 */