Пример #1
0
static void print_trap_information(const trapframe *tf)
{
	const char *previous_mode;
	bool mprv = !!(tf->status & MSTATUS_MPRV);

	/* Leave some space around the trap message */
	printk(BIOS_DEBUG, "\n");

	if (tf->cause < ARRAY_SIZE(exception_names))
		printk(BIOS_DEBUG, "Exception:          %s\n",
				exception_names[tf->cause]);
	else
		printk(BIOS_DEBUG, "Trap:               Unknown cause %p\n",
				(void *)tf->cause);

	previous_mode = mstatus_to_previous_mode(read_csr(mstatus));
	printk(BIOS_DEBUG, "Previous mode:      %s%s\n",
			previous_mode, mprv? " (MPRV)":"");
	printk(BIOS_DEBUG, "Bad instruction pc: %p\n", (void *)tf->epc);
	printk(BIOS_DEBUG, "Bad address:        %p\n", (void *)tf->badvaddr);
	printk(BIOS_DEBUG, "Stored ra:          %p\n", (void*) tf->gpr[1]);
	printk(BIOS_DEBUG, "Stored sp:          %p\n", (void*) tf->gpr[2]);
}
Пример #2
0
static void mstatus_init()
{
  if (!supports_extension('S'))
    panic("supervisor support is required");

  uintptr_t ms = 0;
  ms = INSERT_FIELD(ms, MSTATUS_PRV, PRV_M);
  ms = INSERT_FIELD(ms, MSTATUS_PRV1, PRV_S);
  ms = INSERT_FIELD(ms, MSTATUS_PRV2, PRV_U);
  ms = INSERT_FIELD(ms, MSTATUS_IE2, 1);
  ms = INSERT_FIELD(ms, MSTATUS_VM, VM_CHOICE);
  ms = INSERT_FIELD(ms, MSTATUS_FS, 3);
  ms = INSERT_FIELD(ms, MSTATUS_XS, 3);
  write_csr(mstatus, ms);
  ms = read_csr(mstatus);

  if (EXTRACT_FIELD(ms, MSTATUS_VM) != VM_CHOICE)
    have_vm = 0;

  write_csr(mtimecmp, 0);
  clear_csr(mip, MIP_MSIP);
  set_csr(mie, MIP_MSIP);
}
Пример #3
0
static int simple_enroll_attempt (EST_CTX *ectx)
{
    int pkcs7_len = 0;
    int rv;
    char file_name[MAX_FILENAME_LEN];
    unsigned char *new_client_cert;
    X509_REQ *csr = NULL;

    if (force_pop) {
        rv =  est_client_force_pop(ectx);
        if (rv != EST_ERR_NONE) {
            printf("\nFailed to enable force PoP");
        }
    }

    if (csr_file[0]) {
        csr = read_csr(csr_file);
        if (csr == NULL) {
            rv = EST_ERR_PEM_READ;
        }else  {
            rv = est_client_enroll_csr(ectx, csr, &pkcs7_len, NULL);
        }
    }else  {
        rv = est_client_enroll(ectx, subj_cn, &pkcs7_len, priv_key);
    }
    if (csr) {
        X509_REQ_free(csr);
    }
    if (verbose) {
        printf("\nenrollment rv = %d (%s) with pkcs7 length = %d\n",
               rv, EST_ERR_NUM_TO_STR(rv), pkcs7_len);
    }
    if (rv == EST_ERR_NONE) {
        /*
         * client library has obtained the new client certificate.
         * now retrieve it from the library
         */
        new_client_cert = malloc(pkcs7_len);
        if (new_client_cert == NULL) {
            if (verbose) {
                printf("\nmalloc of destination buffer for enrollment cert failed\n");
            }
            return (EST_ERR_MALLOC);
        }

        rv = est_client_copy_enrolled_cert(ectx, new_client_cert);
        if (verbose) {
            printf("\nenrollment copy rv = %d\n", rv);
        }
        if (rv == EST_ERR_NONE) {
            /*
             * Enrollment copy worked, dump the pkcs7 cert to stdout
             */
            if (verbose) {
                dumpbin(new_client_cert, pkcs7_len);
            }
        }

        snprintf(file_name, MAX_FILENAME_LEN, "%s/newcert", out_dir);
        save_cert(file_name, new_client_cert, pkcs7_len);
        free(new_client_cert);
    }

    return (rv);
}
Пример #4
0
void parse_config_string()
{
  const char* s = (const char*)read_csr(mcfgaddr);
  query_mem(s);
  query_harts(s);
}
Пример #5
0
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;
}
Пример #6
0
void handle_fault_store(trapframe_t* tf)
{
  tf->badvaddr = read_csr(sbadaddr);
  if (handle_page_fault(tf->badvaddr, PROT_WRITE) != 0)
    segfault(tf, tf->badvaddr, "store");
}
Пример #7
0
void handle_fault_load(trapframe_t* tf)
{
  tf->badvaddr = read_csr(sbadaddr);
  if (handle_page_fault(tf->badvaddr, PROT_READ) != 0)
    segfault(tf, tf->badvaddr, "load");
}