⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sched.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 C
字号:
#include "hos.h"struct task_struct * next_p(){	// select next processor	// skip pid=0 when there is other processes	if (current->next_run->pid==0)	   return (current->next_run->next_run);	return (current->next_run);}#define switch_to(prev, next, last) do { \	asm volatile("pushl %%esi\n\t"  \			"pushl %%edi\n\t"  \			"pushl %%ebp\n\t" \			"movl %%esp, %0\n\t" /*save esp*/ \			"movl %2, %%esp\n\t" /*restore esp*/ \			"movl $1f, %1\n\t" /*save eip*/ \			"pushl %3\n\t" /*restore eip*/ \			"ret\n\t" \			"1:\t" \			"popl %%ebp\n\t"  \			"popl %%edi\n\t"  \			"popl %%esi\n\t"  \			:"=m"(prev->esp), "=m"(prev->eip) \			:"m"(next->esp), "m"(next->eip) \			 ); \}while (0)void schedule(void){	struct task_struct *prev, *next;	unsigned long *pgdir_loc;/*    // for hacking exec. skip scheduling	if (current->pid==1) {		  return;    }*/	//unsigned long addr; //float x=0.0; int i;	if (!current->need_reschedule) return;	//get next process and start it	prev=current;	current->need_reschedule=0; // reset	next=next_p();	current=next;	pgdir_loc = current->mm.pgdir; // location of pgdir of current	// change page directory	__asm__ ("pushl %%eax\n\t"	         "movl %0, %%eax\n\t"			 "movl %%eax, %%cr3\n\t"			 "popl %%eax\n\t"			 ::"m"(pgdir_loc));	if (next!=prev){		//printk("about to switch. current is %x\n",current);		/*		for(i=0;i<100000000;i++)			x=x+1.0;			*/		// take care tss first		//init_tss.esp0 = next->esp0; we don't handel user mode process		//printk("bef switch. stack top of next is %x\n", next->esp);		//printk("and stack is "); 		//display_regs((struct pt_regs *)next->esp);		//printk("and ret address is %x\n", next->eip);		switch_to(prev,next,prev);		/*		asm("popl %%eax\n\t"		    "movl %%eax, %0\n\t"		    :"=m"(addr):);		printk("p1_body is %x, return addr: %x\n", p1_body, addr);		for(;;);		*/	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -