mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Prepare ioctl support
This commit is contained in:
parent
0a5128dfa7
commit
ca4600a51b
18
kernel/include/ioctl.hpp
Normal file
18
kernel/include/ioctl.hpp
Normal 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
19
kernel/src/ioctl.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
|
@ -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
19
tlib/include/io.hpp
Normal 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
|
17
tlib/include/ioctl_codes.hpp
Normal file
17
tlib/include/ioctl_codes.hpp
Normal 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
17
tlib/src/io.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user