1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#ifndef _REFOS_INITIALISE_HELPER_H_
14#define _REFOS_INITIALISE_HELPER_H_
15
16#include <stdint.h>
17#include <stdbool.h>
18#include <sel4/sel4.h>
19#include <autoconf.h>
20
21/*! @file
22    @brief RefOS client environment initialisation helper functions.
23
24    Helper functions which initialise a RefOS user or system process environment. Initialises the
25    allocators and file tables and so forth.
26*/
27
28#define SELFLOADER_PROCINFO_MAGIC 0xD174A029
29#define REFOS_DEFAULT_TIMER_DSPACE "/dev_timer/time"
30#define REFOS_DEFAULT_DSPACE_IPC_MAXLEN 64
31
32#if defined(CONFIG_REFOS_STDIO_DSPACE_SERIAL)
33    #define REFOS_DEFAULT_STDIO_DSPACE "/dev_console/serial"
34#elif defined(CONFIG_REFOS_STDIO_DSPACE_SCREEN)
35    #define REFOS_DEFAULT_STDIO_DSPACE "/dev_console/screen"
36#else
37    #define REFOS_DEFAULT_STDIO_DSPACE "/dev_console/stdio"
38#endif
39
40/*! @brief Self-loader dataspace mapping struct. */
41typedef struct sl_dataspace_s {
42    seL4_CPtr dataspace;
43    seL4_CPtr window;
44    uint32_t vaddr;
45    uint32_t size;
46} sl_dataspace_t;
47
48/*! @brief Self-loader process boot info struct. Contains ELF related information used for dynamic
49           heap and mmap. */
50typedef struct sl_procinfo_s {
51    uint32_t magic;
52    uint32_t elfSegmentEnd;
53
54    sl_dataspace_t heapRegion;
55    sl_dataspace_t stackRegion;
56} sl_procinfo_t;
57
58/*! @brief Point the selfloaded process to the parent's system call table. */
59void refos_init_selfload_child(uintptr_t parent_syscall_table_address);
60
61/*! @brief Initialise minimal OS environment, for RefOS low-level OS servers. */
62void refos_initialise_os_minimal(void);
63
64/*! @brief Initialise a tiny environment, just for the selfloader. */
65void refos_initialise_selfloader(void);
66
67/*! @brief Initialise a full RefOS userland environment for the timer server. Requires all the system
68           infrastructure to be set up. */
69void refos_initialise_timer(void);
70
71/*! @brief Initialise a full RefOS userland environment. Requires all the system infrastructure to
72           be set up. */
73void refos_initialise(void);
74
75/*! @brief Returns pointer to the contents of the static parameter buffer.
76
77    The static parameter buffer is used to pass information from the process management server
78    downwards to its child process; This is needed so that the process server can pass information
79    down before proper parameter sharing using a shared dataspace has been set up.
80
81    Assumes that the parent process has written the content to a constant predefined address.
82
83    @return Pointer to static parameter buffer.
84 */
85char *refos_static_param(void);
86
87/*! @brief Returns pointer to the contents of the static procinfo structure.
88    @return Pointer to static procinfo structure. (See sl_procinfo_s).
89*/
90struct sl_procinfo_s *refos_static_param_procinfo(void);
91
92#endif /* _REFOS_INITIALISE_HELPER_H_ */
93