public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [m68k] Final part of architecture cleanup
@ 2006-03-06 18:34 Nathan Sidwell
  2006-03-06 19:01 ` Peter Barada
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Sidwell @ 2006-03-06 18:34 UTC (permalink / raw)
  To: Ben Elliston; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1503 bytes --]

This is the final part of the architecture switch cleanup.

include/opcodes/m68k.h enumerated all the 68k & cf cores.  That enumeration was 
only used by the assembler to map cpu selection to control register sets. This 
patch does away with that by changing the cpu table to simply point directly at 
the relevent control register array.  Thus removing some unnecessary indirection.

I also reordered the cpu table in cpu order, rather than having all the aliases 
follow all the primary names.  I found it very hard to keep track of with the 
separated ordering.  The new ordering I find easier to deal with.  The 'isalias' 
field indicates whether the alias is preceeding or succeeding the primary name, 
and also whether the name is deprecated -- the '521x' name is now ambiguous.

I reworked find_cf_chip for the new ordering.  Previously that was using strncat 
to try and avoid overrunning the provided array and then giving an as_fatal if 
it did.  However, that had a logic bug in that strncat does not write the 
trailing NUL char if the array gets full.  Thus the following strlen's and 
subsequent strncat's will go wandering off anyway.  This patch simply uses 
strcat and then checks if we wandered off or not.  As we never return if that 
happens, I think this is ok.

built & tested with m68k-none-elf cross tools. ok?

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


[-- Attachment #2: ctrl-regs.patch --]
[-- Type: text/x-patch, Size: 31032 bytes --]

2006-03-06  Nathan Sidwell  <nathan@codesourcery.com>

	gas:
	* config/tc-m68k.c (m68000_control_regs, m68010_control_regs,
	m68020_control_regs, m68040_control_regs, m68060_control_regs,
	mcf_control_regs, mcf5208_control_regs, mcf5213_control_regs,
	mcf5329_control_regs, mcf5249_control_regs, mcf528x_control_regs,
	mcfv4e_control_regs, m68010_control_regs): Rename and reorder to ...
	(m68000_ctrl, m68010_ctrl, m68020_ctrl, m68040_ctrl, m68060_ctrl,
	mcf_ctrl, mcf5208_ctrl, mcf5213_ctrl, mcf5235_ctrl, mcf5249_ctrl, 
	mcf5216_ctrl, mcf5250_ctrl, mcf5271_ctrl, mcf5272_ctrl,
	mcf5282_ctrl, mcfv4e_ctrl): ... these.
	(mcf5275_ctrl, mcf5329_ctrl, mcf5373_ctrl): New.
	(struct m68k_cpu): Change chip field to control_regs.
	(current_chip): Remove.
	(control_regs): New.
	(m68k_archs, m68k_extensions): Adjust.
	(m68k_cpus): Reorder to be in cpu number order.  Adjust.
	(CPU_ALLOW_MC, CPU_ALLOW_NEGATION): Remove.
	(find_cf_chip): Reimplement for new organization of cpu table.
	(select_control_regs): Remove.
	(mri_chip): Adjust.
	(struct save_opts): Save control regs, not chip.
	(s_save, s_restore): Adjust.
	(m68k_lookup_cpu): Give deprecated warning when necessary.
	(m68k_init_arch): Adjust.
	(md_show_usage): Adjust for new cpu table organization.

	include/opcodes:
	* m68k.h (cpu_m68k, cpu_cf, cpu_m68000, cpu_m68008, cpu_m68010,
	cpu_m68020, cpu_m68ec030, cpu_m68040, cpu_m68060, cpu_m68851,
	cpu_m68881, cpu_m68882, cpu_cpu32, cpu_cf5200, cpu_cf5206e,
	cpu_cf5208, cpu_cf521x, cpu_cf5213, cpu_cf5249, cpu_cf528x,
	cpu_cf5307, cpu_cf5329, cpu_cf5407, cpu_cf547x, cpu_cf548x): Remove.

Index: gas/config/tc-m68k.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.c,v
retrieving revision 1.72
diff -c -3 -p -r1.72 tc-m68k.c
*** gas/config/tc-m68k.c	6 Mar 2006 13:42:04 -0000	1.72
--- gas/config/tc-m68k.c	6 Mar 2006 13:52:48 -0000
*************** struct m68k_incant
*** 152,209 ****
  #define getone(x)	((((x)->m_opcode)>>16)&0xffff)
  #define gettwo(x)	(((x)->m_opcode)&0xffff)
  
! static const enum m68k_register m68000_control_regs[] = { 0 };
! static const enum m68k_register m68010_control_regs[] = {
    SFC, DFC, USP, VBR,
    0
  };
! static const enum m68k_register m68020_control_regs[] = {
    SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
    0
  };
! static const enum m68k_register m68040_control_regs[] = {
    SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
    USP, VBR, MSP, ISP, MMUSR, URP, SRP,
    0
  };
! static const enum m68k_register m68060_control_regs[] = {
    SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
    USP, VBR, URP, SRP, PCR,
    0
  };
! static const enum m68k_register mcf_control_regs[] = {
    CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
    RAMBAR0, RAMBAR1, MBAR,
    0
  };
! static const enum m68k_register mcf5208_control_regs[] = {
    CACR, ACR0, ACR1, VBR, RAMBAR1,
    0
  };
! static const enum m68k_register mcf5213_control_regs[] = {
    VBR, RAMBAR, FLASHBAR,
    0
  };
! static const enum m68k_register mcf5329_control_regs[] = {
!   CACR, ACR0, ACR1, VBR, RAMBAR,
    0
  };
! static const enum m68k_register mcf5249_control_regs[] = {
!   CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR1, MBAR, MBAR2,
    0
  };
! static const enum m68k_register mcf528x_control_regs[] = {
!   CACR, ACR0, ACR1, VBR, FLASHBAR, RAMBAR,
    0
  };
! static const enum m68k_register mcfv4e_control_regs[] = {
    CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
    ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
    PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
    PCR3U0, PCR3L0, PCR3U1, PCR3L1,
    0
  };
! #define cpu32_control_regs m68010_control_regs
  
  static const enum m68k_register *control_regs;
  
--- 152,237 ----
  #define getone(x)	((((x)->m_opcode)>>16)&0xffff)
  #define gettwo(x)	(((x)->m_opcode)&0xffff)
  
! static const enum m68k_register m68000_ctrl[] = { 0 };
! static const enum m68k_register m68010_ctrl[] = {
    SFC, DFC, USP, VBR,
    0
  };
! static const enum m68k_register m68020_ctrl[] = {
    SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
    0
  };
! static const enum m68k_register m68040_ctrl[] = {
    SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
    USP, VBR, MSP, ISP, MMUSR, URP, SRP,
    0
  };
! static const enum m68k_register m68060_ctrl[] = {
    SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
    USP, VBR, URP, SRP, PCR,
    0
  };
! static const enum m68k_register mcf_ctrl[] = {
    CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
    RAMBAR0, RAMBAR1, MBAR,
    0
  };
! static const enum m68k_register mcf5208_ctrl[] = {
    CACR, ACR0, ACR1, VBR, RAMBAR1,
    0
  };
! static const enum m68k_register mcf5213_ctrl[] = {
    VBR, RAMBAR, FLASHBAR,
    0
  };
! static const enum m68k_register mcf5216_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR,
    0
  };
! static const enum m68k_register mcf5235_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR,
    0
  };
! static const enum m68k_register mcf5249_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, MBAR, MBAR2,
    0
  };
! static const enum m68k_register mcf5250_ctrl[] = {
!   VBR,
!   0
! };
! static const enum m68k_register mcf5271_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR,
!   0
! };
! static const enum m68k_register mcf5272_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR, MBAR,
!   0
! };
! static const enum m68k_register mcf5275_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR,
!   0
! };
! static const enum m68k_register mcf5282_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR,
!   0
! };
! static const enum m68k_register mcf5329_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR,
!   0
! };
! static const enum m68k_register mcf5373_ctrl[] = {
!   VBR, CACR, ACR0, ACR1, RAMBAR,
!   0
! };
! static const enum m68k_register mcfv4e_ctrl[] = {
    CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
    ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
    PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
    PCR3U0, PCR3L0, PCR3U1, PCR3L1,
    0
  };
! #define cpu32_ctrl m68010_ctrl
  
  static const enum m68k_register *control_regs;
  
*************** static void s_m68k_arch (int);
*** 366,372 ****
  struct m68k_cpu
  {
    unsigned long arch;	/* Architecture features.  */
!   unsigned long chip;	/* Specific chip */
    const char *name;	/* Name */
    int alias;       	/* Alias for a cannonical name.  If 1, then
  			   succeeds canonical name, if -1 then
--- 394,400 ----
  struct m68k_cpu
  {
    unsigned long arch;	/* Architecture features.  */
!   const enum m68k_register *control_regs;	/* Control regs on chip */
    const char *name;	/* Name */
    int alias;       	/* Alias for a cannonical name.  If 1, then
  			   succeeds canonical name, if -1 then
*************** struct m68k_cpu
*** 379,385 ****
     disabled.  */
  static int current_architecture;
  static int not_current_architecture;
- static int current_chip;
  static const struct m68k_cpu *selected_arch;
  static const struct m68k_cpu *selected_cpu;
  static int initialized;
--- 407,412 ----
*************** static int initialized;
*** 387,404 ****
  /* Architecture models.  */
  static const struct m68k_cpu m68k_archs[] =
  {
!   {m68000,					cpu_m68000, "68000", 0},
!   {m68010,					cpu_m68010, "68010", 0},
!   {m68020|m68881|m68851,			cpu_m68020, "68020", 0},
!   {m68030|m68881|m68851,			cpu_m68030, "68030", 0},
!   {m68040,					cpu_m68040, "68040", 0},
!   {m68060,					cpu_m68060, "68060", 0},
!   {cpu32|m68881,				cpu_cpu32, "cpu32", 0},
!   {mcfisa_a|mcfhwdiv,				0, "isaa", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp,		0, "isaaplus", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp,		0, "isab", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!    cpu_cf547x, "cfv4e", 0},
    {0,0,NULL, 0}
  };
  
--- 414,431 ----
  /* Architecture models.  */
  static const struct m68k_cpu m68k_archs[] =
  {
!   {m68000,					m68000_ctrl, "68000", 0},
!   {m68010,					m68010_ctrl, "68010", 0},
!   {m68020|m68881|m68851,			m68020_ctrl, "68020", 0},
!   {m68030|m68881|m68851,			m68020_ctrl, "68030", 0},
!   {m68040,					m68040_ctrl, "68040", 0},
!   {m68060,					m68060_ctrl, "68060", 0},
!   {cpu32|m68881,				cpu32_ctrl, "cpu32", 0},
!   {mcfisa_a|mcfhwdiv,				NULL, "isaa", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp,		NULL, "isaaplus", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp,		NULL, "isab", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac|mcfusp,	mcf_ctrl, "cfv4", 0},
!   {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "cfv4e", 0},
    {0,0,NULL, 0}
  };
  
*************** static const struct m68k_cpu m68k_archs[
*** 406,521 ****
     for either.  */
  static const struct m68k_cpu m68k_extensions[] =
  {
!   {m68851,					0, "68851", -1},
!   {m68881,					0, "68881", -1},
!   {m68881,					0, "68882", -1},
    
!   {cfloat|m68881,				0, "float", 0},
    
!   {mcfhwdiv,					0, "div", 1},
!   {mcfusp,					0, "usp", 1},
!   {mcfmac,					0, "mac", 1},
!   {mcfemac,					0, "emac", 1},
     
!   {0,0,NULL, 0}
  };
  
  /* Processor list */
  static const struct m68k_cpu m68k_cpus[] =
  {
!   { m68000,					cpu_m68000, "68000", 0},
!   { m68010,					cpu_m68010, "68010", 0},
!   { m68020|m68881|m68851,			cpu_m68020, "68020", 0},
!   { m68030|m68881|m68851,			cpu_m68030, "68030", 0},
!   { m68040,					cpu_m68040, "68040", 0},
!   { m68060,					cpu_m68060, "68060", 0},
!   { cpu32|m68881,				cpu_cpu32, "cpu32",  0},
!   { mcfisa_a,					cpu_cf5200, "5200", 0},
!   { mcfisa_a|mcfhwdiv|mcfmac,			cpu_cf5206e, "5206e", 0},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	cpu_cf5208, "5208", 0},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	cpu_cf5213, "5213", 0},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,cpu_cf521x, "521x", 0},
!   { mcfisa_a|mcfhwdiv|mcfemac,		cpu_cf5249, "5249", 0},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,cpu_cf528x, "528x", 0},
!   { mcfisa_a|mcfhwdiv|mcfmac,			cpu_cf5307, "5307", 0},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf5329, "5329", 0},
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac,	cpu_cf5407, "5407",0},
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "547x", 0},
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!       						cpu_cf548x, "548x", 0},
!   /* Aliases (effectively, so far as gas is concerned) for the above
!      cpus.  */
!   { m68020|m68881|m68851,			cpu_m68020, "68k", 1},
!   { m68000,					cpu_m68000, "68008", 1},
!   { m68000,					cpu_m68000, "68302", 1},
!   { m68000,					cpu_m68000, "68306", 1},
!   { m68000,					cpu_m68000, "68307", 1},
!   { m68000,					cpu_m68000, "68322", 1},
!   { m68000,					cpu_m68000, "68356", 1},
!   { m68000,					cpu_m68000, "68ec000", 1},
!   { m68000,					cpu_m68000, "68hc000", 1},
!   { m68000,					cpu_m68000, "68hc001", 1},
!   { m68020|m68881|m68851,			cpu_m68020, "68ec020", 1},
!   { m68030|m68881|m68851,			cpu_m68030, "68ec030", 1},
!   { m68040,					cpu_m68040, "68ec040", 1},
!   { m68060,					cpu_m68060, "68ec060", 1},
!   { cpu32|m68881,				cpu_cpu32, "68330", 1},
!   { cpu32|m68881,				cpu_cpu32, "68331", 1},
!   { cpu32|m68881,				cpu_cpu32, "68332", 1},
!   { cpu32|m68881,				cpu_cpu32, "68333", 1},
!   { cpu32|m68881,				cpu_cpu32, "68334", 1},
!   { cpu32|m68881,				cpu_cpu32, "68336", 1},
!   { cpu32|m68881,				cpu_cpu32, "68340", 1},
!   { cpu32|m68881,				cpu_cpu32, "68341", 1},
!   { cpu32|m68881,				cpu_cpu32, "68349", 1},
!   { cpu32|m68881,				cpu_cpu32, "68360", 1},
!   { mcfisa_a,					cpu_cf5200, "5202", 1},
!   { mcfisa_a,					cpu_cf5200, "5204", 1},
!   { mcfisa_a,					cpu_cf5200, "5206", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	cpu_cf5208, "5207", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	cpu_cf5213, "5211", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	cpu_cf5213, "5212", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf521x, "5214", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf521x, "5216", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf5329, "5327", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf5329, "5328", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf528x, "5280", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf528x, "5281", 1},
!   { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	cpu_cf528x, "5282", 1},
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac,	cpu_cf5407,	"cfv4", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "cfv4e", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5470", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5471", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5472", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5473", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5474", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf547x, "5475", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5480", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5481", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5482", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5483", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5484", 1 },
!   { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat,
!     cpu_cf548x, "5485", 1 },
!   {0,0,NULL, 0}
    };
  
- #define CPU_ALLOW_MC 1
- #define CPU_ALLOW_NEGATION 4
- 
  static const struct m68k_cpu *m68k_lookup_cpu
  (const char *, const struct m68k_cpu *, int, int *);
  static int m68k_set_arch (const char *, int, int);
--- 433,560 ----
     for either.  */
  static const struct m68k_cpu m68k_extensions[] =
  {
!   {m68851,					NULL, "68851", -1},
!   {m68881,					NULL, "68881", -1},
!   {m68881,					NULL, "68882", -1},
    
!   {cfloat|m68881,				NULL, "float", 0},
    
!   {mcfhwdiv,					NULL, "div", 1},
!   {mcfusp,					NULL, "usp", 1},
!   {mcfmac,					NULL, "mac", 1},
!   {mcfemac,					NULL, "emac", 1},
     
!   {0,NULL,NULL, 0}
  };
  
  /* Processor list */
  static const struct m68k_cpu m68k_cpus[] =
  {
!   {m68000,					m68000_ctrl, "68000", 0},
!   {m68000,					m68000_ctrl, "68ec000", 1},
!   {m68000,					m68000_ctrl, "68hc000", 1},
!   {m68000,					m68000_ctrl, "68hc001", 1},
!   {m68000,					m68000_ctrl, "68008", 1},
!   {m68000,					m68000_ctrl, "68302", 1},
!   {m68000,					m68000_ctrl, "68306", 1},
!   {m68000,					m68000_ctrl, "68307", 1},
!   {m68000,					m68000_ctrl, "68322", 1},
!   {m68000,					m68000_ctrl, "68356", 1},
!   {m68010,					m68010_ctrl, "68010", 0},
!   {m68020|m68881|m68851,			m68020_ctrl, "68020", 0},
!   {m68020|m68881|m68851,			m68020_ctrl, "68k", 1},
!   {m68020|m68881|m68851,			m68020_ctrl, "68ec020", 1},
!   {m68030|m68881|m68851,			m68020_ctrl, "68030", 0},
!   {m68030|m68881|m68851,			m68020_ctrl, "68ec030", 1},
!   {m68040,					m68040_ctrl, "68040", 0},
!   {m68040,					m68040_ctrl, "68ec040", 1},
!   {m68060,					m68060_ctrl, "68060", 0},
!   {m68060,					m68060_ctrl, "68ec060", 1},
!   
!   {cpu32|m68881,				cpu32_ctrl, "cpu32",  0},
!   {cpu32|m68881,				cpu32_ctrl, "68330", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68331", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68332", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68333", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68334", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68336", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68340", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68341", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68349", 1},
!   {cpu32|m68881,				cpu32_ctrl, "68360", 1},
!   
!   {mcfisa_a,					mcf_ctrl, "5200", 0},
!   {mcfisa_a,					mcf_ctrl, "5202", 1},
!   {mcfisa_a,					mcf_ctrl, "5204", 1},
!   {mcfisa_a,					mcf_ctrl, "5206", 1},
!   
!   {mcfisa_a|mcfhwdiv|mcfmac,			mcf_ctrl, "5206e", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,		mcf5208_ctrl, "5207", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5208_ctrl, "5208", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	mcf5213_ctrl, "5211", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	mcf5213_ctrl, "5212", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp,	mcf5213_ctrl, "5213", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5216_ctrl, "5214", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5216_ctrl, "5216", 0},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5216_ctrl, "521x", 2},
! 
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5235_ctrl, "5232", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5235_ctrl, "5233", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5235_ctrl, "5234", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5235_ctrl, "5235", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5235_ctrl, "523x", 0},
!   
!   {mcfisa_a|mcfhwdiv|mcfemac,			mcf5249_ctrl, "5249", 0},
!   {mcfisa_a|mcfhwdiv|mcfemac,			mcf5250_ctrl, "5250", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5271_ctrl, "5270", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5271_ctrl, "5271", 0},
!   
!   {mcfisa_a|mcfhwdiv|mcfmac,			mcf5272_ctrl, "5272", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5275_ctrl, "5274", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5275_ctrl, "5275", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5282_ctrl, "5280", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5282_ctrl, "5281", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5282_ctrl, "5282", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5282_ctrl, "528x", 0},
!   
!   {mcfisa_a|mcfhwdiv|mcfmac,			mcf_ctrl, "5307", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5329_ctrl, "5327", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5329_ctrl, "5328", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5329_ctrl, "5329", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5329_ctrl, "532x", 0},
!   
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5373_ctrl, "5372", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5373_ctrl, "5373", -1},
!   {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp,	mcf5373_ctrl, "537x", 0},
!   
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfmac,		mcf_ctrl, "5407",0},
!   
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5470", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5471", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5472", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5473", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5474", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5475", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "547x", 0},
!   
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5480", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5481", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5482", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5483", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5484", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5485", -1},
!   {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "548x", 0},
!   
!   {0,NULL,NULL, 0}
    };
  
  static const struct m68k_cpu *m68k_lookup_cpu
  (const char *, const struct m68k_cpu *, int, int *);
  static int m68k_set_arch (const char *, int, int);
*************** static char *
*** 771,832 ****
  find_cf_chip (int architecture)
  {
    static char buf[1024];
-   int i, j, n_chips, n_alias;
    char *cp;
! 
    strcpy (buf, " (");
    cp = buf + strlen (buf);
  
!   for (i = 0, n_chips = 0, n_alias = 0; m68k_cpus[i].name; ++i)
!     if (m68k_cpus[i].arch & architecture)
        {
! 	n_chips++;
! 	if (m68k_cpus[i].alias)
! 	  n_alias++;
!       }
! 
!   if (n_chips == 0)
!     as_fatal (_("no matching ColdFire architectures found"));
! 
!   if (n_alias > 1)
!     n_chips -= n_alias;
!       
!   for (i = 0, j = 0; m68k_cpus[i].name && j < n_chips; ++i)
!     if (m68k_cpus[i].arch & architecture)
!       {
! 	if (j)
  	  {
! 	    if ((j == n_chips - 1 && !(n_alias > 1)) || ! n_alias)
! 	      {
! 		if (n_chips == 2)
! 		  {
! 		    strncpy (cp, _(" or "), (sizeof (buf) - (cp - buf)));
! 		    cp += strlen (cp);
! 		  }
! 		else
! 		  {
! 		    strncpy (cp, _(", or "), (sizeof (buf) - (cp - buf)));
! 		    cp += strlen (cp);
! 		  }
! 	      }
! 	    else
  	      {
! 		strncpy (cp, ", ", (sizeof (buf) - (cp - buf)));
! 		cp += strlen (cp);
  	      }
  	  }
! 	strncpy (cp, m68k_cpus[i].name, (sizeof (buf) - (cp - buf)));
! 	cp += strlen (cp);
! 	j++;
        }
! 
!   if (n_alias > 1)
!     {
!       strncpy (cp, _(", or aliases"), (sizeof (buf) - (cp - buf)));
!       cp += strlen (cp);
!     }
! 
!   strncpy (cp, ")", (sizeof (buf) - (cp - buf)));
  
    return buf;
  }
--- 810,866 ----
  find_cf_chip (int architecture)
  {
    static char buf[1024];
    char *cp;
!   const struct m68k_cpu *cpu;
!   int any = 0;
!   
    strcpy (buf, " (");
    cp = buf + strlen (buf);
  
!   for (cpu = m68k_cpus; cpu->name; cpu++)
!     if (!cpu->alias && (cpu->arch & architecture))
        {
! 	const struct m68k_cpu *alias;
! 	if (any)
  	  {
! 	    strcpy (cp, ", ");
! 	    cp += 2;
! 	  }
! 	any = 0;
! 	strcpy (cp, cpu->name);
! 	cp += strlen (cp);
! 	strcpy (cp, " [");
! 	cp += 2;
! 	if (cpu != m68k_cpus)
! 	  for (alias = cpu - 1; alias->alias; alias--)
! 	    {	
! 	      if (any)
! 		{
! 		  strcpy (cp, ", ");
! 		  cp += 2;
! 		}
! 	      strcpy (cp, alias->name);
! 	      cp += strlen (cp);
! 	      any = 1;
! 	    }
! 	for (alias = cpu + 1; alias->alias; alias++)
! 	  {
! 	    if (any)
  	      {
! 		strcpy (cp, ", ");
! 		cp += 2;
  	      }
+ 	    strcpy (cp, alias->name);
+ 	    cp += strlen (cp);
+ 	    any = 1;
  	  }
! 	
! 	strcpy (cp, "]");
! 	any = 1;
! 	if ((unsigned)(cp - buf) >= sizeof (buf))
! 	  as_fatal (_("coldfire string overflow"));
        }
!   strcat (cp, ")");
  
    return buf;
  }
*************** md_begin (void)
*** 4375,4442 ****
  #endif
  }
  
- static void
- select_control_regs (void)
- {
-   /* Note which set of "movec" control registers is available.  */
-   switch (current_chip)
-     {
-     case 0:
-       if (verbose)
- 	as_warn (_("architecture not yet selected: defaulting to 68020"));
-       control_regs = m68020_control_regs;
-       break;
-       
-     case cpu_m68000:
-       control_regs = m68000_control_regs;
-       break;
-     case cpu_m68010:
-       control_regs = m68010_control_regs;
-       break;
-     case cpu_m68020:
-     case cpu_m68030:
-       control_regs = m68020_control_regs;
-       break;
-     case cpu_m68040:
-       control_regs = m68040_control_regs;
-       break;
-     case cpu_m68060:
-       control_regs = m68060_control_regs;
-       break;
-     case cpu_cpu32:
-       control_regs = cpu32_control_regs;
-       break;
-     case cpu_cf5200:
-     case cpu_cf5206e:
-     case cpu_cf5307:
-     case cpu_cf5407:
-       control_regs = mcf_control_regs;
-       break;
-     case cpu_cf5249:
-       control_regs = mcf5249_control_regs;
-       break;
-     case cpu_cf528x:
-     case cpu_cf521x:
-       control_regs = mcf528x_control_regs;
-       break;
-     case cpu_cf547x:
-     case cpu_cf548x:
-       control_regs = mcfv4e_control_regs;
-       break;
-     case cpu_cf5208:
-       control_regs = mcf5208_control_regs;
-       break;
-     case cpu_cf5213:
-       control_regs = mcf5213_control_regs;
-       break;
-     case cpu_cf5329:
-       control_regs = mcf5329_control_regs;
-       break;
-     default:
-       abort ();
-     }
- }
- 
  \f
  /* This is called when a label is defined.  */
  
--- 4409,4414 ----
*************** mri_chip (void)
*** 5366,5372 ****
    else
      current_architecture &= m68881 | m68851;
    current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
!   current_chip = m68k_cpus[i].chip;
  
    while (*input_line_pointer == '/')
      {
--- 5338,5344 ----
    else
      current_architecture &= m68881 | m68851;
    current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
!   control_regs = m68k_cpus[i].control_regs;
  
    while (*input_line_pointer == '/')
      {
*************** mri_chip (void)
*** 5383,5391 ****
  	current_architecture |= m68851;
        *input_line_pointer = c;
      }
- 
-   /* Update info about available control registers.  */
-   select_control_regs ();
  }
  
  /* The MRI CHIP pseudo-op.  */
--- 5355,5360 ----
*************** struct save_opts
*** 5731,5737 ****
    int keep_locals;
    int short_refs;
    int architecture;
!   int chip;
    int quick;
    int rel32;
    int listing;
--- 5700,5706 ----
    int keep_locals;
    int short_refs;
    int architecture;
!   const enum m68k_register *control_regs;
    int quick;
    int rel32;
    int listing;
*************** s_save (int ignore ATTRIBUTE_UNUSED)
*** 5756,5762 ****
    s->keep_locals = flag_keep_locals;
    s->short_refs = flag_short_refs;
    s->architecture = current_architecture;
!   s->chip = current_chip;
    s->quick = m68k_quick;
    s->rel32 = m68k_rel32;
    s->listing = listing;
--- 5725,5731 ----
    s->keep_locals = flag_keep_locals;
    s->short_refs = flag_short_refs;
    s->architecture = current_architecture;
!   s->control_regs = control_regs;
    s->quick = m68k_quick;
    s->rel32 = m68k_rel32;
    s->listing = listing;
*************** s_restore (int ignore ATTRIBUTE_UNUSED)
*** 5790,5796 ****
    flag_keep_locals = s->keep_locals;
    flag_short_refs = s->short_refs;
    current_architecture = s->architecture;
!   current_chip = s->chip;
    m68k_quick = s->quick;
    m68k_rel32 = s->rel32;
    listing = s->listing;
--- 5759,5765 ----
    flag_keep_locals = s->keep_locals;
    flag_short_refs = s->short_refs;
    current_architecture = s->architecture;
!   control_regs = s->control_regs;
    m68k_quick = s->quick;
    m68k_rel32 = s->rel32;
    listing = s->listing;
*************** m68k_lookup_cpu (const char *arg, const 
*** 7079,7085 ****
  
    for (; table->name; table++)
      if (!strcmp (arg, table->name))
!       return table;
    return 0;
  }
  
--- 7048,7059 ----
  
    for (; table->name; table++)
      if (!strcmp (arg, table->name))
!       {
! 	if (table->alias < -1 || table->alias > 1)
! 	  as_bad (_("`%s' is deprecated, use `%s'"),
! 		  table->name, table[table->alias < 0 ? 1 : -1].name);
! 	return table;
!       }
    return 0;
  }
  
