VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Syscall64Generic.asm@ 106560

Last change on this file since 106560 was 105094, checked in by vboxsync, 7 months ago

VMM/IEM,ValKit/bs3-cpu-weird-1: syscall TF & debug event fixes; extended bs3-cpu-weird-1 with syscall (only tested on intel). bugref:10715

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1; $Id: bs3-c64-Syscall64Generic.asm 105094 2024-07-02 09:33:52Z vboxsync $
2;; @file
3; BS3Kit - Syscall, 64-bit assembly handlers.
4;
5
6;
7; Copyright (C) 2007-2024 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37;*********************************************************************************************************************************
38;* Header Files *
39;*********************************************************************************************************************************
40%include "bs3kit-template-header.mac"
41
42%ifndef TMPL_64BIT
43 %error "64-bit only template"
44%endif
45
46
47;*********************************************************************************************************************************
48;* External Symbols *
49;*********************************************************************************************************************************
50BS3_EXTERN_DATA16 g_bBs3CurrentMode
51TMPL_BEGIN_TEXT
52BS3_EXTERN_CMN Bs3TrapDefaultHandler
53BS3_EXTERN_CMN Bs3RegCtxRestore
54
55
56;*********************************************************************************************************************************
57;* Global Variables *
58;*********************************************************************************************************************************
59BS3_BEGIN_DATA16
60;; Easy to access flat address of Bs3Syscall64Generic.
61BS3_GLOBAL_DATA g_pfnBs3Syscall64GenericFlat, 4
62 dd Bs3Syscall64Generic wrt FLAT
63;; Easy to access flat address of Bs3Syscall64Generic.
64BS3_GLOBAL_DATA g_pfnBs3Syscall64GenericCompatibilityFlat, 4
65 dd Bs3Syscall64GenericCompatibility wrt FLAT
66
67
68TMPL_BEGIN_TEXT
69
70;;
71; Generic function to load into LSTAR
72;
73; This will just skip 20h on the stack and set up a flat call frame there.
74;
75BS3_PROC_BEGIN Bs3Syscall64Generic
76 lea rsp, [rsp - 20h]
77 push rcx ; fake return address
78 push rbp ; 0
79 mov rbp, rsp
80 push 0xffff ; rbp-08h: bXpct+cbIretFrame values
81 jmp Bs3Syscall64GenericCommon
82BS3_PROC_END Bs3Syscall64Generic
83
84
85;;
86; Generic function to load into CSTAR.
87;
88; Companion to Bs3Syscall64Generic.
89;
90BS3_PROC_BEGIN Bs3Syscall64GenericCompatibility
91 lea rsp, [rsp - 20h]
92 push rcx ; fake return address
93 push rbp ; 0
94 mov rbp, rsp
95 push 0xfffe ; rbp-08h: bXpct+cbIretFrame values
96 jmp Bs3Syscall64GenericCommon
97BS3_PROC_END Bs3Syscall64GenericCompatibility
98
99
100;;
101; Common context saving code and dispatching.
102;
103; @param rbp Pointer to fake RBP frame.
104;
105BS3_PROC_BEGIN Bs3Syscall64GenericCommon
106 pushfq ; rbp-10h
107 cld
108 push rdi ; rbp-10h
109 mov di, ds
110 push rdi ; rbp-20h
111 mov di, ss
112 mov ds, di ; ds := ss
113
114 ;
115 ; Align the stack and reserve space for the register and trap frame.
116 ;
117 and rsp, ~0xf
118 mov edi, (BS3TRAPFRAME_size + 15) / 16
119.more_zeroed_space:
120 push qword 0
121 push qword 0
122 dec edi
123 jnz .more_zeroed_space
124 mov rdi, rsp ; rdi points to trapframe structure.
125
126 ;
127 ; Save rax so we can use it.
128 ;
129 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], rax
130
131 ;
132 ; Mark the trap frame as a special one.
133 ;
134 mov ax, [rbp - 08h]
135 mov word [rdi + BS3TRAPFRAME.bXcpt], ax ; Also sets cbIretFrame
136
137 mov word [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], 0 ; We cannot tell.
138 mov word [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], 0 ; We cannot tell.
139 mov byte [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], 3 ; We cannot tell.
140
141 mov [rdi + BS3TRAPFRAME.uHandlerCs], cs
142 mov [rdi + BS3TRAPFRAME.uHandlerSs], ss
143
144 ;
145 ; Copy stuff from the stack over.
146 ;
147 mov rax, [rbp]
148 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], rax
149
150 mov rax, [rbp - 10h]
151 mov [rdi + BS3TRAPFRAME.fHandlerRfl], rax
152 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], r11 ; with RF cleared
153
154 mov rax, [rbp - 18h]
155 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], rax
156
157 lea rax, [rbp + 20h + 8 + 8]
158 mov [rdi + BS3TRAPFRAME.uHandlerRsp], rax
159 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], rax
160
161 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], rcx
162
163 mov ax, [rbp - 20h]
164 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], ax
165
166 mov [rdi + BS3TRAPFRAME.uHandlerSs], ss
167
168 ;
169 ; Save the remaining GPRs and segment registers.
170 ;
171 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], rcx
172 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], rdx
173 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], rbx
174 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], rsi
175 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r8 ], r8
176 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r9 ], r9
177 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r10], r10
178 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r11], r11
179 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r12], r12
180 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r13], r13
181 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r14], r14
182 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r15], r15
183 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.es], es
184 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], fs
185 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], gs
186
187 ;
188 ; Load the SS selector into ES.
189 ;
190 mov ax, ss
191 mov es, ax
192
193 ;
194 ; Copy and update the mode.
195 ;
196 mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
197 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], al
198 mov byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_LM64
199
200 ;
201 ; Control registers.
202 ;
203 str ax
204 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.tr], ax
205 sldt ax
206 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr], ax
207
208 mov rax, cr0
209 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], rax
210 mov rax, cr2
211 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], rax
212 mov rax, cr3
213 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], rax
214 mov rax, cr4
215 mov [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], rax
216
217 ;
218 ; There are no _g_apfnBs3TrapHandlers_c64 entries for syscalls, but call
219 ; Bs3TrapDefaultHandler to get the g_pBs3TrapSetJmpFrame handling & panic.
220 ;
221 sub rsp, 20h
222 mov [rsp], rdi
223 mov rcx, rdi
224 call Bs3TrapDefaultHandler
225
226 ;
227 ; Resume execution using trap frame.
228 ;
229 xor edx, edx ; fFlags
230 mov [rsp + 8], rdx
231 lea rcx, [rdi + BS3TRAPFRAME.Ctx] ; pCtx
232 mov [rsp], rcx
233 call Bs3RegCtxRestore
234.panic:
235 hlt
236 jmp .panic
237BS3_PROC_END Bs3Syscall64GenericCommon
238
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette