Example #1
0
void handle_sdcard()
{

  DEBUG_PUTS("[Card inserted]\n");

  if (sd_init())
    if (fatfs_mount())
      if (find_imgfile())
	if (imgfile_init()) {
	  set_disk_type(imgheader.disk_type);
	  PORTA = fatfs_filenumber;
	  fatfs_next_filename();
	} else {
	  fatfs_reset_filename();
	  PORTA = ~0;
	}

  while (SDCARD_INSERTED) {
    service_ide();
    service_cdda();
  }

  DEBUG_PUTS("[Card extracted]\n");
  cdda_stop();
  set_disk_type(0xff);
}
Example #2
0
PSW systeme(PSW m) {
    if(lastInputTime + 3 < time(NULL)){
        system_io_fake_input();
        DEBUG_PUTS(DEBUG_T_SYSTEM, "FAKE INPUT");
        lastInputTime = time(NULL);
    }
    
    if (m.IN == 0)
        return m;

    DEBUG_PRINTF(DEBUG_T_SHOW_INT, "INTERUPT: %s\n", system_int2str(m.IN));

    switch (m.IN) {
        case INT_INIT:
            return (systeme_init());
        case INT_SEGV:
            system_int_fatal(m.IN);
            break;
        case INT_TRACE:
            system_int_trace(&m);
            break;
        case INT_INST:
            system_int_fatal(m.IN);
            break;
        case INT_SYSC:
            system_int_sysc(&m);
            break;
        case INT_CLOCK:
            system_clock(&m);
            break;
    }
    return m;
}
Example #3
0
void net_init(const uint8_t *mac_address, struct ip_info *p_ip_info, const uint8_t *hostname, bool use_dhcp) {
	uint16_t i;

	net_timers_init();

	if (use_dhcp) {
		p_ip_info->ip.addr = 0;
		p_ip_info->gw.addr = 0;
		p_ip_info->netmask.addr = 0;
	} else {
		arp_init(mac_address, p_ip_info);
	}

	ip_init(mac_address, p_ip_info);

	if (use_dhcp) {
		if (dhcp_client(mac_address, p_ip_info, hostname) < 0) {
			DEBUG_PUTS("DHCP Client failed");
		} else {
			arp_init(mac_address, p_ip_info);
			ip_set_ip(p_ip_info);
		}
	}

	for (i = 0; i < ETH_ADDR_LEN; i++) {
		s_mac_address[i] = mac_address[i];
	}

	uint8_t *src = (uint8_t *) p_ip_info;
	uint8_t *dst = (uint8_t *) &s_ip_info;

	for (i = 0; i < sizeof(struct ip_info); i++) {
		*dst++ = *src++;
	}
}
Example #4
0
static void system_sysc_getchar(PSW* m){
    DEBUG_PUTS(DEBUG_T_SYSC, "SYSCALL GETCHAR()");
    
    Process* proc = process_current();
    char c = system_io_getchar(proc);
    
    //Change de processus (en attente de caractère)
    if(proc->state == PROC_STATE_GETCHAR){
        system_clock(m);
        return;
    }
    
    m->DR[m->RI.i] = c;
    ++m->PC;
}
Example #5
0
static void system_sysc_exit(PSW* m) {
    DEBUG_PRINTF(DEBUG_T_SYSC, "SYSCALL EXIT()\n");
    
    Process* process = process_current();
    
    if(process == NULL){
        DEBUG_PUTS(DEBUG_T_SYSTEM, "Pas de processus courant");
        return;
    }
    
    DEBUG_PRINTF(DEBUG_T_SYSTEM, "Suppr. proc %d\n", (int)process->number);
    
    process_kill(process);
    system_clock(m);
}
Example #6
0
static void system_sysc_fork(PSW* m) {
    DEBUG_PUTS(DEBUG_T_SYSC, "SYSCALL FORK()");
    
    Process* child = process_fork(process_current());
    
    if(child == NULL){
        ++m->PC;
        return;
    }

    m->AC = child->number;
    m->DR[m->RI.i] = child->number;
    ++m->PC;

    child->cpu.PC = m->PC;
    child->state = PROC_STATE_READY;
}
Example #7
0
static PSW systeme_init(void) {
    DEBUG_PUTS(DEBUG_T_SYSTEM, "Booting");

    process_init();

    //Création du processus père
    process_alloc()->state = PROC_STATE_READY;
    process_next();

    PSW cpu;

    const int varIndex = 15;

    /*** creation d'un programme ***/
    make_inst(0, INST_SUB, 1, 1, 0); //R1 = 0
    make_inst(1, INST_SUB, 2, 2, 0); //R2 = 0
    make_inst(2, INST_STORE, 1, 1, varIndex); //mem[15] = 0
    make_inst(3, INST_SYSC, 2, 2, SYSC_FORK); //R2 = fork()
    make_inst(4, INST_IFGT, 0, 0, 10); //if(AC == 0) faire fils, sinon le père

    //Code fils
    make_inst(5, INST_ADD, 1, 0, 1); //R1 = 1
    make_inst(6, INST_SYSC, 1, 0, SYSC_PUTI); //puti(1)
    make_inst(7, INST_SYSC, 1, 0, SYSC_SLEEP);//sleep(1)
    make_inst(8, INST_SYSC, 1, 0, SYSC_PUTI);//puti(1)
    make_inst(9, INST_SYSC, 0, 0, SYSC_EXIT);//exit()

    //Code Père
    make_inst(10, INST_ADD, 1, 0, 1); //R1 = 4
    make_inst(11, INST_SYSC, 1, 0, SYSC_SLEEP); //sleep(4)
    make_inst(12, INST_JUMP, 0, 0, 3); //refait le fork
    make_inst(13, INST_SYSC, 2, 0, SYSC_PUTI); //puti(R2)
    make_inst(14, INST_JUMP, 0, 0, 11);

    /*** valeur initiale du PSW ***/
    memset(&cpu, 0, sizeof (PSW));
    cpu.IN = INT_NONE;
    cpu.PC = 0;
    cpu.SB = 0;
    cpu.SS = 20;

    return cpu;
}
Example #8
0
int nid_table_analyzeStub(const void *stub, SceNID nid, nidTable_entry *entry)
{
        entry->nid = nid;
        entry->value.i = 0;

        ARM_INSTRUCTION instr;

        while(1)
        {
                if(Disassemble(stub, &instr) < 0)
                        return ANALYZE_STUB_INVAL;

                switch(instr.instruction)
                {
                        case ARM_INST_MOVW:
                                entry->value.i = instr.value[1];
                                break;
                        case ARM_INST_MOVT:
                                entry->value.i |= instr.value[1] << 16;
                                break;

                        case ARM_INST_BX:
                        case ARM_INST_BLX:
                                entry->type = ENTRY_TYPES_FUNCTION;
                                return ANALYZE_STUB_OK;

                        case ARM_INST_SVC:
                                entry->type = ENTRY_TYPES_SYSCALL;
                                return ANALYZE_STUB_OK;

                        case ARM_INST_MVN:
                                return ANALYZE_STUB_UNRESOLVED;

                        default:
                                DEBUG_PUTS("ERROR");
                                return ANALYZE_STUB_INVAL;
                }
                stub = (char*)stub + sizeof(SceUInt);
        }
}
Example #9
0
static int nid_table_addStubsInModule(Psp2LoadedModuleInfo *target)
{
        nidTable_entry entry;
        DEBUG_PUTS("Searching for module info");
        SceModuleInfo *orig_mod_info = nid_table_findModuleInfo(target->segments[0].vaddr, target->segments[0].memsz, target->module_name);
        DEBUG_PUTS("Found");
        if(orig_mod_info != NULL) {

                //Build entries from export table
                SceUInt base_orig = (SceUInt)orig_mod_info - orig_mod_info->ent_top + sizeof(SceModuleInfo);
                SceModuleExports *exportTable_orig = (SceModuleExports*)(base_orig + orig_mod_info->ent_top);

                for(; (SceUInt)exportTable_orig < (SceUInt)(base_orig + orig_mod_info->ent_end); exportTable_orig++)
                {
                        for(int i = 0; i < exportTable_orig->num_functions; i++)
                        {
                                entry.nid = exportTable_orig->nid_table[i];
                                entry.type = ENTRY_TYPES_FUNCTION;
                                entry.value.p = exportTable_orig->entry_table[i];
                                nid_storage_addEntry(&entry);
                        }
                }
                DEBUG_PUTS("Exports resolved");
                //NOTE: The problem is somewhere here

                //Build entries from import table

                Psp2LoadedModuleInfo l_mod_info;

                int loadResult = sizeof(int);
                SceUID l_mod_uid = sceKernelLoadModule(target->path,0,&loadResult);
                if(l_mod_uid < 0) {
                        DEBUG_PUTS("Reload failed...");
                        return -1;
                }

                l_mod_info.size = sizeof(Psp2LoadedModuleInfo);
                if(sceKernelGetModuleInfo(l_mod_uid, &l_mod_info) < 0) {
                        DEBUG_PUTS("Failed to get module info...");
                        return -1;
                }


                SceModuleInfo *mod_info = nid_table_findModuleInfo(l_mod_info.segments[0].vaddr, l_mod_info.segments[0].memsz, l_mod_info.module_name);

                if(mod_info != NULL)
                {
                        SceUInt base_orig = (SceUInt)target->segments[0].vaddr;

                        SceUInt base_l = (SceUInt)l_mod_info.segments[0].vaddr;
                        SceModuleImports *importTable_l = (SceModuleImports*)(base_l + mod_info->stub_top);

                        //Check the export tables to see if the NID is present
                        //If so assign the respective pointer to functionPtrLocation
                        FOREACH_IMPORT(base_orig, orig_mod_info, importTable_orig)
                        {
                                void **entryTable = GET_FUNCTIONS_ENTRYTABLE(importTable_orig);
                                SceNID *nidTable = GET_FUNCTIONS_NIDTABLE(importTable_l);

                                for(unsigned int i = 0; i < GET_FUNCTION_COUNT(importTable_orig); i++)
                                {
                                        int err = nid_table_analyzeStub(entryTable[i], nidTable[i], &entry);
                                        if(err == ANALYZE_STUB_OK)
                                               nid_storage_addEntry(&entry);
                                        else if(err == ANALYZE_STUB_INVAL)
                                               break;
                                }

                                entryTable = GET_VARIABLE_ENTRYTABLE(importTable_orig);
                                nidTable = GET_VARIABLE_NIDTABLE(importTable_l);

                                for(int i = 0; i < GET_VARIABLE_COUNT(importTable_orig); i++)
                                {
                                        entry.type = ENTRY_TYPES_VARIABLE;
                                        entry.nid = nidTable[i];
                                        entry.value.i = *(SceUInt*)entryTable[i];
                                        nid_storage_addEntry(&entry);
                                }

                                importTable_l = GET_NEXT_IMPORT(importTable_l);
                        }
Example #10
0
File: png.c Project: m4t3uz/yummy
uint32_t * load_png(struct load_image *args)
{
	png_structp png;
	png_infop info;
	int color_type;
	void *rgb_data;
	png_bytep *pointers;
	int i;
	png_uint_32 w,h;
	int depth;
	struct png_context context;
	png_uint_32 stride;
	
	if(png_sig_cmp(args->data, 0, 8)) {
		DEBUG_PUTS("not png");
		return 0;
	}
	png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
	info = png_create_info_struct(png);
	context.data = args->data;
	context.len = args->length;
	context.pos = 8;
	png_set_read_fn(png, &context, &read_callback);
	png_set_sig_bytes(png, 8);
	png_read_info(png, info);
	png_get_IHDR(png, info, &w, &h, &depth, &color_type, 0, 0, 0);
	DEBUG_PRINTF("w: %d\n", w);
	DEBUG_PRINTF("h: %d\n", h);
	switch (color_type) {
		case PNG_COLOR_TYPE_PALETTE:
		DEBUG_PUTS("pallete");
		png_set_palette_to_rgb(png);
		break;
		case PNG_COLOR_TYPE_RGB_ALPHA:
		DEBUG_PUTS("rgba");
		break;
		default:
		rgb_data = 0;
		goto out;
	};
	png_set_filler(png, 0xff, PNG_FILLER_AFTER);
	pointers = (png_bytep *) malloc(h * sizeof(*pointers));
	if (!pointers) {
		rgb_data = 0;
		goto out;
	}
	stride = png_get_rowbytes(png, info);
	rgb_data = malloc(stride * 4 * h);
	if (!rgb_data) {
		rgb_data = 0;
		goto out;
	}
	for (i = 0; i < h; i++)
		pointers[i] = rgb_data + w * 4 * i;
	png_read_image(png, pointers);
	*args->w = w;
	*args->h = h;
out:
	png_destroy_read_struct(&png, &info, 0);
	
	return rgb_data;
}