This commit is contained in:
Baptiste Wicht 2014-01-19 15:23:04 +01:00
parent 53bd5bbe42
commit 6054bf8a06
2 changed files with 83 additions and 56 deletions

View File

@ -18,9 +18,9 @@ typedef pt_t* pdt_t;
typedef pdt_t* pdpt_t;
typedef pdpt_t* pml4t_t;
constexpr const int PRESENT = 0x1;
constexpr const int WRITEABLE = 0x2;
constexpr const int USER = 0x4;
constexpr const uint8_t PRESENT = 0x1;
constexpr const uint8_t WRITEABLE = 0x2;
constexpr const uint8_t USER = 0x4;
//Memory from 0x70000 can be used for pages
uintptr_t last_page = 0x73000;

View File

@ -743,54 +743,10 @@ std::optional<std::string> read_elf_file(const std::string& file, const std::str
return {std::move(content)};
}
void exec_command(const std::vector<std::string>& params){
if(params.size() < 2){
k_print_line("exec: Need the name of the executable to read");
return;
}
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
return;
}
auto content = read_elf_file(params[1], "exec");
if(!content){
return;
}
//TODO
}
void execin_command(const std::vector<std::string>& params){
if(params.size() < 2){
k_print_line("execin: Need the name of the executable to read");
return;
}
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
return;
}
auto content = read_elf_file(params[1], "execin");
if(!content){
return;
}
auto buffer = content->c_str();
bool allocate_segments(char* buffer, void** allocated_segments){
auto header = reinterpret_cast<elf::elf_header*>(buffer);
auto program_header_table = reinterpret_cast<elf::program_header*>(buffer + header->e_phoff);
auto allocated_segments = new void*[header->e_phnum];
bool failed = false;
for(size_t p = 0; p < header->e_phnum; ++p){
auto& p_header = program_header_table[p];
@ -851,15 +807,12 @@ void execin_command(const std::vector<std::string>& params){
}
}
if(!failed){
auto main_function = reinterpret_cast<int(*)()>(header->e_entry);
return failed;
}
auto return_code = main_function();
k_printf("Returned %d\n", return_code);
} else {
k_print_line("execin: Unable to execute the program");
}
void release_segments(char* buffer, void** allocated_segments){
auto header = reinterpret_cast<elf::elf_header*>(buffer);
auto program_header_table = reinterpret_cast<elf::program_header*>(buffer + header->e_phoff);
//Release physical memory
for(size_t p = 0; p < header->e_phnum; ++p){
@ -882,6 +835,80 @@ void execin_command(const std::vector<std::string>& params){
}
}
void exec_command(const std::vector<std::string>& params){
if(params.size() < 2){
k_print_line("exec: Need the name of the executable to read");
return;
}
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
return;
}
auto content = read_elf_file(params[1], "exec");
if(!content){
return;
}
auto buffer = content->c_str();
auto header = reinterpret_cast<elf::elf_header*>(buffer);
std::unique_heap_array<void*> allocated_segments(header->e_phnum);
auto failed = allocate_segments(buffer, allocated_segments.get());
if(!failed){
//TODO
} else {
k_print_line("execin: Unable to execute the program");
}
release_segments(buffer, allocated_segments.get());
}
void execin_command(const std::vector<std::string>& params){
if(params.size() < 2){
k_print_line("execin: Need the name of the executable to read");
return;
}
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
return;
}
auto content = read_elf_file(params[1], "execin");
if(!content){
return;
}
auto buffer = content->c_str();
auto header = reinterpret_cast<elf::elf_header*>(buffer);
std::unique_heap_array<void*> allocated_segments(header->e_phnum);
auto failed = allocate_segments(buffer, allocated_segments.get());
if(!failed){
auto main_function = reinterpret_cast<int(*)()>(header->e_entry);
auto return_code = main_function();
k_printf("Returned %d\n", return_code);
} else {
k_print_line("execin: Unable to execute the program");
}
release_segments(buffer, allocated_segments.get());
}
void vesainfo_command(const std::vector<std::string>&){
if(vesa::vesa_enabled){
auto& block = vesa::mode_info_block;