*************** m68k_init_arch (void)
*** 7305,7318 ****
        not_current_architecture &= ~current_architecture;
      }
    if (selected_arch)
!     current_architecture |= selected_arch->arch;
    else
      current_architecture |= selected_cpu->arch;
- 
-   current_architecture &= ~not_current_architecture;
    
    if (selected_cpu)
      {
        if (current_architecture & ~selected_cpu->arch)
  	{
  	  as_bad (_("selected processor does not have all features of selected architecture"));
--- 7279,7296 ----
        not_current_architecture &= ~current_architecture;
      }
    if (selected_arch)
!     {
!       current_architecture |= selected_arch->arch;
!       control_regs = selected_arch->control_regs;
!     }
    else
      current_architecture |= selected_cpu->arch;
    
+   current_architecture &= ~not_current_architecture;
+ 
    if (selected_cpu)
      {
+       control_regs = selected_cpu->control_regs;
        if (current_architecture & ~selected_cpu->arch)
  	{
  	  as_bad (_("selected processor does not have all features of selected architecture"));
*************** m68k_init_arch (void)
*** 7349,7357 ****
      }
    /* What other incompatibilities could we check for?  */
  
-   /* Note which set of "movec" control registers is available.  */
-   select_control_regs ();
- 
    if (cpu_of_arch (current_architecture) < m68020
        || arch_coldfire_p (current_architecture))
      md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
--- 7327,7332 ----
*************** md_show_usage (FILE *stream)
*** 7374,7388 ****
        if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
  	{
  	  default_arch = m68k_cpus[i].arch;
! 	  for (i = 0; m68k_cpus[i].name; i++)
! 	    {
! 	      if (m68k_cpus[i].arch == default_arch
! 		  && !m68k_cpus[i].alias)
! 		{
! 		  default_cpu = m68k_cpus[i].name;
! 		  break;
! 		}
! 	    }
  	}
      }
  
--- 7349,7359 ----
        if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
  	{
  	  default_arch = m68k_cpus[i].arch;
! 	  while (m68k_cpus[i].alias > 0)
! 	    i--;
! 	  while (m68k_cpus[i].alias < 0)
! 	    i++;
! 	  default_cpu = m68k_cpus[i].name;
  	}
      }
  
