[gnu.utils.bug] GAS for Sun-2s

dupuy@CS.COLUMBIA.EDU (Alexander Dupuy) (09/28/89)

In order to use GAS properly on the Sun-2, it is necessary to make the default
ouput be for 68000, however, it should still be possible to generate 68020 code
if desired.  Sun allows this via the -m68010 and -m68020 flags, which work on
both Sun-2 and Sun-3 assemblers, with the obvious default on each machine.  It
seemed helpful in doing this to clearly separate whether or not a -m flag had
been given from the type of cpu for which code was being generated.  This will
be useful if/when Motorola adds additional instructions/modes/... in the 68040.

In addition, it seems useful to support generating a.out files with the old
magic number OMAGIC rather than (1<<16)|OMAGIC, for Sun-2s running releases
prior to 3.0, or other 68000 boxes; this can be supported by a -m68000 flag.

Here are context diffs to m-sun3.h and m68k.c from the 1.34 (not I guess) GAS
which make those changes.  They have been tested on a Sun-2 running 4.0.

*** /tmp/,RCSt1a20311	Wed Sep 27 19:55:29 1989
--- m-sun3.h	Wed Sep 27 19:47:47 1989
***************
*** 1,4 ****
! /* m-sun3.h -- 68020 version of the assembler for the Sun-3
     Copyright (C) 1987 Free Software Foundation, Inc.
  
  This file is part of GAS, the GNU Assembler.
--- 1,4 ----
! /* m-sun3.h -- 680[12]0 version of the assembler for the Sun-[23]
     Copyright (C) 1987 Free Software Foundation, Inc.
  
  This file is part of GAS, the GNU Assembler.
***************
*** 19,31 ****
  
  
  
! /* This header file contains the #defines specific
!    to SUN computer SUN 3 series computers.  (The only kind
!    we have around here, unfortunatly.)
!    
!    Rumor has it that this file will work on the Sun-2 if the assembler
!    is called with -m68010  This is not tested.  */
  
  
  #define M_SUN	1
  #define SUN_ASM_SYNTAX
--- 19,28 ----
  
  
  
! /* This header file contains the #defines specific to SUN computers running
!    version 3.0 or later.  */
  
+ /* #define CPU mc68000 /* for Sun-2, undefine this line */
  
  #define M_SUN	1
  #define SUN_ASM_SYNTAX
*** /tmp/,RCSt1a20311	Wed Sep 27 19:55:30 1989
--- m68k.c	Wed Sep 27 19:48:19 1989
***************
*** 32,43 ****
  #include "md.h"
  #include "m68k.h"
  
  #ifdef M_SUN
  /* This variable contains the value to write out at the beginning of
!    the a.out file.  The 2<<16 means that this is a 68020 file instead
!    of an old-style 68000 file */
  
! long omagic = 2<<16|OMAGIC;	/* Magic byte for header file */
  #else
  long omagic = OMAGIC;
  #endif
--- 32,51 ----
  #include "md.h"
  #include "m68k.h"
  
+ #ifndef CPU
+ #define CPU 2
+ #endif
+ 
+ #undef mc68000
+ #undef mc68020
+ 
+ static enum { mc68000=1, mc68020=2 } cputype = CPU;
+ 
  #ifdef M_SUN
  /* This variable contains the value to write out at the beginning of
!    the a.out file. */
  
! long omagic = ((int)CPU)<<16|OMAGIC;	/* Magic byte for header file */
  #else
  long omagic = OMAGIC;
  #endif
***************
*** 1596,1602 ****
  					   !subs(opP->con1) &&
  					   seg(opP->con1)==SEG_TEXT &&
   					   now_seg==SEG_TEXT &&
