My Kernel v0.1.0
process.h
Go to the documentation of this file.
1#ifndef KERNEL_ARCH_I686_PROCESS_H
2#define KERNEL_ARCH_I686_PROCESS_H
3
14#include <kernel/interrupts.h>
15#include <kernel/types.h>
16
21typedef struct x86_thread {
22
23 u32 cr3;
24
33 u32 esp0;
34
40
48 u32 esp;
49
52
54
55static inline void
56arch_thread_set_stack_pointer(thread_context_t *ctx, void *stack)
57{
58 ctx->esp = (u32)stack;
59}
60
61static inline void *arch_thread_get_stack_pointer(thread_context_t *ctx)
62{
63 return (void *)ctx->esp;
64}
65
66static inline void
67arch_thread_set_base_pointer(thread_context_t *ctx, void *ptr)
68{
69 ctx->frame.regs.ebp = (vaddr_t)ptr;
70}
71
72static inline void *arch_thread_get_base_pointer(thread_context_t *ctx)
73{
74 return (void *)ctx->frame.regs.ebp;
75}
76
77static inline void
78arch_thread_set_interrupt_frame(thread_context_t *ctx,
79 const struct interrupt_frame *frame)
80{
81 ctx->frame = *frame;
82}
83
84static inline struct interrupt_frame *
85arch_thread_get_interrupt_frame(thread_context_t *ctx)
86{
87 return &ctx->frame;
88}
89
90static inline void
91arch_thread_set_kernel_stack_top(thread_context_t *ctx, void *top)
92{
93 ctx->esp0 = (u32)top;
94}
95
96static inline void *
97arch_thread_get_kernel_stack_top(const thread_context_t *ctx)
98{
99 return (void *)ctx->esp0;
100}
101
102static inline void
103arch_thread_set_user_stack_top(thread_context_t *ctx, void *top)
104{
105 ctx->esp_user = (u32)top;
106}
107
108static inline void *arch_thread_get_user_stack_top(const thread_context_t *ctx)
109{
110 return (void *)ctx->esp_user;
111}
112
113static inline void *
114arch_thread_get_interrupt_return_address(const thread_context_t *ctx)
115{
116 return (void *)ctx->frame.frame.eip;
117}
118
119#endif /* KERNEL_ARCH_I686_PROCESS_H */
struct x86_regs regs
Snapshot of the registers at the time the interrupt happened.
Definition: interrupts.h:121
struct interrupt_frame frame
Frame pushed during the last userland -> kernel context switch.
Definition: process.h:51
u32 esp0
Address of the top of the thread's kernel stack.
Definition: process.h:33
u32 esp_user
Address of the top of the user stack This is only valid for user threads.
Definition: process.h:39
u32 cr3
Physical address of the process's page directory.
Definition: process.h:23
u32 esp
The thread's current stack pointer.
Definition: process.h:48
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:118
Contains all the system-level information about a task.
Definition: process.h:21