<commit_before>#![feature(compiler_builtins_lib, lang_items, asm, pointer_methods)]
#![feature(core_intrinsics)]
#![feature(const_fn)]
#![feature(alloc, allocator_api)]
#![feature(global_allocator)]
#![feature(decl_macro)]

#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate alloc;
extern crate slab_allocator;
extern crate spin;
extern crate stack_vec;
extern crate volatile;

#[macro_use]
extern crate log;

extern crate fat32;

#[macro_use]
#[cfg(not(test))]
pub mod print;

//#[cfg(not(test))]
//pub mod console;
pub mod externs;
#[cfg(not(test))]
pub mod panic;

#[cfg(not(test))]
pub mod util;

#[cfg(not(test))]
pub mod exception;
#[cfg(not(test))]
pub mod mmu;

#[cfg(not(test))]
pub mod pi;
#[cfg(not(test))]
pub mod fb;
#[cfg(not(test))]
pub mod shell;
//pub mod sd;
pub mod sdn;
pub mod gles;


pub mod fs;


pub mod allocator;

use slab_allocator::LockedHeap;
use alloc::*;

#[cfg(not(test))]
#[global_allocator]
static mut ALLOCATOR: LockedHeap = LockedHeap::empty();

const BINARY_START_ADDR: usize = 0x8_0000; // 512kb

const ADDR_1MB: usize   = 0x0010_0000;
const ADDR_2MB: usize   = 0x0020_0000;
const ADDR_4MB: usize   = 0x0040_0000;
const ADDR_8MB: usize   = 0x0080_0000;
const ADDR_16MB: usize  = 0x0100_0000;
const ADDR_32MB: usize  = 0x0200_0000;
const ADDR_64MB: usize  = 0x0400_0000;
const ADDR_128MB: usize = 0x0800_0000;
const ADDR_256MB: usize = 0x1000_0000;
const ADDR_512MB: usize = 0x2000_0000;
const ADDR_1GB: usize   = 0x4000_0000;
const ADDR_2GB: usize   = 0x8000_0000;

#[cfg(not(test))]
pub fn init_heap() {
    // TODO why?
    let heap_start = 0x0F00_0000;
    let heap_end =   0x1000_0000;
    let heap_size = heap_end - heap_start;
    unsafe {
        ALLOCATOR.init(heap_start, heap_size);
    }
}

#[no_mangle]
#[inline(never)]
#[cfg(not(test))]
pub extern "C" fn kernel_main() -> ! {
    init_heap();

    pi::uart0::Uart0::new().initialize();

    kprintln!("      .  ");
    kprintln!("    < 0 >");
    kprintln!("    ./ \\.");
    kprintln!("");

    unsafe {
        let f: u32 = (1 << 0) | (1 << 1) | (1 << 2);
        asm!("msr cntv_ctl_el0, $0" : : "r"(f) : : "volatile");
    }

    let s = String::from("fucking string!");

    kprintln!("Hello Rust Kernel world! 0x{:X} {}", 0xDEAD, s);


    kprintln!("init fs");
    let fs = fs::FileSystem::uninitialized();
    fs.initialize();

    {<commit_msg>fix src/kmain.rs<commit_after>#![feature(compiler_builtins_lib, lang_items, asm, pointer_methods)]
#![feature(core_intrinsics)]
#![feature(const_fn)]
#![feature(alloc, allocator_api)]
#![feature(global_allocator)]
#![feature(decl_macro)]

#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate alloc;
extern crate slab_allocator;
extern crate spin;
extern crate stack_vec;
extern crate volatile;

#[macro_use]
extern crate log;

extern crate fat32;

#[macro_use]
#[cfg(not(test))]
pub mod print;

//#[cfg(not(test))]
//pub mod console;
pub mod externs;
#[cfg(not(test))]
pub mod panic;

#[cfg(not(test))]
pub mod util;

#[cfg(not(test))]
pub mod exception;
#[cfg(not(test))]
pub mod mmu;

#[cfg(not(test))]
pub mod pi;
#[cfg(not(test))]
pub mod fb;
#[cfg(not(test))]
pub mod shell;
//pub mod sd;
pub mod sdn;
pub mod gles;


pub mod fs;


pub mod allocator;

use slab_allocator::LockedHeap;
use alloc::*;

#[cfg(not(test))]
#[global_allocator]
static mut ALLOCATOR: LockedHeap = LockedHeap::empty();

const BINARY_START_ADDR: usize = 0x8_0000; // 512kb

const ADDR_1MB: usize   = 0x0010_0000;
const ADDR_2MB: usize   = 0x0020_0000;
const ADDR_4MB: usize   = 0x0040_0000;
const ADDR_8MB: usize   = 0x0080_0000;
const ADDR_16MB: usize  = 0x0100_0000;
const ADDR_32MB: usize  = 0x0200_0000;
const ADDR_64MB: usize  = 0x0400_0000;
const ADDR_128MB: usize = 0x0800_0000;
const ADDR_256MB: usize = 0x1000_0000;
const ADDR_512MB: usize = 0x2000_0000;
const ADDR_1GB: usize   = 0x4000_0000;
const ADDR_2GB: usize   = 0x8000_0000;

static FILE_SYSTEM: fs::FileSystem = fs::FileSystem::uninitialized();

#[cfg(not(test))]
pub fn init_heap() {
    // TODO why?
    let heap_start = 0x0F00_0000;
    let heap_end =   0x1000_0000;
    let heap_size = heap_end - heap_start;
    unsafe {
        ALLOCATOR.init(heap_start, heap_size);
    }
}

#[no_mangle]
#[inline(never)]
#[cfg(not(test))]
pub extern "C" fn kernel_main() -> ! {
    init_heap();

    pi::uart0::Uart0::new().initialize();

    kprintln!("      .  ");
    kprintln!("    < 0 >");
    kprintln!("    ./ \\.");
    kprintln!("");

    unsafe {
        let f: u32 = (1 << 0) | (1 << 1) | (1 << 2);
        asm!("msr cntv_ctl_el0, $0" : : "r"(f) : : "volatile");
    }

    let s = String::from("fucking string!");

    kprintln!("Hello Rust Kernel world! 0x{:X} {}", 0xDEAD, s);


    kprintln!("init fs");
    FILE_SYSTEM.initialize();

    {
{'fraction_non_alphanumeric': 0.1642542479546885, 'fraction_numerical': 0.07216278581917349, 'mean_word_length': 4.274336283185841, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6761205', 'n_tokens_mistral': 2146, 'n_tokens_neox': 1939, 'n_words': 446}