#include <cassert>
#include <cstring>
#include "cpu_io.h"
#include "per_cpu.hpp"
#include "task_manager.hpp"
#include "test_environment_state.hpp"
#include <stdio.h>
Go to the source code of this file.
◆ etl_putchar()
| void etl_putchar |
( |
int |
c | ) |
|
早期控制台字符输出
- Copyright
- Copyright The SimpleKernel Contributors
- Parameters
-
早期控制台字符输出
- Copyright
- Copyright The SimpleKernel Contributors
Definition at line 77 of file arch.cpp.
◆ InitTaskContext() [1/2]
初始化用户线程的任务上下文(重载2)
- Parameters
-
| task_context | 指向任务上下文的指针 |
| trap_context_ptr | 指向 Trap 上下文的指针 |
| stack_top | 内核栈顶地址 |
- Precondition
- task_context 不为 nullptr,trap_context_ptr 已填充用户态寄存器
- Postcondition
- task_context 已设置为经由 trap_return 返回用户态的状态
- Todo:
- x86_64 实现待补充
Definition at line 62 of file arch.cpp.
64 {
65
67
71 task_context->
EntryArgument() =
reinterpret_cast<uint64_t
>(trap_context_ptr);
73}
void kernel_thread_entry()
__always_inline uint64_t & EntryFunction()
__always_inline uint64_t & EntryArgument()
__always_inline uint64_t & ReturnAddress()
__always_inline uint64_t & StackPointer()
◆ InitTaskContext() [2/2]
初始化内核线程的任务上下文(重载1)
- Parameters
-
| task_context | 指向任务上下文的指针 |
| entry | 线程入口函数 |
| arg | 传递给线程的参数 |
| stack_top | 内核栈顶地址 |
- Precondition
- task_context 不为 nullptr,stack_top 已按架构要求对齐
- Postcondition
- task_context 已设置为可被 switch_to 恢复的状态
- Todo:
- x86_64 实现待补充
Definition at line 50 of file arch.cpp.
51 {
52
54
57 task_context->
EntryFunction() =
reinterpret_cast<uint64_t
>(entry);
58 task_context->
EntryArgument() =
reinterpret_cast<uint64_t
>(arg);
60}
◆ kernel_thread_entry()
| void kernel_thread_entry |
( |
| ) |
|
◆ switch_to()
- Copyright
- Copyright The SimpleKernel Contributors
Definition at line 15 of file arch.cpp.
16 {
17 auto* env_state =
19 assert(env_state &&
20 "TestEnvironmentState not set for current thread. "
21 "Did you forget to call SetCurrentThreadEnvironment()?");
22
23 auto& core_env = env_state->GetCurrentCoreEnv();
24
25
26 auto* prev_task = env_state->FindTaskByContext(prev_ctx);
27 auto* next_task = env_state->FindTaskByContext(next_ctx);
28
29
31
32
35 event.from = prev_task;
36 event.to = next_task;
37 event.core_id = core_env.core_id;
38 core_env.switch_history.push_back(event);
39
40
41 per_cpu.running_task = next_task;
42}
static auto GetCurrentThreadEnvironment() -> TestEnvironmentState *
获取当前线程的环境实例指针(供 Mock 层调用)
static __always_inline auto GetCurrentCore() -> PerCpu &
获取当前核心的 PerCpu 数据
◆ trap_entry()
◆ trap_return()
| void trap_return |
( |
void * |
| ) |
|