From bc21634b467631b3350b42f83894a7339bea54b1 Mon Sep 17 00:00:00 2001 From: florian Date: Thu, 13 May 2021 18:59:28 +0000 Subject: [PATCH] * AVR: made avr_des intrinsic more usefull git-svn-id: trunk@49362 - --- compiler/avr/navrinl.pas | 72 ++++++++++++++++++++++++++++++++++------ rtl/avr/intrinsics.pp | 2 +- tests/test/tdes1.pp | 4 ++- tests/test/tdes2.pp | 4 ++- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/compiler/avr/navrinl.pas b/compiler/avr/navrinl.pas index 17137a773f..aca5b699bc 100644 --- a/compiler/avr/navrinl.pas +++ b/compiler/avr/navrinl.pas @@ -75,6 +75,8 @@ unit navrinl; function tavrinlinenode.pass_typecheck_cpu : tnode; + var + para1,para2,para3,para4: tcallparanode; begin Result:=nil; case inlinenumber of @@ -99,15 +101,19 @@ unit navrinl; end; in_avr_des: begin - CheckParameters(2); + CheckParameters(4); resultdef:=voidtype; - if not(is_constintnode(tcallparanode(left).paravalue)) then - MessagePos(tcallparanode(left).paravalue.fileinfo,type_e_constant_expr_expected); - if not(is_constboolnode(tcallparanode(tcallparanode(left).nextpara).paravalue)) then - MessagePos(tcallparanode(tcallparanode(left).nextpara).paravalue.fileinfo,type_e_constant_expr_expected); - if (tordconstnode(tcallparanode(left).paravalue).value<0) or - (tordconstnode(tcallparanode(left).paravalue).value>15) then - MessagePos(tcallparanode(left).paravalue.fileinfo,parser_e_range_check_error); + para4:=tcallparanode(left); + para3:=tcallparanode(tcallparanode(para4).nextpara); + para2:=tcallparanode(tcallparanode(para3).nextpara); + para1:=tcallparanode(tcallparanode(para2).nextpara); + if not(is_constintnode(para4.paravalue)) then + MessagePos(para4.paravalue.fileinfo,type_e_constant_expr_expected); + if not(is_constboolnode(para3.paravalue)) then + MessagePos(para3.paravalue.fileinfo,type_e_constant_expr_expected); + if (tordconstnode(para4.paravalue).value<0) or + (tordconstnode(para4.paravalue).value>15) then + MessagePos(para4.paravalue.fileinfo,parser_e_range_check_error); end; else Result:=inherited pass_typecheck_cpu; @@ -142,6 +148,10 @@ unit navrinl; procedure tavrinlinenode.pass_generate_code_cpu; + var + para1,para2,para3,para4: tcallparanode; + ref: treference; + r: TRegister; begin case inlinenumber of in_avr_nop: @@ -170,12 +180,52 @@ unit navrinl; end; in_avr_des: begin - if tordconstnode(tcallparanode(tcallparanode(left).nextpara).paravalue).value=0 then + para4:=tcallparanode(left); + para3:=tcallparanode(tcallparanode(para4).nextpara); + para2:=tcallparanode(tcallparanode(para3).nextpara); + para1:=tcallparanode(tcallparanode(para2).nextpara); + secondpass(tcallparanode(para1).paravalue); + secondpass(tcallparanode(para2).paravalue); + + cg.getcpuregister(current_asmdata.CurrAsmList,NR_R30); + cg.getcpuregister(current_asmdata.CurrAsmList,NR_R31); + + cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,tcallparanode(para2).paravalue.location.reference,NR_R30); + reference_reset(ref,0,[]); + ref.base:=NR_R30; + for r:=NR_R8 to NR_R15 do + begin + cg.getcpuregister(current_asmdata.CurrAsmList,r); + cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_8,OS_8,ref,r); + inc(ref.offset); + end; + cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,tcallparanode(para1).paravalue.location.reference,NR_R30); + reference_reset(ref,0,[]); + ref.base:=NR_R30; + for r:=NR_R0 to NR_R7 do + begin + cg.getcpuregister(current_asmdata.CurrAsmList,r); + cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_8,OS_8,ref,r); + inc(ref.offset); + end; + if tordconstnode(para3.paravalue).value=0 then current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLH)) else current_asmdata.CurrAsmList.concat(taicpu.op_none(A_SEH)); - current_asmdata.CurrAsmList.concat(taicpu.op_const(A_DES,int64(tordconstnode(tcallparanode(left).paravalue).value))); - end; + current_asmdata.CurrAsmList.concat(taicpu.op_const(A_DES,int64(tordconstnode(para4.paravalue).value))); + + for r:=NR_R8 to NR_R15 do + cg.ungetcpuregister(current_asmdata.CurrAsmList,r); + + { save data } + ref.offset:=0; + for r:=NR_R0 to NR_R7 do + begin + cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_8,OS_8,r,ref); + cg.ungetcpuregister(current_asmdata.CurrAsmList,r); + inc(ref.offset); + end; + end else inherited pass_generate_code_cpu; end; diff --git a/rtl/avr/intrinsics.pp b/rtl/avr/intrinsics.pp index d6b66389c3..aa33cf3891 100644 --- a/rtl/avr/intrinsics.pp +++ b/rtl/avr/intrinsics.pp @@ -29,7 +29,7 @@ unit intrinsics; { Restores SREG } procedure avr_restore(old_sreg: byte); [INTERNPROC: in_avr_restore]; - procedure avr_des(decrypt: boolean;round: byte);[INTERNPROC: in_avr_des]; + procedure avr_des(var data;var key;decrypt: boolean;round: byte);[INTERNPROC: in_avr_des]; implementation diff --git a/tests/test/tdes1.pp b/tests/test/tdes1.pp index 58ed48502f..21d050536e 100644 --- a/tests/test/tdes1.pp +++ b/tests/test/tdes1.pp @@ -2,8 +2,10 @@ { %norun } uses intrinsics; +var + data,key : array[0..7] of byte; begin - avr_des(true,1); + avr_des(data,key,true,1); end. \ No newline at end of file diff --git a/tests/test/tdes2.pp b/tests/test/tdes2.pp index 9e5499579f..2dedd5d1a8 100644 --- a/tests/test/tdes2.pp +++ b/tests/test/tdes2.pp @@ -3,8 +3,10 @@ { %norun } uses intrinsics; +var + data,key : array[0..7] of byte; begin - avr_des(true,100); + avr_des(data,key,true,100); end. \ No newline at end of file