home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1972 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  32.6 KB

  1. From: loic@adesign.uucp (Loic Dachary)
  2. Newsgroups: alt.sources
  3. Subject: gas-1.36 patches for COFF generation
  4. Message-ID: <LOIC.90Oct16093516@adesign.uucp>
  5. Date: 16 Oct 90 08:35:16 GMT
  6.  
  7. *** m68k.c    Wed May 16 16:47:44 1990
  8. --- /lasvegas/spare/usenet/port/gas-1.36/m68k.c    Sat Oct 13 09:21:00 1990
  9. ***************
  10. *** 22,27 ****
  11. --- 22,28 ----
  12.   #include <ctype.h>
  13.   
  14.   #include "m68k-opcode.h"
  15. + #include "oformat.h"
  16.   #include "as.h"
  17.   #include "obstack.h"
  18.   #include "frags.h"
  19. ***************
  20. *** 2669,2675 ****
  21.     know(fragP->fr_symbol);
  22.   
  23.     /* The displacement of the address, from current location.  */
  24. !   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  25.   
  26.     switch(fragP->fr_subtype) {
  27.     case TAB(BCC68000,BYTE):
  28. --- 2670,2676 ----
  29.     know(fragP->fr_symbol);
  30.   
  31.     /* The displacement of the address, from current location.  */
  32. !   disp = (S_GET_VALUE(fragP->fr_symbol) + fragP->fr_offset) - object_address;
  33.   
  34.     switch(fragP->fr_subtype) {
  35.     case TAB(BCC68000,BYTE):
  36. ***************
  37. *** 2798,2804 ****
  38.       /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  39.       switch(fragP->fr_subtype) {
  40.       case TAB(DBCC,SZ_UNDEF):
  41. !         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  42.               fragP->fr_subtype=TAB(DBCC,SHORT);
  43.               fragP->fr_var+=2;
  44.               break;
  45. --- 2799,2805 ----
  46.       /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  47.       switch(fragP->fr_subtype) {
  48.       case TAB(DBCC,SZ_UNDEF):
  49. !                 if(S_GET_SEGMENT(fragP->fr_symbol)==segtype) {
  50.               fragP->fr_subtype=TAB(DBCC,SHORT);
  51.               fragP->fr_var+=2;
  52.               break;
  53. ***************
  54. *** 2820,2826 ****
  55.           break;
  56.   
  57.       case TAB(BCC68000,SZ_UNDEF):
  58. !         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  59.               fragP->fr_subtype=TAB(BCC68000,BYTE);
  60.               break;
  61.           }
  62. --- 2821,2827 ----
  63.           break;
  64.   
  65.       case TAB(BCC68000,SZ_UNDEF):
  66. !                 if(S_GET_SEGMENT(fragP->fr_symbol)==segtype) {
  67.               fragP->fr_subtype=TAB(BCC68000,BYTE);
  68.               break;
  69.           }
  70. ***************
  71. *** 2839,2845 ****
  72.           break;
  73.   
  74.       case TAB(BRANCH,SZ_UNDEF):
  75. !         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  76.               fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  77.               break;
  78.           } else if(flagseen['m']) {
  79. --- 2840,2846 ----
  80.           break;
  81.   
  82.       case TAB(BRANCH,SZ_UNDEF):
  83. !         if(S_GET_SEGMENT(fragP->fr_symbol)==segtype) {
  84.               fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  85.               break;
  86.           } else if(flagseen['m']) {
  87. ***************
  88. *** 2880,2886 ****
  89.       case TAB(BRANCH,BYTE):
  90.               /* We can't do a short jump to the next instruction,
  91.                  so we force word mode.  */
  92. !         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  93.    fragP->fr_symbol->sy_frag==fragP->fr_next) {
  94.               fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  95.               fragP->fr_var+=2;
  96. --- 2881,2887 ----
  97.       case TAB(BRANCH,BYTE):
  98.               /* We can't do a short jump to the next instruction,
  99.                  so we force word mode.  */
  100. !         if(fragP->fr_symbol && S_GET_VALUE(fragP->fr_symbol)==0 &&
  101.    fragP->fr_symbol->sy_frag==fragP->fr_next) {
  102.               fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  103.               fragP->fr_var+=2;
  104. ***************
  105. *** 2887,2893 ****
  106.           }
  107.           break;
  108.       case TAB(FBRANCH,SZ_UNDEF):
  109. !         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  110.               fragP->fr_subtype=TAB(FBRANCH,SHORT);
  111.               fragP->fr_var+=2;
  112.           } else {
  113. --- 2888,2894 ----
  114.           }
  115.           break;
  116.       case TAB(FBRANCH,SZ_UNDEF):
  117. !         if(S_GET_SEGMENT(fragP->fr_symbol)==segtype) {
  118.               fragP->fr_subtype=TAB(FBRANCH,SHORT);
  119.               fragP->fr_var+=2;
  120.           } else {
  121. ***************
  122. *** 2896,2902 ****
  123.           }
  124.           break;
  125.       case TAB(PCREL,SZ_UNDEF):
  126. !         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  127.               fragP->fr_subtype=TAB(PCREL,SHORT);
  128.               fragP->fr_var+=2;
  129.           } else {
  130. --- 2897,2903 ----
  131.           }
  132.           break;
  133.       case TAB(PCREL,SZ_UNDEF):
  134. !         if(S_GET_SEGMENT(fragP->fr_symbol)==segtype) {
  135.               fragP->fr_subtype=TAB(PCREL,SHORT);
  136.               fragP->fr_var+=2;
  137.           } else {
  138. ***************
  139. *** 2910,2915 ****
  140. --- 2911,2917 ----
  141.       return fragP->fr_var + fragP->fr_fix - old_fix;
  142.   }
  143.   
  144. + #ifdef aout
  145.   /* the bit-field entries in the relocation_info struct plays hell 
  146.      with the byte-order problems of cross-assembly.  So as a hack,
  147.      I added this mach. dependent ri twiddler.  Ugly, but it gets
  148. ***************
  149. *** 2935,2940 ****
  150. --- 2937,2943 ----
  151.     /* now put it back where you found it */
  152.     bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  153.   }
  154. + #endif /* aout */
  155.   
  156.   #ifndef WORKING_DOT_WORD
  157.   int md_short_jump_size = 4;
  158. *** read.c    Tue Mar  6 22:08:29 1990
  159. --- /lasvegas/spare/usenet/port/gas-1.36/read.c    Mon Oct 15 11:31:29 1990
  160. ***************
  161. *** 35,40 ****
  162. --- 35,41 ----
  163.   #include <ctype.h>
  164.   #include <sys/types.h>
  165.   #include <sys/stat.h>
  166. + #include "oformat.h"
  167.   #include "as.h"
  168.   #include "read.h"
  169.   #include "md.h"
  170. ***************
  171. *** 115,121 ****
  172. --- 116,127 ----
  173.   static int        is_it_end_of_statement();
  174.   static void        pobegin();
  175.   static void        pseudo_set();
  176. + #ifdef coff
  177. + static void        def();
  178. + static void        line();
  179. + #else /* coff */
  180.   static void        stab();
  181. + #endif /* coff */
  182.   static void        stringer();
  183.   
  184.   extern char line_comment_chars[];
  185. ***************
  186. *** 131,136 ****
  187. --- 137,149 ----
  188.   static char *old_input;
  189.   static char *old_limit;
  190.   
  191. + #ifdef coff
  192. + static struct hash_control* tag_hash;
  193. + static void            tag_init();
  194. + static void            tag_insert();
  195. + static symbolS*            tag_find();
  196. + #endif /* coff */
  197.   #ifndef WORKING_DOT_WORD
  198.   struct broken_word *broken_words;
  199.   int new_broken_words = 0;
  200. ***************
  201. *** 143,148 ****
  202. --- 156,164 ----
  203.   read_begin()
  204.   {
  205.     pobegin();
  206. + #ifdef coff
  207. +   tag_init();
  208. + #endif /* coff */
  209.     obstack_begin( ¬es, 5000 );
  210.   #define BIGNUM_BEGIN_SIZE (16)
  211.     bignum_low = xmalloc((long)BIGNUM_BEGIN_SIZE);
  212. ***************
  213. *** 155,162 ****
  214.   po_hash = NULL;            /* use before set up: NULL-> address error */
  215.   
  216.   
  217.   void    s_abort(),    s_align(),    s_comm(),    s_data();
  218. ! void    s_desc(),    s_even(),    s_file(),    s_fill();
  219.   void    s_globl(),    s_lcomm(),    s_line(),    s_lsym();
  220.   void    s_org(),    s_set(),    s_space(),    s_text();
  221.   
  222. --- 171,181 ----
  223.   po_hash = NULL;            /* use before set up: NULL-> address error */
  224.   
  225.   
  226. + #ifdef aout
  227. + void s_desc();
  228. + #endif /* aout */
  229.   void    s_abort(),    s_align(),    s_comm(),    s_data();
  230. ! void    s_even(),    s_file(),    s_fill();
  231.   void    s_globl(),    s_lcomm(),    s_line(),    s_lsym();
  232.   void    s_org(),    s_set(),    s_space(),    s_text();
  233.   
  234. ***************
  235. *** 181,187 ****
  236. --- 200,208 ----
  237.     { "byte",    cons,        1    },
  238.     { "comm",    s_comm,        0    },
  239.     { "data",    s_data,        0    },
  240. + #ifdef aout
  241.     { "desc",    s_desc,        0    },
  242. + #endif /* aout */
  243.     { "double",    float_cons,    'd'    },
  244.     { "file",    s_file,        0    },
  245.     { "fill",    s_fill,        0    },
  246. ***************
  247. *** 207,215 ****
  248. --- 228,241 ----
  249.     { "short",    cons,        2    },
  250.     { "single",    float_cons,    'f'    },
  251.     { "space",    s_space,    0    },
  252. + #ifdef coff
  253. +   { "def",    def,        0    },
  254. +   { "ln",    line,        0    },
  255. + #else /* coff */
  256.     { "stabd",    stab,        'd'    },
  257.     { "stabn",    stab,        'n'    },
  258.     { "stabs",    stab,        's'    },
  259. + #endif /* coff */
  260.     { "text",    s_text,        0    },
  261.   #ifndef SPARC
  262.     { "word",    cons,        2    },
  263. ***************
  264. *** 570,588 ****
  265.       *p = 0;
  266.       symbolP = symbol_find_or_make (name);
  267.       *p = c;
  268. !     if (   (symbolP -> sy_type & N_TYPE) != N_UNDF ||
  269. !  symbolP -> sy_other != 0 || symbolP -> sy_desc != 0) {
  270.           as_warn( "Ignoring attempt to re-define symbol");
  271.           ignore_rest_of_line();
  272.           return;
  273.       }
  274. !     if (symbolP -> sy_value) {
  275. !         if (symbolP -> sy_value != temp)
  276.               as_warn( "Length of .comm \"%s\" is already %d. Not changed to %d.",
  277. !  symbolP -> sy_name, symbolP -> sy_value, temp);
  278.       } else {
  279. !         symbolP -> sy_value = temp;
  280. !         symbolP -> sy_type |= N_EXT;
  281.       }
  282.       know( symbolP -> sy_frag == &zero_address_frag );
  283.       demand_empty_rest_of_line();
  284. --- 596,619 ----
  285.       *p = 0;
  286.       symbolP = symbol_find_or_make (name);
  287.       *p = c;
  288. !     if (S_IS_DEFINED(symbolP) 
  289. ! #ifdef aout
  290. !         || S_GET_OTHER(symbolP) != 0 || S_GET_DESC(symbolP) != 0
  291. ! #endif /* aout */
  292. !         ) {
  293.           as_warn( "Ignoring attempt to re-define symbol");
  294.           ignore_rest_of_line();
  295.           return;
  296.       }
  297. !     if (S_GET_VALUE(symbolP)) {
  298. !         if (S_GET_VALUE(symbolP) != temp)
  299.               as_warn( "Length of .comm \"%s\" is already %d. Not changed to %d.",
  300. !                 S_GET_NAME(symbolP),
  301. !                 S_GET_VALUE(symbolP),
  302. !                 temp);
  303.       } else {
  304. !         S_SET_VALUE(symbolP, temp);
  305. !         S_SET_EXTERNAL(symbolP);
  306.       }
  307.       know( symbolP -> sy_frag == &zero_address_frag );
  308.       demand_empty_rest_of_line();
  309. ***************
  310. *** 598,603 ****
  311. --- 629,635 ----
  312.       demand_empty_rest_of_line();
  313.   }
  314.   
  315. + #ifdef aout
  316.   void
  317.   s_desc()
  318.   {
  319. ***************
  320. *** 627,648 ****
  321.           *p = 0;
  322.           symbolP = symbol_find_or_make (name);
  323.           *p = c;
  324. !         symbolP -> sy_desc = temp;
  325.       }
  326.       demand_empty_rest_of_line();
  327.   }
  328.   
  329.   void
  330.   s_file()
  331.   {
  332. !     register char *s;
  333. !     int    length;
  334. !     /* Some assemblers tolerate immediately following '"' */
  335. !     if ( s = demand_copy_string( & length ) ) {
  336. !         new_logical_line (s, -1);
  337. !         demand_empty_rest_of_line();
  338. !     }
  339.   }
  340.   
  341.   void
  342. --- 659,684 ----
  343.           *p = 0;
  344.           symbolP = symbol_find_or_make (name);
  345.           *p = c;
  346. !         S_SET_DESC(symbolP,temp);
  347.       }
  348.       demand_empty_rest_of_line();
  349.   }
  350. + #endif /* aout */
  351.   
  352.   void
  353.   s_file()
  354.   {
  355. !     register char *s;
  356. !     int    length;
  357. !     
  358. !     /* Some assemblers tolerate immediately following '"' */
  359. !     if ( s = demand_copy_string( & length ) ) {
  360. !     new_logical_line (s, -1);
  361. !     demand_empty_rest_of_line();
  362. !     }
  363. ! #ifdef coff
  364. !     c_dot_file_symbol(s);
  365. ! #endif /* coff */
  366.   }
  367.   
  368.   void
  369. ***************
  370. *** 825,831 ****
  371.           symbolP = symbol_find_or_make (name);
  372.           * input_line_pointer = c;
  373.           SKIP_WHITESPACE();
  374. !         symbolP -> sy_type |= N_EXT;
  375.           if(c==',') {
  376.               input_line_pointer++;
  377.               SKIP_WHITESPACE();
  378. --- 861,867 ----
  379.           symbolP = symbol_find_or_make (name);
  380.           * input_line_pointer = c;
  381.           SKIP_WHITESPACE();
  382. !         S_SET_EXTERNAL(symbolP);
  383.           if(c==',') {
  384.               input_line_pointer++;
  385.               SKIP_WHITESPACE();
  386. ***************
  387. *** 864,882 ****
  388.       *p = 0;
  389.       symbolP = symbol_find_or_make (name);
  390.       *p = c;
  391. !     if (   symbolP -> sy_other == 0
  392. !         && symbolP -> sy_desc  == 0
  393. !         && (   (   symbolP -> sy_type  == N_BSS
  394. !         && symbolP -> sy_value == local_bss_counter)
  395. !         || (   (symbolP -> sy_type & N_TYPE) == N_UNDF
  396. !         && symbolP -> sy_value == 0))) {
  397. !         symbolP -> sy_value = local_bss_counter;
  398. !         symbolP -> sy_type  = N_BSS;
  399.           symbolP -> sy_frag  = & bss_address_frag;
  400.           local_bss_counter += temp;
  401.       } else
  402.           as_warn( "Ignoring attempt to re-define symbol from %d. to %d.",
  403. !  symbolP -> sy_value, local_bss_counter );
  404.       demand_empty_rest_of_line();
  405.   }
  406.   
  407. --- 900,926 ----
  408.       *p = 0;
  409.       symbolP = symbol_find_or_make (name);
  410.       *p = c;
  411. !     if (
  412. ! #ifdef aout
  413. !         S_GET_OTHER(symbolP) == 0 &&
  414. !         S_GET_DESC(symbolP)  == 0 &&
  415. ! #endif /* aout */  
  416. !         (S_IS_BSS(symbolP) && S_GET_VALUE(symbolP) == local_bss_counter)
  417. ! /* What S_GET_VALUE(symbolP) == 0 is supposed to mean (in aout case) ? 
  418. !    In the coff case it clearly does not mean anything (the only case
  419. !    where a symbol is not defined is from an external declaration (extern a)
  420. !    and this kind of symbol have a 0 value. */
  421. !         || (!S_IS_DEFINED(symbolP) && S_GET_VALUE(symbolP) == 0)) {
  422. !         S_SET_VALUE(symbolP,local_bss_counter);
  423. !         S_SET_BSS(symbolP);
  424. ! #ifdef coff
  425. !         S_SET_STORAGE_CLASS(symbolP, C_STAT);
  426. ! #endif /* coff */
  427.           symbolP -> sy_frag  = & bss_address_frag;
  428.           local_bss_counter += temp;
  429.       } else
  430.           as_warn( "Ignoring attempt to re-define symbol from %d. to %d.",
  431. !  S_GET_VALUE(symbolP), local_bss_counter );
  432.       demand_empty_rest_of_line();
  433.   }
  434.   
  435. ***************
  436. *** 929,942 ****
  437.       segment = expression (& exp);
  438.       if (   segment != SEG_ABSOLUTE && segment != SEG_DATA &&
  439.    segment != SEG_TEXT && segment != SEG_BSS) {
  440. !         as_warn("Bad expression: %s", seg_name [(int)segment]);
  441.           ignore_rest_of_line();
  442.           return;
  443.       }
  444.    know(   segment == SEG_ABSOLUTE || segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS );
  445.       *p = 0;
  446. !     symbolP = symbol_new (name,(unsigned char)(seg_N_TYPE [(int) segment]),
  447.    0, 0, (valueT)(exp . X_add_number), & zero_address_frag);
  448.       *p = c;
  449.       demand_empty_rest_of_line();
  450.   }
  451. --- 973,991 ----
  452.       segment = expression (& exp);
  453.       if (   segment != SEG_ABSOLUTE && segment != SEG_DATA &&
  454.    segment != SEG_TEXT && segment != SEG_BSS) {
  455. !         as_warn("Bad expression: %s", segment_name((int)segment));
  456.           ignore_rest_of_line();
  457.           return;
  458.       }
  459.    know(   segment == SEG_ABSOLUTE || segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS );
  460.       *p = 0;
  461. ! #ifdef coff
  462. !     symbolP = symbol_new(name, segment, (valueT)(exp . X_add_number),
  463. !                  0, &zero_address_frag);
  464. ! #else /* coff */
  465. !     symbolP = symbol_new (name,(unsigned char)(seg_SEG((int) segment)),
  466.    0, 0, (valueT)(exp . X_add_number), & zero_address_frag);
  467. + #endif /* coff */
  468.       *p = c;
  469.       demand_empty_rest_of_line();
  470.   }
  471. ***************
  472. *** 972,978 ****
  473.       if ( ! need_pass_2 ) {
  474.           if (segment != now_seg && segment != SEG_ABSOLUTE)
  475.               as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  476. !  seg_name [(int) segment], seg_name [(int) now_seg]);
  477.           p = frag_var (rs_org, 1, 1, (relax_substateT)0, exp . X_add_symbol,
  478.    exp . X_add_number, (char *)0);
  479.           * p = temp_fill;
  480. --- 1021,1027 ----
  481.       if ( ! need_pass_2 ) {
  482.           if (segment != now_seg && segment != SEG_ABSOLUTE)
  483.               as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  484. !  segment_name((int) segment), segment_name((int) now_seg));
  485.           p = frag_var (rs_org, 1, 1, (relax_substateT)0, exp . X_add_symbol,
  486.    exp . X_add_number, (char *)0);
  487.           * p = temp_fill;
  488. ***************
  489. *** 1017,1023 ****
  490.         if ( ! need_pass_2 ) {
  491.           if (segment != now_seg && segment != SEG_ABSOLUTE)
  492.             as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  493. !               seg_name [(int) segment], seg_name [(int) now_seg]);
  494.           ptr = frag_var (rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
  495.                 exp.X_add_number, (char *)0);
  496.           *ptr= 0;
  497. --- 1066,1073 ----
  498.         if ( ! need_pass_2 ) {
  499.           if (segment != now_seg && segment != SEG_ABSOLUTE)
  500.             as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  501. !               segment_name((int) segment),
  502. !               segment_name((int) now_seg));
  503.           ptr = frag_var (rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
  504.                 exp.X_add_number, (char *)0);
  505.           *ptr= 0;
  506. ***************
  507. *** 1104,1109 ****
  508. --- 1154,1476 ----
  509.     know( is_end_of_line [input_line_pointer [-1]] );
  510.   }
  511.   
  512. + #ifdef coff
  513. + /*
  514. +  * Handle .ln directives.
  515. +  */
  516. + static void
  517. + line(what)
  518. + int what;
  519. + {
  520. +     c_line_new(obstack_next_free(&frags) - frag_now->fr_literal,
  521. +            get_absolute_expression(),
  522. +            frag_now);
  523. +     demand_empty_rest_of_line();
  524. +     return;
  525. + }
  526. + /*
  527. +  *            def()
  528. +  *
  529. +  * Handle .def directives.
  530. +  *
  531. +  * One would say : why can't we symbol_new if the symbol does not
  532. +  * allready exists and fill it with debug information. Because of
  533. +  * the C_EFCN special symbol. It would clobber the value of the
  534. +  * function symbol before we have a chance to notice that it is
  535. +  * a C_EFCN. And a second reason is that the code is more clear this
  536. +  * way. (at least I think it is:-).
  537. +  * 
  538. +  */
  539. + #define SKIP_SEMI_COLON()    while(*input_line_pointer++ != ';')
  540. + #define SKIP_WHITESPACES()    while(*input_line_pointer == ' ' || \
  541. +                       *input_line_pointer == '\t') \
  542. +                                          input_line_pointer++;
  543. + #define NEXT_DEF_DIRECTIVE()     SKIP_SEMI_COLON(); SKIP_WHITESPACES()
  544. + #define equal            !strcmp
  545. + #define MAX_DIRECTIVE        20
  546. + static void
  547. + def(what)
  548. + int what;
  549. + {
  550. +     char    name_end;        /* Char after the end of name */
  551. +     symbolS*    symbolP;        /* Debug symbol just created */
  552. +     symbolS    symbol;            /* Temporary symbol to hold .def */
  553. +     char*    symbol_name;        /* Name of the debug symbol */
  554. +     char*    symbol_name_copy;    /* Temporary copy of the name */
  555. +     unsigned int symbol_name_length;    /* */
  556. +     char*    directiveP;        /* Name of the pseudo opcode */
  557. +     char    directive[MAX_DIRECTIVE]; /* Backup of the directive */
  558. +     char    end = 0;        /* If 1, stop parsing */
  559. +     
  560. +     SKIP_WHITESPACES();
  561. +     symbolP = &symbol;
  562. +     memset((char*)symbolP, '\0', sizeof(symbolS));
  563. +     symbol_name = input_line_pointer;
  564. +     name_end = get_symbol_end();
  565. +     symbol_name_length = strlen(symbol_name);
  566. +     symbol_name_copy = xmalloc(symbol_name_length + 1);
  567. +     strcpy(symbol_name_copy, symbol_name);
  568. +     
  569. +     /* Initialize the new symbol */
  570. + #if STRIP_UNDERSCORE
  571. +     S_SET_NAME(symbolP, *symbol_name_copy == '_' ? symbol_name_copy + 1 :
  572. +                                                symbol_name_copy);
  573. + #else /* STRIP_UNDERSCORE */
  574. +     S_SET_NAME(symbolP, symbol_name_copy);
  575. + #endif /* STRIP_UNDERSCORE */
  576. +     symbolP->sy_name_offset = ~0;
  577. +     symbolP->sy_number = ~0;
  578. +     symbolP->sy_frag = &zero_address_frag;
  579. +     if(S_IS_STRING(symbolP))
  580. +     SF_SET_STRING(symbolP);
  581. +     *input_line_pointer = name_end;
  582. +     while(!end) {
  583. +     NEXT_DEF_DIRECTIVE();
  584. +     directiveP = input_line_pointer;
  585. +     name_end = get_symbol_end();
  586. +     strncpy(directive, directiveP, MAX_DIRECTIVE);
  587. +     *input_line_pointer = name_end;
  588. +     SKIP_WHITESPACES();
  589. +     switch(directive[1]) {
  590. +       case 'd':
  591. +         if(equal(directive, ".dim")) {
  592. +         register int dim_index;
  593. +         register int dimension;
  594. +         S_SET_NUMBER_AUXILIARY(symbolP, 1);
  595. +         for(dim_index = 0; dim_index < DIMNUM; dim_index++) {
  596. +             SKIP_WHITESPACES();
  597. +             SA_SET_SYM_DIMEN(symbolP, dim_index,
  598. +                      get_absolute_expression());
  599. +             switch(*input_line_pointer) {
  600. +               case ',':
  601. +             input_line_pointer++;
  602. +             break;
  603. +               default:
  604. +             as_warn("badly formed .dim directive");
  605. +               case ';':
  606. +             dim_index = DIMNUM;
  607. +             break;
  608. +             }
  609. +         }
  610. +         } else
  611. +         as_warn("unknown debug directive : %s", directive);
  612. +         break;
  613. +       case 'e':
  614. +         if(equal(directive, ".endef"))
  615. +         end = 1;
  616. +         else
  617. +         as_warn("unknown debug directive : %s", directive);
  618. +         break;
  619. +       case 'l':
  620. +         if(equal(directive, ".line")) {
  621. +         S_SET_NUMBER_AUXILIARY(symbolP, 1);
  622. +         SA_SET_SYM_LNNO(symbolP, get_absolute_expression());
  623. +         } else
  624. +         as_warn("unknown debug directive : %s", directive);
  625. +         break;
  626. +       case 's':
  627. +         if(equal(directive, ".size")) {
  628. +         S_SET_NUMBER_AUXILIARY(symbolP, 1);
  629. +         SA_SET_SYM_SIZE(symbolP, get_absolute_expression());
  630. +         } else if(equal(directive, ".scl"))
  631. +         S_SET_STORAGE_CLASS(symbolP, get_absolute_expression());
  632. +         else
  633. +         as_warn("unknown debug directive : %s", directive);
  634. +         break;
  635. +       case 't':
  636. +         if(equal(directive, ".tag")) {
  637. +         symbolS * tag_symbolP;
  638. +         S_SET_NUMBER_AUXILIARY(symbolP, 1);
  639. +         symbol_name = input_line_pointer;
  640. +         name_end = get_symbol_end();
  641. +         /* Assume that the symbol referred to by .tag is 
  642. +            always defined. */
  643. +         SA_SET_SYM_TAGNDX(symbolP, (long)tag_find(symbol_name));
  644. +         if(SA_GET_SYM_TAGNDX(symbolP) == 0L)
  645. +             as_warn("tag not found for .tag %s", symbol_name);
  646. +         SF_SET_TAGGED(symbolP);
  647. +         *input_line_pointer = name_end;
  648. +         } else if(equal(directive, ".type")) {
  649. +         S_SET_DATA_TYPE(symbolP, get_absolute_expression());
  650. +         if(ISFCN(S_GET_DATA_TYPE(symbolP)) &&
  651. +            S_GET_STORAGE_CLASS(symbolP) != C_TPDEF)
  652. +             SF_SET_FUNCTION(symbolP);
  653. +         } else
  654. +         as_warn("unknown debug directive : %s", directive);
  655. +         break;
  656. +       case 'v':
  657. +         if(equal(directive, ".val")) {
  658. +         if(is_name_beginner(*input_line_pointer)) {
  659. +             symbol_name = input_line_pointer;
  660. +             name_end = get_symbol_end();
  661. +             if(equal(symbol_name, ".")) {
  662. +             symbolP->sy_frag = frag_now;
  663. +             S_SET_VALUE(symbolP, obstack_next_free(&frags) -
  664. +                              frag_now->fr_literal);
  665. +             /* If the .val is != from the .def (i.e. statics) */
  666. +             } else if(strcmp(symbol_name_copy, symbol_name)) {
  667. +             register symbolS* forwardP;
  668. +             if(forwardP = symbol_find(symbol_name))
  669. +                 symbolP->sy_forward = forwardP;
  670. +             else
  671. +                 /* Create a new undefined symbol. */
  672. +                 symbolP->sy_forward =
  673. +                 symbol_new (symbol_name, SEG_UNKNOWN,
  674. +                         0, 0, &zero_address_frag);
  675. +             }
  676. +             /* Otherwise, it is the name of a non debug symbol and its
  677. +                value will be calculated later. */
  678. +             *input_line_pointer = name_end;
  679. +         } else
  680. +             S_SET_VALUE(symbolP, get_absolute_expression());
  681. +         } else
  682. +         as_warn("unknown debug directive : %s", directive);
  683. +         break;
  684. +       default:
  685. +         as_warn("unknown debug directive : %s", directive);
  686. +         break;
  687. +     }
  688. +     }
  689. +     demand_empty_rest_of_line();
  690. +     /* Set the section number according to storage class. */
  691. +     switch(S_GET_STORAGE_CLASS(symbolP)) {
  692. +       case C_STRTAG: case C_ENTAG: case C_UNTAG:
  693. +     SF_SET_TAG(symbolP);
  694. +       case C_FILE:
  695. +       case C_TPDEF:
  696. +     SF_SET_DEBUG(symbolP);
  697. +     S_SET_SEGMENT(symbolP, C_DEBUG_SECTION);
  698. +     break;
  699. +       case C_EFCN:
  700. +     SF_SET_LOCAL(symbolP);   /* Do not emit this symbol. */
  701. +       case C_BLOCK:
  702. +     SF_SET_PROCESS(symbolP); /* Will need processing before writing */
  703. +       case C_FCN:
  704. +     S_SET_SEGMENT(symbolP, C_TEXT_SECTION);
  705. +     break;
  706. +       case C_AUTO:
  707. +       case C_REG:
  708. +       case C_MOS: case C_MOE: case C_MOU:
  709. +       case C_ARG:
  710. +       case C_REGPARM:
  711. +       case C_FIELD:
  712. +       case C_EOS:
  713. +     SF_SET_DEBUG(symbolP);
  714. +     S_SET_SEGMENT(symbolP, C_ABS_SECTION);
  715. +     break;
  716. +       case C_EXT:
  717. +       case C_STAT:
  718. +     /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
  719. +     break;
  720. +       case C_USTATIC:
  721. +       case C_EXTDEF:
  722. +       case C_LABEL:
  723. +       case C_ULABEL:
  724. +     as_warn("unexpected storage class %d", S_GET_STORAGE_CLASS(symbolP));
  725. +     break;
  726. +     }
  727. +     /* Now that we have build up a debug symbol, try to find if we should
  728. +        merge with an existing symbol or not. */
  729. +     /* If symbol does not exist, or symbol is a end function mark,
  730. +        or symbol is in debug or abs section,
  731. +        insert it in the list of symbols. */
  732. +     if(S_GET_STORAGE_CLASS(symbolP) == C_EFCN ||
  733. +        S_GET_SEGMENT(symbolP) == C_DEBUG_SECTION ||
  734. +        S_GET_SEGMENT(symbolP) == C_ABS_SECTION ||
  735. +        (symbolP = symbol_find_base(S_GET_NAME(symbolP), DO_NOT_STRIP)) ==
  736. +     (symbolS*)0) {
  737. +     symbolP = (symbolS *)obstack_alloc(¬es, sizeof(symbolS));
  738. +     memcpy((char*)symbolP, &symbol, sizeof(symbolS));
  739. +     symbol_lastP->sy_next = symbolP;
  740. +     symbolP->sy_previous = symbol_lastP;
  741. +     symbol_lastP = symbolP;
  742. +     } else {
  743. +     /* This symbol allready exists, merge the newly created symbol into
  744. +        the old one. This is not mandatory. The linker can handle
  745. +        duplicate symbols correctly. But I guess that it save a *lot*
  746. +        of space if the assembly file defines a lot of symbols. */
  747. +     /* The debug entry (symbol) is merged into symbolP. */
  748. +     c_symbol_merge(&symbol, symbolP);
  749. +     /* For the function, the symbol *must* be were the debug symbol
  750. +        appear. Move the existing symbol to the current place. */
  751. +     /* Do not take in account special cases where symbolP is first 
  752. +        in the list. It is always after a .bf */
  753. +     if(SF_GET_FUNCTION(symbolP)) {
  754. +         /* If it already is at the end of the symbol list, do nothing */
  755. +         if(symbolP != symbol_lastP) {
  756. +         /* Remove from the list */
  757. +         symbolP->sy_next->sy_previous = symbolP->sy_previous;
  758. +         symbolP->sy_previous->sy_next = symbolP->sy_next;
  759. +         /* Append at the end of the list */
  760. +         symbol_lastP->sy_next = symbolP;
  761. +         symbolP->sy_previous = symbol_lastP;
  762. +         symbol_lastP = symbolP;
  763. +         }
  764. +     } else
  765. +         free(symbol_name_copy);
  766. +     }
  767. +     
  768. +     /* If symbol is a {structure,union} tag, associate symbol to its name. */
  769. +     if(SF_GET_TAG(symbolP))
  770. +     tag_insert(S_GET_NAME(symbolP), symbolP);
  771. +     /* Create the line number entry pointing on the function being defined */
  772. +     if(SF_GET_FUNCTION(symbolP)) {
  773. +     c_line_new((long)S_GET_NAME(symbolP), 0, &zero_address_frag);
  774. +     SF_SET_PROCESS(symbolP);
  775. +     }
  776. + }
  777. + /* 
  778. +  *  Maintain a list of the tagnames of the structres.
  779. +  */
  780. + static void
  781. + tag_init()
  782. + {
  783. +     tag_hash = hash_new();
  784. +     return ;
  785. + }
  786. + static void
  787. + tag_insert(name, symbolP)
  788. + char* name;
  789. + symbolS* symbolP;
  790. + {
  791. +     register char *    error_string;
  792. +     if(*(error_string = hash_jam (tag_hash, name, (char *)symbolP))) {
  793. +     as_fatal("Inserting \"%s\" into structure table failed: %s",
  794. +          name, error_string);
  795. +     }
  796. +     return ;
  797. + }
  798. + static symbolS*
  799. + tag_find(name)
  800. + char* name;
  801. + {
  802. + #if STRIP_UNDERSCORE
  803. +     if(*name == '_') name++;
  804. + #endif /* STRIP_UNDERSCORE */
  805. +     return((symbolS*)hash_find(tag_hash, name));
  806. + }
  807. + #else /* coff */
  808.   /*
  809.    *            stab()
  810.    *
  811. ***************
  812. *** 1158,1165 ****
  813.           symbolP = symbol_new (string, 0,0,0,0,(struct frag *)0);
  814.           switch (what) {
  815.           case 'd':
  816. !             symbolP->sy_name = NULL; /* .stabd feature. */
  817. !             symbolP->sy_value = obstack_next_free(& frags) - frag_now->fr_literal;
  818.               symbolP->sy_frag = frag_now;
  819.               break;
  820.   
  821. --- 1525,1533 ----
  822.           symbolP = symbol_new (string, 0,0,0,0,(struct frag *)0);
  823.           switch (what) {
  824.           case 'd':
  825. !             S_SET_NAME(symbolP,NULL); /* .stabd feature. */
  826. !             S_SET_VALUE(symbolP,obstack_next_free(&frags) - 
  827. !                     frag_now->fr_literal);
  828.               symbolP->sy_frag = frag_now;
  829.               break;
  830.   
  831. ***************
  832. *** 1185,1191 ****
  833.       }
  834.       if (! goof) {
  835.           if (get_absolute_expression_and_terminator (& longint) == ',')
  836. !             symbolP->sy_other = longint;
  837.           else {
  838.               as_warn( "I want a comma after the n_other expression" );
  839.               goof = TRUE;
  840. --- 1553,1559 ----
  841.       }
  842.       if (! goof) {
  843.           if (get_absolute_expression_and_terminator (& longint) == ',')
  844. !             S_SET_OTHER(symbolP,longint);
  845.           else {
  846.               as_warn( "I want a comma after the n_other expression" );
  847.               goof = TRUE;
  848. ***************
  849. *** 1193,1199 ****
  850.           }
  851.       }
  852.       if (! goof) {
  853. !         symbolP->sy_desc = get_absolute_expression ();
  854.           if (what == 's' || what == 'n') {
  855.               if (* input_line_pointer != ',') {
  856.                   as_warn( "I want a comma after the n_desc expression" );
  857. --- 1561,1567 ----
  858.           }
  859.       }
  860.       if (! goof) {
  861. !         S_SET_DESC(symbolP, get_absolute_expression ());
  862.           if (what == 's' || what == 'n') {
  863.               if (* input_line_pointer != ',') {
  864.                   as_warn( "I want a comma after the n_desc expression" );
  865. ***************
  866. *** 1212,1217 ****
  867. --- 1580,1586 ----
  868.       else
  869.           demand_empty_rest_of_line ();
  870.   }
  871. + #endif /* coff */
  872.   
  873.   /*
  874.    *            pseudo_set()
  875. ***************
  876. *** 1230,1239 ****
  877.   {
  878.     expressionS    exp;
  879.     register segT    segment;
  880.     int ext;
  881.   
  882.     know( symbolP );        /* NULL pointer is logic error. */
  883. !   ext=(symbolP->sy_type&N_EXT);
  884.     if ((segment = expression( & exp )) == SEG_NONE)
  885.       {
  886.         as_warn( "Missing expression: absolute 0 assumed" );
  887. --- 1599,1612 ----
  888.   {
  889.     expressionS    exp;
  890.     register segT    segment;
  891. + #ifdef aout
  892.     int ext;
  893. + #endif /* aout */
  894.   
  895.     know( symbolP );        /* NULL pointer is logic error. */
  896. ! #ifdef aout
  897. !   ext=S_IS_EXTERNAL(symbolP);
  898. ! #endif /* aout */
  899.     if ((segment = expression( & exp )) == SEG_NONE)
  900.       {
  901.         as_warn( "Missing expression: absolute 0 assumed" );
  902. ***************
  903. *** 1245,1272 ****
  904.       case SEG_BIG:
  905.         as_warn( "%s number illegal. Absolute 0 assumed.",
  906.             exp . X_add_number > 0 ? "Bignum" : "Floating-Point" );
  907. !       symbolP -> sy_type = N_ABS | ext;
  908. !       symbolP -> sy_value = 0;
  909.         symbolP -> sy_frag = & zero_address_frag;
  910.         break;
  911.   
  912.       case SEG_NONE:
  913.         as_warn("No expression:  Using absolute 0");
  914. !       symbolP -> sy_type = N_ABS | ext;
  915. !       symbolP -> sy_value = 0;
  916.         symbolP -> sy_frag = & zero_address_frag;
  917.         break;
  918.   
  919.       case SEG_DIFFERENCE:
  920.         if (exp.X_add_symbol && exp.X_subtract_symbol
  921. !           &&    (exp.X_add_symbol->sy_type & N_TYPE)
  922. !          == (exp.X_subtract_symbol->sy_type & N_TYPE))
  923.       exp.X_add_number+=exp.X_add_symbol->sy_value - exp.X_subtract_symbol->sy_value;
  924.         else
  925.       as_warn( "Complex expression. Absolute segment assumed." );
  926.       case SEG_ABSOLUTE:
  927. !       symbolP -> sy_type = N_ABS | ext;
  928. !       symbolP -> sy_value = exp . X_add_number;
  929.         symbolP -> sy_frag = & zero_address_frag;
  930.         break;
  931.    
  932. --- 1618,1657 ----
  933.       case SEG_BIG:
  934.         as_warn( "%s number illegal. Absolute 0 assumed.",
  935.             exp . X_add_number > 0 ? "Bignum" : "Floating-Point" );
  936. !       S_SET_ABS(symbolP); 
  937. ! #ifdef aout
  938. !       ext ? S_SET_EXTERNAL(symbolP) : 
  939. !         S_CLEAR_EXTERNAL(symbolP);
  940. ! #endif /* aout */
  941. !       S_SET_VALUE(symbolP, 0);
  942.         symbolP -> sy_frag = & zero_address_frag;
  943.         break;
  944.   
  945.       case SEG_NONE:
  946.         as_warn("No expression:  Using absolute 0");
  947. !       S_SET_ABS(symbolP); 
  948. ! #ifdef aout
  949. !       ext ? S_SET_EXTERNAL(symbolP) : 
  950. !         S_CLEAR_EXTERNAL(symbolP);
  951. ! #endif /* aout */
  952. !       S_SET_VALUE(symbolP, 0);
  953.         symbolP -> sy_frag = & zero_address_frag;
  954.         break;
  955.   
  956.       case SEG_DIFFERENCE:
  957.         if (exp.X_add_symbol && exp.X_subtract_symbol
  958. !           && (S_GET_SEGMENT(exp.X_add_symbol) ==
  959. !           S_GET_SEGMENT(exp.X_subtract_symbol)))
  960.       exp.X_add_number+=exp.X_add_symbol->sy_value - exp.X_subtract_symbol->sy_value;
  961.         else
  962.       as_warn( "Complex expression. Absolute segment assumed." );
  963.       case SEG_ABSOLUTE:
  964. !       S_SET_ABS(symbolP); 
  965. ! #ifdef aout
  966. !       ext ? S_SET_EXTERNAL(symbolP) : 
  967. !         S_CLEAR_EXTERNAL(symbolP);
  968. ! #endif /* aout */
  969. !       S_SET_VALUE(symbolP, exp.X_add_number);
  970.         symbolP -> sy_frag = & zero_address_frag;
  971.         break;
  972.    
  973. ***************
  974. *** 1273,1280 ****
  975.       case SEG_DATA:
  976.       case SEG_TEXT:
  977.       case SEG_BSS:
  978. !       symbolP -> sy_type = seg_N_TYPE [(int) segment] | ext;
  979. !       symbolP -> sy_value= exp . X_add_number + exp . X_add_symbol -> sy_value;
  980.         symbolP -> sy_frag = exp . X_add_symbol -> sy_frag;
  981.         break;
  982.         
  983. --- 1658,1673 ----
  984.       case SEG_DATA:
  985.       case SEG_TEXT:
  986.       case SEG_BSS:
  987. !       switch(segment) {
  988. !     case SEG_DATA:      S_SET_DATA(symbolP); break;
  989. !     case SEG_TEXT:      S_SET_TEXT(symbolP); break;
  990. !     case SEG_BSS:      S_SET_BSS(symbolP); break;
  991. !       }
  992. ! #ifdef aout
  993. !       ext ? S_SET_EXTERNAL(symbolP) : 
  994. !         S_CLEAR_EXTERNAL(symbolP);
  995. ! #endif /* aout */
  996. !       S_SET_VALUE(symbolP, exp.X_add_number + S_GET_VALUE(exp.X_add_symbol));
  997.         symbolP -> sy_frag = exp . X_add_symbol -> sy_frag;
  998.         break;
  999.         
  1000. ***************
  1001. *** 1371,1378 ****
  1002.         if ( segment == SEG_DIFFERENCE && exp . X_add_symbol == NULL )
  1003.           {
  1004.             as_warn( "Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
  1005. !               exp . X_subtract_symbol -> sy_name,
  1006. !               seg_name [(int) N_TYPE_seg [exp . X_subtract_symbol -> sy_type & N_TYPE]]);
  1007.             segment = SEG_ABSOLUTE;
  1008.             /* Leave exp . X_add_number alone. */
  1009.           }
  1010. --- 1764,1771 ----
  1011.         if ( segment == SEG_DIFFERENCE && exp . X_add_symbol == NULL )
  1012.           {
  1013.             as_warn( "Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
  1014. !          S_GET_NAME(exp.X_subtract_symbol),
  1015. !              segment_name((int)SEG_seg(S_GET_SEGMENT(exp.X_subtract_symbol))));
  1016.             segment = SEG_ABSOLUTE;
  1017.             /* Leave exp . X_add_number alone. */
  1018.           }
  1019. ***************
  1020. *** 1853,1860 ****
  1021.     if (   (retval = get_segmented_expression (expP)) == SEG_UNKNOWN
  1022.         )
  1023.       {
  1024. !       name1 = expP -> X_add_symbol ? expP -> X_add_symbol -> sy_name : "";
  1025. !       name2 = expP -> X_subtract_symbol ? expP -> X_subtract_symbol -> sy_name : "";
  1026.         if ( name1 && name2 )
  1027.       {
  1028.         as_warn("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
  1029. --- 2246,2255 ----
  1030.     if (   (retval = get_segmented_expression (expP)) == SEG_UNKNOWN
  1031.         )
  1032.       {
  1033. !       name1 = expP->X_add_symbol ? S_GET_NAME(expP->X_add_symbol) : "";
  1034. !       name2 = expP->X_subtract_symbol ?
  1035. !           S_GET_NAME(expP->X_subtract_symbol) :
  1036. !           "";
  1037.         if ( name1 && name2 )
  1038.       {
  1039.         as_warn("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
  1040. ***************
  1041. *** 1988,1994 ****
  1042.   equals(sym_name)
  1043.   char *sym_name;
  1044.   {
  1045. !   register struct symbol * symbolP; /* symbol we are working with */
  1046.   
  1047.     if(sym_name[0]=='.' && sym_name[1]=='\0') {
  1048.       /* Turn '. = mumble' into a .org mumble */
  1049. --- 2383,2389 ----
  1050.   equals(sym_name)
  1051.   char *sym_name;
  1052.   {
  1053. !   register symbolS * symbolP; /* symbol we are working with */
  1054.   
  1055.     if(sym_name[0]=='.' && sym_name[1]=='\0') {
  1056.       /* Turn '. = mumble' into a .org mumble */
  1057. ***************
  1058. *** 2006,2012 ****
  1059.       if ( ! need_pass_2 ) {
  1060.         if (segment != now_seg && segment != SEG_ABSOLUTE)
  1061.           as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  1062. !                 seg_name [(int) segment], seg_name [(int) now_seg]);
  1063.         p = frag_var (rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
  1064.                       exp.X_add_number, (char *)0);
  1065.         * p = 0;
  1066. --- 2401,2408 ----
  1067.       if ( ! need_pass_2 ) {
  1068.         if (segment != now_seg && segment != SEG_ABSOLUTE)
  1069.           as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
  1070. !                 segment_name((int) segment),
  1071. !         segment_name((int) now_seg));
  1072.         p = frag_var (rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
  1073.                       exp.X_add_number, (char *)0);
  1074.         * p = 0;
  1075. --
  1076. Loic Dachary     loic@adesign.uucp or loic@afp.uucp 
  1077. Voice        +33 1 40 35 20 20
  1078.