source: mainline/kernel/generic/include/arch.h@ 690ad20

Last change on this file since 690ad20 was f35749e, checked in by Jiri Svoboda <jiri@…>, 4 months ago

System restart via shutdown -r

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[f761f1eb]1/*
[f35749e]2 * Copyright (c) 2025 Jiri Svoboda
[df4ed85]3 * Copyright (c) 2001-2004 Jakub Jermar
[f761f1eb]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
[174156fd]30/** @addtogroup kernel_generic
[b45c443]31 * @{
32 */
33/** @file
34 */
35
[9a5b556]36#ifndef KERN_ARCH_H_
37#define KERN_ARCH_H_
[f761f1eb]38
[d4d36f9]39#include <config.h>
[1066041]40
[128359eb]41/** Return the current_t structure
42 *
[a6e55886]43 * The current_t structure holds pointers to various parts of the current
44 * execution state, like running task, thread, address space, etc.
[128359eb]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 *
[473d5d2]50 */
[128359eb]51#define CURRENT \
52 ((current_t *) (((uintptr_t) __builtin_frame_address(0)) & \
53 (~((uintptr_t) STACK_SIZE - 1))))
[cfffb290]54
[128359eb]55#define MAGIC UINT32_C(0xfacefeed)
[473d5d2]56
57#define container_check(ctn1, ctn2) ((ctn1) == (ctn2))
[f761f1eb]58
[473d5d2]59#define DEFAULT_CONTAINER 0
60#define CONTAINER \
[a6e55886]61 ((CURRENT->task) ? (CURRENT->task->container) : (DEFAULT_CONTAINER))
[cfffb290]62
[1066041]63/* Fwd decl. to avoid include hell. */
64struct thread;
65struct task;
66struct cpu;
67struct as;
68
[128359eb]69/** Current structure
70 *
[361635c]71 * For each possible kernel stack, structure
72 * of the following type will be placed at
[ff75d34]73 * the base address of the stack.
[128359eb]74 *
[361635c]75 */
[62c63fc]76typedef struct {
[128359eb]77 size_t preemption; /**< Preemption disabled counter and flag. */
[b076dfb]78 size_t mutex_locks;
[128359eb]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. */
[a6e55886]84} current_t;
[361635c]85
[36df4109]86typedef struct {
[5b0cf63]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);
[36df4109]92} arch_ops_t;
93
94extern arch_ops_t *arch_ops;
95
[7510326]96#define ARCH_STRUCT_OP(s, op) \
[36df4109]97 do { \
[7510326]98 if ((s)->op) \
99 (s)->op(); \
[36df4109]100 } while (0)
101
[128359eb]102#define ARCH_OP(op) ARCH_STRUCT_OP(arch_ops, op)
[7510326]103
[a6e55886]104extern void current_initialize(current_t *);
105extern void current_copy(current_t *, current_t *);
[bcdd9aa]106
[f761f1eb]107extern void calibrate_delay_loop(void);
108
[f74bbaf]109extern void arch_reboot(void);
[2e4e706]110extern void *arch_construct_function(fncptr_t *, void *, void *);
[f74bbaf]111
[f761f1eb]112#endif
[b45c443]113
[42d3be3]114/** @}
[b45c443]115 */
Note: See TracBrowser for help on using the repository browser.