Skip to content

Commit

Permalink
Bridge commit to rectify rebase-merge differences
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinaboos committed Sep 1, 2020
1 parent c0ed269 commit 74f90fd
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 559 deletions.
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,19 @@ endif ## BYPASS_XARGO_CHECK
###################################################################################################
### This section has QEMU arguments and configuration
###################################################################################################

QEMU_MEMORY ?= 512M
QEMU_FLAGS := -cdrom $(iso) -no-reboot -no-shutdown -s -m $(QEMU_MEMORY) -serial stdio
## QEMU_FLAGS += -cpu Haswell
## the most recent CPU model supported by QEMU 2.5.0
QEMU_FLAGS += -cpu Broadwell
## multicore
QEMU_FLAGS += -smp 4

## basic networking with a standard e1000 ethernet card
#QEMU_FLAGS += -netdev user,id=u1 -device e1000,netdev=u1,mac=11:22:33:44:55:66
#QEMU_FLAGS += -object filter-dump,id=f1,netdev=u1,file=netdump.pcap

#QEMU_FLAGS += -net nic,vlan=0,model=e1000,macaddr=00:0b:82:01:fc:42 -net dump,file=netdump.pcap
QEMU_FLAGS += -net nic,vlan=1,model=e1000,macaddr=00:0b:82:01:fc:42 -net user,vlan=1 -net dump,file=netdump.pcap
#QEMU_FLAGS += -net nic,vlan=1,model=e1000 -net user,vlan=1 -net dump,file=netdump.pcap

#drive and devices commands from http://forum.osdev.org/viewtopic.php?f=1&t=26483 to use sata emulation
## drive and devices commands from http://forum.osdev.org/viewtopic.php?f=1&t=26483 to use sata emulation
QEMU_FLAGS += -drive format=raw,file=random_data2.img,if=none,id=mydisk -device ide-hd,drive=mydisk,bus=ide.0,serial=4696886396

ifeq ($(int),yes)
Expand Down
8 changes: 7 additions & 1 deletion bochsrc.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# configuration file generated by Bochs
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=0, iodebug=1
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=0, iodebug=1, e1000=1
config_interface: textconfig
display_library: x
memory: host=256, guest=256
Expand Down Expand Up @@ -41,6 +41,12 @@ debug: action=ignore
#debug: action=ignore, cpu1=report


## e1000 settings to match QEMU
#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=slirp.conf
#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=linux, ethdev=eth0
e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=vnet, ethdev=./temp


