-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hypercall for a serial output of a whole buffer
- Loading branch information
1 parent
a3ab47a
commit a2b664c
Showing
10 changed files
with
226 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
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
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,10 @@ | ||
mod common; | ||
|
||
use common::{build_hermit_bin, run_simple_vm}; | ||
|
||
#[test] | ||
fn serial_buffer_test() { | ||
// TODO: Check the output once https://github.com/hermit-os/uhyve/issues/528 is resolved | ||
let bin_path = build_hermit_bin("serial"); | ||
run_simple_vm(bin_path); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
#[cfg(target_os = "hermit")] | ||
use hermit as _; | ||
use uhyve_interface::{parameters::SerialWriteBufferParams, GuestPhysAddr, HypercallAddress}; | ||
#[cfg(target_arch = "x86_64")] | ||
use x86_64::{ | ||
instructions::port::Port, | ||
structures::paging::{PageTable, RecursivePageTable}, | ||
VirtAddr, | ||
}; | ||
|
||
unsafe fn get_page_table() -> RecursivePageTable<'static> { | ||
let level_4_table_addr: u64 = 0xFFFF_FFFF_FFFF_F000; | ||
unsafe { | ||
let level_4_table = &mut *(level_4_table_addr as *mut PageTable); | ||
RecursivePageTable::new(level_4_table).unwrap() | ||
} | ||
} | ||
|
||
/// Translate a virtual memory address to a physical one. | ||
pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<GuestPhysAddr> { | ||
use x86_64::structures::paging::mapper::Translate; | ||
|
||
let page_table = unsafe { get_page_table() }; | ||
page_table | ||
.translate_addr(virtual_address) | ||
.map(|addr| GuestPhysAddr::new(addr.as_u64())) | ||
} | ||
|
||
fn main() { | ||
println!("Test"); | ||
|
||
let mut serial_byte_port = Port::new(HypercallAddress::Uart as u16); | ||
for c in "ABCD\n".bytes() { | ||
unsafe { serial_byte_port.write(c) }; | ||
} | ||
|
||
let mut serial_buf_port = Port::new(HypercallAddress::SerialBufferWrite as u16); | ||
let testtext = "1234ASDF!@#$\n"; | ||
let serial_write_params = SerialWriteBufferParams { | ||
buf: virtual_to_physical(VirtAddr::new( | ||
core::ptr::addr_of!(*testtext) as *const u8 as u64 | ||
)) | ||
.unwrap(), | ||
len: testtext.bytes().len(), | ||
}; | ||
let params_addr = virtual_to_physical(VirtAddr::new( | ||
core::ptr::addr_of!(serial_write_params) as u64 | ||
)) | ||
.unwrap(); | ||
|
||
unsafe { serial_buf_port.write(params_addr.as_u64() as u32) }; | ||
} |
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