vms-misc.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,123 行 · 第 1/2 页
C
1,123 行
#if VMS_DEBUG vms_debug (4, "<pop %016lx(%d)>\n", value, PRIV (stack[PRIV (stackptr)]).psect);#endif return value;}/* object file output functions *//* GAS tends to write sections in little chunks (bfd_set_section_contents) which we can't use directly. So we save the little chunks in linked lists (one per section) and write them later. *//* Add a new vms_section structure to vms_section_table - forward chaining - */static vms_section *add_new_contents (abfd, section) bfd *abfd; sec_ptr section;{ vms_section *sptr, *newptr; sptr = PRIV (vms_section_table)[section->index]; if (sptr != NULL) return sptr; newptr = (vms_section *) bfd_malloc (sizeof (vms_section)); if (newptr == (vms_section *) NULL) return NULL; newptr->contents = (unsigned char *) bfd_alloc (abfd, (int)section->_raw_size); if (newptr->contents == (unsigned char *)NULL) return NULL; newptr->offset = 0; newptr->size = section->_raw_size; newptr->next = 0; PRIV (vms_section_table)[section->index] = newptr; return newptr;}/* Save section data & offset to an vms_section structure vms_section_table[] holds the vms_section chain */boolean_bfd_save_vms_section (abfd, section, data, offset, count) bfd *abfd; sec_ptr section; PTR data; file_ptr offset; bfd_size_type count;{ vms_section *sptr; if (section->index >= VMS_SECTION_COUNT) { bfd_set_error (bfd_error_nonrepresentable_section); return false; } if (count == (bfd_size_type)0) return true; sptr = add_new_contents (abfd, section); if (sptr == NULL) return false; memcpy (sptr->contents + offset, data, (size_t) count); return true;}/* Get vms_section pointer to saved contents for section # index */vms_section *_bfd_get_vms_section (abfd, index) bfd *abfd; int index;{ if (index >= VMS_SECTION_COUNT) { bfd_set_error (bfd_error_nonrepresentable_section); return NULL; } return PRIV (vms_section_table)[index];}/* Object output routines *//* Begin new record or record header write 2 bytes rectype write 2 bytes record length (filled in at flush) write 2 bytes header type (ommitted if rechead == -1) */void_bfd_vms_output_begin (abfd, rectype, rechead) bfd *abfd; int rectype; int rechead;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_begin(type %d, head %d)\n", rectype, rechead);#endif _bfd_vms_output_short (abfd,rectype); /* save current output position to fill in lenght later */ if (PRIV (push_level) > 0) PRIV (length_pos) = PRIV (output_size);#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_begin: length_pos = %d\n", PRIV (length_pos));#endif _bfd_vms_output_short (abfd,0); /* placeholder for length */ if (rechead != -1) _bfd_vms_output_short (abfd,rechead); return;}/* Set record/subrecord alignment */void_bfd_vms_output_alignment (abfd, alignto) bfd *abfd; int alignto;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_alignment(%d)\n", alignto);#endif PRIV (output_alignment) = alignto; return;}/* Prepare for subrecord fields */void_bfd_vms_output_push (abfd) bfd *abfd;{#if VMS_DEBUG vms_debug (6, "vms_output_push(pushed_size = %d)\n", PRIV (output_size));#endif PRIV (push_level)++; PRIV (pushed_size) = PRIV (output_size); return;}/* End of subrecord fields */void_bfd_vms_output_pop (abfd) bfd *abfd;{#if VMS_DEBUG vms_debug (6, "vms_output_pop(pushed_size = %d)\n", PRIV (pushed_size));#endif _bfd_vms_output_flush (abfd); PRIV (length_pos) = 2;#if VMS_DEBUG vms_debug (6, "vms_output_pop: length_pos = %d\n", PRIV (length_pos));#endif PRIV (pushed_size) = 0; PRIV (push_level)--; return;}/* Flush unwritten output, ends current record */void_bfd_vms_output_flush (abfd) bfd *abfd;{ int real_size = PRIV (output_size); int aligncount; int length;#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_flush(real_size = %d, pushed_size %d at lenpos %d)\n", real_size, PRIV (pushed_size), PRIV (length_pos));#endif if (PRIV (push_level) > 0) length = real_size - PRIV (pushed_size); else length = real_size; if (length == 0) return; aligncount = (PRIV (output_alignment) - (length % PRIV (output_alignment))) % PRIV (output_alignment);#if VMS_DEBUG vms_debug (6, "align: adding %d bytes\n", aligncount);#endif while (aligncount-- > 0) { PRIV (output_buf)[real_size++] = 0;#if 0 /* this is why I *love* vms: inconsistency :-} alignment is added to the subrecord length but not to the record length */ if (PRIV (push_level) > 0)#endif length++; } /* put length to buffer */ PRIV (output_size) = PRIV (length_pos); _bfd_vms_output_short (abfd, (unsigned int)length); if (PRIV (push_level) == 0) {#ifndef VMS /* write length first, see FF_FOREIGN in the input routines */ fwrite (PRIV (output_buf)+2, 2, 1, (FILE *)abfd->iostream);#endif fwrite (PRIV (output_buf), real_size, 1, (FILE *)abfd->iostream); PRIV (output_size) = 0; } else { PRIV (output_size) = real_size; PRIV (pushed_size) = PRIV (output_size); } return;}/* End record output */void_bfd_vms_output_end (abfd) bfd *abfd;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_end\n");#endif _bfd_vms_output_flush (abfd); return;}/* check remaining buffer size return what's left. */int_bfd_vms_output_check (abfd, size) bfd *abfd; int size;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_check(%d)\n", size);#endif return (MAX_OUTREC_SIZE - (PRIV (output_size) + size + MIN_OUTREC_LUFT));}/* Output byte (8 bit) value */void_bfd_vms_output_byte (abfd, value) bfd *abfd; unsigned int value;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_byte(%02x)\n", value);#endif bfd_put_8 (abfd, value & 0xff, PRIV (output_buf) + PRIV (output_size)); PRIV (output_size) += 1; return;}/* Output short (16 bit) value */void_bfd_vms_output_short (abfd, value) bfd *abfd; unsigned int value;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_short (%04x)\n", value);#endif bfd_put_16 (abfd, value & 0xffff, PRIV (output_buf) + PRIV (output_size)); PRIV (output_size) += 2; return;}/* Output long (32 bit) value */void_bfd_vms_output_long (abfd, value) bfd *abfd; unsigned long value;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_long (%08lx)\n", value);#endif bfd_put_32 (abfd, value, PRIV (output_buf) + PRIV (output_size)); PRIV (output_size) += 4; return;}/* Output quad (64 bit) value */void_bfd_vms_output_quad (abfd, value) bfd *abfd; uquad value;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_quad(%016lx)\n", value);#endif bfd_put_64(abfd, value, PRIV (output_buf) + PRIV (output_size)); PRIV (output_size) += 8; return;}/* Output c-string as counted string */void_bfd_vms_output_counted (abfd, value) bfd *abfd; char *value;{int len;#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_counted(%s)\n", value);#endif len = strlen (value); if (len == 0) { (*_bfd_error_handler) (_("_bfd_vms_output_counted called with zero bytes")); return; } if (len > 255) { (*_bfd_error_handler) (_("_bfd_vms_output_counted called with too many bytes")); return; } _bfd_vms_output_byte (abfd, len & 0xff); _bfd_vms_output_dump (abfd, (unsigned char *)value, len);}/* Output character area */void_bfd_vms_output_dump (abfd, data, length) bfd *abfd; unsigned char *data; int length;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_dump(%d)\n", length);#endif if (length == 0) return; memcpy (PRIV (output_buf) + PRIV (output_size), data, length); PRIV (output_size) += length; return;}/* Output count bytes of value */void_bfd_vms_output_fill (abfd, value, count) bfd *abfd; int value; int count;{#if VMS_DEBUG vms_debug (6, "_bfd_vms_output_fill(val %02x times %d)\n", value, count);#endif if (count == 0) return; memset (PRIV (output_buf) + PRIV (output_size), value, count); PRIV (output_size) += count; return;}/* this hash routine borrowed from GNU-EMACS, and strengthened slightly ERY*/static inthash_string (ptr) const char *ptr;{ register const unsigned char *p = (unsigned char *) ptr; register const unsigned char *end = p + strlen (ptr); register unsigned char c; register int hash = 0; while (p != end) { c = *p++; hash = ((hash << 3) + (hash << 15) + (hash >> 28) + c); } return hash;}/* Generate a length-hashed VMS symbol name (limited to maxlen chars). */char *_bfd_vms_length_hash_symbol (abfd, in, maxlen) bfd *abfd; const char *in; int maxlen;{ long int result; int in_len; char *new_name; const char *old_name; int i; static char outbuf[EOBJ_S_C_SYMSIZ+1]; char *out = outbuf;#if VMS_DEBUG vms_debug(4, "_bfd_vms_length_hash_symbol \"%s\"\n", in);#endif if (maxlen > EOBJ_S_C_SYMSIZ) maxlen = EOBJ_S_C_SYMSIZ; new_name = out; /* save this for later. */ /* We may need to truncate the symbol, save the hash for later. */ in_len = strlen (in); result = (in_len > maxlen) ? hash_string (in) : 0; old_name = in; /* Do the length checking. */ if (in_len <= maxlen) { i = in_len; } else { if (PRIV (flag_hash_long_names)) i = maxlen-9; else i = maxlen; } strncpy (out, in, i); in += i; out += i; if ((in_len > maxlen) && PRIV (flag_hash_long_names)) sprintf (out, "_%08lx", result); else *out = 0;#if VMS_DEBUG vms_debug(4, "--> [%d]\"%s\"\n", strlen (outbuf), outbuf);#endif if (in_len > maxlen && PRIV (flag_hash_long_names) && PRIV (flag_show_after_trunc)) printf (_("Symbol %s replaced by %s\n"), old_name, new_name); return outbuf;}/* Allocate and initialize a new symbol. */static asymbol *new_symbol (abfd, name) bfd *abfd; char *name;{ asymbol *symbol;#if VMS_DEBUG _bfd_vms_debug (7, "new_symbol %s\n", name);#endif symbol = _bfd_vms_make_empty_symbol (abfd); if (symbol == 0) return symbol; symbol->name = name; symbol->section = bfd_make_section (abfd, BFD_UND_SECTION_NAME); return symbol;}/* Allocate and enter a new private symbol. */vms_symbol_entry *_bfd_vms_enter_symbol (abfd, name) bfd *abfd; char *name;{ vms_symbol_entry *entry;#if VMS_DEBUG _bfd_vms_debug (6, "_bfd_vms_enter_symbol %s\n", name);#endif entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table), name, false, false); if (entry == 0) {#if VMS_DEBUG _bfd_vms_debug (8, "creating hash entry for %s\n", name);#endif entry = (vms_symbol_entry *)bfd_hash_lookup (PRIV (vms_symbol_table), name, true, false); if (entry != 0) { asymbol *symbol; symbol = new_symbol (abfd, name); if (symbol != 0) { entry->symbol = symbol; PRIV (gsd_sym_count)++; abfd->symcount++; } else entry = 0; } else (*_bfd_error_handler) (_("failed to enter %s"), name); } else {#if VMS_DEBUG _bfd_vms_debug (8, "found hash entry for %s\n", name);#endif }#if VMS_DEBUG _bfd_vms_debug (7, "-> entry %p, entry->symbol %p\n", entry, entry->symbol);#endif return entry;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?