/* * mm_realloc - Implemented simply in terms of mm_malloc and mm_free */ void *mm_realloc(void *ptr, size_t size) { if (!ptr) { return mm_malloc(size); } if (!size) { mm_free(ptr); return NULL; } void *hdrp = get_hdrp(ptr); size_t old_size = get_size(hdrp); size_t ori_size = old_size; size_t target_size = align_with_min_bk_size(size + WSIZE); // if possible, we won't move the data, collect space in place hdrp = backward_collect(hdrp, target_size); old_size = get_size(hdrp); if (target_size <= old_size) { #if HEAP_CHECK delete_from_alloc_list(ptr); #endif size_t left_size = old_size - target_size; if (left_size && is_align_with_min_bk_size(left_size)) { set_size(hdrp, target_size); set_alloc_bit(hdrp); void *new_free_hdrp = (char*)hdrp + target_size; write_word(new_free_hdrp, PREV_ALLOC); init_free_block(new_free_hdrp, left_size); insert_into_size_class(new_free_hdrp, find_index(left_size)); } else { set_alloc_bit(hdrp); set_prev_alloc_bit((char*)hdrp + old_size); } #if HEAP_CHECK add_to_alloc_list(ptr, size, target_size); #endif return (char*)hdrp + WSIZE; } // find fit void *new_hdrp = find_fit(target_size); if (new_hdrp) { new_hdrp = place_and_split(new_hdrp, target_size); mm_memcpy((char*)new_hdrp + WSIZE, ptr, ori_size - WSIZE); mm_free(ptr); #if HEAP_CHECK add_to_alloc_list((char*)new_hdrp + WSIZE, size, target_size); #endif return (char*)new_hdrp + WSIZE; } // extend heap new_hdrp = extend_heap(target_size, 1); if (!new_hdrp) return NULL; new_hdrp = place_and_split(new_hdrp, target_size); mm_memcpy((char*)new_hdrp + WSIZE, ptr, ori_size - WSIZE); mm_free(ptr); #if HEAP_CHECK add_to_alloc_list((char*)new_hdrp + WSIZE, size, target_size); #endif return (char*)new_hdrp + WSIZE; }
static inline void write_ATKHLD(int channel,int i) { write_word (6,channel,2,i); }
static inline void write_IP(int channel,int i) { write_word (0,channel,3,i); }
static inline void write_INIT1(int channel,int i) { write_word (2,channel,1,i); } /* `channel' is really `element' here */
static inline void write_ENVVAL(int channel,int i) { write_word (6,channel,1,i); }
static inline void write_WC(int i) { write_word (1, 27,2,i); }
static inline void write_HWCF2(int i) { write_word (1, 30,1,i); }
void Fl_Type::write_properties() { int level = 0; for (Fl_Type* p = parent; p; p = p->parent) level++; // repeat this for each attribute: if (!label().empty()) { write_indent(level+1); write_word("label"); write_word(label()); } if (!user_data().empty()) { write_indent(level+1); write_word("user_data"); write_word(user_data()); if (!user_data_type().empty()) { write_word("user_data_type"); write_word(user_data_type()); } } if (!callback().empty()) { write_indent(level+1); write_word("callback"); write_word(callback()); } if (is_parent() && open_) write_word("open"); if (selected) write_word("selected"); if (!tooltip().empty()) { write_indent(level+1); write_word("tooltip"); write_word(tooltip()); } }
/* * Copy memory to flash, returns: * 0 - OK * 1 - write timeout * 2 - Flash not erased */ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) { ulong cp, wp, data; int i, l, rc; wp = (addr & ~3); /* get lower word aligned address */ /* * handle unaligned start bytes */ if ((l = addr - wp) != 0) { data = 0; for (i=0, cp=wp; i<l; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } for (; i<4 && cnt>0; ++i) { data = (data << 8) | *src++; --cnt; ++cp; } for (; cnt==0 && i<4; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } if ((rc = write_word(info, wp, data)) != 0) { return (rc); } wp += 4; } /* * handle word aligned part */ while (cnt >= 4) { data = 0; for (i=0; i<4; ++i) { data = (data << 8) | *src++; } if ((rc = write_word(info, wp, data)) != 0) { return (rc); } wp += 4; cnt -= 4; } if (cnt == 0) { return (0); } /* * handle unaligned tail bytes */ data = 0; for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) { data = (data << 8) | *src++; --cnt; } for (; i<4; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } return (write_word(info, wp, data)); }
void BIOSCALL int13_eltorito(disk_regs_t r) { // @TODO: a macro or a function for getting the EBDA segment uint16_t ebda_seg=read_word(0x0040,0x000E); cdemu_t __far *cdemu; cdemu = ebda_seg :> &EbdaData->cdemu; BX_DEBUG_INT13_ET("%s: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", __func__, AX, BX, CX, DX, ES); // BX_DEBUG_INT13_ET("%s: SS=%04x DS=%04x ES=%04x DI=%04x SI=%04x\n", __func__, get_SS(), DS, ES, DI, SI); switch (GET_AH()) { // FIXME ElTorito Various. Should be implemented case 0x4a: // ElTorito - Initiate disk emu case 0x4c: // ElTorito - Initiate disk emu and boot case 0x4d: // ElTorito - Return Boot catalog BX_PANIC("%s: call with AX=%04x. Please report\n", __func__, AX); goto int13_fail; break; case 0x4b: // ElTorito - Terminate disk emu // FIXME ElTorito Hardcoded //@todo: maybe our cdemu struct should match El Torito to allow memcpy()? write_byte(DS,SI+0x00,0x13); write_byte(DS,SI+0x01,cdemu->media); write_byte(DS,SI+0x02,cdemu->emulated_drive); write_byte(DS,SI+0x03,cdemu->controller_index); write_dword(DS,SI+0x04,cdemu->ilba); write_word(DS,SI+0x08,cdemu->device_spec); write_word(DS,SI+0x0a,cdemu->buffer_segment); write_word(DS,SI+0x0c,cdemu->load_segment); write_word(DS,SI+0x0e,cdemu->sector_count); write_byte(DS,SI+0x10,cdemu->vdevice.cylinders); write_byte(DS,SI+0x11,cdemu->vdevice.spt); write_byte(DS,SI+0x12,cdemu->vdevice.heads); // If we have to terminate emulation if(GET_AL() == 0x00) { // FIXME ElTorito Various. Should be handled accordingly to spec cdemu->active = 0; // bye bye } goto int13_success; break; default: BX_INFO("%s: unsupported AH=%02x\n", __func__, GET_AH()); goto int13_fail; break; } int13_fail: SET_AH(0x01); // defaults to invalid function in AH or invalid parameter SET_DISK_RET_STATUS(GET_AH()); SET_CF(); // error occurred return; int13_success: SET_AH(0x00); // no error SET_DISK_RET_STATUS(0x00); CLEAR_CF(); // no error return; }
int WaveProc::WriteWord(FILE *out, int n) { return write_word(out, n); }
Dynamixel::CommStatus Dynamixel::set_max_torque(unsigned char id, int value) { return write_word(id, 0x22, value); }
Dynamixel::CommStatus Dynamixel::set_moving_speed(unsigned char id, int value) { return write_word(id, 0x20, value); }
Dynamixel::CommStatus Dynamixel::set_goal_position(unsigned char id, int value) { return write_word(id, 0x1E, value); }
static inline void write_SMLD(int i) { write_word (1, 26,1,i); }
static void metafile_version(FILE *pt) { write_word(pt,0x1022); write_word(pt,0x0001); return; }
static inline void write_SMRD(int i) { write_word (1, 26,2,i); }
static void colour_selection_mode(FILE *pt,int mode) { write_word(pt,0x2042); write_word(pt,(WORD)mode); return; }
static inline void write_HWCF1(int i) { write_word (1, 29,1,i); }
static void line_width_specification_mode(FILE *pt,WORD mode) { write_word(pt,0x2062); write_word(pt,mode); return; }
static inline void write_HWCF3(int i) { write_word (1, 31,1,i); }
static void begin_picture_body(FILE *pt) { write_word(pt,0x0080); return; }
static inline void write_INIT4(int channel,int i) { write_word (3,channel,2,i); }
static void line_width(FILE *pt,WORD width) { write_word(pt,0x5062); write_word(pt,width); return; }
static inline void write_DCYSUS(int channel,int i) { write_word (7,channel,1,i); }
static void interior_style(FILE *pt,WORD style) { write_word(pt,0x52c2); write_word(pt,style); return; }
static inline void write_LFO2VAL(int channel,int i) { write_word (7,channel,2,i); }
static void end_picture(FILE *pt) { write_word(pt,0x00a0); return; }
static inline void write_IFATN(int channel,int i) { write_word (1,channel,3,i); }
/* broken for 2x16: TODO */ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) { ulong cp, wp, data; int i, l, rc; if(info->portwidth==4) return 1; if((info->flash_id & FLASH_TYPEMASK) == FLASH_ROM) return 0; if((info->flash_id & FLASH_TYPEMASK) == FLASH_RAM) { memcpy((void *)addr, src, cnt); return 0; } wp = (addr & ~3); /* get lower word aligned address */ /* * handle unaligned start bytes */ if ((l = addr - wp) != 0) { data = 0; for (i=0, cp=wp; i<l; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } for (; i<4 && cnt>0; ++i) { data = (data << 8) | *src++; --cnt; ++cp; } for (; cnt==0 && i<4; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } if ((rc = write_word(info, wp, data)) != 0) { return (rc); } wp += 4; } /* * handle word aligned part */ while (cnt >= 4) { data = 0; for (i=0; i<4; ++i) { data = (data << 8) | *src++; } if ((rc = write_word(info, wp, data)) != 0) { return (rc); } wp += 4; cnt -= 4; } if (cnt == 0) { return (0); } /* * handle unaligned tail bytes */ data = 0; for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) { data = (data << 8) | *src++; --cnt; } for (; i<4; ++i, ++cp) { data = (data << 8) | (*(uchar *)cp); } return (write_word(info, wp, data)); }