Skip to content

Commit

Permalink
Remap memory on timer tick
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Jul 12, 2023
1 parent df106c8 commit 51bfab9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
13 changes: 13 additions & 0 deletions kernel/src/interrupts/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ use crate::multitasking::task::CPUState;
use crate::multitasking::task::TASK_MANAGER;
use core::arch::asm;

use crate::memory::paging::PAGING;
use crate::memory::paging::TABLES;

pub const TIMER_INT: u8 = 32;

const APP_TARGET: u32 = 0x00a0_0000;
const APP_SIZE: u32 = 0x0001_0000;

//TIMER IRQ
#[naked]
pub extern "C" fn timer() {
Expand Down Expand Up @@ -51,6 +57,13 @@ pub extern "C" fn timer_handler(esp: u32) -> u32 {
unsafe {
let new_esp: u32 = TASK_MANAGER.schedule(esp as *mut CPUState) as u32;

let slot = TASK_MANAGER.get_current_slot();
let target = APP_TARGET + (slot as u32 * APP_SIZE);

//map table 8 (0x02000000) to the address where the executable is loaded
TABLES[8].set(target);
PAGING.set_table(8, &TABLES[8]);

PICS.end_interrupt(TIMER_INT);

return new_esp;
Expand Down
3 changes: 0 additions & 3 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ pub extern "C" fn _start() -> ! {
unsafe {
PAGING.identity();

TABLES[8].set(0x00a0_0000);
PAGING.set_table(8, &TABLES[8]);

PAGING.enable();
}

Expand Down
4 changes: 4 additions & 0 deletions kernel/src/multitasking/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ impl TaskManager {
slot
}

pub fn get_current_slot(&self) -> i8 {
self.current_task
}

pub fn list_tasks(&self) {
libfelix::println!("Running tasks:");

Expand Down
17 changes: 14 additions & 3 deletions kernel/src/shell/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use crate::filesystem::fat::FAT;
use crate::multitasking::task::TASK_MANAGER;
use crate::syscalls::print::PRINTER;

use crate::memory::paging::PAGING;
use crate::memory::paging::TABLES;

const APP_TARGET: u32 = 0x00a0_0000;
const APP_SIZE: u32 = 0x0001_0000;
const APP_SIGNATURE: u32 = 0xB16B00B5;

const HELP: &'static str = "Available commands:
Expand Down Expand Up @@ -183,13 +187,20 @@ impl Shell {

let entry = FAT.search_file(&self.arg);
if entry.name[0] != 0 {
FAT.read_file_to_target(&entry, APP_TARGET as *mut u32);
let slot = TASK_MANAGER.get_free_slot();
let target = APP_TARGET + (slot as u32 * APP_SIZE);

//map table 8 (0x02000000) to the address where the executable is loaded
TABLES[8].set(target);
PAGING.set_table(8, &TABLES[8]);

FAT.read_file_to_target(&entry, target as *mut u32);

unsafe {
let signature = *(APP_TARGET as *mut u32);
let signature = *(target as *mut u32);

if signature == APP_SIGNATURE {
TASK_MANAGER.add_task((APP_TARGET + 4) as u32);
TASK_MANAGER.add_task((target + 4) as u32);
} else {
libfelix::println!("File is not a valid executable!");
}
Expand Down

0 comments on commit 51bfab9

Please sign in to comment.