Skip to content

Commit

Permalink
feat: support penglai enclave [1/n]
Browse files Browse the repository at this point in the history
  • Loading branch information
luojia65 committed Jul 30, 2022
1 parent 9c0d7f7 commit 45f54b7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 13 deletions.
26 changes: 13 additions & 13 deletions rustsbi-qemu/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{clint, hart_id, qemu_hsm::QemuHsm, Supervisor};
use crate::{clint, hart_id, penglai, qemu_hsm::QemuHsm, Supervisor};
use core::arch::asm;
use riscv::register::*;

Expand Down Expand Up @@ -111,18 +111,18 @@ impl Context {
use rustsbi::spec::{binary::*, hsm::*, srst::*};
let extension = self.a(7);
let function = self.a(6);
let ans = rustsbi::ecall(
extension,
function,
[
self.a(0),
self.a(1),
self.a(2),
self.a(3),
self.a(4),
self.a(5),
],
);
let param = [
self.a(0),
self.a(1),
self.a(2),
self.a(3),
self.a(4),
self.a(5),
];
let ans = match extension {
penglai::EID_PENGLAI_HOST => penglai::ecall(extension, function, param),
_ => rustsbi::ecall(extension, function, param),
};
// 判断导致退出执行流程的调用
if ans.error == RET_SUCCESS {
match extension {
Expand Down
3 changes: 3 additions & 0 deletions rustsbi-qemu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ mod ns16550a;
mod qemu_hsm;
mod qemu_test;

// penglai enclave. todo: move to separate crate?
mod penglai;

#[macro_use] // for print
extern crate rustsbi;

Expand Down
82 changes: 82 additions & 0 deletions rustsbi-qemu/src/penglai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* todo: move to separate crate like sbi_spec? */
pub use host::EID_PENGLAI_HOST;
use rustsbi::spec::binary::SbiRet;

mod host {
pub const EID_PENGLAI_HOST: usize /*u32*/ = 0x100100;

pub const CREATE_ENCLAVE: usize = 99;
pub const ATTEST_ENCLAVE: usize = 98;
pub const RUN_ENCLAVE: usize = 97;
pub const STOP_ENCLAVE: usize = 96;
pub const RESUME_ENCLAVE: usize = 95;
pub const DESTROY_ENCALVE: usize = 94;

#[repr(C)]
pub struct EnclaveCreate {
pub enclave_id_ptr: usize, /* todo: what's this? */
pub enclave_name: [u8; 16],
pub enclave_type: EnclaveType,
pub enclave_physical_address: usize,
pub enclave_length: usize,
pub entry_point: usize,
pub free_memory: usize, // what's this?
pub kbuffer_physical_address: usize,
pub kbuffer_length: usize,
pub shared_mem_physical_address: usize,
pub shared_mem_length: usize,
pub ecall_argument: [usize; 4],
pub return_value: usize,
}

#[repr(C)]
pub struct EnclaveRun {
pub memory_argument_address: usize,
pub memory_argument_size: usize,
// todo: extended arguments
}

#[repr(usize)]
pub enum EnclaveType {
Normal = 0,
Server = 1,
}

#[repr(C)]
pub struct ShangMiReport {
pub hash: [u8; 32],
pub signature: [u8; 64],
pub public_key: [u8; 64],
}

#[repr(C)]
pub struct EnclaveReport {
pub hash: [u8; 32],
pub signature: [u8; 64],
pub nonce: usize,
}

#[repr(C)]
pub struct Report {
pub shangmi_report: ShangMiReport,
pub enclave_report: EnclaveReport,
pub device_public_key: [u8; 64],
}
}

use host::*;

// todo: instance based? strctu Contect { penglai: Penglai, ... }

#[inline]
pub fn ecall(extension: usize, function: usize, param: [usize; 6]) -> SbiRet {
match (extension, function) {
(EID_PENGLAI_HOST, CREATE_ENCLAVE) => create_enclave(param[0]),
_ => SbiRet::not_supported(),
}
}

#[inline]
fn create_enclave(param: usize) -> SbiRet {
todo!()
}

0 comments on commit 45f54b7

Please sign in to comment.