diff --git a/kernel/include/shell.hpp b/kernel/include/shell.hpp deleted file mode 100644 index c6afa41f..00000000 --- a/kernel/include/shell.hpp +++ /dev/null @@ -1,13 +0,0 @@ -//======================================================================= -// 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) -//======================================================================= - -#ifndef SHELL_H -#define SHELL_H - -void init_shell(); - -#endif diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index d24f0397..07f6fe31 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -11,7 +11,6 @@ #include "paging.hpp" #include "kalloc.hpp" #include "timer.hpp" -#include "shell.hpp" #include "keyboard.hpp" #include "disks.hpp" #include "acpi.hpp" diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp deleted file mode 100644 index 646b83af..00000000 --- a/kernel/src/shell.cpp +++ /dev/null @@ -1,185 +0,0 @@ -//======================================================================= -// 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 -#include -#include -#include -#include - -#include "shell.hpp" -#include "keyboard.hpp" -#include "kernel_utils.hpp" -#include "console.hpp" -#include "timer.hpp" -#include "disks.hpp" -#include "ata.hpp" -#include "acpi.hpp" -#include "rtc.hpp" -#include "elf.hpp" -#include "paging.hpp" -#include "gdt.hpp" -#include "process.hpp" -#include "scheduler.hpp" - -#include "physical_allocator.hpp" -#include "virtual_allocator.hpp" -#include "kalloc.hpp" -#include "e820.hpp" - -namespace { - -#ifdef CONFIG_HISTORY -static constexpr const bool History = true; -#else -static constexpr const bool History = false; -#endif - -std::vector history; -uint64_t history_index = 0; - -bool shift = false; - -//Declarations of the different functions - -void exec_command(const std::vector& params); - -struct command_definition { - const char* name; - void (*function)(const std::vector&); -}; - -command_definition commands[1] = { - {"exec", exec_command}, -}; - -std::string current_input(16); - -void exec_shell_command(); - -template -void history_key(char key){ - if(history.size() > 0){ - if(key == keyboard::KEY_UP){ - if(history_index == 0){ - return; - } - - --history_index; - } else { //KEY_DOWN - if(history_index == history.size()){ - return; - } - - ++history_index; - } - - set_column(6); - - for(uint64_t i = 0; i < current_input.size(); ++i){ - k_print(' '); - } - - set_column(6); - - if(history_index < history.size()){ - current_input = history[history_index]; - } - - k_print(current_input); - } -} - -template<> void history_key(char){} - -template -void history_save(){ - history.push_back(current_input); - history_index = history.size(); -} - -template<> void history_save(){} - -void start_shell(){ - while(true){ - auto key = keyboard::get_char(); - - //Key released - if(key & 0x80){ - key &= ~(0x80); - if(key == keyboard::KEY_LEFT_SHIFT || key == keyboard::KEY_RIGHT_SHIFT){ - shift = false; - } - } - //Key pressed - else { - //ENTER validate the command - if(key == keyboard::KEY_ENTER){ - if(current_input.size() > 0){ - exec_shell_command(); - - if(get_column() != 0){ - k_print_line(); - } - - current_input.clear(); - } - - k_print("thor> "); - } else if(key == keyboard::KEY_LEFT_SHIFT || key == keyboard::KEY_RIGHT_SHIFT){ - shift = true; - } else if(key == keyboard::KEY_UP || key == keyboard::KEY_DOWN){ - history_key(key); - } else if(key == keyboard::KEY_BACKSPACE){ - if(current_input.size() > 0){ - current_input.pop_back(); - } - } else { - auto qwertz_key = - shift - ? keyboard::shift_key_to_ascii(key) - : keyboard::key_to_ascii(key); - - if(qwertz_key){ - current_input += qwertz_key; - } - } - } - } -} - -void exec_shell_command(){ - history_save(); - - auto params = std::split(current_input);; - - for(auto& command : commands){ - if(params[0] == command.name){ - command.function(params); - - return; - } - } - - k_printf("The command \"%s\" does not exist\n", current_input.c_str()); -} - -void exec_command(const std::vector&){ - //Fake exec just to start() the scheduler - std::vector params; - scheduler::exec("", params); -} - -} //end of anonymous namespace - -void init_shell(){ - wipeout(); - - k_print("thor> "); - - start_shell(); -}