keyboard: type=mf, serial_delay=250, paste_delay=100000, keymap=
#user_shortcut: keys=none
mouse: enabled=0, type=ps2, toggle=ctrl+mbutton
Expand Down
7 changes: 3 additions & 4 deletions kernel/apic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,9 @@ pub fn broadcast_tlb_shootdown(vaddr: VirtualAddress) {

/// Handles a TLB shootdown ipi by flushing the VirtualAddress
/// currently stored in TLB_SHOOTDOWN_IPI_VIRT_ADDR.
pub fn handle_tlb_shootdown_ipi() {
let apic_id = get_my_apic_id().unwrap_or(0xFF);
let vaddr = TLB_SHOOTDOWN_IPI_VIRT_ADDR.load(Ordering::Acquire);

/// DO not invoke this directly, it will be called by an IPI interrupt handler.
pub fn handle_tlb_shootdown_ipi(vaddr: VirtualAddress) {
// let apic_id = get_my_apic_id().unwrap_or(0xFF);
// trace!("handle_tlb_shootdown_ipi(): (AP {}) flushing vaddr {:#X}", apic_id, vaddr);

x86_64::instructions::tlb::flush(x86_64::VirtualAddress(vaddr));
Expand Down
168 changes: 65 additions & 103 deletions kernel/captain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@
#![feature(used)]
#![feature(core_intrinsics)]

extern crate alloc;

#[macro_use] extern crate alloc;
#[macro_use] extern crate log;


extern crate kernel_config; // our configuration options, just a set of const definitions.
extern crate irq_safety; // for irq-safe locking and interrupt utilities
extern crate dfqueue; // decoupled, fault-tolerant queue

#[cfg(feature = "loadable")]
#[macro_use] extern crate vga_buffer;
#[cfg(not(feature = "loadable"))]
extern crate vga_buffer;

extern crate console_types; // a temporary way to use console types
extern crate console_types; // a temporary way to use console types
extern crate logger;
extern crate memory; // the virtual memory subsystem
extern crate apic;
Expand All @@ -39,68 +35,19 @@ extern crate acpi;
extern crate driver_init;
extern crate e1000;
extern crate window_manager;

extern crate scheduler;



#[cfg(feature = "loadable")]
extern crate console;
#[cfg(not(feature = "loadable"))]
#[macro_use] extern crate console;


#[cfg(target_feature = "sse2")]
extern crate simd_test;

// temporarily moving these macros here because I'm not sure if/how we can load macros from a crate at runtime
/// calls print!() with an extra "\n" at the end.
#[macro_export]
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}

/// The main printing macro, which simply pushes an output event to the console's event queue.
/// This ensures that only one thread (the console) ever accesses the UI, which right now is just the VGA buffer.
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
use core::fmt::Write;
use alloc::String;
let mut s: String = String::new();
match write!(&mut s, $($arg)*) {
Ok(_) => { }
Err(e) => error!("print!(): writing to String failed, error: {}", e),
}

#[cfg(feature = "loadable")] {
if let Some(section) = ::mod_mgmt::metadata::get_symbol("console::print_to_console").upgrade() {
type PrintFuncSignature = fn(String) -> Result<(), &'static str>;

if let Some(mp) = section.mapped_pages() {
let mut space = 0; // this must persist throughout the print_func being called
let print_func: Result<&PrintFuncSignature, &'static str> = mp.as_func(section.mapped_pages_offset(), &mut space);
match print_func {
Ok(func) => {
let _ = func(s.clone());
}
Err(e) => {
error!("print!(): couldn't get print_func from the section's mapped_pages, error: {}", e);
}
}
}
else {
error!("print!(): couldn't get section's mapped_pages");
}
}
else {
// if console crate hasn't been loaded yet, write to the raw VGA buffer instead
error!("print!(): no \"console::print_to_console\" symbol. Printing: {}", s);
println_raw!("print!(): couldn't get \"console::print_to_console\" symbol! Tried to print: {}", s);
}
}
#[cfg(not(feature = "loadable"))]
{
let _ = console::print_to_console(s);
}
});
}


// Here, we add pub use statements for any function or data that we want to export from the nano_core
// and make visible/accessible to other modules that depend on nano_core functions.
Expand All @@ -117,15 +64,27 @@ use irq_safety::{MutexIrqSafe, enable_interrupts};
#[cfg(feature = "loadable")] use task::TaskRef;
#[cfg(feature = "loadable")] use memory::{VirtualAddress, ModuleArea};
#[cfg(feature = "loadable")] use console_types::ConsoleEvent;
#[cfg(feature = "loadable")] use mouse_console_type::MouseConsoleEvent;
#[cfg(feature = "loadable")] use dfqueue::DFQueueProducer;
#[cfg(feature = "loadable")] use acpi::madt::MadtIter;



/// the callback use in the logger crate for mirroring log functions to the console
pub fn mirror_to_vga_cb(_color: logger::LogColor, prefix: &'static str, args: fmt::Arguments) {
println!("{} {}", prefix, args);
#[cfg(feature = "loadable")]
{
let mut space = 0;
if let Some(section) = mod_mgmt::metadata::get_symbol("console::print_to_console").upgrade() {
if let Some(func) = section.mapped_pages().and_then(|mp| mp.as_func::<fn(String)>(section.mapped_pages_offset(), &mut space).ok())
{
let _ = func(format!("{} {}", prefix, args));
}
}
}
#[cfg(not(feature = "loadable"))]
{
println!("{} {}", prefix, args);
}
}


Expand All @@ -139,7 +98,7 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
ap_start_realmode_begin: usize, ap_start_realmode_end: usize)
-> Result<(), &'static str>
{

#[cfg(feature = "loadable")]
{
let mut kernel_mmi = kernel_mmi_ref.lock();
Expand All @@ -160,15 +119,20 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
let _tsc_freq = {
#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("tsc::get_tsc_frequency").upgrade().ok_or("no symbol: tsc::get_tsc_frequency")?.virt_addr();
let func: fn() -> Result<u64, &'static str> = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("tsc::get_tsc_frequency").upgrade().ok_or("no symbol: tsc::get_tsc_frequency")?;
let mut space = 0;
let func: & fn() -> Result<u64, &'static str> =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"tsc::get_tsc_frequency\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func()?
}
#[cfg(not(feature = "loadable"))]
{
tsc::get_tsc_frequency()?
}
};
// info!("TSC frequency calculated: {}", _tsc_freq);


// load the rest of our crate dependencies
Expand All @@ -179,12 +143,6 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
mod_mgmt::load_kernel_crate(memory::get_module("__k_keycodes_ascii") .ok_or("couldn't find __k_keycodes_ascii module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_console_types") .ok_or("couldn't find __k_console_types module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_keyboard") .ok_or("couldn't find __k_keyboard module")?, &mut kernel_mmi, false)?;

mod_mgmt::load_kernel_crate(memory::get_module("__k_mouse_data") .ok_or("couldn't find __k_mouse_data module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_mouse_console_type") .ok_or("couldn't find __k_mouse_console_type module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_mouse") .ok_or("couldn't find __k_mouse module")?, &mut kernel_mmi, false)?;
debug!("Here is the Bowen's mouse stuffs, I just want to see whether my stuffs are acutually being called \n\n\n\n\n\n\n\n\n\n\n\
\n I hope tey are called \n\n\n\n\n\n");

mod_mgmt::load_kernel_crate(memory::get_module("__k_spin") .ok_or("couldn't find __k_spin module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_pci") .ok_or("couldn't find __k_pci module")?, &mut kernel_mmi, false)?;
Expand All @@ -203,7 +161,6 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
mod_mgmt::load_kernel_crate(memory::get_module("__k_interrupts") .ok_or("couldn't find __k_interrupts module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_vga_buffer") .ok_or("couldn't find __k_vga_buffer module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_console") .ok_or("couldn't find __k_console module")?, &mut kernel_mmi, false)?;
mod_mgmt::load_kernel_crate(memory::get_module("__k_mouse_console") .ok_or("couldn't find __k_mouse_console module")?, &mut kernel_mmi, false)?;


mod_mgmt::load_kernel_crate(memory::get_module("__k_dbus") .ok_or("couldn't find __k_dbus module")?, &mut kernel_mmi, false)?;
Expand All @@ -228,8 +185,12 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,

#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("driver_init::early_init").upgrade().ok_or("no symbol: driver_init::early_init")?.virt_addr();
let func: fn(&mut memory::MemoryManagementInfo) -> Result<MadtIter, &'static str> = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("driver_init::early_init").upgrade().ok_or("no symbol: driver_init::early_init")?;
let mut space = 0;
let func: & fn(&mut memory::MemoryManagementInfo) -> Result<MadtIter, &'static str> =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"driver_init::early_init\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func(&mut kernel_mmi)?
}
#[cfg(not(feature = "loadable"))]
Expand All @@ -251,8 +212,12 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,

