Изменение структуры
This commit is contained in:
parent
a540661cf4
commit
fa67828241
|
@ -1,4 +1,4 @@
|
|||
ColumnLimit: 80
|
||||
ColumnLimit: 120
|
||||
IndentWidth: 4
|
||||
UseTab: ForIndentation
|
||||
TabWidth: 4
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
#define FONT_6X8_SLIM_CHAR_WIDTH 6
|
||||
#define FONT_6X8_SLIM_CHAR_HEIGHT 8
|
||||
#define FONT_6X8_SLIM_FONT_TYPE (FONT_TYPE_MONOSPACED)
|
||||
#define FONT_6X8_SLIM_ARRAY_LENGTH \
|
||||
(FONT_6X8_SLIM_LENGTH * FONT_6X8_SLIM_CHAR_HEIGHT)
|
||||
#define FONT_6X8_SLIM_ARRAY_LENGTH (FONT_6X8_SLIM_LENGTH * FONT_6X8_SLIM_CHAR_HEIGHT)
|
||||
|
||||
static const unsigned char font_6x8_slim[FONT_6X8_SLIM_ARRAY_LENGTH] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Символ 32 < >
|
||||
|
|
|
@ -35,8 +35,7 @@ enum colors {
|
|||
|
||||
#ifndef NO_DEBUG
|
||||
#define LOG(...) \
|
||||
fb_printf("[%u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, \
|
||||
__LINE__); \
|
||||
fb_printf("[%u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, __LINE__); \
|
||||
fb_printf(__VA_ARGS__)
|
||||
#else
|
||||
#define LOG(...)
|
||||
|
|
|
@ -18,16 +18,14 @@
|
|||
#define assert(check) \
|
||||
do { \
|
||||
if (!(check)) { \
|
||||
fb_printf("\nassert() failed in %s() (%s:%d)\n", __func__, \
|
||||
__FILE__, __LINE__); \
|
||||
fb_printf("\nassert() failed in %s() (%s:%d)\n", __func__, __FILE__, __LINE__); \
|
||||
for (;;) asm volatile("hlt"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALIGN_UP(NUM, ALIGN) (((NUM) + ALIGN - 1) & ~(ALIGN - 1))
|
||||
#define ALIGN_DOWN(NUM, ALIGN) ((NUM) & ~(ALIGN - 1))
|
||||
#define CONTAINER_OF(PTR, TYPE, MEMBER) \
|
||||
((TYPE *)((void *)PTR - offsetof(TYPE, MEMBER)))
|
||||
#define CONTAINER_OF(PTR, TYPE, MEMBER) ((TYPE *)((void *)PTR - offsetof(TYPE, MEMBER)))
|
||||
|
||||
#define BIT_SET(BIT) (bitmap[(BIT) / 8] |= (1 << ((BIT) % 8)))
|
||||
#define BIT_CLEAR(BIT) (bitmap[(BIT) / 8] &= ~(1 << ((BIT) % 8)))
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 1
|
||||
#define VERSION_BUILD 769
|
||||
#define VERSION_BUILD 771
|
||||
|
|
|
@ -14,19 +14,15 @@
|
|||
|
||||
static bool acpi_msrs_support = false;
|
||||
|
||||
static void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx,
|
||||
uint32_t *edx) {
|
||||
asm volatile("cpuid"
|
||||
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
|
||||
: "a"(leaf));
|
||||
static void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
|
||||
}
|
||||
|
||||
static void msr_get(uint32_t msr, uint32_t *lo, uint32_t *hi) {
|
||||
asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
|
||||
}
|
||||
|
||||
static void __attribute__((unused))
|
||||
msr_set(uint32_t msr, uint32_t lo, uint32_t hi) {
|
||||
static void __attribute__((unused)) msr_set(uint32_t msr, uint32_t lo, uint32_t hi) {
|
||||
asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
|
||||
}
|
||||
|
||||
|
@ -71,8 +67,7 @@ static void brandname( ) {
|
|||
uint32_t manufacturer[4];
|
||||
char manufacturer_string[13];
|
||||
|
||||
cpuid(0, &manufacturer[3], &manufacturer[0], &manufacturer[2],
|
||||
&manufacturer[1]);
|
||||
cpuid(0, &manufacturer[3], &manufacturer[0], &manufacturer[2], &manufacturer[1]);
|
||||
tool_memcpy(manufacturer_string, manufacturer, 12);
|
||||
|
||||
brand_string[48] = 0;
|
||||
|
@ -93,10 +88,7 @@ static void brandname( ) {
|
|||
}
|
||||
|
||||
void cpu_idle( ) {
|
||||
if (acpi_msrs_support) {
|
||||
LOG("Температура: %d (в QEMU/KVM всегда 0)\n",
|
||||
get_cpu_temperature_intel( ));
|
||||
}
|
||||
if (acpi_msrs_support) { LOG("Температура: %d (в QEMU/KVM всегда 0)\n", get_cpu_temperature_intel( )); }
|
||||
}
|
||||
|
||||
void cpu_init( ) {
|
||||
|
@ -111,8 +103,7 @@ void cpu_init( ) {
|
|||
if ((edx >> 22) & 1) {
|
||||
acpi_msrs_support = true;
|
||||
LOG("Встроенный терморегулятор MSRS для ACPI\n");
|
||||
LOG("Температура: %d (в QEMU/KVM всегда 0)\n",
|
||||
get_cpu_temperature_intel( ));
|
||||
LOG("Температура: %d (в QEMU/KVM всегда 0)\n", get_cpu_temperature_intel( ));
|
||||
}
|
||||
|
||||
cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
|
||||
|
@ -128,9 +119,7 @@ void cpu_init( ) {
|
|||
"поддерживается!\n");
|
||||
}
|
||||
|
||||
if ((edx >> 10) & 1) {
|
||||
LOG("SYSCALL/SYSRET(для AMD семейства 5 линейки 7) подерживаются!\n");
|
||||
}
|
||||
if ((edx >> 10) & 1) { LOG("SYSCALL/SYSRET(для AMD семейства 5 линейки 7) подерживаются!\n"); }
|
||||
if ((edx >> 11) & 1) { LOG("SYSCALL/SYSRET подерживаются!\n"); }
|
||||
|
||||
if ((edx >> 29) & 1) { LOG("AMD64 поддерживается!\n"); }
|
||||
|
@ -138,12 +127,8 @@ void cpu_init( ) {
|
|||
cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
|
||||
|
||||
if ((edx >> 0) & 1) { LOG("Датчик температуры поддерживается!\n"); }
|
||||
if ((edx >> 4) & 1) {
|
||||
LOG("Аппаратный терморегулятор (HTC) поддерживается!\n");
|
||||
}
|
||||
if ((edx >> 5) & 1) {
|
||||
LOG("Программный терморегулятор (STC) поддерживается!\n");
|
||||
}
|
||||
if ((edx >> 4) & 1) { LOG("Аппаратный терморегулятор (HTC) поддерживается!\n"); }
|
||||
if ((edx >> 5) & 1) { LOG("Программный терморегулятор (STC) поддерживается!\n"); }
|
||||
|
||||
brandname( );
|
||||
}
|
|
@ -38,8 +38,7 @@ void gdt_load( ) {
|
|||
load_gdt((uint64_t)&gdtr);
|
||||
}
|
||||
|
||||
void set_gdt_entry(gdt_entry_t *entry, uint16_t limit, uint64_t base,
|
||||
uint8_t access, uint8_t granularity) {
|
||||
void set_gdt_entry(gdt_entry_t *entry, uint16_t limit, uint64_t base, uint8_t access, uint8_t granularity) {
|
||||
entry->limit = limit;
|
||||
entry->base_16 = base & 0xFFFF;
|
||||
entry->base_middle_16 = (base >> 16) & 0xFF;
|
||||
|
|
|
@ -66,17 +66,15 @@ void exception_handler(struct frame state) {
|
|||
" RIP=%x RFLAGS=%x\n"
|
||||
" CS=%x SS=%x\n"
|
||||
" ERR=%x INT=%u",
|
||||
state.rax, state.rbx, state.rcx, state.rdx, state.rsi, state.rdi,
|
||||
state.rbp, state.rsp, state.r8, state.r9, state.r10, state.r11,
|
||||
state.r12, state.r13, state.r14, state.r15, state.rip, state.rflags,
|
||||
state.cs, state.ss, state.err, state.int_number);
|
||||
state.rax, state.rbx, state.rcx, state.rdx, state.rsi, state.rdi, state.rbp, state.rsp, state.r8, state.r9,
|
||||
state.r10, state.r11, state.r12, state.r13, state.r14, state.r15, state.rip, state.rflags, state.cs, state.ss,
|
||||
state.err, state.int_number);
|
||||
LOG("stack_top = %x\n", stack_top);
|
||||
|
||||
asm volatile("cli; hlt");
|
||||
}
|
||||
|
||||
static void idt_desc_setup(struct idt_desc *desc, unsigned sel, uintptr_t offs,
|
||||
unsigned flags) {
|
||||
static void idt_desc_setup(struct idt_desc *desc, unsigned sel, uintptr_t offs, unsigned flags) {
|
||||
desc->offs0 = offs & 0xfffful;
|
||||
desc->offs1 = (offs >> 16) & 0xfffful;
|
||||
desc->offs2 = (offs >> 32) & 0xfffffffful;
|
||||
|
@ -92,8 +90,7 @@ static void idt_load( ) {
|
|||
}
|
||||
|
||||
void idt_set_int(uint8_t vector, void *int_handler) {
|
||||
idt_desc_setup(&IDT[vector], KERNEL_CS, (uintptr_t)int_handler,
|
||||
IDT_INTERRUPT_FLAGS);
|
||||
idt_desc_setup(&IDT[vector], KERNEL_CS, (uintptr_t)int_handler, IDT_INTERRUPT_FLAGS);
|
||||
idt_load( );
|
||||
}
|
||||
|
||||
|
@ -112,8 +109,7 @@ void idt_init( ) {
|
|||
idt_desc_setup(&IDT[i], KERNEL_CS, handler, IDT_INTERRUPT_FLAGS);
|
||||
}
|
||||
|
||||
idt_desc_setup(&IDT[255], KERNEL_CS, (uintptr_t)isr_stubs[255],
|
||||
IDT_SPURIOUS_FLAGS);
|
||||
idt_desc_setup(&IDT[255], KERNEL_CS, (uintptr_t)isr_stubs[255], IDT_SPURIOUS_FLAGS);
|
||||
|
||||
idt_load( );
|
||||
LOG("IDT инициализирован\n");
|
||||
|
|
35
kernel/fb.c
35
kernel/fb.c
|
@ -16,9 +16,7 @@
|
|||
#include <tool.h>
|
||||
|
||||
static volatile struct limine_framebuffer_request framebuffer_request = {
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||
.revision = 0,
|
||||
.response = (struct limine_framebuffer_response *)0
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0, .response = (struct limine_framebuffer_response *)0
|
||||
};
|
||||
|
||||
static struct limine_framebuffer_response *framebuffer_response;
|
||||
|
@ -58,24 +56,18 @@ void fb_init( ) {
|
|||
|
||||
if (framebuffer_response->framebuffer_count == 1) { return; }
|
||||
|
||||
LOG("Инициализация дополнительных: %u мониторов\n",
|
||||
framebuffer_response->framebuffer_count);
|
||||
LOG("Инициализация дополнительных: %u мониторов\n", framebuffer_response->framebuffer_count);
|
||||
|
||||
for (uint64_t i = 1; i < framebuffer_response->framebuffer_count; i++) {
|
||||
struct limine_framebuffer *framebuffer =
|
||||
framebuffer_response->framebuffers[i];
|
||||
struct limine_framebuffer *framebuffer = framebuffer_response->framebuffers[i];
|
||||
uint32_t *framebuffer_addr = (uint32_t *)framebuffer->address;
|
||||
LOG("[%u]->0x%x %ux%u\n", i, framebuffer->address, framebuffer->width,
|
||||
framebuffer->height);
|
||||
for (uint64_t ij = 0; ij < width * height; ij++) {
|
||||
framebuffer_addr[ij] = background;
|
||||
}
|
||||
LOG("[%u]->0x%x %ux%u\n", i, framebuffer->address, framebuffer->width, framebuffer->height);
|
||||
for (uint64_t ij = 0; ij < width * height; ij++) { framebuffer_addr[ij] = background; }
|
||||
}
|
||||
}
|
||||
|
||||
// Отрисовка буффера по координатам (полезно для картинок)
|
||||
void fb_print_buf(uint64_t x, uint64_t y, uint64_t h, uint64_t w,
|
||||
uint32_t *buf) {
|
||||
void fb_print_buf(uint64_t x, uint64_t y, uint64_t h, uint64_t w, uint32_t *buf) {
|
||||
for (uint64_t j = 0; j < h; j++) {
|
||||
for (uint64_t i = 0; i < w; i++) {
|
||||
uint64_t where = (i + x) + (j + y) * width;
|
||||
|
@ -86,9 +78,7 @@ void fb_print_buf(uint64_t x, uint64_t y, uint64_t h, uint64_t 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) {
|
||||
SCREEN_BUFFER[x + i + y * SCREEN_WIDTH] = text_color;
|
||||
}
|
||||
if ((num >> i) & 1) { SCREEN_BUFFER[x + i + y * SCREEN_WIDTH] = text_color; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,20 +95,15 @@ static void print_char(int x, int y, char glyth) {
|
|||
}
|
||||
|
||||
void scroll_fb( ) {
|
||||
size_t last_line_index =
|
||||
(SCREEN_HEIGHT - (FONT_6X8_SLIM_CHAR_HEIGHT)) * SCREEN_WIDTH;
|
||||
size_t last_line_index = (SCREEN_HEIGHT - (FONT_6X8_SLIM_CHAR_HEIGHT)) * SCREEN_WIDTH;
|
||||
|
||||
for (uint64_t y = 0; y < SCREEN_HEIGHT - (FONT_6X8_SLIM_CHAR_HEIGHT); y++) {
|
||||
for (uint64_t x = 0; x < SCREEN_WIDTH; x++) {
|
||||
SCREEN_BUFFER[x + y * SCREEN_WIDTH] =
|
||||
SCREEN_BUFFER[x +
|
||||
(y + (FONT_6X8_SLIM_CHAR_HEIGHT)) * SCREEN_WIDTH];
|
||||
SCREEN_BUFFER[x + y * SCREEN_WIDTH] = SCREEN_BUFFER[x + (y + (FONT_6X8_SLIM_CHAR_HEIGHT)) * SCREEN_WIDTH];
|
||||
}
|
||||
}
|
||||
|
||||
for (uint64_t i = last_line_index; i < SCREEN_HEIGHT * SCREEN_WIDTH; i++) {
|
||||
SCREEN_BUFFER[i] = background;
|
||||
}
|
||||
for (uint64_t i = last_line_index; i < SCREEN_HEIGHT * SCREEN_WIDTH; i++) { SCREEN_BUFFER[i] = background; }
|
||||
}
|
||||
|
||||
// Вывод одного символа
|
||||
|
|
|
@ -31,24 +31,21 @@ typedef struct {
|
|||
|
||||
unsigned int *tga_parse(unsigned char *ptr, int size) {
|
||||
unsigned int *data;
|
||||
int i, j, k, x, y, w = (ptr[13] << 8) + ptr[12],
|
||||
h = (ptr[15] << 8) + ptr[14],
|
||||
o = (ptr[11] << 8) + ptr[10];
|
||||
int i, j, k, x, y, w = (ptr[13] << 8) + ptr[12], h = (ptr[15] << 8) + ptr[14], o = (ptr[11] << 8) + ptr[10];
|
||||
int m = ((ptr[1] ? (ptr[7] >> 3) * ptr[5] : 0) + 18);
|
||||
|
||||
if (w < 1 || h < 1) return NULL;
|
||||
|
||||
data = (unsigned int *)mem_alloc((w * h + 2) * sizeof(unsigned int));
|
||||
if (!data) {
|
||||
LOG("Ошибка декодирования TGA на строчке: %u, %x, %u kb\n", __LINE__,
|
||||
data, ((w * h + 2) * sizeof(unsigned int)) / 1024);
|
||||
LOG("Ошибка декодирования TGA на строчке: %u, %x, %u kb\n", __LINE__, data,
|
||||
((w * h + 2) * sizeof(unsigned int)) / 1024);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (ptr[2]) {
|
||||
case 1:
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 ||
|
||||
(ptr[7] != 24 && ptr[7] != 32)) {
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) {
|
||||
TGA_ERR( );
|
||||
mem_free(data);
|
||||
return NULL;
|
||||
|
@ -57,15 +54,13 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
k = ((!o ? h - y - 1 : y) * w);
|
||||
for (x = 0; x < w; x++) {
|
||||
j = ptr[m + k++] * (ptr[7] >> 3) + 18;
|
||||
data[2 + i++] = ((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) |
|
||||
(ptr[j + 2] << 16) | (ptr[j + 1] << 8) |
|
||||
ptr[j];
|
||||
data[2 + i++] =
|
||||
((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 ||
|
||||
(ptr[16] != 24 && ptr[16] != 32)) {
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) {
|
||||
TGA_ERR( );
|
||||
mem_free(data);
|
||||
return NULL;
|
||||
|
@ -74,15 +69,13 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
j = ((!o ? h - y - 1 : y) * w * (ptr[16] >> 3));
|
||||
for (x = 0; x < w; x++) {
|
||||
data[2 + i++] =
|
||||
((ptr[16] == 32 ? ptr[j + 3] : 0xFF) << 24) |
|
||||
(ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
((ptr[16] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
j += ptr[16] >> 3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 ||
|
||||
(ptr[7] != 24 && ptr[7] != 32)) {
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) {
|
||||
TGA_ERR( );
|
||||
mem_free(data);
|
||||
return NULL;
|
||||
|
@ -99,9 +92,8 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] =
|
||||
((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) |
|
||||
(ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
data[2 + i++] = ((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) |
|
||||
(ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
} else {
|
||||
k++;
|
||||
|
@ -112,16 +104,14 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] =
|
||||
((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) |
|
||||
(ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
data[2 + i++] = ((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) |
|
||||
(ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 ||
|
||||
(ptr[16] != 24 && ptr[16] != 32)) {
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) {
|
||||
TGA_ERR( );
|
||||
mem_free(data);
|
||||
return NULL;
|
||||
|
@ -137,9 +127,8 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] =
|
||||
((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) |
|
||||
(ptr[m + 2] << 16) | (ptr[m + 1] << 8) | ptr[m];
|
||||
data[2 + i++] = ((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) | (ptr[m + 2] << 16) |
|
||||
(ptr[m + 1] << 8) | ptr[m];
|
||||
}
|
||||
m += ptr[16] >> 3;
|
||||
} else {
|
||||
|
@ -150,9 +139,8 @@ unsigned int *tga_parse(unsigned char *ptr, int size) {
|
|||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] =
|
||||
((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) |
|
||||
(ptr[m + 2] << 16) | (ptr[m + 1] << 8) | ptr[m];
|
||||
data[2 + i++] = ((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) | (ptr[m + 2] << 16) |
|
||||
(ptr[m + 1] << 8) | ptr[m];
|
||||
m += ptr[16] >> 3;
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +164,7 @@ void main( ) {
|
|||
|
||||
tga_header_t *head = (tga_header_t *)bootpng_ptr;
|
||||
|
||||
if (res != NULL) {
|
||||
LOG("Размер экрана загрузки: %ux%u \n", res[0], res[1]);
|
||||
}
|
||||
if (res != NULL) { LOG("Размер экрана загрузки: %ux%u \n", res[0], res[1]); }
|
||||
LOG("Размер экрана загрузки: %ux%u \n", head->h, head->w);
|
||||
mem_dump_memory( );
|
||||
|
||||
|
|
45
kernel/mem.c
45
kernel/mem.c
|
@ -13,16 +13,12 @@
|
|||
#include <stdbool.h>
|
||||
#include <tool.h>
|
||||
|
||||
static volatile struct limine_memmap_request memmap_request = {
|
||||
.id = LIMINE_MEMMAP_REQUEST,
|
||||
static volatile struct limine_memmap_request memmap_request = { .id = LIMINE_MEMMAP_REQUEST,
|
||||
.revision = 0,
|
||||
.response = (struct limine_memmap_response *)0
|
||||
};
|
||||
static volatile struct limine_hhdm_request hhdm_request = {
|
||||
.id = LIMINE_HHDM_REQUEST,
|
||||
.response = (struct limine_memmap_response *)0 };
|
||||
static volatile struct limine_hhdm_request hhdm_request = { .id = LIMINE_HHDM_REQUEST,
|
||||
.revision = 0,
|
||||
.response = (struct limine_hhdm_response *)0
|
||||
};
|
||||
.response = (struct limine_hhdm_response *)0 };
|
||||
|
||||
struct mem_entry {
|
||||
struct mem_entry *next;
|
||||
|
@ -50,11 +46,9 @@ static uint64_t highest = 0;
|
|||
// Количество записей в карте памяти
|
||||
static uint64_t mmmap_count = 0;
|
||||
|
||||
static const char memory_types[8][82] = {
|
||||
"Доступно", "Зарезервировано", "ACPI, можно освободить",
|
||||
static const char memory_types[8][82] = { "Доступно", "Зарезервировано", "ACPI, можно освободить",
|
||||
"ACPI NVS", "Плохая память", "Загрузчик, можно освободить",
|
||||
"Ядро и модули", "Буфер кадра"
|
||||
};
|
||||
"Ядро и модули", "Буфер кадра" };
|
||||
|
||||
static struct limine_memmap_response *memmap_response;
|
||||
|
||||
|
@ -65,13 +59,10 @@ void mem_dump_memory( ) {
|
|||
|
||||
while (curr) {
|
||||
if (curr->next) {
|
||||
fb_printf("->0x%x | %u килобайт | %s | 0x%x\n", &curr->data,
|
||||
(curr->size) / 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1],
|
||||
curr->next);
|
||||
fb_printf("->0x%x | %u килобайт | %s | 0x%x\n", &curr->data, (curr->size) / 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1], curr->next);
|
||||
} else {
|
||||
fb_printf("->0x%x | %u килобайт | %s | Это последний блок\n",
|
||||
&curr->data, (curr->size) / 1024,
|
||||
fb_printf("->0x%x | %u килобайт | %s | Это последний блок\n", &curr->data, (curr->size) / 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1]);
|
||||
}
|
||||
curr = curr->next;
|
||||
|
@ -270,8 +261,7 @@ void mem_init( ) {
|
|||
if (mmaps[i]->type == LIMINE_MEMMAP_FRAMEBUFFER) {
|
||||
LOG("На видеопамять BIOS/UEFI выделено: %u мегабайт + %u "
|
||||
"килобайт\n",
|
||||
mmaps[i]->length / 1024 / 1024,
|
||||
(mmaps[i]->length / 1024) % 1024);
|
||||
mmaps[i]->length / 1024 / 1024, (mmaps[i]->length / 1024) % 1024);
|
||||
}
|
||||
if (!(mmaps[i]->type == LIMINE_MEMMAP_USABLE)) { continue; }
|
||||
|
||||
|
@ -299,22 +289,17 @@ void mem_init( ) {
|
|||
|
||||
// Освобождаем все доступные фреймы памяти
|
||||
for (uint64_t i = 0; i < mmmap_count; i++) {
|
||||
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) {
|
||||
bitmap_limit++;
|
||||
}
|
||||
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) { bitmap_limit++; }
|
||||
|
||||
if (!(mmaps[i]->type == LIMINE_MEMMAP_USABLE)) { continue; }
|
||||
|
||||
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) {
|
||||
mem_frame_free((void *)mmaps[i]->base + t, 1);
|
||||
}
|
||||
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) { mem_frame_free((void *)mmaps[i]->base + t, 1); }
|
||||
}
|
||||
|
||||
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
|
||||
LOG("Размер битовой карты: %u\n", bitmap_size);
|
||||
alloc_init(mem_frame_alloc(1), BLOCK_SIZE);
|
||||
LOG("%u мегабайт выделено в динамичную память\n",
|
||||
(256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
|
||||
LOG("%u мегабайт выделено в динамичную память\n", (256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
|
||||
|
||||
// Выделяем по 4 мегабайта в аллокатор динамичной памяти
|
||||
for (int64_t i = 0; i < 16; i += 4) {
|
||||
|
@ -323,8 +308,8 @@ void mem_init( ) {
|
|||
}
|
||||
mem_merge_all_blocks( );
|
||||
mem_dump_memory( );
|
||||
LOG("%u МБ объем доступной памяти, %u МБ объем виртуальной памяти\n",
|
||||
(bitmap_available * BLOCK_SIZE) / 1024 / 1024, available / 1024 / 1024);
|
||||
LOG("%u МБ объем доступной памяти, %u МБ объем виртуальной памяти\n", (bitmap_available * BLOCK_SIZE) / 1024 / 1024,
|
||||
available / 1024 / 1024);
|
||||
|
||||
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
|
||||
}
|
22
kernel/mod.c
22
kernel/mod.c
|
@ -13,11 +13,9 @@
|
|||
#include <sys.h>
|
||||
#include <tool.h>
|
||||
|
||||
static volatile struct limine_module_request module_request = {
|
||||
.id = LIMINE_MODULE_REQUEST,
|
||||
static volatile struct limine_module_request module_request = { .id = LIMINE_MODULE_REQUEST,
|
||||
.revision = 0,
|
||||
.response = (struct limine_module_response *)0
|
||||
};
|
||||
.response = (struct limine_module_response *)0 };
|
||||
|
||||
static struct limine_module_response *module_response;
|
||||
uint64_t modules_count = 0;
|
||||
|
@ -33,8 +31,7 @@ uint64_t bootpng_size;
|
|||
static void *elf_entry(elf64_header_t *module_bin) {
|
||||
// Приводим заголовок ELF файла к типу elf64_header_t
|
||||
elf64_header_t *elf_header = (elf64_header_t *)module_bin;
|
||||
LOG("(uint64_t)elf_header->e_entry = 0x%x, type = %u\n",
|
||||
(uint64_t)elf_header->e_entry, elf_header->e_type);
|
||||
LOG("(uint64_t)elf_header->e_entry = 0x%x, type = %u\n", (uint64_t)elf_header->e_entry, elf_header->e_type);
|
||||
if (elf_header->e_type != 2) {
|
||||
fb_printf("\t\tОшибка! Модуль неправильно собран!\n");
|
||||
for (;;) {}
|
||||
|
@ -58,9 +55,7 @@ void mod_list_show( ) {
|
|||
|
||||
module_info_t *mod_find(char *tag) {
|
||||
for (uint64_t i = 0; i < modules_count; i++) {
|
||||
if (tool_starts_with(module_list[i].name, tag)) {
|
||||
return &module_list[i];
|
||||
}
|
||||
if (tool_starts_with(module_list[i].name, tag)) { return &module_list[i]; }
|
||||
}
|
||||
return (module_info_t *)NULL;
|
||||
}
|
||||
|
@ -73,8 +68,8 @@ void mod_init( ) {
|
|||
for (uint64_t i = 0; i < module_count; i++) {
|
||||
module_ptr = module_response->modules[i];
|
||||
|
||||
LOG("[%d] %s [%s] 0x%x Размер: %u\n", i, module_ptr->path,
|
||||
module_ptr->cmdline, module_ptr->address, module_ptr->size);
|
||||
LOG("[%d] %s [%s] 0x%x Размер: %u\n", i, module_ptr->path, module_ptr->cmdline, module_ptr->address,
|
||||
module_ptr->size);
|
||||
|
||||
if (modules_count >= MOD_MAX) {
|
||||
LOG("Модуль не обработан. Максимум %u модулей!\n", MOD_MAX);
|
||||
|
@ -103,9 +98,8 @@ void mod_init( ) {
|
|||
continue;
|
||||
}
|
||||
|
||||
module_info_t (*module_init)(env_t *env) =
|
||||
(module_info_t(*)(env_t * env))
|
||||
elf_entry((elf64_header_t *)module_ptr->address);
|
||||
module_info_t (*module_init)(env_t * env) =
|
||||
(module_info_t(*)(env_t * env)) elf_entry((elf64_header_t *)module_ptr->address);
|
||||
|
||||
LOG("\t->Точка входа: 0x%x\n", module_init);
|
||||
|
||||
|
|
|
@ -87,10 +87,7 @@ void tool_int_to_str(int64_t i, uint8_t base, char *buf) {
|
|||
int64_t remainder = i % base;
|
||||
// Преобразовываем остаток в символ и добавляем его в строку
|
||||
buf[index++] =
|
||||
(remainder > 9)
|
||||
? (remainder - 10) + 'A'
|
||||
: remainder +
|
||||
'0'; // Если остаток > 9, добавляем заглавную букву А
|
||||
(remainder > 9) ? (remainder - 10) + 'A' : remainder + '0'; // Если остаток > 9, добавляем заглавную букву А
|
||||
i /= base;
|
||||
} while (i > 0);
|
||||
|
||||
|
@ -113,10 +110,7 @@ void tool_uint_to_str(uint64_t i, uint8_t base, char *buf) {
|
|||
uint64_t remainder = i % base;
|
||||
// Преобразовываем остаток в символ и добавляем его в строку
|
||||
buf[index++] =
|
||||
(remainder > 9)
|
||||
? (remainder - 10) + 'A'
|
||||
: remainder +
|
||||
'0'; // Если остаток > 9, добавляем заглавную букву А
|
||||
(remainder > 9) ? (remainder - 10) + 'A' : remainder + '0'; // Если остаток > 9, добавляем заглавную букву А
|
||||
i /= base;
|
||||
} while (i > 0);
|
||||
|
||||
|
@ -128,8 +122,7 @@ void tool_uint_to_str(uint64_t i, uint8_t base, char *buf) {
|
|||
}
|
||||
|
||||
// Функция для форматированного вывода
|
||||
void tool_format(void (*putc)(char c), const char *format_string,
|
||||
va_list args) {
|
||||
void tool_format(void (*putc)(char c), const char *format_string, va_list args) {
|
||||
while (*format_string != '\0') {
|
||||
if (*format_string == '%') {
|
||||
char buf[48];
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
|
||||
static char fxsave_region[512] __attribute__((aligned(16)));
|
||||
|
||||
static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,
|
||||
uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid"
|
||||
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
|
||||
: "a"(leaf));
|
||||
static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
|
||||
}
|
||||
|
||||
static inline void L1_cache_size( ) {
|
||||
|
@ -16,9 +13,8 @@ static inline void L1_cache_size( ) {
|
|||
fb_printf("L1 кэш недоступен\n");
|
||||
return;
|
||||
}
|
||||
fb_printf(
|
||||
"L1: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n",
|
||||
ecx & 0xff, (ecx >> 12) & 0x07, (ecx >> 16) & 0xffff);
|
||||
fb_printf("L1: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", ecx & 0xff, (ecx >> 12) & 0x07,
|
||||
(ecx >> 16) & 0xffff);
|
||||
}
|
||||
|
||||
static inline void L2_cache_size( ) {
|
||||
|
@ -28,9 +24,8 @@ static inline void L2_cache_size( ) {
|
|||
fb_printf("L2 кэш недоступен\n");
|
||||
return;
|
||||
}
|
||||
fb_printf(
|
||||
"L2: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n",
|
||||
ecx & 0xff, (ecx >> 12) & 0x0F, (ecx >> 16) & 0xFFFF);
|
||||
fb_printf("L2: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", ecx & 0xff, (ecx >> 12) & 0x0F,
|
||||
(ecx >> 16) & 0xFFFF);
|
||||
}
|
||||
|
||||
static inline void L3_cache_size( ) {
|
||||
|
@ -40,9 +35,8 @@ static inline void L3_cache_size( ) {
|
|||
fb_printf("L3 кэш недоступен\n");
|
||||
return;
|
||||
}
|
||||
fb_printf(
|
||||
"L3: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n",
|
||||
edx & 0xff, (edx >> 12) & 0x0F, (edx >> 16) & 0xFFFF);
|
||||
fb_printf("L3: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", edx & 0xff, (edx >> 12) & 0x0F,
|
||||
(edx >> 16) & 0xFFFF);
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
|
|
|
@ -25,40 +25,34 @@ static inline void outl(uint16_t port, uint32_t data) {
|
|||
asm volatile("outl %0, %1" : : "a"(data), "Nd"(port));
|
||||
}
|
||||
|
||||
static inline uint16_t pci_read_word(uint16_t bus, uint16_t slot, uint16_t func,
|
||||
uint16_t offset) {
|
||||
static inline uint16_t pci_read_word(uint16_t bus, uint16_t slot, uint16_t func, uint16_t offset) {
|
||||
uint64_t address;
|
||||
uint64_t lbus = (uint64_t)bus;
|
||||
uint64_t lslot = (uint64_t)slot;
|
||||
uint64_t lfunc = (uint64_t)func;
|
||||
uint16_t tmp = 0;
|
||||
address = (uint64_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) |
|
||||
(offset & 0xFC) | ((uint32_t)0x80000000));
|
||||
address = (uint64_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
|
||||
outl(0xCF8, address);
|
||||
tmp = (uint16_t)((inl(0xCFC) >> ((offset & 2) * 8)) & 0xFFFF);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
static inline uint16_t get_vendor_id(uint16_t bus, uint16_t device,
|
||||
uint16_t function) {
|
||||
static inline uint16_t get_vendor_id(uint16_t bus, uint16_t device, uint16_t function) {
|
||||
uint32_t r0 = pci_read_word(bus, device, function, 0);
|
||||
return r0;
|
||||
}
|
||||
|
||||
static inline uint16_t get_device_id(uint16_t bus, uint16_t device,
|
||||
uint16_t function) {
|
||||
static inline uint16_t get_device_id(uint16_t bus, uint16_t device, uint16_t function) {
|
||||
uint32_t r0 = pci_read_word(bus, device, function, 2);
|
||||
return r0;
|
||||
}
|
||||
|
||||
static inline uint16_t get_class_id(uint16_t bus, uint16_t device,
|
||||
uint16_t function) {
|
||||
static inline uint16_t get_class_id(uint16_t bus, uint16_t device, uint16_t function) {
|
||||
uint32_t r0 = pci_read_word(bus, device, function, 0xA);
|
||||
return (r0 & ~0x00FF) >> 8;
|
||||
}
|
||||
|
||||
static inline uint16_t get_sub_class_id(uint16_t bus, uint16_t device,
|
||||
uint16_t function) {
|
||||
static inline uint16_t get_sub_class_id(uint16_t bus, uint16_t device, uint16_t function) {
|
||||
uint32_t r0 = pci_read_word(bus, device, function, 0xA);
|
||||
return (r0 & ~0xFF00);
|
||||
}
|
||||
|
@ -102,8 +96,7 @@ static inline void scan( ) {
|
|||
char *name = find_vendor(vendor);
|
||||
fb_printf("[%u] %x [%s], устройство: %x, класс: %u, "
|
||||
"%u.%u.%u\n",
|
||||
devices, vendor, name, device_id, class_id, bus, slot,
|
||||
function);
|
||||
devices, vendor, name, device_id, class_id, bus, slot, function);
|
||||
fb_printf("\t\\->%s\n", get_class_name(class_id));
|
||||
|
||||
devices++;
|
||||
|
|
|
@ -6,13 +6,10 @@ typedef struct {
|
|||
} vendor_t;
|
||||
|
||||
static vendor_t **parse_file(char *str, uint64_t num_vendors, uint64_t size) {
|
||||
vendor_t **vendor_list =
|
||||
(vendor_t **)alloc(num_vendors * sizeof(vendor_t *));
|
||||
vendor_t **vendor_list = (vendor_t **)alloc(num_vendors * sizeof(vendor_t *));
|
||||
|
||||
if (vendor_list == NULL) { return NULL; }
|
||||
for (uint64_t i = 0; i < num_vendors; i++) {
|
||||
vendor_list[i] = (vendor_t *)alloc(sizeof(vendor_t));
|
||||
}
|
||||
for (uint64_t i = 0; i < num_vendors; i++) { vendor_list[i] = (vendor_t *)alloc(sizeof(vendor_t)); }
|
||||
|
||||
uint64_t i = 0;
|
||||
|
||||
|
@ -72,8 +69,7 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
|||
uint64_t num_vendors = count_chars(pci_data->data, ';');
|
||||
fb_printf("Количество вендоров: %u\n", num_vendors);
|
||||
|
||||
vendor_t **vendor_list =
|
||||
parse_file(pci_data->data, num_vendors, pci_data->data_size);
|
||||
vendor_t **vendor_list = parse_file(pci_data->data, num_vendors, pci_data->data_size);
|
||||
// print_vendors(num_vendors, vendor_list);
|
||||
return (module_info_t){
|
||||
.name = (char *)"[PCI][ADAPTER]",
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
|
||||
static char fxsave_region[512] __attribute__((aligned(16)));
|
||||
|
||||
static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,
|
||||
uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid"
|
||||
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
|
||||
: "a"(leaf));
|
||||
static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
|
|
1
run.sh
1
run.sh
|
@ -1,5 +1,6 @@
|
|||
#!/bin/sh
|
||||
qemu-system-x86_64 -name "БМПОС" -cpu max -m 1G -smp 1 \
|
||||
-bios ovmf/OVMF.fd \
|
||||
-drive file=bmosp.hdd,if=none,id=sata_drive -device ahci \
|
||||
-device virtio-blk-pci,drive=sata_drive --no-reboot
|
||||
#qemu-system-x86_64 -name "БМПОС" -cpu max -m 1G -smp 1 -hda bmosp.hdd --no-reboot
|
||||
|
|
|
@ -144,7 +144,7 @@ def create_hdd(IMAGE_NAME):
|
|||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M kernel.elf configs/limine.cfg limine/limine-bios.sys ::/")
|
||||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M modules/bin/* ::/mod")
|
||||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M limine/BOOTX64.EFI limine/BOOTIA32.EFI ::/EFI/BOOT")
|
||||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M boot.jpg boot.tga ::/")
|
||||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M boot.tga ::/")
|
||||
os.system(f"./limine/limine bios-install {IMAGE_NAME}.hdd")
|
||||
|
||||
|
||||
|
@ -152,7 +152,7 @@ def create_iso(IMAGE_NAME):
|
|||
os.system(f"rm -f {IMAGE_NAME}.iso")
|
||||
os.system(f"rm -rf iso_root")
|
||||
os.system(f"mkdir -p iso_root")
|
||||
os.system(f"cp -v kernel.elf boot.jpg boot.tga configs/limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/")
|
||||
os.system(f"cp -v kernel.elf boot.tga configs/limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/")
|
||||
os.system(f"mkdir -p iso_root/EFI/BOOT")
|
||||
shutil.copytree("modules/bin", "iso_root/mod")
|
||||
os.system(f"cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/")
|
Loading…
Reference in New Issue