Prepare ioctl support

This commit is contained in:
Baptiste Wicht 2016-08-11 20:07:28 +02:00
parent 0a5128dfa7
commit ca4600a51b
7 changed files with 106 additions and 0 deletions

18
kernel/include/ioctl.hpp Normal file
View File

@ -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 <types.hpp>
#include <string.hpp>
#include "ioctl_codes.hpp"
int64_t ioctl(const std::string& device, ioctl_request request, void* data);
#endif

19
kernel/src/ioctl.cpp Normal file
View File

@ -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<size_t*>(data) = 0;
return 0;
}
return std::ERROR_INVALID_REQUEST;
}

View File

@ -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<const char*>(regs->rbx);
auto request = regs->rcx;
auto data = reinterpret_cast<void*>(regs->rdx);
regs->rax = ioctl(device, static_cast<ioctl_request>(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;

View File

@ -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){

19
tlib/include/io.hpp Normal file
View File

@ -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 <types.hpp>
#include <expected.hpp>
#include <string.hpp>
#include "ioctl_codes.hpp"
int64_t ioctl(const std::string& device, ioctl_request request, void* data);
#endif

View File

@ -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 <types.hpp>
enum class ioctl_request : size_t {
GET_BLK_SIZE = 1
};
#endif

17
tlib/src/io.cpp Normal file
View File

@ -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 <io.hpp>
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<size_t>(device.c_str())), [request] "g" (static_cast<size_t>(request)), [data] "g" (reinterpret_cast<size_t>(data))
: "rax", "rbx", "rcx", "rdx");
return code;
}