mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Prepare scheduling
This commit is contained in:
parent
5be3be8b64
commit
a192ed9613
@ -20,6 +20,8 @@ struct process_t;
|
||||
|
||||
namespace paging {
|
||||
|
||||
//TODO Probably some of it could be moved in the source file
|
||||
|
||||
typedef uint64_t* page_entry;
|
||||
typedef page_entry* pt_t;
|
||||
typedef pt_t* pd_t;
|
||||
@ -101,6 +103,8 @@ void map_kernel_inside_user(scheduler::process_t& process);
|
||||
bool user_map(scheduler::process_t& process, size_t virt, size_t physical);
|
||||
bool user_map_pages(scheduler::process_t& process, size_t virt, size_t physical, size_t pages);
|
||||
|
||||
size_t get_physical_pml4t();
|
||||
|
||||
} //end of namespace paging
|
||||
|
||||
#endif
|
||||
|
@ -21,12 +21,20 @@ struct segment_t {
|
||||
};
|
||||
|
||||
struct process_t {
|
||||
size_t pid;
|
||||
|
||||
bool system;
|
||||
|
||||
size_t physical_cr3;
|
||||
size_t paging_size;
|
||||
|
||||
size_t physical_user_stack;
|
||||
size_t physical_kernel_stack;
|
||||
|
||||
size_t rip;
|
||||
size_t user_rsp;
|
||||
size_t kernel_rsp;
|
||||
|
||||
std::vector<segment_t> segments;
|
||||
std::vector<size_t> physical_paging;
|
||||
};
|
||||
|
@ -13,6 +13,10 @@ namespace scheduler {
|
||||
void init();
|
||||
void start();
|
||||
|
||||
void kill_current_process();
|
||||
|
||||
void reschedule();
|
||||
|
||||
} //end of namespace scheduler
|
||||
|
||||
#endif
|
||||
|
@ -84,19 +84,14 @@ public:
|
||||
|
||||
//Modifiers
|
||||
|
||||
void push_back(value_type&& element){
|
||||
ensure_capacity();
|
||||
|
||||
data[_size++] = std::forward<value_type>(element);
|
||||
}
|
||||
|
||||
void push_back(const value_type& element){
|
||||
if(_capacity == 0){
|
||||
_capacity = 1;
|
||||
data = new T[_capacity];
|
||||
} else if(_capacity == _size){
|
||||
_capacity= _capacity * 2;
|
||||
|
||||
auto new_data = new T[_capacity];
|
||||
std::move_n(new_data, data, _size);
|
||||
|
||||
delete[] data;
|
||||
data = new_data;
|
||||
}
|
||||
ensure_capacity();
|
||||
|
||||
data[_size++] = element;
|
||||
}
|
||||
@ -126,6 +121,22 @@ public:
|
||||
constexpr const_iterator end() const {
|
||||
return const_iterator(&data[_size]);
|
||||
}
|
||||
|
||||
private:
|
||||
void ensure_capacity(){
|
||||
if(_capacity == 0){
|
||||
_capacity = 1;
|
||||
data = new T[_capacity];
|
||||
} else if(_capacity == _size){
|
||||
_capacity= _capacity * 2;
|
||||
|
||||
auto new_data = new T[_capacity];
|
||||
std::move_n(new_data, data, _size);
|
||||
|
||||
delete[] data;
|
||||
data = new_data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} //end of namespace std
|
||||
|
@ -519,3 +519,7 @@ bool paging::user_map_pages(scheduler::process_t& process, size_t virt, size_t p
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t paging::get_physical_pml4t(){
|
||||
return physical_pml4t_start;
|
||||
}
|
||||
|
77
kernel/src/scheduler.cpp
Normal file
77
kernel/src/scheduler.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2014.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//=======================================================================
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "process.hpp"
|
||||
#include "paging.hpp"
|
||||
#include "assert.hpp"
|
||||
|
||||
#include "console.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<scheduler::process_t> processes;
|
||||
size_t current_pid;
|
||||
|
||||
size_t next_pid = 1;
|
||||
|
||||
void idle_task(){
|
||||
while(true){
|
||||
asm volatile("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
size_t idle_stack[64];
|
||||
size_t idle_kernel_stack[4096]; //TODO Perhaps not good
|
||||
|
||||
void create_idle_task(){
|
||||
scheduler::process_t idle_process;
|
||||
idle_process.pid = next_pid++;
|
||||
idle_process.system = true;
|
||||
idle_process.physical_cr3 = paging::get_physical_pml4t();
|
||||
idle_process.paging_size = 0;
|
||||
|
||||
idle_process.physical_user_stack = 0;
|
||||
idle_process.physical_kernel_stack = 0;
|
||||
|
||||
idle_process.rip = reinterpret_cast<size_t>(&idle_task);
|
||||
idle_process.user_rsp = reinterpret_cast<size_t>(&idle_stack[63]);
|
||||
idle_process.kernel_rsp = reinterpret_cast<size_t>(&idle_kernel_stack[4095]);
|
||||
|
||||
processes.push_back(std::move(idle_process));
|
||||
}
|
||||
|
||||
void switch_to_process(size_t pid){
|
||||
current_pid = pid;
|
||||
|
||||
k_printf("Switched to %u\n", current_pid);
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void scheduler::init(){
|
||||
//Create the idle task
|
||||
create_idle_task();
|
||||
}
|
||||
|
||||
void scheduler::start(){
|
||||
thor_assert(!processes.empty(), "There should at least be the idle task");
|
||||
|
||||
switch_to_process(processes.size() - 1);
|
||||
}
|
||||
|
||||
void scheduler::kill_current_process(){
|
||||
k_printf("Kill %u\n", current_pid);
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
void scheduler::reschedule(){
|
||||
//TODO
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
#include "gdt.hpp"
|
||||
#include "vesa.hpp"
|
||||
#include "process.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "physical_allocator.hpp"
|
||||
#include "virtual_allocator.hpp"
|
||||
@ -868,6 +869,8 @@ void exec_command(const std::vector<std::string>& params){
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler::init();
|
||||
|
||||
auto content = read_elf_file(params[1], "exec");
|
||||
|
||||
if(!content){
|
||||
|
Loading…
x
Reference in New Issue
Block a user