#include #include "mypcb.h"
extern tPCB task[MAX_TASK_NUM];
extern tPCB * my_current_task;
extern volatile int my_need_sched;
volatile int time_count = 0; //时钟计数
/*
* Called by timer interrupt.
* it runs in the name of current running process,
* so it use kernel stack of current running process
*/
void my_timer_handler(void)
{
#if 1
if(time_count%1000 == 0 && my_need_sched != 1)//时钟终端1000次,且调度标识符不为1时输出提示,且将调度标识符变为1。
{
printk(KERN_NOTICE ">>>my_timer_handler here<
{
return;
}
printk(KERN_NOTICE ">>>my_schedule<
prev = my_current_task;
if(next->state == 0)//判断下一个进程是否为正在执行状态
{
/* switch to next process */
asm volatile(
"pushl %%ebp\n\t" //保存当前进程的ebp
"movl %%esp,%0\n\t" //将当前进程的esp保存在prev->thread.sp中
"movl %2,%%esp\n\t" //将下一个进程的esp(next->thread.sp)放在esp中
"movl $1f,%1\n\t" //将1:标志处的内存地址保存在prev->thread.ip中
"pushl %3\n\t" //将下一个进程的eip放入栈中
"ret\n\t" //释放下一个进程的eip,下一个进程开始执行
"1:\t" /* next process start here */
"popl %%ebp\n\t"
: "=m" (prev->thread.sp),"=m" (prev->thread.ip)
: "m" (next->thread.sp),"m" (next->thread.ip)
);
my_current_task = next;
printk(KERN_NOTICE ">>>switch %d to %d<pid);
}
else //对于还没有执行过的进程的处理
{
next->state = 0; //将进程状态转为执行状态
my_current_task = next;
printk(KERN_NOTICE ">>>switch %d to %d<pid);
/* switch to new process */
asm volatile(
"pushl %%ebp\n\t" /* save ebp */
"movl %%esp,%0\n\t" /* save esp */
"movl %2,%%esp\n\t" /* restore esp */
"movl %2,%%ebp\n\t" /* restore ebp */
"movl $1f,%1\n\t" /* save eip */
"pushl %3\n\t" //保存将当前进程的入口
"ret\n\t" /* restore eip */
: "=m" (prev->thread.sp),"=m" (prev->thread.ip)
: "m" (next->thread.sp),"m" (next->thread.ip)
);
}
return;
}