home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / config / sparc / next.c < prev    next >
C/C++ Source or Header  |  1996-06-12  |  4KB  |  112 lines

  1. /* next.c:  Functions for NeXT as target machine for GNU C compiler.  */
  2.  
  3. #include "sparc/sparc.c"
  4. #include "next/nextstep.c"
  5. #include "next/machopic.h"
  6.  
  7. #define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N)        \
  8.   do {                                \
  9.     const char *symbol_ = (SYMBOL);                \
  10.     char *buffer_ = (BUF);                    \
  11.     if (symbol_[0] == '"')                    \
  12.       {                                \
  13.         sprintf(buffer_, "\"L%d$%s", (N), symbol_+1);        \
  14.       }                                \
  15.     else if (name_needs_quotes(symbol_))            \
  16.       {                                \
  17.         sprintf(buffer_, "\"L%d$%s\"", (N), symbol_);        \
  18.       }                                \
  19.     else                            \
  20.       {                                \
  21.         sprintf(buffer_, "L%d$%s", (N), symbol_);        \
  22.       }                                \
  23.   } while (0)
  24.  
  25. // Generate PIC and indirect symbol stubs 
  26. void
  27. machopic_output_stub (file, symb, stub)
  28.      FILE *file;
  29.      const char *symb, *stub;
  30. {
  31.   unsigned int length;
  32.   char *binder_name, *symbol_name, *lazy_ptr_name;
  33.   char *local_label_0, *local_label_1, *local_label_2;
  34.   static int label = 0;
  35.  
  36.   label += 1;
  37.  
  38.   length = strlen(stub);
  39.   binder_name = alloca(length + 32);
  40.   GEN_BINDER_NAME_FOR_STUB(binder_name, stub, length);
  41.  
  42.   length = strlen(symb);
  43.   symbol_name = alloca(length + 32);
  44.   GEN_SYMBOL_NAME_FOR_SYMBOL(symbol_name, symb, length);
  45.  
  46.   lazy_ptr_name = alloca(length + 32);
  47.   GEN_LAZY_PTR_NAME_FOR_SYMBOL(lazy_ptr_name, symb, length);
  48.  
  49.   local_label_0 = alloca(length + 32);
  50.   GEN_LOCAL_LABEL_FOR_SYMBOL(local_label_0, symb, length, 0);
  51.  
  52.   local_label_1 = alloca(length + 32);
  53.   GEN_LOCAL_LABEL_FOR_SYMBOL(local_label_1, symb, length, 1);
  54.  
  55.   local_label_2 = alloca(length + 32);
  56.   GEN_LOCAL_LABEL_FOR_SYMBOL(local_label_2, symb, length, 2);
  57.  
  58.   if (MACHOPIC_PURE)
  59.     machopic_picsymbol_stub_section ();
  60.   else
  61.     machopic_symbol_stub_section ();
  62.  
  63.   fprintf (file, "%s:\n", stub);
  64.   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
  65.  
  66.   if (MACHOPIC_PURE) {
  67.       fprintf(file, "\tmov %%o7,%%g4\n");
  68.       fprintf(file, "%s:\n\tcall %s\n", local_label_0, local_label_1);
  69.       fprintf(file, "\tsethi %%hi(%s-%s),%%g6\n",
  70.           lazy_ptr_name, local_label_0);
  71.       fprintf(file, "%s:\n\tor %%g6,%%lo(%s-%s),%%g6\n", local_label_1,
  72.           lazy_ptr_name, local_label_0);
  73.       fprintf(file, "\tld [%%g6+%%o7],%%g6\n");
  74.       fprintf(file, "\tjmp %%g6\n");
  75.       fprintf(file, "\tmov %%g4,%%o7\n");
  76.   } else {
  77.       fprintf(file, "\tsethi %%hi(%s),%%g6\n", lazy_ptr_name);
  78.       fprintf(file, "\tld [%%g6+%%lo(%s),%g6\n", lazy_ptr_name);
  79.       fprintf(file, "\tjmp %g6\n\tnop\n");
  80.   }
  81.   
  82.   fprintf (file, "%s:\n", binder_name);
  83.   
  84.   if (MACHOPIC_PURE) {
  85.       char *binder = machopic_non_lazy_ptr_name ("*dyld_stub_binding_helper");
  86.       machopic_validate_non_lazy_ptr (binder);
  87.  
  88.       if (binder[0] == '*') 
  89.       binder += 1;
  90.       fprintf(file, "\tcall %s\n", local_label_2);
  91.       fprintf(file, "\tsethi %%hi(%s-%s),%%g6\n", binder, binder_name);
  92.       fprintf(file, "%s:\n\tor %%g6,%%lo(%s-%s),%%g6\n", local_label_2,
  93.           binder, binder_name);
  94.       fprintf(file, "\tld [%%g6+%%o7],%%g6\n");
  95.       fprintf(file, "\tsethi %%hi(%s-%s),%%g5\n", lazy_ptr_name, binder_name);
  96.       fprintf(file, "\tor %%g5,%%lo(%s-%s),%%g5\n", lazy_ptr_name,
  97.           binder_name);
  98.       fprintf(file, "\tjmp %%g6\n\tadd %%g5,%%o7,%%g5\n");
  99.   } else {
  100.       fprintf(file, "\tsethi %%hi(%s),%%g5\n", lazy_ptr_name);
  101.       fprintf(file, "\tsethi %%hi(dyld_stub_binding_helper),%%g6\n");
  102.       fprintf(file, "\tjmp %%g6+%%lo(dyld_stub_binding_helper\n");
  103.       fprintf(file, "\tor %%g5,%%lo(%s),%%g5\n", lazy_ptr_name);
  104.   }
  105.  
  106.   machopic_lazy_symbol_ptr_section ();
  107.   fprintf (file, "%s:\n", lazy_ptr_name);
  108.   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
  109.   fprintf (file, "\t.long %s\n", binder_name);
  110. }
  111.  
  112.