2018-04-28 08:48:16 +04:00
|
|
|
#![allow(dead_code)]
|
2018-04-13 10:22:09 +04:00
|
|
|
|
2018-08-04 12:20:25 +04:00
|
|
|
#[cfg(target_arch = "riscv32")]
|
2018-07-10 13:37:38 +04:00
|
|
|
pub use self::riscv::*;
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
pub use self::x86_64::*;
|
|
|
|
|
2018-07-11 06:57:07 +04:00
|
|
|
pub const MAX_CPU_NUM: usize = 8;
|
2018-07-14 21:07:25 +04:00
|
|
|
pub const MAX_PROCESS_NUM: usize = 48;
|
2018-07-11 06:57:07 +04:00
|
|
|
|
2018-08-04 12:20:25 +04:00
|
|
|
#[cfg(target_arch = "riscv32")]
|
2018-07-10 13:37:38 +04:00
|
|
|
mod riscv {
|
|
|
|
// Physical address available on THINPAD:
|
|
|
|
// [0x80000000, 0x80800000]
|
|
|
|
const P2_SIZE: usize = 1 << 22;
|
|
|
|
const P2_MASK: usize = 0x3ff << 22;
|
2018-07-11 17:37:42 +04:00
|
|
|
pub const RECURSIVE_PAGE_PML4: usize = 0x3fe;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const KERNEL_OFFSET: usize = 0;
|
2018-07-12 18:44:34 +04:00
|
|
|
pub const KERNEL_PML4: usize = 0x8000_0000 >> 22;
|
2018-07-14 13:41:45 +04:00
|
|
|
pub const KERNEL_HEAP_OFFSET: usize = 0x8020_0000;
|
2018-07-14 21:07:25 +04:00
|
|
|
pub const KERNEL_HEAP_SIZE: usize = 0x0020_0000;
|
2018-07-11 17:37:42 +04:00
|
|
|
pub const MEMORY_OFFSET: usize = 0x8000_0000;
|
|
|
|
pub const MEMORY_END: usize = 0x8080_0000;
|
2018-07-12 14:56:29 +04:00
|
|
|
pub const USER_STACK_OFFSET: usize = 0x70000000;
|
2018-07-14 14:42:58 +04:00
|
|
|
pub const USER_STACK_SIZE: usize = 0x10000;
|
2018-07-12 14:56:29 +04:00
|
|
|
pub const USER32_STACK_OFFSET: usize = USER_STACK_OFFSET;
|
2018-07-10 13:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
mod x86_64 {
|
|
|
|
// Copy from Redox consts.rs:
|
2018-04-13 10:22:09 +04:00
|
|
|
|
2018-07-10 13:37:38 +04:00
|
|
|
// Because the memory map is so important to not be aliased, it is defined here, in one place
|
|
|
|
// The lower 256 PML4 entries are reserved for userspace
|
|
|
|
// Each PML4 entry references up to 512 GB of memory
|
|
|
|
// The top (511) PML4 is reserved for recursive mapping
|
|
|
|
// The second from the top (510) PML4 is reserved for the kernel
|
2018-04-13 10:22:09 +04:00
|
|
|
/// The size of a single PML4
|
|
|
|
pub const PML4_SIZE: usize = 0x0000_0080_0000_0000;
|
|
|
|
pub const PML4_MASK: usize = 0x0000_ff80_0000_0000;
|
|
|
|
|
|
|
|
/// Offset of recursive paging
|
|
|
|
pub const RECURSIVE_PAGE_OFFSET: usize = (-(PML4_SIZE as isize)) as usize;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const RECURSIVE_PAGE_PML4: usize = (RECURSIVE_PAGE_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset of kernel
|
|
|
|
pub const KERNEL_OFFSET: usize = RECURSIVE_PAGE_OFFSET - PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const KERNEL_PML4: usize = (KERNEL_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
2018-04-13 14:41:39 +04:00
|
|
|
pub const KERNEL_SIZE: usize = PML4_SIZE;
|
|
|
|
|
2018-04-13 10:22:09 +04:00
|
|
|
/// Offset to kernel heap
|
|
|
|
pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const KERNEL_HEAP_PML4: usize = (KERNEL_HEAP_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
/// Size of kernel heap
|
2018-05-17 18:15:26 +04:00
|
|
|
pub const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024; // 8 MB
|
2018-04-13 10:22:09 +04:00
|
|
|
|
2018-07-11 17:37:42 +04:00
|
|
|
pub const MEMORY_OFFSET: usize = 0;
|
2018-07-11 06:57:07 +04:00
|
|
|
|
2018-04-13 10:22:09 +04:00
|
|
|
/// Offset to kernel percpu variables
|
|
|
|
//TODO: Use 64-bit fs offset to enable this pub const KERNEL_PERCPU_OFFSET: usize = KERNEL_HEAP_OFFSET - PML4_SIZE;
|
|
|
|
pub const KERNEL_PERCPU_OFFSET: usize = 0xC000_0000;
|
|
|
|
/// Size of kernel percpu variables
|
|
|
|
pub const KERNEL_PERCPU_SIZE: usize = 64 * 1024; // 64 KB
|
|
|
|
|
|
|
|
/// Offset to user image
|
|
|
|
pub const USER_OFFSET: usize = 0;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_PML4: usize = (USER_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user TCB
|
|
|
|
pub const USER_TCB_OFFSET: usize = 0xB000_0000;
|
|
|
|
|
|
|
|
/// Offset to user arguments
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_ARG_OFFSET: usize = USER_OFFSET + PML4_SIZE / 2;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user heap
|
|
|
|
pub const USER_HEAP_OFFSET: usize = USER_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_HEAP_PML4: usize = (USER_HEAP_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user grants
|
|
|
|
pub const USER_GRANT_OFFSET: usize = USER_HEAP_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_GRANT_PML4: usize = (USER_GRANT_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user stack
|
|
|
|
pub const USER_STACK_OFFSET: usize = USER_GRANT_OFFSET + PML4_SIZE;
|
2018-07-12 14:56:29 +04:00
|
|
|
pub const USER32_STACK_OFFSET: usize = 0xB000_0000;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_STACK_PML4: usize = (USER_STACK_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
/// Size of user stack
|
|
|
|
pub const USER_STACK_SIZE: usize = 1024 * 1024; // 1 MB
|
|
|
|
|
|
|
|
/// Offset to user sigstack
|
|
|
|
pub const USER_SIGSTACK_OFFSET: usize = USER_STACK_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_SIGSTACK_PML4: usize = (USER_SIGSTACK_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
/// Size of user sigstack
|
|
|
|
pub const USER_SIGSTACK_SIZE: usize = 256 * 1024; // 256 KB
|
|
|
|
|
|
|
|
/// Offset to user TLS
|
|
|
|
pub const USER_TLS_OFFSET: usize = USER_SIGSTACK_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TLS_PML4: usize = (USER_TLS_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary image (used when cloning)
|
|
|
|
pub const USER_TMP_OFFSET: usize = USER_TLS_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_PML4: usize = (USER_TMP_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary heap (used when cloning)
|
|
|
|
pub const USER_TMP_HEAP_OFFSET: usize = USER_TMP_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_HEAP_PML4: usize = (USER_TMP_HEAP_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary page for grants
|
|
|
|
pub const USER_TMP_GRANT_OFFSET: usize = USER_TMP_HEAP_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_GRANT_PML4: usize = (USER_TMP_GRANT_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary stack (used when cloning)
|
|
|
|
pub const USER_TMP_STACK_OFFSET: usize = USER_TMP_GRANT_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_STACK_PML4: usize = (USER_TMP_STACK_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary sigstack (used when cloning)
|
|
|
|
pub const USER_TMP_SIGSTACK_OFFSET: usize = USER_TMP_STACK_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_SIGSTACK_PML4: usize = (USER_TMP_SIGSTACK_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset to user temporary tls (used when cloning)
|
|
|
|
pub const USER_TMP_TLS_OFFSET: usize = USER_TMP_SIGSTACK_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_TLS_PML4: usize = (USER_TMP_TLS_OFFSET & PML4_MASK) / PML4_SIZE;
|
2018-04-13 10:22:09 +04:00
|
|
|
|
|
|
|
/// Offset for usage in other temporary pages
|
|
|
|
pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE;
|
2018-07-10 13:37:38 +04:00
|
|
|
pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK) / PML4_SIZE;
|
|
|
|
}
|