Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/kernel.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _KERNEL_H_
0019 #define _KERNEL_H_
0020 
0021 //#define ENABLE_GDBSTUB          /* the remote debugger via GDB */
0022 
0023 #ifdef ENABLE_GDBSTUB
0024 #define GDBSTUB_TCP             /* using TCP instead of serial port */
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        /* in Hz */
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 /* Bitmap utility functions for e.g., physical memory map and also
0057    scheduling priority queues */
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 /* Don't let preprocessed assemby files (*.S) include these lines */
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   /* Below are paramters used for window-constrained scheduling */
0073   int C;                        /* service quantum */
0074   int T;                        /* period */
0075   int m;                        /* mandatory instance count in a window */
0076   int k;                        /* window of requests  */
0077 };
0078 
0079 #define NUM_M 32
0080 
0081 /* A Quest TSS is a software-only construct, a.k.a Thread Control
0082  * Block (TCB). */
0083 typedef struct _quest_tss
0084 {
0085   u32 ESP;
0086   u32 EBP;
0087   /* The initial instruction pointer is written both to here and the
0088    * kernel stack.  In the case of the initial user-space application,
0089    * this field is used to load the first IRET into user-space.  In
0090    * all other cases, the kernel stack contains the EIP to resume
0091    * operation. */
0092   u32 initial_EIP;
0093   u32 CR3;
0094   u32 EFLAGS;
0095   struct _semaphore Msem;
0096   u32 M[NUM_M];
0097 
0098   uint16 next;                  /* selector for next TSS in corresponding queue
0099                                    (beit the runqueue for the CPU or a waitqueue for
0100                                    a resource; 0 if task is at end of queue. If a
0101                                    task is runnable 'next' refers to a TSS selector
0102                                    on the runqueue; if a task is waiting on a
0103                                    resource, 'next' refers to a TSS selector on the
0104                                    corresponding waitqueue; for all other cases,
0105                                    'next' is irrelevant */
0106   uint16 waitqueue;             /* queue of other tasks waiting for this
0107                                    one -- either attempting to send IPC to it,
0108                                    or waiting for it to exit */
0109   bool busy;                    /* mutex for server: when busy, clients must add themselves to
0110                                    waitqueue above */
0111   uint32 priority;
0112   uint64 time;                  /* A field for time values associated
0113                                    with task, for example, to be used
0114                                    by waitqueue managers. */
0115   u16 cpu;                      /* [V]CPU binding */
0116 } quest_tss;
0117 
0118 extern char *kernel_version;
0119 extern uint16 runqueue[];       /* TSS of next runnable task; 0 if none */
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 /* Declare space for a stack */
0164 extern uint32 ul_stack[][1024] __attribute__ ((aligned (4096)));
0165 
0166 /* Declare space for a task state segment */
0167 extern uint32 ul_tss[][1024] __attribute__ ((aligned (4096)));
0168 
0169 /* Declare space for a page directory */
0170 extern uint32 pg_dir[][1024] __attribute__ ((aligned (4096)));
0171 
0172 /* Declare space for a page table */
0173 extern uint32 pg_table[][1024] __attribute__ ((aligned (4096)));
0174 
0175 /* Declare space for per process kernel stack */
0176 extern uint32 kl_stack[][1024] __attribute__ ((aligned (4096)));
0177 
0178 /* Declare space for a page table mappings for kernel stacks */
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 /* __ASSEMBLER__ */
0207 #endif
0208 
0209 /*
0210  * Local Variables:
0211  * indent-tabs-mode: nil
0212  * mode: C
0213  * c-file-style: "gnu"
0214  * c-basic-offset: 2
0215  * End:
0216  */
0217 
0218 /* vi: set et sw=2 sts=2: */