Index: include/opcode/m68k.h
===================================================================
RCS file: /cvs/src/src/include/opcode/m68k.h,v
retrieving revision 1.11
diff -c -3 -p -r1.11 m68k.h
*** include/opcode/m68k.h	7 Feb 2006 19:01:10 -0000	1.11
--- include/opcode/m68k.h	6 Mar 2006 13:52:49 -0000
***************
*** 53,96 ****
  #define	mfloat  (m68881 | m68040 | m68060)
  #define	mmmu    (m68851 | m68030 | m68040 | m68060)
  
- /* CPU numbering.  There are too many of these to use a bit vector.
-    These are a one-of-many selection.  Choose a numbering scheme that
-    simply maps onto manufacturer's part numbers. */
- 
- /* All m68k cpus */
- #define cpu_m68k 0
- /* All coldfire cpus */
- #define cpu_cf  1000000
- 
- #define cpu_m68000  (cpu_m68k + 68000)
- #define	cpu_m68008  cpu_m68000 /* Synonym for -m68000.  otherwise unused.  */
- #define	cpu_m68010  (cpu_m68k + 68010)
- #define	cpu_m68020  (cpu_m68k + 68020)
- #define	cpu_m68030  (cpu_m68k + 68030)
- #define cpu_m68ec030 cpu_m68030 /* Similar enough to -m68030 to ignore
- 			   differences; gas will deal with the few
- 			   differences.  */
- #define	cpu_m68040  (cpu_m68k + 68040)
- /* There is no 68050.  */
- #define cpu_m68060  (cpu_m68k + 68060)
- #define	cpu_m68851  (cpu_m68k + 68851)
- #define	cpu_m68881  (cpu_m68k + 68881)
- #define	cpu_m68882   cpu_m68881 /* Synonym for -m68881.  otherwise unused.  */
- #define cpu_cpu32   (cpu_m68k + 32)
- 
- #define cpu_cf5200  (cpu_cf + 5200)
- #define cpu_cf5206e (cpu_cf + 5206)
- #define cpu_cf5208  (cpu_cf + 5208)
- #define cpu_cf521x  (cpu_cf + 5210)
- #define cpu_cf5213  (cpu_cf + 5213)
- #define cpu_cf5249  (cpu_cf + 5249)
- #define cpu_cf528x  (cpu_cf + 5280)
- #define cpu_cf5307  (cpu_cf + 5307)
- #define cpu_cf5329  (cpu_cf + 5329)
- #define cpu_cf5407  (cpu_cf + 5407)
- #define cpu_cf547x  (cpu_cf + 5470)
- #define cpu_cf548x  (cpu_cf + 5480)
- 
  /* The structure used to hold information for an opcode.  */
  
  struct m68k_opcode
