Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[librm] Add rm stack copying functions
- Loading branch information
1 parent
2539f5f
commit aa28544
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* librm: a library for interfacing to real-mode code | ||
* | ||
* Michael Brown <mbrown@fensystems.co.uk> | ||
* | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <librm.h> | ||
|
||
/* | ||
* This file provides functions for managing librm. | ||
* | ||
*/ | ||
|
||
/** | ||
* Allocate space on the real-mode stack and copy data there from a | ||
* user buffer | ||
* | ||
* @v data User buffer | ||
* @v size Size of stack data | ||
* @ret sp New value of real-mode stack pointer | ||
*/ | ||
uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) { | ||
userptr_t rm_stack; | ||
rm_sp -= size; | ||
rm_stack = real_to_user ( rm_ss, rm_sp ); | ||
memcpy_user ( rm_stack, 0, data, 0, size ); | ||
return rm_sp; | ||
}; | ||
|
||
/** | ||
* Deallocate space on the real-mode stack, optionally copying back | ||
* data to a user buffer. | ||
* | ||
* @v data User buffer | ||
* @v size Size of stack data | ||
*/ | ||
void remove_user_from_rm_stack ( userptr_t data, size_t size ) { | ||
if ( data ) { | ||
userptr_t rm_stack = real_to_user ( rm_ss, rm_sp ); | ||
memcpy_user ( rm_stack, 0, data, 0, size ); | ||
} | ||
rm_sp += size; | ||
}; |