Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kernel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
redox-os
kernel
Commits
78e79fc4
Commit
78e79fc4
authored
Jun 21, 2019
by
Jeremy Soller
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2018' into 'master'
Switch to 2018 edition See merge request
!102
parents
1be77c2a
fe705d9b
Changes
73
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
73 changed files
with
374 additions
and
368 deletions
+374
-368
Cargo.toml
Cargo.toml
+1
-0
src/allocator/linked_list.rs
src/allocator/linked_list.rs
+3
-3
src/allocator/mod.rs
src/allocator/mod.rs
+5
-5
src/arch/x86_64/debug.rs
src/arch/x86_64/debug.rs
+3
-3
src/arch/x86_64/device/local_apic.rs
src/arch/x86_64/device/local_apic.rs
+5
-5
src/arch/x86_64/device/mod.rs
src/arch/x86_64/device/mod.rs
+1
-1
src/arch/x86_64/device/pic.rs
src/arch/x86_64/device/pic.rs
+1
-1
src/arch/x86_64/device/pit.rs
src/arch/x86_64/device/pit.rs
+1
-1
src/arch/x86_64/device/rtc.rs
src/arch/x86_64/device/rtc.rs
+2
-2
src/arch/x86_64/device/serial.rs
src/arch/x86_64/device/serial.rs
+2
-2
src/arch/x86_64/gdt.rs
src/arch/x86_64/gdt.rs
+2
-2
src/arch/x86_64/idt.rs
src/arch/x86_64/idt.rs
+2
-2
src/arch/x86_64/interrupt/exception.rs
src/arch/x86_64/interrupt/exception.rs
+2
-2
src/arch/x86_64/interrupt/ipi.rs
src/arch/x86_64/interrupt/ipi.rs
+2
-2
src/arch/x86_64/interrupt/irq.rs
src/arch/x86_64/interrupt/irq.rs
+7
-7
src/arch/x86_64/interrupt/syscall.rs
src/arch/x86_64/interrupt/syscall.rs
+2
-2
src/arch/x86_64/interrupt/trace.rs
src/arch/x86_64/interrupt/trace.rs
+4
-4
src/arch/x86_64/paging/entry.rs
src/arch/x86_64/paging/entry.rs
+1
-1
src/arch/x86_64/paging/mapper.rs
src/arch/x86_64/paging/mapper.rs
+1
-1
src/arch/x86_64/paging/mod.rs
src/arch/x86_64/paging/mod.rs
+15
-15
src/arch/x86_64/paging/table.rs
src/arch/x86_64/paging/table.rs
+2
-2
src/arch/x86_64/paging/temporary_page.rs
src/arch/x86_64/paging/temporary_page.rs
+1
-1
src/arch/x86_64/start.rs
src/arch/x86_64/start.rs
+11
-11
src/arch/x86_64/stop.rs
src/arch/x86_64/stop.rs
+1
-1
src/common/int_like.rs
src/common/int_like.rs
+7
-2
src/context/context.rs
src/context/context.rs
+12
-12
src/context/file.rs
src/context/file.rs
+3
-3
src/context/list.rs
src/context/list.rs
+3
-3
src/context/memory.rs
src/context/memory.rs
+8
-8
src/context/mod.rs
src/context/mod.rs
+2
-2
src/context/signal.rs
src/context/signal.rs
+7
-7
src/context/switch.rs
src/context/switch.rs
+7
-7
src/context/timeout.rs
src/context/timeout.rs
+5
-5
src/devices/uart_16550.rs
src/devices/uart_16550.rs
+1
-1
src/event.rs
src/event.rs
+6
-6
src/lib.rs
src/lib.rs
+3
-3
src/memory/bump.rs
src/memory/bump.rs
+1
-1
src/memory/mod.rs
src/memory/mod.rs
+1
-1
src/memory/recycle.rs
src/memory/recycle.rs
+1
-1
src/panic.rs
src/panic.rs
+1
-1
src/scheme/debug.rs
src/scheme/debug.rs
+6
-6
src/scheme/event.rs
src/scheme/event.rs
+4
-4
src/scheme/initfs.rs
src/scheme/initfs.rs
+4
-4
src/scheme/irq.rs
src/scheme/irq.rs
+6
-6
src/scheme/itimer.rs
src/scheme/itimer.rs
+6
-6
src/scheme/memory.rs
src/scheme/memory.rs
+10
-10
src/scheme/mod.rs
src/scheme/mod.rs
+5
-5
src/scheme/pipe.rs
src/scheme/pipe.rs
+8
-8
src/scheme/root.rs
src/scheme/root.rs
+7
-7
src/scheme/sys/context.rs
src/scheme/sys/context.rs
+2
-2
src/scheme/sys/cpu.rs
src/scheme/sys/cpu.rs
+3
-3
src/scheme/sys/exe.rs
src/scheme/sys/exe.rs
+2
-2
src/scheme/sys/iostat.rs
src/scheme/sys/iostat.rs
+3
-3
src/scheme/sys/log.rs
src/scheme/sys/log.rs
+2
-2
src/scheme/sys/mod.rs
src/scheme/sys/mod.rs
+4
-4
src/scheme/sys/scheme.rs
src/scheme/sys/scheme.rs
+3
-3
src/scheme/sys/scheme_num.rs
src/scheme/sys/scheme_num.rs
+3
-3
src/scheme/sys/syscall.rs
src/scheme/sys/syscall.rs
+3
-3
src/scheme/sys/uname.rs
src/scheme/sys/uname.rs
+1
-1
src/scheme/time.rs
src/scheme/time.rs
+7
-7
src/scheme/user.rs
src/scheme/user.rs
+17
-17
src/sync/wait_condition.rs
src/sync/wait_condition.rs
+1
-1
src/sync/wait_map.rs
src/sync/wait_map.rs
+1
-1
src/sync/wait_queue.rs
src/sync/wait_queue.rs
+1
-1
src/syscall/driver.rs
src/syscall/driver.rs
+9
-9
src/syscall/fs.rs
src/syscall/fs.rs
+9
-9
src/syscall/futex.rs
src/syscall/futex.rs
+6
-6
src/syscall/mod.rs
src/syscall/mod.rs
+11
-11
src/syscall/privilege.rs
src/syscall/privilege.rs
+4
-4
src/syscall/process.rs
src/syscall/process.rs
+71
-71
src/syscall/time.rs
src/syscall/time.rs
+5
-5
src/syscall/validate.rs
src/syscall/validate.rs
+3
-3
src/tests/mod.rs
src/tests/mod.rs
+2
-2
No files found.
Cargo.toml
View file @
78e79fc4
...
...
@@ -2,6 +2,7 @@
name
=
"kernel"
version
=
"0.1.54"
build
=
"build.rs"
edition
=
"2018"
[lib]
name
=
"kernel"
...
...
src/allocator/linked_list.rs
View file @
78e79fc4
...
...
@@ -3,7 +3,7 @@ use core::ptr::NonNull;
use
linked_list_allocator
::
Heap
;
use
spin
::
Mutex
;
use
paging
::
ActivePageTable
;
use
crate
::
paging
::
ActivePageTable
;
static
HEAP
:
Mutex
<
Option
<
Heap
>>
=
Mutex
::
new
(
None
);
...
...
@@ -32,10 +32,10 @@ unsafe impl GlobalAlloc for Allocator {
panic!
(
"__rust_allocate: heap not initialized"
);
};
super
::
map_heap
(
&
mut
ActivePageTable
::
new
(),
::
KERNEL_HEAP_OFFSET
+
size
,
::
KERNEL_HEAP_SIZE
);
super
::
map_heap
(
&
mut
ActivePageTable
::
new
(),
crate
::
KERNEL_HEAP_OFFSET
+
size
,
crate
::
KERNEL_HEAP_SIZE
);
if
let
Some
(
ref
mut
heap
)
=
*
HEAP
.lock
()
{
heap
.extend
(::
KERNEL_HEAP_SIZE
);
heap
.extend
(
crate
::
KERNEL_HEAP_SIZE
);
}
else
{
panic!
(
"__rust_allocate: heap not initialized"
);
}
...
...
src/allocator/mod.rs
View file @
78e79fc4
use
paging
::{
ActivePageTable
,
Page
,
VirtualAddress
};
use
paging
::
entry
::
EntryFlags
;
use
paging
::
mapper
::
MapperFlushAll
;
use
crate
::
paging
::{
ActivePageTable
,
Page
,
VirtualAddress
};
use
crate
::
paging
::
entry
::
EntryFlags
;
use
crate
::
paging
::
mapper
::
MapperFlushAll
;
#[cfg(not(feature=
"slab"
))]
pub
use
self
::
linked_list
::
Allocator
;
...
...
@@ -28,8 +28,8 @@ unsafe fn map_heap(active_table: &mut ActivePageTable, offset: usize, size: usiz
}
pub
unsafe
fn
init
(
active_table
:
&
mut
ActivePageTable
)
{
let
offset
=
::
KERNEL_HEAP_OFFSET
;
let
size
=
::
KERNEL_HEAP_SIZE
;
let
offset
=
crate
::
KERNEL_HEAP_OFFSET
;
let
size
=
crate
::
KERNEL_HEAP_SIZE
;
// Map heap pages
map_heap
(
active_table
,
offset
,
size
);
...
...
src/arch/x86_64/debug.rs
View file @
78e79fc4
...
...
@@ -3,12 +3,12 @@ use core::fmt;
use
spin
::
Mutex
;
use
spin
::
MutexGuard
;
use
log
::{
LOG
,
Log
};
use
crate
::
log
::{
LOG
,
Log
};
#[cfg(feature
=
"qemu_debug"
)]
use
syscall
::
io
::
Io
;
use
syscall
::
io
::
Pio
;
use
crate
::
syscall
::
io
::
Pio
;
#[cfg(feature
=
"serial_debug"
)]
use
devices
::
uart_16550
::
SerialPort
;
use
crate
::
devices
::
uart_16550
::
SerialPort
;
#[cfg(feature
=
"graphical_debug"
)]
use
super
::
graphical_debug
::{
DEBUG_DISPLAY
,
DebugDisplay
};
...
...
src/arch/x86_64/device/local_apic.rs
View file @
78e79fc4
...
...
@@ -2,9 +2,9 @@ use core::intrinsics::{volatile_load, volatile_store};
use
x86
::
shared
::
cpuid
::
CpuId
;
use
x86
::
shared
::
msr
::
*
;
use
memory
::
Frame
;
use
paging
::{
ActivePageTable
,
PhysicalAddress
,
Page
,
VirtualAddress
};
use
paging
::
entry
::
EntryFlags
;
use
crate
::
memory
::
Frame
;
use
crate
::
paging
::{
ActivePageTable
,
PhysicalAddress
,
Page
,
VirtualAddress
};
use
crate
::
paging
::
entry
::
EntryFlags
;
pub
static
mut
LOCAL_APIC
:
LocalApic
=
LocalApic
{
address
:
0
,
...
...
@@ -27,12 +27,12 @@ pub struct LocalApic {
impl
LocalApic
{
unsafe
fn
init
(
&
mut
self
,
active_table
:
&
mut
ActivePageTable
)
{
self
.address
=
(
rdmsr
(
IA32_APIC_BASE
)
as
usize
&
0xFFFF_0000
)
+
::
KERNEL_OFFSET
;
self
.address
=
(
rdmsr
(
IA32_APIC_BASE
)
as
usize
&
0xFFFF_0000
)
+
crate
::
KERNEL_OFFSET
;
self
.x2
=
CpuId
::
new
()
.get_feature_info
()
.unwrap
()
.has_x2apic
();
if
!
self
.x2
{
let
page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
self
.address
));
let
frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
self
.address
-
::
KERNEL_OFFSET
));
let
frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
self
.address
-
crate
::
KERNEL_OFFSET
));
let
result
=
active_table
.map_to
(
page
,
frame
,
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
result
.flush
(
active_table
);
}
...
...
src/arch/x86_64/device/mod.rs
View file @
78e79fc4
use
paging
::
ActivePageTable
;
use
crate
::
paging
::
ActivePageTable
;
pub
mod
cpu
;
pub
mod
local_apic
;
...
...
src/arch/x86_64/device/pic.rs
View file @
78e79fc4
use
syscall
::
io
::{
Io
,
Pio
};
use
crate
::
syscall
::
io
::{
Io
,
Pio
};
pub
static
mut
MASTER
:
Pic
=
Pic
::
new
(
0x20
);
pub
static
mut
SLAVE
:
Pic
=
Pic
::
new
(
0xA0
);
...
...
src/arch/x86_64/device/pit.rs
View file @
78e79fc4
use
syscall
::
io
::{
Io
,
Pio
};
use
crate
::
syscall
::
io
::{
Io
,
Pio
};
pub
static
mut
CHAN0
:
Pio
<
u8
>
=
Pio
::
new
(
0x40
);
pub
static
mut
CHAN1
:
Pio
<
u8
>
=
Pio
::
new
(
0x41
);
...
...
src/arch/x86_64/device/rtc.rs
View file @
78e79fc4
use
syscall
::
io
::{
Io
,
Pio
};
use
time
;
use
crate
::
syscall
::
io
::{
Io
,
Pio
};
use
crate
::
time
;
pub
fn
init
()
{
let
mut
rtc
=
Rtc
::
new
();
...
...
src/arch/x86_64/device/serial.rs
View file @
78e79fc4
use
devices
::
uart_16550
::
SerialPort
;
use
syscall
::
io
::
Pio
;
use
crate
::
devices
::
uart_16550
::
SerialPort
;
use
crate
::
syscall
::
io
::
Pio
;
use
spin
::
Mutex
;
pub
static
COM1
:
Mutex
<
SerialPort
<
Pio
<
u8
>>>
=
Mutex
::
new
(
SerialPort
::
<
Pio
<
u8
>>
::
new
(
0x3F8
));
...
...
src/arch/x86_64/gdt.rs
View file @
78e79fc4
...
...
@@ -8,7 +8,7 @@ use x86::shared::dtables::{self, DescriptorTablePointer};
use
x86
::
shared
::
segmentation
::{
self
,
SegmentDescriptor
,
SegmentSelector
};
use
x86
::
shared
::
task
;
use
paging
::
PAGE_SIZE
;
use
crate
::
paging
::
PAGE_SIZE
;
pub
const
GDT_NULL
:
usize
=
0
;
pub
const
GDT_KERNEL_CODE
:
usize
=
1
;
...
...
@@ -94,7 +94,7 @@ pub static mut TSS: TaskStateSegment = TaskStateSegment {
};
pub
unsafe
fn
set_tcb
(
pid
:
usize
)
{
GDT
[
GDT_USER_TLS
]
.set_offset
((::
USER_TCB_OFFSET
+
pid
*
PAGE_SIZE
)
as
u32
);
GDT
[
GDT_USER_TLS
]
.set_offset
((
crate
::
USER_TCB_OFFSET
+
pid
*
PAGE_SIZE
)
as
u32
);
}
#[cfg(feature
=
"pti"
)]
...
...
src/arch/x86_64/idt.rs
View file @
78e79fc4
...
...
@@ -2,8 +2,8 @@ use core::mem;
use
x86
::
current
::
irq
::
IdtEntry
as
X86IdtEntry
;
use
x86
::
shared
::
dtables
::{
self
,
DescriptorTablePointer
};
use
interrupt
::
*
;
use
ipi
::
IpiKind
;
use
crate
::
interrupt
::
*
;
use
crate
::
ipi
::
IpiKind
;
pub
static
mut
INIT_IDTR
:
DescriptorTablePointer
<
X86IdtEntry
>
=
DescriptorTablePointer
{
limit
:
0
,
...
...
src/arch/x86_64/interrupt/exception.rs
View file @
78e79fc4
use
interrupt
::
stack_trace
;
use
syscall
::
flag
::
*
;
use
crate
::
interrupt
::
stack_trace
;
use
crate
::
syscall
::
flag
::
*
;
extern
{
fn
ksignal
(
signal
:
usize
);
...
...
src/arch/x86_64/interrupt/ipi.rs
View file @
78e79fc4
use
core
::
sync
::
atomic
::
Ordering
;
use
x86
::
shared
::
tlb
;
use
context
;
use
device
::
local_apic
::
LOCAL_APIC
;
use
c
rate
::
c
ontext
;
use
crate
::
device
::
local_apic
::
LOCAL_APIC
;
use
super
::
irq
::
PIT_TICKS
;
interrupt!
(
wakeup
,
{
...
...
src/arch/x86_64/interrupt/irq.rs
View file @
78e79fc4
use
core
::
sync
::
atomic
::{
AtomicUsize
,
Ordering
};
use
context
;
use
context
::
timeout
;
use
device
::
pic
;
use
device
::
serial
::{
COM1
,
COM2
};
use
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
scheme
::
debug
::
debug_input
;
use
time
;
use
c
rate
::
c
ontext
;
use
c
rate
::
c
ontext
::
timeout
;
use
crate
::
device
::
pic
;
use
crate
::
device
::
serial
::{
COM1
,
COM2
};
use
crate
::
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
crate
::
scheme
::
debug
::
debug_input
;
use
crate
::
time
;
//resets to 0 in context::switch()
pub
static
PIT_TICKS
:
AtomicUsize
=
AtomicUsize
::
new
(
0
);
...
...
src/arch/x86_64/interrupt/syscall.rs
View file @
78e79fc4
use
arch
::{
gdt
,
pti
};
use
syscall
;
use
crate
::
arch
::{
gdt
,
pti
};
use
crate
::
syscall
;
use
x86
::
shared
::
msr
;
pub
unsafe
fn
init
()
{
...
...
src/arch/x86_64/interrupt/trace.rs
View file @
78e79fc4
...
...
@@ -2,7 +2,7 @@ use core::{mem, str};
use
goblin
::
elf
::
sym
;
use
rustc_demangle
::
demangle
;
use
paging
::{
ActivePageTable
,
VirtualAddress
};
use
crate
::
paging
::{
ActivePageTable
,
VirtualAddress
};
/// Get a stack trace
//TODO: Check for stack being mapped before dereferencing
...
...
@@ -43,10 +43,10 @@ pub unsafe fn symbol_trace(addr: usize) {
use
core
::
slice
;
use
core
::
sync
::
atomic
::
Ordering
;
use
elf
::
Elf
;
use
start
::{
KERNEL_BASE
,
KERNEL_SIZE
};
use
crate
::
elf
::
Elf
;
use
crate
::
start
::{
KERNEL_BASE
,
KERNEL_SIZE
};
let
kernel_ptr
=
(
KERNEL_BASE
.load
(
Ordering
::
SeqCst
)
+
::
KERNEL_OFFSET
)
as
*
const
u8
;
let
kernel_ptr
=
(
KERNEL_BASE
.load
(
Ordering
::
SeqCst
)
+
crate
::
KERNEL_OFFSET
)
as
*
const
u8
;
let
kernel_slice
=
slice
::
from_raw_parts
(
kernel_ptr
,
KERNEL_SIZE
.load
(
Ordering
::
SeqCst
));
if
let
Ok
(
elf
)
=
Elf
::
from
(
kernel_slice
)
{
let
mut
strtab_opt
=
None
;
...
...
src/arch/x86_64/paging/entry.rs
View file @
78e79fc4
//! # Page table entry
//! Some code borrowed from [Phil Opp's Blog](http://os.phil-opp.com/modifying-page-tables.html)
use
memory
::
Frame
;
use
crate
::
memory
::
Frame
;
use
super
::
PhysicalAddress
;
...
...
src/arch/x86_64/paging/mapper.rs
View file @
78e79fc4
use
core
::
mem
;
use
core
::
ptr
::
Unique
;
use
memory
::{
allocate_frames
,
deallocate_frames
,
Frame
};
use
crate
::
memory
::{
allocate_frames
,
deallocate_frames
,
Frame
};
use
super
::{
ActivePageTable
,
Page
,
PAGE_SIZE
,
PhysicalAddress
,
VirtualAddress
};
use
super
::
entry
::
EntryFlags
;
...
...
src/arch/x86_64/paging/mod.rs
View file @
78e79fc4
...
...
@@ -5,7 +5,7 @@ use core::{mem, ptr};
use
core
::
ops
::{
Deref
,
DerefMut
};
use
x86
::
shared
::{
control_regs
,
msr
,
tlb
};
use
memory
::{
allocate_frames
,
Frame
};
use
crate
::
memory
::{
allocate_frames
,
Frame
};
use
self
::
entry
::
EntryFlags
;
use
self
::
mapper
::
Mapper
;
...
...
@@ -63,7 +63,7 @@ unsafe fn init_tcb(cpu_id: usize) -> usize {
let
size
=
&
__
tbss_end
as
*
const
_
as
usize
-
&
__
tdata_start
as
*
const
_
as
usize
;
let
tbss_offset
=
&
__
tbss_start
as
*
const
_
as
usize
-
&
__
tdata_start
as
*
const
_
as
usize
;
let
start
=
::
KERNEL_PERCPU_OFFSET
+
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
start
=
crate
::
KERNEL_PERCPU_OFFSET
+
crate
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
end
=
start
+
size
;
tcb_offset
=
end
-
mem
::
size_of
::
<
usize
>
();
...
...
@@ -110,7 +110,7 @@ pub unsafe fn init(cpu_id: usize, kernel_start: usize, kernel_end: usize, stack_
let
mut
active_table
=
ActivePageTable
::
new
();
let
mut
temporary_page
=
TemporaryPage
::
new
(
Page
::
containing_address
(
VirtualAddress
::
new
(::
USER_TMP_MISC_OFFSET
)));
let
mut
temporary_page
=
TemporaryPage
::
new
(
Page
::
containing_address
(
VirtualAddress
::
new
(
crate
::
USER_TMP_MISC_OFFSET
)));
let
mut
new_table
=
{
let
frame
=
allocate_frames
(
1
)
.expect
(
"no more frames in paging::init new_table"
);
...
...
@@ -120,10 +120,10 @@ pub unsafe fn init(cpu_id: usize, kernel_start: usize, kernel_end: usize, stack_
active_table
.with
(
&
mut
new_table
,
&
mut
temporary_page
,
|
mapper
|
{
// Remap stack writable, no execute
{
let
start_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
stack_start
-
::
KERNEL_OFFSET
));
let
end_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
stack_end
-
::
KERNEL_OFFSET
-
1
));
let
start_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
stack_start
-
crate
::
KERNEL_OFFSET
));
let
end_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
stack_end
-
crate
::
KERNEL_OFFSET
-
1
));
for
frame
in
Frame
::
range_inclusive
(
start_frame
,
end_frame
)
{
let
page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
frame
.start_address
()
.get
()
+
::
KERNEL_OFFSET
));
let
page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
frame
.start_address
()
.get
()
+
crate
::
KERNEL_OFFSET
));
let
result
=
mapper
.map_to
(
page
,
frame
,
EntryFlags
::
PRESENT
|
EntryFlags
::
GLOBAL
|
EntryFlags
::
NO_EXECUTE
|
EntryFlags
::
WRITABLE
);
// The flush can be ignored as this is not the active table. See later active_table.switch
/* unsafe */
{
result
.ignore
();
}
...
...
@@ -136,7 +136,7 @@ pub unsafe fn init(cpu_id: usize, kernel_start: usize, kernel_end: usize, stack_
let
end_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
kernel_end
-
1
));
for
frame
in
Frame
::
range_inclusive
(
start_frame
,
end_frame
)
{
let
phys_addr
=
frame
.start_address
()
.get
();
let
virt_addr
=
phys_addr
+
::
KERNEL_OFFSET
;
let
virt_addr
=
phys_addr
+
crate
::
KERNEL_OFFSET
;
macro_rules!
in_section
{
(
$n
:
ident
)
=>
(
...
...
@@ -176,7 +176,7 @@ pub unsafe fn init(cpu_id: usize, kernel_start: usize, kernel_end: usize, stack_
{
let
size
=
&
__
tbss_end
as
*
const
_
as
usize
-
&
__
tdata_start
as
*
const
_
as
usize
;
let
start
=
::
KERNEL_PERCPU_OFFSET
+
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
start
=
crate
::
KERNEL_PERCPU_OFFSET
+
crate
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
end
=
start
+
size
;
let
start_page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
start
));
...
...
@@ -214,14 +214,14 @@ pub unsafe fn init_ap(cpu_id: usize, bsp_table: usize, stack_start: usize, stack
let
mut
new_table
=
InactivePageTable
::
from_address
(
bsp_table
);
let
mut
temporary_page
=
TemporaryPage
::
new
(
Page
::
containing_address
(
VirtualAddress
::
new
(::
USER_TMP_MISC_OFFSET
)));
let
mut
temporary_page
=
TemporaryPage
::
new
(
Page
::
containing_address
(
VirtualAddress
::
new
(
crate
::
USER_TMP_MISC_OFFSET
)));
active_table
.with
(
&
mut
new_table
,
&
mut
temporary_page
,
|
mapper
|
{
// Map tdata and tbss
{
let
size
=
&
__
tbss_end
as
*
const
_
as
usize
-
&
__
tdata_start
as
*
const
_
as
usize
;
let
start
=
::
KERNEL_PERCPU_OFFSET
+
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
start
=
crate
::
KERNEL_PERCPU_OFFSET
+
crate
::
KERNEL_PERCPU_SIZE
*
cpu_id
;
let
end
=
start
+
size
;
let
start_page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
start
));
...
...
@@ -238,7 +238,7 @@ pub unsafe fn init_ap(cpu_id: usize, bsp_table: usize, stack_start: usize, stack
let
start_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
start
));
let
end_frame
=
Frame
::
containing_address
(
PhysicalAddress
::
new
(
end
-
1
));
for
frame
in
Frame
::
range_inclusive
(
start_frame
,
end_frame
)
{
let
page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
frame
.start_address
()
.get
()
+
::
KERNEL_OFFSET
));
let
page
=
Page
::
containing_address
(
VirtualAddress
::
new
(
frame
.start_address
()
.get
()
+
crate
::
KERNEL_OFFSET
));
let
result
=
mapper
.map_to
(
page
,
frame
,
flags
);
// The flush can be ignored as this is not the active table. See later active_table.switch
result
.ignore
();
...
...
@@ -247,7 +247,7 @@ pub unsafe fn init_ap(cpu_id: usize, bsp_table: usize, stack_start: usize, stack
};
// Remap stack writable, no execute
remap
(
stack_start
-
::
KERNEL_OFFSET
,
stack_end
-
::
KERNEL_OFFSET
,
EntryFlags
::
PRESENT
|
EntryFlags
::
GLOBAL
|
EntryFlags
::
NO_EXECUTE
|
EntryFlags
::
WRITABLE
);
remap
(
stack_start
-
crate
::
KERNEL_OFFSET
,
stack_end
-
crate
::
KERNEL_OFFSET
,
EntryFlags
::
PRESENT
|
EntryFlags
::
GLOBAL
|
EntryFlags
::
NO_EXECUTE
|
EntryFlags
::
WRITABLE
);
});
// This switches the active table, which is setup by the bootloader, to a correct table
...
...
@@ -312,14 +312,14 @@ impl ActivePageTable {
let
p4_table
=
temporary_page
.map_table_frame
(
backup
.clone
(),
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
,
self
);
// overwrite recursive mapping
self
.p4_mut
()[::
RECURSIVE_PAGE_PML4
]
.set
(
table
.p4_frame
.clone
(),
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
self
.p4_mut
()[
crate
::
RECURSIVE_PAGE_PML4
]
.set
(
table
.p4_frame
.clone
(),
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
self
.flush_all
();
// execute f in the new context
f
(
self
);
// restore recursive mapping to original p4 table
p4_table
[::
RECURSIVE_PAGE_PML4
]
.set
(
backup
,
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
p4_table
[
crate
::
RECURSIVE_PAGE_PML4
]
.set
(
backup
,
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
self
.flush_all
();
}
...
...
@@ -342,7 +342,7 @@ impl InactivePageTable {
// now we are able to zero the table
table
.zero
();
// set up recursive mapping for the table
table
[::
RECURSIVE_PAGE_PML4
]
.set
(
frame
.clone
(),
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
table
[
crate
::
RECURSIVE_PAGE_PML4
]
.set
(
frame
.clone
(),
EntryFlags
::
PRESENT
|
EntryFlags
::
WRITABLE
|
EntryFlags
::
NO_EXECUTE
);
}
temporary_page
.unmap
(
active_table
);
...
...
src/arch/x86_64/paging/table.rs
View file @
78e79fc4
...
...
@@ -4,12 +4,12 @@
use
core
::
marker
::
PhantomData
;
use
core
::
ops
::{
Index
,
IndexMut
};
use
memory
::
allocate_frames
;
use
crate
::
memory
::
allocate_frames
;
use
super
::
entry
::{
EntryFlags
,
Entry
};
use
super
::
ENTRY_COUNT
;
pub
const
P4
:
*
mut
Table
<
Level4
>
=
(::
RECURSIVE_PAGE_OFFSET
|
0x7ffffff000
)
as
*
mut
_
;
pub
const
P4
:
*
mut
Table
<
Level4
>
=
(
crate
::
RECURSIVE_PAGE_OFFSET
|
0x7ffffff000
)
as
*
mut
_
;
pub
trait
TableLevel
{}
...
...
src/arch/x86_64/paging/temporary_page.rs
View file @
78e79fc4
//! Temporarily map a page
//! From [Phil Opp's Blog](http://os.phil-opp.com/remap-the-kernel.html)
use
memory
::
Frame
;
use
crate
::
memory
::
Frame
;
use
super
::{
ActivePageTable
,
Page
,
VirtualAddress
};
use
super
::
entry
::
EntryFlags
;
...
...
src/arch/x86_64/start.rs
View file @
78e79fc4
...
...
@@ -6,19 +6,19 @@
use
core
::
slice
;
use
core
::
sync
::
atomic
::{
AtomicBool
,
AtomicUsize
,
Ordering
};
use
allocator
;
use
crate
::
allocator
;
#[cfg(feature
=
"acpi"
)]
use
acpi
;
#[cfg(feature
=
"graphical_debug"
)]
use
arch
::
x86_64
::
graphical_debug
;
use
arch
::
x86_64
::
pti
;
use
device
;
use
gdt
;
use
idt
;
use
interrupt
;
use
log
;
use
memory
;
use
paging
;
use
crate
::
arch
::
x86_64
::
pti
;
use
crate
::
device
;
use
crate
::
gdt
;
use
crate
::
idt
;
use
crate
::
interrupt
;
use
crate
::
log
;
use
crate
::
memory
;
use
crate
::
paging
;
/// Test of zero values in BSS.
static
BSS_TEST_ZERO
:
usize
=
0
;
...
...
@@ -141,7 +141,7 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! {
slice
::
from_raw_parts
(
env_base
as
*
const
u8
,
env_size
)
};
::
kmain
(
CPU_COUNT
.load
(
Ordering
::
SeqCst
),
env
);
crate
::
kmain
(
CPU_COUNT
.load
(
Ordering
::
SeqCst
),
env
);
}
#[repr(packed)]
...
...
@@ -204,7 +204,7 @@ pub unsafe extern fn kstart_ap(args_ptr: *const KernelArgsAp) -> ! {
interrupt
::
pause
();
}
::
kmain_ap
(
cpu_id
);
crate
::
kmain_ap
(
cpu_id
);
}
#[naked]
...
...
src/arch/x86_64/stop.rs
View file @
78e79fc4
#[cfg(feature
=
"acpi"
)]
use
acpi
;
use
syscall
::
io
::{
Io
,
Pio
};
use
crate
::
syscall
::
io
::{
Io
,
Pio
};
#[no_mangle]
pub
unsafe
extern
fn
kreset
()
->
!
{
...
...
src/common/int_like.rs
View file @
78e79fc4
...
...
@@ -29,9 +29,11 @@ macro_rules! int_like {
pub
struct
$new_type_name
(
$backing_type
);
impl
$new_type_name
{
#[allow(dead_code)]
pub
const
fn
into
(
self
)
->
$backing_type
{
self
.0
}
#[allow(dead_code)]
pub
const
fn
from
(
x
:
$backing_type
)
->
Self
{
$new_type_name
(
x
)
}
...
...
@@ -48,17 +50,21 @@ macro_rules! int_like {
}
impl
$new_atomic_type_name
{
#[allow(dead_code)]
pub
const
fn
new
(
x
:
$new_type_name
)
->
Self
{
$new_atomic_type_name
{
container
:
$backing_atomic_type
::
new
(
x
.into
())
}
}
#[allow(dead_code)]
pub
const
fn
default
()
->
Self
{
Self
::
new
(
$new_type_name
::
from
(
0
))
}
#[allow(dead_code)]
pub
fn
load
(
&
self
,
order
:
::
core
::
sync
::
atomic
::
Ordering
)
->
$new_type_name
{
$new_type_name
::
from
(
self
.container
.load
(
order
))
}
#[allow(dead_code)]
pub
fn
store
(
&
self
,
val
:
$new_type_name
,
order
:
::
core
::
sync
::
atomic
::
Ordering
)
{
self
.container
.store
(
val
.into
(),
order
)
}
...
...
@@ -88,14 +94,13 @@ macro_rules! int_like {
}
}
#[
cfg(test)
]
#[
test
]
fn
test
()
{
use
core
::
mem
::
size_of
;
use
::
core
::
sync
::
atomic
::
AtomicUsize
;
// Generate type `usize_like`.
int_like!
(
UsizeLike
,
usize
);
const
ZERO
:
UsizeLike
=
UsizeLike
::
from
(
0
);
assert_eq!
(
size_of
::
<
UsizeLike
>
(),
size_of
::
<
usize
>
());
...
...
src/context/context.rs
View file @
78e79fc4
...
...
@@ -7,15 +7,15 @@ use core::cmp::Ordering;
use
core
::
mem
;
use
spin
::
Mutex
;
use
arch
::
paging
::
PAGE_SIZE
;
use
context
::
arch
;
use
context
::
file
::
FileDescriptor
;
use
context
::
memory
::{
Grant
,
Memory
,
SharedMemory
,
Tls
};
use
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
scheme
::{
SchemeNamespace
,
FileHandle
};
use
syscall
::
data
::
SigAction
;
use
syscall
::
flag
::
SIG_DFL
;
use
sync
::
WaitMap
;
use
crate
::
arch
::
paging
::
PAGE_SIZE
;
use
c
rate
::
c
ontext
::
arch
;
use
c
rate
::
c
ontext
::
file
::
FileDescriptor
;
use
c
rate
::
c
ontext
::
memory
::{
Grant
,
Memory
,
SharedMemory
,
Tls
};
use
crate
::
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
crate
::
scheme
::{
SchemeNamespace
,
FileHandle
};
use
crate
::
syscall
::
data
::
SigAction
;
use
crate
::
syscall
::
flag
::
SIG_DFL
;
use
crate
::
sync
::
WaitMap
;
/// Unique identifier for a context (i.e. `pid`).
use
::
core
::
sync
::
atomic
::
AtomicUsize
;
...
...
@@ -169,8 +169,8 @@ pub struct Context {
impl
Context
{
pub
fn
new
(
id
:
ContextId
)
->
Context
{
let
syscall_head
=
unsafe
{
Box
::
from_raw
(::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
PAGE_SIZE
,
PAGE_SIZE
))
as
*
mut
[
u8
;
PAGE_SIZE
])
};
let
syscall_tail
=
unsafe
{
Box
::
from_raw
(::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
PAGE_SIZE
,
PAGE_SIZE
))
as
*
mut
[
u8
;
PAGE_SIZE
])
};
let
syscall_head
=
unsafe
{
Box
::
from_raw
(
crate
::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
PAGE_SIZE
,
PAGE_SIZE
))
as
*
mut
[
u8
;
PAGE_SIZE
])
};
let
syscall_tail
=
unsafe
{
Box
::
from_raw
(
crate
::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
PAGE_SIZE
,
PAGE_SIZE
))
as
*
mut
[
u8
;
PAGE_SIZE
])
};
Context
{
id
:
id
,
...
...
@@ -304,7 +304,7 @@ impl Context {
self
.status
=
Status
::
Runnable
;
if
let
Some
(
cpu_id
)
=
self
.cpu_id
{
if
cpu_id
!=
::
cpu_id
()
{
if
cpu_id
!=
crate
::
cpu_id
()
{
// Send IPI if not on current CPU
ipi
(
IpiKind
::
Wakeup
,
IpiTarget
::
Other
);
}
...
...
src/context/file.rs
View file @
78e79fc4
//! File structs
use
alloc
::
sync
::
Arc
;
use
event
;
use
crate
::
event
;
use
spin
::
RwLock
;
use
scheme
::{
self
,
SchemeId
};
use
syscall
::
error
::{
Result
,
Error
,
EBADF
};
use
crate
::
scheme
::{
self
,
SchemeId
};
use
crate
::
syscall
::
error
::{
Result
,
Error
,
EBADF
};
/// A file description
#[derive(Debug)]
...
...
src/context/list.rs
View file @
78e79fc4
...
...
@@ -4,10 +4,10 @@ use alloc::collections::BTreeMap;
use
core
::
alloc
::{
GlobalAlloc
,
Layout
};
use
core
::
mem
;
use
core
::
sync
::
atomic
::
Ordering
;
use
paging
;
use
crate
::
paging
;
use
spin
::
RwLock
;
use
syscall
::
error
::{
Result
,
Error
,
EAGAIN
};
use
crate
::
syscall
::
error
::{
Result
,
Error
,
EAGAIN
};
use
super
::
context
::{
Context
,
ContextId
};
/// Context list type
...
...
@@ -66,7 +66,7 @@ impl ContextList {
let
context_lock
=
self
.new_context
()
?
;
{
let
mut
context
=
context_lock
.write
();
let
mut
fx
=
unsafe
{
Box
::
from_raw
(::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
512
,
16
))
as
*
mut
[
u8
;
512
])
};
let
mut
fx
=
unsafe
{
Box
::
from_raw
(
crate
::
ALLOCATOR
.alloc
(
Layout
::
from_size_align_unchecked
(
512
,
16
))
as
*
mut
[
u8
;
512
])
};
for
b
in
fx
.iter_mut
()
{
*
b
=
0
;
}
...
...
src/context/memory.rs
View file @
78e79fc4
...
...
@@ -3,14 +3,14 @@ use alloc::collections::VecDeque;
use
core
::
intrinsics
;
use
spin
::
Mutex
;
use
arch
::
paging
::
PAGE_SIZE
;
use
context
::
file
::
FileDescriptor
;
use
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
memory
::
Frame
;
use
paging
::{
ActivePageTable
,
InactivePageTable
,
Page
,
PageIter
,
PhysicalAddress
,
VirtualAddress
};
use
paging
::
entry
::
EntryFlags
;
use
paging
::
mapper
::
MapperFlushAll
;
use
paging
::
temporary_page
::
TemporaryPage
;
use
crate
::
arch
::
paging
::
PAGE_SIZE
;
use
c
rate
::
c
ontext
::
file
::
FileDescriptor
;
use
crate
::
ipi
::{
ipi
,
IpiKind
,
IpiTarget
};
use
crate
::
memory
::
Frame
;
use
crate
::
paging
::{
ActivePageTable
,
InactivePageTable
,
Page
,
PageIter
,
PhysicalAddress
,
VirtualAddress
};
use
crate
::
paging
::
entry
::
EntryFlags
;
use
crate
::