	.text
	//===-- __ucps_interrupt.S -------------------------===//

	.p2align	2, 0xff
	//DEFINE_COMPILERRT_FUNCTION(__ucps_interrupt)
	//.extern ucp_OSTCBHighRdy 	
	.global	__ucps2_interrupt5
	.global	OSStartHighRdy
	.global	__ucps2_OSCtxSw1
	.global	__ucps2_OSSave_ISP
	.global	__ucps2_reg_restore5
	.global	__ucps2_reg_restore2
	.global	OSIntCtxSw
	.global TASKCTXSW
	.type	__ucps2_interrupt5,@function
	
OSStartHighRdy:
	SCU: R1 = 0x1 (E) (L)||	SYN: R2 = %OSRunning (L);

	SCU: R2 = %OSRunning;

	AGU: [R2 + 0x0] = R1;
	//OSRunning=1 
	SCU: R3 = %OSTCBHighRdy (L);

	SCU: R3 = %OSTCBHighRdy;

	AGU: R2 = [R3 + 0x0];

	AGU: ISP = [R2 + 0x0];

 // scu: r1=  0x78 (e)(l);
 // scu:R10 = ISP + r1 (t);
 
// 	AGU: R1 = [R10 + 0x0];
//  scu: r1=  0x0c (e)(l);
//  scu:ISP = ISP + r1 (t);

     scu: r1=  0x80 (e)(l);
     scu:ISP = ISP + r1 (t);
   	 AGU: R1 = [ISP + 0x0];
     SCU: r2=  0x8 (e)(l);

	SCU: ISP = ISP + R2 (T);

	AGU: R31 = [ISP + 0x0];
	SEQ: if !R0, jump R31;	//pop off RETI value into RETS                   


__ucps2_OSSave_ISP:

	SCU: R6 = %OSTCBCur (L);

	SCU: R6 = %OSTCBCur;
	AGU: R7 = [R6 + 0x0];
	AGU: [R7 + 0x0] = ISP;
	SEQ: if !R0, jump R31;	//pop off RETI value into RETS 

TASKCTXSW:
  SEQ: IntEn (Disable);
  AGU:[ISP + -116] = R1;
  AGU:[ISP + -120] = R2;
  AGU:[ISP + -124] = R3;
  AGU:[ISP + -128] = R4;
  AGU:[ISP + -132] = R5;
  AGU:[ISP + -136] = R6;
  AGU:[ISP + -140] = R7;
  AGU:[ISP + -144] = R8;
  AGU:[ISP + -148] = R9;
  AGU:[ISP + -152] = R10;
  AGU:[ISP + -156] = R11;
  AGU:[ISP + -160] = R12;
  AGU:[ISP + -164] = R13;
  AGU:[ISP + -168] = R14;
  AGU:[ISP + -172] = R15;
  AGU:[ISP + -176] = R16;
  AGU:[ISP + -180] = R17;
  AGU:[ISP + -184] = R18;
  AGU:[ISP + -188] = R19;
  AGU:[ISP + -192] = R20;
  AGU:[ISP + -196] = R21;
  AGU:[ISP + -200] = R22;
  AGU:[ISP + -204] = R23;
  AGU:[ISP + -208] = R24;
  AGU:[ISP + -212] = R25;
  AGU:[ISP + -216] = DFP;//R26
  AGU:[ISP + -220] = IFP;//R28
  AGU:[ISP + -224] = R30;
  AGU:[ISP + -228] = R31;
  SCU:IFP = R0 + ISP;//R29
  SCU:DFP = R0 + DSP;//R27

  SCU: R25 = RFC;
  AGU:[ISP + -232] = R25;


  SCU: R25 = ReadC0;
  AGU:[ISP + -236] = R25;
  SCU: R25 = ReadC1;
  AGU:[ISP + -240] = R25;

  SCU: R25=  0x3a3b (e)(l)(u);
  AGU:[ISP + -244] = R25;
  
  SCU:R25 = -244 (L)(E);
  SCU:ISP = ISP + R25 (T);

  SCU: R1 = %__ucps2_OSSave_ISP (L)(E)(U);
  SCU: R1 = %__ucps2_OSSave_ISP;
  SEQ: call R1;

  SEQ: if !R0, jump %__ucps2_OSCtxSw1;


TASKCTXSW_END:

