expose libm functions to kernel

This commit is contained in:
Sebastien Bourdeauducq 2020-07-21 13:50:33 +08:00
parent 59cf2764ce
commit e0560a2db9
4 changed files with 38 additions and 1 deletions

View File

@ -14,7 +14,7 @@ let
version = "0.1.0"; version = "0.1.0";
src = ./src; src = ./src;
cargoSha256 = "11kd1vmm4i4plqwxbsgrxia1ihs2szw1r7af8j645zib71f0qx87"; cargoSha256 = "04asmk07xc7asbpl15d9pgm31dd77lj9hkfgf76kcq6ds7l04k12";
nativeBuildInputs = [ nativeBuildInputs = [
pkgs.gnumake pkgs.gnumake

7
src/Cargo.lock generated
View File

@ -242,6 +242,12 @@ dependencies = [
"libregister", "libregister",
] ]
[[package]]
name = "libm"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]] [[package]]
name = "libregister" name = "libregister"
version = "0.0.0" version = "0.0.0"
@ -412,6 +418,7 @@ dependencies = [
"libboard_zynq", "libboard_zynq",
"libc", "libc",
"libcortex_a9", "libcortex_a9",
"libm",
"libregister", "libregister",
"libsupport_zynq", "libsupport_zynq",
"log", "log",

View File

@ -23,6 +23,7 @@ futures = { version = "0.3", default-features = false, features = ["async-await"
async-recursion = "0.3" async-recursion = "0.3"
fatfs = { version = "0.3", features = ["core_io"], default-features = false } fatfs = { version = "0.3", features = ["core_io"], default-features = false }
log_buffer = { version = "1.2" } log_buffer = { version = "1.2" }
libm = { version = "0.2", features = ["unstable"] }
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
libsupport_zynq = { default-features = false, git = "https://git.m-labs.hk/M-Labs/zc706.git" } libsupport_zynq = { default-features = false, git = "https://git.m-labs.hk/M-Labs/zc706.git" }

View File

@ -1,3 +1,5 @@
use libm;
use crate::eh_artiq; use crate::eh_artiq;
use crate::rtio; use crate::rtio;
use super::rpc::{rpc_send, rpc_send_async, rpc_recv}; use super::rpc::{rpc_send, rpc_send_async, rpc_recv};
@ -16,6 +18,15 @@ macro_rules! api {
} }
} }
macro_rules! api_libm_f64f64 {
($i:ident) => ({
extern fn $i(x: f64) -> f64 {
libm::$i(x)
}
api!($i = $i)
})
}
pub fn resolve(required: &[u8]) -> Option<u32> { pub fn resolve(required: &[u8]) -> Option<u32> {
let api = &[ let api = &[
// timing // timing
@ -117,14 +128,32 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
api!(__aeabi_memclr8), api!(__aeabi_memclr8),
api!(__aeabi_memclr4), api!(__aeabi_memclr4),
api!(__aeabi_memclr), api!(__aeabi_memclr),
// libc // libc
api!(memcmp, extern { fn memcmp(a: *const u8, b: *mut u8, size: usize); }), api!(memcmp, extern { fn memcmp(a: *const u8, b: *mut u8, size: usize); }),
// exceptions // exceptions
api!(_Unwind_Resume = unwind::_Unwind_Resume), api!(_Unwind_Resume = unwind::_Unwind_Resume),
api!(__artiq_personality = eh_artiq::artiq_personality), api!(__artiq_personality = eh_artiq::artiq_personality),
api!(__artiq_raise = eh_artiq::raise), api!(__artiq_raise = eh_artiq::raise),
api!(__artiq_reraise = eh_artiq::reraise), api!(__artiq_reraise = eh_artiq::reraise),
// libm
api_libm_f64f64!(log),
api_libm_f64f64!(log10),
api_libm_f64f64!(exp),
{
extern fn pow(x: f64, y: f64) -> f64 {
libm::pow(x, y)
}
api!(pow = pow)
},
api_libm_f64f64!(sin),
api_libm_f64f64!(cos),
api_libm_f64f64!(tan),
api_libm_f64f64!(asin),
api_libm_f64f64!(acos),
api_libm_f64f64!(atan),
]; ];
api.iter() api.iter()
.find(|&&(exported, _)| exported.as_bytes() == required) .find(|&&(exported, _)| exported.as_bytes() == required)