Skip to content

Commit fffa3ae

Browse files
committed
Crudely throw everything together
1 parent aaf2659 commit fffa3ae

29 files changed

+84
-122
lines changed

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2015 Gerd Zellweger
4+
Copyright (c) 2015 The libcpu Developers
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod performance_counter {
2323

2424
use self::serde_json::Value;
2525

26-
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/perfcnt/intel/description.rs"));
26+
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/bits64/perfcnt/intel/description.rs"));
2727

2828
/// HACK: We need to convert parsed strings to static because we're reusing
2929
/// the struct definition which declare strings as static in the generated code.

tobba/src/x86.rs renamed to src/bits32/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
//! Data structures and functions used by Protected Mode but not IA-32e.
2+
13
#![allow(non_upper_case_globals)]
24

3-
pub use self::x86_shared::*;
5+
pub use shared::*;
46

57
use core::mem::size_of;
68

7-
mod x86_shared;
8-
99
bitflags! {
1010
pub flags GdtAccess: u8 {
1111
const Accessed = 1 << 0,
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/irq.rs renamed to src/bits64/irq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Interrupt description and set-up code.
22
33
use core::fmt;
4-
use paging::VAddr;
4+
use super::paging::VAddr;
55

66
/// x86 Exception description (see also Intel Vol. 3a Chapter 6).
77
#[derive(Debug)]

src/bits64/mod.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! Data structures and functions used by IA-32e but not Protected Mode.
2+
3+
macro_rules! bit {
4+
( $x:expr ) => {
5+
1 << $x
6+
};
7+
}
8+
9+
macro_rules! check_flag {
10+
($doc:meta, $fun:ident, $flag:ident) => (
11+
#[$doc]
12+
pub fn $fun(&self) -> bool {
13+
self.contains($flag)
14+
}
15+
)
16+
}
17+
18+
macro_rules! is_bit_set {
19+
($field:expr, $bit:expr) => (
20+
$field & (1 << $bit) > 0
21+
)
22+
}
23+
24+
macro_rules! check_bit_fn {
25+
($doc:meta, $fun:ident, $field:ident, $bit:expr) => (
26+
#[$doc]
27+
pub fn $fun(&self) -> bool {
28+
is_bit_set!(self.$field, $bit)
29+
}
30+
)
31+
}
32+
33+
pub mod io;
34+
pub mod controlregs;
35+
pub mod msr;
36+
pub mod time;
37+
pub mod irq;
38+
pub mod rflags;
39+
pub mod paging;
40+
pub mod segmentation;
41+
pub mod task;
42+
pub mod dtables;
43+
pub mod syscall;
44+
pub mod sgx;
45+
#[cfg(feature = "performance-counter")]
46+
pub mod perfcnt;
47+
pub mod cpuid {
48+
pub use raw_cpuid::*;
49+
}
50+
pub mod tlb;
51+
52+
pub mod tobba;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/sgx.rs renamed to src/bits64/sgx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
/// * Function needs to be executed in ring 0.
77
macro_rules! encls {
88
($rax:expr, $rbx:expr)
9-
=> ( $crate::sgx::encls2($rax as u64, $rbx as u64) );
9+
=> ( $crate::bits64::sgx::encls2($rax as u64, $rbx as u64) );
1010

1111
($rax:expr, $rbx:expr, $rcx:expr)
12-
=> ( $crate::sgx::encls3($rax as u64, $rbx as u64, $rcx as u64) );
12+
=> ( $crate::bits64::sgx::encls3($rax as u64, $rbx as u64, $rcx as u64) );
1313

1414
($rax:expr, $rbx:expr, $rcx:expr, $rdx:expr)
15-
=> ( $crate::sgx::encls4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) );
15+
=> ( $crate::bits64::sgx::encls4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) );
1616
}
1717

1818
/// encls with two arguments -- consider calling the encls! macro instead!
@@ -226,10 +226,10 @@ pub unsafe fn encls_ewb(pageinfo: u64, epc_page: u64, va_slot: u64) -> u32 {
226226
/// * Function needs to be executed in ring 3.
227227
macro_rules! enclu {
228228
($rax:expr, $rbx:expr, $rcx:expr)
229-
=> ( $crate::sgx::enclu3($rax as u64, $rbx as u64, $rcx as u64) );
229+
=> ( $crate::bits64::sgx::enclu3($rax as u64, $rbx as u64, $rcx as u64) );
230230

231231
($rax:expr, $rbx:expr, $rcx:expr, $rdx:expr)
232-
=> ( $crate::sgx::enclu4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) );
232+
=> ( $crate::bits64::sgx::enclu4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) );
233233
}
234234

