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