-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.h
executable file
·61 lines (52 loc) · 2.23 KB
/
kernel.h
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
/**
* Immortal Operating System - immortalOS
*
*/
#ifndef KERNEL_H
#define KERNEL_H
#include "types.h"
extern tcb_t F_APTOS[MAX_TASKS];
extern u_int task_running;
void create_task(u_int id, u_int prior, f_ptr task_f);
u_int get_id(u_int task_ptr);
void delay(u_int time_ms);
void dispatcher(state_t state);
void task_idle();
void start_os();
void setupOS();
void interrupt int_high();
// Macros para salvamento de contexto
#define SAVE_CONTEXT(state) \
F_APTOS[task_running].task_state = state; \
F_APTOS[task_running].BSR_register = BSR; \
F_APTOS[task_running].STATUS_register = STATUS; \
F_APTOS[task_running].WORK_register = WREG; \
F_APTOS[task_running].task_stack.stack_size = 0; \
do { \\
F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSU_register = TOSU; \
F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSL_register = TOSL; \
F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSH_register = TOSH; \
F_APTOS[task_running].task_stack.stack_size++; \
asm("POP");\
} while (STKPTR);
#define RESTORE_CONTEXT()\\
STKPTR = 0;\\
if (F_APTOS[task_running].task_stack.stack_size == 0) {\\
asm("PUSH");\\
TOS = F_APTOS[task_running].task_f;\\
}\\
else {\\
BSR = F_APTOS[task_running].BSR_register;\\
STATUS = F_APTOS[task_running].STATUS_register;\\
WREG = F_APTOS[task_running].WORK_register;\\
do { \\
asm("PUSH");\\
F_APTOS[task_running].task_stack.stack_size--;\\
TOSU = F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSU_register;\\
TOSL = F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSL_register;\\
TOSH = F_APTOS[task_running].task_stack.STACK[F_APTOS[task_running].task_stack.stack_size].TOSH_register;\\
} while (F_APTOS[task_running].task_stack.stack_size);\\
}\\
F_APTOS[task_running].task_state = RUNNING;\\
ei();\
#endif /* KERNEL_H */