Beispiel #1
0
void process_main(void) {
    // Fork a total of three new copies.
    pid_t p = sys_fork();
    assert(p >= 0);
    p = sys_fork();
    assert(p >= 0);

    // The rest of this code is like p-allocator.c.

    p = sys_getpid();
    srand(p);

    heap_top = ROUNDUP((uint8_t *) end, PAGESIZE);
    stack_bottom = ROUNDDOWN((uint8_t *) read_esp() - 1, PAGESIZE);

    while (1) {
	if ((rand() % ALLOC_SLOWDOWN) < p) {
	    if (heap_top == stack_bottom || sys_page_alloc(heap_top) < 0)
		break;
	    *heap_top = p;	/* check we have write access to new page */
	    heap_top += PAGESIZE;
	}
	sys_yield();
    }

    // After running out of memory, do nothing forever
    while (1)
	sys_yield();
}
Beispiel #2
0
int
mon_backtrace(int argc, char **argv, struct Trapframe *tf)
{	struct Eipdebuginfo info;
	unsigned int *ebp=(unsigned int *)read_ebp();
	unsigned int *esp=(unsigned int *)read_esp();
	unsigned int *eip=0;
	unsigned int arg[5];
	int i=0;
	while(ebp)
	{		
			for(i=0;i<5;i++)
				arg[i]=*(ebp+i+2);
			eip=ebp+1;
			debuginfo_eip(*eip,&info);
			cprintf("  ebp %08x eip %08x args  ",(unsigned int)ebp,*eip );
			for(i=0;i<5;++i)
			cprintf("%08x  ", arg[i]);
			cprintf("\n");
			
			cprintf("\t\t%s:%u:%.*s+%u\n",
				info.eip_file,
				info.eip_line,
				info.eip_fn_namelen,
				info.eip_fn_name,
				*eip-info.eip_fn_addr);
			esp=ebp+2;
			ebp=(unsigned int *)*ebp;
	}
	return 0;
}
Beispiel #3
0
// This is the first function that gets run in user mode (ring 3).
// It acts as PIOS's "root process",
// of which all other processes are descendants.
void
user()
{
	cprintf("in user()\n");
	assert(read_esp() > (uint32_t) &user_stack[0]);
	assert(read_esp() < (uint32_t) &user_stack[sizeof(user_stack)]);

	// Check the system call and process scheduling code.
  	cprintf("proc_check");
	proc_check();

	// Check that we're in user mode and can handle traps from there.
	trap_check_user();

	done();
}
Beispiel #4
0
void x86_kernel_main(struct multiboot *multiboot)
{
	init_output();
	init_paging(multiboot);
	init_acpi();
	init_descriptor_tables();

	kprint("Stack pointer: ");
	kprint_hexnl(read_esp());
	kprint("Mod count: ");
	kprint_hexnl(multiboot->mods_count);
	kprint("Kernel phys end : ");
	kprint_hexnl((u32)&__phys_end);
	kprint("Mod addr start : ");
	kprint_hexnl(*(u32*)(phys_to_virt(multiboot->mods_addr)));
	kprint("Mod addr end : ");
	kprint_hexnl(*(u32*)(phys_to_virt(multiboot->mods_addr) + 4));

	//init_tasking();

	kernel_main();

	if (multiboot->mods_count == 13) {
		kprint("Executing module..\n");

		typedef void (*module_fun)(void);

		u32 modaddr = phys_to_virt(multiboot->mods_addr);
		modaddr = phys_to_virt(*(u32*)modaddr);

		//kprint_hexnl(modaddr);
		//kprint_hexnl(*(u32*)modaddr);

		module_fun module = (module_fun)modaddr;

		module();
		kprint("Modadr is ");

	}
}
Beispiel #5
0
void init_tasking()
{
	u8 *sp;

	tsk1 = (task_t*)kmalloc(sizeof *tsk1);
	tsk2 = (task_t*)kmalloc(sizeof *tsk2);

	kprint("ESP: ");
	kprint_hexnl(read_esp());

	sp = (u8*)(kmalloc_a(STACK_SIZE) + STACK_SIZE);
	sp -= sizeof *tsk2->context;
	tsk2->context = (context_t *)sp;
	memset(tsk2->context, 0, sizeof *tsk2->context);
	tsk2->context->eip = (u32)task2;

	tsk1->context = 0;
	while (1) {
		kprint("I AM TASK 1\r");
		swtch(&tsk1->context, tsk2->context);
	}
}
Beispiel #6
0
//exception dispatcher
void _on_exception(int code, int codedata, CPUState *cpudata) {
  e9printf("_on_exception called.  code: %d, codedata: %d, cpudata: %p\n", code, codedata, cpudata);
  e9printf("  eax: %x, ebx: %x, edx: %x\n", read_eax(), read_ebx(), read_edx());
  e9printf("  ebp: %x, esp: %x, eip: %x\n\n", read_ebp(), read_esp(), get_eip());

  //sanitize code, just to be safe
  code = code & 31;
  
  int handled = 0;
  for (LinkNode *node=exception_stacks[code].first; node; node=node->next) {
    ExceptionHandler handler = node->data;
    
    if (handler(code, codedata, cpudata)) {
      handled = 1;
      break;
    }
  }
  
  if (!handled) {
    e9printf("Unhandled exception %d\n", code);
    kerror(-1, "Unhandled exception");
  }
}