• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * librm: a library for interfacing to real-mode code
3  *
4  * Michael Brown <mbrown@fensystems.co.uk>
5  *
6  */
7 
8 FILE_LICENCE ( GPL2_OR_LATER );
9 
10 #include <stdint.h>
11 #include <realmode.h>
12 
13 /*
14  * This file provides functions for managing librm.
15  *
16  */
17 
18 /**
19  * Allocate space on the real-mode stack and copy data there from a
20  * user buffer
21  *
22  * @v data			User buffer
23  * @v size			Size of stack data
24  * @ret sp			New value of real-mode stack pointer
25  */
copy_user_to_rm_stack(userptr_t data,size_t size)26 uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
27 	userptr_t rm_stack;
28 	rm_sp -= size;
29 	rm_stack = real_to_user ( rm_ss, rm_sp );
30 	memcpy_user ( rm_stack, 0, data, 0, size );
31 	return rm_sp;
32 };
33 
34 /**
35  * Deallocate space on the real-mode stack, optionally copying back
36  * data to a user buffer.
37  *
38  * @v data			User buffer
39  * @v size			Size of stack data
40  */
remove_user_from_rm_stack(userptr_t data,size_t size)41 void remove_user_from_rm_stack ( userptr_t data, size_t size ) {
42 	if ( data ) {
43 		userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
44 		memcpy_user ( rm_stack, 0, data, 0, size );
45 	}
46 	rm_sp += size;
47 };
48 
49 PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
50 PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
51 PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
52 PROVIDE_UACCESS_INLINE ( librm, user_to_virt );
53 PROVIDE_UACCESS_INLINE ( librm, userptr_add );
54 PROVIDE_UACCESS_INLINE ( librm, memcpy_user );
55 PROVIDE_UACCESS_INLINE ( librm, memmove_user );
56 PROVIDE_UACCESS_INLINE ( librm, memset_user );
57 PROVIDE_UACCESS_INLINE ( librm, strlen_user );
58 PROVIDE_UACCESS_INLINE ( librm, memchr_user );
59