Esempio n. 1
0
void kloader_cmain(struct mem_map_entry mem_map[], uint32_t mem_entry_count)
{
    screen_init();
    screen_cursor_hide();
    terminal_init();

    KINFO("Welcome to Nox (Bootloader mode)");

    mem_mgr_init(mem_map, mem_entry_count);

    ata_init();
    fs_init();

    struct fat_part_info* part_info = fs_get_system_part();
    struct fat_dir_entry kernel;
    if(!fat_get_dir_entry(part_info, "KERNEL  ELF", &kernel)) {
        KPANIC("Failed to locate KERNEL.ELF");
        while(1);
    }

    intptr_t kernel_entry_point;

    if(!elf_load_trusted("KERNEL  ELF", &kernel_entry_point)) {
        KWARN("Failed to load elf!");
    } 

    kernel_entry cmain = (kernel_entry)(kernel_entry_point);

    cmain(mem_map, mem_entry_count);


    KINFO("Bootloader done");

    while(1);
}
Esempio n. 2
0
kmain() {
	terminal_init();

	setup_IDT_entry (&idt[0x08], 0x08, (dword)&_int_08_hand, ACS_INT, 0);
	setup_IDT_entry (&idt[0x09], 0x08, (dword)&_int_09_hand, ACS_INT, 0);
	setup_IDT_entry (&idt[0x74], 0x08, (dword)&_int_74_hand, ACS_INT, 0);
	setup_IDT_entry (&idt[0x80], 0x08, (dword)&_int_80_hand, ACS_INT, 0);
	

	/* IDTR Setting */ 

	idtr.base = 0;  
	idtr.base +=(dword) &idt;
	idtr.limit = sizeof(idt)-1;
	
	_lidt(&idtr);

	/* Interrupt unmasking */
	
	_cli();

	_maskPIC1(0xF8);           /*0XF8*/
	_maskPIC2(0xEF);		/*0XEF*/
	
	_sti();

	video_init();
	timertick_init();
	rtc_init();
	mouse_init();
	shell_run();
}
Esempio n. 3
0
void kmain( void* mbd, unsigned int magic )
{
   if ( magic != 0x2BADB002 )
   {
      /* Something went not according to specs. Print an error */
      /* message and halt, but do *not* rely on the multiboot */
      /* data structure. */
   }

   /* You could either use multiboot.h */
   /* (http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#multiboot_002eh) */
   /* or do your offsets yourself. The following is merely an example. */
   char * boot_loader_name =(char*) ((long*)mbd)[16];


   /* Write your kernel here. */
   terminal_init();

   int i;

   for(i = 0; i < 10000000; i++);

   char str[] = "Welcome to Mark Kernel\n";
   k_printf(str);

   for(i = 0; i < 10000000; i++);

   char str2[] = "This is a \n";
   k_printf(str2);
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    /*  Initialize terminal and start virtual machine  */
    terminal_init();
    machine_start();

    return (EXIT_SUCCESS);
}
Esempio n. 5
0
void text_init (struct term *tty)  {
  terminal_init (tty);
  memset_words(tty->backup,0x0720,SCREEN_BUFFER/2);
  tty->screen = SCREEN_VIDEO;
  tty->write = text_write;
  tty->clear = text_clrscr;
  tty->scroll = text_scroll;
  tty->tty_switch = text_switch;
  tty->attr   = 0xf;
  tty->has_shell = 0;
  tty->x = 0,tty->y = 0;
}
Esempio n. 6
0
void kernel_main(void* mem)
{
	init_serial();


	terminal_init();
	terminal_writeln("Kernel Startup.");

	pool = tlsf_create((void*)0x2000000, 32768);
  //terminal_writehexln(pool);
	lua_State* L = lua_newstate(l_alloc, pool);

  lua_pushcfunction(L, l_Print);
  lua_setglobal(L, "print");
  

#define BUFFER_SIZE 128
#if 0
	char test[BUFFER_SIZE]; test[BUFFER_SIZE-1] = 0;
  int i ;
	for(i = 0; i < BUFFER_SIZE-1; ++i) {
		test[i] = read_serial();
		if(test[i] == 0 || test[i] == '\r' || test[i] == '\n') {
			break;
		}
		if(!IsValid(test[i])) {
			i--;
			continue;
		}
 	}
  test[i] = 0;
terminal_write("Read ");
terminal_writehexln(i);
terminal_writeln(test);
#else
  char* test = "print(1 + 2)";
#endif
  size_t len = strlen(test);
  if(luaL_loadbufferx(L, test, len, "Sample", 0) != 0) {
    terminal_writeln(lua_tostring(L, -1));
  }
  if(lua_pcall(L, 0, LUA_MULTRET, 0) != 0) {
    terminal_writeln(lua_tostring(L, -1));
  }

  terminal_writeln("Finished");
}
Esempio n. 7
0
int main(void) {
    // LCD Screen
    lcd_init();
    terminal_init();

    // Input
    input_init();

    // Set power LED
    DDRB |= (1 << PINB6);
    clear_bit(PORTB, PINB6);

    // Radio
    uint8_t local_addr[] = { 0x1B, 0x1B, 0x1B, 0x1B, 0x1B };
    uint8_t robot_addr[] = { 0x0A, 0x0A, 0x0A, 0x0A, 0x0A };
    spi_init();
    nrf24_init();
    nrf24_config(47, sizeof(RemoteCommand)); // Channel 7
    nrf24_set_rx_addr(local_addr);
    nrf24_set_tx_addr(robot_addr);

    // Ready to go!
    sei();

    RemoteMode mode = MODE_MANUAL;

    while (1)
    {
        input_update(&input_state);

        switch (mode) {
        case MODE_MANUAL:
            UpdateManualMode(&input_state);
            break;
        case MODE_AUTO:
            asm("nop"::);
            break;
        case MODE_MENU:
            asm("nop"::);
            break;
        }
    }
}
Esempio n. 8
0
/**
 * Setting up the board
 */
static void internal_setup()
{
    // Intialise les servomoteurs
    servos_init();
    
    // Initialise le mode WiFly
    WiFly.begin(921600);
    terminal_init(&WiFly);
    
    // Définit l'interruption @50hz
    servos_attach_interrupt(setFlag);

    // Configure la led de la board
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN, LOW);

    // Lance la configuration de l'utilisateur
    setup();
}
Esempio n. 9
0
/**
 * 初始化窗口管理器
 * 就不写注释了 函数名写的已经很明白。。
 **/
si_t window_manager_init()
{
	if(0 != terminal_init())
	{
		EGUI_PRINT_ERROR("failed to init terminal");
		return -1;
	}

	if(0 != config_init())
	{
		EGUI_PRINT_ERROR("failed to init config");
		return -1;
	}

	if(0 != event_init("/dev/input/event9", "/dev/input/event10", 1000))
	{
		EGUI_PRINT_ERROR("failed to init event module");
		return -1;
	}

	if(0 != comm_init("/tmp/server"))
	{
		EGUI_PRINT_ERROR("failed to init comm module");
		return -1;
	}

	if(0 != graph_init("/dev/fb0", 0, 0, 0, 0))
	{
		EGUI_PRINT_ERROR("failed to init graph module");
		return -1;
	}

	if(0 != cursor_init("CURSOR_SHAPE_X"))
	{
		EGUI_PRINT_ERROR("failed to init cursor");
		return -1;
	}

	applications_init(3, 30);

	return 0;
}
Esempio n. 10
0
int main(void) {
    wdt_enable (WDTO_2S);

    lcd_backlight_service__init();
    terminal_init();
    keypad__init();

    led__init();
    alarm_state__init();
    state_change_pulse_transmitter__init();
    alarm_client__init();


    system_timer__init();
    system_timer__start();

    lcd_print_string_progmem (MSG_READY);
    sei();
    return 0;
}
Esempio n. 11
0
void event_init(void)
{
  // Initialize the event queues
  deferred_events = kl_init(Event);
  immediate_events = kl_init(Event);
  // early msgpack-rpc initialization
  msgpack_rpc_init_method_table();
  msgpack_rpc_helpers_init();
  // Initialize input events
  input_init();
  // Timer to wake the event loop if a timeout argument is passed to
  // `event_poll`
  // Signals
  signal_init();
  // Jobs
  job_init();
  // finish mspgack-rpc initialization
  channel_init();
  server_init();
  terminal_init();
}
Esempio n. 12
0
/**
 * Boucle principale
 */
static void internal_loop()
{
    // Gère la communication du terminal
    terminal_tick();

    // Si quelque chose est disponible au niveau de l'USB, switch
    // sur le port
    if (SerialUSB.available() && !isUSB) {
        isUSB = true;
        terminal_init(&SerialUSB);
    }

    // Exécute le code @50hz
    if (flag) {
        flag = false;
        tick();
    }

    // Appelle la fonction loop de l'utilisateur
    loop();
}
Esempio n. 13
0
/** @brief preStart() is the function for the startup thread, which is the
 * one spawned by main().
 *
 * It does all the initialization that needs to happen after the
 * kernel is up and running, and then it calls the application start function.
 */
void pre_start(void)
{
    //TODO: this should somehow be auto-generated
#ifdef PLATFORM_LINUX
    mos_node_id_init();	// must be called before gevent_init ()
    gevent_init();

    serial_init();
    terminal_init();
    //udp_init();
    xmos_radio_init();	// gevent_init() must be called first
    xmos_flash_init();	// gevent_init() must be called first
    mos_thread_suspend(); //fixes threading issue with freebsd

#elif defined(ARCH_MICRO)
    uart_init();
    printf_init();
    plat_init();
    clock_init();
#if defined(PLATFORM_TELOSB)
    // clock_init() clobbers TimerA
    // re-initialize TimerA here as a kludge.
    kernel_timer_init();
#endif
    mos_node_id_init();

    //dev_loopback_init();
    //com_loopback_init();


    // seed the rng
    //srandom(mos_node_id_get());
#endif //if defined(ARCH_AVR)

#ifdef MOS_DEBUG
    mos_debug_post_init();
#endif

    start();
}
Esempio n. 14
0
void kernel_main(void)
{
	terminal_init();
	puts("This is BermudOS!");
	if(!is_apic_compatible())
		puts("Hardware is not APIC compatible");
	if(!has_MSR())
		puts("CPU has no MSR");
	if(!gdt_setup())
		puts("Error while setting up GDT");
	setup_interrupts();
	if(!keyboard_setup())
		puts("Error while setting up the keyboard");
	wait_sec(4);
	char bfr[KEYBOARD_BUFFER_SIZE+1];
	int i;
	for(i = 0; i < 4; ++i)
	{
		read_keyboard_buffer(bfr);
		printf("The buffer contained: %s", bfr);
	}
}
Esempio n. 15
0
/**
 * Setting up the board
 */
