
 IF :DEF:|ads$version| 
      PRESERVE8 
     AREA ACodeForIRAM, CODE, READONLY
 ELSE 
    AREA ACodeForIRAM, CODE, READONLY, INTERWORK
 ENDIF
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































      CODE32

      EXPORT GSMDisableInterrupts
      EXPORT GSMRestoreCPUState
      EXPORT GSMDisableALLInterrupts
      EXPORT GSMRestoreALLCPUState
      EXPORT SlowClkDis
      EXPORT RefOscRequest
      EXPORT GSMGetPrevARMSP
      IMPORT DisIntsLinkRegister
      IMPORT DisIntsStartTime
      IMPORT DisIntsEndTime
      IMPORT GSMExitIntsDisabledTooLong
      IMPORT InterruptTooLongTime
      IMPORT DisIntsTimeOverrun


GSMDisableALLInterrupts
GSMDisableInterrupts
      MRS  r0,cpsr        

      ORR  r1,r0,#&C0     
      MSR  cpsr_cxsf,r1   

      TST  r0,#0xC0       
      BNE  DisIntsDone    

      LDR  r1,=(0x700C6000 + 0x034) 
      LDR  r1,[r1]
      LDR  r2,=|DisIntsStartTime| 
      STR  r1,[r2]

DisIntsDone
      BX   lr             


GSMRestoreALLCPUState
GSMRestoreCPUState
      TST   r0,#0xC0
      BNE   EnableInts      

      LDR   r1,=(0x700C6000 + 0x034)  
      LDR   r1,[r1]

      LDR   r2,=|DisIntsStartTime|
      LDR   r2,[r2]

      CMP   r2,r1           
      BLT   EnableInts      

      SUB   r1,r2,r1        
      LDR   r2,=|InterruptTooLongTime|
      LDR   r2,[r2]
      CMP   r1,r2          

      BLT   EnableInts      

      LDR   r3,=|DisIntsLinkRegister| 
      STR   r14,[r3]        
      LDR   r3,=|DisIntsEndTime|
      STR   r1,[r3]         

      B     DisIntsTimeOverrun 

EnableInts      
      MSR  cpsr_cxsf,r0    
      BX   lr         


    CODE16                              

 IF :DEF:|ads$version| 
    IMPORT lib_heap
    EXPORT __user_initial_stackheap

__user_initial_stackheap    
    LDR   r0, =lib_heap
    MOV   pc,lr
 ENDIF  


   EXPORT InstructionWaits

InstructionWaits
   LSR  r0,#2 
ContinueWaiting
   CMP r0,#0 
   BEQ InstructionWaitsReturnToCaller 
   SUB r0,#1 
   B ContinueWaiting 
InstructionWaitsReturnToCaller
   MOV pc, lr 


      CODE32
GSMGetPrevARMSP
      MRS   r1,cpsr    
      AND   r3,r1,#&1F 
      AND   r2,r0,#&1F 
      CMP   r2,r3      
      BEQ   EasySP     
      CMP   r2,#&10    
      BEQ   ShitSP     
      BIC   r3,r1,#&1F 
      ORR   r3,r3,r2   
      MSR   cpsr_cxsf,r3    
      MOV   r0,r13
      MSR   cpsr_cxsf,r1    
      BX    lr         
ShitSP
      SUB   sp,sp,#4   
      STMFD sp,{r13}^  
      NOP                     
      LDMFD sp!,{r0}   
      BX    lr         
EasySP
      MOV   r0,r13     
      BX    lr         


   AREA Startup_bss, DATA, READWRITE, NOINIT
SlowClkDis
      DCD   0
RefOscRequest      
      DCD   0

      END
