implement mem api and fixes
This commit is contained in:
parent
9ce30d2941
commit
b013e95f2c
9 changed files with 393 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -220,6 +220,7 @@ dependencies = [
|
||||||
"microlang",
|
"microlang",
|
||||||
"pic8259",
|
"pic8259",
|
||||||
"spin",
|
"spin",
|
||||||
|
"spinning_top",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ spin = "0.9.8"
|
||||||
x86_64 = "0.15.1"
|
x86_64 = "0.15.1"
|
||||||
microlang = { git = "https://git.barnulf.net/mb/microlang.git" }
|
microlang = { git = "https://git.barnulf.net/mb/microlang.git" }
|
||||||
blinkcast = "0.2.0"
|
blinkcast = "0.2.0"
|
||||||
|
spinning_top = "0.2.5"
|
||||||
|
|
||||||
# artefact configuration
|
# artefact configuration
|
||||||
|
|
||||||
|
|
303
data/keymaps/azerty.conf
Normal file
303
data/keymaps/azerty.conf
Normal file
|
@ -0,0 +1,303 @@
|
||||||
|
# control altgr keycode 111 = Boot
|
||||||
|
# control altgr keycode 83 = Boot
|
||||||
|
# control shift keycode 59 = F37
|
||||||
|
#keycode 99 = VoidSymbol # SysRq/PrintScrn
|
||||||
|
alt keycode 1 = Meta_Escape
|
||||||
|
alt keycode 10 = Meta_nine
|
||||||
|
alt keycode 100 = Compose
|
||||||
|
alt keycode 103 = KeyboardSignal
|
||||||
|
alt keycode 105 = Decr_Console
|
||||||
|
alt keycode 106 = Incr_Console
|
||||||
|
alt keycode 11 = Meta_zero
|
||||||
|
alt keycode 12 = Meta_minus
|
||||||
|
alt keycode 13 = Meta_equal
|
||||||
|
alt keycode 14 = Meta_Delete
|
||||||
|
alt keycode 15 = Meta_Tab
|
||||||
|
alt keycode 2 = Meta_one
|
||||||
|
alt keycode 26 = Meta_bracketleft
|
||||||
|
alt keycode 27 = Meta_bracketright
|
||||||
|
alt keycode 28 = Meta_Control_m
|
||||||
|
alt keycode 3 = Meta_two
|
||||||
|
alt keycode 4 = Meta_three
|
||||||
|
alt keycode 40 = Meta_apostrophe
|
||||||
|
alt keycode 41 = Meta_grave
|
||||||
|
alt keycode 43 = Meta_backslash
|
||||||
|
alt keycode 5 = Meta_four
|
||||||
|
alt keycode 51 = Meta_comma
|
||||||
|
alt keycode 52 = Meta_period
|
||||||
|
alt keycode 53 = Meta_slash
|
||||||
|
alt keycode 57 = Meta_space
|
||||||
|
alt keycode 59 = Console_1
|
||||||
|
alt keycode 6 = Meta_five
|
||||||
|
alt keycode 60 = Console_2
|
||||||
|
alt keycode 61 = Console_3
|
||||||
|
alt keycode 62 = Console_4
|
||||||
|
alt keycode 63 = Console_5
|
||||||
|
alt keycode 64 = Console_6
|
||||||
|
alt keycode 65 = Console_7
|
||||||
|
alt keycode 66 = Console_8
|
||||||
|
alt keycode 67 = Console_9
|
||||||
|
alt keycode 68 = Console_10
|
||||||
|
alt keycode 7 = Meta_six
|
||||||
|
alt keycode 70 = Scroll_Lock
|
||||||
|
alt keycode 70 = Show_Registers
|
||||||
|
alt keycode 71 = Ascii_7
|
||||||
|
alt keycode 72 = Ascii_8
|
||||||
|
alt keycode 73 = Ascii_9
|
||||||
|
alt keycode 75 = Ascii_4
|
||||||
|
alt keycode 76 = Ascii_5
|
||||||
|
alt keycode 77 = Ascii_6
|
||||||
|
alt keycode 79 = Ascii_1
|
||||||
|
alt keycode 8 = Meta_seven
|
||||||
|
alt keycode 80 = Ascii_2
|
||||||
|
alt keycode 81 = Ascii_3
|
||||||
|
alt keycode 82 = Ascii_0
|
||||||
|
alt keycode 86 = Meta_less
|
||||||
|
alt keycode 87 = Console_11
|
||||||
|
alt keycode 88 = Console_12
|
||||||
|
alt keycode 9 = Meta_eight
|
||||||
|
alt keycode 99 = Control_backslash
|
||||||
|
altgr keycode 10 = asciicircum
|
||||||
|
altgr keycode 10 = asciicircum
|
||||||
|
altgr keycode 102 = Find
|
||||||
|
altgr keycode 104 = Prior
|
||||||
|
altgr keycode 107 = Select
|
||||||
|
altgr keycode 109 = Next
|
||||||
|
altgr keycode 11 = at
|
||||||
|
altgr keycode 11 = at
|
||||||
|
altgr keycode 119 = Pause # Pause
|
||||||
|
altgr keycode 12 = bracketright
|
||||||
|
altgr keycode 12 = bracketright
|
||||||
|
altgr keycode 13 = braceright
|
||||||
|
altgr keycode 13 = braceright
|
||||||
|
altgr keycode 27 = asciitilde
|
||||||
|
altgr keycode 27 = asciitilde
|
||||||
|
altgr keycode 3 = asciitilde
|
||||||
|
altgr keycode 3 = asciitilde
|
||||||
|
altgr keycode 4 = numbersign
|
||||||
|
altgr keycode 4 = numbersign
|
||||||
|
altgr keycode 5 = braceleft
|
||||||
|
altgr keycode 5 = braceleft
|
||||||
|
altgr keycode 55 = Hex_C
|
||||||
|
altgr keycode 6 = bracketleft
|
||||||
|
altgr keycode 6 = bracketleft
|
||||||
|
altgr keycode 69 = Hex_A
|
||||||
|
altgr keycode 7 = bar
|
||||||
|
altgr keycode 7 = bar
|
||||||
|
altgr keycode 70 = Show_Registers
|
||||||
|
altgr keycode 71 = Hex_7
|
||||||
|
altgr keycode 72 = Hex_8
|
||||||
|
altgr keycode 73 = Hex_9
|
||||||
|
altgr keycode 74 = Hex_D
|
||||||
|
altgr keycode 75 = Hex_4
|
||||||
|
altgr keycode 76 = Hex_5
|
||||||
|
altgr keycode 77 = Hex_6
|
||||||
|
altgr keycode 78 = Hex_E
|
||||||
|
altgr keycode 79 = Hex_1
|
||||||
|
altgr keycode 8 = grave
|
||||||
|
altgr keycode 8 = grave
|
||||||
|
altgr keycode 80 = Hex_2
|
||||||
|
altgr keycode 81 = Hex_3
|
||||||
|
altgr keycode 82 = Hex_0
|
||||||
|
altgr keycode 83 = or KP_Comma
|
||||||
|
altgr keycode 86 = bar
|
||||||
|
altgr keycode 86 = bar
|
||||||
|
altgr keycode 9 = backslash
|
||||||
|
altgr keycode 9 = backslash
|
||||||
|
altgr keycode 96 = Hex_F
|
||||||
|
altgr keycode 98 = Hex_B
|
||||||
|
altgr keycode 99 = Compose # PrintScrn
|
||||||
|
control alt keycode 111 = Boot
|
||||||
|
control alt keycode 59 = Console_1
|
||||||
|
control alt keycode 60 = Console_2
|
||||||
|
control alt keycode 61 = Console_3
|
||||||
|
control alt keycode 62 = Console_4
|
||||||
|
control alt keycode 63 = Console_5
|
||||||
|
control alt keycode 64 = Console_6
|
||||||
|
control alt keycode 65 = Console_7
|
||||||
|
control alt keycode 66 = Console_8
|
||||||
|
control alt keycode 67 = Console_9
|
||||||
|
control alt keycode 68 = Console_10
|
||||||
|
control alt keycode 83 = Boot
|
||||||
|
control alt keycode 87 = Console_11
|
||||||
|
control alt keycode 88 = Console_12
|
||||||
|
control altgr keycode 111 = Boot
|
||||||
|
control altgr keycode 83 = Boot
|
||||||
|
control keycode 12 = Control_underscore
|
||||||
|
control keycode 26 = Escape
|
||||||
|
control keycode 27 = Control_bracketright
|
||||||
|
control keycode 3 = nul
|
||||||
|
control keycode 4 = Escape
|
||||||
|
control keycode 40 = Control_g
|
||||||
|
control keycode 41 = nul
|
||||||
|
control keycode 43 = Control_backslash
|
||||||
|
control keycode 5 = Control_backslash
|
||||||
|
control keycode 53 = Delete
|
||||||
|
control keycode 57 = nul
|
||||||
|
control keycode 59 = F25
|
||||||
|
control keycode 6 = Control_bracketright
|
||||||
|
control keycode 60 = F26
|
||||||
|
control keycode 61 = F27
|
||||||
|
control keycode 62 = F28
|
||||||
|
control keycode 63 = F29
|
||||||
|
control keycode 64 = F30
|
||||||
|
control keycode 65 = F31
|
||||||
|
control keycode 66 = F32
|
||||||
|
control keycode 67 = F33
|
||||||
|
control keycode 68 = F34
|
||||||
|
control keycode 7 = Control_asciicircum
|
||||||
|
control keycode 70 = Show_State
|
||||||
|
control keycode 8 = Control_underscore
|
||||||
|
control keycode 87 = F35
|
||||||
|
control keycode 88 = F36
|
||||||
|
control keycode 9 = Delete
|
||||||
|
control keycode 99 = Control_backslash
|
||||||
|
keycode 1 = Escape
|
||||||
|
keycode 10 = slash
|
||||||
|
keycode 100 = AltGr
|
||||||
|
keycode 101 = Break
|
||||||
|
keycode 101 = Break # Ctrl+Break/Pause
|
||||||
|
keycode 102 = Home # Find
|
||||||
|
keycode 103 = Up
|
||||||
|
keycode 104 = PageUp # Prior
|
||||||
|
keycode 105 = Left
|
||||||
|
keycode 106 = Right
|
||||||
|
keycode 107 = End # Select
|
||||||
|
keycode 108 = Down
|
||||||
|
keycode 109 = PageDown # Next
|
||||||
|
keycode 11 = at
|
||||||
|
keycode 110 = Insert
|
||||||
|
keycode 111 = Remove
|
||||||
|
keycode 119 = Pause # Break/Pause
|
||||||
|
keycode 12 = parenright
|
||||||
|
keycode 13 = equal
|
||||||
|
keycode 14 = Delete
|
||||||
|
keycode 15 = Tab
|
||||||
|
keycode 16 = a
|
||||||
|
keycode 17 = z
|
||||||
|
keycode 18 = e
|
||||||
|
keycode 19 = r
|
||||||
|
keycode 2 = ampersand
|
||||||
|
keycode 20 = t
|
||||||
|
keycode 21 = y
|
||||||
|
keycode 22 = u
|
||||||
|
keycode 23 = i
|
||||||
|
keycode 24 = o
|
||||||
|
keycode 25 = p
|
||||||
|
keycode 26 = asciicircum
|
||||||
|
keycode 27 = dollar
|
||||||
|
keycode 28 = Return
|
||||||
|
keycode 29 = Control
|
||||||
|
keycode 3 = braceleft
|
||||||
|
keycode 30 = q
|
||||||
|
keycode 31 = s
|
||||||
|
keycode 32 = d
|
||||||
|
keycode 33 = f
|
||||||
|
keycode 34 = g
|
||||||
|
keycode 35 = h
|
||||||
|
keycode 36 = j
|
||||||
|
keycode 37 = k
|
||||||
|
keycode 38 = l
|
||||||
|
keycode 39 = m
|
||||||
|
keycode 4 = quotedbl
|
||||||
|
keycode 40 = bar
|
||||||
|
keycode 41 = asterisk
|
||||||
|
keycode 42 = Shift
|
||||||
|
keycode 43 = asterisk
|
||||||
|
keycode 44 = w
|
||||||
|
keycode 45 = x
|
||||||
|
keycode 46 = c
|
||||||
|
keycode 47 = v
|
||||||
|
keycode 48 = b
|
||||||
|
keycode 49 = n
|
||||||
|
keycode 5 = apostrophe
|
||||||
|
keycode 50 = comma
|
||||||
|
keycode 51 = semicolon
|
||||||
|
keycode 52 = colon
|
||||||
|
keycode 53 = exclam
|
||||||
|
keycode 54 = Shift
|
||||||
|
keycode 55 = KP_Multiply
|
||||||
|
keycode 56 = Alt
|
||||||
|
keycode 57 = space
|
||||||
|
keycode 58 = Caps_Lock
|
||||||
|
keycode 59 = F1
|
||||||
|
keycode 6 = parenleft
|
||||||
|
keycode 60 = F2
|
||||||
|
keycode 61 = F3
|
||||||
|
keycode 62 = F4
|
||||||
|
keycode 63 = F5
|
||||||
|
keycode 64 = F6
|
||||||
|
keycode 65 = F7
|
||||||
|
keycode 66 = F8
|
||||||
|
keycode 67 = F9
|
||||||
|
keycode 68 = F10
|
||||||
|
keycode 69 = Num_Lock
|
||||||
|
keycode 7 = minus
|
||||||
|
keycode 70 = Scroll_Lock
|
||||||
|
keycode 71 = KP_7
|
||||||
|
keycode 72 = KP_8
|
||||||
|
keycode 73 = KP_9
|
||||||
|
keycode 74 = KP_Subtract
|
||||||
|
keycode 75 = KP_4
|
||||||
|
keycode 76 = KP_5
|
||||||
|
keycode 77 = KP_6
|
||||||
|
keycode 78 = KP_Add
|
||||||
|
keycode 79 = KP_1
|
||||||
|
keycode 8 = braceright
|
||||||
|
keycode 80 = KP_2
|
||||||
|
keycode 81 = KP_3
|
||||||
|
keycode 82 = KP_0
|
||||||
|
keycode 83 = KP_Period # or
|
||||||
|
keycode 84 = Last_Console
|
||||||
|
keycode 84 = Last_Console # Alt+SysRq/PrintScrn
|
||||||
|
keycode 86 = less
|
||||||
|
keycode 87 = F11
|
||||||
|
keycode 88 = F12
|
||||||
|
keycode 9 = underscore
|
||||||
|
keycode 96 = KP_Enter
|
||||||
|
keycode 97 = Control
|
||||||
|
keycode 98 = KP_Divide
|
||||||
|
keycode 99 = Compose # SysRq/PrintScrn
|
||||||
|
shift keycode 1 = Escape
|
||||||
|
shift keycode 10 = nine
|
||||||
|
shift keycode 101 = altgr
|
||||||
|
shift keycode 104 = Scroll_Backward
|
||||||
|
shift keycode 109 = Scroll_Forward
|
||||||
|
shift keycode 11 = zero
|
||||||
|
shift keycode 12 = bracketright
|
||||||
|
shift keycode 13 = plus
|
||||||
|
shift keycode 14 = Delete
|
||||||
|
shift keycode 15 = Meta_Tab
|
||||||
|
shift keycode 2 = one
|
||||||
|
shift keycode 26 = less
|
||||||
|
shift keycode 27 = greater
|
||||||
|
shift keycode 3 = two
|
||||||
|
shift keycode 4 = three
|
||||||
|
shift keycode 40 = percent
|
||||||
|
shift keycode 41 = asciitilde
|
||||||
|
shift keycode 43 = numbersign
|
||||||
|
shift keycode 5 = four
|
||||||
|
shift keycode 50 = question
|
||||||
|
shift keycode 51 = period
|
||||||
|
shift keycode 52 = slash
|
||||||
|
shift keycode 53 = backslash
|
||||||
|
shift keycode 57 = space
|
||||||
|
shift keycode 59 = F13
|
||||||
|
shift keycode 6 = five
|
||||||
|
shift keycode 60 = F14
|
||||||
|
shift keycode 61 = F15
|
||||||
|
shift keycode 62 = F16
|
||||||
|
shift keycode 63 = F17
|
||||||
|
shift keycode 64 = F18
|
||||||
|
shift keycode 65 = F19
|
||||||
|
shift keycode 66 = F20
|
||||||
|
shift keycode 67 = F21
|
||||||
|
shift keycode 68 = F22
|
||||||
|
shift keycode 7 = six
|
||||||
|
shift keycode 70 = Show_Memory
|
||||||
|
shift keycode 8 = seven
|
||||||
|
shift keycode 84 = altgr
|
||||||
|
shift keycode 86 = greater
|
||||||
|
shift keycode 87 = F23
|
||||||
|
shift keycode 88 = F24
|
||||||
|
shift keycode 9 = eight
|
|
@ -47,15 +47,17 @@ impl Console {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.vga.set_cursor_pos(self.cursor.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn correct(&mut self) {
|
pub fn correct(&mut self) {
|
||||||
self.cursor.set_col((self.cursor.col().max(1) - 1));
|
self.cursor.set_col(self.cursor.col().max(1) - 1);
|
||||||
self.vga.write_at(self.cursor.pos(), ' ');
|
self.vga.write_at(self.cursor.pos(), ' ');
|
||||||
|
self.vga.set_cursor_pos(self.cursor.pos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cursor {
|
pub struct Cursor {
|
||||||
line: usize,
|
line: usize,
|
||||||
column: usize,
|
column: usize,
|
||||||
width: usize,
|
width: usize,
|
||||||
|
@ -126,6 +128,6 @@ pub fn print_args(args: fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use x86_64::instructions::interrupts;
|
use x86_64::instructions::interrupts;
|
||||||
interrupts::without_interrupts(|| {
|
interrupts::without_interrupts(|| {
|
||||||
OUT.lock().write_fmt(args).unwrap();
|
out().write_fmt(args).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
||||||
|
use linked_list_allocator::{Heap, LockedHeap};
|
||||||
|
use spinning_top::{lock_api::MutexGuard, RawSpinlock};
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
registers::control::Cr3,
|
registers::control::Cr3,
|
||||||
structures::paging::{
|
structures::paging::{
|
||||||
|
@ -60,7 +62,7 @@ unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||||
pub const HEAP_SIZE: usize = 1_000 * 1024; // 1 MiB
|
pub const HEAP_SIZE: usize = 10_000 * 1024; // 10 MiB
|
||||||
|
|
||||||
pub fn init_heap(
|
pub fn init_heap(
|
||||||
mapper: &mut impl Mapper<Size4KiB>,
|
mapper: &mut impl Mapper<Size4KiB>,
|
||||||
|
@ -83,16 +85,18 @@ pub fn init_heap(
|
||||||
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { ALLOCATOR.lock().init(HEAP_START as _, HEAP_SIZE) };
|
unsafe { alloc().init(HEAP_START as _, HEAP_SIZE) };
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
use linked_list_allocator::LockedHeap;
|
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
|
|
||||||
|
pub fn alloc<'l>() -> MutexGuard<'l, RawSpinlock, Heap> {
|
||||||
|
ALLOCATOR.lock()
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe fn translate_addr(addr: VirtAddr, physical_memory_start: VirtAddr) -> Option<PhysAddr> {
|
pub unsafe fn translate_addr(addr: VirtAddr, physical_memory_start: VirtAddr) -> Option<PhysAddr> {
|
||||||
translate_addr_inner(addr, physical_memory_start)
|
translate_addr_inner(addr, physical_memory_start)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,9 +74,9 @@ pub enum Key {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct KeyModState {
|
pub struct KeyModState {
|
||||||
ctrl: bool,
|
pub ctrl: bool,
|
||||||
shift: bool,
|
pub shift: bool,
|
||||||
alt: bool,
|
pub alt: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyModState {
|
impl KeyModState {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use x86_64::instructions::{interrupts, port::Port};
|
||||||
|
|
||||||
pub const WIDTH: usize = 80;
|
pub const WIDTH: usize = 80;
|
||||||
pub const HEIGHT: usize = 25;
|
pub const HEIGHT: usize = 25;
|
||||||
|
|
||||||
|
@ -13,4 +15,49 @@ impl Vga {
|
||||||
*Vga::BUFF.offset(index * 2 + 1) = 0xb;
|
*Vga::BUFF.offset(index * 2 + 1) = 0xb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_cursor_pos(&self, pos: (usize, usize)) {
|
||||||
|
type Uk = u16;
|
||||||
|
let index = (pos.0 + pos.1 * WIDTH) as Uk + 1;
|
||||||
|
interrupts::without_interrupts(|| unsafe {
|
||||||
|
let mut cmd = Port::<Uk>::new(0x3D4);
|
||||||
|
let mut data = Port::<Uk>::new(0x3D5);
|
||||||
|
cmd.write(0x0F);
|
||||||
|
data.write(index & 0xFF);
|
||||||
|
|
||||||
|
cmd.write(0x0E);
|
||||||
|
data.write((index >> 8) & 0xFF);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum Color {
|
||||||
|
Black = 0,
|
||||||
|
Blue = 1,
|
||||||
|
Green = 2,
|
||||||
|
Cyan = 3,
|
||||||
|
Red = 4,
|
||||||
|
Magenta = 5,
|
||||||
|
Brown = 6,
|
||||||
|
LightGray = 7,
|
||||||
|
DarkGray = 8,
|
||||||
|
LightBlue = 9,
|
||||||
|
LightGreen = 10,
|
||||||
|
LightCyan = 11,
|
||||||
|
LightRed = 12,
|
||||||
|
Pink = 13,
|
||||||
|
Yellow = 14,
|
||||||
|
White = 15,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
struct ColorCode(u8);
|
||||||
|
|
||||||
|
impl ColorCode {
|
||||||
|
fn new(foreground: Color, background: Color) -> ColorCode {
|
||||||
|
ColorCode((background as u8) << 4 | (foreground as u8))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
|
#![feature(allocator_api)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
mod dev;
|
mod dev;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use core::{cell::RefCell, mem};
|
use core::mem;
|
||||||
|
|
||||||
use alloc::{
|
use alloc::{
|
||||||
rc::Rc,
|
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
@ -9,19 +8,25 @@ use blinkcast::alloc::channel;
|
||||||
use microlang::eval::{Context, Scope, Value};
|
use microlang::eval::{Context, Scope, Value};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::console::out,
|
dev::{console::out, memory::alloc},
|
||||||
hard::keyboard::{keyboard, Azerty, Code, Key, KeyModState, Qwerty},
|
hard::keyboard::{keyboard, Code, Key, KeyModState},
|
||||||
print, println,
|
print, println,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::hard::keyboard::Azerty as Keymap;
|
||||||
|
// use crate::hard::keyboard::Qwerty as Keymap;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let keymap = Azerty::default();
|
let keymap = Keymap::default();
|
||||||
|
|
||||||
let (tx, mut rx) = channel(1024);
|
let (tx, mut rx) = channel(1024);
|
||||||
let mut buff = String::new();
|
let mut buff = String::new();
|
||||||
let mut state = KeyModState::default();
|
let mut state = KeyModState::default();
|
||||||
keyboard().keymap(keymap.clone());
|
keyboard().keymap(keymap.clone());
|
||||||
keyboard().on_code(move |c| match state.translate(&keymap, c) {
|
keyboard().on_code(move |c| match state.translate(&keymap, c) {
|
||||||
|
Code::Down(Key::Char('d')) if state.ctrl => {
|
||||||
|
panic!("Exiting.");
|
||||||
|
}
|
||||||
Code::Down(Key::Char(c)) => {
|
Code::Down(Key::Char(c)) => {
|
||||||
print!("{c}");
|
print!("{c}");
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
|
@ -93,4 +98,18 @@ fn prelude(context: &mut Context) {
|
||||||
.collect();
|
.collect();
|
||||||
Ok(Value::array(values))
|
Ok(Value::array(values))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context.define_built("mem", |_args, _ctx| {
|
||||||
|
let size = alloc().size() as f64;
|
||||||
|
let used = alloc().used() as f64;
|
||||||
|
let free_frac = 1. - (used / size);
|
||||||
|
Ok(Value::object(
|
||||||
|
[
|
||||||
|
("size".into(), Value::Num(size)),
|
||||||
|
("used".into(), Value::Num(used)),
|
||||||
|
("free_frac".into(), Value::Num(free_frac)),
|
||||||
|
]
|
||||||
|
.into_iter(),
|
||||||
|
))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue