Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception handling for moxie #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcc/config/moxie/moxie-protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */

extern void moxie_expand_prologue (void);
extern void moxie_expand_epilogue (void);
extern void moxie_expand_epilogue (int);
extern int moxie_initial_elimination_offset (int, int);
extern bool moxie_offset_address_p (rtx);
7 changes: 5 additions & 2 deletions gcc/config/moxie/moxie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,15 @@ moxie_expand_prologue (void)
}

void
moxie_expand_epilogue (void)
moxie_expand_epilogue (int style)
{
int regno;
rtx reg;

if (cfun->machine->callee_saved_reg_size != 0)
{
reg = gen_rtx_REG (Pmode, MOXIE_R12);
if (style) emit_insn (gen_movsi_push(reg));
if (cfun->machine->callee_saved_reg_size <= 255)
{
emit_move_insn (reg, hard_frame_pointer_rtx);
Expand All @@ -356,9 +357,11 @@ moxie_expand_epilogue (void)
rtx preg = gen_rtx_REG (Pmode, regno);
emit_insn (gen_movsi_pop (reg, preg));
}
if (style) emit_insn (gen_movsi_pop(gen_rtx_REG(Pmode, MOXIE_SP), reg));
}

emit_jump_insn (gen_returner ());
if (style) emit_jump_insn (gen_eh_returner());
else emit_jump_insn (gen_returner ());
}

/* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
Expand Down
15 changes: 12 additions & 3 deletions gcc/config/moxie/moxie.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,21 @@ enum reg_class
gen_frame_mem (Pmode, \
plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD))

#define RETURN_ADDR_RTX(C,FA) C!=0?NULL_RTX: \
gen_frame_mem (Pmode, \
plus_constant (Pmode, hard_frame_pointer_rtx, UNITS_PER_WORD))

/* Describe how we implement __builtin_eh_return. */
#define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N+2) : INVALID_REGNUM)
#define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N+8) : INVALID_REGNUM)

/* Store the return handler into the call frame. */
#define EH_RETURN_HANDLER_RTX \
/*#define EH_RETURN_HANDLER_RTX \
gen_frame_mem (Pmode, \
plus_constant (Pmode, frame_pointer_rtx, UNITS_PER_WORD))
plus_constant (Pmode, frame_pointer_rtx, UNITS_PER_WORD))*/
#define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, MOXIE_R12)
#define INCOMING_FRAME_SP_OFFSET 12
#define ARG_POINTER_CFA_OFFSET(FUNDECL) 12
#define DYNAMIC_CHAIN_ADDRESS(FRAMEADDR) plus_constant(Pmode, FRAMEADDR, -12)

/* Storage Layout */

Expand Down Expand Up @@ -424,5 +432,6 @@ enum reg_class
}

#define HAS_LONG_UNCOND_BRANCH true
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) DW_EH_PE_sdata4

#endif /* GCC_MOXIE_H */
35 changes: 34 additions & 1 deletion gcc/config/moxie/moxie.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@
""
"
{
moxie_expand_epilogue ();
moxie_expand_epilogue (0);
DONE;
}
")
Expand All @@ -515,3 +515,36 @@
[(return)]
"reload_completed"
"ret")

(define_expand "eh_return"
[(use (match_operand 0 "register_operand"))]
""
{
rtx tmp, sa = EH_RETURN_STACKADJ_RTX, ra = operands[0];

/* Tricky bit: we write the address of the handler to which we will
be returning into someone else's stack frame, one word below the
stack address we wish to restore. */
tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
tmp = plus_constant (Pmode, tmp, 2*UNITS_PER_WORD);
tmp = gen_rtx_MEM (Pmode, tmp);
emit_move_insn (tmp, ra);

emit_jump_insn (gen_eh_return_internal ());
emit_barrier ();
DONE;
})

(define_insn_and_split "eh_return_internal"
[(eh_return)]
""
"#"
"epilogue_completed"
[(const_int 0)]
"moxie_expand_epilogue (1); DONE;")

(define_insn "eh_returner"
[(simple_return)]
""
"add\\t$r12, $fp\\n\\tinc\\t$r12, 12\\n\\tmov\\t$sp, $r12\\n\\tld.l\\t$fp, ($fp)\\n\\tcmp\\t$fp, $r12\\n\\tbltu\\t.-6\\n\\tldo.l\\t$r12, -4($r12)\\n\\tjmp\\t$r12"
[(set_attr "length" "18")])