Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 支持蓬莱可信运行时 #30

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion rustsbi-qemu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![feature(naked_functions, asm_sym, asm_const)]
#![no_std]
#![no_main]
#![deny(warnings)]

mod clint;
mod device_tree;
Expand All @@ -11,6 +10,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!()
}