1
0
mirror of https://github.com/rcore-os/rCore.git synced 2025-01-19 01:07:05 +04:00

Merge pull request #53 from CircuitCoder/master

This commit is contained in:
Chen 2020-05-16 07:05:11 +08:00 committed by GitHub
commit 425daba70e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 11 deletions

View File

@ -33,6 +33,7 @@ impl Clone for Box<dyn MemoryHandler> {
pub trait FrameAllocator: Debug + Clone + Send + Sync + 'static {
fn alloc(&self) -> Option<PhysAddr>;
fn alloc_contiguous(&self, size: usize, align_log2: usize) -> Option<PhysAddr>;
fn dealloc(&self, target: PhysAddr);
}

6
kernel/Cargo.lock generated
View File

@ -91,7 +91,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitmap-allocator"
version = "0.1.0"
source = "git+https://github.com/rcore-os/bitmap-allocator?rev=03bd990#03bd9909d0dc85e99f5559b97a163ab81073df83"
source = "git+https://github.com/rcore-os/bitmap-allocator#03bd9909d0dc85e99f5559b97a163ab81073df83"
dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -347,7 +347,7 @@ dependencies = [
"bcm2837 2.5.1 (git+https://github.com/rcore-os/bcm2837)",
"bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator?rev=03bd990)",
"bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)",
"bitvec 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"buddy_system_allocator 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
@ -717,7 +717,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a165d606cf084741d4ac3a28fb6e9b1eb0bd31f6cd999098cfddb0b2ab381dc0"
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator?rev=03bd990)" = "<none>"
"checksum bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)" = "<none>"
"checksum bitvec 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1fe4300c1d7a9ea6f3e3f39c10b39862bb79e1175c0572b6b49539a30e5562f5"
"checksum buddy_system_allocator 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9e953b958d83e13a44b1ead5b6aaa2a5f854bd5170239a66b606e030a14d018f"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"

View File

@ -9,6 +9,12 @@ pub unsafe fn init_external_interrupt() {
const HART0_S_MODE_INTERRUPT_ENABLES: *mut u32 = phys_to_virt(0x0C00_2080) as *mut u32;
const SERIAL: u32 = 0xa;
HART0_S_MODE_INTERRUPT_ENABLES.write_volatile(1 << SERIAL);
const SERIAL_PRIO: *mut u32 = phys_to_virt(0x0C000000 + (SERIAL as usize) * 4) as *mut u32;
SERIAL_PRIO.write_volatile(7); // QEMU: priority[irq] <- value & 0x7, hence the 7 here.
const HART0_S_MODE_PRIO_THRESH: *mut u32 = phys_to_virt(0x0C00_0000 + 0x20_1000) as *mut u32;
HART0_S_MODE_PRIO_THRESH.write_volatile(0); // Permits everything
}
pub unsafe fn enable_serial_interrupt() {

View File

@ -1,5 +1,5 @@
pub use crate::arch::paging::PageTableImpl;
use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt, virt_to_phys};
use crate::memory::{alloc_frame_contiguous, dealloc_frame, phys_to_virt, virt_to_phys};
use isomorphic_drivers::provider;
use rcore_memory::PAGE_SIZE;
@ -24,13 +24,7 @@ impl provider::Provider for Provider {
#[no_mangle]
extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {
// TODO: allocate continuous pages
let mut paddr = alloc_frame().unwrap();
for _ in 1..pages {
let paddr_new = alloc_frame().unwrap();
assert_eq!(paddr - PAGE_SIZE, paddr_new);
paddr = paddr_new;
}
let paddr = alloc_frame_contiguous(pages, 0).unwrap();
trace!("alloc DMA: paddr={:#x}, pages={}", paddr, pages);
paddr
}

View File

@ -82,6 +82,16 @@ impl FrameAllocator for GlobalFrameAlloc {
ret
// TODO: try to swap out when alloc failed
}
fn alloc_contiguous(&self, size: usize, align_log2: usize) -> Option<PhysAddr> {
// get the real address of the alloc frame
let ret = FRAME_ALLOCATOR
.lock()
.alloc_contiguous(size, align_log2)
.map(|id| id * PAGE_SIZE + MEMORY_OFFSET);
trace!("Allocate frame: {:x?}", ret);
ret
// TODO: try to swap out when alloc failed
}
fn dealloc(&self, target: usize) {
trace!("Deallocate frame: {:x}", target);
FRAME_ALLOCATOR
@ -96,6 +106,9 @@ pub fn alloc_frame() -> Option<usize> {
pub fn dealloc_frame(target: usize) {
GlobalFrameAlloc.dealloc(target);
}
pub fn alloc_frame_contiguous(size: usize, align_log2: usize) -> Option<usize> {
GlobalFrameAlloc.alloc_contiguous(size, align_log2)
}
pub struct KernelStack(usize);
const KSTACK_SIZE: usize = 0x4000; //16KB