1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup kernel_generic
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef KERN_ARCH_H_
|
---|
37 | #define KERN_ARCH_H_
|
---|
38 |
|
---|
39 | #include <config.h>
|
---|
40 |
|
---|
41 | /** Return the current_t structure
|
---|
42 | *
|
---|
43 | * The current_t structure holds pointers to various parts of the current
|
---|
44 | * execution state, like running task, thread, address space, etc.
|
---|
45 | *
|
---|
46 | * The current_t structure is located at the base address of the current
|
---|
47 | * stack. The stack is assumed to be STACK_SIZE bytes long. The stack base
|
---|
48 | * address must be aligned to STACK_SIZE.
|
---|
49 | *
|
---|
50 | */
|
---|
51 | #define CURRENT \
|
---|
52 | ((current_t *) (((uintptr_t) __builtin_frame_address(0)) & \
|
---|
53 | (~((uintptr_t) STACK_SIZE - 1))))
|
---|
54 |
|
---|
55 | #define MAGIC UINT32_C(0xfacefeed)
|
---|
56 |
|
---|
57 | #define container_check(ctn1, ctn2) ((ctn1) == (ctn2))
|
---|
58 |
|
---|
59 | #define DEFAULT_CONTAINER 0
|
---|
60 | #define CONTAINER \
|
---|
61 | ((CURRENT->task) ? (CURRENT->task->container) : (DEFAULT_CONTAINER))
|
---|
62 |
|
---|
63 | /* Fwd decl. to avoid include hell. */
|
---|
64 | struct thread;
|
---|
65 | struct task;
|
---|
66 | struct cpu;
|
---|
67 | struct as;
|
---|
68 |
|
---|
69 | /** Current structure
|
---|
70 | *
|
---|
71 | * For each possible kernel stack, structure
|
---|
72 | * of the following type will be placed at
|
---|
73 | * the base address of the stack.
|
---|
74 | *
|
---|
75 | */
|
---|
76 | typedef struct {
|
---|
77 | size_t preemption; /**< Preemption disabled counter and flag. */
|
---|
78 | size_t mutex_locks;
|
---|
79 | struct thread *thread; /**< Current thread. */
|
---|
80 | struct task *task; /**< Current task. */
|
---|
81 | struct cpu *cpu; /**< Executing CPU. */
|
---|
82 | struct as *as; /**< Current address space. */
|
---|
83 | uint32_t magic; /**< Magic value. */
|
---|
84 | } current_t;
|
---|
85 |
|
---|
86 | typedef struct {
|
---|
87 | void (*pre_mm_init)(void);
|
---|
88 | void (*post_mm_init)(void);
|
---|
89 | void (*post_cpu_init)(void);
|
---|
90 | void (*pre_smp_init)(void);
|
---|
91 | void (*post_smp_init)(void);
|
---|
92 | } arch_ops_t;
|
---|
93 |
|
---|
94 | extern arch_ops_t *arch_ops;
|
---|
95 |
|
---|
96 | #define ARCH_STRUCT_OP(s, op) \
|
---|
97 | do { \
|
---|
98 | if ((s)->op) \
|
---|
99 | (s)->op(); \
|
---|
100 | } while (0)
|
---|
101 |
|
---|
102 | #define ARCH_OP(op) ARCH_STRUCT_OP(arch_ops, op)
|
---|
103 |
|
---|
104 | extern void current_initialize(current_t *);
|
---|
105 | extern void current_copy(current_t *, current_t *);
|
---|
106 |
|
---|
107 | extern void calibrate_delay_loop(void);
|
---|
108 |
|
---|
109 | extern void arch_reboot(void);
|
---|
110 | extern void *arch_construct_function(fncptr_t *, void *, void *);
|
---|
111 |
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | /** @}
|
---|
115 | */
|
---|