/** * Adds a control dependence from node to dep_on. */ static void add_cdep(ir_node *node, ir_node *dep_on) { ir_cdep *dep = find_cdep(node); assert(is_Block(dep_on)); if (dep == NULL) { ir_cdep *newdep = OALLOC(&cdep_data->obst, ir_cdep); newdep->node = dep_on; newdep->next = NULL; pmap_insert(cdep_data->cdep_map, node, newdep); } else { ir_cdep *newdep; for (;;) { if (get_cdep_node(dep) == dep_on) return; if (dep->next == NULL) break; dep = dep->next; } newdep = OALLOC(&cdep_data->obst, ir_cdep); newdep->node = dep_on; newdep->next = NULL; dep->next = newdep; } }
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) { ir_entity *entity = pmap_get(ir_entity, irp->compilerlib_entities, id); if (entity != NULL) return entity; /* let frontend mangle the name */ ident *ld_name = compilerlib_mangler(id, mt); /* search for an existing entity */ ir_type *glob = get_glob_type(); for (size_t i = 0, n_members = get_compound_n_members(glob); i < n_members; ++i) { ir_entity *member = get_compound_member(glob, i); if (get_entity_ld_ident(member) == ld_name) { entity = member; goto found; } } entity = new_entity(glob, id, mt); set_entity_ld_ident(entity, ld_name); set_entity_visibility(entity, ir_visibility_external); found: pmap_insert(irp->compilerlib_entities, id, entity); return entity; }
static ir_entity *get_pic_symbol(be_main_env_t *env, ir_entity *entity) { ir_entity *result = pmap_get(ir_entity, env->ent_pic_symbol_map, entity); if (result == NULL) { result = create_pic_symbol(env, entity); pmap_insert(env->ent_pic_symbol_map, entity, result); } return result; }
/** * Returns the trampoline entity for the given method. */ static ir_entity *get_trampoline(be_main_env_t *env, ir_entity *method) { ir_entity *result = pmap_get(ir_entity, env->ent_trampoline_map, method); if (result == NULL) { result = create_trampoline(env, method); pmap_insert(env->ent_trampoline_map, method, result); } return result; }
/** * @return The lowered method type. */ static ir_type *lower_method_type(ir_type *mtp) { ir_type *res = pmap_get(ir_type, lowered_type, mtp); if (res != NULL) return res; size_t const n_param = get_method_n_params(mtp); size_t const n_res = get_method_n_ress(mtp); bool const is_variadic = is_method_variadic(mtp); res = new_type_method(n_param, n_res, is_variadic); /* set param types and result types */ for (size_t i = 0; i < n_param; ++i) { ir_type *ptp = get_method_param_type(mtp, i); ir_mode *pmode = get_type_mode(ptp); if (pmode != NULL && mode_is_float(pmode)) { ptp = lower_type(ptp); } set_method_param_type(res, i, ptp); } for (size_t i = 0; i < n_res; ++i) { ir_type *rtp = get_method_res_type(mtp, i); ir_mode *rmode = get_type_mode(rtp); if (rmode != NULL && mode_is_float(rmode)) { rtp = lower_type(rtp); } set_method_res_type(res, i, rtp); } copy_method_properties(res, mtp); set_higher_type(res, mtp); pmap_insert(lowered_type, mtp, res); return res; }
void exchange_cdep(ir_node *old, const ir_node *nw) { ir_cdep *cdep = find_cdep(nw); assert(is_Block(old)); pmap_insert(cdep_data->cdep_map, old, cdep); }
// Called first from entry.S on the bootstrap processor, // and later from boot/bootother.S on all other processors. // As a rule, "init" functions in PIOS are called once on EACH processor. void init(void) { extern char start[], edata[], end[]; // Before anything else, complete the ELF loading process. // Clear all uninitialized global data (BSS) in our program, // ensuring that all static/global variables start out zero. if (cpu_onboot()) memset(edata, 0, end - edata); // Initialize the console. // Can't call cprintf until after we do this! cons_init(); extern uint8_t _binary_obj_boot_bootother_start[], _binary_obj_boot_bootother_size[]; uint8_t *code = (uint8_t*)lowmem_bootother_vec; memmove(code, _binary_obj_boot_bootother_start, (uint32_t) _binary_obj_boot_bootother_size); // Lab 1: test cprintf and debug_trace cprintf("1234 decimal is %o octal!\n", 1234); debug_check(); // Initialize and load the bootstrap CPU's GDT, TSS, and IDT. cpu_init(); trap_init(); // Physical memory detection/initialization. // Can't call mem_alloc until after we do this! mem_init(); // Lab 2: check spinlock implementation if (cpu_onboot()) spinlock_check(); // Initialize the paged virtual memory system. pmap_init(); // Find and start other processors in a multiprocessor system mp_init(); // Find info about processors in system pic_init(); // setup the legacy PIC (mainly to disable it) ioapic_init(); // prepare to handle external device interrupts lapic_init(); // setup this CPU's local APIC cpu_bootothers(); // Get other processors started // cprintf("CPU %d (%s) has booted\n", cpu_cur()->id, // cpu_onboot() ? "BP" : "AP"); file_init(); // Create root directory and console I/O files // Lab 4: uncomment this when you can handle IRQ_SERIAL and IRQ_KBD. //cons_intenable(); // Let the console start producing interrupts // Initialize the process management code. proc_init(); // Initialize the process management code. proc_init(); if(!cpu_onboot()) proc_sched(); proc *root = proc_root = proc_alloc(NULL,0); elfhdr *ehs = (elfhdr *)ROOTEXE_START; assert(ehs->e_magic == ELF_MAGIC); proghdr *phs = (proghdr *) ((void *) ehs + ehs->e_phoff); proghdr *ep = phs + ehs->e_phnum; for (; phs < ep; phs++) { if (phs->p_type != ELF_PROG_LOAD) continue; void *fa = (void *) ehs + ROUNDDOWN(phs->p_offset, PAGESIZE); uint32_t va = ROUNDDOWN(phs->p_va, PAGESIZE); uint32_t zva = phs->p_va + phs->p_filesz; uint32_t eva = ROUNDUP(phs->p_va + phs->p_memsz, PAGESIZE); uint32_t perm = SYS_READ | PTE_P | PTE_U; if(phs->p_flags & ELF_PROG_FLAG_WRITE) perm |= SYS_WRITE | PTE_W; for (; va < eva; va += PAGESIZE, fa += PAGESIZE) { pageinfo *pi = mem_alloc(); assert(pi != NULL); if(va < ROUNDDOWN(zva, PAGESIZE)) memmove(mem_pi2ptr(pi), fa, PAGESIZE); else if (va < zva && phs->p_filesz) { memset(mem_pi2ptr(pi),0, PAGESIZE); memmove(mem_pi2ptr(pi), fa, zva-va); } else memset(mem_pi2ptr(pi), 0, PAGESIZE); pte_t *pte = pmap_insert(root->pdir, pi, va, perm); assert(pte != NULL); } } root->sv.tf.eip = ehs->e_entry; root->sv.tf.eflags |= FL_IF; pageinfo *pi = mem_alloc(); assert(pi != NULL); pte_t *pte = pmap_insert(root->pdir, pi, VM_STACKHI-PAGESIZE, SYS_READ | SYS_WRITE | PTE_P | PTE_U | PTE_W); assert(pte != NULL); root->sv.tf.esp = VM_STACKHI; proc_ready(root); proc_sched(); // Initialize the I/O system. // Lab 1: change this so it enters user() in user mode, // running on the user_stack declared above, // instead of just calling user() directly. user(); // FIXME: Maybe get rid of this }