Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Theodore A. Roth" <troth@openavr.org>
To: gdb-patches@sources.redhat.com
Subject: [commit] [avr] prologue scanner update
Date: Mon, 16 Jun 2003 00:44:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.44.0306151740230.20396-200000@bozoland.mynet> (raw)

[-- Attachment #1: Type: TEXT/PLAIN, Size: 411 bytes --]

Hi,

Committed the attached.

This updates the avr prologue scanner and fixes a few problems.

Ted Roth

2003-06-15  Theodore A. Roth  <troth@openavr.org>

        * avr-tdep.c (avr_scan_prologue): Update comment describing the various
        prologue types.
        Properly scan prologues generated by gcc with the -mcall-prologues
        option.
        Add code to scan -mcall-prologues for mega devices.

[-- Attachment #2: Type: TEXT/PLAIN, Size: 8075 bytes --]

2003-06-15  Theodore A. Roth  <troth@openavr.org>

	* ChangeLog:
	* avr-tdep.c:

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.4395
diff -u -p -r1.4395 ChangeLog
--- ChangeLog	15 Jun 2003 22:01:05 -0000	1.4395
+++ ChangeLog	16 Jun 2003 00:34:27 -0000
@@ -1,5 +1,13 @@
 2003-06-15  Theodore A. Roth  <troth@openavr.org>
 
+	* avr-tdep.c (avr_scan_prologue): Update comment describing the various
+	prologue types.
+	Properly scan prologues generated by gcc with the -mcall-prologues 
+	option.
+	Add code to scan -mcall-prologues for mega devices.
+
+2003-06-15  Theodore A. Roth  <troth@openavr.org>
+
 	* avr-tdep.c (avr_register_byte): Delete function.
 	(avr_register_raw_size): Delete function.
 	(avr_register_virtual_size): Delete function.
Index: avr-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/avr-tdep.c,v
retrieving revision 1.57
diff -u -p -r1.57 avr-tdep.c
--- avr-tdep.c	15 Jun 2003 22:01:05 -0000	1.57
+++ avr-tdep.c	16 Jun 2003 00:34:34 -0000
@@ -359,26 +359,81 @@ avr_read_fp (void)
      3) the offsets of saved regs
    This information is stored in the "extra_info" field of the frame_info.
 
-   A typical AVR function prologue might look like this:
-        push rXX
-        push r28
-        push r29
-        in r28,__SP_L__
-        in r29,__SP_H__
-        sbiw r28,<LOCALS_SIZE>
-        in __tmp_reg__,__SREG__
+   Some devices lack the sbiw instruction, so on those replace this:
+        sbiw    r28, XX
+   with this:
+        subi    r28,lo8(XX)
+        sbci    r29,hi8(XX)
+
+   A typical AVR function prologue with a frame pointer might look like this:
+        push    rXX        ; saved regs
+        ...
+        push    r28
+        push    r29
+        in      r28,__SP_L__
+        in      r29,__SP_H__
+        sbiw    r28,<LOCALS_SIZE>
+        in      __tmp_reg__,__SREG__
         cli
-        out __SP_L__,r28
-        out __SREG__,__tmp_reg__
-        out __SP_H__,r29
-
-  A `-mcall-prologues' prologue look like this:
-        ldi r26,<LOCALS_SIZE>
-        ldi r27,<LOCALS_SIZE>/265
-        ldi r30,pm_lo8(.L_foo_body)
-        ldi r31,pm_hi8(.L_foo_body)
-        rjmp __prologue_saves__+RRR
-  .L_foo_body:  */
+        out     __SP_L__,r28
+        out     __SREG__,__tmp_reg__
+        out     __SP_H__,r29
+
+   A typical AVR function prologue without a frame pointer might look like
+   this:
+        push    rXX        ; saved regs
+        ...
+
+   A main function prologue looks like this:
+        ldi     r28,lo8(<RAM_ADDR> - <LOCALS_SIZE>)
+        ldi     r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>)
+        out     __SP_H__,r29
+        out     __SP_L__,r28
+
+   A signal handler prologue looks like this:
+        push    __zero_reg__
+        push    __tmp_reg__
+        in      __tmp_reg__, __SREG__
+        push    __tmp_reg__
+        clr     __zero_reg__
+        push    rXX             ; save registers r18:r27, r30:r31
+        ...
+        push    r28             ; save frame pointer
+        push    r29
+        in      r28, __SP_L__
+        in      r29, __SP_H__
+        sbiw    r28, <LOCALS_SIZE>
+        out     __SP_H__, r29
+        out     __SP_L__, r28
+        
+   A interrupt handler prologue looks like this:
+        sei
+        push    __zero_reg__
+        push    __tmp_reg__
+        in      __tmp_reg__, __SREG__
+        push    __tmp_reg__
+        clr     __zero_reg__
+        push    rXX             ; save registers r18:r27, r30:r31
+        ...
+        push    r28             ; save frame pointer
+        push    r29
+        in      r28, __SP_L__
+        in      r29, __SP_H__
+        sbiw    r28, <LOCALS_SIZE>
+        cli
+        out     __SP_H__, r29
+        sei     
+        out     __SP_L__, r28
+
+   A `-mcall-prologues' prologue looks like this (Note that the megas use a
+   jmp instead of a rjmp, thus the prologue is one word larger since jmp is a
+   32 bit insn and rjmp is a 16 bit insn):
+        ldi     r26,lo8(<LOCALS_SIZE>)
+        ldi     r27,hi8(<LOCALS_SIZE>)
+        ldi     r30,pm_lo8(.L_foo_body)
+        ldi     r31,pm_hi8(.L_foo_body)
+        rjmp    __prologue_saves__+RRR
+        .L_foo_body:  */
 
 static void
 avr_scan_prologue (struct frame_info *fi)
