tartan_arch/
lib.rs

1//! Architecture-specific primitives for Tartan OS
2
3#![no_std]
4#![feature(doc_cfg)]
5#![warn(missing_docs)]
6#![warn(clippy::pedantic)]
7#![allow(clippy::must_use_candidate)]
8#![allow(clippy::upper_case_acronyms)]
9
10use core::arch::asm;
11
12#[cfg(any(target_arch = "aarch64", doc))]
13#[doc(cfg(target_arch = "aarch64"))]
14#[macro_use]
15pub mod aarch64;
16
17#[cfg(any(target_arch = "arm", doc))]
18#[doc(cfg(target_arch = "arm"))]
19#[macro_use]
20pub mod arm;
21
22#[cfg(any(target_arch = "x86_64", doc))]
23#[doc(cfg(target_arch = "x86_64"))]
24pub mod x86_64;
25
26#[cfg(any(target_arch = "x86", doc))]
27#[doc(cfg(target_arch = "x86"))]
28pub mod x86;
29
30#[cfg(any(target_arch = "x86", target_arch = "x86_64", doc))]
31#[doc(cfg(any(target_arch = "x86", target_arch = "x86_64")))]
32#[macro_use]
33pub mod x86_common;
34
35
36/// Unconditionally transfer control to the instruction at the given address
37///
38/// # Safety
39/// Make sure you know where you're going. You're not coming back.
40#[cfg(any(target_arch = "x86", target_arch = "x86_64", doc))]
41#[allow(clippy::missing_panics_doc)]
42pub unsafe fn jump(address: usize) -> ! {
43    asm!("jmp {}", in(reg) address);
44    unreachable!();
45}
46
47/// Unconditionally transfer control to the instruction at the given address
48///
49/// # Safety
50/// Make sure you know where you're going. You're not coming back.
51#[cfg(target_arch = "arm")]
52#[allow(clippy::missing_panics_doc)]
53pub unsafe fn jump(address: usize) -> ! {
54    asm!("bx {}", in(reg) address);
55    unreachable!();
56}
57
58/// Unconditionally transfer control to the instruction at the given address
59///
60/// # Safety
61/// Make sure you know where you're going. You're not coming back.
62#[cfg(target_arch = "aarch64")]
63#[allow(clippy::missing_panics_doc)]
64pub unsafe fn jump(address: usize) -> ! {
65    asm!("br {}", in(reg) address);
66    unreachable!();
67}