Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Extensions to HVM ROS userspace library corresponding to HVM enhancements
[palacios.git] / guest / linux / hvm-ros / v3_hvm_ros_user_low_level.S
1 .section .text
2         
3 .extern __v3_hvm_ros_signal_handler  
4
5 /* 
6    This is the entry point for signal dispatch
7    from the VMM.
8         
9    VMM invokes this stub when a user signal is
10    raised and:  the relevant address space
11    is active, and we are at user-level.
12    It will be invoked  on exactly one core,  
13    although there are  no guarantees on which one.
14    
15 */
16
17
18 #define GPR_SAVE()                                               \
19         pushq %rbp              ;                                \
20         pushq %rax              ;                                \
21         pushq %rbx              ;                                \
22         pushq %rcx              ;                                \
23         pushq %rdx              ;                                \
24         pushq %rsi              ;                                \
25         pushq %rdi              ;                                \
26         pushq %r8               ;                                \
27         pushq %r9               ;                                \
28         pushq %r10              ;                                \
29         pushq %r11              ;                                \
30         pushq %r12              ;                                \
31         pushq %r13              ;                                \
32         pushq %r14              ;                                \
33         pushq %r15              ;                                \
34
35 #define GPR_LOAD()                       \
36         popq %r15               ;                                \
37         popq %r14               ;                                \
38         popq %r13               ;                                \
39         popq %r12               ;                                \
40         popq %r11               ;                                \
41         popq %r10               ;                                \
42         popq %r9                ;                                \
43         popq %r8                ;                                \
44         popq %rdi               ;                                \
45         popq %rsi               ;                                \
46         popq %rdx               ;                                \
47         popq %rcx               ;                                \
48         popq %rbx               ;                                \
49         popq %rax               ;                                \
50         popq %rbp               ;          
51
52         
53 /*
54    The VMM puts us here with what looks like a long mode 
55    interrupt dispatch, but it's from CPL 3 to CPL 3 and
56    it's not done as an interrupt injection per se, so
57    we can be interrupted, and deliverable interrupts
58    automatically prioritize over us.
59
60    The start of the stack (before the VMM pushes the fake
61    interrupt frame is  16 byte aligned
62
63         48bitsblank | return SS (16 bits)
64         Return RSP
65         Return RFLAGS
66         48bitsblank | return CS (16 bits)
67         Return RIP
68         ERROR CODE (HVM-specific non-zero number here)  <- RSP on entry
69         
70         We then need simply to do this:
71
72         save regs
73         arrange 16 byte alignment at entry of call
74         call the handler (if installed)
75         restore regs
76         iret
77         
78 */
79
80 #define DEBUG_ENTRY 0
81         
82 .global __v3_hvm_ros_signal_handler_stub
83 __v3_hvm_ros_signal_handler_stub:   /* we are 16 byte aligned on entry 16 + 6*8 for interrupt frame */
84         GPR_SAVE()                  /* push 15 words, all but rsp, now not aligned - need 1 more word  */
85         subq $8, %rsp               /* make us 16 byte aligned */
86
87 #if DEBUG_ENTRY                     /* print out something if we are debugging - Note this is danerous code */
88         pushq %rdi
89         pushq %rax
90         movabsq $printf, %rax
91         movabsq $string, %rdi
92         callq *%rax
93         popq %rax
94         popq %rdi
95 #endif
96         movq %rsp, %rbp             /* give us a stack frame for any callee that needs it */
97         movabs __v3_hvm_ros_signal_handler, %rax  /* find the user-level handler */
98         testq %rax, %rax                          /* return immediately if it doesn't exist */
99         jz skip_handler                           /* " */
100         movq 128(%rsp), %rdi        /* error code becomes argument for user-level handler */
101         callq *%rax                 /* call handelr - 16 byte aligned at call */
102         jmp done
103 skip_handler:
104 done:
105         addq $8, %rsp               /* get rid of stack alignment pad */
106         GPR_LOAD()                  /* rbp is restored here */
107         addq $8, %rsp               /* nuke the error code */
108         iretq                       /* restore rip, rsp, and rflags */
109         
110
111 string:
112     .asciz "Got to signal handler stub\12"