-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtn_port.h
109 lines (77 loc) · 3.44 KB
/
tn_port.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
SATNKernel real-time kernel for the Sega Saturn
Based on TNKernel version 2.7
Copyright © 2004, 2013 Yuri Tiomkin
Saturn version modifications copyright © 2013 Anders Montonen
All rights reserved.
Permission to use, copy, modify, and distribute this software in source
and binary forms and its documentation for any purpose and without fee
is hereby granted, provided that the above copyright notice appear
in all copies and that both that copyright notice and this permission
notice appear in supporting documentation.
THIS SOFTWARE IS PROVIDED BY THE YURI TIOMKIN AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL YURI TIOMKIN OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef _TN_PORT_H_
#define _TN_PORT_H_
#define align_attr_start
#define align_attr_end __attribute__((aligned(0x8)))
#define TN_TIMER_STACK_SIZE 80
#define TN_IDLE_STACK_SIZE 60
#define TN_MIN_STACK_SIZE 53
#define TN_BITS_IN_INT 32
#define TN_ALIG sizeof(void*)
#define MAKE_ALIG(a) ((sizeof(a) + (TN_ALIG-1)) & (~(TN_ALIG-1)))
#define TN_PORT_STACK_EXPAND_AT_EXIT 21
#define USE_ASM_FFS
//----------------------------------------------------
#define TN_NUM_PRIORITY TN_BITS_IN_INT //-- 0..31 Priority 0 always is used by timers task
#define TN_WAIT_INFINITE 0xFFFFFFFF
#define TN_FILL_STACK_VAL 0xFFFFFFFF
#define TN_INVALID_VAL 0xFFFFFFFF
//-- Assembler functions prototypes
#ifdef __cplusplus
extern "C" {
#endif
void tn_switch_context_exit(void);
void tn_switch_context(void);
unsigned int tn_cpu_save_sr(void);
void tn_cpu_restore_sr(unsigned int sr);
void tn_start_exe(void);
int tn_chk_irq_disabled(void);
int tn_inside_int(void);
int ffs_asm(unsigned int val);
void *tn_hook_vec(int vec, void *func);
void tn_switch_context_trap(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
//-- Interrupt processing - processor specific
#define TN_INTSAVE_DATA_INT int tn_save_status_reg = 0;
#define TN_INTSAVE_DATA int tn_save_status_reg = 0;
#define tn_disable_interrupt() tn_save_status_reg = tn_cpu_save_sr()
#define tn_enable_interrupt() tn_cpu_restore_sr(tn_save_status_reg)
#define tn_idisable_interrupt() tn_save_status_reg = tn_cpu_save_sr()
#define tn_ienable_interrupt() tn_cpu_restore_sr(tn_save_status_reg)
#define TN_CHECK_INT_CONTEXT \
if(!tn_inside_int()) \
return TERR_WCONTEXT;
#define TN_CHECK_INT_CONTEXT_NORETVAL \
if(!tn_inside_int()) \
return;
#define TN_CHECK_NON_INT_CONTEXT \
if(tn_inside_int()) \
return TERR_WCONTEXT;
#define TN_CHECK_NON_INT_CONTEXT_NORETVAL \
if(tn_inside_int()) \
return ;
#endif