This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Dwarf2 cfi for m68k


This implements the target dependent dwarf2 cfi support for m68k.

Andreas.

gas/
	* config/tc-m68k.h (TARGET_USE_CFIPOP)
	(DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT)
	(tc_regname_to_dw2regnum, tc_cfi_frame_initial_instructions):
	Define.

	* config/tc-m68k.c: Include "dw2gencfi.h".
	(tc_m68k_regname_to_dw2regnum)
	(tc_m68k_frame_initial_instructions): New functions.

gas/testsuite/
	* gas/cfi/cfi-m68k.s, gas/cfi/cfi-m68k.d: New test.
	* gas/cfi/cfi.exp (run_list_test): Run it.

Index: gas/config/tc-m68k.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.c,v
retrieving revision 1.44
diff -u -a -p -r1.44 tc-m68k.c
--- gas/config/tc-m68k.c	21 May 2003 12:07:55 -0000	1.44
+++ gas/config/tc-m68k.c	3 Aug 2003 17:11:14 -0000
@@ -1,6 +1,6 @@
 /* tc-m68k.c -- Assemble for the m68k family
    Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002
+   2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -25,6 +25,7 @@
 #include "obstack.h"
 #include "subsegs.h"
 #include "dwarf2dbg.h"
+#include "dw2gencfi.h"
 
 #include "opcode/m68k.h"
 #include "m68k-parse.h"
@@ -7146,3 +7147,34 @@ m68k_elf_final_processing ()
     elf_elfheader (stdoutput)->e_flags |= EF_M68000;
 }
 #endif
+
+int
+tc_m68k_regname_to_dw2regnum (const char *regname)
+{
+  unsigned int regnum;
+  static const char *const regnames[] =
+    {
+      "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
+      "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
+      "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
+      "pc"
+    };
+
+  for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
+    if (strcmp (regname, regnames[regnum]) == 0)
+      return regnum;
+
+  return -1;
+}
+
+void
+tc_m68k_frame_initial_instructions (void)
+{
+  static int sp_regno = -1;
+
+  if (sp_regno < 0)
+    sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
+
+  cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
+  cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);
+}
Index: gas/config/tc-m68k.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.h,v
retrieving revision 1.13
diff -u -a -p -r1.13 tc-m68k.h
--- gas/config/tc-m68k.h	23 Jan 2003 12:51:05 -0000	1.13
+++ gas/config/tc-m68k.h	3 Aug 2003 17:11:14 -0000
@@ -220,3 +220,15 @@ extern struct relax_type md_relax_table[
   while (0)
 
 #define DWARF2_LINE_MIN_INSN_LENGTH 2
+
+/* We want .cfi_* pseudo-ops for generating unwind info.  */
+#define TARGET_USE_CFIPOP 1
+
+#define DWARF2_DEFAULT_RETURN_COLUMN 24
+#define DWARF2_CIE_DATA_ALIGNMENT (-4)
+
+#define tc_regname_to_dw2regnum tc_m68k_regname_to_dw2regnum
+extern int tc_m68k_regname_to_dw2regnum (const char *regname);
+
+#define tc_cfi_frame_initial_instructions tc_m68k_frame_initial_instructions
+extern void tc_m68k_frame_initial_instructions (void);
Index: gas/testsuite/gas/cfi/cfi-m68k.d
===================================================================
RCS file: gas/testsuite/gas/cfi/cfi-m68k.d
diff -N gas/testsuite/gas/cfi/cfi-m68k.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/cfi/cfi-m68k.d	3 Aug 2003 17:11:15 -0000
@@ -0,0 +1,33 @@
+#readelf: -wf
+#name: CFI on m68k
+The section .eh_frame contains:
+
+00000000 00000012 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 2
+  Data alignment factor: -4
+  Return address column: 24
+  Augmentation data:     1b
+
+  DW_CFA_def_cfa: r15 ofs 4
+  DW_CFA_offset: r24 at cfa-4
+
+00000016 00000014 0000001a FDE cie=00000000 pc=0000001e..0000002a
+  DW_CFA_advance_loc: 4 to 00000022
+  DW_CFA_def_cfa_offset: 4664
+  DW_CFA_advance_loc: 6 to 00000028
+  DW_CFA_def_cfa_offset: 4
+
+0000002e 00000017 00000032 FDE cie=00000000 pc=00000036..00000042
+  DW_CFA_advance_loc: 4 to 0000003a
+  DW_CFA_def_cfa_offset: 8
+  DW_CFA_offset: r14 at cfa-8
+  DW_CFA_def_cfa_reg: r14
+  DW_CFA_advance_loc: 6 to 00000040
+  DW_CFA_def_cfa_reg: r15
+
+00000049 0000000f 0000004d FDE cie=00000000 pc=00000051..00000055
+
+  DW_CFA_nop
+  DW_CFA_nop
Index: gas/testsuite/gas/cfi/cfi-m68k.s
===================================================================
RCS file: gas/testsuite/gas/cfi/cfi-m68k.s
diff -N gas/testsuite/gas/cfi/cfi-m68k.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/cfi/cfi-m68k.s	3 Aug 2003 17:11:15 -0000
@@ -0,0 +1,64 @@
+#; $ as -o test.o gas-cfi-test.s && gcc -nostdlib -o test test.o
+
+	.text
+
+#; func_locvars
+#; - function with a space on the stack 
+#;   allocated for local variables
+
+	.type	func_locvars,@function
+func_locvars:
+	.cfi_startproc
+	
+	#; alocate space for local vars
+	suba.w	#0x1234,%sp
+	.cfi_adjust_cfa_offset	0x1234
+	
+	#; dummy body
+	moveq.l	#1,%d0
+	
+	#; release space of local vars and return
+	adda.w	#0x1234,%sp
+	.cfi_adjust_cfa_offset	-0x1234
+	rts
+	.cfi_endproc
+
+#; func_prologue
+#; - functions that begins with standard
+#;   prologue: "link %a6,#0"
+
+	.type	func_prologue,@function
+func_prologue:
+	.cfi_startproc
+	
+	#; prologue, CFI is valid after 
+	#; each instruction.
+	link	%a6,#0
+	.cfi_def_cfa_offset	8
+	.cfi_offset		a6,-8
+	.cfi_def_cfa_register	a6
+
+	#; function body
+	jbsr	func_locvars
+	addq.l	#3, %d0
+
+	#; epilogue with valid CFI
+	#; (we're better than gcc :-)
+	unlk	%a6
+	.cfi_def_cfa_register	sp
+	rts
+	.cfi_endproc
+
+#; main
+#; - typical function
+	.type	main,@function
+main:
+	.cfi_startproc
+	
+	#; only function body that doesn't
+	#; touch the stack at all.
+	jbsr	func_prologue
+	
+	#; return
+	rts
+	.cfi_endproc
Index: gas/testsuite/gas/cfi/cfi.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/cfi/cfi.exp,v
retrieving revision 1.8
diff -u -a -p -r1.8 cfi.exp
--- gas/testsuite/gas/cfi/cfi.exp	10 Jul 2003 16:46:38 -0000	1.8
+++ gas/testsuite/gas/cfi/cfi.exp	3 Aug 2003 17:11:15 -0000
@@ -36,6 +36,9 @@ if [istarget "x86_64-*"] then {
 	run_dump_test "cfi-s390x-1"
     }
 
+} elseif { [istarget "m68*-*"] } then {
+    run_dump_test "cfi-m68k"
+
 } else {
     return
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]