From 8c91384816c17856593e835004ee44559f49cc01 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 18 Sep 2016 20:16:20 +0000 Subject: Adds thumb directives and fixes for storing the PC Added directives: - .syntax unified at the start of the file - .thumb at the start of each code section - .thumb_func before each code label Storing the PC: - PC cannot be Rd for str, hence we need the scratch register --- cgthumb2was.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cgthumb2was.c b/cgthumb2was.c index 8529878..d43a5ec 100644 --- a/cgthumb2was.c +++ b/cgthumb2was.c @@ -92,6 +92,7 @@ static void w_as_to_code_section (VOID) { if (in_data_section){ in_data_section=0; + w_as_instruction_without_parameters (".thumb"); w_as_instruction_without_parameters (".text"); } } @@ -387,6 +388,7 @@ static void w_as_define_code_label (LABEL *label) w_as_newline(); } + w_as_instruction_without_parameters (".thumb_func"); w_as_label (label->label_name); w_as_colon(); w_as_newline(); @@ -1491,15 +1493,21 @@ static void w_as_jsr_instruction (struct instruction *instruction) w_as_newline_after_instruction(); } else { if (instruction->instruction_arity>1) + w_as_opcode ("mov"); + w_as_scratch_register_comma(); + fprintf (assembly_file,"pc"); + w_as_newline_after_instruction(); switch (instruction->instruction_parameters[1].parameter_type){ case P_INDIRECT_WITH_UPDATE: w_as_opcode ("str"); - fprintf (assembly_file,"pc,[sp,#%d]!",instruction->instruction_parameters[1].parameter_offset); + w_as_scratch_register_comma(); + fprintf (assembly_file,"[sp,#%d]!",instruction->instruction_parameters[1].parameter_offset); w_as_newline_after_instruction(); break; case P_INDIRECT: w_as_opcode ("str"); - fprintf (assembly_file,"pc,[sp,#%d]",instruction->instruction_parameters[1].parameter_offset); + w_as_scratch_register_comma(); + fprintf (assembly_file,"[sp,#%d]",instruction->instruction_parameters[1].parameter_offset); w_as_newline_after_instruction(); break; } @@ -2869,6 +2877,8 @@ void write_assembly (VOID) instruction_n_after_ltorg = 0u; ltorg_at_instruction_n = 0u-1u; + fprintf (assembly_file,"\t.syntax unified"); + w_as_newline(); fprintf (assembly_file,"\t.fpu\tvfp"); w_as_newline(); -- cgit v1.2.3