--- 53,58 ----

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
  2006-03-06 18:34 [m68k] Final part of architecture cleanup Nathan Sidwell
@ 2006-03-06 19:01 ` Peter Barada
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Barada @ 2006-03-06 19:01 UTC (permalink / raw)
  To: nathan; +Cc: bje, binutils


The v4e has ASID as a control register, its value is 0x003, as well as
ACR0-3.  I've used the following patch to call out for the v4e movec
register names instead of their m68k equivalents:

Index: tc-m68k.c
===================================================================
RCS file: /cvs/eps/dev_eng/sw/products/Linux/FireEngine/LinuxTools/crosstool/build/m68k-linux/gcc-3.4.3-glibc-2.3.2/binutils-2.15/gas/config/tc-m68k.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -c -3 -p -r1.2 -r1.3
*** tc-m68k.c	12 Mar 2005 00:40:48 -0000	1.2
--- tc-m68k.c	26 Sep 2005 20:46:23 -0000	1.3
*************** static const enum m68k_register mcf528x_
*** 176,182 ****
    0
  };
  static const enum m68k_register mcfv4e_control_regs[] = {
!   CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
    ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
    PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
    PCR3U0, PCR3L0, PCR3U1, PCR3L1,
--- 176,182 ----
    0
  };
  static const enum m68k_register mcfv4e_control_regs[] = {
!   CACR, ASID, ACR0, ACR1, ACR2, ACR3, BUSCR, VBR, PC, ROMBAR,
    ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
    PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
    PCR3U0, PCR3L0, PCR3U1, PCR3L1,
*************** m68k_ip (instring)
*** 2765,2770 ****
--- 2765,2771 ----
  	    case CACR:
  	      tmpreg = 0x002;
  	      break;
+ 	    case ASID:
  	    case TC:
  	      tmpreg = 0x003;
  	      break;
*************** static const struct init_entry init_tabl
*** 3564,3570 ****
    { "mpcr",     MPCR },		/* mcfv4e registers.  */
    { "edrambar", EDRAMBAR },	/* mcfv4e registers.  */
    { "secmbar",  SECMBAR },	/* mcfv4e registers.  */
!   { "asid",     TC },		/* mcfv4e registers.  */
    { "mmubar",   BUSCR },	/* mcfv4e registers.  */
    { "pcr1u0",   PCR1U0 },	/* mcfv4e registers.  */
    { "pcr1l0",   PCR1L0 },	/* mcfv4e registers.  */
--- 3565,3571 ----
    { "mpcr",     MPCR },		/* mcfv4e registers.  */
    { "edrambar", EDRAMBAR },	/* mcfv4e registers.  */
    { "secmbar",  SECMBAR },	/* mcfv4e registers.  */
!   { "asid",     ASID },		/* mcfv4e registers.  */
    { "mmubar",   BUSCR },	/* mcfv4e registers.  */
    { "pcr1u0",   PCR1U0 },	/* mcfv4e registers.  */
    { "pcr1l0",   PCR1L0 },	/* mcfv4e registers.  */

-- 
Peter Barada
peter@the-baradas.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
  2006-03-24 11:01   ` Nathan Sidwell
