linux c 实践,linux操作系统学习实践 ---sched.c

#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 */

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值