OSIntCtxSw:

	SCU: R1 = %OSPrioHighRdy (L);

	SCU: R1 = %OSPrioHighRdy;

	AGU: R2 = [R1 + 0x0] (B);

	SCU: R3 = %OSPrioCur (L);

	SCU: R3 = %OSPrioCur;

	AGU: R4 = [R3 + 0x0] (B);

	SCU: R5 = R2 == R4;

	SEQ: if R5, jump %OSIntCtxSw_end;

	AGU: [R3 + 0x0] = R2 (B);
	
	SCU: R6 = %OSTCBCur (L);	// ucp_OSPrioCur=ucp_OSPrioHighRdy

	SCU: R6 = %OSTCBCur;

	AGU: R2 = [R6 + 0x0];

	AGU: R9 = [R2 + 0x0];

	SCU: R3 = %OSTCBHighRdy (L);

	SCU: R3 = %OSTCBHighRdy;

	AGU: R2 = [R3 + 0x0];

	AGU: R9 = [R2 + 0x0];


//	AGU: [R6 + 0x0] = R9;
	AGU: [R6 + 0x0] = R2;

//	SCU: R27 = 0x90 (E) (L) (U);
	SCU: R27 = 0xF4 (E) (L) (U);

	SCU: R11 = R9 + R27;

	AGU:[IFP + -0x4] = R11;
	SEQ: if !R0, jump R31;


OSIntCtxSw_end:


__ucps2_OSCtxSw1:
	SCU: R1 = %OSPrioHighRdy (L);

	SCU: R1 = %OSPrioHighRdy;

	AGU: R2 = [R1 + 0x0] (B);

	SCU: R3 = %OSPrioCur (L);

	SCU: R3 = %OSPrioCur;

	AGU: R4 = [R3 + 0x0] (B);

	SCU: R5 = R2 == R4;

	SEQ: if R5, jump %OSIntCtxSw_end;


	AGU: [R3 + 0x0] = R2 (B);

	SCU: R6 = %OSTCBCur (L);	// ucp_OSPrioCur=ucp_OSPrioHighRdy

	SCU: R6 = %OSTCBCur;

	SCU: R3 = %OSTCBHighRdy (L);

	SCU: R3 = %OSTCBHighRdy;

	AGU: R2 = [R3 + 0x0];

	AGU: ISP = [R2 + 0x0];


	AGU: [R6 + 0x0] = R2;
	// ucp_OSTCBCur= ucp_OSTCBHighRdy

	SCU: R27 = 0xF4 (E) (L);

	SCU: IFP = ISP + R27;

//	AGU:R25 = [IFP + -144];
	AGU:R25 = [IFP + -244];

     SCU: R24 = 0x3a3b (L)(E)(U);
     SCU: R27 = R25 == R24;
     SEQ:if R27,jump %__ucps2_reg_restore2;

     SEQ:if !R27,jump %__ucps2_reg_restore5;


__ucps2_interrupt5:
  SEQ: IntEn (Disable);

  AGU:[ISP + -116] = R1;

  AGU:[ISP + -120] = R2;
  AGU:[ISP + -124] = R3;
  AGU:[ISP + -128] = R4;
  AGU:[ISP + -132] = R5;
  AGU:[ISP + -136] = R6;
  AGU:[ISP + -140] = R7;
  AGU:[ISP + -144] = R8;
  AGU:[ISP + -148] = R9;
  AGU:[ISP + -152] = R10;
  AGU:[ISP + -156] = R11;
  AGU:[ISP + -160] = R12;
  AGU:[ISP + -164] = R13;
  AGU:[ISP + -168] = R14;
  AGU:[ISP + -172] = R15;
  AGU:[ISP + -176] = R16;
  AGU:[ISP + -180] = R17;
  AGU:[ISP + -184] = R18;
  AGU:[ISP + -188] = R19;
  AGU:[ISP + -192] = R20;
  AGU:[ISP + -196] = R21;
  AGU:[ISP + -200] = R22;
  AGU:[ISP + -204] = R23;
  AGU:[ISP + -208] = R24;
  AGU:[ISP + -212] = R25;
  AGU:[ISP + -216] = DFP;//R26
  AGU:[ISP + -220] = IFP;//R28
  AGU:[ISP + -224] = R30;  //return address
  AGU:[ISP + -228] = R31;
  SCU:IFP = R0 + ISP;//R29
  SCU:DFP = R0 + DSP;//R27

  SCU: R25 = RFC;
  AGU:[ISP + -232] = R25;

  SCU: R25 = ReadC0;
  AGU:[ISP + -236] = R25;
  SCU: R25 = ReadC1;
  AGU:[ISP + -240] = R25;

  SCU: R25=  0xa3b3 (L)(E)(U);
  AGU:[ISP + -244] = R25;


  SCU:R25 = -244(L)(E);
  SCU:ISP = ISP + R25 (T);



