paul@324 | 1 | /* |
paul@324 | 2 | * Stack support for new tasks and threads. |
paul@324 | 3 | * |
paul@324 | 4 | * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> |
paul@324 | 5 | * |
paul@324 | 6 | * This program is free software; you can redistribute it and/or |
paul@324 | 7 | * modify it under the terms of the GNU General Public License as |
paul@324 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@324 | 9 | * the License, or (at your option) any later version. |
paul@324 | 10 | * |
paul@324 | 11 | * This program is distributed in the hope that it will be useful, |
paul@324 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@324 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@324 | 14 | * GNU General Public License for more details. |
paul@324 | 15 | * |
paul@324 | 16 | * You should have received a copy of the GNU General Public License |
paul@324 | 17 | * along with this program; if not, write to the Free Software |
paul@324 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@324 | 19 | * Boston, MA 02110-1301, USA |
paul@324 | 20 | */ |
paul@324 | 21 | |
paul@324 | 22 | #pragma once |
paul@324 | 23 | |
paul@324 | 24 | #include <l4/re/env.h> |
paul@324 | 25 | #include <l4/re/l4aux.h> |
paul@324 | 26 | |
paul@324 | 27 | #include <exec/segment.h> |
paul@324 | 28 | |
paul@324 | 29 | |
paul@324 | 30 | |
paul@324 | 31 | /* A stack abstraction. */ |
paul@324 | 32 | |
paul@324 | 33 | class Stack |
paul@324 | 34 | { |
paul@324 | 35 | protected: |
paul@324 | 36 | |
paul@324 | 37 | /* Auxiliary vector key-value pair. */ |
paul@324 | 38 | |
paul@324 | 39 | struct auxv_entry |
paul@324 | 40 | { |
paul@324 | 41 | l4_umword_t key, value; |
paul@324 | 42 | }; |
paul@324 | 43 | |
paul@324 | 44 | /* Program segment holding the stack contents. */ |
paul@324 | 45 | |
paul@324 | 46 | Segment &_segment; |
paul@324 | 47 | |
paul@324 | 48 | /* Next element pointer. */ |
paul@324 | 49 | |
paul@324 | 50 | l4_umword_t *_element; |
paul@324 | 51 | |
paul@324 | 52 | /* Stack section properties. */ |
paul@324 | 53 | |
paul@324 | 54 | l4_addr_t _caps; |
paul@324 | 55 | char *_arg_top, *_env_top; |
paul@324 | 56 | char **_argv; |
paul@324 | 57 | char *_auxv_end; |
paul@324 | 58 | int _env_entries; |
paul@324 | 59 | |
paul@324 | 60 | /* L4Re auxiliary and environment regions. */ |
paul@324 | 61 | |
paul@324 | 62 | l4re_aux_t *_aux; |
paul@324 | 63 | l4re_env_t *_env; |
paul@324 | 64 | |
paul@324 | 65 | /* Stack pointer start address. */ |
paul@324 | 66 | |
paul@324 | 67 | l4_addr_t _start; |
paul@324 | 68 | |
paul@324 | 69 | /* Internal stack population methods. */ |
paul@324 | 70 | |
paul@324 | 71 | void push_cap_entries(l4re_env_cap_entry_t *entries); |
paul@324 | 72 | |
paul@324 | 73 | void push_string(char *s); |
paul@324 | 74 | |
paul@324 | 75 | void push_env(char *envp[]); |
paul@324 | 76 | |
paul@324 | 77 | void push_args(int argc, char *argv[]); |
paul@324 | 78 | |
paul@324 | 79 | void push_l4re_aux(); |
paul@324 | 80 | |
paul@324 | 81 | void push_l4re_env(); |
paul@324 | 82 | |
paul@324 | 83 | void push_auxv(); |
paul@324 | 84 | |
paul@324 | 85 | offset_t write_address(char *arg, char **addr, char *s); |
paul@324 | 86 | |
paul@324 | 87 | void push_envp(char *envp[]); |
paul@324 | 88 | |
paul@324 | 89 | void push_argv(int argc, char *argv[]); |
paul@324 | 90 | |
paul@324 | 91 | l4_addr_t align_stack(); |
paul@324 | 92 | |
paul@324 | 93 | public: |
paul@324 | 94 | explicit Stack(Segment &segment); |
paul@324 | 95 | |
paul@324 | 96 | void set_l4re_aux(l4re_aux_t *aux); |
paul@324 | 97 | |
paul@324 | 98 | void set_l4re_env(l4re_env_t *env); |
paul@324 | 99 | |
paul@324 | 100 | void populate(int argc, char *argv[], char *envp[]); |
paul@324 | 101 | |
paul@324 | 102 | l4_addr_t start_address(); |
paul@324 | 103 | }; |
paul@324 | 104 | |
paul@324 | 105 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@324 | 106 | */ |