#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("interrupts::init").upgrade().ok_or("no symbol: interrupts::init")?.virt_addr();
let func: fn(usize, usize) -> Result<(), &'static str> = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("interrupts::init").upgrade().ok_or("no symbol: interrupts::init")?;
let mut space = 0;
let func: & fn(usize, usize) -> Result<(), &'static str> =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"interrupts::init\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func(double_fault_stack.top_unusable(), privilege_stack.top_unusable())?;
}
#[cfg(not(feature = "loadable"))]
Expand All @@ -265,8 +230,12 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
// interrupts::init_handlers_pic();
#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("interrupts::init_handlers_apic").upgrade().ok_or("no symbol: interrupts::init_handlers_apic")?.virt_addr();
let func: fn() = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("interrupts::init_handlers_apic").upgrade().ok_or("no symbol: interrupts::init_handlers_apic")?;
let mut space = 0;
let func: & fn() =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"interrupts::init_handlers_apic\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func();
}
#[cfg(not(feature = "loadable"))]
Expand All @@ -277,8 +246,12 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
// initialize the syscall subsystem
#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("syscall::init").upgrade().ok_or("no symbol: syscall::init")?.virt_addr();
let func: fn(usize) = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("syscall::init").upgrade().ok_or("no symbol: syscall::init")?;
let mut space = 0;
let func: & fn(usize) =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"syscall::init\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func(syscall_stack.top_usable());
}
#[cfg(not(feature = "loadable"))]
Expand All @@ -290,8 +263,12 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
let bsp_apic_id = {
#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("apic::get_bsp_id").upgrade().ok_or("no symbol: apic::get_bsp_id")?.virt_addr();
let func: fn() -> Option<u8> = unsafe { ::core::mem::transmute(vaddr) };
let section = mod_mgmt::metadata::get_symbol("apic::get_bsp_id").upgrade().ok_or("no symbol: apic::get_bsp_id")?;
let mut space = 0;
let func: & fn() -> Option<u8> =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"apic::get_bsp_id\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;
func().ok_or("captain::init(): Coudln't get BSP's apic_id!")?
}
#[cfg(not(feature = "loadable"))]
Expand Down Expand Up @@ -337,6 +314,7 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
};



// initialize the rest of our drivers
#[cfg(feature = "loadable")]
{
Expand All @@ -345,12 +323,9 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
let func: & fn(DFQueueProducer<ConsoleEvent>) -> Result<(), &'static str> =
section.mapped_pages()
.ok_or("Couldn't get section's mapped_pages for \"driver_init::init\"")?
.as_func(section.mapped_pages_offset(), &mut space)?;

.as_func(section.mapped_pages_offset(), &mut space)?;
func(console_queue_producer)?;
}


#[cfg(not(feature = "loadable"))]
{
driver_init::init(console_queue_producer)?;
Expand Down Expand Up @@ -416,7 +391,7 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
#[cfg(not(feature = "loadable"))]
{
use e1000::test_nic_driver::test_nic_driver;
spawn::spawn_kthread(test_nic_driver, None, String::from("test_nic_driver"), None).unwrap();
spawn::spawn_kthread(test_nic_driver, None, String::from("test_nic_driver"), None)?;
}
}

Expand Down Expand Up @@ -512,7 +487,7 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,
.as_func(section.mapped_pages_offset(), &mut space)?;
func(module, None)?;
}
#[cfg(not(feature = "loadable"))]
#[cfg(not(feature = "loadable"))]
{
spawn::spawn_userspace(module, None)?;
}
Expand Down Expand Up @@ -563,19 +538,6 @@ pub fn init(kernel_mmi_ref: Arc<MutexIrqSafe<MemoryManagementInfo>>,


loop {

#[cfg(feature = "loadable")]
{
let vaddr = mod_mgmt::metadata::get_symbol("scheduler::schedule").upgrade().ok_or("no symbol: scheduler::schedule")?.virt_addr();
let func: fn() = unsafe { ::core::mem::transmute(vaddr) };
func();
}
#[cfg(not(feature = "loadable"))]
{
scheduler::schedule();
}


spin_loop_hint();
// TODO: exit this loop cleanly upon a shutdown signal
}
Expand Down
Loading

0 comments on commit 74f90fd

Please sign in to comment.