void sisAllocZStencilBuffer( sisContextPtr smesa ) { GLuint z_depth; GLuint totalBytes; int width2; GLubyte *addr; z_depth = ( smesa->glCtx->Visual.depthBits + smesa->glCtx->Visual.stencilBits ) / 8; width2 = ALIGNMENT( smesa->width * z_depth, 4 ); totalBytes = smesa->height * width2 + Z_BUFFER_HW_PLUS; addr = sisAllocFB( smesa, totalBytes, &smesa->zbFree ); if (addr == NULL) sis_fatal_error("Failure to allocate Z buffer.\n"); if (SIS_VERBOSE & VERBOSE_SIS_BUFFER) { fprintf(stderr, "sis_alloc_z_stencil_buffer: addr=%p\n", addr); } addr = (GLubyte *)ALIGNMENT( (unsigned long)addr, Z_BUFFER_HW_ALIGNMENT ); smesa->depthbuffer = (void *) addr; smesa->depthPitch = width2; smesa->depthOffset = (unsigned long)addr - (unsigned long)smesa->FbBase; /* set pZClearPacket */ memset( &smesa->zClearPacket, 0, sizeof(ENGPACKET) ); smesa->zClearPacket.dwSrcPitch = (z_depth == 2) ? 0x80000000 : 0xf0000000; smesa->zClearPacket.dwDestBaseAddr = (unsigned long)(addr - (unsigned long)smesa->FbBase); smesa->zClearPacket.wDestPitch = width2; smesa->zClearPacket.stdwDestPos.wY = 0; smesa->zClearPacket.stdwDestPos.wX = 0; smesa->zClearPacket.wDestHeight = smesa->virtualY; smesa->zClearPacket.stdwDim.wWidth = (GLshort)width2 / z_depth; smesa->zClearPacket.stdwDim.wHeight = (GLshort)smesa->height; smesa->zClearPacket.stdwCmd.cRop = 0xf0; if (smesa->blockWrite) smesa->zClearPacket.stdwCmd.cCmd0 = CMD0_PAT_FG_COLOR; else smesa->zClearPacket.stdwCmd.cCmd0 = 0; smesa->zClearPacket.stdwCmd.cCmd1 = CMD1_DIR_X_INC | CMD1_DIR_Y_INC; }
/* * Returns the number of bytes of padding to align the type */ static uint32_t PadForType(char typeId, AJ_IOBuffer* ioBuf) { uint8_t* base = (ioBuf->direction == AJ_IO_BUF_RX) ? ioBuf->readPtr : ioBuf->writePtr; uint32_t offset = (uint32_t)(base - ioBuf->bufStart); uint32_t alignment = ALIGNMENT(typeId); return (alignment - offset) & (alignment - 1); }
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags) { JSString *str; char buf[2 * ALIGNMENT(JSString)]; str = ALIGN(buf, JSString); str->chars = (jschar *)chars; str->length = length; return js_AtomizeString(cx, str, ATOM_TMPSTR | flags); }
void sisAllocBackbuffer( sisContextPtr smesa ) { GLuint depth = smesa->bytesPerPixel; GLuint size, width2; char *addr; width2 = (depth == 2) ? ALIGNMENT (smesa->width, 2) : smesa->width; size = width2 * smesa->height * depth + DRAW_BUFFER_HW_PLUS; /* Fixme: unique context alloc/free back-buffer? */ addr = sisAllocFB( smesa, size, &smesa->bbFree ); if (addr == NULL) sis_fatal_error("Failure to allocate back buffer.\n"); addr = (char *)ALIGNMENT( (unsigned long)addr, DRAW_BUFFER_HW_ALIGNMENT ); smesa->backbuffer = addr; smesa->backOffset = (unsigned long)(addr - (unsigned long)smesa->FbBase); smesa->backPitch = width2 * depth; memset ( &smesa->cbClearPacket, 0, sizeof(ENGPACKET) ); smesa->cbClearPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xf0000000; smesa->cbClearPacket.dwDestBaseAddr = smesa->backOffset; smesa->cbClearPacket.wDestPitch = smesa->backPitch; smesa->cbClearPacket.stdwDestPos.wY = 0; smesa->cbClearPacket.stdwDestPos.wX = 0; smesa->cbClearPacket.wDestHeight = smesa->virtualY; smesa->cbClearPacket.stdwDim.wWidth = (GLshort) width2; smesa->cbClearPacket.stdwDim.wHeight = (GLshort) smesa->height; smesa->cbClearPacket.stdwCmd.cRop = 0xf0; if (smesa->blockWrite) smesa->cbClearPacket.stdwCmd.cCmd0 = (GLbyte)(CMD0_PAT_FG_COLOR); else smesa->cbClearPacket.stdwCmd.cCmd0 = 0; smesa->cbClearPacket.stdwCmd.cCmd1 = CMD1_DIR_X_INC | CMD1_DIR_Y_INC; }
cl_object si_alignment_of_foreign_elt_type(cl_object type) { enum ecl_ffi_tag tag = ecl_foreign_type_code(type); { #line 669 const cl_env_ptr the_env = ecl_process_env(); #line 669 #line 669 cl_object __value0 = ecl_make_fixnum(ALIGNMENT(tag)); #line 669 the_env->nvalues = 1; #line 669 return __value0; #line 669 } }
AJ_Status AJ_MarshalCloseContainer(AJ_Message* msg, AJ_Arg* arg) { AJ_IOBuffer* ioBuf = &msg->bus->sock.tx; AJ_Status status = AJ_OK; AJ_ASSERT(TYPE_FLAG(arg->typeId) & AJ_CONTAINER); AJ_ASSERT(msg->outer == arg); msg->outer = arg->container; if (arg->typeId == AJ_ARG_ARRAY) { uint32_t lenOffset = (uint32_t)((uint8_t*)arg->val.v_data - ioBuf->bufStart); /* * The length we marshal does not include the length field itself. */ arg->len = (uint16_t)(ioBuf->writePtr - (uint8_t*)arg->val.v_data) - 4; /* * If the array element is 8 byte aligned and the array is not empty check if there was * padding after the length. The length we marshal should not include the padding. */ if ((ALIGNMENT(*arg->sigPtr) == 8) && !(lenOffset & 4) && arg->len) { arg->len -= 4; } /* * Write array length into the buffer */ *(arg->val.v_uint32) = arg->len; } else { arg->len = 0; /* * Check the signature is correctly closed. */ if ((arg->typeId == AJ_ARG_STRUCT) && (*arg->sigPtr != AJ_STRUCT_CLOSE)) { return AJ_ERR_SIGNATURE; } if ((arg->typeId == AJ_ARG_DICT_ENTRY) && (*arg->sigPtr != AJ_DICT_ENTRY_CLOSE)) { return AJ_ERR_SIGNATURE; } } return status; }
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags) { jschar *chars; JSString *str; JSAtom *atom; char buf[2 * ALIGNMENT(JSString)]; /* * Avoiding the malloc in js_InflateString on shorter strings saves us * over 20,000 malloc calls on mozilla browser startup. This compares to * only 131 calls where the string is longer than a 31 char (net) buffer. * The vast majority of atomized strings are already in the hashtable. So * js_AtomizeString rarely has to copy the temp string we make. */ #define ATOMIZE_BUF_MAX 32 jschar inflated[ATOMIZE_BUF_MAX]; size_t inflatedLength = ATOMIZE_BUF_MAX - 1; if (length < ATOMIZE_BUF_MAX) { js_InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength); inflated[inflatedLength] = 0; chars = inflated; } else { inflatedLength = length; chars = js_InflateString(cx, bytes, &inflatedLength); if (!chars) return NULL; flags |= ATOM_NOCOPY; } str = ALIGN(buf, JSString); str->chars = chars; str->length = inflatedLength; atom = js_AtomizeString(cx, str, ATOM_TMPSTR | flags); if (chars != inflated && (!atom || ATOM_TO_STRING(atom)->chars != chars)) JS_free(cx, chars); return atom; }
/** * @brief update metadata to buffer * @param data Pointer to structure of metadata data * @param type metadata type * @param keyid metadata Key ID * @param size metadata size * @param values matadata value * @return zero for success or non-zero on any faillure */ int update_metadata(struct camera_metadata_package *data, uint8_t type, Camera_Metadata_type_t keyid, int size, const uint8_t *values) { int nEntry = 0; if (data->header.entry_count >= MAX_METADATA_NUMBER) { printf("update_metadata no MEMORY\n"); return -ENOMEM; } nEntry = data->header.entry_count; data->entries[nEntry].entry_tag = keyid; data->entries[nEntry].data_type = type; data->entries[nEntry].data_count = size; memcpy(&data->data[data->header.size], (void *)values, size); //address alignment data->header.size += size; data->header.size = ALIGNMENT(data->header.size, 8); data->entries[nEntry].data_offset = data->header.size; data->header.entry_count++; return 0; }
#include "xmodem.h" #include "crc.h" #include "uart.h" #include "flash.h" #include "aes.h" #include "bootloader_config.h" #define ALIGNMENT(base,align) (((base)+((align)-1))&(~((align)-1))) /* Packet storage. Double buffered to allow DMA to write to flash * while receiving the next packet. These buffers will be accessed * with both 8 and 32 bit alignment */ #if defined (__ICCARM__) #pragma data_alignment=4 uint8_t rawPacket[2][ALIGNMENT(sizeof(XMODEM_packet),4)]; #pragma data_alignment=4 uint8_t rawBuffer[2][ALIGNMENT(XMODEM_DATA_SIZE,4)]; #elif defined (__CC_ARM) uint8_t rawPacket[2][ALIGNMENT(sizeof(XMODEM_packet),4)] __attribute__ ((aligned(4))); uint8_t rawBuffer[2][ALIGNMENT(XMODEM_DATA_SIZE,4)] __attribute__ ((aligned(4))); #elif defined (__GNUC__) uint8_t rawPacket[2][ALIGNMENT(sizeof(XMODEM_packet),4)] __attribute__ ((aligned(4))); uint8_t rawBuffer[2][ALIGNMENT(XMODEM_DATA_SIZE,4)] __attribute__ ((aligned(4))); #else #error Undefined toolkit, need to define alignment #endif /**************************************************************************//**
/* * Unmarshal a single argument */ static AJ_Status Unmarshal(AJ_Message* msg, const char** sig, AJ_Arg* arg) { AJ_Status status; AJ_IOBuffer* ioBuf = &msg->bus->sock.rx; char typeId; uint32_t pad; uint32_t sz; memset(arg, 0, sizeof(AJ_Arg)); if (!*sig || !**sig) { return AJ_ERR_END_OF_DATA; } typeId = **sig; *sig += 1; pad = PadForType(typeId, ioBuf); if (IsScalarType(typeId)) { sz = SizeOfType(typeId); status = LoadBytes(ioBuf, sz, pad); if (status != AJ_OK) { return status; } /* * For numeric types we just return a pointer into the buffer */ arg->typeId = typeId; arg->val.v_byte = ioBuf->readPtr; arg->len = 0; ioBuf->readPtr += sz; EndianSwap(msg, typeId, (void*)arg->val.v_data, 1); } else if (TYPE_FLAG(typeId) & (AJ_STRING | AJ_VARIANT)) { /* * Length field for a signature is 1 byte, for regular strings its 4 bytes */ uint32_t lenSize = ALIGNMENT(typeId); /* * Read the string length. Note the length doesn't include the terminating NUL * so an empty string in encoded as two zero bytes. */ status = LoadBytes(ioBuf, lenSize, pad); if (status != AJ_OK) { return status; } if (lenSize == 4) { EndianSwap(msg, AJ_ARG_UINT32, ioBuf->readPtr, 1); sz = *((uint32_t*)ioBuf->readPtr); } else { sz = (uint32_t)(*ioBuf->readPtr); } ioBuf->readPtr += lenSize; status = LoadBytes(ioBuf, sz + 1, 0); if (status != AJ_OK) { return status; } arg->typeId = typeId; arg->len = sz; arg->val.v_string = (char*)ioBuf->readPtr; ioBuf->readPtr += sz + 1; /* * If unmarshalling a variant store offset to start of signature */ if (typeId == AJ_ARG_VARIANT) { msg->varOffset = (uint8_t)(sz + 1); } } else if (typeId == AJ_ARG_ARRAY) { status = UnmarshalArray(msg, sig, arg, pad); } else if ((typeId == AJ_ARG_STRUCT) || (typeId == AJ_ARG_DICT_ENTRY)) { arg->typeId = typeId; status = UnmarshalStruct(msg, sig, arg, pad); } else { status = AJ_ERR_UNMARSHAL; } return status; }
static AJ_Status Marshal(AJ_Message* msg, const char** sig, AJ_Arg* arg) { AJ_Status status = AJ_OK; AJ_IOBuffer* ioBuf = &msg->bus->sock.tx; char typeId = **sig; uint32_t pad = PadForType(typeId, ioBuf); size_t sz; if (!arg) { return AJ_ERR_NULL; } *sig += 1; if (IsScalarType(arg->typeId)) { if (arg->flags & AJ_ARRAY_FLAG) { if ((typeId != AJ_ARG_ARRAY) || (**sig != arg->typeId)) { return AJ_ERR_MARSHAL; } *sig += 1; sz = arg->len; status = WriteBytes(msg, &sz, 4, pad); if (status == AJ_OK) { /* * May need to pad if the elements required 8 byte alignment */ pad = PadForType(arg->typeId, ioBuf); } } else { if (typeId != arg->typeId) { return AJ_ERR_MARSHAL; } sz = SizeOfType(typeId); } if (status == AJ_OK) { status = WriteBytes(msg, arg->val.v_data, sz, pad); } } else if (TYPE_FLAG(typeId) & (AJ_STRING | AJ_VARIANT)) { if (typeId != arg->typeId) { return AJ_ERR_MARSHAL; } sz = arg->len ? arg->len : strlen(arg->val.v_string); /* * Length field for a signature is 1 byte, for regular strings its 4 bytes */ if (ALIGNMENT(typeId) == 1) { uint8_t szu8 = (uint8_t)sz; if (sz > 255) { return AJ_ERR_MARSHAL; } status = WriteBytes(msg, &szu8, 1, pad); } else { status = WriteBytes(msg, &sz, 4, pad); } if (status == AJ_OK) { status = WriteBytes(msg, arg->val.v_string, sz, 0); /* * String must be NUL terminated on the wire */ if (status == AJ_OK) { status = WritePad(msg, 1); } /* * If marshalling a variant store offset to start of signature */ if (typeId == AJ_ARG_VARIANT) { msg->varOffset = (uint8_t)(sz + 1); } } } else if (TYPE_FLAG(typeId) & AJ_CONTAINER) { if (typeId != arg->typeId) { return AJ_ERR_MARSHAL; } status = MarshalContainer(msg, sig, arg, pad); } else { return AJ_ERR_MARSHAL; } return status; }