paul@367 | 1 | /* |
paul@367 | 2 | * A region mapper for deployment in a new task. |
paul@367 | 3 | * |
paul@492 | 4 | * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@367 | 5 | * |
paul@367 | 6 | * This program is free software; you can redistribute it and/or |
paul@367 | 7 | * modify it under the terms of the GNU General Public License as |
paul@367 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@367 | 9 | * the License, or (at your option) any later version. |
paul@367 | 10 | * |
paul@367 | 11 | * This program is distributed in the hope that it will be useful, |
paul@367 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@367 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@367 | 14 | * GNU General Public License for more details. |
paul@367 | 15 | * |
paul@367 | 16 | * You should have received a copy of the GNU General Public License |
paul@367 | 17 | * along with this program; if not, write to the Free Software |
paul@367 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@367 | 19 | * Boston, MA 02110-1301, USA |
paul@367 | 20 | */ |
paul@367 | 21 | |
paul@367 | 22 | #include <l4/re/env.h> |
paul@367 | 23 | |
paul@367 | 24 | #include <exec/common.h> |
paul@367 | 25 | #include <exec/internal_pager.h> |
paul@367 | 26 | #include <exec/stack.h> |
paul@367 | 27 | #include <ipc/server.h> |
paul@367 | 28 | |
paul@367 | 29 | #include "pager_object_server.h" |
paul@367 | 30 | |
paul@367 | 31 | |
paul@367 | 32 | |
paul@431 | 33 | /* Initialise a pager for programs, reserving space below the allocated regions |
paul@431 | 34 | for the region mapper itself. */ |
paul@431 | 35 | |
paul@431 | 36 | static InternalPager exec_pager(L4_PAGESIZE * 10); |
paul@367 | 37 | |
paul@367 | 38 | |
paul@367 | 39 | |
paul@367 | 40 | int main(int argc, char *argv[]) |
paul@367 | 41 | { |
paul@367 | 42 | /* Initialise pager regions from region descriptions obtained via the |
paul@367 | 43 | auxiliary data. */ |
paul@367 | 44 | |
paul@367 | 45 | l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv); |
paul@367 | 46 | |
paul@368 | 47 | printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags); |
paul@368 | 48 | |
paul@367 | 49 | /* Skip past the auxiliary structure itself. */ |
paul@367 | 50 | |
paul@368 | 51 | struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1)); |
paul@367 | 52 | |
paul@367 | 53 | if (!region) |
paul@367 | 54 | { |
paul@367 | 55 | printf("Could not find regions.\n"); |
paul@367 | 56 | return 1; |
paul@367 | 57 | } |
paul@367 | 58 | |
paul@367 | 59 | for (; region && (region->ds != L4_INVALID_CAP); region++) |
paul@367 | 60 | { |
paul@433 | 61 | printf("Adding region: {%lx, %llx, %lx, %lx}\n", region->start, region->size, region->flags, region->ds); |
paul@431 | 62 | MappedRegion r(region->start, region->size, region->flags, region->ds); |
paul@431 | 63 | exec_pager.add(r); |
paul@367 | 64 | } |
paul@367 | 65 | |
paul@367 | 66 | /* Start the pager. */ |
paul@367 | 67 | |
paul@367 | 68 | printf("Starting pager...\n"); |
paul@376 | 69 | printf("Pager capability: %lx\n", l4re_env_get_cap("server")); |
paul@376 | 70 | printf("Main thread: %lx\n", l4re_env()->main_thread); |
paul@376 | 71 | |
paul@492 | 72 | /* Initialise the server, enabling notifications. */ |
paul@492 | 73 | |
paul@492 | 74 | ipc_server_config_type config; |
paul@492 | 75 | ipc_server_init_for(&config, PagerObject, &exec_pager); |
paul@492 | 76 | config.notifications = 1; |
paul@492 | 77 | |
paul@492 | 78 | /* Bind to the named capability and serve until the IPC gate is released. */ |
paul@492 | 79 | |
paul@492 | 80 | ipc_server_bind("server", (l4_umword_t) &config, &config.server); |
paul@492 | 81 | ipc_server_start_config(&config); |
paul@367 | 82 | |
paul@376 | 83 | printf("Ending pager...\n"); |
paul@367 | 84 | return 0; |
paul@367 | 85 | } |
paul@367 | 86 | |
paul@367 | 87 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@367 | 88 | */ |