static void internal_setup()
{
    // Initializing servos
    servos_init();
   
    // Initializing RC
    RC.begin(921600);
    terminal_init(&RC);

    // Configuring board LED
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN, LOW);

    // Runing user setup
    setup();

#if defined(DXL_AVAILABLE)
    // Enabling asychronous dynamixel
    dxl_async(true);
#endif
    
    // Enabling 50hz interrupt
    servos_attach_interrupt(setFlag);
}
Esempio n. 16
0
/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR. */
void
entry (unsigned long magic, unsigned long addr)
{
	multiboot_info_t *mbi;
	uint8_t* filesystem_address;

	/* Clear the screen. */
	clear();

	/* Am I booted by a Multiboot-compliant boot loader? */
	if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
	{
		printf ("Invalid magic number: 0x%#x\n", (unsigned) magic);
		return;
	}

	/* Set MBI to the address of the Multiboot information structure. */
	mbi = (multiboot_info_t *) addr;

	/* Print out the flags. */
	printf ("flags = 0x%#x\n", (unsigned) mbi->flags);

	/* Are mem_* valid? */
	if (CHECK_FLAG (mbi->flags, 0))
		printf ("mem_lower = %uKB, mem_upper = %uKB\n",
				(unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper);

	/* Is boot_device valid? */
	if (CHECK_FLAG (mbi->flags, 1))
		printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device);

	/* Is the command line passed? */
	if (CHECK_FLAG (mbi->flags, 2))
		printf ("cmdline = %s\n", (char *) mbi->cmdline);

	if (CHECK_FLAG (mbi->flags, 3)) {
		int mod_count = 0;
		int i;
		module_t* mod = (module_t*)mbi->mods_addr;
		while(mod_count < mbi->mods_count) {
			filesystem_address = (uint8_t*)mod->mod_start;
			printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start);
			printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end);
			printf("First few bytes of module:\n");
			for(i = 0; i<16; i++) {
				printf("0x%x ", *((char*)(mod->mod_start+i)));
			}
			printf("\n");
			mod_count++;
			mod++;
		}
	}
	/* Bits 4 and 5 are mutually exclusive! */
	if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
	{
		printf ("Both bits 4 and 5 are set.\n");
		return;
	}

	/* Is the section header table of ELF valid? */
	if (CHECK_FLAG (mbi->flags, 5))
	{
		elf_section_header_table_t *elf_sec = &(mbi->elf_sec);

		printf ("elf_sec: num = %u, size = 0x%#x,"
				" addr = 0x%#x, shndx = 0x%#x\n",
				(unsigned) elf_sec->num, (unsigned) elf_sec->size,
				(unsigned) elf_sec->addr, (unsigned) elf_sec->shndx);
	}

	/* Are mmap_* valid? */
	if (CHECK_FLAG (mbi->flags, 6))
	{
		memory_map_t *mmap;

		printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n",
				(unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
		for (mmap = (memory_map_t *) mbi->mmap_addr;
				(unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
				mmap = (memory_map_t *) ((unsigned long) mmap
					+ mmap->size + sizeof (mmap->size)))
			printf (" size = 0x%x,     base_addr = 0x%#x%#x\n"
					"     type = 0x%x,  length    = 0x%#x%#x\n",
					(unsigned) mmap->size,
					(unsigned) mmap->base_addr_high,
					(unsigned) mmap->base_addr_low,
					(unsigned) mmap->type,
					(unsigned) mmap->length_high,
					(unsigned) mmap->length_low);
	}

	/* Construct an LDT entry in the GDT */
	{
		seg_desc_t the_ldt_desc;
		the_ldt_desc.granularity    = 0;
		the_ldt_desc.opsize         = 1;
		the_ldt_desc.reserved       = 0;
		the_ldt_desc.avail          = 0;
		the_ldt_desc.present        = 1;
		the_ldt_desc.dpl            = 0x0;
		the_ldt_desc.sys            = 0;
		the_ldt_desc.type           = 0x2;

		SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size);
		ldt_desc_ptr = the_ldt_desc;
		lldt(KERNEL_LDT);
	}

	/* Construct a TSS entry in the GDT */
	{
		seg_desc_t the_tss_desc;
		the_tss_desc.granularity    = 0;
		the_tss_desc.opsize         = 0;
		the_tss_desc.reserved       = 0;
		the_tss_desc.avail          = 0;
		the_tss_desc.seg_lim_19_16  = TSS_SIZE & 0x000F0000;
		the_tss_desc.present        = 1;
		the_tss_desc.dpl            = 0x0;
		the_tss_desc.sys            = 0;
		the_tss_desc.type           = 0x9;
		the_tss_desc.seg_lim_15_00  = TSS_SIZE & 0x0000FFFF;

		SET_TSS_PARAMS(the_tss_desc, &tss, tss_size);

		tss_desc_ptr = the_tss_desc;

		tss.ldt_segment_selector = KERNEL_LDT;
		tss.ss0 = KERNEL_DS;
		tss.esp0 = 0x800000;
		ltr(KERNEL_TSS);
	}
	

	int z = 0;
	reset_scr();

	//set the IDT	
	set_idt();
	lidt(idt_desc_ptr);
	
	/* Init the PIC */
	i8259_init();

	/* Initialize devices, memory, filesystem, enable device interrupts on the
	 * PIC, any other initialization stuff... */

	//init paging
	init_paging();
			
	//init filesystem
	init_filesys(filesystem_address);
	
	//init keyboard
	init_keyboard();

	//init the rtc
	init_rtc();

	//init the mouse
	init_mouse();

	//clear the screen
	reset_scr();
	
	// boot_screen();
	for(z = 0; z < 3; z++)
	{
		terminal_init();
	}
	node* buffer = screens[0];
	reset_buf(buffer);
	//display the status bar

	/* Enable interrupts */
	
	sti();
	/* Do not enable the following until after you have set up your
	 * IDT correctly otherwise QEMU will triple fault and simple close
	 * without showing you any output */


	boot_screen();
	//sample mario sound
	for(z = 0; z < 500000; z++)
		play_sound(1000);

	for(z = 0; z < 500000; z++)
		play_sound(100);

	for(z = 0; z < 500000; z++)
		play_sound(900);

	for(z = 0; z < 50000; z++)
		play_sound(200);

	for(z = 0; z < 500000; z++)
		play_sound(800);

	for(z = 0; z < 500000; z++)
		play_sound(300);

	for(z = 0; z < 500000; z++)
		play_sound(700);

	for(z = 0; z < 500000; z++)
		play_sound(400);

	for(z = 0; z < 500000; z++)
		play_sound(600);

	for(z = 0; z < 500000; z++)
		play_sound(500);

	for(z = 0; z < 500000; z++)
		play_sound(500);

	for(z = 0; z < 500000; z++)
		play_sound(1000);

	for(z = 0; z < 500000; z++)
		play_sound(400);

	for(z = 0; z < 500000; z++)
		play_sound(300);

	for(z = 0; z < 500000; z++)
		play_sound(300);

	for(z = 0; z < 500000; z++)
		play_sound(200);

	//boot_screen();
	nosound();
	reset_scr();

	//init PIT for sound, timer
	init_pit(0, 100);

	/////////////////////////////////////////////////////////////

//	void imperial();

	status_bar();
	/* Execute the first program (`shell') ... */
	uint8_t fname[33] = "shell";
	execute(fname);

	/* We should never get to this point */
	//printf("Initial shell halted.");

	/* Spin (nicely, so we don't chew up cycles) */
	asm volatile(".1: hlt; jmp .1;");
}
Esempio n. 17
0
void kernel_main(void)
{
	terminal_init();
	puts("This is BermudOS with puts!");
	printf("This is BermudOS with printf!");
}
Esempio n. 18
0
void terminal_to_usb()
{
    isUSB = true;
    terminal_init(&SerialUSB);
}
Esempio n. 19
0
/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR. */
void
entry(unsigned long magic, unsigned long addr)
{
	multiboot_info_t *mbi;
	uint32_t filesys_start_addr;

	/* Clear the screen. */
	vga_text_clear();

	/* Am I booted by a Multiboot-compliant boot loader? */
	if(magic != MULTIBOOT_BOOTLOADER_MAGIC) {
		printf("Invalid magic number: 0x%#x\n", (unsigned)magic);
		return;
	}

	/* Set MBI to the address of the Multiboot information structure. */
	mbi = (multiboot_info_t *)addr;

	/* Print out the flags. */
	printf("flags = 0x%#x\n", (unsigned)mbi->flags);

	/* Are mem_* valid? */
	if(CHECK_FLAG(mbi->flags, 0))
		printf("mem_lower = %uKB, mem_upper = %uKB\n", (unsigned)mbi->mem_lower, (unsigned)mbi->mem_upper);

	/* Is boot_device valid? */
	if(CHECK_FLAG(mbi->flags, 1))
		printf("boot_device = 0x%#x\n", (unsigned)mbi->boot_device);

	/* Is the command line passed? */
	if(CHECK_FLAG(mbi->flags, 2))
		printf("cmdline = %s\n", (char *)mbi->cmdline);

	if(CHECK_FLAG(mbi->flags, 3)) {
		int mod_count = 0;
		int i;
		module_t* mod = (module_t*)mbi->mods_addr;
		filesys_start_addr = (uint32_t)mod->mod_start;
		while(mod_count < mbi->mods_count) {
			printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start);
			printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end);
			printf("First few bytes of module:\n");
			for(i = 0; i < 16; i++) {
				printf("0x%x ", *((char*)(mod->mod_start+i)));
			}
			printf("\n");
			mod_count++;
		}
	}

	/* Bits 4 and 5 are mutually exclusive! */
	if(CHECK_FLAG(mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)) {
		printf("Both bits 4 and 5 are set.\n");
		return;
	}

	/* Is the section header table of ELF valid? */
	if(CHECK_FLAG(mbi->flags, 5)) {
		elf_section_header_table_t *elf_sec = &(mbi->elf_sec);

		printf("elf_sec: num = %u, size = 0x%#x,"
			   " addr = 0x%#x, shndx = 0x%#x\n",
			   (unsigned)elf_sec->num, (unsigned)elf_sec->size,
			   (unsigned)elf_sec->addr, (unsigned)elf_sec->shndx);
	}

	/* Are mmap_* valid? */
	if(CHECK_FLAG(mbi->flags, 6)) {
		memory_map_t *mmap;

		printf("mmap_addr = 0x%#x, mmap_length = 0x%x\n",
			   (unsigned)mbi->mmap_addr,
			   (unsigned)mbi->mmap_length);
		for(mmap = (memory_map_t *)mbi->mmap_addr; 
			(unsigned long)mmap < mbi->mmap_addr + mbi->mmap_length;
			mmap = (memory_map_t *)((unsigned long)mmap + mmap->size + sizeof(mmap->size)))
			printf(" size = 0x%x,    base_addr = 0x%#x%#x\n"
				   " type = 0x%x,    length    = 0x%#x%#x\n",
				   (unsigned)mmap->size,
				   (unsigned)mmap->base_addr_high,
				   (unsigned)mmap->base_addr_low,
				   (unsigned)mmap->type,
				   (unsigned)mmap->length_high,
				   (unsigned)mmap->length_low);
	}

	/* Construct an LDT entry in the GDT */
	{
		seg_desc_t the_ldt_desc;
		the_ldt_desc.granularity	= 0;
		the_ldt_desc.opsize			= 1;
		the_ldt_desc.reserved		= 0;
		the_ldt_desc.avail			= 0;
		the_ldt_desc.present		= 1;
		the_ldt_desc.dpl			= 0x0;
		the_ldt_desc.sys			= 0;
		the_ldt_desc.type			= 0x2;

		SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size);
		ldt_desc_ptr = the_ldt_desc;
		lldt(KERNEL_LDT);
	}

	/* Construct a TSS entry in the GDT */
	{
		seg_desc_t the_tss_desc;
		the_tss_desc.granularity	= 0;
		the_tss_desc.opsize			= 0;
		the_tss_desc.reserved		= 0;
		the_tss_desc.avail			= 0;
		the_tss_desc.seg_lim_19_16	= TSS_SIZE & 0x000F0000;
		the_tss_desc.present		= 1;
		the_tss_desc.dpl			= 0x0;
		the_tss_desc.sys			= 0;
		the_tss_desc.type			= 0x9;
		the_tss_desc.seg_lim_15_00	= TSS_SIZE & 0x0000FFFF;

		SET_TSS_PARAMS(the_tss_desc, &tss, tss_size);

		tss_desc_ptr = the_tss_desc;

		tss.ldt_segment_selector = KERNEL_LDT;
		tss.ss0 = KERNEL_DS;
		tss.esp0 = 0x800000;
		ltr(KERNEL_TSS);
	}
	
	/* If kernel got to here, that means everything should be fine with the boot.
	 * Now we should initialize IDT, PIC, Syscall, paging, devices, filesystem,
	 * and any other initialization stuff... terminal_init() should be called at
	 * the very end of the initializations (after sti). */
	
	/* But first, let's clear the screen */
	vga_text_clear();
	
	/* Init the IDT */
	idt_init();

	/* Init the PIC */
	i8259_init();
	
	/* Init Syscall */
	syscall_init();
	
	/* Init Paging */
	paging_init();
	
	/* Init file system */
	filesys_init(filesys_start_addr);
	
	/* Init the Keyboard */
	keyboard_init();
	
	/* Init the RTC */
	rtc_init();

	/* Enable interrupts */
	sti();
	
	/* booting screen in mode X */
	start_up = 3;
	set_mode_x();
	load_bmp((uint8_t*)"boot", LOAD_FLAG_BOOT);
	while(start_up == 3);
	set_text_mode();
	
	/* Init the good looking terminal */
	terminal_init();
	
	/* wait for a key press to clear the start up screen */
	while(start_up == 2);

	vga_text_clear();
	welcome_and_credit();
	while(start_up == 1);
	
	/* Init the status bar for that terminal */
	terminal_stat_bar_init();
	terminal_clear();

	/* Init the PIT */
	pit_init();
	
	/* Execute the first program "shell" */
	pid_now = 1;
	pid_running[0] = 1;
	root_shell_flag = 1;
	execute((uint8_t*)"shell");

	/* Spin (nicely, so we don't chew up cycles) */
	asm volatile(".1: hlt; jmp .1;");
}
Esempio n. 20
0
File: cli.c Progetto: mhfan/stoken
int main(int argc, char **argv)
{
	char *cmd = parse_cmdline(argc, argv, NOT_GUI);
	int rc;
	char buf[BUFLEN];
	struct securid_token *t;

	rc = common_init(cmd);
	if (rc != ERR_NONE)
		die("can't initialize: %s\n", stoken_errstr[rc]);

	t = current_token;
	if (!t)
		die("error: no token present.  Use 'stoken import' to add one.\n");

	terminal_init();

	if (!strcmp(cmd, "tokencode")) {
		int days_left = securid_check_exp(t, adjusted_time());

		if (days_left < 0 && !opt_force)
			die("error: token has expired; use --force to override\n");

		unlock_token(t, 1, NULL);
		securid_compute_tokencode(t, adjusted_time(), buf);
		puts(buf);

		if (days_left < 14 && !opt_force)
			warn("warning: token expires in %d day%s\n", days_left,
				days_left == 1 ? "" : "s");
	} else if (!strcmp(cmd, "import")) {
		char *pass;

		unlock_token(t, 0, &pass);
		if (!opt_keep_password) {
			pass = xmalloc(BUFLEN);
			request_new_pass(pass);
		}

		t->is_smartphone = 0;
		securid_encode_token(t, pass, opt_new_devid, buf);
		rc = write_token_and_pin(buf, NULL, pass);
		if (rc != ERR_NONE)
			die("rcfile: error writing new token: %s\n",
				stoken_errstr[rc]);
	} else if (!strcmp(cmd, "export")) {
		char *pass;

		unlock_token(t, 0, &pass);
		if (opt_new_password)
			pass = opt_new_password;
		else if (!opt_keep_password)
			pass = NULL;

		t->is_smartphone = opt_iphone || opt_android;
		securid_encode_token(t, pass, opt_new_devid, buf);
		print_formatted(buf);
	} else if (!strcmp(cmd, "show")) {
		unlock_token(t, 0, NULL);
		securid_token_info(t, &print_token_info_line);
	} else if (!strcmp(cmd, "setpin")) {
		char *pass = NULL, pin[BUFLEN], confirm_pin[BUFLEN];
		int len;

		if (opt_file || opt_token)
			die("error: setpin only operates on the rcfile token\n");

		unlock_token(t, 0, &pass);

		if (opt_new_pin) {
			if (securid_pin_format_ok(opt_new_pin) != ERR_NONE)
				die("error: invalid --new-pin format\n");
			strncpy(pin, opt_new_pin, BUFLEN);
			len = strlen(pin);
		} else {
			prompt("Enter new PIN: ");
			len = read_user_input(pin, BUFLEN, 1);
			if (len > 0 && securid_pin_format_ok(pin) != ERR_NONE)
				die("error: PIN must be 4-8 digits\n");

			prompt("Confirm new PIN: ");
			read_user_input(confirm_pin, BUFLEN, 1);
			if (strcmp(pin, confirm_pin) != 0)
				die("error: PINs do not match\n");
		}

		securid_encode_token(t, pass, NULL, buf);
		rc = write_token_and_pin(buf, len ? pin : NULL, pass);
		free(pass);

		if (rc != ERR_NONE)
			die("error: can't set PIN: %s\n", stoken_errstr[rc]);
	} else if (!strcmp(cmd, "setpass")) {
		char pass[BUFLEN];

		unlock_token(t, 0, NULL);
		request_new_pass(pass);
		securid_encode_token(t, pass, NULL, buf);

		/* just print to stdout if it didn't come from the rcfile */
		if (opt_file || opt_token)
			print_formatted(buf);
		else {
			rc = write_token_and_pin(buf,
						 strlen(t->pin) ? t->pin : NULL,
						 strlen(pass) ? pass : NULL);
			if (rc != ERR_NONE)
				die("error: can't set password: %s\n",
				    stoken_errstr[rc]);
		}
	} else
		die("error: invalid command '%s'\n", cmd);

	return 0;
}
Esempio n. 21
0
int main(int argc, const char *argv[]) {

	const char *socket = NULL;

	mem_init();
	atexit(mem_exit);

	terminal_init();

	// --------------------------------------------
	// parse the parameters

        // Check -v (verbose) first to enable log_debug()
        // when processing other options
        for (int i=1; i < argc; i++) if (!strcmp("-v", argv[i])) set_verbose(1);

	int p = 1;
	while (p < argc && argv[p][0]=='-') {

		switch(argv[p][1]) {
		case 0:
			// single '-' option ends parameter processing
			p++;
			goto endpars;
		case 'v':
                	assert_single_char(argv[p]);
			// verbose is already checked above
			set_verbose(1);
			break;
            	case '?':
                	assert_single_char(argv[p]);
                	usage(EXIT_SUCCESS);    /* usage() exits already */
                	break;
		case 'T':
			assert_single_char(argv[p]);
                	if (p < argc-2) {
                  		p++;
                  		socket = argv[p];
                  		log_info("main: tools socket = %s\n", socket);
                	} else {
                  		log_error("-T requires <socket name> parameter\n");
                  		exit(EXIT_RESPAWN_NEVER);
                	}
                	break;
            	default:
                	log_error("Unknown command line option %s\n", argv[p]);
                	usage(EXIT_RESPAWN_NEVER);
                	break;
		}
		p++;
	}
endpars:
	// --------------------------------------------
	// open the socket

        if (socket == NULL) {
                const char *home = os_get_home_dir();
                socket = malloc_path(home, ".xdtools");
        }

	int sockfd = socket_open(socket, 0);
	if (sockfd < 0) {
		log_errno("Could not open socket %s\n", socket);
		mem_free(socket);
		exit(1);
	}
	mem_free(socket);

	// --------------------------------------------
	// find our command either as ending part of the name of the binary ...
	

	const cmdtab_t *cmd = NULL;
	int l = strlen(argv[0]);

	for (int i = 0; i < numcmds; i++) {
		int cl = strlen(cmdtab[i].name);

		if ((cl <= l)
			&& !strcmp(cmdtab[i].name, &argv[0][l-cl])) {
			cmd = &cmdtab[i];
			break;
		}
	}
	// ... or as command line parameter
	if (p < argc) {
		l = strlen(argv[p]);
		if (cmd == NULL) {
			for (int i = 0; i < numcmds; i++) {
				int cl = strlen(cmdtab[i].name);

				if ((cl <= l)
					&& !strcmp(cmdtab[i].name, argv[p])) {
					cmd = &cmdtab[i];
					p++;
					break;
				}
			}
		}
	}

	if (cmd == NULL) {
		log_error("Could not identify any of the commands!\n");
		usage(1);
	}	

	int rv = cmd->func(sockfd, argc-p, argv+p);


	close(sockfd);

	return rv;
}
Esempio n. 22
0
File: reflect.c Progetto: GNOME/vte
int
main(int argc, char **argv)
{
	GtkWidget *label, *terminal, *tophalf, *pane, *window, *sw;
	AtkObject *obj;
	char *text, *p;
	gunichar c;
	guint count;

	gtk_init(&argc, &argv);

	contents = g_array_new(TRUE, FALSE, sizeof(gunichar));

	terminal_init(&terminal);

#ifdef USE_TEXT_VIEW
	tophalf = gtk_scrolled_window_new(NULL, terminal_adjustment(terminal));
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tophalf),
				       GTK_POLICY_AUTOMATIC,
				       GTK_POLICY_AUTOMATIC);
	gtk_container_add(GTK_CONTAINER(tophalf), terminal);
