⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oasys.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
DEFUN(oasys_write_sections, (abfd),      bfd *CONST abfd){  asection *s;  static  oasys_section_record_type out = {0};  for (s = abfd->sections; s != (asection *)NULL; s = s->next) {    if (!isdigit(s->name[0])) 	{          bfd_error_vector.nonrepresentable_section(abfd,						    s->name);	}    out.relb = RELOCATION_TYPE_REL | s->target_index;    bfd_h_put_32(abfd, s->_cooked_size, (bfd_byte *) out.value);    bfd_h_put_32(abfd, s->vma, (bfd_byte *) out.vma);    oasys_write_record(abfd,		       oasys_record_is_section_enum,		       (oasys_record_union_type *) &out,		       sizeof(out));  }}static voidDEFUN(oasys_write_header, (abfd),      bfd *CONST abfd){  /* Create and write the header */  oasys_header_record_type r;  size_t length = strlen(abfd->filename);  if (length > (size_t)sizeof(r.module_name)) {    length = sizeof(r.module_name);  }  (void)memcpy(r.module_name,	       abfd->filename,	       length);  (void)memset(r.module_name + length,	       ' ',	       sizeof(r.module_name) - length);  r.version_number = OASYS_VERSION_NUMBER;  r.rev_number = OASYS_REV_NUMBER;  oasys_write_record(abfd,		     oasys_record_is_header_enum,		     (oasys_record_union_type *)&r,		     offsetof(oasys_header_record_type, description[0]));}static voidDEFUN(oasys_write_end,(abfd),      bfd *CONST abfd){  oasys_end_record_type end;  uint8e_type null = 0;  end.relb = RELOCATION_TYPE_ABS;  bfd_h_put_32(abfd, abfd->start_address, (bfd_byte *)end.entry);   bfd_h_put_16(abfd, 0, (bfd_byte *)end.fill);  end.zero =0;  oasys_write_record(abfd,		     oasys_record_is_end_enum,		     (oasys_record_union_type *)&end,		     sizeof(end));  bfd_write((PTR)&null, 1, 1, abfd);}static int DEFUN(comp,(ap, bp),   CONST PTR ap AND   CONST PTR bp){  arelent *a = *((arelent **)ap);  arelent *b = *((arelent **)bp);  return a->address - b->address;}/* Writing data.. */static voidDEFUN(oasys_write_data, (abfd),      bfd *CONST abfd){  asection *s;  for (s = abfd->sections; s != (asection *)NULL; s = s->next) {    if (s->flags & SEC_LOAD) {      uint8e_type *raw_data = oasys_per_section(s)->data;      oasys_data_record_type processed_data;      bfd_size_type current_byte_index = 0;      unsigned int relocs_to_go = s->reloc_count;      arelent **p = s->orelocation;      if (s->reloc_count != 0) {/* Sort the reloc records so it's easy to insert the relocs into the	   data */    	qsort(s->orelocation,	      s->reloc_count,	      sizeof(arelent **),	      comp);      }      current_byte_index = 0;      processed_data.relb = s->target_index | RELOCATION_TYPE_REL;      while (current_byte_index < s->_cooked_size) 	  {	    /* Scan forwards by eight bytes or however much is left and see if	       there are any relocations going on */	    uint8e_type *mod = &processed_data.data[0];	    uint8e_type *dst = &processed_data.data[1];	    unsigned int i;	    *mod = 0;	    bfd_h_put_32(abfd, s->vma + current_byte_index,			 processed_data.addr); 	    /* Don't start a relocation unless you're sure you can finish it 	       within the same data record.  The worst case relocation is a 	       4-byte relocatable value which is split across two modification 	       bytes (1 relocation byte + 2 symbol reference bytes + 2 data + 	       1 modification byte + 2 data = 8 bytes total).  That's where 	       the magic number 8 comes from. 	    */ 	    while (current_byte_index < s->_raw_size && dst <= 		(uint8e_type*)&processed_data.data[sizeof(processed_data.data)-8]) { 	    		if (relocs_to_go != 0) {			  arelent *r = *p;		  reloc_howto_type *CONST how=r->howto;		  /* There is a relocation, is it for this byte ? */		  if (r->address == current_byte_index) {		    uint8e_type rel_byte;		    p++;		    relocs_to_go--;		    *mod |= (1<<i);		    if(how->pc_relative) {		      rel_byte = 0x80;		      /* Also patch the raw data so that it doesn't have			 the -ve stuff any more */		      if (how->size != 2) {			bfd_put_16(abfd, 				   bfd_get_16(abfd,raw_data) +				   current_byte_index, raw_data);		      }		      else {			bfd_put_32(abfd, 				   bfd_get_32(abfd,raw_data) +				   current_byte_index, raw_data);		      }		    }		    else {		      rel_byte = 0;		    }		    if (how->size ==2) {		      rel_byte |= 0x40;		    }		  		    /* Is this a section relative relocation, or a symbol		       relative relocation ? */		    abort();	#if 0		    if (r->section != (asection*)NULL) 			{			  /* The relent has a section attached, so it must be section			     relative */			  rel_byte |= RELOCATION_TYPE_REL;			  rel_byte |= r->section->output_section->target_index;			  *dst++ = rel_byte;			}		    else #endif			{			  asymbol *p = *(r->sym_ptr_ptr);			  /* If this symbol has a section attached, then it			     has already been resolved.  Change from a symbol			     ref to a section ref */			  if(p->section != (asection *)NULL) {			    rel_byte |= RELOCATION_TYPE_REL;			    rel_byte |=			      p->section->output_section->target_index;			    *dst++ = rel_byte;			  }			  else {			    rel_byte |= RELOCATION_TYPE_UND;		  			    *dst++ = rel_byte;			    /* Next two bytes are a symbol index - we can get			       this from the symbol value which has been zapped			       into the symbol index in the table when the			       symbol table was written			       */			    *dst++ = p->value >> 8;			    *dst++ = p->value;			  }			}#define ADVANCE { if (++i >= 8) { i = 0; mod = dst++; *mod = 0; } current_byte_index++; }		    /* relocations never occur from an unloadable section,		       so we can assume that raw_data is not NULL		     */		    *dst++ = *raw_data++;		    ADVANCE		    *dst++ = *raw_data++;		    ADVANCE		    if (how->size == 2) {		      *dst++ = *raw_data++;		      ADVANCE		      *dst++ = *raw_data++;		      ADVANCE		    }		    continue;		  }		}		/* If this is coming from an unloadable section then copy		   zeros */		if (raw_data == (uint8e_type *)NULL) {		  *dst++ = 0;		}		else {		  *dst++ = *raw_data++;		}		ADVANCE	    }	    /* Don't write a useless null modification byte */	    if (dst == mod+1) {	      --dst;	    }	    oasys_write_record(abfd,			       oasys_record_is_data_enum,			       (oasys_record_union_type *)&processed_data,			       dst - (uint8e_type*)&processed_data);			 	  }    }  }}static booleanDEFUN(oasys_write_object_contents, (abfd),      bfd * CONST abfd){  oasys_write_header(abfd);  oasys_write_syms(abfd);  oasys_write_sections(abfd);  oasys_write_data(abfd);  oasys_write_end(abfd);  return true;}/** exec and core file sections *//* set section contents is complicated with OASYS since the format is * not a byte image, but a record stream.*/static booleanDEFUN(oasys_set_section_contents,(abfd, section, location, offset, count),      bfd *abfd AND      sec_ptr section AND       PTR location AND      file_ptr offset AND      bfd_size_type count){  if (count != 0) {    if (oasys_per_section(section)->data == (bfd_byte *)NULL ) 	{	  oasys_per_section(section)->data =	    (bfd_byte *)(bfd_alloc(abfd,section->_cooked_size));    	}    (void) memcpy((PTR)(oasys_per_section(section)->data + offset),		  location,		  count);  }  return true;}/* Native-level interface to symbols. *//* We read the symbols into a buffer, which is discarded when thisfunction exits.  We read the strings into a buffer large enough tohold them all plus all the cached symbol entries. */static asymbol *DEFUN(oasys_make_empty_symbol,(abfd),      bfd *abfd){  oasys_symbol_type  *new =    (oasys_symbol_type *)bfd_zalloc (abfd, sizeof (oasys_symbol_type));  new->symbol.the_bfd = abfd;  return &new->symbol;}/* User should have checked the file flags; perhaps we should returnBFD_NO_MORE_SYMBOLS if there are none? */static bfd *oasys_openr_next_archived_file(arch, prev)bfd *arch;bfd *prev;{  oasys_ar_data_type *ar = OASYS_AR_DATA(arch);  oasys_module_info_type *p;  /* take the next one from the arch state, or reset */  if (prev == (bfd *)NULL) {    /* Reset the index - the first two entries are bogus*/    ar->module_index = 0;  }  p = ar->module + ar->module_index;  ar->module_index++;  if (ar->module_index <= ar->module_count) {    if (p->abfd == (bfd *)NULL) {      p->abfd = _bfd_create_empty_archive_element_shell(arch);      p->abfd->origin = p->pos;      p->abfd->filename = p->name;      /* Fixup a pointer to this element for the member */      p->abfd->arelt_data = (PTR)p;    }    return p->abfd;  }  else {    bfd_error = no_more_archived_files;    return (bfd *)NULL;  }}static booleanoasys_find_nearest_line(abfd,			 section,			 symbols,			 offset,			 filename_ptr,			 functionname_ptr,			 line_ptr)bfd *abfd;asection *section;asymbol **symbols;bfd_vma offset;char **filename_ptr;char **functionname_ptr;unsigned int *line_ptr;{  return false;}static intDEFUN(oasys_generic_stat_arch_elt,(abfd, buf),      bfd *abfd AND      struct stat *buf){  oasys_module_info_type *mod = (oasys_module_info_type *) abfd->arelt_data;  if (mod == (oasys_module_info_type *)NULL) {    bfd_error = invalid_operation;    return -1;  }  else {    buf->st_size = mod->size;    buf->st_mode = 0666;    return 0;  }}static int DEFUN(oasys_sizeof_headers,(abfd, exec),      bfd *abfd AND      boolean exec){return 0;}#define FOO PROTO#define oasys_core_file_failing_command (char *(*)())(bfd_nullvoidptr)#define oasys_core_file_failing_signal (int (*)())bfd_0#define oasys_core_file_matches_executable_p  0 #define oasys_slurp_armap bfd_true#define oasys_slurp_extended_name_table bfd_true#define oasys_truncate_arname (void (*)())bfd_nullvoidptr#define oasys_write_armap 0#define oasys_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr#define	oasys_close_and_cleanup		bfd_generic_close_and_cleanup#define oasys_set_arch_mach bfd_default_set_arch_mach#define oasys_bfd_debug_info_start bfd_void#define oasys_bfd_debug_info_end bfd_void#define oasys_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *, asection *)))bfd_void#define oasys_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents#define oasys_bfd_relax_section bfd_generic_relax_section/*SUPPRESS 460 */bfd_target oasys_vec ={  "oasys",			/* name */  bfd_target_oasys_flavour,  true,				/* target byte order */  true,				/* target headers byte order */  (HAS_RELOC | EXEC_P |		/* object flags */   HAS_LINENO | HAS_DEBUG |   HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),  (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS   |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */   0,				/* leading underscore */  ' ',				/* ar_pad_char */  16,				/* ar_max_namelen */  1,				/* minimum alignment */  _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */  _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */    {_bfd_dummy_target,       oasys_object_p,		/* bfd_check_format */       oasys_archive_p,       _bfd_dummy_target,     },    {				/* bfd_set_format */      bfd_false,      oasys_mkobject,       _bfd_generic_mkarchive,      bfd_false      },    {				/* bfd_write_contents */      bfd_false,      oasys_write_object_contents,      _bfd_write_archive_contents,      bfd_false,    },  JUMP_TABLE(oasys)};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -