コード例 #1
0
ファイル: gdt.c プロジェクト: semahawk/kernel
void gdt_init(void)
{
  /* that's kind of ugly (setting the null segment) */
  memset(&gdt[SEG_NULL_IDX], 0x0, sizeof(struct gdt_entry));

  /* 0x08 */
  gdt_set_segment(SEG_KCODE_IDX, 0x0, 0xffffffff,
      GDTE_DPL_KERNEL | GDTE_X | GDTE_W | GDTE_NOT_TSS,
      GDTE_PAGE_GRAN | GDTE_32_BIT);

  /* 0x10 */
  gdt_set_segment(SEG_KDATA_IDX, 0x0, 0xffffffff,
      GDTE_DPL_KERNEL | GDTE_R | GDTE_NOT_TSS,
      GDTE_PAGE_GRAN | GDTE_32_BIT);

  /* 0x18 */
  gdt_set_segment(SEG_UCODE_IDX, 0x0, 0xffffffff,
      GDTE_DPL_USER | GDTE_X | GDTE_W | GDTE_NOT_TSS,
      GDTE_PAGE_GRAN | GDTE_32_BIT);

  /* 0x20 */
  gdt_set_segment(SEG_UDATA_IDX, 0x0, 0xffffffff,
      GDTE_DPL_USER | GDTE_R | GDTE_NOT_TSS,
      GDTE_PAGE_GRAN | GDTE_32_BIT);

  /* task switching structure */
  tss_init(SEG_KDATA, (uint32_t)&kernel_stack_top);

  gdt_install();

  kprintf("[gdt] global descriptors were set up\n");

  tss_flush(SEG_TSS);
}
コード例 #2
0
ファイル: arch_system.c プロジェクト: bdunlay/os-projects
PUBLIC void arch_init(void)
{
#ifdef CONFIG_APIC
    /*
     * this is setting kernel segments to cover most of the phys memory. The
     * value is high enough to reach local APIC nad IOAPICs before paging is
     * turned on.
     */
    prot_set_kern_seg_limit(0xfff00000);
    reload_ds();
#endif

    idt_init();

    tss_init(&tss, &k_boot_stktop, 0);

    acpi_init();

#if defined(CONFIG_APIC) && !defined(CONFIG_SMP)
    if (config_no_apic) {
        BOOT_VERBOSE(printf("APIC disabled, using legacy PIC\n"));
    }
    else if (!apic_single_cpu_init()) {
        BOOT_VERBOSE(printf("APIC not present, using legacy PIC\n"));
    }
#endif

    fpu_init();
}
コード例 #3
0
ファイル: arch_system.c プロジェクト: bdeepak77/minix3
void arch_init(void)
{
	k_stacks = (void*) &k_stacks_start;
	assert(!((vir_bytes) k_stacks % K_STACK_SIZE));

#ifndef CONFIG_SMP
	/*
	 * use stack 0 and cpu id 0 on a single processor machine, SMP
	 * configuration does this in smp_init() for all cpus at once
	 */
	tss_init(0, get_k_stack_top(0));
#endif

#if !CONFIG_OXPCIE
	ser_init();
#endif

#ifdef USE_ACPI
	acpi_init();
#endif

#if defined(USE_APIC) && !defined(CONFIG_SMP)
	if (config_no_apic) {
		BOOT_VERBOSE(printf("APIC disabled, using legacy PIC\n"));
	}
	else if (!apic_single_cpu_init()) {
		BOOT_VERBOSE(printf("APIC not present, using legacy PIC\n"));
	}
#endif

	/* Reserve some BIOS ranges */
	cut_memmap(&kinfo, BIOS_MEM_BEGIN, BIOS_MEM_END);
	cut_memmap(&kinfo, BASE_MEM_TOP, UPPER_MEM_END);
}
コード例 #4
0
ファイル: main.c プロジェクト: Imajie/ARM
int main( void )
{
	int i;

	uart_init(9600);

	init_gpio();
	init_PWM();
	tss_init();

	__enable_interrupts();
	for( i=0; i<DELAY; i++) ;

	uart_putstr( "Initialization Complete\r\n" );

	// wait for user to press a key
	uart_putstr( "Press any key:" );
	uart_getchar();

	TSI0_DATA |= TSI_DATA_SWTS_MASK;

	while( 1 )
	{	
		uart_putnum( tss_pin9, 5 );		// 2^16 = 65536 = 5 digits
		uart_putstr( "\t" );
		uart_putnum( tss_pin10, 5 );	// 2^16 = 65536 = 5 digits
		uart_putstr( "\r\n" );

		for( i=0; i<DELAY; i++);
	}
	

	return 0;
}
コード例 #5
0
t_error			ia32_thread_init(void)
{
  THREAD_ENTER(thread);

  o_as*			as;
  t_vaddr		int_stack;

  /*
   * 1)
   */

  if (as_get(kasid, &as) != ERROR_NONE)
    THREAD_LEAVE(thread, ERROR_UNKNOWN);

  /*
   * 2)
   */

  if (map_reserve(kasid,
		  MAP_OPT_PRIVILEGED,
		  3 * PAGESZ,
		  PERM_READ | PERM_WRITE,
		  (t_vaddr*)&thread->machdep.tss) != ERROR_NONE)
    THREAD_LEAVE(thread, ERROR_UNKNOWN);

      memset(thread->machdep.tss, 0x0, sizeof(t_ia32_tss));

  /*
   * 3)
   */

  if (map_reserve(kasid,
		  MAP_OPT_PRIVILEGED,
		  2 * PAGESZ,
		  PERM_READ | PERM_WRITE,
		  &int_stack) != ERROR_NONE)
    THREAD_LEAVE(thread, ERROR_UNKNOWN);

  /*
   * 4)
   */

  if (tss_load(thread->machdep.tss,
	       SEGSEL(PMODE_GDT_CORE_DS, PRIV_RING0),
	       int_stack + 2 * PAGESZ - 16,
	       0x68) != ERROR_NONE)
    THREAD_LEAVE(thread, ERROR_UNKNOWN);

  gl_stack_int = int_stack + 2 * PAGESZ - 16;

  /*
   * 5)
   */

  if (tss_init(thread->machdep.tss) != ERROR_NONE)
    THREAD_LEAVE(thread, ERROR_UNKNOWN);

  THREAD_LEAVE(thread, ERROR_NONE);
}
コード例 #6
0
ファイル: descriptor.c プロジェクト: jiangxilong/kiwi
/** Initialize descriptor tables for the current CPU.
 * @param cpu		CPU to initialize for. */
