~kameliya/syso

ref: e1e59ca17a1649d2102744770310c62b671e3ee3 syso/src/mem.rs -rw-r--r-- 1.6 KiB
e1e59ca1 — Yuki Izumi Add placement allocator until we get a heap 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use core::fmt::Write;
use collections::{BTreeSet, Vec};
use multiboot2::BootInformation;
use hole_list_allocator;

use debug::DEBUG;

pub fn init(multiboot: &BootInformation) {
    let memory_map_tag = multiboot.memory_map_tag().expect("Memory map tag required");
    let elf_sections_tag = multiboot.elf_sections_tag().expect("ELF sections tag required");

    let kernel_end = elf_sections_tag.sections().map(|s| s.addr + s.size)
        .max().unwrap() as usize;
    let multiboot_end = multiboot.end_address();

    let placement_start = if kernel_end > multiboot_end { kernel_end } else { multiboot_end };
    unsafe { hole_list_allocator::init_placement(placement_start) }

    /*
    let upper_memory = memory_map_tag.memory_areas().map(|a| a.base_addr + a.length)
        .max().unwrap() as usize;

    let frame_count = upper_memory / 0x1000;
    let mut frames: Vec<u8> = vec![0; frame_count / 8 + 1];


    unsafe { hole_list_allocator::init_heap(heap_start, 0x10000) }
    unsafe { write!(DEBUG, "HEAP created at 0x{:x}\n", heap_start).unwrap() }

    {
        let mut usable_memory: BTreeSet<Extent> = BTreeSet::new();

        for area in memory_map_tag.memory_areas() {
            usable_memory.insert(Extent::new(area.base_addr as usize, area.length as usize));
        }

        //remove_extents(&usable_memory, kernel_start, kernel_end);
        //remove_extents(&usable_memory, multiboot_start, multiboot_end);
        unsafe { write!(DEBUG, "Upper memory: 0x{:x}\n", upper_memory).unwrap() }
        unsafe { write!(DEBUG, "Usable memory: {:?}\n", usable_memory).unwrap() }
    }
    */
}