Add codegen for new rust yunq parser.
This commit is contained in:
parent
8f35d38e93
commit
2cbf871d09
8 changed files with 261 additions and 96 deletions
|
|
@ -1,7 +1,5 @@
|
|||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::string::String;
|
||||
use alloc::string::ToString;
|
||||
use mammoth::syscall::z_cap_t;
|
||||
|
|
@ -9,22 +7,54 @@ use mammoth::syscall::ZError;
|
|||
use yunq::ByteBuffer;
|
||||
use yunq::YunqMessage;
|
||||
use yunq_derive::YunqMessage;
|
||||
|
||||
#[derive(YunqMessage)]
|
||||
pub struct RegisterEndpointRequest {
|
||||
pub endpoint_name: String,
|
||||
pub endpoint_capability: z_cap_t,
|
||||
}
|
||||
#[derive(YunqMessage)]
|
||||
pub struct GetEndpointRequest {
|
||||
pub endpoint_name: String,
|
||||
}
|
||||
|
||||
#[derive(YunqMessage)]
|
||||
pub struct Endpoint {
|
||||
pub endpoint: z_cap_t,
|
||||
}
|
||||
|
||||
#[derive(YunqMessage)]
|
||||
pub struct AhciInfo {
|
||||
pub ahci_region: z_cap_t,
|
||||
pub region_length: u64,
|
||||
}
|
||||
#[derive(YunqMessage)]
|
||||
pub struct XhciInfo {
|
||||
pub xhci_region: z_cap_t,
|
||||
pub region_length: u64,
|
||||
}
|
||||
#[derive(YunqMessage)]
|
||||
pub struct FramebufferInfo {
|
||||
pub address_phys: u64,
|
||||
pub width: u64,
|
||||
pub height: u64,
|
||||
pub pitch: u64,
|
||||
pub bpp: u64,
|
||||
pub memory_model: u64,
|
||||
pub red_mask_size: u64,
|
||||
pub red_mask_shift: u64,
|
||||
pub green_mask_size: u64,
|
||||
pub green_mask_shift: u64,
|
||||
pub blue_mask_size: u64,
|
||||
pub blue_mask_shift: u64,
|
||||
}
|
||||
#[derive(YunqMessage)]
|
||||
pub struct DenaliInfo {
|
||||
pub denali_endpoint: z_cap_t,
|
||||
pub device_id: u64,
|
||||
pub lba_offset: u64,
|
||||
}
|
||||
pub struct YellowstoneClient {
|
||||
endpoint_cap: z_cap_t,
|
||||
byte_buffer: ByteBuffer<0x1000>,
|
||||
}
|
||||
|
||||
impl YellowstoneClient {
|
||||
pub fn new(endpoint_cap: z_cap_t) -> Self {
|
||||
Self {
|
||||
|
|
@ -32,7 +62,44 @@ impl YellowstoneClient {
|
|||
byte_buffer: ByteBuffer::new(),
|
||||
}
|
||||
}
|
||||
pub fn get_endpoint(&mut self, req: &GetEndpointRequest) -> Result<Endpoint, ZError> {
|
||||
pub fn register_endpoint(
|
||||
&mut self,
|
||||
req: &RegisterEndpointRequest,
|
||||
) -> Result<yunq::message::Empty, ZError> {
|
||||
yunq::client::call_endpoint(req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
}
|
||||
pub fn get_endpoint(
|
||||
&mut self,
|
||||
req: &GetEndpointRequest,
|
||||
) -> Result<Endpoint, ZError> {
|
||||
yunq::client::call_endpoint(req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
}
|
||||
pub fn get_ahci_info(&mut self) -> Result<AhciInfo, ZError> {
|
||||
yunq::client::call_endpoint(
|
||||
&yunq::message::Empty {},
|
||||
&mut self.byte_buffer,
|
||||
self.endpoint_cap,
|
||||
)
|
||||
}
|
||||
pub fn get_xhci_info(&mut self) -> Result<XhciInfo, ZError> {
|
||||
yunq::client::call_endpoint(
|
||||
&yunq::message::Empty {},
|
||||
&mut self.byte_buffer,
|
||||
self.endpoint_cap,
|
||||
)
|
||||
}
|
||||
pub fn get_framebuffer_info(&mut self) -> Result<FramebufferInfo, ZError> {
|
||||
yunq::client::call_endpoint(
|
||||
&yunq::message::Empty {},
|
||||
&mut self.byte_buffer,
|
||||
self.endpoint_cap,
|
||||
)
|
||||
}
|
||||
pub fn get_denali(&mut self) -> Result<DenaliInfo, ZError> {
|
||||
yunq::client::call_endpoint(
|
||||
&yunq::message::Empty {},
|
||||
&mut self.byte_buffer,
|
||||
self.endpoint_cap,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ fn serialize_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenS
|
|||
buf.write_at(yunq::message::field_offset(offset, #ind), cap_ind as u64)?;
|
||||
}
|
||||
}
|
||||
} else if path.is_ident("u64") {
|
||||
quote! {
|
||||
{
|
||||
buf.write_at(yunq::message::field_offset(offset, #ind), self.#name as u64)?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
panic!(
|
||||
"Serialization not implemented for: {}",
|
||||
|
|
@ -51,6 +57,10 @@ fn parse_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenStrea
|
|||
caps[cap_ind as usize]
|
||||
};
|
||||
}
|
||||
} else if path.is_ident("u64") {
|
||||
quote! {
|
||||
let #name = buf.at::<u64>(yunq::message::field_offset(offset, #ind))?;
|
||||
}
|
||||
} else {
|
||||
panic!("Parsing not implemented for: {}", path.into_token_stream());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,3 +26,27 @@ pub trait YunqMessage {
|
|||
caps: &mut Vec<z_cap_t>,
|
||||
) -> Result<usize, ZError>;
|
||||
}
|
||||
|
||||
pub struct Empty {}
|
||||
|
||||
impl YunqMessage for Empty {
|
||||
fn parse<const N: usize>(
|
||||
buf: &ByteBuffer<N>,
|
||||
offset: usize,
|
||||
caps: &Vec<z_cap_t>,
|
||||
) -> Result<Self, ZError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn serialize<const N: usize>(
|
||||
&self,
|
||||
buf: &mut ByteBuffer<N>,
|
||||
offset: usize,
|
||||
caps: &mut Vec<z_cap_t>,
|
||||
) -> Result<usize, ZError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue