cynix

x86 UNIX-like OS
git clone git://git.2f30.org/cynix
Log | Files | Refs | README | LICENSE

tss.h (3575B)


      1 #ifndef __TSS_H__
      2 #define __TSS_H__
      3 
      4 #include <stdint.h>
      5 #include <idt.h>
      6 #include <mm.h>
      7 #include <list.h>
      8 #include <ext2.h>
      9 #include <x86.h>
     10 #include <sys/types.h>
     11 #include <serial.h>
     12 
     13 #define DUMP_CSWITCH_FRAME(frame) \
     14 	({ \
     15 		DEBUG_CODE(serial_dump("ds = 0x%lx\n", frame->ds);) \
     16 		DEBUG_CODE(serial_dump("edi = 0x%lx, esi = 0x%lx, ebp = 0x%lx, esp = 0x%lx, ebx = 0x%lx, edx = 0x%lx, ecx = 0x%lx, eax = 0x%lx\n", \
     17 				       frame->edi, frame->esi, frame->ebp, frame->esp, frame->ebx, frame->edx, frame->ecx, frame->eax);) \
     18 		DEBUG_CODE(serial_dump("int_no = 0x%lx, err_code = 0x%lx\n", frame->int_no, frame->err_code);) \
     19 		DEBUG_CODE(serial_dump("eip = 0x%lx, cs = 0x%lx, eflags = 0x%lx\n", \
     20 				       frame->eip, frame->cs, frame->eflags);) \
     21 	})
     22 
     23 #define TASK_STACK_SIZE (2048 * sizeof(uint32_t))
     24 #define WNOHANG 1
     25 
     26 enum task_state_t {
     27 	TASK_ZOMBIE,
     28 	TASK_SLEEPING,
     29 	TASK_RUNNABLE,
     30 	TASK_RUNNING
     31 };
     32 
     33 enum task_fl {
     34 	KERNEL_PROCESS = 1,
     35 	USER_PROCESS
     36 };
     37 
     38 struct tss_t {
     39 	uint32_t link;
     40 	uint32_t esp0;
     41 	uint32_t ss0;
     42 	uint32_t esp1;
     43 	uint32_t ss1;
     44 	uint32_t esp2;
     45 	uint32_t ss2;
     46 	uint32_t cr3;
     47 	uint32_t eip;
     48 	uint32_t eflags;
     49 	uint32_t eax;
     50 	uint32_t ecx;
     51 	uint32_t edx;
     52 	uint32_t ebx;
     53 	uint32_t esp;
     54 	uint32_t ebp;
     55 	uint32_t esi;
     56 	uint32_t edi;
     57 	uint32_t es;
     58 	uint32_t cs;
     59 	uint32_t ss;
     60 	uint32_t ds;
     61 	uint32_t fs;
     62 	uint32_t gs;
     63 	uint32_t ldt;
     64 	uint16_t trace_bitmap;
     65 	uint16_t iomap;
     66 } __attribute__ ((packed));
     67 
     68 struct cswitch_frame_t {
     69 	uint32_t ds; /* Data segment selector */
     70 	uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; /* Pushed by pusha. */
     71 	uint32_t int_no, err_code; /* Interrupt number and error code (if applicable) */
     72 	uint32_t eip, cs, eflags; /* Pushed by the processor automatically. I might need to add useresp and ss.*/
     73 } __attribute__ ((packed));
     74 
     75 struct tss_descriptor_t {
     76 	uint16_t limit_lo         : 16;
     77 	uint16_t base_lo          : 16;
     78 	uint8_t  base_middle      : 8;
     79 	uint8_t  type             : 4; /* 1001b inactive, 1011b busy */
     80 	uint8_t  s                : 1; /* zero */
     81 	uint8_t  privilege_level  : 2;
     82 	uint8_t  segment_present  : 1;
     83 	uint8_t  limit_hi         : 4;
     84 	uint8_t  available        : 1;
     85 	uint8_t  l                : 1; /* zero */
     86 	uint8_t  db               : 1; /* zero */
     87 	uint8_t  granularity      : 1; /* must be zero */
     88 	uint8_t  base_hi          : 8;
     89 } __attribute__ ((packed));
     90 
     91 struct mmap_region {
     92 	uint32_t base_addr;
     93 	uint32_t size;
     94 	struct list_head l_region;
     95 };
     96 
     97 struct task_t {
     98 	uint32_t esp, old_esp;
     99 	enum task_state_t state, old_state;
    100 	struct page_directory_t *page_dir;
    101 	uint32_t *stack;
    102 	char *name;
    103 	enum task_fl flags;
    104 	struct list_head q_task;
    105 	pid_t pid;
    106 	int status;
    107 	struct task_t *parent;
    108 	struct cswitch_frame_t *cf;
    109 	struct ext2_inode_t *cdir;
    110 	struct file_t *fdtable[NR_MAX_OPEN_FILES];
    111 	char *pipebufs[NR_MAX_OPEN_FILES];
    112 	uid_t uid;
    113 	gid_t gid;
    114 	uid_t fuid;
    115 	gid_t fgid;
    116 	struct list_head l_regions;
    117 };
    118 
    119 extern void ps(void);
    120 extern void kick_tss(void);
    121 extern void remove_task(struct task_t *task);
    122 extern void add_task(struct task_t *task);
    123 extern struct task_t *create_kthread(const char *name, void *routine);
    124 extern struct task_t *current;
    125 extern int init_tss(void);
    126 extern void schedule(void);
    127 extern int fork(void);
    128 extern pid_t waitpid(pid_t pid, int *status, int options);
    129 extern void suspend_task(void *channel);
    130 extern int resume_task(void *channel);
    131 extern void freeze_tasks(void);
    132 extern void unfreeze_tasks(void);
    133 extern uid_t getuid(void);
    134 extern int setuid(uid_t uid);
    135 extern gid_t getgid(void);
    136 extern int setgid(gid_t gid);
    137 
    138 extern struct task_t *curr_proc;
    139 
    140 #endif
    141