__init_text void descriptor_init(cpu_t *cpu) {
	/* Initialize and load the GDT/TSS. */
	gdt_init(cpu);
	tss_init(cpu);

	/* Point the CPU to the global IDT. */
	x86_lidt(kernel_idt, (sizeof(kernel_idt) - 1));
}
コード例 #7
0
ファイル: init.c プロジェクト: descent/elephant
/*负责初始化所有模块 */
void init_all() {
   put_str("init_all\n");
   idt_init();	     // 初始化中断
   mem_init();	     // 初始化内存管理系统
   thread_init();    // 初始化线程相关结构
   timer_init();     // 初始化PIT
   console_init();   // 控制台初始化最好放在开中断之前
   keyboard_init();  // 键盘初始化
   tss_init();       // tss初始化
}
コード例 #8
0
ファイル: arch_system.c プロジェクト: chanddu/MINIX
PUBLIC void arch_init(void)
{
#ifdef USE_APIC
	/*
	 * this is setting kernel segments to cover most of the phys memory. The
	 * value is high enough to reach local APIC nad IOAPICs before paging is
	 * turned on.
	 */
	prot_set_kern_seg_limit(0xfff00000);
	reload_ds();
#endif

	idt_init();

	/* FIXME stupid a.out
	 * align the stacks in the stack are to the K_STACK_SIZE which is a
	 * power of 2
	 */
	k_stacks = (void*) (((vir_bytes)&k_stacks_start + K_STACK_SIZE - 1) &
							~(K_STACK_SIZE - 1));

#ifndef CONFIG_SMP
	/*
	 * use stack 0 and cpu id 0 on a single processor machine, SMP
	 * configuration does this in smp_init() for all cpus at once
	 */
	tss_init(0, get_k_stack_top(0));
#endif

#if !CONFIG_OXPCIE
	ser_init();
#endif

#ifdef USE_ACPI
	acpi_init();
#endif

#if defined(USE_APIC) && !defined(CONFIG_SMP)
	if (config_no_apic) {
		BOOT_VERBOSE(printf("APIC disabled, using legacy PIC\n"));
	}
	else if (!apic_single_cpu_init()) {
		BOOT_VERBOSE(printf("APIC not present, using legacy PIC\n"));
	}
#endif
}
コード例 #9
0
ファイル: kinit.c プロジェクト: thomasloven/os5
registers_t *kinit(mboot_info_t *mboot, uint32_t mboot_magic)
{

  kdbg_init();
  assert(mboot_magic == MBOOT_MAGIC2);

  mboot_mod_t *mods = (mboot_mod_t *)(assert_higher(mboot->mods_addr));

  kernel_elf_init(mboot);
  pmm_init(mboot);
  vmm_init(mods[0].mod_end);
  idt_init();
  tss_init();

  register_int_handler(INT_PF, page_fault_handler);
  register_int_handler(INT_SCHEDULE, switch_kernel_thread);

  scheduler_init();
  timer_init(500);
  /* vfs_init(); */
  syscall_init();
  process_init((void(*)(void))&_idle);

  tar_header_t *tarfs_location = assert_higher((tar_header_t *)mods[0].mod_start);
  debug_enabled = 1;

  debug("[info] Mboot flags %x\n", mboot->mods_addr);
  debug("[info] Mounting tarfs as root\n");
  vfs_init();
  vfs_mount("/", tarfs_init(tarfs_location));
  vfs_mount("/mnt/tarfs", tarfs_init(tarfs_location));
  vfs_mount("/dev/debug", debug_dev_init());
  keyboard_init();

  fopen("/dev/debug", "w");
  fopen("/dev/debug", "w");
  /* for(;;); */

  /* vfs_mount("/", tarfs_init(tarfs_location)); */
  /* keyboard_init(); */
  /* vfs_mount("/dev/debug", debug_dev_init()); */

  /* fopen("/dev/kbd", "r"); */
  /* fopen("/dev/debug", "w"); */
  /* fopen("/dev/debug", "w"); */

  execve("/bin/init",0,0);

  debug("[status]========================\n");
  debug("[status] Os5 by Thomas Lovén\n");
  debug("[status] Kernel git data: [%s (%s)] %s\n", __kernel_git_hash, (__kernel_git_dirty)?"dirty":"clean", __kernel_git_date);
  debug("[status] %s: %s\n", __kernel_git_branch, __kernel_git_message);
  debug("[status] Kernel compilation: %s %s\n", __kernel_build_date, __kernel_build_time);
  debug("[status]========================\n");

  thread_t *init = new_thread((void(*)(void))current->proc->mm.code_entry,1);
  init->proc = current->proc;

  debug("[status] Kernel booted\n");
  return switch_kernel_thread(0);
}
コード例 #10
0
ファイル: thread.c プロジェクト: teodor-pripoae/maxtable
void msg_process(char * (*handler_request)(char *req_buf, int fd))
{
	LOCALTSS(tss);
	int resp_size;
	RPCREQ* req;
	char* resp;

	int fd;
	MSG_DATA *req_msg;
	MSG_DATA *resp_msg;


	req_msg = NULL;
	resp_msg = NULL;
	
	while(TRUE)
	{
		
		pthread_mutex_lock(&mutex);

		while (msg_list_head == NULL)
			pthread_cond_wait(&cond, &mutex);

	
		req_msg = msg_list_head;
		msg_list_head = msg_list_head->next;
		msg_list_len--;
		pthread_mutex_unlock(&mutex);

		if(!strncasecmp(RPC_RBD_MAGIC, req_msg->data, STRLEN(RPC_RBD_MAGIC)))
		{
			req = conn_build_req(req_msg->block_buffer, req_msg->n_size);
		}
		else
		{
			req = conn_build_req(req_msg->data, req_msg->n_size);
		}
		
		fd = req_msg->fd;

		if(req_msg->n_size)
		{
			resp = handler_request(req->data, fd);

			if (resp == NULL)
			{
				if (tss->tstat & TSS_PARSER_ERR)
				{
					resp = conn_build_resp_byte(RPC_PARSER_ERR, 0, NULL);
				}
				else
				{
					resp = conn_build_resp_byte(RPC_FAIL, 0, NULL);					
				}
			}
		}
		else
		{	resp = conn_build_resp_byte(RPC_FAIL, 0, NULL);
		}

		/* If it's the select where/range session, skip the success operation. */
		if((fd < 0) || (((RPCRESP *)resp)->status_code & RPC_SKIP_SEND))
		{
			//local msg, such as recovery task msg, so no need to response
			goto finish;
		}

		resp_size = conn_get_resp_size((RPCRESP *)resp);

		resp_msg = NULL;
		resp_msg = (MSG_DATA *)msg_mem_alloc();
		resp_msg->n_size = resp_size;
		resp_msg->block_buffer = NULL;
		Assert(resp_size < MSG_SIZE);
		MEMCPY(resp_msg->data, resp, resp_size);
		resp_msg->fd = fd;	
		
		struct epoll_event ev;
		ev.data.ptr = resp_msg;
	
		ev.events = EPOLLOUT | EPOLLET;

		epoll_ctl(epfd, EPOLL_CTL_MOD, fd, &ev);

finish:

		if (req_msg->block_buffer != NULL)
		{
			free(req_msg->block_buffer);
		}
		
		msg_mem_free(req_msg);
  
		conn_destroy_req(req);
		conn_destroy_resp_byte(resp);		
		
		tss_init(tss);
	}
}