Warning, cross-references for /kernel/include/kernel.h need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef _KERNEL_H_
0019 #define _KERNEL_H_
0020
0021
0022
0023 #ifdef ENABLE_GDBSTUB
0024 #define GDBSTUB_TCP
0025 #define GDBSTUB_TCP_PORT 1234
0026 #define GDBSTUB_ETHDEV "en0"
0027 #define GDBSTUB_BUFFER_SIZE 512
0028 #define BREAKPOINT() asm(" int $3");
0029 #else
0030 #define BREAKPOINT() ;
0031 #endif
0032
0033 #define PIT_FREQ 1193181
0034 #define HZ 500
0035 #define MAX_CPUS 8
0036
0037 #include "kernel-defs.h"
0038
0039 #ifndef NULL
0040 #define NULL ((void*)0)
0041 #endif
0042
0043 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
0044 #define container_of(ptr, type, member) ({ \
0045 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
0046 (type *)( (char *)__mptr - offsetof(type,member) );})
0047
0048 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
0049 #define BIT(nr) (1UL << (nr))
0050 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
0051 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
0052 #define BITS_PER_BYTE 8
0053 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
0054
0055
0056
0057
0058 #define BITMAP_SET(table,index) ((table)[(index)>>5] |= (1 << ((index) & 31)))
0059 #define BITMAP_CLR(table,index) ((table)[(index)>>5] &= ~(1 << ((index) & 31)))
0060 #define BITMAP_TST(table,index) ((table)[(index)>>5] & (1 << ((index) & 31)))
0061
0062
0063 #ifndef __ASSEMBLER__
0064 #include "arch/i386.h"
0065 #include "smp/spinlock.h"
0066 #include "smp/semaphore.h"
0067
0068 struct sched_param
0069 {
0070 int sched_priority;
0071
0072
0073 int C;
0074 int T;
0075 int m;
0076 int k;
0077 };
0078
0079 #define NUM_M 32
0080
0081
0082
0083 typedef struct _quest_tss
0084 {
0085 u32 ESP;
0086 u32 EBP;
0087
0088
0089
0090
0091
0092 u32 initial_EIP;
0093 u32 CR3;
0094 u32 EFLAGS;
0095 struct _semaphore Msem;
0096 u32 M[NUM_M];
0097
0098 uint16 next;
0099
0100
0101
0102
0103
0104
0105
0106 uint16 waitqueue;
0107
0108
0109 bool busy;
0110
0111 uint32 priority;
0112 uint64 time;
0113
0114
0115 u16 cpu;
0116 } quest_tss;
0117
0118 extern char *kernel_version;
0119 extern uint16 runqueue[];
0120
0121 extern quest_tss *lookup_TSS (uint16 selector);
0122 extern void *lookup_GDT_selector (uint16 selector);
0123 extern void get_GDT_descriptor (uint16, descriptor *);
0124
0125 extern void panic (char *sz) __attribute__ ((noreturn));
0126
0127 extern void lock_kernel (void);
0128 extern void unlock_kernel (void);
0129
0130 extern void disable_idt (void);
0131 extern void enable_idt (void);
0132 extern void enable_idt_entry (uint16);
0133 extern void set_idt_descriptor_by_addr (uint8, void *, uint8);
0134 extern void get_idt_descriptor (uint8, idt_descriptor *);
0135 extern void set_idt_descriptor (uint8, idt_descriptor *);
0136
0137 typedef uint32 (*vector_handler) (uint8 vector);
0138 extern void set_vector_handler (uint8 vector, vector_handler func);
0139 extern void clr_vector_handler (uint8 vector);
0140 extern vector_handler get_vector_handler (uint8 vector);
0141 #define MINIMUM_VECTOR_PRIORITY 0x4
0142 extern u8 find_unused_vector (u8 min_prio);
0143 extern void init_interrupt_handlers (void);
0144
0145 void stacktrace (void);
0146
0147 void tsc_delay_usec (uint32 usec);
0148
0149 uint16 duplicate_TSS (uint32 ebp,
0150 uint32 *esp,
0151 uint32 child_eip,
0152 uint32 child_ebp,
0153 uint32 child_esp,
0154 uint32 child_eflags,
0155 uint32 child_directory);
0156
0157 typedef uint16 task_id;
0158
0159 task_id start_kernel_thread (uint eip, uint esp);
0160 task_id create_kernel_thread_args (uint eip, uint esp, bool run, uint n, ...);
0161 void exit_kernel_thread (void);
0162
0163
0164 extern uint32 ul_stack[][1024] __attribute__ ((aligned (4096)));
0165
0166
0167 extern uint32 ul_tss[][1024] __attribute__ ((aligned (4096)));
0168
0169
0170 extern uint32 pg_dir[][1024] __attribute__ ((aligned (4096)));
0171
0172
0173 extern uint32 pg_table[][1024] __attribute__ ((aligned (4096)));
0174
0175
0176 extern uint32 kl_stack[][1024] __attribute__ ((aligned (4096)));
0177
0178
0179 extern uint32 kls_pg_table[][1024] __attribute__ ((aligned (4096)));
0180
0181 extern quest_tss idleTSS[MAX_CPUS];
0182
0183 extern tss cpuTSS[MAX_CPUS];
0184
0185 extern uint16 idleTSS_selector[MAX_CPUS];
0186
0187 extern uint16 cpuTSS_selector[MAX_CPUS];
0188
0189 extern spinlock screen_lock;
0190
0191 extern uint8 idt_ptr[];
0192
0193 extern uint8 sched_enabled;
0194
0195 static inline uint8
0196 checksum (uint8 * ptr, int length)
0197 {
0198 uint8 sum = 0;
0199 while (length-- > 0)
0200 sum += *ptr++;
0201 return sum;
0202 }
0203
0204 extern uint get_pcpu_id (void);
0205
0206 #endif
0207 #endif
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218