@ 2006-03-27 13:21     ` Ben Elliston
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Elliston @ 2006-03-27 13:21 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]

Hi Nathan

> Would you prefer
> 
> a) Commit the arch cleanup as is, and then commit the patch I attach here?
> b) post a combined patch for this change and the later change.

(a) will be fine, thanks.

Cheers, Ben

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
  2006-03-24  5:17 ` Ben Elliston
@ 2006-03-24 11:01   ` Nathan Sidwell
  2006-03-27 13:21     ` Ben Elliston
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Sidwell @ 2006-03-24 11:01 UTC (permalink / raw)
  To: Ben Elliston; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1990 bytes --]

Ben Elliston wrote:
> Hi Nathan

> The problem is that you detect the buffer overflow after it has
> occurred; it will likely be too late.  I'd like to see this code made
> more robust.
> 
> How about adding some assertions, at the very least (as the code only
> processes compile-time strings and not external untrusted data)?

Actually I have a follow up patch that fixes the strncpy issue correctly -- I 
found it was still lurking in m68k_ip, and I got bit by it.  I attach that patch.

The attached patch folds find_cf_chip into its only caller and uses it for both 
cf and m68k chips.  Rather than generate the message into a stack allocated 
array, and them copy it to a malloced area, I simply malloc the area first and 
construct directly into it.  Although this might mean the malloced area is 
longer than necessary, I don't really see the point of optimizing that in this 
error handling case.  I use a local macro to do the string appending in a safe 
manner, and you'll see I place a sentinel NUL char right at the end of the 
buffer to start with, so that when strncpy runs out of room, it'll be right 
there.  Then I detect if the buffer is full and replace the last few chars with 
'  ...', rather than die horribly.  (hm, a thought occurs, we could retry with a 
longer buffer -- I'd really like to do that as a separate change though.)

Would you prefer

a) Commit the arch cleanup as is, and then commit the patch I attach here?
b) post a combined patch for this change and the later change.

