|
@@ -0,0 +1,45 @@
|
|
1
|
+/*
|
|
2
|
+ * librm: a library for interfacing to real-mode code
|
|
3
|
+ *
|
|
4
|
+ * Michael Brown <mbrown@fensystems.co.uk>
|
|
5
|
+ *
|
|
6
|
+ */
|
|
7
|
+
|
|
8
|
+#include <stdint.h>
|
|
9
|
+#include <librm.h>
|
|
10
|
+
|
|
11
|
+/*
|
|
12
|
+ * This file provides functions for managing librm.
|
|
13
|
+ *
|
|
14
|
+ */
|
|
15
|
+
|
|
16
|
+/**
|
|
17
|
+ * Allocate space on the real-mode stack and copy data there from a
|
|
18
|
+ * user buffer
|
|
19
|
+ *
|
|
20
|
+ * @v data User buffer
|
|
21
|
+ * @v size Size of stack data
|
|
22
|
+ * @ret sp New value of real-mode stack pointer
|
|
23
|
+ */
|
|
24
|
+uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
|
|
25
|
+ userptr_t rm_stack;
|
|
26
|
+ rm_sp -= size;
|
|
27
|
+ rm_stack = real_to_user ( rm_ss, rm_sp );
|
|
28
|
+ memcpy_user ( rm_stack, 0, data, 0, size );
|
|
29
|
+ return rm_sp;
|
|
30
|
+};
|
|
31
|
+
|
|
32
|
+/**
|
|
33
|
+ * Deallocate space on the real-mode stack, optionally copying back
|
|
34
|
+ * data to a user buffer.
|
|
35
|
+ *
|
|
36
|
+ * @v data User buffer
|
|
37
|
+ * @v size Size of stack data
|
|
38
|
+ */
|
|
39
|
+void remove_user_from_rm_stack ( userptr_t data, size_t size ) {
|
|
40
|
+ if ( data ) {
|
|
41
|
+ userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
|
|
42
|
+ memcpy_user ( rm_stack, 0, data, 0, size );
|
|
43
|
+ }
|
|
44
|
+ rm_sp += size;
|
|
45
|
+};
|