コード例 #1
0
ファイル: trap.c プロジェクト: XinYao1994/TinyComputer
static int pgfault_handler(struct trapframe *tf)
{
	extern struct mm_struct *check_mm_struct;
	struct mm_struct *mm;
	if (check_mm_struct != NULL) {
		//assert(current == idleproc);
		assert(pls_read(current) == pls_read(idleproc));
		mm = check_mm_struct;
	} else {
		if (pls_read(current) == NULL) {
			print_trapframe(tf);
			print_pgfault(tf);
			panic("unhandled page fault.\n");
		}
		mm = pls_read(current)->mm;
	}
	//print_pgfault(tf);
	/* convert ARM error code to kernel error code */
	machine_word_t error_code = 0;
	if (tf->tf_err & (1 << 11))
		error_code |= 0x02;	//write
	if ((tf->tf_err & 0xC) != 0x04)
		error_code |= 0x01;
	uint32_t badaddr = 0;
	if (tf->tf_trapno == T_PABT) {
		badaddr = tf->tf_epc;
	} else {
		badaddr = far();
	}
	//kprintf("rrr %08x   %08x\n", error_code, *(volatile uint32_t*)(VPT_BASE+4*0xe00));
	return do_pgfault(mm, error_code, badaddr);
}
コード例 #2
0
ファイル: trap.c プロジェクト: huhanGitHub/Ucore
static int
pgfault_handler(struct trapframe *tf) {
    extern struct mm_struct *check_mm_struct;
    print_pgfault(tf);
    if (check_mm_struct != NULL) {
        return do_pgfault(check_mm_struct, tf->tf_err, rcr2());
    }
    panic("unhandled page fault.\n");
}
コード例 #3
0
ファイル: trap.c プロジェクト: thuyangyu/ucore_lab
static int
pgfault_handler(struct trapframe *tf) {
    extern struct mm_struct *check_mm_struct;
    if(check_mm_struct !=NULL) { //used for test check_swap
            print_pgfault(tf);
        }
    struct mm_struct *mm;
    if (check_mm_struct != NULL) {
        assert(current == idleproc);
        mm = check_mm_struct;
    }
    else {
        if (current == NULL) {
            print_trapframe(tf);
            print_pgfault(tf);
            panic("unhandled page fault.\n");
        }
        mm = current->mm;
    }
    return do_pgfault(mm, tf->tf_err, rcr2());
}
コード例 #4
0
ファイル: trap.c プロジェクト: TySag/project
static int pgfault_handler(struct trapframe *tf)
{
	extern struct mm_struct *check_mm_struct;
	struct mm_struct *mm;
	if (check_mm_struct != NULL) {
		assert(pls_read(current) == pls_read(idleproc));
		mm = check_mm_struct;
	} else {
		if (pls_read(current) == NULL) {
			print_trapframe(tf);
			print_pgfault(tf);
			panic("unhandled page fault.\n");
		}
		mm = pls_read(current)->mm;
	}
	return do_pgfault(mm, tf->tf_err, rcr2());
}
コード例 #5
0
ファイル: trap.c プロジェクト: XinYao1994/TinyComputer
/* trap_dispatch - dispatch based on what type of trap occurred */
static void trap_dispatch(struct trapframe *tf)
{
	char c;

	int ret;

	//kprintf("Trap [%03d %03d]\n", tf->tf_trapno, tf->tf_trapsubno);

	switch (tf->tf_trapno) {
		// Prefetch Abort service routine
		// Data Abort service routine
	case T_PABT:
	case T_DABT:
		if ((ret = pgfault_handler(tf)) != 0) {
			print_pgfault(tf);
			print_trapframe(tf);
			if (pls_read(current) == NULL) {
				panic("handle pgfault failed. %e\n", ret);
			} else {
				if (trap_in_kernel(tf)) {
					panic
					    ("handle pgfault failed in kernel mode. %e\n",
					     ret);
				}
				killed_by_kernel();
			}
		}
		break;
	case T_SWI:
		syscall();
		break;
		// IRQ Service Routine
		/*        case IRQ_OFFSET + INT_TIMER4:
		   ticks ++;
		   if (ticks % TICK_NUM == 0) {
		   print_ticks();
		   //print_trapframe(tf);
		   }
		   break;
		   case IRQ_OFFSET + INT_UART0:
		   c = cons_getc();
		   kprintf("serial [%03d] %c\n", c, c);
		   break;
		 */
		// SWI Service Routine
#if 0
	case T_SWITCH_TOK:	// a random System call
		kprintf("Random system call\n");
		print_cur_status();
		//print_stackframe();
		break;
#endif
	case T_IRQ:
		__irq_level++;
#if 0
		if (!trap_in_kernel(tf)) {
			uint32_t sp;
			asm volatile ("mov %0, sp":"=r" (sp));
			kprintf("### iRQnotK %08x\n", sp);
		}
#endif
		irq_handler();
		__irq_level--;
		break;
#if 0
	case T_PANIC:
		print_cur_status();
		//print_stackframe();
		break;
#endif
		/* for debugging */
	case T_UNDEF:
		udef_handler(tf);
		break;
	default:
		print_trapframe(tf);
		if (pls_read(current) != NULL) {
			kprintf("unhandled trap.\n");
			do_exit(-E_KILLED);
		}
		panic("unexpected trap in kernel.\n");
	}
コード例 #6
0
ファイル: trap.c プロジェクト: lhh520/os-4-risc-v
unsigned long trapHandler(struct rtrapframe* tf, long cause, long epc, long badaddr)//long* tf
{
	uint32_t sp1=read_sp();
	uint32_t saved=tf;
	long funRe=0;
	long returnValue = 0;
	long sysNum=(long)(tf->a7);

	long args[5];
	args[0]=(long)(tf->a0);
	args[1]=(long)(tf->a1);
	args[2]=(long)(tf->a2);
	args[3]=(long)(tf->a3);
	args[4]=(long)(tf->a4);
	struct rtrapframe *otf = current->tf;
	current->tf = tf;
	bool ifuser=tf->t0;
	funRe=((ifuser==1)?-1:0);
	switch(cause)
	{
		case CAUSE_MACHINE_ECALL:
		case CAUSE_SUPERVISOR_ECALL:
		{


			switch(sysNum)
			{
				case SYS_exit:
				{
					cprintf("exit\n");
					sys_exit(args[0]);
					break;
				}

				case SYS_write:
				{
					returnValue=sys_write(sysNum,args[0],args[1],args[2]);
					current->tf=otf;
						tf->a0 = (uint32_t)returnValue;
						//asm volatile("csrw mepc, %0"::"r"(epc+4));
						return funRe;
					break;
				}

				case SYS_exec:
				{
					const char *name = (const char *)args[0];
					size_t len = (size_t)args[1];
					returnValue = sys_execve(name, len);
					funRe=-1;
					break;
				}

				case SYS_S2M:
				{
					set_mstatus_field(MSTATUS_PRV1,3);
					break;
				}

				case SYS_S2U:
				{
					set_mstatus_field(MSTATUS_PRV1,0);
					break;
				}

				case SYS_getpid:
				{
					returnValue = sys_getpid();
					break;
				}

				case SYS_fork:
				{
					returnValue=sys_fork();
					//funRe=-1;
//					cprintf("hello\n");
					break;
				}

				case SYS_yield:
				{
					//cprintf("yield\n");
					returnValue=sys_yield();
					break;
				}

				case SYS_wait:
				{
					returnValue=sys_wait(args[0],args[1]);
					break;
				}
			}
			break;
		}
		case CAUSE_USER_ECALL:
		{

			switch(sysNum)
			{

				case SYS_write:
				{
					returnValue = sys_write(sysNum, args[0], args[1], args[2]);
					current->tf=otf;
						tf->a0 = (uint32_t)returnValue;
						return funRe;
					break;
				}

				case SYS_getpid:
				{
					returnValue = sys_getpid();
					break;
				}
				case SYS_exit:
				{
					returnValue = sys_exit(args[0]);
					break;
				}
			}
			break;
		}
		case CAUSE_FAULT_LOAD:
		case CAUSE_FAULT_STORE:
		case CAUSE_ILLEGAL_INSTRUCTION:
		{
			extern struct mm_struct *check_mm_struct;
			uint32_t mstatus=read_csr(mstatus);
			print_pgfault(mstatus,cause,badaddr);
			if (check_mm_struct != NULL) {
			        if(do_pgfault(check_mm_struct, cause, badaddr, mstatus)!=0)
			        	panic("unhandled page fault in function.\n");
			    }
			else
			{
				if(current==NULL)
					panic("unhandled page fault.\n");
				do_pgfault(current->mm, cause, badaddr, mstatus);
			}
			break;
		}
		default:
		{
			prvSyscallExit(cause);
		}
	}
	//uint32_t sp3=read_sp();
	//cprintf("sysNum=%d\n",sysNum);
							//cprintf("sp3=%08x\n",sp3);
	current->tf=otf;
	tf->a0 = (uint32_t)returnValue;
	//asm volatile("csrw mepc, %0"::"r"(epc+4));
	return funRe;
}