235235
/// enclu with three arguments -- consider calling the enclu! macro instead!
File renamed without changes.

src/task.rs renamed to src/bits64/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Helpers to program the task state segment.
22
3-
use segmentation;
3+
use super::segmentation;
44

55
pub type TaskStateDescriptorLow = segmentation::SegmentDescriptor;
66
pub type TaskStateDescriptorHigh = u64;
File renamed without changes.

src/tlb.rs renamed to src/bits64/tlb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub unsafe fn flush(addr: usize) {
1515
/// This function is unsafe as it causes a general protection fault (GP) if the current privilege
1616
/// level is not 0.
1717
pub unsafe fn flush_all() {
18-
use controlregs::{cr3, cr3_write};
18+
use super::controlregs::{cr3, cr3_write};
1919
cr3_write(cr3())
2020
}

tobba/src/x86_64.rs renamed to src/bits64/tobba.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![allow(non_upper_case_globals)]
22

3-
pub use self::x86_shared::*;
4-
5-
mod x86_shared;
3+
pub use shared::*;
64

75
#[inline(always)]
86
pub fn get_flags() -> Flags {

src/lib.rs

+9-52
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
#![cfg(any(target_arch="x86", target_arch="x86_64"))]
2+
13
#![feature(const_fn)]
24
#![feature(asm)]
5+
#![feature(associated_consts)]
36
#![no_std]
47
#![cfg_attr(test, allow(unused_features))]
58

6-
#![crate_name = "x86"]
7-
#![crate_type = "lib"]
8-
99
#[macro_use]
1010
extern crate bitflags;
1111

@@ -16,57 +16,14 @@ extern crate raw_cpuid;
1616
#[macro_use]
1717
extern crate phf;
1818

19+
#[cfg(target_arch="x86")]
20+
pub mod bits32;
21+
#[cfg(target_arch="x86_64")]
22+
pub mod bits64;
23+
pub mod shared;
24+
1925
mod std {
2026
pub use core::fmt;
2127
pub use core::ops;
2228
pub use core::option;
2329
}
24-
25-
macro_rules! bit {
26-
( $x:expr ) => {
27-
1 << $x
28-
};
29-
}
30-
31-
macro_rules! check_flag {
32-
($doc:meta, $fun:ident, $flag:ident) => (
33-
#[$doc]
34-
pub fn $fun(&self) -> bool {
35-
self.contains($flag)
36-
}
37-
)
38-
}
39-
40-
macro_rules! is_bit_set {
41-
($field:expr, $bit:expr) => (
42-
$field & (1 << $bit) > 0
43-
)
44-
}
45-
46-
macro_rules! check_bit_fn {
47-
($doc:meta, $fun:ident, $field:ident, $bit:expr) => (
48-
#[$doc]
49-
pub fn $fun(&self) -> bool {
50-
is_bit_set!(self.$field, $bit)
51-
}
52-
)
53-
}
54-
55-
pub mod io;
56-
pub mod controlregs;
57-
pub mod msr;
58-
pub mod time;
59-
pub mod irq;
60-
pub mod rflags;
61-
pub mod paging;
62-
pub mod segmentation;
63-
pub mod task;
64-
pub mod dtables;
65-
pub mod syscall;
66-
pub mod sgx;
67-
#[cfg(feature = "performance-counter")]
68-
pub mod perfcnt;
69-
pub mod cpuid {
70-
pub use raw_cpuid::*;
71-
}
72-
pub mod tlb;

tobba/src/x86_shared.rs renamed to src/shared/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Data structures and functions used by both protected mode and IA-32e.
2+
3+
// In a few rare-cases this module includes mode-specific
4+
// *implementations*. This is usually because we cannot trust the LLVM inline
5+
// assembler to infer instruction variants from argument size, and thus we add
6+
// size-suffixes wherever possible.
7+
//
8+
// That said, *interfaces* must always be mode-portable
9+
110
#![allow(non_upper_case_globals)]
211

312
bitflags! {

tobba/.gitignore

-2
This file was deleted.

tobba/Cargo.toml

-7
This file was deleted.

tobba/LICENSE

-19
This file was deleted.

tobba/README.md

-6
This file was deleted.

tobba/src/lib.rs

-21
This file was deleted.

0 commit comments

Comments
 (0)