Browse Source

[librm] Add rm stack copying functions

tags/v0.9.4
Daniel Verkamp 16 years ago
parent
commit
aa28544373
2 changed files with 48 additions and 0 deletions
  1. 3
    0
      src/arch/i386/include/librm.h
  2. 45
    0
      src/arch/i386/transitions/librm_mgmt.c

+ 3
- 0
src/arch/i386/include/librm.h View File

@@ -279,6 +279,9 @@ user_to_phys ( userptr_t buffer, off_t offset ) {
279 279
 	return virt_to_phys ( ( void * ) buffer + offset );
280 280
 }
281 281
 
282
+extern uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size );
283
+extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
284
+
282 285
 /* TEXT16_CODE: declare a fragment of code that resides in .text16 */
283 286
 #define TEXT16_CODE( asm_code_str )			\
284 287
 	".section \".text16\", \"ax\", @progbits\n\t"	\

+ 45
- 0
src/arch/i386/transitions/librm_mgmt.c View File

@@ -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
+};

Loading…
Cancel
Save