khypervisor  v1
monitor.S
Go to the documentation of this file.
00001 /*
00002  * monitor.S - Hyp mode portion of Monitor code
00003  *
00004  * Copyright (C) 2013 KESL. All rights reserved.
00005  *
00006  */
00007 
00008     .syntax unified
00009     .arch_extension sec
00010     .arch_extension virt
00011     .text
00012 
00013 
00014 .global monitor_hyp_vectors
00015 /*
00016  * Monitor Vector Table
00017  */
00018 .align 5
00019 monitor_hyp_vectors:
00020     .word 0 /* reset */
00021     b   trap_unhandled  /* undef*/
00022     b   trap_unhandled  /* hypervisor */
00023     b   trap_unhandled  /* pabt*/
00024     b   trap_dabt   /* dabt */
00025     b   trap_hvc    /* hvc */
00026     b   trap_irq    /* irq */
00027     b   trap_unhandled  /* fiq*/
00028 
00029 
00030 trap_hvc:
00031     @ Push registers
00032     push    {r0-r12}
00033     mrs r0, spsr_hyp
00034     mrs r1, elr_hyp
00035     push    {r0, r1, lr}
00036 
00037     @ service other argument values -> _hyp_hvc_service(sp)
00038     mov r0, sp
00039     bl  _hyp_hvc_service    @ r0: HSR
00040 
00041     @ r0 = return
00042     tst r0, #1          
00043     @ if return == HYP_RET_STAY -> stay in Hyp mode 
00044     bne 1f          
00045     
00046     @ Pop registers
00047     pop     {r0-r1, lr}
00048     msr     spsr_hyp, r0
00049     msr     elr_hyp, r1
00050     pop     {r0-r12}
00051 
00052     @ else if return == HYP_RET_ERET -> Exception Return
00053     eret
00054     
00055 1:  
00056     @ Pop registers
00057     pop     {r0-r1, lr}
00058     tst     r0, #0x1f
00059     msrne   spsr_hyp, r0
00060     msr elr_hyp, r1
00061     pop     {r0-r12}
00062     @ stay in Hyp mode
00063     mrs lr, elr_hyp
00064     mov pc, lr
00065 
00066 trap_dabt:
00067     @ Push registers
00068     push    {r0-r12}
00069     mrs r0, spsr_hyp
00070     mrs r1, elr_hyp
00071     push    {r0, r1, lr}
00072 
00073     @ service other argument values -> _hyp_trap_dabort(sp)
00074     mov r0, sp
00075     bl  _hyp_trap_dabort    @ r0: HSR
00076 
00077     @ if (return == 0) execute a conditional code
00078     @ tst   r0, #1          
00079     @ <conditional code>
00080 
00081     @ Pop registers
00082     pop     {r0-r1, lr}
00083     msr spsr_hyp, r0
00084     msr elr_hyp, r1
00085     pop     {r0-r12}
00086     eret
00087 
00088 trap_irq:
00089     @ Push registers
00090     push    {r0-r12}
00091     mrs r0, spsr_hyp
00092     mrs r1, elr_hyp
00093     push    {r0, r1, lr}
00094 
00095     @ service other argument values -> _hyp_trap_irq(sp)
00096     mov r0, sp
00097     bl  _hyp_trap_irq   @ r0: HSR
00098 
00099     @ Pop registers
00100     pop     {r0-r1, lr}
00101     msr     spsr_hyp, r0
00102     msr     elr_hyp, r1
00103     pop     {r0-r12}
00104     eret
00105 
00106 trap_unhandled:
00107     @ Push registers
00108     push    {r0-r12}
00109     mrs     r0, spsr_hyp
00110     mrs     r1, elr_hyp
00111     push    {r0, r1, lr}
00112 
00113     @ service other argument values -> _hyp_trap_unhandled(sp)
00114     mov r0, sp
00115     bl  _hyp_trap_unhandled @ r0: HSR
00116 
00117     @ Pop registers
00118     pop     {r0-r1, lr}
00119     msr     spsr_hyp, r0
00120     msr     elr_hyp, r1
00121     pop     {r0-r12}
00122     eret
00123 
00124 .global __mon_switch_to_guest_context
00125 __mon_switch_to_guest_context:  @ struct arch_regs *r0
00126     ldmfd   r0!, {r1, r3, lr}
00127     msr     spsr_hyp, r1
00128     msr     elr_hyp, r3
00129     ldm     r0, {r0-r12}
00130     clrex
00131     eret
00132 .type __mon_switch_to_guest_context, %function
00133 
00134     
00135 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines