blob: b982d136b3e6facb5f5bf425c85138135789c80f (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#ifndef TASKS_H
#define TASKS_H
#include "stdint.h"
#define TASK_STACK_SIZE 4096
#if defined( __TINYC__ )
#pragma pack(1)
#endif
typedef struct {
// pushed by us
uint32_t eax;
uint32_t ebx;
uint32_t ecx;
uint32_t edx;
uint32_t esi;
uint32_t edi;
uint32_t ebp;
// really needed?
//~ uint32_t gs;
//~ uint32_t fs;
//~ uint32_t es;
//~ uint32_t ds;
// ?
uint32_t error;
// pushed by the CPU
uint32_t eip;
uint32_t cs;
uint32_t eflags;
uint32_t esp;
uint32_t ss;
} __attribute__( ( packed ) ) cpu_state_t;
#if defined( __TINYC__ )
#pragma pack()
#endif
typedef struct {
uint8_t stack[TASK_STACK_SIZE];
cpu_state_t *cpu_state;
int nof_switches;
} task_t;
typedef void (*task_func_t)( void );
void task_init( task_t *task, uint16_t gdt_code_segment_selector, task_func_t entrypoint );
#define MAX_NOF_TASKS 256
typedef struct {
int nof_tasks;
int current_task;
task_t *task[MAX_NOF_TASKS];
} task_manager_t;
void task_manager_init( task_manager_t *manager );
void task_manager_add_task( task_manager_t *manager, task_t *task );
cpu_state_t *task_manager_schedule_task( task_manager_t *manager, cpu_state_t *cpu_state );
#endif // TASKS_H
|