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

📄 ieee.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	case 0x3e: copy_till_end(); break;	case 0x40: copy_till_end(); break;	case 0x41: ID; break;	}      }}static void f0_record(){  /* Attribute record */  NEXT();  OUT(0xf0);  INTn(Symbol name );  ID;}static void copy_till_end(){  int  ch = THIS();  while (1) {    while (ch <= 0x80) 	{	  OUT(ch);	  NEXT();	  ch = THIS();	}    switch (ch) {    case 0x84:      OUT(THIS());      NEXT();    case 0x83:      OUT(THIS());      NEXT();    case 0x82:      OUT(THIS());      NEXT();    case 0x81:      OUT(THIS());      NEXT();      OUT(THIS());      NEXT();      ch = THIS();      break;    default:      return;    }  }    }static void f2_record(){  NEXT();  OUT(0xf2);  INT ;  NEXT();  OUT(0xce);  INT ;  copy_till_end();}static void block();static void f8_record(){  int ch;  NEXT();  ch = THIS();  switch (ch)       {      case 0x01:      case 0x02:      case 0x03:	/* Unique typedefs for module */	/* GLobal typedefs  */	/* High level module scope beginning */	  {	    struct output_buffer_struct ob;	    NEXT();	    OUT(0xf8); OUT(ch);	    drop_int(&ob); ID ;	    block();	    NEXT();	    fill_int(&ob);	    OUT(0xf9);	  }	break;      case 0x04:		/* Global function */	  {	    struct output_buffer_struct ob;	    NEXT();	    OUT(0xf8); OUT(0x04);	    drop_int(&ob); ID ; INTn(stack size); INTn(ret val);	    EXPn(offset); 	    block();	    NEXT();	    OUT(0xf9);		    EXPn(size of block);	    fill_int(&ob);	  }	break;      case 0x05:	/* File name for source line numbers */	  {	    struct output_buffer_struct ob;	    NEXT();	    OUT(0xf8); OUT(0x05);	    drop_int(&ob);	    ID; INTn(year); INTn(month); INTn(day);	    INTn(hour); INTn(monute); INTn(second);	    block();	    NEXT();	    OUT(0xf9);	    fill_int(&ob);	  }	break;	      case 0x06:	/* Local function */	  { struct output_buffer_struct ob;	    NEXT(); OUT(0xf8); OUT(0x06);	    drop_int(&ob);	    ID; INTn(stack size); INTn(type return);	    EXPn(offset);	    block();	    NEXT();	    OUT(0xf9);	    EXPn(size);	    fill_int(&ob);	  }	break;	      case 0x0a:	/* Assembler module scope beginning -*/	  { struct output_buffer_struct ob;	    NEXT();	    OUT(0xf8); OUT(0x0a); 	    drop_int(&ob);	      ID; ID; INT; ID; INT; INT; INT; INT; INT; INT;	    block();		    NEXT();	    OUT(0xf9);	    fill_int(&ob);	  }	break;      case 0x0b:	  {	    struct output_buffer_struct ob;	    NEXT();	    OUT(0xf8); OUT(0x0b); 	    drop_int(&ob); ID ; INT; INTn(section index); EXPn(offset); INTn(stuff);	    block();	    OUT(0xf9);	    NEXT();      	    EXPn(Size in Maus);	    fill_int(&ob);	  }	break;      }}static void e2_record(){  OUT(0xe2);  NEXT();  OUT(0xce);  NEXT();  INT;  EXP;}static void DEFUN_VOID(block){  int ch ;  while (1) {    ch = THIS();    switch (ch) {    case 0xe1:    case 0xe5:      return;    case 0xf9:      return;    case 0xf0:      f0_record();      break;    case 0xf1:      f1_record();          break;    case 0xf2:      f2_record();      break;    case 0xf8:      f8_record();      break;    case 0xe2:      e2_record();      break;    }    }}  /* relocate_debug,    moves all the debug information from the source bfd to the output   bfd, and relocates any expressions it finds*/static voidDEFUN(relocate_debug,(output, input),      bfd *output AND      bfd *input){#define IBS 400#define OBS 400  unsigned char input_buffer[IBS];  input_ptr_start = input_ptr = input_buffer;  input_ptr_end = input_buffer + IBS;  input_bfd = input;  bfd_read((PTR)input_ptr_start, 1, IBS, input);  block();}/*   During linking, we we told about the bfds which made up our  contents, we have a list of them. They will still be open, so go to  the debug info in each, and copy it out, relocating it as we go.*/static void DEFUN(ieee_write_debug_part, (abfd),      bfd *abfd){  ieee_data_type *ieee = IEEE_DATA(abfd);  bfd_chain_type *chain = ieee->chain_root;  unsigned char output_buffer[OBS];  boolean some_debug = false;  file_ptr here = bfd_tell(abfd);  output_ptr_start = output_ptr = output_buffer ;  output_ptr_end = output_buffer + OBS;  output_ptr = output_buffer;  output_bfd = abfd;  if (chain == (bfd_chain_type *)NULL) {#if 0      /* There is no debug info, so we'll fake some up */      CONST static char fake[] = {	  0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,	  '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };      ieee->w.r.debug_information_part = 0;      here;      /*    bfd_write(fake, 1, sizeof(fake), abfd);*/      /* Now write a header for each section */    {      int i = 0;      asection *s = abfd->sections;      while (s) {	  if (s != abfd->abs_section) 	  {	      	    ieee_write_byte(abfd, 0xf8);		    ieee_write_byte(abfd, 0x0b);	    ieee_write_byte(abfd, 0);	    ieee_write_byte(abfd, 0);	    ieee_write_byte(abfd, 1);	    ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE);	    ieee_write_expression(abfd, 0, s->symbol, 0, 0, 0);	    ieee_write_byte(abfd,0);	    ieee_write_byte(abfd, 0xf9);	    ieee_write_expression(abfd, s->size,				  bfd_abs_section.symbol, 0, 0, 0);		    i++;	  }	    	  s = s->next;	}	      /* Close the scope */      ieee_write_byte(abfd, 0xf9);    }#endif    }  else{      while (chain != (bfd_chain_type *)NULL) {	  bfd *entry = chain->this;	  ieee_data_type *entry_ieee = IEEE_DATA(entry);	  if (entry_ieee->w.r.debug_information_part) {	      bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET);	      relocate_debug(abfd, entry);	    }	  chain = chain->next;	}      if (some_debug) {	  ieee->w.r.debug_information_part = here;	}      else {	  ieee->w.r.debug_information_part = 0;	}    }  flush();}  /* write the data in an ieee way */static voidDEFUN(ieee_write_data_part,(abfd),      bfd *abfd){  asection *s;  ieee_data_type *ieee = IEEE_DATA(abfd);  ieee->w.r.data_part = bfd_tell(abfd);  for (s = abfd->sections; s != (asection *)NULL; s = s->next)       {	/* Sort the reloc records so we can insert them in the correct	   places */	if (s->reloc_count != 0) 	    {	     do_with_relocs(abfd, s);	    }	else	    {	      do_without_relocs(abfd, s);	    }      }}static voidDEFUN(init_for_output,(abfd),      bfd *abfd){  asection *s;   for (s = abfd->sections; s != (asection *)NULL; s = s->next) {    if (s->_raw_size != 0) {      ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_raw_size));    }  }}/** exec and core file sections *//* set section contents is complicated with IEEE since the format is * not a byte image, but a record stream.*/booleanDEFUN(ieee_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 (ieee_per_section(section)->data == (bfd_byte *)NULL) {    init_for_output(abfd);  }  (void) memcpy((PTR)(ieee_per_section(section)->data + offset),		(PTR)location,		(unsigned int)count);  return true;}/*write the external symbols of a file, IEEE considers two sorts ofexternal symbols, public, and referenced. It uses to internal formsto index them as well. When we write them out we turn their symbolvalues into indexes from the right base.*/static voidDEFUN(ieee_write_external_part,(abfd),      bfd *abfd){  asymbol **q;  ieee_data_type *ieee = IEEE_DATA(abfd);  unsigned int reference_index = IEEE_REFERENCE_BASE;  unsigned int public_index = IEEE_PUBLIC_BASE+2;  file_ptr here = bfd_tell(abfd);  boolean hadone = false;  if (abfd->outsymbols != (asymbol **)NULL) {    for (q = abfd->outsymbols; *q  != (asymbol *)NULL; q++) {      asymbol *p = *q;      hadone = true;      if (p->section == &bfd_und_section) {	/* This must be a symbol reference .. */	ieee_write_byte(abfd, ieee_external_reference_enum);	ieee_write_int(abfd, reference_index);	ieee_write_id(abfd, p->name);	p->value = reference_index;	reference_index++;      }      else if(p->section == &bfd_com_section) {	/* This is a weak reference */	ieee_write_byte(abfd, ieee_external_reference_enum);	ieee_write_int(abfd, reference_index);	ieee_write_id(abfd, p->name);	ieee_write_byte(abfd, ieee_weak_external_reference_enum);	ieee_write_int(abfd, reference_index);	ieee_write_int(abfd, p->value);	ieee_write_int(abfd, BFD_FORT_COMM_DEFAULT_VALUE);	p->value = reference_index;	reference_index++;      }      else if(p->flags & BSF_GLOBAL) {	/* This must be a symbol definition */	ieee_write_byte(abfd, ieee_external_symbol_enum);	ieee_write_int(abfd, public_index );	ieee_write_id(abfd, p->name);	ieee_write_twobyte(abfd, ieee_attribute_record_enum);	ieee_write_int(abfd, public_index );	ieee_write_byte(abfd, 15);	 /* instruction address */	ieee_write_byte(abfd, 19);	/* static symbol */	ieee_write_byte(abfd, 1);	/* one of them */	/* Write out the value */	ieee_write_2bytes(abfd, ieee_value_record_enum);	ieee_write_int(abfd, public_index);	if (p->section != &bfd_abs_section)	    {	      if (abfd->flags & EXEC_P) 	      {		/* If fully linked, then output all symbols		   relocated */		ieee_write_int(abfd,			       p->value + p->section->output_offset+ p->section->output_section->vma);	      }	      else { 		  ieee_write_expression(abfd,					p->value + p->section->output_offset,					p->section->output_section->symbol					, false, 0);		}	    }	else	    {	      ieee_write_expression(abfd,				    p->value,				    bfd_abs_section.symbol,				    false, 0);	    }	p->value = public_index;	public_index++;      }      else {	/* This can happen - when there are gaps in the symbols read */	/* from an input ieee file */      }    }  }  if (hadone)    ieee->w.r.external_part = here;}CONST static unsigned char exten[] =   {    0xf0, 0x20, 0x00,					    0xf1, 0xce, 0x20, 0x00, 37, 3, 3,	/* Set version 3 rev 3   	*/    0xf1, 0xce, 0x20, 0x00, 39, 2,	/* keep symbol in  original case */    0xf1, 0xce, 0x20, 0x00, 38		/* set object type relocateable to x */  };CONST static unsigned char envi[] =  {    0xf0, 0x21, 0x00,/*    0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,    0x19, 0x2c, */    0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */    0xf1, 0xce, 0x21, 0, 53, 0x03,	/* host unix *//*    0xf1, 0xce, 0x21, 0, 54, 2,1,1	tool & version # */  };staticvoid DEFUN(ieee_write_me_part,(abfd),      bfd *abfd){  ieee_data_type *ieee= IEEE_DATA(abfd);  ieee->w.r.trailer_part = bfd_tell(abfd);  if (abfd->start_address) {    ieee->w.r.me_record = bfd_tell(abfd);    ieee_write_2bytes(abfd, ieee_value_starting_address_enum);    ieee_write_byte(abfd, ieee_function_either_open_b_enum);    ieee_write_int(abfd, abfd->start_address);    ieee_write_byte(abfd, ieee_function_either_close_b_enum);  }  else {    ieee->w.r.me_record = bfd_tell(abfd);  }  ieee_write_byte(abfd, ieee_module_end_enum);}booleanDEFUN(ieee_write_object_contents,(abfd),      bfd *abfd){  ieee_data_type *ieee = IEEE_DATA(abfd);  unsigned int i;  file_ptr   old;  /* Fast forward over the header area */  bfd_seek(abfd, (file_ptr) 0, SEEK_SET);  ieee_write_byte(abfd, ieee_module_beginning_enum);  ieee_write_id(abfd, bfd_printable_name(abfd));  ieee_write_id(abfd, abfd->filename);  /* Fast forward over the variable bits */	  ieee_write_byte(abfd, ieee_address_descriptor_enum);  /* Bits per MAU */  ieee_write_byte(abfd, bfd_arch_bits_per_byte(abfd));  /* MAU's per address */  ieee_write_byte(abfd, bfd_arch_bits_per_address(abfd)  /		  bfd_arch_bits_per_byte(abfd));  old = bfd_te

⌨️ 快捷键说明

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