Kernel: Add tty to process and make termios modifiable
This commit is contained in:
parent
22c72d8c70
commit
abbbf7ec15
|
@ -5,6 +5,7 @@
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
#include <kernel/FS/Inode.h>
|
#include <kernel/FS/Inode.h>
|
||||||
#include <kernel/SpinLock.h>
|
#include <kernel/SpinLock.h>
|
||||||
|
#include <kernel/Terminal/TTY.h>
|
||||||
#include <kernel/Thread.h>
|
#include <kernel/Thread.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -28,6 +29,7 @@ namespace Kernel
|
||||||
void on_thread_exit(Thread&);
|
void on_thread_exit(Thread&);
|
||||||
|
|
||||||
BAN::ErrorOr<void> init_stdio();
|
BAN::ErrorOr<void> init_stdio();
|
||||||
|
BAN::ErrorOr<void> set_termios(const termios&);
|
||||||
|
|
||||||
pid_t pid() const { return m_pid; }
|
pid_t pid() const { return m_pid; }
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ namespace Kernel
|
||||||
static BAN::RefPtr<Process> current() { return Thread::current().process(); }
|
static BAN::RefPtr<Process> current() { return Thread::current().process(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Process(pid_t pid) : m_pid(pid) {}
|
Process(pid_t);
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::String> absolute_path_of(BAN::StringView) const;
|
BAN::ErrorOr<BAN::String> absolute_path_of(BAN::StringView) const;
|
||||||
|
|
||||||
|
@ -75,6 +77,8 @@ namespace Kernel
|
||||||
BAN::String m_working_directory;
|
BAN::String m_working_directory;
|
||||||
BAN::Vector<Thread*> m_threads;
|
BAN::Vector<Thread*> m_threads;
|
||||||
|
|
||||||
|
TTY* m_tty { nullptr };
|
||||||
|
|
||||||
friend class BAN::RefPtr<Process>;
|
friend class BAN::RefPtr<Process>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,8 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TTY(TerminalDriver*);
|
TTY(TerminalDriver*);
|
||||||
void clear();
|
|
||||||
void putchar(uint8_t ch);
|
void set_termios(const termios& termios) { m_termios = termios; }
|
||||||
void set_cursor_position(uint32_t x, uint32_t y);
|
|
||||||
void set_font(const Kernel::Font&);
|
void set_font(const Kernel::Font&);
|
||||||
|
|
||||||
uint32_t height() const { return m_height; }
|
uint32_t height() const { return m_height; }
|
||||||
|
@ -27,16 +26,20 @@ namespace Kernel
|
||||||
// for kprint
|
// for kprint
|
||||||
static void putchar_current(uint8_t ch);
|
static void putchar_current(uint8_t ch);
|
||||||
static bool is_initialized();
|
static bool is_initialized();
|
||||||
|
static TTY* current();
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void clear();
|
||||||
|
void putchar(uint8_t ch);
|
||||||
void reset_ansi();
|
void reset_ansi();
|
||||||
void handle_ansi_csi(uint8_t ch);
|
void handle_ansi_csi(uint8_t ch);
|
||||||
void handle_ansi_csi_color();
|
void handle_ansi_csi_color();
|
||||||
void putchar_at(uint32_t codepoint, uint32_t x, uint32_t y);
|
void putchar_at(uint32_t codepoint, uint32_t x, uint32_t y);
|
||||||
void render_from_buffer(uint32_t x, uint32_t y);
|
void render_from_buffer(uint32_t x, uint32_t y);
|
||||||
|
void set_cursor_position(uint32_t x, uint32_t y);
|
||||||
|
|
||||||
void on_key(Input::KeyEvent);
|
void on_key(Input::KeyEvent);
|
||||||
void do_backspace();
|
void do_backspace();
|
||||||
|
|
|
@ -18,15 +18,10 @@ namespace Kernel
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> Process::init_stdio()
|
Process::Process(pid_t pid)
|
||||||
{
|
: m_pid(pid)
|
||||||
if (!m_open_files.empty())
|
, m_tty(TTY::current())
|
||||||
return BAN::Error::from_c_string("Could not init stdio, process already has open files");
|
{ }
|
||||||
TRY(open("/dev/tty1", O_RDONLY)); // stdin
|
|
||||||
TRY(open("/dev/tty1", O_WRONLY)); // stdout
|
|
||||||
TRY(open("/dev/tty1", O_WRONLY)); // stderr
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
BAN::ErrorOr<void> Process::add_thread(entry_t entry, void* data)
|
BAN::ErrorOr<void> Process::add_thread(entry_t entry, void* data)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +46,24 @@ namespace Kernel
|
||||||
m_threads.remove(i);
|
m_threads.remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<void> Process::init_stdio()
|
||||||
|
{
|
||||||
|
if (!m_open_files.empty())
|
||||||
|
return BAN::Error::from_c_string("Could not init stdio, process already has open files");
|
||||||
|
TRY(open("/dev/tty1", O_RDONLY)); // stdin
|
||||||
|
TRY(open("/dev/tty1", O_WRONLY)); // stdout
|
||||||
|
TRY(open("/dev/tty1", O_WRONLY)); // stderr
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<void> Process::set_termios(const termios& termios)
|
||||||
|
{
|
||||||
|
if (m_tty == nullptr)
|
||||||
|
return BAN::Error::from_errno(ENOTTY);
|
||||||
|
m_tty->set_termios(termios);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<int> Process::open(BAN::StringView path, int flags)
|
BAN::ErrorOr<int> Process::open(BAN::StringView path, int flags)
|
||||||
{
|
{
|
||||||
if (flags & ~O_RDWR)
|
if (flags & ~O_RDWR)
|
||||||
|
|
|
@ -59,6 +59,11 @@ namespace Kernel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TTY* TTY::current()
|
||||||
|
{
|
||||||
|
return s_tty;
|
||||||
|
}
|
||||||
|
|
||||||
void TTY::on_key(Input::KeyEvent event)
|
void TTY::on_key(Input::KeyEvent event)
|
||||||
{
|
{
|
||||||
ASSERT(!m_lock.is_locked());
|
ASSERT(!m_lock.is_locked());
|
||||||
|
|
Loading…
Reference in New Issue