! 					   flagseen['m']==0 &&
  					    !index("~%&$?", s[0])) {
  						tmpreg=0x3A; /* 7.2 */
  						add_frag(adds(opP->con1),
--- 1604,1610 ----
  					   !subs(opP->con1) &&
  					   seg(opP->con1)==SEG_TEXT &&
   					   now_seg==SEG_TEXT &&
! 					   cputype!=mc68000 &&
  					    !index("~%&$?", s[0])) {
  						tmpreg=0x3A; /* 7.2 */
  						add_frag(adds(opP->con1),
***************
*** 1718,1724 ****
  					addword(0);
  					addword(0);
  				} else if(adds(opP->con1)) {
! 					if (flagseen['m'] && 
  					    (the_ins.opcode[0] >= 0x6200) &&
  					    (the_ins.opcode[0] <= 0x6f00)) {
  					  add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
--- 1726,1732 ----
  					addword(0);
  					addword(0);
  				} else if(adds(opP->con1)) {
! 					if (cputype==mc68000 && 
  					    (the_ins.opcode[0] >= 0x6200) &&
  					    (the_ins.opcode[0] <= 0x6f00)) {
  					  add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
***************
*** 2683,2689 ****
      ext=2;
      break;
    case TAB(BRANCH,LONG):
!     if(flagseen['m']) {
        if(fragP->fr_opcode[0]==0x61) {
  	fragP->fr_opcode[0]= 0x4E;
  	fragP->fr_opcode[1]= 0xB9;	/* JBSR with ABSL LONG offset */
--- 2691,2697 ----
      ext=2;
      break;
    case TAB(BRANCH,LONG):
!     if(cputype==mc68000) {
        if(fragP->fr_opcode[0]==0x61) {
  	fragP->fr_opcode[0]= 0x4E;
  	fragP->fr_opcode[1]= 0xB9;	/* JBSR with ABSL LONG offset */
***************
*** 2834,2840 ****
  		if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
                          fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
                          break;
! 		} else if(flagseen['m']) {
  		  if(fragP->fr_opcode[0]==0x61) {
  		    fragP->fr_opcode[0]= 0x4E;
  		    fragP->fr_opcode[1]= 0xB9;	/* JBSR with ABSL LONG offset */
--- 2842,2848 ----
  		if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
                          fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
                          break;
! 		} else if(cputype==mc68000) {
  		  if(fragP->fr_opcode[0]==0x61) {
  		    fragP->fr_opcode[0]= 0x4E;
  		    fragP->fr_opcode[1]= 0xB9;	/* JBSR with ABSL LONG offset */
***************
*** 2958,2964 ****
  {
  	long offset;
  
! 	if(flagseen['m']) {
  		offset=to_addr-to_symbol->sy_value;
  		md_number_to_chars(ptr  ,(long)0x4EF9,2);
  		md_number_to_chars(ptr+2,(long)offset,4);
--- 2966,2972 ----
  {
  	long offset;
  
! 	if(cputype==mc68000) {
  		offset=to_addr-to_symbol->sy_value;
  		md_number_to_chars(ptr  ,(long)0x4EF9,2);
  		md_number_to_chars(ptr+2,(long)offset,4);
***************
*** 3194,3213 ****
  		break;
  
  	case 'm':
! 		/* Gas simply ignores this option! */
  		(*argP)++;
  		if(**argP=='c')
  			(*argP)++;
! 		if(!strcmp(*argP,"68000"))
! 			flagseen['m']=2;
! 		else if(!strcmp(*argP,"68010")) {
  #ifdef M_SUN
  			omagic= 1<<16|OMAGIC;
  #endif
  			flagseen['m']=1;
! 		} else if(!strcmp(*argP,"68020"))
! 			flagseen['m']=0;
! 		else
  			as_warn("Unknown -m option ignored");
  		while(**argP)
  			(*argP)++;
--- 3202,3227 ----
  		break;
  
  	case 'm':
! 		/* specify whether 68020 code can be generated */
  		(*argP)++;
  		if(**argP=='c')
  			(*argP)++;
! 		if(!strcmp(*argP,"68000")) {
! 			cputype = mc68000;
! 			flagseen['m']=1;
! 		} else if(!strcmp(*argP,"68010")) {
  #ifdef M_SUN
  			omagic= 1<<16|OMAGIC;
  #endif
+ 			cputype = mc68000;
  			flagseen['m']=1;
! 		} else if(!strcmp(*argP,"68020")) {
! #ifdef M_SUN
! 			omagic= 2<<16|OMAGIC;
! #endif
! 			cputype = mc68020;
! 			flagseen['m']=1;
! 		} else
  			as_warn("Unknown -m option ignored");
  		while(**argP)
  			(*argP)++;