@@ -457,10 +512,9 @@ avr_scan_prologue (struct frame_info *fi
 	}
     }
 
-  /* Scanning `-mcall-prologues' prologue
-     FIXME: mega prologue have a 12 bytes long */
+  /* Scanning `-mcall-prologues' prologue  */
 
-  while (prologue_len <= 12)	/* I'm use while to avoit many goto's */
+  while (1)	/* Using a while to avoid many goto's */
     {
       int loc_size;
       int body_addr;
@@ -490,9 +544,6 @@ avr_scan_prologue (struct frame_info *fi
 	break;
       body_addr |= ((insn & 0xf) | ((insn & 0x0f00) >> 4)) << 8;
 
-      if (body_addr != (prologue_start + 10) / 2)
-	break;
-
       msymbol = lookup_minimal_symbol ("__prologue_saves__", NULL, NULL);
       if (!msymbol)
 	break;
@@ -500,15 +551,33 @@ avr_scan_prologue (struct frame_info *fi
       /* FIXME: prologue for mega have a JMP instead of RJMP */
       insn = EXTRACT_INSN (&prologue[vpc + 8]);
       /* rjmp __prologue_saves__+RRR */
-      if ((insn & 0xf000) != 0xc000)
-	break;
+      if ((insn & 0xf000) == 0xc000)
+        {
+          /* Extract PC relative offset from RJMP */
+          i = (insn & 0xfff) | (insn & 0x800 ? (-1 ^ 0xfff) : 0);
+          /* Convert offset to byte addressable mode */
+          i *= 2;
+          /* Destination address */
+          i += prologue_start + 10;
+
+          if (body_addr != (prologue_start + 10) / 2)
+            break;
+        }
+      /* jmp __prologue_saves__+RRR */
+      else if ((insn & 0xfe0e) == 0x940c)
+        {
+          /* Extract absolute PC address from JMP */
+          i = (((insn & 0x1) | ((insn & 0x1f0) >> 3) << 16)
+            | (EXTRACT_INSN (&prologue[vpc + 10]) & 0xffff));
+          /* Convert address to byte addressable mode */
+          i *= 2;
+
+          if (body_addr != (prologue_start + 12)/2)
+            break;
+        }
+      else
+        break;
 
-      /* Extract PC relative offset from RJMP */
-      i = (insn & 0xfff) | (insn & 0x800 ? (-1 ^ 0xfff) : 0);
-      /* Convert offset to byte addressable mode */
-      i *= 2;
-      /* Destination address */
-      i += vpc + prologue_start + 10;
       /* Resovle offset (in words) from __prologue_saves__ symbol.
          Which is a pushes count in `-mcall-prologues' mode */
       num_pushes = AVR_MAX_PUSHES - (i - SYMBOL_VALUE_ADDRESS (msymbol)) / 2;
@@ -606,9 +675,9 @@ avr_scan_prologue (struct frame_info *fi
      sbci r29,hi8(XX)
      in __tmp_reg__,__SREG__
      cli
-     out __SP_L__,r28
+     out __SP_H__,r29
      out __SREG__,__tmp_reg__
-     out __SP_H__,r29 */
+     out __SP_L__,r28 */
 
   if (scan_stage == 2 && vpc + 12 <= prologue_len)
     {
@@ -616,19 +685,19 @@ avr_scan_prologue (struct frame_info *fi
       unsigned char img[] = {
 	0x0f, 0xb6,		/* in r0,0x3f */
 	0xf8, 0x94,		/* cli */
-	0xcd, 0xbf,		/* out 0x3d,r28 ; SPL */
+	0xde, 0xbf,		/* out 0x3e,r29 ; SPH */
 	0x0f, 0xbe,		/* out 0x3f,r0  ; SREG */
-	0xde, 0xbf		/* out 0x3e,r29 ; SPH */
+	0xcd, 0xbf		/* out 0x3d,r28 ; SPL */
       };
       unsigned char img_sig[] = {
-	0xcd, 0xbf,		/* out 0x3d,r28 ; SPL */
-	0xde, 0xbf		/* out 0x3e,r29 ; SPH */
+	0xde, 0xbf,		/* out 0x3e,r29 ; SPH */
+	0xcd, 0xbf		/* out 0x3d,r28 ; SPL */
       };
       unsigned char img_int[] = {
 	0xf8, 0x94,		/* cli */
-	0xcd, 0xbf,		/* out 0x3d,r28 ; SPL */
+	0xde, 0xbf,		/* out 0x3e,r29 ; SPH */
 	0x78, 0x94,		/* sei */
-	0xde, 0xbf		/* out 0x3e,r29 ; SPH */
+	0xcd, 0xbf		/* out 0x3d,r28 ; SPL */
       };
 
       insn = EXTRACT_INSN (&prologue[vpc]);

                 reply	other threads:[~2003-06-16  0:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0306151740230.20396-200000@bozoland.mynet \
    --to=troth@openavr.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox