forked from mwkmwkmwk/zso-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.c
More file actions
32 lines (29 loc) · 741 Bytes
/
Copy paththread.c
File metadata and controls
32 lines (29 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "thread.h"
#include "io.h"
struct thread idle_thread = {
.next = &idle_thread,
.prev = &idle_thread,
.blocked = 1,
};
struct thread *current_thread = &idle_thread;
void start_thread(struct thread *thread, uint8_t *stack, void (*func) (void *), void *param) {
cli();
thread->prev = current_thread;
thread->next = current_thread->next;
current_thread->next->prev = thread;
current_thread->next = thread;
uint32_t *pparam = (uint32_t *)(stack - 4);
*pparam = (uint32_t)param;
stack -= 8;
thread->blocked = 0;
thread->eip = (uint32_t)func;
thread->esp = (uint32_t)stack;
thread->eflags = 0x202;
thread->es = 0x10;
thread->cs = 0x8;
thread->ss = 0x10;
thread->ds = 0x10;
thread->fs = 0;
thread->gs = 0;
sti();
}