mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-10 23:09:18 +00:00
tty: Fix kcon & tty implementation; Add stub ptmx
This commit is contained in:
@ -93,6 +93,7 @@ namespace Driver
|
||||
FileNode *devNode = nullptr;
|
||||
FileNode *devInputNode = nullptr;
|
||||
|
||||
|
||||
int LoadDriverFile(DriverObject &Drv, FileNode *File);
|
||||
|
||||
void InitializeDaemonFS();
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_FILESYSTEM_DEV_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_DEV_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <bitmap.hpp>
|
||||
#include <termios.h>
|
||||
#include <lock.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class PTYDevice
|
||||
{
|
||||
private:
|
||||
Inode *pts;
|
||||
int id;
|
||||
termios term{};
|
||||
winsize termSize{};
|
||||
|
||||
class PTYSlave
|
||||
{
|
||||
};
|
||||
|
||||
class PTYMaster
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
decltype(id) &ptyId = id;
|
||||
|
||||
ssize_t Read(struct Inode *Node, void *Buffer, size_t Size, off_t Offset);
|
||||
ssize_t Write(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset);
|
||||
int Ioctl(struct Inode *Node, unsigned long Request, void *Argp);
|
||||
|
||||
PTYDevice(Inode *pts, int id);
|
||||
~PTYDevice();
|
||||
};
|
||||
|
||||
class PTMXDevice
|
||||
{
|
||||
private:
|
||||
NewLock(PTMXLock);
|
||||
FileNode *ptmx;
|
||||
FileNode *pts;
|
||||
Bitmap ptysId;
|
||||
std::unordered_map<size_t, PTYDevice *> ptysList;
|
||||
|
||||
public:
|
||||
int Open(struct Inode *Node, int Flags, mode_t Mode, struct Inode *Result);
|
||||
int Close(struct Inode *Node);
|
||||
|
||||
PTMXDevice();
|
||||
~PTMXDevice();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_DEV_H__
|
@ -19,8 +19,7 @@
|
||||
#define __FENNIX_KERNEL_KERNEL_CONSOLE_H__
|
||||
|
||||
#include <display.hpp>
|
||||
#include <termios.h>
|
||||
#include <atomic>
|
||||
#include <tty.hpp>
|
||||
|
||||
namespace KernelConsole
|
||||
{
|
||||
@ -86,7 +85,7 @@ namespace KernelConsole
|
||||
char Paint(long CellX, long CellY, char Char, uint32_t Foreground, uint32_t Background);
|
||||
};
|
||||
|
||||
class VirtualTerminal
|
||||
class VirtualTerminal : public TTY::TeletypeDriver
|
||||
{
|
||||
private:
|
||||
ANSIParser Parser{};
|
||||
@ -98,9 +97,17 @@ namespace KernelConsole
|
||||
PaintCallback PaintCB = nullptr;
|
||||
CursorCallback CursorCB = nullptr;
|
||||
|
||||
std::mutex Mutex;
|
||||
|
||||
public:
|
||||
termios term;
|
||||
winsize termSize;
|
||||
termios *GetTermios() { return &this->TerminalConfig; }
|
||||
winsize *GetWinsize() { return &this->TerminalSize; }
|
||||
|
||||
int Open(int Flags, mode_t Mode) final;
|
||||
int Close() final;
|
||||
ssize_t Read(void *Buffer, size_t Size, off_t Offset) final;
|
||||
ssize_t Write(const void *Buffer, size_t Size, off_t Offset) final;
|
||||
int Ioctl(unsigned long Request, void *Argp) final;
|
||||
|
||||
void Clear(unsigned short StartX, unsigned short StartY, unsigned short EndX, unsigned short EndY);
|
||||
void Scroll(unsigned short Lines);
|
||||
|
@ -484,6 +484,7 @@ namespace Tasking
|
||||
FileNode *stdin;
|
||||
FileNode *stdout;
|
||||
FileNode *stderr;
|
||||
/*TTY::TeletypeDriver*/ void *tty;
|
||||
|
||||
/* Memory */
|
||||
Memory::PageTable *PageTable;
|
||||
|
130
include/tty.hpp
Normal file
130
include/tty.hpp
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_TTY_H__
|
||||
#define __FENNIX_KERNEL_TTY_H__
|
||||
|
||||
#include <termios.h>
|
||||
#include <mutex>
|
||||
|
||||
namespace TTY
|
||||
{
|
||||
class TerminalBuffer
|
||||
{
|
||||
private:
|
||||
std::vector<char> Buffer;
|
||||
size_t ReadIndex;
|
||||
size_t WriteIndex;
|
||||
std::mutex Mutex;
|
||||
|
||||
public:
|
||||
TerminalBuffer(size_t Size) : Buffer(Size), ReadIndex(0), WriteIndex(0) {}
|
||||
|
||||
ssize_t Read(char *OutputBuffer, size_t Size);
|
||||
ssize_t Write(const char *InputBuffer, size_t Size);
|
||||
|
||||
void DrainOutput()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(Mutex);
|
||||
ReadIndex = WriteIndex;
|
||||
}
|
||||
|
||||
size_t AvailableToRead() const
|
||||
{
|
||||
return (WriteIndex - ReadIndex + Buffer.size()) % Buffer.size();
|
||||
}
|
||||
|
||||
size_t AvailableToWrite() const
|
||||
{
|
||||
return Buffer.size() - AvailableToRead() - 1;
|
||||
}
|
||||
};
|
||||
|
||||
class TeletypeDriver
|
||||
{
|
||||
protected:
|
||||
termios TerminalConfig;
|
||||
winsize TerminalSize;
|
||||
TerminalBuffer TermBuf;
|
||||
|
||||
public:
|
||||
virtual int Open(int Flags, mode_t Mode);
|
||||
virtual int Close();
|
||||
virtual ssize_t Read(void *Buffer, size_t Size, off_t Offset);
|
||||
virtual ssize_t Write(const void *Buffer, size_t Size, off_t Offset);
|
||||
virtual int Ioctl(unsigned long Request, void *Argp);
|
||||
|
||||
TeletypeDriver();
|
||||
virtual ~TeletypeDriver();
|
||||
};
|
||||
|
||||
class PTYDevice
|
||||
{
|
||||
private:
|
||||
class PTYMaster
|
||||
{
|
||||
private:
|
||||
TerminalBuffer TermBuf;
|
||||
|
||||
public:
|
||||
PTYMaster();
|
||||
~PTYMaster();
|
||||
ssize_t Read(void *Buffer, size_t Size);
|
||||
ssize_t Write(const void *Buffer, size_t Size);
|
||||
};
|
||||
|
||||
class PTYSlave
|
||||
{
|
||||
private:
|
||||
TerminalBuffer TermBuf;
|
||||
|
||||
public:
|
||||
PTYSlave();
|
||||
~PTYSlave();
|
||||
ssize_t Read(void *Buffer, size_t Size);
|
||||
ssize_t Write(const void *Buffer, size_t Size);
|
||||
};
|
||||
|
||||
PTYMaster Master;
|
||||
PTYSlave Slave;
|
||||
|
||||
public:
|
||||
PTYDevice();
|
||||
~PTYDevice();
|
||||
int Open();
|
||||
int Close();
|
||||
ssize_t Read(void *Buffer, size_t Size);
|
||||
ssize_t Write(const void *Buffer, size_t Size);
|
||||
};
|
||||
|
||||
class PTMXDevice
|
||||
{
|
||||
private:
|
||||
std::vector<PTYDevice *> PTYs;
|
||||
std::mutex PTYMutex;
|
||||
|
||||
public:
|
||||
PTMXDevice();
|
||||
~PTMXDevice();
|
||||
int Open();
|
||||
int Close();
|
||||
PTYDevice *CreatePTY();
|
||||
int RemovePTY(PTYDevice *pty);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TTY_H__
|
Reference in New Issue
Block a user