void free_page_structure(uintptr_t vaddress, uintptr_t cr3) { v_address_t va; memcpy(&va, &vaddress, 8); puint_t* pml4 = (puint_t*)ALIGN(physical_to_virtual(cr3)); if (!PRESENT(pml4[va.pml])) { return; } puint_t* pdpt = (puint_t*)ALIGN(physical_to_virtual(pml4[va.pml])); if (!PRESENT(pdpt[va.directory_ptr])) { return; } puint_t* pdir = (puint_t*)ALIGN(physical_to_virtual(pdpt[va.directory_ptr])); if (!PRESENT(pdir[va.directory])) { return; } puint_t* pt = (puint_t*)ALIGN(physical_to_virtual(pdir[va.directory])); pt[va.table] = 0; // free table entry // check for other table entries for (size_t i=0; i<512; i++) { if (pt[i] != 0) return; } free_frame(ALIGN(pdir[va.directory])); pdir[va.directory] = 0; // free pt address // check for other pdir adresses for (size_t i=0; i<512; i++) { if (pdir[i] != 0) return; } free_frame(ALIGN(pdpt[va.directory_ptr])); pdpt[va.directory_ptr] = 0; // free pdir address for (size_t i=0; i<512; i++) { if (pdpt[i] != 0) return; } free_frame(ALIGN(pml4[va.pml])); pml4[va.pml] = 0; // free pdpt address }
/** * Initializes memory mirror. * * Memory mirror allocates all available ram to specific range address. * If 1GB paging is supported, 1GB paging is used, otherwise only 4KB * paging is used, which means much more physical ram is used. */ void initialize_memory_mirror() { section_info_t* head = frame_pool; frame_pool = NULL; bool first_set = false; if (is_1GB_paging_supported() != 0) { for (puint_t start=0; start < maxram; start+=1<<30) { puint_t vaddress = start + ADDRESS_OFFSET(RESERVED_KBLOCK_RAM_MAPPINGS); v_address_t va; memcpy(&va, &vaddress, 8); puint_t* pml4 = (puint_t*)ALIGN(physical_to_virtual(get_active_page())); if (!PRESENT(pml4[va.pml])) { pdpt_t pdpt; memset(&pdpt, 0, sizeof(pdpt_t)); pdpt.number = get_free_frame(); pdpt.flaggable.present = 1; pdpt.flaggable.us = 0; pdpt.flaggable.rw = 1; pml4[va.pml] = pdpt.number; memset((void*)physical_to_virtual(ALIGN(pdpt.number)), 0, 0x1000); } puint_t* pdpt = (puint_t*)ALIGN(physical_to_virtual(pml4[va.pml])); page_directory1GB_t dir; memset(&dir, 0, sizeof(page_directory1GB_t)); dir.number = start; dir.flaggable.present = 1; dir.flaggable.ps = 1; dir.flaggable.rw = 1; pdpt[va.directory_ptr] = dir.number; if (!first_set) { first_set = true; frame_pool = head; } } } else { for (puint_t start=0; start < maxram; start+=0x1000) { puint_t kend = kernel_tmp_heap_start - 0xFFFFFFFF80000000 + 0x40000; if (kend+0x4000 >= tmp_heap && !first_set) { first_set = true; frame_pool = head; } puint_t vaddress = start + ADDRESS_OFFSET(RESERVED_KBLOCK_RAM_MAPPINGS); puint_t* paddress = get_page(vaddress, get_active_page(), true); page_t page; memset(&page, 0, sizeof(page_t)); page.address = start; page.flaggable.present = 1; page.flaggable.rw = 1; page.flaggable.us = 0; *paddress = page.address; } } }
/** * Computes virtual to physical mapping. * * Checks for page hierarchy and determines what physical address will be. * If page structures are missing on the way to decode, physical address cannot * be found and this valid will contain 0, otherwise valid will contain 1 * * 1GB page sector (ram identity map) behaves slightly different, because it * needs different v_address_t type. */ ruint_t virtual_to_physical(uintptr_t vaddress, uintptr_t cr3, uint8_t* valid) { *valid = 1; v_address_t va; memcpy(&va, &vaddress, 8); puint_t* address = (puint_t*)ALIGN(physical_to_virtual(cr3)); address = (puint_t*)ALIGN(physical_to_virtual(address[va.pml])); if (!PRESENT(address)) { *valid = 0; return 0; } if (vaddress > ADDRESS_OFFSET(RESERVED_KBLOCK_RAM_MAPPINGS) && vaddress < ADDRESS_OFFSET((RESERVED_KBLOCK_RAM_MAPPINGS+1)) && is_1GB_paging_supported()) { v_address1GB_t va = *((v_address1GB_t*) &vaddress); page_directory1GB_t pd1gb; pd1gb.number = (uint64_t) address; return pd1gb.flaggable.address + va.offset; } address = (puint_t*)ALIGN(physical_to_virtual(address[va.directory_ptr])); if (!PRESENT(address)) { *valid = 0; return 0; } address = (puint_t*)ALIGN(physical_to_virtual(address[va.directory])); if (!PRESENT(address)) { *valid = 0; return 0; } if (!PRESENT(*address)) { *valid = 0; return 0; } puint_t physadd = *address; return ALIGN(physadd) + va.offset; }
static char * set_attribute_9(TERMTYPE *tp, int flag) { const char *value; char *result; value = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag); if (PRESENT(value)) result = strdup(value); else result = 0; return result; }
/* * Improve similar_sgr a little by moving the attr-string from the beginning * to the end of the s-string. */ static bool rewrite_sgr(char *s, char *attr) { if (PRESENT(s)) { if (PRESENT(attr)) { unsigned len_s = strlen(s); unsigned len_a = strlen(attr); if (len_s > len_a && !strncmp(attr, s, len_a)) { unsigned n; TR(TRACE_DATABASE, ("rewrite:\n\t%s", s)); for (n = 0; n < len_s - len_a; ++n) { s[n] = s[n + len_a]; } strlcpy(s + n, attr, len_s - n); TR(TRACE_DATABASE, ("to:\n\t%s", s)); } } return TRUE; } return FALSE; /* oops */ }
void FLPCAL(struct STACK *a, int n) { int j; if(a!=NULL){ FLPCAL(a->L,n); if(a->data=='.'){ if(PRESENT(a->L->LP,n,1)==1) for(j=1;j<=a->R->FP[0];j++) if(PRESENT(flps[n],a->R->FP[j],1)==0){ flps[n][1]++; flps[n][flps[n][1]+1]=a->R->FP[j]; } } else if(a->data=='*'){ if(PRESENT(a->LP,n,1)==1) for(j=1;j<=a->FP[0];j++) if(PRESENT(flps[n],a->FP[j],1)==0){ flps[n][1]++; flps[n][flps[n][1]+1]=a->FP[j]; } } FLPCAL(a->R,n); } }
void util_spawn(void) { char buf[256]; $DESCRIPTOR(d_buf,buf); $DESCRIPTOR(d_ent," "); d_ent.dsc$a_pointer = "COMMAND"; d_ent.dsc$w_length = 7; if (CLI$PRESENT(&d_ent) == CLI$_PRESENT) { if (CLI$GET_VALUE(&d_ent,&d_buf) == SS$_NORMAL) lib$spawn(&d_buf); return; } d_buf.dsc$w_length = 0; lib$spawn(&d_buf); return; }
static void postprocess_terminfo(TERMTYPE * tp) { /* * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION * ---------------------------------------------------------------------- */ /* * Translate AIX forms characters. */ if (PRESENT(box_chars_1)) { char buf2[MAX_TERMCAP_LENGTH]; string_desc result; _nc_str_init(&result, buf2, sizeof(buf2)); _nc_safe_strcat(&result, acs_chars); append_acs0 (&result, 'l', box_chars_1[0]); /* ACS_ULCORNER */ append_acs0 (&result, 'q', box_chars_1[1]); /* ACS_HLINE */ append_acs0 (&result, 'k', box_chars_1[2]); /* ACS_URCORNER */ append_acs0 (&result, 'x', box_chars_1[3]); /* ACS_VLINE */ append_acs0 (&result, 'j', box_chars_1[4]); /* ACS_LRCORNER */ append_acs0 (&result, 'm', box_chars_1[5]); /* ACS_LLCORNER */ append_acs0 (&result, 'w', box_chars_1[6]); /* ACS_TTEE */ append_acs0 (&result, 'u', box_chars_1[7]); /* ACS_RTEE */ append_acs0 (&result, 'v', box_chars_1[8]); /* ACS_BTEE */ append_acs0 (&result, 't', box_chars_1[9]); /* ACS_LTEE */ append_acs0 (&result, 'n', box_chars_1[10]); /* ACS_PLUS */ if (buf2[0]) { acs_chars = _nc_save_str(buf2); _nc_warning("acsc string synthesized from AIX capabilities"); box_chars_1 = ABSENT_STRING; } } /* * ---------------------------------------------------------------------- */ }
_nc_trim_sgr0(TERMTYPE *tp) { char *result = exit_attribute_mode; T((T_CALLED("_nc_trim_sgr0()"))); if (PRESENT(exit_attribute_mode) && PRESENT(set_attributes)) { bool found = FALSE; char *on = set_attribute_9(tp, 1); char *off = set_attribute_9(tp, 0); char *end = strdup(exit_attribute_mode); char *tmp; size_t i, j, k; TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr")); TR(TRACE_DATABASE, ("sgr0 %s", _nc_visbuf(end))); TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off))); TR(TRACE_DATABASE, ("sgr(9:on) %s", _nc_visbuf(on))); if (!rewrite_sgr(on, enter_alt_charset_mode) || !rewrite_sgr(off, exit_alt_charset_mode) || !rewrite_sgr(end, exit_alt_charset_mode)) { FreeIfNeeded(off); } else if (similar_sgr(off, end) && !similar_sgr(off, on)) { TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off))); result = off; /* * If rmacs is a substring of sgr(0), remove that chunk. */ if (exit_alt_charset_mode != 0) { TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode))); j = strlen(off); k = strlen(exit_alt_charset_mode); if (j > k) { for (i = 0; i <= (j - k); ++i) { unsigned k2 = compare_part(exit_alt_charset_mode, off + i); if (k2 != 0) { found = TRUE; chop_out(off, (unsigned) i, (unsigned) (i + k2)); break; } } } } /* * SGR 10 would reset to normal font. */ if (!found) { if ((i = (size_t) is_csi(off)) != 0 && off[strlen(off) - 1] == 'm') { TR(TRACE_DATABASE, ("looking for SGR 10 in %s", _nc_visbuf(off))); tmp = skip_zero(off + i); if (tmp[0] == '1' && skip_zero(tmp + 1) != tmp + 1) { i = (size_t) (tmp - off); if (off[i - 1] == ';') i--; j = (size_t) (skip_zero(tmp + 1) - off); (void) chop_out(off, (unsigned) i, (unsigned) j); found = TRUE; } } } if (!found && (tmp = strstr(end, off)) != 0 && strcmp(end, off) != 0) { i = (size_t) (tmp - end); j = strlen(off); tmp = strdup(end); chop_out(tmp, (unsigned) i, (unsigned) j); free(off); result = tmp; } TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result))); if (!strcmp(result, exit_attribute_mode)) { TR(TRACE_DATABASE, ("...same result, discard")); free(result); result = exit_attribute_mode; } } else { /* * Either the sgr does not reference alternate character set, * or it is incorrect. That's too hard to decide right now. */ free(off); } FreeIfNeeded(end); FreeIfNeeded(on); } else { /* * Possibly some applications are confused if sgr0 contains rmacs, * but that would be a different bug report -TD */ } returnPtr(result); }
/** * Called when a pagefault occurs, is in charge of fixing the fault and swapping * if necessary. */ void cPageFault(isrVal_t registers) { addr_t page = getCR2(); addr_t page_addr = page & ~(0xFFF); #ifdef PAGEDBG printf("PG!\n"); printf("Fault addr: %X\nPage index: %X\n", page, page_addr); printf("Fault type: %X\n", registers.errCode); printf("EIP: %X\nESP: %X\nESP: %X\n", registers.eip, registers.procesp, registers.esp); printf("eax: %X\tebx: %X\necx: %X\tedx: %X\n", registers.eax, registers.ebx, registers.ecx, registers.edx); #endif if (registers.cs != 0x8 && registers.cs != 0x18) panic("Incorrect frame!"); if (USER(registers.errCode)) panic("Userspace isn't implemented yet!"); if (RESERVED(registers.errCode)) panic("A reserved bit has been set!\n"); if (PRESENT(registers.errCode)) panic("Illegal operation!"); addr_t pd = getPageDir(); /** * The data bit only works if a specific bit is set. See intel docs volume 3 * for more information. */ if (DATA(registers.errCode)) { #ifdef PAGEDBG printf("Trying to access unimplemented data!\n"); #endif if (WRITE(registers.errCode)) { #ifdef PAGEDBG printf("Faulted a write attempt!\n"); printf("Adding page!\n"); #endif if (USER(registers.errCode)) { //Add a user page! } else { #ifdef PAGEDBG printf("Adding a kernel page!\n"); #endif if (idx_kernel_space == MAP_NOMAP) panic("Kernel page map not correctly initialised!"); int ret = page_alloc_page (idx_kernel_space, page_addr, (void*)pd, FALSE); if (ret != -E_SUCCESS) { printf("ERRCODE: %X\n", -ret); panic("Couldn't alloc page!"); } #ifdef PAGEDBG printf("Phys of %X = %X\n", page, page_phys_addr(page, (void*)pd)); #endif } } else { #ifdef PAGEDBG printf("Faulted a read attempt!\n"); #endif // Assume the page may be read! if (idx_kernel_space == MAP_NOMAP) panic("Kernel page map not correctly initialised!"); int ret = page_alloc_page(idx_kernel_space, page_addr, (void*)pd, FALSE); if (ret != -E_SUCCESS) { printf("ERRCODE: %X\n", -ret); panic("Couldn't alloc page!"); } #ifdef PAGEDBG printf("Phys of %X = %X\n", page, page_phys_addr(page, (void*)pd)); #endif } } else { #ifdef PAGEDBG panic("Trying to run unimplemented code!\n"); #endif } #ifdef UNDEFINED printf("Page faults currently under construction!\n"); #endif }
static void postprocess_termcap(TERMTYPE * tp, bool has_base) { char buf[MAX_LINE * 2 + 2]; string_desc result; /* * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS * * This first part of the code is the functional inverse of the * fragment in capdefaults.c. * ---------------------------------------------------------------------- */ /* if there was a tc entry, assume we picked up defaults via that */ if (!has_base) { if (WANTED(init_3string) && termcap_init2) init_3string = _nc_save_str(termcap_init2); if (WANTED(reset_2string) && termcap_reset) reset_2string = _nc_save_str(termcap_reset); if (WANTED(carriage_return)) { if (carriage_return_delay > 0) { sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay); carriage_return = _nc_save_str(buf); } else carriage_return = _nc_save_str(C_CR); } if (WANTED(cursor_left)) { if (backspace_delay > 0) { sprintf(buf, "%s$<%d>", C_BS, backspace_delay); cursor_left = _nc_save_str(buf); } else if (backspaces_with_bs == 1) cursor_left = _nc_save_str(C_BS); else if (PRESENT(backspace_if_not_bs)) cursor_left = backspace_if_not_bs; } /* vi doesn't use "do", but it does seems to use nl (or '\n') instead */ if (WANTED(cursor_down)) { if (PRESENT(linefeed_if_not_lf)) cursor_down = linefeed_if_not_lf; else if (linefeed_is_newline != 1) { if (new_line_delay > 0) { sprintf(buf, "%s$<%d>", C_LF, new_line_delay); cursor_down = _nc_save_str(buf); } else cursor_down = _nc_save_str(C_LF); } } if (WANTED(scroll_forward) && crt_no_scrolling != 1) { if (PRESENT(linefeed_if_not_lf)) cursor_down = linefeed_if_not_lf; else if (linefeed_is_newline != 1) { if (new_line_delay > 0) { sprintf(buf, "%s$<%d>", C_LF, new_line_delay); scroll_forward = _nc_save_str(buf); } else scroll_forward = _nc_save_str(C_LF); } } if (WANTED(newline)) { if (linefeed_is_newline == 1) { if (new_line_delay > 0) { sprintf(buf, "%s$<%d>", C_LF, new_line_delay); newline = _nc_save_str(buf); } else newline = _nc_save_str(C_LF); } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) { _nc_str_init(&result, buf, sizeof(buf)); if (_nc_safe_strcat(&result, carriage_return) && _nc_safe_strcat(&result, scroll_forward)) newline = _nc_save_str(buf); } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) { _nc_str_init(&result, buf, sizeof(buf)); if (_nc_safe_strcat(&result, carriage_return) && _nc_safe_strcat(&result, cursor_down)) newline = _nc_save_str(buf); } } } /* * Inverse of capdefaults.c code ends here. * ---------------------------------------------------------------------- * * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION * * These translations will *not* be inverted by tgetent(). */ if (!has_base) { /* * We wait until now to decide if we've got a working cr because even * one that doesn't work can be used for newline. Unfortunately the * space allocated for it is wasted. */ if (return_does_clr_eol == 1 || no_correctly_working_cr == 1) carriage_return = ABSENT_STRING; /* * Supposedly most termcap entries have ta now and '\t' is no longer a * default, but it doesn't seem to be true... */ if (WANTED(tab)) { if (horizontal_tab_delay > 0) { sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay); tab = _nc_save_str(buf); } else tab = _nc_save_str(C_HT); } if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE) init_tabs = 8; /* * Assume we can beep with ^G unless we're given bl@. */ if (WANTED(bell)) bell = _nc_save_str("\007"); } /* * Translate the old termcap :pt: capability to it#8 + ht=\t */ if (has_hardware_tabs == TRUE) { if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC) _nc_warning("hardware tabs with a width other than 8: %d", init_tabs); else { if (tab && _nc_capcmp(tab, C_HT)) _nc_warning("hardware tabs with a non-^I tab string %s", _nc_visbuf(tab)); else { if (WANTED(tab)) tab = _nc_save_str(C_HT); init_tabs = 8; } } } /* * Now translate the ko capability, if there is one. This * isn't from mytinfo... */ if (PRESENT(other_non_function_keys)) { char *base = other_non_function_keys; char *bp, *cp, *dp; struct name_table_entry const *from_ptr; struct name_table_entry const *to_ptr; assoc const *ap; char buf2[MAX_TERMINFO_LENGTH]; bool foundim; /* we're going to use this for a special case later */ dp = strchr(other_non_function_keys, 'i'); foundim = (dp != 0) && (dp[1] == 'm'); /* look at each comma-separated capability in the ko string... */ for (base = other_non_function_keys; (cp = strchr(base, ',')) != 0; base = cp + 1) { size_t len = cp - base; for (ap = ko_xlate; ap->from; ap++) if (len == strlen(ap->from) && strncmp(ap->from, base, len) == 0) break; if (!ap->to) { _nc_warning("unknown capability `%.*s' in ko string", (int) len, base); continue; } else if (ap->to == CANCELLED_STRING) /* ignore it */ continue; /* now we know we found a match in ko_table, so... */ from_ptr = _nc_find_entry(ap->from, _nc_cap_hash_table); to_ptr = _nc_find_entry(ap->to, _nc_info_hash_table); if (!from_ptr || !to_ptr) /* should never happen! */ _nc_err_abort("ko translation table is invalid, I give up"); if (WANTED(tp->Strings[from_ptr->nte_index])) { _nc_warning("no value for ko capability %s", ap->from); continue; } if (tp->Strings[to_ptr->nte_index]) { /* There's no point in warning about it if it's the same * string; that's just an inefficiency. */ if (strcmp( tp->Strings[from_ptr->nte_index], tp->Strings[to_ptr->nte_index]) != 0) _nc_warning("%s (%s) already has an explicit value %s, ignoring ko", ap->to, ap->from, _nc_visbuf(tp->Strings[to_ptr->nte_index])); continue; } /* * The magic moment -- copy the mapped key string over, * stripping out padding. */ for (dp = buf2, bp = tp->Strings[from_ptr->nte_index]; *bp; bp++) { if (bp[0] == '$' && bp[1] == '<') { while (*bp && *bp != '>') { ++bp; } } else *dp++ = *bp; } *dp++ = '\0'; tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2); } /* * Note: ko=im and ko=ic both want to grab the `Insert' * keycap. There's a kich1 but no ksmir, so the ic capability * got mapped to kich1 and im to kIC to avoid a collision. * If the description has im but not ic, hack kIC back to kich1. */ if (foundim && WANTED(key_ic) && key_sic) { key_ic = key_sic; key_sic = ABSENT_STRING; } } if (!hard_copy) { if (WANTED(key_backspace)) key_backspace = _nc_save_str(C_BS); if (WANTED(key_left)) key_left = _nc_save_str(C_BS); if (WANTED(key_down)) key_down = _nc_save_str(C_LF); } /* * Translate XENIX forms characters. */ if (PRESENT(acs_ulcorner) || PRESENT(acs_llcorner) || PRESENT(acs_urcorner) || PRESENT(acs_lrcorner) || PRESENT(acs_ltee) || PRESENT(acs_rtee) || PRESENT(acs_btee) || PRESENT(acs_ttee) || PRESENT(acs_hline) || PRESENT(acs_vline) || PRESENT(acs_plus)) { char buf2[MAX_TERMCAP_LENGTH]; _nc_str_init(&result, buf2, sizeof(buf2)); _nc_safe_strcat(&result, acs_chars); append_acs (&result, 'j', acs_lrcorner); append_acs (&result, 'k', acs_urcorner); append_acs (&result, 'l', acs_ulcorner); append_acs (&result, 'm', acs_llcorner); append_acs (&result, 'n', acs_plus); append_acs (&result, 'q', acs_hline); append_acs (&result, 't', acs_ltee); append_acs (&result, 'u', acs_rtee); append_acs (&result, 'v', acs_btee); append_acs (&result, 'w', acs_ttee); append_acs (&result, 'x', acs_vline); if (buf2[0]) { acs_chars = _nc_save_str(buf2); _nc_warning("acsc string synthesized from XENIX capabilities"); } } else if (acs_chars == 0 && enter_alt_charset_mode != 0 && exit_alt_charset_mode != 0) { acs_chars = _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"); } }
/** * Returns page allocated for that virtual address. * * If allocate_new is specified to true, it will allocate substructures, * if not present.Otherwise returns NULL if page structures are not present * on the way to the virtual address. Returned pointer points to page in page * table. */ static puint_t* __get_page(uintptr_t vaddress, uintptr_t cr3, bool allocate_new, bool user) { v_address_t va; memcpy(&va, &vaddress, 8); puint_t* pml4 = (puint_t*)ALIGN(physical_to_virtual(cr3)); if (!PRESENT(pml4[va.pml])) { if (!allocate_new) { return 0; } pdpt_t pdpt; memset(&pdpt, 0, sizeof(pdpt_t)); pdpt.number = get_free_frame(); if (pdpt.number == 0) return 0; pdpt.flaggable.present = 1; pdpt.flaggable.us = user; pdpt.flaggable.rw = 1; pml4[va.pml] = pdpt.number; memset((void*)physical_to_virtual(ALIGN(pdpt.number)), 0, 0x1000); } puint_t* pdpt = (puint_t*)ALIGN(physical_to_virtual(pml4[va.pml])); if (!PRESENT(pdpt[va.directory_ptr])) { if (!allocate_new) return 0; page_directory_t dir; memset(&dir, 0, sizeof(page_directory_t)); dir.number = get_free_frame(); if (dir.number == 0) { return 0; } dir.flaggable.present = 1; dir.flaggable.us = user; dir.flaggable.rw = 1; pdpt[va.directory_ptr] = dir.number; memset((void*)physical_to_virtual(ALIGN(dir.number)), 0, 0x1000); } puint_t* pdir = (puint_t*)ALIGN(physical_to_virtual(pdpt[va.directory_ptr])); if (!PRESENT(pdir[va.directory])) { if (!allocate_new) return 0; page_table_t pt; memset(&pt, 0, sizeof(page_table_t)); pt.number = get_free_frame(); if (pt.number == 0) { return 0; } pt.flaggable.present = 1; pt.flaggable.us = user; pt.flaggable.rw = 1; pdir[va.directory] = pt.number; memset((void*)physical_to_virtual(ALIGN(pt.number)), 0, 0x1000); } puint_t* pt = (puint_t*)ALIGN(physical_to_virtual(pdir[va.directory])); return &pt[va.table]; }
OBJECT * vmm_vaddr_to_memobj(PROCESS *prp, void *addr, unsigned *offset, int mark_page) { uint32_t *pde; uint32_t pte; unsigned pg_offset; paddr_t paddr; uintptr_t vaddr = (uintptr_t)addr; ADDRESS *adp; unsigned mask; /* piece of cake for P1, P2 addresses */ if(SH_IS_P1(vaddr) || SH_IS_P2(vaddr)) { // Assuming P1 & P2 are the same size paddr = vaddr & (SH_P1SIZE - 1); *offset = PADDR_TO_SYNC_OFF(paddr); return PADDR_TO_SYNC_OBJ(paddr); } pg_offset = ADDR_OFFSET(vaddr); // Check for system, cpu pages... if(ADDR_PAGE(vaddr) == SYSP_ADDCOLOR(VM_CPUPAGE_ADDR, SYSP_GETCOLOR(_cpupage_ptr))) { paddr = SH_P1_TO_PHYS((uintptr_t)_cpupage_ptr) | pg_offset; *offset = PADDR_TO_SYNC_OFF(paddr); return PADDR_TO_SYNC_OBJ(paddr); } if(ADDR_PAGE(vaddr) == SYSP_ADDCOLOR(VM_SYSPAGE_ADDR, SYSP_GETCOLOR(_syspage_ptr))) { paddr = SH_P1_TO_PHYS((uintptr_t)_syspage_ptr) | pg_offset; *offset = PADDR_TO_SYNC_OFF(paddr); return PADDR_TO_SYNC_OBJ(paddr); } #ifndef NDEBUG if(prp == NULL) crash(); #endif adp = prp->memory; #ifndef NDEBUG if(adp == NULL) crash(); #endif pde = adp->cpu.pgdir[L1PAGEIDX(vaddr)]; if((pde == NULL) || !PRESENT((pte = pde[L2PAGEIDX(vaddr)]))) { /* not mapped, check for perm mappings */ goto fail; } mask = SH_PTE_PGSIZE_MASK(pte); paddr = (pte & mask) | (vaddr & ~mask); if(mark_page) { struct pa_quantum *pq; pq = pa_paddr_to_quantum(paddr); if(pq != NULL) { pq->flags |= PAQ_FLAG_HAS_SYNC; } } *offset = PADDR_TO_SYNC_OFF(paddr); return PADDR_TO_SYNC_OBJ(paddr); fail: #ifndef NDEBUG crash(); /* NOTREACHED */ #endif return (OBJECT *)-1; }
void DFA() { int i,j,k,l,m,fg,find; int tmp[10], newn[10]; node[0][0]=1; node[1][0]='A'; node[1][1]=0; for(i=1;i<=O->D->FP[0];i++){ node[1][1]++; node[1][node[1][1]+1]=O->D->FP[i]; } DF[0][0]=var-1; for(i=1;i<var;i++) DF[0][i]=position[i-1][0]; for(i=1;i<=node[0][0];i++){ DF[i][0]=node[i][0]; for(j=1;j<=DF[0][0];j++){ tmp[0]=0; newn[0]=0; for(k=2;k<=node[i][1]+1;k++){ if(PRESENT(position[j-1],node[i][k],2)==1) tmp[++tmp[0]]=node[i][k]; for(l=1;l<=tmp[0];l++){ for(m=2;m<=flps[tmp[l]][1]+1;m++) if(PRESENT(newn,flps[tmp[l]][m],1)==0){ newn[0]++; newn[newn[0]]=flps[tmp[l]][m]; } } } printf(" "); fg=0; for(l=1;l<=node[0][0];l++){ find=0; if(newn[0]==node[l][1]) for(k=1;k<=newn[0];k++) if(PRESENT(node[l],newn[k],2)==0) fg=1; else find++; if(find==newn[0]&&find!=0) goto l1; } if(newn[0]==0){ DF[i][j]='-'; goto l2; } node[0][0]++; node[node[0][0]][0]=node[node[0][0]-1][0]+1; for(m=0;m<=newn[0];m++) node[node[0][0]][m+1]=newn[m]; DF[i][j]=node[node[0][0]][0]; goto l2; l1: DF[i][j]=node[l][0]; l2: if(fg==1||fg==0) printf(" "); } } printf("\n\nNODES:\n\n"); for(i=1;i<=node[0][0];i++,printf("\n\n")) for(j=0;j<=node[i][1]+1;j++) if(j==0) printf(" %c ",node[i][j]); else if(j==1) printf(" => "); else printf(" %d ",node[i][j]); printf("\n\nDFA TABLE:\n\n"); for(i=0;i<=node[0][0];i++,printf("\n\n")) for(j=0;j<=DF[0][0];j++) if(i==0&&j==0) printf(" "); else printf("%4c",DF[i][j]); }
void FP_LP_CAL(struct STACK *a) { if(a!=NULL){ int i, flg; FP_LP_CAL(a->L); FP_LP_CAL(a->R); if(a->data!='+'&&a->data!='.'&&a->data!='*'){ a->FP[0]++; a->LP[0]++; a->FP[a->FP[0]]=terp; a->LP[a->LP[0]]=terp++; flg=0; for(i=0;i<var;i++) if(position[i][0]==a->data){ position[i][1]++; position[i][position[i][1]+1]=terp-1; flg=1; } if(flg==0){ position[var++][1]=1; position[var-1][2]=terp-1; position[var-1][0]=a->data; } } else if(a->data=='+'){ for(i=1;i<=a->L->FP[0];i++){ a->FP[0]++; a->FP[a->FP[0]]=a->L->FP[i]; } for(i=1;i<=a->R->FP[0];i++){ if(PRESENT(a->FP, a->R->FP[i],1)==0){ a->FP[0]++; a->FP[a->FP[0]]=a->R->FP[i]; } } for(i=1;i<=a->L->LP[0];i++){ a->LP[0]++; a->LP[a->LP[0]]=a->L->LP[i]; } for(i=1;i<=a->R->LP[0];i++) if(PRESENT(a->LP, a->R->LP[i], 1)==0){ a->LP[0]++; a->LP[a->LP[0]]=a->R->LP[i]; } } else if(a->data=='*'){ for(i=1;i<=a->L->FP[0];i++){ a->FP[0]++; a->FP[a->FP[0]]=a->L->FP[i]; } for(i=1;i<=a->L->LP[0];i++){ a->LP[0]++; a->LP[a->LP[0]]=a->L->LP[i]; } } else if(a->data=='.'){ //firstpos for(i=1;i<=a->L->FP[0];i++){ a->FP[0]++; a->FP[a->FP[0]]=a->L->FP[i]; } if(a->L->data=='*') for(i=1;i<=a->R->FP[0];i++) if(PRESENT(a->FP, a->R->FP[i],1)==0){ a->FP[0]++; a->FP[a->FP[0]]=a->R->FP[i]; } //lastpos for(i=1;i<=a->R->LP[0];i++){ a->LP[0]++; a->LP[a->LP[0]]=a->R->LP[i]; } if(a->R->data=='*') for(i=1;i<=a->L->LP[0];i++) if(PRESENT(a->LP,a->L->LP[i],1)==0){ a->LP[0]++; a->LP[a->LP[0]]=a->L->LP[i]; } } } }
static void postprocess_terminfo(TERMTYPE *tp) { /* * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION * ---------------------------------------------------------------------- */ /* * Translate AIX forms characters. */ if (PRESENT(box_chars_1)) { char buf2[MAX_TERMCAP_LENGTH], *bp = buf2; if (acs_chars) { (void)strcpy(bp, acs_chars); bp += strlen(bp); } if (box_chars_1[0]) /* ACS_ULCORNER */ { *bp++ = 'l'; *bp++ = box_chars_1[0]; } if (box_chars_1[1]) /* ACS_HLINE */ { *bp++ = 'q'; *bp++ = box_chars_1[1]; } if (box_chars_1[2]) /* ACS_URCORNER */ { *bp++ = 'k'; *bp++ = box_chars_1[2]; } if (box_chars_1[3]) /* ACS_VLINE */ { *bp++ = 'x'; *bp++ = box_chars_1[3]; } if (box_chars_1[4]) /* ACS_LRCORNER */ { *bp++ = 'j'; *bp++ = box_chars_1[4]; } if (box_chars_1[5]) /* ACS_LLCORNER */ { *bp++ = 'm'; *bp++ = box_chars_1[5]; } if (box_chars_1[6]) /* ACS_TTEE */ { *bp++ = 'w'; *bp++ = box_chars_1[6]; } if (box_chars_1[7]) /* ACS_RTEE */ { *bp++ = 'u'; *bp++ = box_chars_1[7]; } if (box_chars_1[8]) /* ACS_BTEE */ { *bp++ = 'v'; *bp++ = box_chars_1[8]; } if (box_chars_1[9]) /* ACS_LTEE */ { *bp++ = 't'; *bp++ = box_chars_1[9]; } if (box_chars_1[10]) /* ACS_PLUS */ { *bp++ = 'n'; *bp++ = box_chars_1[10]; } if (bp != buf2) { *bp++ = '\0'; acs_chars = _nc_save_str(buf2); _nc_warning("acsc string synthesized from AIX capabilities"); box_chars_1 = ABSENT_STRING; } } /* * ---------------------------------------------------------------------- */ }