프로세서 예외 처리; highest priority active interrupt.MOV R12, #IntBase ; Get the interrupt controller's; base address.LDR R12, [R12, #IntLevel] ; Get the interrupt level (0 to 31) .; Now read-modify-write the CPSR; to enable interrupts.MRS lr, APSR ; Read the status register.BIC lr, lr, #0x80 ; Clear the I bit; (use 0x40 for the F bit) .MSR CPSR_c, lr ; Write it back to re-enable; interrupts andLDR pc, [pc, R12, LSL #2] ; jump to the correct handler.; PC base address points to this; instruction + 8NOP; pad so the PC indexes this table.; Table of handler start addressesDCD Priority0HandlerDCD Priority1HandlerDCD Priority2Handler; ...Priority0HandlerPUSH {R0-R11} ; Save other working registers.; Insert handler code here.; ...POP {R0-R11} ; Restore working registers (not R12) .; Now read-modify-write the CPSR; to disable interrupts.MRS R12, APSR ; Read the status register.ORR R12, R12, #0x80 ; Set the I bit; (use 0x40 for the F bit) .MSR CPSR_c, R12 ; Write it back to disable interrupts.; Now that interrupt disabled, can safely; restore SPSR then return.POP {r12,lr} ; Restore R12 and get SPSR.MSR SPSR_cxsf, lr ; Restore status register from R14.LDM sp!, {pc}^ ; Return from handler.Priority1Handler; ...컨텍스트 전환6-19페이지의 예제 6-7에서는 사용자 모드 프로세스에서 컨텍스트 전환을 수행합니다. 이 코드는 실행할 수 있는 프로세스의 PCB (프로세스 제어 블록) 에 대한포인터 목록을 기반으로 합니다.6-19페이지의 그림 6-2에서는 이 예제에 필요한 PCB의 레이아웃을 보여 줍니다.6-18 Copyright © 2002-2008 <strong>ARM</strong> Limited. All rights reserved. <strong>ARM</strong> DUI 0203IKNon-ConfidentialUnrestricted Access
프로세서 예외 처리PCBpointerr14r13r12r11r10r9r8r7r6r5r4r3r2r1r0lrspsrUser moderegisters그림 6-2 PCB 레이아웃R12는 실행할 다음 프로세스의 PCB에 대한 포인터를 가리키며 목록의 끝에는 0포인터가 있습니다. 레지스터 R13은 PCB에 대한 포인터로, 일정 시간마다 저장되므로 진입 시점에서는 현재 실행하고 있는 프로세스의 PCB를 가리킵니다.예제 6-7 사용자 모드 프로세스에 대한 컨텍스트 전환STM sp,{R0-lr}^ ; Dump user registers above R13.MRS R0, SPSR ; Pick up the user statusSTMDB sp, {R0, lr} ; and dump with return address below.LDR sp, [R12], #4 ; Load next process info pointer.CMP sp, #0 ; If it is zero, it is invalidLDMDBNE sp, {R0, lr}; Pick up status and return address.MSRNE SPSR_cxsf, R0 ; Restore the status.LDMNE sp, {R0 - lr}^ ; Get the rest of the registersNOPSUBSNE pc, lr, #4; and return and restore CPSR.; Insert "no next process code" here.6.2.8 SVC 처리기예외 처리기에서는 예외가 발생할 때 프로세서가 <strong>ARM</strong> 상태에 있었는지 아니면Thumb 상태에 있었는지를 확인해야 할 수 있습니다.<strong>ARM</strong> DUI 0203IK Copyright © 2002-2008 <strong>ARM</strong> Limited. All rights reserved. 6-19Unrestricted AccessNon-Confidential