diff --git a/kernel/include/ioctl.hpp b/kernel/include/ioctl.hpp new file mode 100644 index 00000000..5411589e --- /dev/null +++ b/kernel/include/ioctl.hpp @@ -0,0 +1,18 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// 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 IOCTL_HPP +#define IOCTL_HPP + +#include +#include + +#include "ioctl_codes.hpp" + +int64_t ioctl(const std::string& device, ioctl_request request, void* data); + +#endif diff --git a/kernel/src/ioctl.cpp b/kernel/src/ioctl.cpp new file mode 100644 index 00000000..36780908 --- /dev/null +++ b/kernel/src/ioctl.cpp @@ -0,0 +1,19 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// 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 "ioctl.hpp" +#include "errors.hpp" + +int64_t ioctl(const std::string& device, ioctl_request request, void* data){ + if(request == ioctl_request::GET_BLK_SIZE){ + *reinterpret_cast(data) = 0; + + return 0; + } + + return std::ERROR_INVALID_REQUEST; +} diff --git a/kernel/src/system_calls.cpp b/kernel/src/system_calls.cpp index ffb25bb6..d6803607 100644 --- a/kernel/src/system_calls.cpp +++ b/kernel/src/system_calls.cpp @@ -17,6 +17,9 @@ #include "vesa.hpp" #include "mouse.hpp" #include "vfs/vfs.hpp" +#include "ioctl.hpp" + +//TODO Split this file namespace { @@ -275,6 +278,14 @@ void sc_mouse_y(interrupt::syscall_regs* regs){ regs->rax = mouse::y(); } +void sc_ioctl(interrupt::syscall_regs* regs){ + auto device = reinterpret_cast(regs->rbx); + auto request = regs->rcx; + auto data = reinterpret_cast(regs->rdx); + + regs->rax = ioctl(device, static_cast(request), data); +} + } //End of anonymous namespace void system_call_entry(interrupt::syscall_regs* regs){ @@ -450,6 +461,10 @@ void system_call_entry(interrupt::syscall_regs* regs){ sc_mouse_y(regs); break; + case 0x2000: + sc_ioctl(regs); + break; + default: k_print_line("Invalid system call"); break; diff --git a/tlib/include/errors.hpp b/tlib/include/errors.hpp index 5f0581ad..b4ba383b 100644 --- a/tlib/include/errors.hpp +++ b/tlib/include/errors.hpp @@ -29,6 +29,7 @@ constexpr const size_t ERROR_PERMISSION_DENIED = 13; constexpr const size_t ERROR_INVALID_OFFSET = 14; constexpr const size_t ERROR_UNSUPPORTED = 15; constexpr const size_t ERROR_INVALID_COUNT = 16; +constexpr const size_t ERROR_INVALID_REQUEST = 17; inline const char* error_message(size_t error){ switch(error){ diff --git a/tlib/include/io.hpp b/tlib/include/io.hpp new file mode 100644 index 00000000..e998873f --- /dev/null +++ b/tlib/include/io.hpp @@ -0,0 +1,19 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// 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 IO_HPP +#define IO_HPP + +#include +#include +#include + +#include "ioctl_codes.hpp" + +int64_t ioctl(const std::string& device, ioctl_request request, void* data); + +#endif diff --git a/tlib/include/ioctl_codes.hpp b/tlib/include/ioctl_codes.hpp new file mode 100644 index 00000000..fd09dc02 --- /dev/null +++ b/tlib/include/ioctl_codes.hpp @@ -0,0 +1,17 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// 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 IOCTL_CODES_H +#define IOCTL_CODE_H + +#include + +enum class ioctl_request : size_t { + GET_BLK_SIZE = 1 +}; + +#endif diff --git a/tlib/src/io.cpp b/tlib/src/io.cpp new file mode 100644 index 00000000..016457d0 --- /dev/null +++ b/tlib/src/io.cpp @@ -0,0 +1,17 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// 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 + +int64_t ioctl(const std::string& device, ioctl_request request, void* data){ + int64_t code; + asm volatile("mov rax, 0x2000; mov rbx, %[path]; mov rcx, %[request]; mov rdx, %[data]; int 50; mov %[code], rax" + : [code] "=m" (code) + : [path] "g" (reinterpret_cast(device.c_str())), [request] "g" (static_cast(request)), [data] "g" (reinterpret_cast(data)) + : "rax", "rbx", "rcx", "rdx"); + return code; +}