//allocate memory void *malloc(size_t size){ t_block newBlock, last; size_t newSize = align8(size); if(base){ last = (t_block) base; newBlock = find_block(&last, newSize); if(newBlock){ //can we split if((newBlock->size - newSize) >= (OFFSET + PTR_SIZE)){ split_block(newBlock, newSize); } newBlock->block_free = false; } else { //Can't find block, try extending the heap newBlock = extend_heap(last, newSize); if(!newBlock){ //cannot extend heap return 0x0; } } } else { //first call newBlock = extend_heap(0x0, newSize); if(!newBlock){ //failed to extend return 0x0; } base = newBlock; } return newBlock->data; }
inline object *factorvm::allot_zone(zone *z, cell a) { cell h = z->here; z->here = h + align8(a); object *obj = (object *)h; allot_barrier(obj); return obj; }
/* create a block, mark it as free */ BlockPrefix_t *makeFreeBlock(void *addr, size_t size) { BlockPrefix_t *p = addr; void *limitAddr = addr + size; BlockSuffix_t *s = limitAddr - align8(sizeof(BlockSuffix_t)); p->suffix = s; s->prefix = p; p->allocated = 0; return p; }
callback *callback_heap::add(code_block *compiled) { tagged<array> code_template(parent->userenv[CALLBACK_STUB]); tagged<byte_array> insns(array_nth(code_template.untagged(),0)); cell size = array_capacity(insns.untagged()); cell bump = align8(size) + sizeof(callback); if(here + bump > seg->end) fatal_error("Out of callback space",0); callback *stub = (callback *)here; stub->compiled = compiled; memcpy(stub + 1,insns->data<void>(),size); stub->size = align8(size); here += bump; update(stub); return stub; }
/* * It is up to the caller to fill in the object's fields in a meaningful * fashion! */ inline object *factorvm::allot_object(header header, cell size) { #ifdef GC_DEBUG if(!gc_off) gc(); #endif object *obj; if(nursery.size - allot_buffer_zone > size) { /* If there is insufficient room, collect the nursery */ if(nursery.here + allot_buffer_zone + size > nursery.end) garbage_collection(data->nursery(),false,0); cell h = nursery.here; nursery.here = h + align8(size); obj = (object *)h; } /* If the object is bigger than the nursery, allocate it in tenured space */ else { zone *tenured = &data->generations[data->tenured()]; /* If tenured space does not have enough room, collect */ if(tenured->here + size > tenured->end) { gc(); tenured = &data->generations[data->tenured()]; } /* If it still won't fit, grow the heap */ if(tenured->here + size > tenured->end) { garbage_collection(data->tenured(),true,size); tenured = &data->generations[data->tenured()]; } obj = allot_zone(tenured,size); /* Allows initialization code to store old->new pointers without hitting the write barrier in the common case of a nursery allocation */ write_barrier(obj); } obj->h = header; return obj; }
void *nextFitAllocRegion(size_t s) { size_t asize = align8(s); BlockPrefix_t *p; if (arenaBegin == 0) /* arena uninitialized? */ initializeArena(); p = findNextFit(s); /* find a block */ if (p) { /* found a block */ size_t availSize = computeUsableSpace(p); if (availSize >= (asize + prefixSize + suffixSize + 8)) { /* split block? */ void *freeSliverStart = (void *)p + prefixSize + suffixSize + asize; void *freeSliverEnd = computeNextPrefixAddr(p); makeFreeBlock(freeSliverStart, freeSliverEnd - freeSliverStart); makeFreeBlock(p, freeSliverStart - (void *)p); /* piece being allocated */ } p->allocated = 1; /* mark as allocated */ return prefixToRegion(p); /* convert to *region */ } else { /* failed */ return (void *)0; } }
RBBIDataHeader *RBBIRuleBuilder::flattenData() { int32_t i; if (U_FAILURE(*fStatus)) { return NULL; } // Remove comments and whitespace from the rules to make it smaller. UnicodeString strippedRules((const UnicodeString&)RBBIRuleScanner::stripRules(fRules)); // Calculate the size of each section in the data. // Sizes here are padded up to a multiple of 8 for better memory alignment. // Sections sizes actually stored in the header are for the actual data // without the padding. // int32_t headerSize = align8(sizeof(RBBIDataHeader)); int32_t forwardTableSize = align8(fForwardTables->getTableSize()); int32_t reverseTableSize = align8(fReverseTables->getTableSize()); int32_t safeFwdTableSize = align8(fSafeFwdTables->getTableSize()); int32_t safeRevTableSize = align8(fSafeRevTables->getTableSize()); int32_t trieSize = align8(fSetBuilder->getTrieSize()); int32_t statusTableSize = align8(fRuleStatusVals->size() * sizeof(int32_t)); int32_t rulesSize = align8((strippedRules.length()+1) * sizeof(UChar)); int32_t totalSize = headerSize + forwardTableSize + reverseTableSize + safeFwdTableSize + safeRevTableSize + statusTableSize + trieSize + rulesSize; RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize); if (data == NULL) { *fStatus = U_MEMORY_ALLOCATION_ERROR; return NULL; } uprv_memset(data, 0, totalSize); data->fMagic = 0xb1a0; data->fFormatVersion[0] = 3; data->fFormatVersion[1] = 1; data->fFormatVersion[2] = 0; data->fFormatVersion[3] = 0; data->fLength = totalSize; data->fCatCount = fSetBuilder->getNumCharCategories(); data->fFTable = headerSize; data->fFTableLen = forwardTableSize; data->fRTable = data->fFTable + forwardTableSize; data->fRTableLen = reverseTableSize; data->fSFTable = data->fRTable + reverseTableSize; data->fSFTableLen = safeFwdTableSize; data->fSRTable = data->fSFTable + safeFwdTableSize; data->fSRTableLen = safeRevTableSize; data->fTrie = data->fSRTable + safeRevTableSize; data->fTrieLen = fSetBuilder->getTrieSize(); data->fStatusTable = data->fTrie + trieSize; data->fStatusTableLen= statusTableSize; data->fRuleSource = data->fStatusTable + statusTableSize; data->fRuleSourceLen = strippedRules.length() * sizeof(UChar); uprv_memset(data->fReserved, 0, sizeof(data->fReserved)); fForwardTables->exportTable((uint8_t *)data + data->fFTable); fReverseTables->exportTable((uint8_t *)data + data->fRTable); fSafeFwdTables->exportTable((uint8_t *)data + data->fSFTable); fSafeRevTables->exportTable((uint8_t *)data + data->fSRTable); fSetBuilder->serializeTrie ((uint8_t *)data + data->fTrie); int32_t *ruleStatusTable = (int32_t *)((uint8_t *)data + data->fStatusTable); for (i=0; i<fRuleStatusVals->size(); i++) { ruleStatusTable[i] = fRuleStatusVals->elementAti(i); } strippedRules.extract((UChar *)((uint8_t *)data+data->fRuleSource), rulesSize/2+1, *fStatus); return data; }
RBBIDataHeader *RBBIRuleBuilder::flattenData() { int32_t i; if (U_FAILURE(*fStatus)) { return NULL; } // Remove comments and whitespace from the rules to make it smaller. UnicodeString strippedRules((const UnicodeString&)RBBIRuleScanner::stripRules(fRules)); // Calculate the size of each section in the data. // Sizes here are padded up to a multiple of 8 for better memory alignment. // Sections sizes actually stored in the header are for the actual data // without the padding. // int32_t headerSize = align8(sizeof(RBBIDataHeader)); int32_t forwardTableSize = align8(fForwardTables->getTableSize()); int32_t reverseTableSize = align8(fReverseTables->getTableSize()); int32_t safeFwdTableSize = align8(fSafeFwdTables->getTableSize()); int32_t safeRevTableSize = align8(fSafeRevTables->getTableSize()); int32_t trieSize = align8(fSetBuilder->getTrieSize()); int32_t statusTableSize = align8(fRuleStatusVals->size() * sizeof(int32_t)); int32_t rulesSize = align8((strippedRules.length()+1) * sizeof(UChar)); (void)safeFwdTableSize; int32_t totalSize = headerSize + forwardTableSize + /* reverseTableSize */ 0 + /* safeFwdTableSize */ 0 + (safeRevTableSize ? safeRevTableSize : reverseTableSize) + statusTableSize + trieSize + rulesSize; RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize); if (data == NULL) { *fStatus = U_MEMORY_ALLOCATION_ERROR; return NULL; } uprv_memset(data, 0, totalSize); data->fMagic = 0xb1a0; data->fFormatVersion[0] = RBBI_DATA_FORMAT_VERSION[0]; data->fFormatVersion[1] = RBBI_DATA_FORMAT_VERSION[1]; data->fFormatVersion[2] = RBBI_DATA_FORMAT_VERSION[2]; data->fFormatVersion[3] = RBBI_DATA_FORMAT_VERSION[3]; data->fLength = totalSize; data->fCatCount = fSetBuilder->getNumCharCategories(); // Only save the forward table and the safe reverse table, // because these are the only ones used at run-time. // // For the moment, we still build the other tables if they are present in the rule source files, // for backwards compatibility. Old rule files need to work, and this is the simplest approach. // // Additional backwards compatibility consideration: if no safe rules are provided, consider the // reverse rules to actually be the safe reverse rules. data->fFTable = headerSize; data->fFTableLen = forwardTableSize; // Do not save Reverse Table. data->fRTable = data->fFTable + forwardTableSize; data->fRTableLen = 0; // Do not save the Safe Forward table. data->fSFTable = data->fRTable + 0; data->fSFTableLen = 0; data->fSRTable = data->fSFTable + 0; if (safeRevTableSize > 0) { data->fSRTableLen = safeRevTableSize; } else if (reverseTableSize > 0) { data->fSRTableLen = reverseTableSize; } else { U_ASSERT(FALSE); // Rule build should have failed for lack of a reverse table // before reaching this point. } data->fTrie = data->fSRTable + data->fSRTableLen; data->fTrieLen = fSetBuilder->getTrieSize(); data->fStatusTable = data->fTrie + trieSize; data->fStatusTableLen= statusTableSize; data->fRuleSource = data->fStatusTable + statusTableSize; data->fRuleSourceLen = strippedRules.length() * sizeof(UChar); uprv_memset(data->fReserved, 0, sizeof(data->fReserved)); fForwardTables->exportTable((uint8_t *)data + data->fFTable); // fReverseTables->exportTable((uint8_t *)data + data->fRTable); // fSafeFwdTables->exportTable((uint8_t *)data + data->fSFTable); if (safeRevTableSize > 0) { fSafeRevTables->exportTable((uint8_t *)data + data->fSRTable); } else { fReverseTables->exportTable((uint8_t *)data + data->fSRTable); } fSetBuilder->serializeTrie ((uint8_t *)data + data->fTrie); int32_t *ruleStatusTable = (int32_t *)((uint8_t *)data + data->fStatusTable); for (i=0; i<fRuleStatusVals->size(); i++) { ruleStatusTable[i] = fRuleStatusVals->elementAti(i); } strippedRules.extract((UChar *)((uint8_t *)data+data->fRuleSource), rulesSize/2+1, *fStatus); return data; }
static int jz_lcd_hw_init(vidinfo_t *vid) { struct jz_fb_info *fbi = &vid->jz_fb; unsigned int val = 0; unsigned int pclk; unsigned int stnH; #if defined(CONFIG_MIPS_JZ4740) int pll_div; #endif /* Setting Control register */ switch (jzfb.bpp) { case 1: val |= LCD_CTRL_BPP_1; break; case 2: val |= LCD_CTRL_BPP_2; break; case 4: val |= LCD_CTRL_BPP_4; break; case 8: val |= LCD_CTRL_BPP_8; break; case 15: val |= LCD_CTRL_RGB555; case 16: val |= LCD_CTRL_BPP_16; break; #if defined(CONFIG_MIPS_JZ4740) case 17 ... 32: val |= LCD_CTRL_BPP_18_24; /* target is 4bytes/pixel */ break; #endif default: printf("jz_lcd.c The BPP %d is not supported\n", jzfb.bpp); val |= LCD_CTRL_BPP_16; break; } switch (jzfb.cfg & MODE_MASK) { case MODE_STN_MONO_DUAL: case MODE_STN_COLOR_DUAL: case MODE_STN_MONO_SINGLE: case MODE_STN_COLOR_SINGLE: switch (jzfb.bpp) { case 1: /* val |= LCD_CTRL_PEDN; */ case 2: val |= LCD_CTRL_FRC_2; break; case 4: val |= LCD_CTRL_FRC_4; break; case 8: default: val |= LCD_CTRL_FRC_16; break; } break; } val |= LCD_CTRL_BST_16; /* Burst Length is 16WORD=64Byte */ val |= LCD_CTRL_OFUP; /* OutFIFO underrun protect */ switch (jzfb.cfg & MODE_MASK) { case MODE_STN_MONO_DUAL: case MODE_STN_COLOR_DUAL: case MODE_STN_MONO_SINGLE: case MODE_STN_COLOR_SINGLE: switch (jzfb.cfg & STN_DAT_PINMASK) { #define align2(n) (n)=((((n)+1)>>1)<<1) #define align4(n) (n)=((((n)+3)>>2)<<2) #define align8(n) (n)=((((n)+7)>>3)<<3) case STN_DAT_PIN1: /* Do not adjust the hori-param value. */ break; case STN_DAT_PIN2: align2(jzfb.hsw); align2(jzfb.elw); align2(jzfb.blw); break; case STN_DAT_PIN4: align4(jzfb.hsw); align4(jzfb.elw); align4(jzfb.blw); break; case STN_DAT_PIN8: align8(jzfb.hsw); align8(jzfb.elw); align8(jzfb.blw); break; } break; } REG_LCD_CTRL = val; switch (jzfb.cfg & MODE_MASK) { case MODE_STN_MONO_DUAL: case MODE_STN_COLOR_DUAL: case MODE_STN_MONO_SINGLE: case MODE_STN_COLOR_SINGLE: if (((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL) || ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL)) stnH = jzfb.h >> 1; else stnH = jzfb.h; REG_LCD_VSYNC = (0 << 16) | jzfb.vsw; REG_LCD_HSYNC = ((jzfb.blw+jzfb.w) << 16) | (jzfb.blw+jzfb.w+jzfb.hsw); /* Screen setting */ REG_LCD_VAT = ((jzfb.blw + jzfb.w + jzfb.hsw + jzfb.elw) << 16) | (stnH + jzfb.vsw + jzfb.bfw + jzfb.efw); REG_LCD_DAH = (jzfb.blw << 16) | (jzfb.blw + jzfb.w); REG_LCD_DAV = (0 << 16) | (stnH); /* AC BIAs signal */ REG_LCD_PS = (0 << 16) | (stnH+jzfb.vsw+jzfb.efw+jzfb.bfw); break; case MODE_TFT_GEN: case MODE_TFT_SHARP: case MODE_TFT_CASIO: case MODE_TFT_SAMSUNG: case MODE_8BIT_SERIAL_TFT: case MODE_TFT_18BIT: REG_LCD_VSYNC = (0 << 16) | jzfb.vsw; REG_LCD_HSYNC = (0 << 16) | jzfb.hsw; #if defined(CONFIG_JZLCD_INNOLUX_AT080TN42) REG_LCD_DAV = (0 << 16) | ( jzfb.h ); #else REG_LCD_DAV =((jzfb.vsw+jzfb.bfw) << 16) | (jzfb.vsw +jzfb.bfw+jzfb.h); #endif /*#if defined(CONFIG_JZLCD_INNOLUX_AT080TN42)*/ REG_LCD_DAH = ((jzfb.hsw + jzfb.blw) << 16) | (jzfb.hsw + jzfb.blw + jzfb.w ); REG_LCD_VAT = (((jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw)) << 16) \ | (jzfb.vsw + jzfb.bfw + jzfb.h + jzfb.efw); break; }
/* Size of the object pointed to by an untagged pointer */ cell factor_vm::untagged_object_size(object *pointer) { return align8(unaligned_object_size(pointer)); }