Skip to content

Commit

Permalink
Добавлена поддержка TGA
Browse files Browse the repository at this point in the history
  • Loading branch information
Aren committed Oct 19, 2023
1 parent 3825c1a commit 4a233e1
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 8,607 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bitset": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"complex": "cpp"
"complex": "cpp",
"string": "cpp"
}
}
Binary file added boot.tga
Binary file not shown.
5 changes: 3 additions & 2 deletions configs/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ TIMEOUT=5
DEFAULT_ENTRY=0
INTERFACE_BRANDING=By Aren Elchinyan
BACKGROUND_STYLE=stretched
BACKGROUND_PATH=boot:///boot.png
BACKGROUND_PATH=boot:///boot.tga
#TERM_FONT=boot:///CYRILL2.F16
#TERM_FONT_SIZE=8x16

:BMOSP (KASLR on)
#RESOLUTION=640x480
#RESOLUTION=1024x768
RESOLUTION=1280x720
PROTOCOL=limine
KASLR=no
KERNEL_PATH=boot:///kernel.elf

MODULE_PATH=boot:///mod/hello.so
MODULE_CMDLINE=[MOD]hello.so

MODULE_PATH=boot:///boot.png
MODULE_PATH=boot:///boot.tga
MODULE_CMDLINE=[BOOTIMG]
2 changes: 1 addition & 1 deletion include/fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace fb {

void init( );

void print_buf(size_t x, size_t y, size_t h, size_t w, uint32_t *buf);
void printf(char *str, ...);

void printf_at(size_t x, size_t y, char *str, ...);
Expand Down
1 change: 1 addition & 0 deletions include/mem.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace mem {
void dump_memory( );
void init( );
void *alloc(size_t size);
void free(void *addr);
Expand Down
2 changes: 1 addition & 1 deletion include/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
static inline void pause( ) {
for (uint64_t i = 0; i < 1024; i++) {
for (uint64_t j = 0; j < 1024; j++) {
for (uint64_t q = 0; q < 4; q++) { asm volatile("pause"); }
for (uint64_t q = 0; q < 8; q++) { asm volatile("pause"); }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 135
#define VERSION_BUILD 198
48 changes: 23 additions & 25 deletions kernel/arch/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
#include <stdint.h>
#include <tool.h>

extern "C" {
void sse_init( ) {
uint64_t _cr0 = 0;
asm volatile("mov %0, %%cr0" : "=r"(_cr0) : : "memory");
_cr0 &= ~(1 << 2);
_cr0 |= (1 << 1);
asm volatile("mov %%cr0, %0" : : "r"(_cr0) : "memory");

uint64_t _cr4 = 0;
asm volatile("mov %0, %%cr4" : "=r"(_cr4) : : "memory");
_cr4 |= (3 << 9);
asm volatile("mov %%cr4, %0" : : "r"(_cr4) : "memory");
}
}

namespace cpu {
static bool acpi_msrs_support = false;
static bool mmx_support = false;
Expand Down Expand Up @@ -102,28 +117,6 @@ void brandname( ) {
if (manufacturer[0] == 0x68747541) { do_amd( ); }
}

void sse_init( ) {
asm volatile("clts\n"
"mov %%cr0, %%rax\n"
"and $0xFFFD, %%ax\n"
"or $0x10, %%ax\n"
"mov %%rax, %%cr0\n"
"fninit\n"
"mov %%cr0, %%rax\n"
"and $0xfffb, %%ax\n"
"or $0x0002, %%ax\n"
"mov %%rax, %%cr0\n"
"mov %%cr4, %%rax\n"
"or $0x600, %%rax\n"
"mov %%rax, %%cr4\n"
"push $0x1F80\n"
"ldmxcsr (%%rsp)\n"
"addq $8, %%rsp\n"
:
:
: "rax");
}

void init( ) {
uint32_t eax, ebx, ecx, edx;
cpuid(1, &eax, &ebx, &ecx, &edx);
Expand All @@ -132,8 +125,8 @@ void init( ) {

if ((edx >> 22) & 1) {
acpi_msrs_support = true;
fb::printf("Температура: %u\n", get_cpu_temperature( ));
fb::printf("Встроенный терморегулятор MSRS для ACPI\n");
fb::printf("Температура: %u\n", get_cpu_temperature( ));
}

if ((edx >> 23) & 1) {
Expand All @@ -144,7 +137,7 @@ void init( ) {
if ((edx >> 25) & 1) {
sse2_support = true;
fb::printf("SSE2 подерживается!\n");
sse_init( );
// sse_init( );
}

cpuid(1, &eax, &ebx, &ecx, &edx);
Expand All @@ -164,7 +157,12 @@ void init( ) {
fb::printf("RDRND подерживается!\n");
}

cpuid(0x80000001, &eax, &ebx, &ecx, &edx);

if ((edx >> 11) & 1) { fb::printf("SYSCALL подерживается!\n"); }
if ((edx >> 29) & 1) { fb::printf("AMD64 подерживается!\n"); }

brandname( );
l2_cache( );
// l2_cache( );
}
} // namespace cpu
12 changes: 11 additions & 1 deletion kernel/fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static volatile struct limine_framebuffer_request framebuffer_request = {

struct limine_framebuffer_response *framebuffer_response;
struct limine_framebuffer *boot_framebuffer;
uint32_t *fb_addr;

uint32_t text_color = GREEN;
uint32_t background = DARK_GREEN;
uint64_t width;
Expand All @@ -46,12 +46,22 @@ void init( ) {
width = boot_framebuffer->width;
height = boot_framebuffer->height;
bpp = boot_framebuffer->bpp;
pitch = boot_framebuffer->pitch;

for (uint64_t i = 0; i < width * height; i++) { fb_addr[i] = background; }

fb::printf("0x%x %ux%u\n", fb_addr, width, height);
}

void print_buf(size_t x, size_t y, size_t h, size_t w, uint32_t *buf) {
for (size_t j = 0; j < h; j++) {
for (size_t i = 0; i < w; i++) {
uint64_t where = (i + x) + (j + y) * width;
SCREEN_BUFFER[where] = buf[i + j * w];
}
}
}

static inline void print_bits(size_t x, size_t y, uint8_t num) {
for (size_t i = 0; i <= 7; i++) {
if ((num >> i) & 1) {
Expand Down
Loading

0 comments on commit 4a233e1

Please sign in to comment.