Chinaunix首页 | 论坛 | 博客
  • 博客访问: 378047
  • 博文数量: 56
  • 博客积分: 1449
  • 博客等级: 中尉
  • 技术积分: 822
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-08 10:24
文章分类

全部博文(56)

文章存档

2014年(7)

2012年(13)

2011年(10)

2010年(26)

分类:

2010-10-24 21:28:25

/* sched.c
 *I don't mean to write the whole OS kernel.I just want to put what I have
 *already learned into practice.But what will it be end up looking like.
 *I don't know.ALA I have some free time,I will write something.Just like
 *linus once said,"Just for fun".I don't care what this small ugly codes  
 *will be capable of,or does it worth something.I just write it for fun,  
 *and for practice.
 
 *         10 / 13 / 2010        liangtao
 *            E-mail:liangtao90s@gmail.com
 */
#include
#include
#include
#include
 
#define count_8253 (1843200/100)
 
unsigned int jiffies;
 
union    init_task_union{
    struct    task_struct    init_task;
    unsigned long pad[__KERNEL_STACK_SIZE / sizeof(void *)];
};
 
unsigned long init_stack[__KERNEL_STACK_SIZE / sizeof(void *)] __attribute__((aligned(4096)));
 
union init_task_union init_task __attribute__((aligned (4096))) = INIT_TASK();
 
/* need this for mutil process test, cause we don't have a dynamical memory allocator.so...*/
union init_task_union fake_task __attribute__((aligned(4096))) = __INIT_TASK(1);
unsigned long fake_stack[__KERNEL_STACK_SIZE /sizeof(void *)] __attribute__((aligned(4096)));
struct tss_struct init_tss = INIT_TSS();
/* don't need this now */
#if 0
struct task_struct *task[NR_TASK] = {(struct task_struct *)&init_task,(struct task_struct *)&fake_task, };
#endif
/* useless. it's just a test, no need to make it too complex */
#if 1
void schedule(void)
{
    struct task_struct *prev, *next;
    if((unsigned long)CURRENT == (unsigned long)&init_task) {
        prev = (struct task_struct *)&init_task;
        next = (struct task_struct *)&fake_task;
    }
    else {
        prev = (struct task_struct *)&fake_task;
        next = (struct task_struct *)&init_task;
    }
    if(CAN_TASK_RUNNING(next))
        switch_to(prev, next);
}
#else
void schedule(void)  
{
 
}
#endif        
 
static inline void kernel_tss_setup(void)
{
    set_tss_desc(GDT_TSS_ENTRY, (unsigned long)&init_tss, sizeof(init_tss));
}
 
extern int timer_interrupt(void);   /* in asm/interrupt.c */
void sched_init(void)
{
    kernel_tss_setup();
/* clear NT. make sure no surprises when iret */
    __asm__("pushf; andl $0xffffbfff,(%esp); popf");
    ltr();    /* load the default tss base */
    outb_p(0x36, 0x43);
    outb_p((unsigned char)count_8253, 0x40);
    outb_p((unsigned char)(count_8253>>8), 0x40);
    set_intr_gate(0x20,  ((unsigned long)&timer_interrupt));  /* setup timer intr */
    outb_p((inb_p(0x21)&~0x01), 0x21);   /* enable intr 0 */
}

阅读(1746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~