#else
	tophalf = gtk_hbox_new(FALSE, 0);

	gtk_box_pack_start(GTK_BOX(tophalf), terminal, TRUE, TRUE, 0);
	gtk_widget_show(terminal);

	GtkWidget* scrollbar = gtk_vscrollbar_new(terminal_adjustment(terminal));
	gtk_box_pack_start(GTK_BOX(tophalf), scrollbar, FALSE, TRUE, 0);
	gtk_widget_show(scrollbar);
#endif
	gtk_widget_show(terminal);

	label = gtk_label_new("");
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);

	sw = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), label);
	gtk_widget_show(label);

	pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
	gtk_paned_pack1(GTK_PANED(pane), tophalf, TRUE, FALSE);
	gtk_paned_pack2(GTK_PANED(pane), sw, TRUE, FALSE);
	gtk_widget_show(tophalf);
	gtk_widget_show(sw);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(window), "delete_event",
			 G_CALLBACK(gtk_main_quit), NULL);
	gtk_container_add(GTK_CONTAINER(window), pane);
	gtk_widget_show(pane);

	obj = gtk_widget_get_accessible(terminal);
	g_assert(obj != NULL);
	g_signal_connect(G_OBJECT(obj), "text-changed::insert",
			 G_CALLBACK(text_changed_insert), label);
	g_signal_connect(G_OBJECT(obj), "text-changed::delete",
			 G_CALLBACK(text_changed_delete), label);
	g_signal_connect(G_OBJECT(obj), "text-caret-moved",
			 G_CALLBACK(text_caret_moved), label);
	g_signal_connect(G_OBJECT(obj), "text-selection-changed",
			 G_CALLBACK(text_selection_changed), label);

	count = (guint)atk_text_get_character_count(ATK_TEXT(obj));
	if (count > 0) {
		text = atk_text_get_text(ATK_TEXT(obj), 0, count);
		if (text != NULL) {
			for (p = text;
			     contents->len < count;
			     p = g_utf8_next_char(p)) {
				c = g_utf8_get_char(p);
				g_array_append_val(contents, c);
			}
			g_free(text);
		}
	}
	terminal_shell(terminal);

	gtk_window_set_default_size(GTK_WINDOW(window), 600, 450);
	gtk_widget_show(window);

	update_contents(obj, terminal);

	gtk_main();

	g_array_free(contents, TRUE);
	contents = NULL;

	return 0;
}
Esempio n. 23
0
int main() 
{
     pedal_node_state = pedal_state_neutral;
    LCD_Start();
    CAN_invertor_init();
    ADC_SAR_Start();
    ADC_SAR_StartConvert();
    EEPROM_Start();
    //isr_Start();
    //Timer_Start();
    CAN_timer_Start();
    CAN_Init();
    CAN_Start();

    isr_start_StartEx(&isr_start_handler);
   	Start_Reset_Write(1); /* source of interrupt (reset) */
    isr_start_ClearPending();

    isr_neutral_StartEx(&isr_neutral_handler);
    Neutral_Reset_Write(1);
    isr_neutral_ClearPending();
    
    isr_calibration_StartEx(&isr_calibration_handler);
    
    CyGlobalIntEnable;          //enable global interrupts

    //Initialize terminal
    terminal_init();
    monitor_init();

    pedal_restore_calibration_data();               //set min and max values
    pedal_set_CAN(); //Setup tunnel from pedal control to CAN
    pedal_set_monitor(); //Setup tunnel from pedal control to USB Monitor

    // Initialize global variables
    EEPROM_ERROR_LED_Write(0);
    should_calibrate = false;

    // terminal_registerCommand("newCmd", &newCmdRout);
    sendNMT(NMT_command_startRemoteNode);
    CyDelay(1000);
    pedal_node_state = pedal_state_driving;
    for(;;){
        pedal_fetch_data();
    }
    for(;;)
    {
        CyDelay(50);

        terminal_run(); // Refresh terminal
        if (pedal_node_state == pedal_state_neutral)
        {
            if (should_calibrate)
            {
                pedal_node_state = pedal_state_calibrating;

            } else if (should_turn_to_drive) {
                pedal_node_state = pedal_state_driving;
                //Start sending can message for invertor
                CAN_invertor_resume();
            }
        } else if (pedal_node_state == pedal_state_driving) {
            if (should_turn_to_neutral) {
                pedal_node_state = pedal_state_neutral;
                //Stop sending messages for invertor
                CAN_invertor_pause();
            }
        }
        //Clear all flags after handling
        should_calibrate = false;
        should_turn_to_drive = false;
        should_turn_to_neutral = false;

        uint8_t out_of_range_flag;
        double brake_percent = 0, throttle_percent = 0;
        double brake_percent_diff = 0, throttle_percent_diff = 0;
        uint8_t torque_plausible_flag;
        uint8_t brake_plausible_flag;
        pedal_fetch_data(); //Update ADC readings
        CAN_invertor_update_pedal_state(pedal_node_state);
        monitor_update_vechicle_state(pedal_node_state); //Update vecicle state
        monitor_status_update_vehicle_state(pedal_node_state);
        switch (pedal_node_state)
        {
            case pedal_state_neutral:
                LCD_ClearDisplay();
                LCD_Position(0,0);
                LCD_PrintString("NEUTRAL");

                break;
            case pedal_state_driving:
                LCD_ClearDisplay();
                LCD_Position(0,0);
                LCD_PrintString("DRIVING");
                //out_of_range_flag = pedal_get_out_of_range_flag();
                if (out_of_range_flag != 0)
                {
                    pedal_node_state = pedal_state_out_of_range;
                    break;
                }

                torque_plausible_flag = pedal_is_pedal_reading_matched(&brake_percent_diff, &throttle_percent_diff);
                if (torque_plausible_flag != 0)
                {
                    pedal_node_state = pedal_state_discrepency;
                    break;
                }

                brake_plausible_flag = pedal_is_brake_plausible(&brake_percent, &throttle_percent);
                if (brake_plausible_flag != 0)
                {
                    pedal_node_state = pedal_state_implausible;
                    break;
                }

                break;

            case pedal_state_calibrating:
                //clock_StopBlock();      //stop clock to disable interrupt
                pedal_calibrate();
                LCD_ClearDisplay();
                //isr_ClearPending();
                //clock_Start();
                // isr_calibration_Enable();
                pedal_node_state = pedal_state_neutral;
                break;

            case pedal_state_out_of_range:
                LCD_ClearDisplay();
                LCD_Position(0,0);
                LCD_PrintString("Pedal out of");
                LCD_Position(1,0);
                LCD_PrintString("range");

                out_of_range_flag = pedal_get_out_of_range_flag();
                if (out_of_range_flag == 0)
                {
                    pedal_node_state = pedal_state_driving;
                }
                break;

            case pedal_state_discrepency:
                LCD_ClearDisplay();
                LCD_Position(0,0);
                LCD_PrintString("Pedal discrepency");
                torque_plausible_flag = pedal_is_pedal_reading_matched(&brake_percent_diff, &throttle_percent_diff);
                if (torque_plausible_flag == 0)
                {
                    pedal_node_state = pedal_state_driving;
                }
                break;

            case pedal_state_implausible:
                LCD_ClearDisplay();
                LCD_Position(0,0);
                LCD_PrintString("Pedal implausible");
                brake_plausible_flag = pedal_is_brake_plausible(&brake_percent, &throttle_percent);
                if (throttle_percent < PEDAL_BRAKE_IMPLAUSIBLE_EXIT_THROTTLE_PERCENT)
                {
                    pedal_node_state = pedal_state_driving;
                }
                break;
        }

        // CyDelay(100);
    }

    return 0;
}
Esempio n. 24
0
int main(int argc, char *argv[]) {

	int rv = -1;

	const char *device = NULL;
	const char *scriptname = NULL;

	// wait for socket if not there right away?
	int dowait = 0;

	terminal_init();


        int i=1;
        while(i<argc && argv[i][0]=='-' && argv[i][1] != 0) {
          	switch(argv[i][1]) {
            	case '?':
                	assert_single_char(argv[i]);
                	usage(EXIT_SUCCESS);    /* usage() exits already */
                	break;
            	case 'd':
                	assert_single_char(argv[i]);
                	if (i < argc-1) {
                  		i++;
                  		device = argv[i];
                  		log_info("main: device = %s\n", device);
                	} else {
                  		log_error("-d requires <device> parameter\n");
                  		exit(1);
                	}
                	break;
		case 'v':
			set_verbose();
			break;
		case 't':
			trace = 1;
			break;
		case 'w':
			dowait = 1;
			break;
            	default:
                	log_error("Unknown command line option %s\n", argv[i]);
                	usage(1);
                	break;
          	}
          	i++;
        }

	// next parameter is the script name
	if (i >= argc) {
		log_error("Script name parameter missing!\n");
		return -1;
	}

	scriptname = argv[i];
	i++;

	registry_t *script = load_script_from_file(scriptname);

	if (script != NULL) {

		int sockfd = socket_open(device, dowait);
	
		if (sockfd >= 0) {

			rv = execute_script(sockfd, script);
		}
	}

	
	return rv;
}