I would have preferred not fiddling with find_cf_chip at all in this first 
patch, but it needed changing because of how it traversed the cpus array.  I 
found its logic rather tortuous.  I suppose it would be possible to fix the 
overflow in find_cf_chip first, but right now that just seems like make-work.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


[-- Attachment #2: overrun.patch --]
[-- Type: text/x-patch, Size: 7029 bytes --]

2006-03-21  Nathan Sidwell  <nathan@codesourcery.com>

	* gas/config/tc-m68k.c (find_cf_chip): Merge into ...
	(m68k_ip): ... here.  Use for all chips.  Protect against buffer
	overrun and avoid excessive copying.

Index: gas/config/tc-m68k.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.c,v
retrieving revision 1.72.2.2
diff -c -3 -p -r1.72.2.2 tc-m68k.c
*** gas/config/tc-m68k.c	21 Mar 2006 10:20:17 -0000	1.72.2.2
--- gas/config/tc-m68k.c	21 Mar 2006 10:23:48 -0000
*************** static char alt_notend_table[256];
*** 802,870 ****
        || (*s == ':'						\
  	  && alt_notend_table[(unsigned char) s[1]])))
  
- /* Return a human readable string holding the list of chips that are
-    valid for a particular architecture, suppressing aliases (unless
-    there is only one of them).  */
- 
- static char *
- find_cf_chip (int architecture)
- {
-   static char buf[1024];
-   char *cp;
-   const struct m68k_cpu *cpu;
-   int any = 0;
-   
-   strcpy (buf, " (");
-   cp = buf + strlen (buf);
- 
-   for (cpu = m68k_cpus; cpu->name; cpu++)
-     if (!cpu->alias && (cpu->arch & architecture))
-       {
- 	const struct m68k_cpu *alias;
- 	if (any)
- 	  {
- 	    strcpy (cp, ", ");
- 	    cp += 2;
- 	  }
- 	any = 0;
- 	strcpy (cp, cpu->name);
- 	cp += strlen (cp);
- 	strcpy (cp, " [");
- 	cp += 2;
- 	if (cpu != m68k_cpus)
- 	  for (alias = cpu - 1; alias->alias; alias--)
- 	    {	
- 	      if (any)
- 		{
- 		  strcpy (cp, ", ");
- 		  cp += 2;
- 		}
- 	      strcpy (cp, alias->name);
- 	      cp += strlen (cp);
- 	      any = 1;
- 	    }
- 	for (alias = cpu + 1; alias->alias; alias++)
- 	  {
- 	    if (any)
- 	      {
- 		strcpy (cp, ", ");
- 		cp += 2;
- 	      }
- 	    strcpy (cp, alias->name);
- 	    cp += strlen (cp);
- 	    any = 1;
- 	  }
- 	
- 	strcpy (cp, "]");
- 	any = 1;
- 	if ((unsigned)(cp - buf) >= sizeof (buf))
- 	  as_fatal (_("coldfire string overflow"));
-       }
-   strcat (cp, ")");
- 
-   return buf;
- }
- 
  #ifdef OBJ_ELF
  
  /* Return zero if the reference to SYMBOL from within the same segment may
--- 802,807 ----
*************** m68k_ip (char *instring)
*** 2067,2158 ****
  	  if (ok_arch
  	      && !(ok_arch & current_architecture))
  	    {
! 	      char buf[200], *cp;
  
! 	      strncpy (buf,
! 		       _("invalid instruction for this architecture; needs "),
! 		       sizeof (buf));
! 	      cp = buf + strlen (buf);
  	      switch (ok_arch)
  		{
  		case mcfisa_a:
! 		  strncpy (cp, _("ColdFire ISA_A"),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
! 		  strncpy (cp, find_cf_chip (ok_arch),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
  		  break;
  		case mcfhwdiv:
! 		  strncpy (cp, _("ColdFire hardware divide"),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
! 		  strncpy (cp, find_cf_chip (ok_arch),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
  		  break;
  		case mcfisa_aa:
! 		  strncpy (cp, _("ColdFire ISA_A+"),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
! 		  strncpy (cp, find_cf_chip (ok_arch),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
  		  break;
  		case mcfisa_b:
! 		  strncpy (cp, _("ColdFire ISA_B"),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
! 		  strncpy (cp, find_cf_chip (ok_arch),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
  		  break;
  		case cfloat:
! 		  strncpy (cp, _("ColdFire fpu"), sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
! 		  strncpy (cp, find_cf_chip (ok_arch),
! 			   sizeof (buf) - (cp - buf));
! 		  cp += strlen (cp);
  		  break;
  		case mfloat:
! 		  strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
  		  break;
  		case mmmu:
! 		  strcpy (cp, _("mmu (68030 or 68851)"));
  		  break;
  		case m68020up:
! 		  strcpy (cp, _("68020 or higher"));
  		  break;
  		case m68000up:
! 		  strcpy (cp, _("68000 or higher"));
  		  break;
  		case m68010up:
! 		  strcpy (cp, _("68010 or higher"));
  		  break;
  		default:
  		  {
! 		    int got_one = 0, idx;
  
! 		    for (idx = 0; m68k_cpus[idx].name; idx++)
  		      {
! 			if ((m68k_cpus[idx].arch & ok_arch)
! 			    && ! m68k_cpus[idx].alias)
! 			  {
! 			    if (got_one)
! 			      {
! 				strcpy (cp, " or ");
! 				cp += strlen (cp);
! 			      }
! 			    got_one = 1;
! 			    strcpy (cp, m68k_cpus[idx].name);
! 			    cp += strlen (cp);
! 			  }
  		      }
  		  }
  		}
- 	      cp = xmalloc (strlen (buf) + 1);
- 	      strcpy (cp, buf);
- 	      the_ins.error = cp;
  	    }
  	  else
  	    the_ins.error = _("operands mismatch");
--- 2004,2103 ----
  	  if (ok_arch
  	      && !(ok_arch & current_architecture))
  	    {
! 	      const struct m68k_cpu *cpu;
! 	      int any = 0;
! 	      size_t space = 400;
! 	      char *buf = xmalloc (space + 1);
! 	      size_t len;
! 	      int paren = 1;
! 
! 	      the_ins.error = buf;
! 	      /* Make sure there's a NUL at the end of the buffer -- strncpy
! 		 won't write one when it runs out of buffer */
! 	      buf[space] = 0;
! #define APPEND(STRING) \
!   (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
  
! 	      APPEND (_("invalid instruction for this architecture; needs "));
  	      switch (ok_arch)
  		{
  		case mcfisa_a:
! 		  APPEND (_("ColdFire ISA_A"));
  		  break;
  		case mcfhwdiv:
! 		  APPEND (_("ColdFire hardware divide"));
  		  break;
  		case mcfisa_aa:
! 		  APPEND (_("ColdFire ISA_A+"));
  		  break;
  		case mcfisa_b:
! 		  APPEND (_("ColdFire ISA_B"));
  		  break;
  		case cfloat:
! 		  APPEND (_("ColdFire fpu"));
  		  break;
  		case mfloat:
! 		  APPEND (_("M68K fpu"));
  		  break;
  		case mmmu:
! 		  APPEND (_("M68K mmu"));
  		  break;
  		case m68020up:
! 		  APPEND (_("68020 or higher"));
  		  break;
  		case m68000up:
! 		  APPEND (_("68000 or higher"));
  		  break;
  		case m68010up:
! 		  APPEND (_("68010 or higher"));
  		  break;
  		default:
+ 		  paren = 0;
+ 		}
+ 	      if (paren)
+ 		APPEND (" (");
+ 
+ 	      for (cpu = m68k_cpus; cpu->name; cpu++)
+ 		if (!cpu->alias && (cpu->arch & ok_arch))
  		  {
! 		    const struct m68k_cpu *alias;
  
! 		    if (any)
! 		      APPEND (", ");
! 		    any = 0;
! 		    APPEND (cpu->name);
! 		    APPEND (" [");
! 		    if (cpu != m68k_cpus)
! 		      for (alias = cpu - 1; alias->alias; alias--)
! 			{
! 			  if (any)
! 			    APPEND (", ");
! 			  APPEND (alias->name);
! 			  any = 1;
! 			}
! 		    for (alias = cpu + 1; alias->alias; alias++)
  		      {
! 			if (any)
! 			  APPEND (", ");
! 			APPEND (alias->name);
! 			any = 1;
  		      }
+ 		    
+ 		    APPEND ("]");
+ 		    any = 1;
  		  }
+ 	      if (paren)
+ 		APPEND (")");
+ #undef APPEND
+ 	      if (!space)
+ 		{
+ 		  /* we ran out of space, so replace the end of the list
+ 		     with ellipsis.  */
+ 		  buf -= 4;
+ 		  while (*buf != ' ')
+ 		    buf--;
+ 		  strcpy (buf, " ...");
  		}
  	    }
  	  else
  	    the_ins.error = _("operands mismatch");

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
  2006-03-24  5:05 ` Ben Elliston
@ 2006-03-24  7:41   ` Nathan Sidwell
  0 siblings, 0 replies; 7+ messages in thread
