1/**
2 * \file
3 * \brief Domain spawn functionality.
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, 2012, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef SPAWNDOMAIN_H
16#define SPAWNDOMAIN_H
17
18#include <sys/cdefs.h>
19
20//XXX: added alignment to workaround an arm-gcc bug
21//which generated (potentially) unaligned access code to those fields
22/**
23 * \brief Struct to refer to the various caps within a domain being spawned.
24 */
25struct spawninfo {
26    domainid_t domain_id;
27    struct cnoderef rootcn __attribute__ ((aligned(4)));
28    struct cnoderef taskcn __attribute__ ((aligned(4)));
29    struct cnoderef segcn  __attribute__ ((aligned(4)));
30    struct cnoderef pagecn __attribute__ ((aligned(4)));
31    struct capref   rootcn_cap __attribute__ ((aligned(4)));
32    struct capref	taskcn_cap __attribute__ ((aligned(4)));
33    struct capref	pagecn_cap __attribute__ ((aligned(4)));
34    struct capref   dispframe __attribute__ ((aligned(4)));
35    struct capref	dcb __attribute__ ((aligned(4)));
36    struct capref	argspg __attribute__ ((aligned(4)));
37    struct capref 	vtree __attribute__ ((aligned(4)));
38
39    // Slot (in segcn) from where elfload_allocate should allocate frames from
40    cslot_t elfload_slot;
41
42    // vspace of spawned domain
43    struct vspace *vspace;
44    struct vregion *vregion[16];
45    genvaddr_t base[16];
46    unsigned int vregions;
47
48    dispatcher_handle_t handle;
49    enum cpu_type cpu_type;
50    int codeword;
51    char *append_args;
52
53    // slot allocator for pagecn
54    struct single_slot_allocator pagecn_slot_alloc;
55
56    // TLS data
57    genvaddr_t tls_init_base;
58    size_t tls_init_len, tls_total_len;
59
60    // Error handling data
61    genvaddr_t eh_frame;
62    size_t eh_frame_size;
63    genvaddr_t eh_frame_hdr;
64    size_t eh_frame_hdr_size;
65
66    // name of the image
67    const char *name;
68
69    // spawn flags
70    uint8_t flags;
71};
72
73#define SPAWN_FLAGS_DEFAULT (0)
74#define SPAWN_FLAGS_NEW_DOMAIN    (1 << 0) ///< allocate a new domain ID
75#define SPAWN_FLAGS_OMP           (1 << 1) ///< do the OpenMP parsing
76
77typedef uint8_t spawn_flags_t;
78
79__BEGIN_DECLS
80errval_t spawn_get_cmdline_args(struct mem_region *module,
81                                char **retargs);
82int spawn_tokenize_cmdargs(char *args, char *argv[], size_t argv_len);
83errval_t spawn_load_with_bootinfo(struct spawninfo *si, struct bootinfo *bi,
84                                  const char *name, coreid_t coreid);
85errval_t spawn_load_with_args(struct spawninfo *si, struct mem_region *module,
86                              const char *name, coreid_t coreid,
87                              char *const argv[], char *const envp[]);
88errval_t spawn_load_image(struct spawninfo *si, lvaddr_t binary,
89                          size_t binary_size, enum cpu_type type,
90                          const char *name, coreid_t coreid,
91                          char *const argv[], char *const envp[],
92                          struct capref inheritcn_cap, struct capref argcn_cap);
93errval_t spawn_run(struct spawninfo *si);
94errval_t spawn_free(struct spawninfo *si);
95
96errval_t multiboot_cleanup_mapping(void);
97
98/* spawn_vspace.c */
99errval_t spawn_vspace_init(struct spawninfo *si, struct capref vnode,
100                           enum cpu_type cpu_type);
101errval_t spawn_vspace_map_one_frame(struct spawninfo *si, genvaddr_t *retaddr,
102                                    struct capref frame, size_t size);
103errval_t spawn_vspace_map_fixed_one_frame(struct spawninfo *si, genvaddr_t addr,
104                                          struct capref frame, size_t size);
105errval_t spawn_vspace_map_anon_fixed_attr(struct spawninfo *si, genvaddr_t addr,
106                                          size_t size, struct vregion **vregion,
107                                          struct memobj **memobj,
108                                          vregion_flags_t flags);
109
110/// Returns a raw pointer to the modules string area string
111const char *multiboot_module_rawstring(struct mem_region *region);
112const char *multiboot_module_name(struct mem_region *region);
113struct mem_region *multiboot_find_module(struct bootinfo *bi, const char *name);
114struct mem_region *multiboot_find_module_containing(struct bootinfo *bi,
115						    const char *name,
116						    const char *containing);
117errval_t spawn_map_module(struct mem_region *module, size_t *retsize,
118                          lvaddr_t *retaddr, genpaddr_t *retpaddr);
119errval_t spawn_unmap_module(lvaddr_t mapped_addr);
120errval_t spawn_map_bootinfo(struct spawninfo *si, genvaddr_t *retvaddr);
121const char *getopt_module(struct mem_region *module);
122
123/* typedef void (*spawn_notify_func)(uint64_t domain_id); */
124
125/* errval_t get_cmdline_args(char *name, struct bootinfo *bi, char **retargs); */
126/* void detokenize_cmdargs(char *args, int argc, char *argv[]); */
127/* void tokenize_cmdargs(char *args, int *argc, char *argv[]); */
128errval_t spawn_span_domain(struct spawninfo *si, struct capref vroot,
129                           struct capref disp_frame);
130/* void spawn_notify(struct spawninfo *si, bool notify); */
131/* void spawn_domain_id(struct spawninfo *si, uint64_t domain_id); */
132/* errval_t spawn_make_runnable(struct spawninfo *si); */
133/* errval_t spawn_make_runnable_new_domain(struct spawninfo *si, */
134/*                                         uint64_t *domain_id); */
135/* void spawn_register_notify(spawn_notify_func f); */
136
137/* errval_t spawn_fill_smallcn(struct spawninfo *si, const uint8_t nos); */
138/* errval_t spawn_get_cmdargs(char *name, struct bootinfo *bi, const char **cmdargs); */
139/* errval_t spawn_memory(struct spawninfo *si, const char *name, uint8_t core_id, */
140/*                       int argc, char *argv[], lvaddr_t binary, */
141/*                       size_t binary_size); */
142
143errval_t spawn_symval_lookup_idx(uint32_t idx, char **ret_name, genvaddr_t *ret_add);
144errval_t spawn_symval_lookup_name(char *name, uint32_t *ret_idx,  genvaddr_t *ret_add);
145errval_t spawn_symval_lookup_addr(genvaddr_t addr, uint32_t *ret_idx, char **ret_name);
146errval_t spawn_symval_count(uint32_t *ret_count);
147errval_t spawn_symval_cache_init(uint8_t lazy);
148
149__END_DECLS
150
151#endif //SPAWNDOMAIN_H
152