Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
include
kernel
kernel.h
Go to the documentation of this file.
1
4
#ifndef __KERNEL_H__
5
#define __KERNEL_H__
6
7
#include <
pthread.h
>
8
#include <
signal.h
>
9
#include <stdbool.h>
10
#include <stdint.h>
11
#include <
sys/limits.h
>
12
#include <
sys/resource.h
>
13
#include <
task.h
>
14
15
#include <
common/list.h
>
16
#include <
common/util.h
>
17
#include <
fs/fs.h
>
18
#include <
kernel/kfifo.h
>
19
#include <
kernel/time.h
>
20
#include <
kernel/wait.h
>
21
22
#include "kconfig.h"
23
24
#define DEF_SYSCALL(func, _num) \
25
{ \
26
.handler_func = (unsigned long) sys_##func, .num = _num \
27
}
28
29
#define SYSCALL_ARG(thread, type, idx) *((type *) thread->syscall_args[idx])
30
31
struct
syscall_info
{
32
unsigned
long
handler_func;
33
uint32_t num;
34
};
35
36
struct
staged_handler_info
{
37
uint32_t func;
38
uint32_t args[4];
39
};
40
41
enum
{
42
THREAD_WAIT,
43
THREAD_READY,
44
THREAD_RUNNING,
45
THREAD_SUSPENDED,
46
THREAD_TERMINATED,
47
} THREAD_STATUS;
48
49
enum
{
50
KERNEL_THREAD = 0,
51
USER_THREAD = 1,
52
} THREAD_TYPE;
53
54
struct
task_struct
{
55
uint16_t pid;
/* Task ID */
56
struct
thread_info
*main_thread;
/* The main thread belongs to the task */
57
58
/* For recording for the file descriptors belongs to the task */
59
uint32_t bitmap_fds[BITMAP_SIZE(OPEN_MAX)];
60
61
/* For recording message queue descriptors belongs to the task */
62
uint32_t bitmap_mqds[BITMAP_SIZE(MQUEUE_MAX)];
63
64
struct
list_head
threads_list;
/* List of all threads of the task */
65
struct
list_head
list;
/* Linked to the global task list */
66
};
67
68
struct
thread_info
{
69
/* Task */
70
struct
task_struct
*task;
/* Task of the thread belongs to */
71
72
/* Stack */
73
unsigned
long
*stack_top;
/* Stack pointer to the top of the thread stack */
74
unsigned
long
stack_top_preserved;
/* Preserve for staging new handler */
75
unsigned
long
*stack;
/* Base address of the thread stack */
76
size_t
stack_size;
/* Stack size of the thread in bytes */
77
78
/* Syscall */
79
unsigned
long
*syscall_args[4];
/* Pointer to the syscall arguments */
80
unsigned
long
*syscall_stack_top;
81
bool
syscall_mode;
82
bool
syscall_is_timeout;
/* Indicate if the syscall waiting time is up */
83
struct
timespec
syscall_timeout;
/* For setting timeout of the syscall */
84
85
/* Thread */
86
void
*retval;
/* For passing retval after the thread end */
87
void
**retval_join;
/* To getting retval from a thread to join */
88
size_t
file_request_size;
/* Size of the thread requesting to a file */
89
uint32_t sleep_ticks;
/* Remained ticks to sleep */
90
uint32_t preempt_cnt;
/* For preserving threads's preemption level */
91
uint16_t tid;
/* Thread ID */
92
uint16_t timer_cnt;
/* The number of timers that the thread has */
93
uint8_t privilege;
/* Current execution privilege level */
94
uint8_t status;
/* Thread status */
95
uint8_t priority;
/* Thread priority */
96
uint8_t original_priority;
/* Original priority before inheritance */
97
bool
kernel_thread;
/* Kernel thread or user thread */
98
bool
priority_inherited;
/* True if current priority is inherited */
99
bool
detached;
/* Thread is detached or not */
100
bool
joinable;
/* Thread is joinable or not */
101
char
name[THREAD_NAME_MAX];
/* Thread name */
102
struct
thread_once
*once_control;
/* For handling pthread_once_control */
103
104
/* Signals */
105
struct
sigaction
*sig_table[SIGNAL_CNT];
106
struct
kfifo
signal_queue;
/* The queue for pending signals */
107
sigset_t sig_wait_set;
/* The set of the signals to wait */
108
uint32_t signal_cnt;
/* The number of pending signals in the queue */
109
int
*ret_sig;
/* For storing retval of the sigwait */
110
bool
wait_for_signal;
/* Indicates the thread is waiting for signal */
111
112
/* Lists */
113
struct
list_head
timers_list;
/* List of timers belongs to the thread */
114
struct
list_head
poll_files_list;
/* List of all files polling for */
115
struct
list_head
task_list;
/* Linked to the task thread list */
116
struct
list_head
thread_list;
/* Linked to the global thread list */
117
struct
list_head
timeout_list;
/* Linked to the global timeout list */
118
struct
list_head
join_list;
/* Linked to another thread waiting for join */
119
struct
list_head
list;
/* Linked to a scheduling list */
120
};
121
122
#endif
fs.h
time.h
kfifo.h
limits.h
list.h
pthread.h
resource.h
kfifo
Definition:
kfifo.h:11
list_head
Definition:
list.h:111
sigaction
Definition:
signal.h:35
staged_handler_info
Definition:
kernel.h:36
syscall_info
Definition:
kernel.h:31
task_struct
Definition:
kernel.h:54
thread_info
Definition:
kernel.h:68
thread_once
Definition:
thread.h:22
timespec
Definition:
time.h:14
task.h
signal.h
util.h
wait.h
Generated by
1.9.1