mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Implemented a kinda broken tty
This commit is contained in:
179
include/cpu.hpp
179
include/cpu.hpp
@ -8,127 +8,134 @@
|
||||
*/
|
||||
namespace CPU
|
||||
{
|
||||
/**
|
||||
* @brief Enum for CPU::Interrupts() function.
|
||||
*/
|
||||
enum InterruptsType
|
||||
{
|
||||
/**
|
||||
* @brief Check if interrupts are enabled.
|
||||
* @brief Enum for CPU::Interrupts() function.
|
||||
*/
|
||||
Check,
|
||||
enum InterruptsType
|
||||
{
|
||||
/**
|
||||
* @brief Check if interrupts are enabled.
|
||||
*/
|
||||
Check,
|
||||
/**
|
||||
* @brief Enable interrupts.
|
||||
*/
|
||||
Enable,
|
||||
/**
|
||||
* @brief Disable interrupts.
|
||||
*/
|
||||
Disable
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enable interrupts.
|
||||
* @brief Pause the CPU
|
||||
*/
|
||||
Enable,
|
||||
void Pause();
|
||||
/**
|
||||
* @brief Disable interrupts.
|
||||
* @brief Halt the CPU
|
||||
*/
|
||||
Disable
|
||||
};
|
||||
void Halt();
|
||||
/**
|
||||
* @brief Check if interrupts are enabled
|
||||
*
|
||||
* @return true If InterruptsType::Check and interrupts are enabled, or if other InterruptsType were executed successfully
|
||||
* @return false If InterruptsType::Check and interrupts are disabled, or if other InterruptsType failed
|
||||
*/
|
||||
bool Interrupts(InterruptsType Type = Check);
|
||||
/**
|
||||
* @brief Get/Set the CPU's page table
|
||||
*
|
||||
* @param PT The new page table, if empty, the current page table will be returned
|
||||
* @return void* The current page table
|
||||
*/
|
||||
void *PageTable(void *PT = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Pause the CPU
|
||||
*/
|
||||
void Pause();
|
||||
/**
|
||||
* @brief Halt the CPU
|
||||
*/
|
||||
void Halt();
|
||||
/**
|
||||
* @brief Check if interrupts are enabled
|
||||
*
|
||||
* @return true If InterruptsType::Check and interrupts are enabled, or if other InterruptsType were executed successfully
|
||||
* @return false If InterruptsType::Check and interrupts are disabled, or if other InterruptsType failed
|
||||
*/
|
||||
bool Interrupts(InterruptsType Type = Check);
|
||||
|
||||
namespace MemBar
|
||||
{
|
||||
static inline void Barrier()
|
||||
namespace MemBar
|
||||
{
|
||||
static inline void Barrier()
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
asmv("" ::
|
||||
: "memory");
|
||||
#elif defined(__aarch64__)
|
||||
asmv("dmb ish" ::
|
||||
: "memory");
|
||||
asmv("dmb ish" ::
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void Fence()
|
||||
{
|
||||
static inline void Fence()
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("mfence" ::
|
||||
: "memory");
|
||||
asmv("mfence" ::
|
||||
: "memory");
|
||||
#elif defined(__aarch64__)
|
||||
asmv("dmb ish" ::
|
||||
: "memory");
|
||||
asmv("dmb ish" ::
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void StoreFence()
|
||||
{
|
||||
static inline void StoreFence()
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("sfence" ::
|
||||
: "memory");
|
||||
asmv("sfence" ::
|
||||
: "memory");
|
||||
#elif defined(__aarch64__)
|
||||
asmv("dmb ishst" ::
|
||||
: "memory");
|
||||
asmv("dmb ishst" ::
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void LoadFence()
|
||||
{
|
||||
static inline void LoadFence()
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("lfence" ::
|
||||
: "memory");
|
||||
asmv("lfence" ::
|
||||
: "memory");
|
||||
#elif defined(__aarch64__)
|
||||
asmv("dmb ishld" ::
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
namespace x86
|
||||
{
|
||||
static inline void lgdt(void *gdt)
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("lgdt (%0)"
|
||||
:
|
||||
: "r"(gdt));
|
||||
asmv("dmb ishld" ::
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void lidt(void *idt)
|
||||
namespace x86
|
||||
{
|
||||
static inline void lgdt(void *gdt)
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("lidt (%0)"
|
||||
:
|
||||
: "r"(idt));
|
||||
asmv("lgdt (%0)"
|
||||
:
|
||||
: "r"(gdt));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ltr(uint16_t Segment)
|
||||
{
|
||||
static inline void lidt(void *idt)
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("ltr %0"
|
||||
:
|
||||
: "r"(Segment));
|
||||
asmv("lidt (%0)"
|
||||
:
|
||||
: "r"(idt));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline void invlpg(void *Address)
|
||||
{
|
||||
static inline void ltr(uint16_t Segment)
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("invlpg (%0)"
|
||||
:
|
||||
: "r"(Address)
|
||||
: "memory");
|
||||
asmv("ltr %0"
|
||||
:
|
||||
: "r"(Segment));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void invlpg(void *Address)
|
||||
{
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
asmv("invlpg (%0)"
|
||||
:
|
||||
: "r"(Address)
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_CPU_H__
|
||||
|
159
include/display.hpp
Normal file
159
include/display.hpp
Normal file
@ -0,0 +1,159 @@
|
||||
#ifndef __FENNIX_KERNEL_DISPLAY_H__
|
||||
#define __FENNIX_KERNEL_DISPLAY_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <boot/binfo.h>
|
||||
#include <memory.hpp>
|
||||
|
||||
namespace Video
|
||||
{
|
||||
#define PSF1_MAGIC0 0x36
|
||||
#define PSF1_MAGIC1 0x04
|
||||
|
||||
#define PSF2_MAGIC0 0x72
|
||||
#define PSF2_MAGIC1 0xb5
|
||||
#define PSF2_MAGIC2 0x4a
|
||||
#define PSF2_MAGIC3 0x86
|
||||
|
||||
struct PSF1_HEADER
|
||||
{
|
||||
uint8_t magic[2];
|
||||
uint8_t mode;
|
||||
uint8_t charsize;
|
||||
};
|
||||
|
||||
struct PSF2_HEADER
|
||||
{
|
||||
uint8_t magic[4];
|
||||
uint32_t version;
|
||||
uint32_t headersize;
|
||||
uint32_t flags;
|
||||
uint32_t length;
|
||||
uint32_t charsize;
|
||||
uint32_t height, width;
|
||||
};
|
||||
|
||||
typedef struct _PSF1_FONT
|
||||
{
|
||||
PSF1_HEADER *Header;
|
||||
void *GlyphBuffer;
|
||||
} PSF1_FONT;
|
||||
|
||||
typedef struct _PSF2_FONT
|
||||
{
|
||||
PSF2_HEADER *Header;
|
||||
void *GlyphBuffer;
|
||||
} PSF2_FONT;
|
||||
|
||||
enum FontType
|
||||
{
|
||||
None,
|
||||
PCScreenFont1,
|
||||
PCScreenFont2
|
||||
};
|
||||
|
||||
struct FontInfo
|
||||
{
|
||||
uint64_t *StartAddress;
|
||||
uint64_t *EndAddress;
|
||||
PSF1_FONT *PSF1Font;
|
||||
PSF2_FONT *PSF2Font;
|
||||
uint32_t Width, Height;
|
||||
FontType Type;
|
||||
};
|
||||
|
||||
class Font
|
||||
{
|
||||
private:
|
||||
FontInfo Info;
|
||||
|
||||
public:
|
||||
FontInfo GetInfo() { return Info; }
|
||||
Font(uint64_t *Start, uint64_t *End, FontType Type);
|
||||
~Font();
|
||||
};
|
||||
|
||||
struct ScreenBuffer
|
||||
{
|
||||
void *Buffer;
|
||||
uint32_t Width, Height;
|
||||
uint64_t Size;
|
||||
uint32_t Color;
|
||||
uint32_t CursorX, CursorY;
|
||||
};
|
||||
|
||||
class Display
|
||||
{
|
||||
private:
|
||||
BootInfo::FramebufferInfo framebuffer;
|
||||
Font *CurrentFont;
|
||||
ScreenBuffer *Buffers[16];
|
||||
|
||||
public:
|
||||
Font *GetCurrentFont() { return CurrentFont; }
|
||||
void SetCurrentFont(Font *Font) { CurrentFont = Font; }
|
||||
void CreateBuffer(uint32_t Width, uint32_t Height, int Index)
|
||||
{
|
||||
uint64_t Size = framebuffer.Pitch * Height;
|
||||
ScreenBuffer *buffer = new ScreenBuffer;
|
||||
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
||||
buffer->Width = Width;
|
||||
buffer->Height = Height;
|
||||
buffer->Size = Size;
|
||||
buffer->Color = 0x000000;
|
||||
buffer->CursorX = 0;
|
||||
buffer->CursorY = 0;
|
||||
Buffers[Index] = buffer;
|
||||
__builtin_memset(buffer->Buffer, 0, Size);
|
||||
}
|
||||
void SetBuffer(int Index) { __builtin_memcpy(framebuffer.BaseAddress, Buffers[Index]->Buffer, Buffers[Index]->Size); }
|
||||
void ClearBuffer(int Index) { __builtin_memset(Buffers[Index]->Buffer, 0, Buffers[Index]->Size); }
|
||||
void DeleteBuffer(int Index)
|
||||
{
|
||||
if (Buffers[Index] == nullptr)
|
||||
return;
|
||||
KernelAllocator.FreePages(Buffers[Index]->Buffer, TO_PAGES(Buffers[Index]->Size));
|
||||
delete Buffers[Index];
|
||||
}
|
||||
|
||||
void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index)
|
||||
{
|
||||
if (X >= Buffers[Index]->Width || Y >= Buffers[Index]->Height)
|
||||
return;
|
||||
uint32_t *Pixel = (uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8));
|
||||
*Pixel = Color;
|
||||
}
|
||||
|
||||
uint32_t GetPixel(uint32_t X, uint32_t Y, int Index)
|
||||
{
|
||||
if (X >= Buffers[Index]->Width || Y >= Buffers[Index]->Height)
|
||||
return 0;
|
||||
uint32_t *Pixel = (uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8));
|
||||
return *Pixel;
|
||||
}
|
||||
|
||||
void Scroll(int Index, int Lines)
|
||||
{
|
||||
if (Lines == 0)
|
||||
return;
|
||||
|
||||
if (Lines > 0)
|
||||
{
|
||||
__builtin_memmove(Buffers[Index]->Buffer,
|
||||
(uint8_t *)Buffers[Index]->Buffer + (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines),
|
||||
Buffers[Index]->Size - (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines));
|
||||
|
||||
__builtin_memset((uint8_t *)Buffers[Index]->Buffer + (Buffers[Index]->Size - (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines)),
|
||||
0,
|
||||
Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines);
|
||||
}
|
||||
}
|
||||
|
||||
char Print(char Char, int Index);
|
||||
Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont = true);
|
||||
~Display();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DISPLAY_H__
|
@ -396,9 +396,9 @@ namespace Memory
|
||||
/**
|
||||
* @brief Construct a new Virtual object
|
||||
*
|
||||
* @param Table Page table
|
||||
* @param Table Page table. If null, it will use the current page table.
|
||||
*/
|
||||
Virtual(PageTable *Table);
|
||||
Virtual(PageTable *Table = nullptr);
|
||||
/**
|
||||
* @brief Destroy the Virtual object
|
||||
*
|
||||
|
@ -32,6 +32,8 @@
|
||||
#define in :
|
||||
#endif
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
#ifndef __va_list__
|
||||
typedef __builtin_va_list va_list;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user