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/types.h>
15#include <kernel/interrupts.h>
16
17
22typedef struct x86_thread {
23
24 u32 cr3;
25
34 u32 esp0;
35
41
49 u32 esp;
50
53
55
56static inline void
57arch_thread_set_stack_pointer(thread_context_t *ctx, void *stack)
58{
59 ctx->esp = (u32)stack;
60}
61
62static inline void *arch_thread_get_stack_pointer(thread_context_t *ctx)
63{
64 return (void *)ctx->esp;
65}
66
67static inline void
68arch_thread_set_base_pointer(thread_context_t *ctx, void *ptr)
69{
70 ctx->frame.stub.ebp = (vaddr_t)ptr;
71}
72
73static inline void *arch_thread_get_base_pointer(thread_context_t *ctx)
74{
75 return (void *)ctx->frame.stub.ebp;
76}
77
78static inline void
79arch_thread_set_interrupt_frame(thread_context_t *ctx,
80 const struct interrupt_frame *frame)
81{
82 ctx->frame = *frame;;
83}
84
85static inline void
86arch_thread_set_kernel_stack_top(thread_context_t *ctx, void *top)
87{
88 ctx->esp0 = (u32)top;
89}
90
91static inline void *
92arch_thread_get_kernel_stack_top(const thread_context_t *ctx)
93{
94 return (void *)ctx->esp0;
95}
96
97static inline void
98arch_thread_set_user_stack_top(thread_context_t *ctx, void *top)
99{
100 ctx->esp_user = (u32)top;
101}
102
103static inline void *arch_thread_get_user_stack_top(const thread_context_t *ctx)
104{
105 return (void *)ctx->esp_user;
106}
107
108static inline void *
109arch_thread_get_interrupt_return_address(const thread_context_t *ctx)
110{
111 return (void *)ctx->frame.state.eip;
112}
113
114#endif /* KERNEL_ARCH_I686_PROCESS_H */
struct interrupt_frame frame
Frame pushed during the last userland -> kernel context switch.
Definition: process.h:52
u32 esp0
Address of the top of the thread's kernel stack.
Definition: process.h:34
u32 esp_user
Address of the top of the user stack This is only valid for user threads.
Definition: process.h:40
u32 cr3
Physical address of the process's page directory.
Definition: process.h:24
u32 esp
The thread's current stack pointer.
Definition: process.h:49
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:121
Contains all the system-level information about a task.
Definition: process.h:22