Skip to content

Commit

Permalink
Начальный код инициализации
Browse files Browse the repository at this point in the history
  • Loading branch information
0Nera committed Sep 30, 2023
1 parent 6adf6fa commit 05d4a95
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 3 deletions.
Binary file removed boot/CYRILL1.F16
Binary file not shown.
Binary file removed boot/CYRILL2.F16
Binary file not shown.
Binary file removed boot/CYRILL3.F16
Binary file not shown.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
STANDART_FLAGS = "-std=gnu11"
PROTECT_FLAGS = "-O0 -pipe -ffreestanding -fno-stack-protector -fno-lto -fno-stack-check -fno-PIC -fno-PIE"
CHARSET_FLAGS = "-finput-charset=UTF-8 -fexec-charset=cp1251"
LIBS_FLAGS = "-Ilimine"
LIBS_FLAGS = "-Ilimine -Iinclude"


def find_files(directory, extensions):
Expand Down
4 changes: 2 additions & 2 deletions configs/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ TIMEOUT=5
DEFAULT_ENTRY=0
INTERFACE_BRANDING=By Aren Elchinyan

TERM_FONT=boot:///CYRILL2.F16
TERM_FONT_SIZE=8x16
#TERM_FONT=boot:///CYRILL2.F16
#TERM_FONT_SIZE=8x16

:MSEOS (KASLR on)
PROTOCOL=limine
Expand Down
3 changes: 3 additions & 0 deletions include/arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace arch {
void init();
}
3 changes: 3 additions & 0 deletions include/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace cpu {
void init();
}
3 changes: 3 additions & 0 deletions include/fb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace fb {
void init();
}
6 changes: 6 additions & 0 deletions include/tool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdarg.h>


namespace tool {
void format(void (*putc)(char c), const char *format_string, va_list args);
}
17 changes: 17 additions & 0 deletions kernel/arch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <limine.h>



namespace arch {
static volatile struct limine_kernel_address_request kernel_address_request = {
.id = LIMINE_KERNEL_ADDRESS_REQUEST,
.revision = 0,
.response = (struct limine_kernel_address_response *)0
};

struct limine_kernel_address_response *kernel_address_response;

void init() {
kernel_address_response = kernel_address_request.response;
}
}
15 changes: 15 additions & 0 deletions kernel/cpu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdint.h>
#include <stdbool.h>


namespace cpu {
static bool x87_support = false;
static bool sse_support = false;
static bool avx_support = false;

void init() {
x87_support = false;
sse_support = false;
avx_support = false;
}
}
32 changes: 32 additions & 0 deletions kernel/fb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <limine.h>



namespace fb {
static volatile struct limine_framebuffer_request framebuffer_request = {
.id = LIMINE_FRAMEBUFFER_REQUEST,
.revision = 0,
.response = (struct limine_framebuffer_response *)0
};

struct limine_framebuffer_response *framebuffer_response;
struct limine_framebuffer *boot_framebuffer;
uint32_t *fb_addr;
uint64_t width;
uint64_t height;
uint64_t pitch;
uint16_t bpp;

void init() {
framebuffer_response = framebuffer_request.response;
boot_framebuffer = framebuffer_response->framebuffers[0];
fb_addr = (uint32_t*)boot_framebuffer->address;
width = boot_framebuffer->width;
height = boot_framebuffer->height;
bpp = boot_framebuffer->bpp;

for (uint64_t i = 0; i < width * height; i++) {
fb_addr[i] = 0x0000FF;
}
}
}
8 changes: 8 additions & 0 deletions kernel/start.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#include <limine.h>
#include <arch.h>
#include <cpu.h>
#include <fb.h>
#include <tool.h>



// Точка входа
extern "C" void _start() {
asm volatile("cli");

arch::init();
cpu::init();
fb::init();

for (;;) {
asm volatile("hlt");
}
Expand Down
56 changes: 56 additions & 0 deletions kernel/tool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <limine.h>
#include <stdarg.h>
#include <stdint.h>

namespace tool {
// Функция для форматированного вывода
void format(void (*putc)(char c), const char *format_string, va_list args) {
while (*format_string != '\0') {
if (*format_string == '%') {
format_string++;
if (*format_string == '\0') {
break; // Неожиданный конец строки формата
}
if (*format_string == '%') {
putc('%'); // Вывод одного символа '%'
} else if (*format_string == 'd') {
int arg = va_arg(args, int);
// Преобразование целочисленного аргумента в строку и вывод каждого символа
if (arg < 0) {
putc('-');
arg = -arg;
}
if (arg == 0) {
putc('0');
} else {
char buffer[10]; // Предполагаем, что максимальное число из 10 цифр
int i = 0;

while (arg > 0) {
buffer[i++] = '0' + (arg % 10);
arg /= 10;
}

while (i > 0) {
putc(buffer[--i]);
}
}
} else if (*format_string == 's') {
const char* arg = va_arg(args, const char*);
// Вывод каждого символа строки
while (*arg != '\0') {
putc(*arg);
arg++;
}
} else {
// Неподдерживаемый спецификатор формата
putc('?');
}
} else {
putc(*format_string);
}

format_string++;
}
}
}

0 comments on commit 05d4a95

Please sign in to comment.