//------------disable intflags-----------------

	SCU: R1 = %OSIntEnter (L)(E)(U);
	SCU: R1 = %OSIntEnter;
	SEQ: call R1;

	SCU: R1 = %ucp_int_disable (L)(E)(U);
	SCU: R1 = %ucp_int_disable;
	SEQ: call R1;

	SCU: R1 = %__ucps2_OSSave_ISP (L)(E)(U);
	SCU: R1 = %__ucps2_OSSave_ISP;
    SEQ: call R1;

	  
    SCU:R1 = %isr_entry (L)(E)(U);
    SCU:R1 = %isr_entry ;
    SEQ:call R1;
        

    SCU: R1 = %OSIntExit (L)(E)(U);
	SCU: R1 = %OSIntExit;
	SEQ: call R1;


    SCU: R1 = %ucp_int_enble (L)(E)(U);  //change timer 20230111
	SCU: R1 = %ucp_int_enble;            //change timer 20230111
	SEQ: call R1;                        //change timer 20230111

	AGU:R25 = [IFP + -244];

    SCU: R24 = 0x3a3b (L)(E)(U);
    SCU: R27 = R25 == R24;
    SEQ: if R27,jump %__ucps2_reg_restore2;

    SEQ:if !R27,jump %__ucps2_reg_restore5;


//---------restor register---------------------
__ucps2_reg_restore5:

	AGU:R25 = [IFP + -240];
	SCU: R0,C1 = R25 | R0;
	AGU:R25 = [IFP + -236];
	SCU: R0,C0 = R25 | R0;

	AGU:R25 = [IFP + -232];
	SCU: RFC = R25;

 	AGU:R31 = [IFP + -228];
	AGU:R30 = [IFP + -224];


//	AGU:IFP = [IFP + -220];
//  AGU:DFP = [IFP + -216];

	AGU:R25 = [IFP + -212];
	AGU:R24 = [IFP + -208];
	AGU:R23 = [IFP + -204];
	AGU:R22 = [IFP + -200];
	AGU:R21 = [IFP + -196];
	AGU:R20 = [IFP + -192];
	AGU:R19 = [IFP + -188];
	AGU:R18 = [IFP + -184];
	AGU:R17 = [IFP + -180];
	AGU:R16 = [IFP + -176];
	AGU:R15 = [IFP + -172];
	AGU:R14 = [IFP + -168];
	AGU:R13 = [IFP + -164];
	AGU:R12 = [IFP + -160];
	AGU:R11 = [IFP + -156];
	AGU:R10 = [IFP + -152];
	AGU:R9 = [IFP + -148];
	AGU:R8 = [IFP + -144];
	AGU:R7 = [IFP + -140];
	AGU:R6 = [IFP + -136];
	AGU:R5 = [IFP + -132];
	AGU:R4 = [IFP + -128];
	AGU:R3 = [IFP + -124];

	AGU:R2 = [IFP + -120];
	AGU:R1 = [IFP + -116];
	SCU:ISP = R0 + IFP;
	SCU:DSP = R0 + DFP;
	AGU:IFP = [ISP + -220];
	AGU:DFP = [ISP + -216];

	SEQ:jump R30(Enable); // wall timer:20230101



__ucps2_reg_restore2:

	AGU:R25 = [IFP + -240];
	SCU: R0,C1 = R25 | R0;
	AGU:R25 = [IFP + -236];
	SCU: R0,C0 = R25 | R0;

	AGU:R25 = [IFP + -232];
	SCU: RFC = R25;

 	AGU:R31 = [IFP + -228];
	AGU:R30 = [IFP + -224];

	AGU:R25 = [IFP + -212];
	AGU:R24 = [IFP + -208];
	AGU:R23 = [IFP + -204];
	AGU:R22 = [IFP + -200];
	AGU:R21 = [IFP + -196];
	AGU:R20 = [IFP + -192];
	AGU:R19 = [IFP + -188];
	AGU:R18 = [IFP + -184];
	AGU:R17 = [IFP + -180];
	AGU:R16 = [IFP + -176];
	AGU:R15 = [IFP + -172];
	AGU:R14 = [IFP + -168];
	AGU:R13 = [IFP + -164];
	AGU:R12 = [IFP + -160];
	AGU:R11 = [IFP + -156];
	AGU:R10 = [IFP + -152];
	AGU:R9 = [IFP + -148];
	AGU:R8 = [IFP + -144];
	AGU:R7 = [IFP + -140];
	AGU:R6 = [IFP + -136];
	AGU:R5 = [IFP + -132];
	AGU:R4 = [IFP + -128];
	AGU:R3 = [IFP + -124];
	AGU:R2 = [IFP + -120];
	AGU:R1 = [IFP + -116];
	SCU:ISP = R0 + IFP;
	SCU:DSP = R0 + DFP;
	AGU:IFP = [ISP + -220];
	AGU:DFP = [ISP + -216];

	SEQ: if !R0, jump R31(Enable);  // wall timer:20230101

	


Lfunc_end0:
	.size	__ucps_interrupt, Lfunc_end0-__ucps_interrupt
	//END_COMPILERRT_FUNCTION(__ucps_interrupt)
