示例#1
0
文件: emgr.c 项目: 2garryn/pl_library
void init_emgr(){
  //Initialization code
  emgr_reset( &emgr_struct );

  //#ifdef __DEBUG_MODE
  logger_initialize();
  //#endif

};
示例#2
0
/* mpiperf_initalize: */
void mpiperf_initialize()
{
    int rc;

    rc = logger_initialize(mpiperf_logfile, mpiperf_logmaster_only);
    if (rc == MPIPERF_FAILURE) {
        exit_error("Logger initialization failed");
    }

    if (mpiperf_timername != NULL) {
        if (hpctimer_initialize(mpiperf_timername) == HPCTIMER_FAILURE) {
            exit_error("Error initializing timer: %s", mpiperf_timername);
        }
        logger_log("hpctimer '%s' is initialized", mpiperf_timername);
    }

    rc = bench_initialize(mpiperf_bench);
    if (rc == MPIPERF_FAILURE) {
        exit_error("Error initializing benchmark");
    }
}
t_personaje* personaje_crear(char* config_path) {
    //creamos una instancia de personaje
    alloc(self, t_personaje);

    //creamos una instancia del lector de archivos de config
    t_config* config = config_create(config_path);
    t_config* global_config = config_create("global.cfg");

    //datos basicos del personaje
    self->nombre = string_duplicate(config_get_string_value(config, "Nombre"));
    self->simbolo = *config_get_string_value(config, "Simbolo");
    int vidas = config_get_int_value(config, "Vidas");
    self->vidas_iniciales = vidas;
    self->vidas = vidas;

    //misc
    if(config_has_property(global_config, "AutoContinue")) self->auto_continue = config_get_int_value(global_config, "AutoContinue");
    else self->auto_continue = 0;

    //datos del logger
    char* log_file;
    if(config_has_property(config,"LogFile")) log_file = string_duplicate(config_get_string_value(config, "LogFile"));
    else log_file = string_from_format("%s.log", self->nombre);

    char* log_level;
    if(config_has_property(global_config, "LogLevel")) log_level = config_get_string_value(global_config, "LogLevel");
    else if(config_has_property(config, "LogLevel")) log_level = config_get_string_value(config, "LogLevel");
    else log_level = "INFO";

    //inicializamos el logger
    logger_initialize(log_file, "personaje", log_level, 1);
    self->logger = logger_new_instance();
    var(logger, self->logger);

    //datos de plataforma
    char* plataforma;
    if(config_has_property(global_config, "Plataforma"))
        plataforma = string_duplicate(config_get_string_value(global_config, "Plataforma"));
    else
        plataforma = string_duplicate(config_get_string_value(config, "Plataforma"));
    self->ippuerto_orquestador = plataforma;

    //datos de niveles y objetivos
    char** nombres_niveles = config_get_array_value(config, "Niveles");
    t_list* niveles = list_create();
    int i = 0;
    char* nombre_nivel = nombres_niveles[i];

    while(nombre_nivel != null) {
        alloc(nivel, t_nivel);
        nivel->nombre = string_duplicate(nombre_nivel);
        nivel->objetivos = list_create();

        char* key_objetivos = string_from_format("Obj[%s]", nombre_nivel);
        char* objetivos = config_get_string_value(config, key_objetivos);

        logger_info(logger, "Nivel: %s", nivel->nombre);
        logger_info(logger, "Objetivos: %s", objetivos);
        int ii = 0;
        while(objetivos != null && objetivos[ii] != '\0') {
            char* objetivo = string_from_format("%c" , objetivos[ii]);
            list_add(nivel->objetivos, objetivo);
            ii++;
        }

        free(key_objetivos);

        list_add(niveles, nivel);

        i++;
        nombre_nivel = nombres_niveles[i];
    }
    self->niveles = niveles;

    logger_info(logger, "Log File:%s", log_file);
    free(log_file);
    logger_info(logger, "Log Level:%s", log_level);

    //liberamos recursos
    config_destroy(config);
    config_destroy(global_config);
    liberar_niveles(nombres_niveles);

    return self;
}
示例#4
0
文件: main.cpp 项目: stmobo/Omamori
void test_process_1() {   
    kprintf("Initializing serial logging.\n");
    initialize_serial();
    
    logger_initialize();
    kprintf("Initialized kernel logger process.\n");
    
    terminal_writestring("Initializing ACPI.\n");
    initialize_acpi();

    kprintf("Initializing APICs.\n");
	logger_flush_buffer();
	initialize_apics();
	//logger_flush_buffer();
	//kprintf("Done initializing APICs.\n");
	//logger_flush_buffer();

	/*
	unsigned long long int last_ticked = get_sys_time_counter();
	kprintf("Current system timer = %llu.\n", last_ticked);
	logger_flush_buffer();
	while(true) {
		if( last_ticked != get_sys_time_counter() ) {
			kprintf("Tick.\nCurrent system timer = %llu.\n", last_ticked);
			logger_flush_buffer();
			last_ticked = get_sys_time_counter();
		}
	}
	*/

	//while(true) { asm volatile("pause"); };

    kprintf("Starting kernel worker thread.\n");
    k_work::start();
    
    kprintf("Initializing PS/2 controller.\n");
    ps2_controller_init();
    
    kprintf("Initializing PS/2 keyboard.\n");
    ps2_keyboard_initialize();
    
    kprintf("Initializing I/O.\n");
    io_initialize();
    
    kprintf("Initializing PCI.\n");
    //pci_initialize();
    pci_check_all_buses();

    pci_get_int_routing();
    //while(true) { asm volatile("pause"); };

    kprintf("Initializing ATA storage.\n");
    ata::initialize();
    
    io_detect_disk( io_get_disk( 1 ) );

    kprintf("Scheduling work...\n");
    logger_flush_buffer();
    k_work::work* wk = k_work::schedule( &k_worker_thread_test );
	kprintf("Test work function returned: %u\n", wk->wait());

    uint32_t child_pid = fork();
    if( child_pid == -1 ) {
        kprintf("Whoops, something went wrong with fork!");
    } else if( child_pid == 0 ) {
        kprintf("Hello from (child) process %u!\n", (unsigned int)process_current->id);
        /*
        set_message_listen_status( "keypress", true );
        while(true) {
            unique_ptr<ps2_keypress> kp;
            kp = ps2_keyboard_get_keystroke();
            if( !kp->released ) {
                if( kp->key == KEY_CurUp ) {
                    kprintf("Process %u: Up!\n", process_current->id);
                } else if( kp->key == KEY_CurDown ) {
                    kprintf("Process %u: Down!\n", process_current->id);
                /*} else if( kp->key == KEY_Enter ) {
                    kprintf("Process %u: Forcing ATA cache flush...\n", process_current->id);
                    ata_do_cache_flush(); *//*
                }
            }
        }
        */
        /*
		unsigned long long int last_ticked = 0;
		while(true) {
			if(last_ticked+1000 <= get_sys_time_counter()) {
				kprintf("Tick.");
				last_ticked = get_sys_time_counter();
			}
		}
		*/

    } else {
        kprintf("Hello from (parent) process %u!\n", process_current->id);
        kprintf("Starting lua interpretation.\n");
        lua_State *st = luaL_newstate();
        //kprintf("Opened state..\n");
        
        luaL_openlibs( st );
        //kprintf("Opened libs..\n");
        lua_register( st, "writeout", lua_writeout_proxy );
        //kprintf("Registered writeout..\n");
        int stat = luaL_loadstring( st, "writeout(\"hello from lua version \",_VERSION,\"!\") return 0xC0DE" );
        //kprintf("Loaded test program..\n");
        
        if( stat == 0 ) { // was it loaded successfully?
            //kprintf("Performing call..\n");
            stat = lua_pcall( st, 0, 1, 0 );
            if( stat == 0 ) { // get return values
                int retval = lua_tonumber(st, -1);
                kprintf("Test program returned successfully, returned value: 0x%x\n", retval);
                lua_pop(st, 1);
            }
        }
        if( stat != 0 ) { // was there an error?
            const char *err = lua_tostring(st, -1);
            kprintf("lua-error: %s\n", err);
            lua_pop(st, 1);
        }
        lua_close(st);
        //kprintf("Closed state..\n");
        
        //kprintf("Initializing AHCI.\n");
        //ahci_initialize();

        // format partition 1 as FAT (using our own code):
        //fat32_do_format( 1 );
        
        const char* test_file_name = "test2.txt";
        char *test_file_data = "Hello world! This is a test file!";

        fat_fs::fat_fs f( 1 );
		iso9660::iso9660_fs f2(2);
		device_manager::dev_fs f3;
		vfs::vfs_root = f.base;

		vfs::vfs_status fop_stat = vfs::mount(&f2, (unsigned char*)(const_cast<char*>("/cd")));
		if( fop_stat != vfs::vfs_status::ok ) {
			kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat));
		} else {
			kprintf("FS mount succeeded.\n");
		}

		fop_stat = vfs::mount(&f3, (unsigned char*)(const_cast<char*>("/dev")));
		if( fop_stat != vfs::vfs_status::ok ) {
			kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat));
		} else {
			kprintf("FS mount succeeded.\n");
		}

		while(true) {
			kprintf(">");
			logger_flush_buffer();

			unsigned int len;
			char* line = ps2_keyboard_readline( &len );

			unsigned int cmd_len = 0;
			unsigned int arg1_start = 0;
			unsigned int arg1_end = 0;
			unsigned int arg2_start = 0;

			bool found_cmd = false;
			bool found_arg1 = false;
			bool stopped_arg1 = false;
			bool found_arg2 = false;

			for(unsigned int i=0;i<len;i++) {
				if(line[i] == ' ') {
					if( !found_cmd ) {
						cmd_len = i;
						found_cmd = true;
					} else if( found_arg1 && !stopped_arg1 ) {
						arg1_end = i;
						stopped_arg1 = true;
					}
				} else {
					if( found_cmd && !found_arg1 ) {
						arg1_start = i;
						found_arg1 = true;
					} else if( found_arg1 && stopped_arg1 ) {
						arg2_start = i;
						found_arg2 = true;
						break;
					}
				}
			}


			if( found_cmd ) {
				char* cmd = NULL;
				char* arg1 = NULL;
				char* arg2 = NULL;
				cmd = (char*)kmalloc( cmd_len+1 );

				for(unsigned int i=0;i<cmd_len;i++) {
					cmd[i] = line[i];
				}
				cmd[cmd_len] = '\0';

				if( found_arg1 ) {
					if( stopped_arg1 ) {
						arg1 = (char*)kmalloc( (arg1_end - arg1_start)+1 );

						for(unsigned int i=arg1_start;i<arg1_end;i++) {
							arg1[ i - arg1_start ] = line[i];
						}
						arg1[ arg1_end - arg1_start ] = '\0';

						if( found_arg2 ) {
							arg2 = (char*)kmalloc( (len - arg2_start)+1 );
							for(unsigned int i=arg2_start;i<len;i++) {
								arg2[i-arg2_start] = line[i];
							}
							arg2[len-arg2_start] = '\0';
						}
					} else {
						arg1 = (char*)kmalloc( (len - arg1_start)+1 );
						for(unsigned int i=arg1_start;i<len;i++) {
							arg1[ i - arg1_start ] = line[i];
						}
						arg1[ len - arg1_start ] = '\0';
					}
				}

				if( arg1 != NULL ) {
					if( strcmp( cmd, const_cast<char*>("ls") ) || strcmp( cmd, const_cast<char*>("list") ) ) {
						vector<vfs_node*> dls;
						vfs::vfs_status fop_stat = vfs::list_directory( (unsigned char*)arg1, &dls );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS list succeeded.\n");
						}
						kprintf( "Directory listing:\n" );
						for( unsigned int i=0;i<dls.count();i++) {
							kprintf( "%s\n", dls[i]->name );
						}
					} else if( (arg2 != NULL) && strcmp( cmd, const_cast<char*>("write") ) ) {
						vfs::vfs_status fop_stat = vfs::write_file( (unsigned char*)arg1, (void*)arg2, strlen(arg2)+1);
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS write failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS write succeeded.\n");
						}
					} else if( strcmp( cmd, const_cast<char*>("read") ) ) {
						vfs_node* node = NULL;
						vfs::vfs_status fop_stat = vfs::get_file_info( (unsigned char*)arg1, &node );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS get info failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS get info succeeded.\n");
						}

						if( node != NULL ) {
							if( node->type != vfs_node_types::file ) {
								kprintf("FS read failed with error: incorrect type\n");
								continue;
							}
						}

						vfs_file* fn = (vfs_file*)node;
						void* buffer = kmalloc( fn->size );

						fop_stat = vfs::read_file( (unsigned char*)arg1, buffer );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS read failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS read succeeded.\n");
						}

						kprintf("file data: %s\n", (unsigned char*)buffer );
					} else if( strcmp( cmd, const_cast<char*>("delete") ) || strcmp( cmd, const_cast<char*>("rm") ) ) {
						vfs::vfs_status fop_stat = vfs::delete_file( (unsigned char*)arg1 );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS delete failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS delete succeeded.\n");
						}
					} else if( ( arg2 != NULL ) && (strcmp( cmd, const_cast<char*>("copy") ) || strcmp( cmd, const_cast<char*>("cp") ) ) ) {
						vfs::vfs_status fop_stat = vfs::copy_file( (unsigned char*)arg2, (unsigned char*)arg1 );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS copy failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS copy succeeded.\n");
						}
					} else if( ( arg2 != NULL ) && (strcmp( cmd, const_cast<char*>("move") ) || strcmp( cmd, const_cast<char*>("mv") ) ) ) {
						vfs::vfs_status fop_stat = vfs::move_file( (unsigned char*)arg2, (unsigned char*)arg1 );
						if( fop_stat != vfs::vfs_status::ok ) {
							kprintf("FS move failed with error: %s\n", vfs::status_description(fop_stat));
						} else {
							kprintf("FS move succeeded.\n");
						}
					}
				}
			}
		}

		/*

        vfs_directory *root = f.base;
        vfs_file *test_file = NULL;
        kprintf( "Directory listing:\n" );
        for( unsigned int i=0;i<root->files.count();i++) {
            vfs_node *fn = root->files[i];
            kprintf( "* %u - %s\n", i, fn->name );
            if( strcmp(const_cast<char*>(test_file_name), (char*)(fn->name), 0) ) {
            	test_file = new vfs_file(const_cast<vfs_node*>(fn));
            }
        }

        if(test_file == NULL) {
        	test_file = f.create_file( (unsigned char*)(test_file_name), f.base );
			kprintf("test file created\n");
        	test_file->size = strlen(test_file_data)+1;

        	f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1);
        	kprintf("File written out to %s\n", test_file_name);
        } else {
        	//f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1);
			//kprintf("File written out to %s\n", test_file_name);

			void *readback = kmalloc(strlen(test_file_data)+1);
			f.read_file(test_file, readback);

			char* readback_data = (char*)readback;
			kprintf("Readback data: %s (%#p)\n", readback_data, readback);
        }


		unsigned char f2_mountpoint[] = { '/', 'c', 'd', '\0' };
		root = f2.base;
		kprintf( "Directory listing (ISO 9660):\n" );
		for( unsigned int i=0;i<root->files.count();i++) {
			vfs_node *fn = root->files[i];
			kprintf( "* %u - %s\n", i, fn->name );
		}

		vfs::vfs_status fop_stat = vfs::mount(&f2, f2_mountpoint);
		if( fop_stat != vfs::vfs_status::ok ) {
			kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat));
		} else {
			kprintf("FS mount succeeded.\n");
		}

		vector<vfs_node*> dls;
		fop_stat = vfs::list_directory( (unsigned char*)(const_cast<char*>("/")), &dls );
		if( fop_stat != vfs::vfs_status::ok ) {
			kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat));
		} else {
			kprintf("FS list succeeded.\n");
		}

		kprintf( "Directory listing (VFS root):\n" );
		for( unsigned int i=0;i<dls.count();i++) {
			kprintf("* %u - %s\n", i, dls[i]->name);
		}

		dls.clear();
		fop_stat = vfs::list_directory( (unsigned char*)(const_cast<char*>("/cd")), &dls );
		if( fop_stat != vfs::vfs_status::ok ) {
			kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat));
		} else {
			kprintf("FS list succeeded.\n");
		}

		kprintf( "Directory listing (VFS, /cd):\n" );
		for( unsigned int i=0;i<dls.count();i++) {
			kprintf("* %u - %s\n", i, dls[i]->name);
		}

        logger_flush_buffer();
		while(true) { asm volatile("pause"); }

		*/

        /*
        f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1);

		kprintf("File written out to %s\n", test_file_name);
		logger_flush_buffer();
		system_halt;
		*/

        /*
        test_file = f.create_file( (unsigned char*)(test_file_name), f.base );
		kprintf("test file created\n");
		logger_flush_buffer();
		system_halt;
		*/

        /*
        logger_flush_buffer();
		system_halt;

        if( test_file == NULL ) {
        	test_file = f.create_file( (unsigned char*)(test_file_name), f.base );
        	kprintf("test file created\n");
        	logger_flush_buffer();
			system_halt;
        }

        f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1);

        kprintf("File written out to %s\n", test_file_name);
        logger_flush_buffer();
		system_halt;

        void *readback = kmalloc(strlen(test_file_data)+1);
        f.read_file(test_file, readback);

        char* readback_data = (char*)readback;
        kprintf("Readback data: %s\n", readback_data);
        logger_flush_buffer();
		system_halt;
		*/

        /*

        fat32_fs f2(1);
        root = f2.root_dir_vfs;
        kprintf( "Directory listing:\n" );
		for( unsigned int i=0;i<root->files.count();i++) {
			vfs_node *fn = root->files[i];
			kprintf( "* %u - %s\n", i, fn->name );
		}
        
		logger_flush_buffer();
		system_halt;
		*/

        // hacked-together raw disk function:
        /*
        while( true ) {
            unsigned int len = 0;
            kprintf("sector_n > ");
            char* sector_str = ps2_keyboard_readline(&len);
            if( len > 0 ) {
                uint32_t sector = atoi( sector_str );
                void *buf = kmalloc(512);
                io_read_partition( 1, buf, sector*512, 512 );
                uint8_t *buf2 = (uint8_t*)buf;
                for( int i=0;i<512;i+=16 ) {
                    kprintf("%#02x: ", i);
                    for( int j=0;j<16;j++ ) {
                        kprintf("%02x ", buf2[i+j]);
                    }
                    kprintf("\n");
                    set_message_listen_status( "keypress", true );
                    while(true) {
                        unique_ptr<ps2_keypress> kp;
                        kp = ps2_keyboard_get_keystroke();
                        if( !kp->released ) {
                            if( kp->key == KEY_Enter ) {
                                break;
                            }
                        }
                    }
                }
                kfree(buf);
            }
            kfree(sector_str);
        }
        */
        // hacked-together ls:
        /*
        kprintf("Reading partition 1 as FAT32...");
        fat32_fs *fs = new fat32_fs( 1 );
        kprintf("Reading root directory...\n");
        vfs_directory *root = fs->read_directory(0);
        for( int i=0;i<root->files.count();i++ ) {
            kprintf("* %u - %s\n", i, root->files[i]->name);
        }
        */
    }
}