From: Nathan Sidwell @ 2006-03-24  7:41 UTC (permalink / raw)
  To: Ben Elliston; +Cc: Peter Barada, binutils

Ben Elliston wrote:
>>The v4e has ASID as a control register, its value is 0x003, as well
>>as ACR0-3.  I've used the following patch to call out for the v4e
>>movec register names instead of their m68k equivalents:
> 
> 
> Mostly okay (see below).  You'll need a ChangeLog entry, too, of
> course.
> 
> 
>>*************** m68k_ip (instring)
>>*** 2765,2770 ****
>>--- 2765,2771 ----
>>  	    case CACR:
>>  	      tmpreg = 0x002;
>>  	      break;
>>+ 	    case ASID:
>>  	    case TC:
>>  	      tmpreg = 0x003;
>>  	      break;
> 
> 
> Please add a comment under `case ASID:' like /* Fall through.  */.

Peter, don't forget to patch the enumeration in m68k-parse.h too -- You omitted 
that from your email

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
       [not found] <20060312230407.GA32449@ozlabs.au.ibm.com>
@ 2006-03-24  5:17 ` Ben Elliston
  2006-03-24 11:01   ` Nathan Sidwell
  0 siblings, 1 reply; 7+ messages in thread
From: Ben Elliston @ 2006-03-24  5:17 UTC (permalink / raw)
  To: nathan; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

Hi Nathan

> This is the final part of the architecture switch cleanup.

This patch is okay, with the exception of:

> I reworked find_cf_chip for the new ordering.  Previously that was
> using strncat to try and avoid overrunning the provided array and
> then giving an as_fatal if it did.  However, that had a logic bug in
> that strncat does not write the trailing NUL char if the array gets
> full.  Thus the following strlen's and subsequent strncat's will go
> wandering off anyway.  This patch simply uses strcat and then checks
> if we wandered off or not.  As we never return if that happens, I
> think this is ok.

The problem is that you detect the buffer overflow after it has
occurred; it will likely be too late.  I'd like to see this code made
more robust.

How about adding some assertions, at the very least (as the code only
processes compile-time strings and not external untrusted data)?

Cheers, Ben

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m68k] Final part of architecture cleanup
       [not found] <20060306215827.GB19940@ozlabs.au.ibm.com>
@ 2006-03-24  5:05 ` Ben Elliston
  2006-03-24  7:41   ` Nathan Sidwell
  0 siblings, 1 reply; 7+ messages in thread
From: Ben Elliston @ 2006-03-24  5:05 UTC (permalink / raw)
  To: Peter Barada; +Cc: nathan, binutils

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

> The v4e has ASID as a control register, its value is 0x003, as well
> as ACR0-3.  I've used the following patch to call out for the v4e
> movec register names instead of their m68k equivalents:

Mostly okay (see below).  You'll need a ChangeLog entry, too, of
course.

> *************** m68k_ip (instring)
> *** 2765,2770 ****
> --- 2765,2771 ----
>   	    case CACR:
>   	      tmpreg = 0x002;
>   	      break;
> + 	    case ASID:
>   	    case TC:
>   	      tmpreg = 0x003;
>   	      break;

Please add a comment under `case ASID:' like /* Fall through.  */.

Thanks, Ben

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-03-27 11:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-06 18:34 [m68k] Final part of architecture cleanup Nathan Sidwell
2006-03-06 19:01 ` Peter Barada
     [not found] <20060306215827.GB19940@ozlabs.au.ibm.com>
2006-03-24  5:05 ` Ben Elliston
2006-03-24  7:41   ` Nathan Sidwell
     [not found] <20060312230407.GA32449@ozlabs.au.ibm.com>
2006-03-24  5:17 ` Ben Elliston
2006-03-24 11:01   ` Nathan Sidwell
2006-03-27 13:21     ` Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).