1 | ; $Id: MMRamRCA.asm 37955 2011-07-14 12:23:02Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; MMRamGCA - Guest Context Ram access Assembly Routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2007 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 |
|
---|
18 | ;*******************************************************************************
|
---|
19 | ;* Header Files *
|
---|
20 | ;*******************************************************************************
|
---|
21 | %include "VBox/asmdefs.mac"
|
---|
22 | %include "VBox/err.mac"
|
---|
23 | %include "iprt/err.mac"
|
---|
24 | %include "iprt/x86.mac"
|
---|
25 |
|
---|
26 |
|
---|
27 | BEGINCODE
|
---|
28 |
|
---|
29 |
|
---|
30 | ;;
|
---|
31 | ; Read data in guest context, CDECL calling conv.
|
---|
32 | ; VMMRCDECL(int) MMGCRamRead(void *pDst, void *pSrc, size_t cb);
|
---|
33 | ; MMRamGC page fault handler must be installed prior this call for safe operation.
|
---|
34 | ;
|
---|
35 | ; @returns eax=0 if data read, other code - invalid access, #PF was generated.
|
---|
36 | ; @param [esp + 04h] Param 1 - Pointer where to store result data (pDst).
|
---|
37 | ; @param [esp + 08h] Param 2 - Pointer of data to read (pSrc).
|
---|
38 | ; @param [esp + 0ch] Param 3 - Size of data to read, only 1/2/4/8 is valid.
|
---|
39 | ; @uses eax, ecx, edx
|
---|
40 | ;
|
---|
41 | ; @remark Data is saved to destination (Param 1) even if read error occurred!
|
---|
42 | ;
|
---|
43 | align 16
|
---|
44 | BEGINPROC MMGCRamReadNoTrapHandler
|
---|
45 | mov eax, [esp + 0ch] ; eax = size of data to read
|
---|
46 | cmp eax, byte 8 ; yes, it's slow, validate input
|
---|
47 | ja ramread_InvalidSize
|
---|
48 | mov edx, [esp + 04h] ; edx = result address
|
---|
49 | mov ecx, [esp + 08h] ; ecx = data address
|
---|
50 | jmp [ramread_table + eax*4]
|
---|
51 |
|
---|
52 | ramread_byte:
|
---|
53 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
54 | mov cl, [ecx] ; read data
|
---|
55 | mov [edx], cl ; save data
|
---|
56 | ret
|
---|
57 |
|
---|
58 | ramread_word:
|
---|
59 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
60 | mov cx, [ecx] ; read data
|
---|
61 | mov [edx], cx ; save data
|
---|
62 | ret
|
---|
63 |
|
---|
64 | ramread_dword:
|
---|
65 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
66 | mov ecx, [ecx] ; read data
|
---|
67 | mov [edx], ecx ; save data
|
---|
68 | ret
|
---|
69 |
|
---|
70 | ramread_qword:
|
---|
71 | mov eax, [ecx] ; read data
|
---|
72 | mov [edx], eax ; save data
|
---|
73 | mov eax, [ecx+4] ; read data
|
---|
74 | mov [edx+4], eax ; save data
|
---|
75 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
76 | ret
|
---|
77 |
|
---|
78 | ; Read error - we will be here after our page fault handler.
|
---|
79 | GLOBALNAME MMGCRamRead_Error
|
---|
80 | mov eax, VERR_ACCESS_DENIED
|
---|
81 | ret
|
---|
82 |
|
---|
83 | ; Invalid data size
|
---|
84 | ramread_InvalidSize:
|
---|
85 | mov eax, VERR_INVALID_PARAMETER
|
---|
86 | ret
|
---|
87 |
|
---|
88 | ; Jump table
|
---|
89 | ramread_table:
|
---|
90 | DD ramread_InvalidSize
|
---|
91 | DD ramread_byte
|
---|
92 | DD ramread_word
|
---|
93 | DD ramread_InvalidSize
|
---|
94 | DD ramread_dword
|
---|
95 | DD ramread_InvalidSize
|
---|
96 | DD ramread_InvalidSize
|
---|
97 | DD ramread_InvalidSize
|
---|
98 | DD ramread_qword
|
---|
99 | ENDPROC MMGCRamReadNoTrapHandler
|
---|
100 |
|
---|
101 |
|
---|
102 | ;;
|
---|
103 | ; Write data in guest context, CDECL calling conv.
|
---|
104 | ; VMMRCDECL(int) MMGCRamWrite(void *pDst, void *pSrc, size_t cb);
|
---|
105 | ;
|
---|
106 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
107 | ; @param [esp + 04h] Param 1 - Pointer where to write data (pDst).
|
---|
108 | ; @param [esp + 08h] Param 2 - Pointer of data to write (pSrc).
|
---|
109 | ; @param [esp + 0ch] Param 3 - Size of data to write, only 1/2/4 is valid.
|
---|
110 | ; @uses eax, ecx, edx
|
---|
111 | ;
|
---|
112 | align 16
|
---|
113 | BEGINPROC MMGCRamWriteNoTrapHandler
|
---|
114 | mov eax, [esp + 0ch] ; eax = size of data to write
|
---|
115 | cmp eax, byte 4 ; yes, it's slow, validate input
|
---|
116 | ja ramwrite_InvalidSize
|
---|
117 | mov edx, [esp + 04h] ; edx = write address
|
---|
118 | mov ecx, [esp + 08h] ; ecx = data address
|
---|
119 | jmp [ramwrite_table + eax*4]
|
---|
120 |
|
---|
121 | ramwrite_byte:
|
---|
122 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
123 | mov cl, [ecx] ; read data
|
---|
124 | mov [edx], cl ; write data
|
---|
125 | ret
|
---|
126 |
|
---|
127 | ramwrite_word:
|
---|
128 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
129 | mov cx, [ecx] ; read data
|
---|
130 | mov [edx], cx ; write data
|
---|
131 | ret
|
---|
132 |
|
---|
133 | ramwrite_dword:
|
---|
134 | xor eax, eax ; rc = VINF_SUCCESS by default
|
---|
135 | mov ecx, [ecx] ; read data
|
---|
136 | mov [edx], ecx ; write data
|
---|
137 | ret
|
---|
138 |
|
---|
139 | ; Write error - we will be here after our page fault handler.
|
---|
140 | GLOBALNAME MMGCRamWrite_Error
|
---|
141 | mov eax, VERR_ACCESS_DENIED
|
---|
142 | ret
|
---|
143 |
|
---|
144 | ; Invalid data size
|
---|
145 | ramwrite_InvalidSize:
|
---|
146 | mov eax, VERR_INVALID_PARAMETER
|
---|
147 | ret
|
---|
148 |
|
---|
149 | ; Jump table
|
---|
150 | ramwrite_table:
|
---|
151 | DD ramwrite_InvalidSize
|
---|
152 | DD ramwrite_byte
|
---|
153 | DD ramwrite_word
|
---|
154 | DD ramwrite_InvalidSize
|
---|
155 | DD ramwrite_dword
|
---|
156 | ENDPROC MMGCRamWriteNoTrapHandler
|
---|
157 |
|
---|