init: it boots
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(termOS_krn LANGUAGES C ASM)
|
||||
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
add_compile_options(
|
||||
-ffreestanding
|
||||
-mno-red-zone
|
||||
-fno-stack-protector
|
||||
-fno-builtin
|
||||
-Wall -Wextra
|
||||
)
|
||||
|
||||
add_library(shitgui STATIC src/modules/shitgui.c)
|
||||
target_include_directories(shitgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
add_executable(kernel
|
||||
src/kmain.c
|
||||
src/modules/memory.c
|
||||
)
|
||||
|
||||
target_include_directories(kernel PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../common"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
target_link_libraries(kernel PRIVATE shitgui)
|
||||
|
||||
target_link_options(kernel PRIVATE
|
||||
-nostdlib
|
||||
-static
|
||||
-no-pie
|
||||
-T "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld"
|
||||
)
|
||||
|
||||
set_target_properties(kernel PROPERTIES
|
||||
OUTPUT_NAME "kernel.elf"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET kernel POST_BUILD
|
||||
COMMAND objcopy -O binary $<TARGET_FILE:kernel> $<TARGET_FILE_DIR:kernel>/kernel.bin
|
||||
COMMENT "Stripping ELF headers -> kernel.bin"
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void *memset(void *ptr, int value, usize num);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef SHITGUI_H
|
||||
#define SHITGUI_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
typedef struct {
|
||||
volatile u32 *fb;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 pitch;
|
||||
} SG_Context;
|
||||
typedef struct {
|
||||
u32 x;
|
||||
u32 y;
|
||||
} SG_Point;
|
||||
typedef struct {
|
||||
u32 *buffer;
|
||||
u32 height;
|
||||
u32 width;
|
||||
} SG_Image;
|
||||
|
||||
typedef struct {
|
||||
u32 font_w;
|
||||
u32 font_h;
|
||||
} SG_FontMetrics;
|
||||
|
||||
void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img);
|
||||
void sg_draw_rect(SG_Context *ctx, SG_Point *p, u32 w, u32 h, u32 color);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
typedef unsigned _BitInt(8) u8;
|
||||
typedef unsigned _BitInt(16) u16;
|
||||
typedef unsigned _BitInt(32) u32;
|
||||
typedef unsigned _BitInt(64) u64;
|
||||
|
||||
typedef signed _BitInt(8) i8;
|
||||
typedef signed _BitInt(16) i16;
|
||||
typedef signed _BitInt(32) i32;
|
||||
typedef signed _BitInt(64) i64;
|
||||
|
||||
typedef u64 usize;
|
||||
typedef u64 uintptr_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
ENTRY(kmain)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Смещаем точку сборки на 1МБ (как ты и грузишь) */
|
||||
. = 0x100000;
|
||||
|
||||
/* Сначала идет КОД. Это самое важное. */
|
||||
.text : {
|
||||
*(.text.entry) /* Если будет ассемблерный трамплин */
|
||||
*(.text*)
|
||||
}
|
||||
|
||||
.rodata : {
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.data : {
|
||||
*(.data*)
|
||||
}
|
||||
|
||||
.bss : {
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
/* ВЫРЕЗАЕМ ВЕСЬ МУСОР LINUX/GNU */
|
||||
/DISCARD/ : {
|
||||
*(.note*)
|
||||
*(.comment*)
|
||||
*(.eh_frame*)
|
||||
*(.interp) /* <--- Вот эта гадость содержала путь к ld-linux */
|
||||
*(.dynsym)
|
||||
*(.dynstr)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "../../common/bootinfo.h"
|
||||
#include "types.h"
|
||||
|
||||
#include "shitgui.h"
|
||||
|
||||
void kmain(Bootinfo* info) {
|
||||
u32 *fb = (u32*)info->base;
|
||||
if (!fb) return;
|
||||
|
||||
SG_Context sg_ctx = {0};
|
||||
sg_ctx.fb = fb;
|
||||
sg_ctx.height = info->height;
|
||||
sg_ctx.width = info->width;
|
||||
sg_ctx.pitch = info->pitch;
|
||||
|
||||
SG_Point p = {0};
|
||||
p.x = 0;
|
||||
p.y = 0;
|
||||
|
||||
u32 stripe_h = info->height / 5;
|
||||
|
||||
sg_draw_rect(&sg_ctx, &p, info->width, stripe_h, 0x5BCEFA);
|
||||
p.y += stripe_h;
|
||||
sg_draw_rect(&sg_ctx, &p, info->width, stripe_h, 0xF5A9B8);
|
||||
p.y += stripe_h;
|
||||
sg_draw_rect(&sg_ctx, &p, info->width, stripe_h, 0xFFFFFF);
|
||||
p.y += stripe_h;
|
||||
sg_draw_rect(&sg_ctx, &p, info->width, stripe_h, 0xF5A9B8);
|
||||
p.y += stripe_h;
|
||||
sg_draw_rect(&sg_ctx, &p, info->width, stripe_h, 0x5BCEFA);
|
||||
|
||||
while (1) { __asm__("hlt"); }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "types.h"
|
||||
|
||||
void *memset(void *ptr, int value, usize num) {
|
||||
u8 *p = (u8 *)ptr;
|
||||
while (num--) {
|
||||
*p++ = (u8)value;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// im really sorry for this code
|
||||
// but its called shitgui after all
|
||||
|
||||
#include "shitgui.h"
|
||||
|
||||
|
||||
void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img) {
|
||||
if (!ctx->fb || !img) return;
|
||||
|
||||
u32 start_x = p->x;
|
||||
u32 start_y = p->y;
|
||||
u32 draw_w = img->width;
|
||||
u32 draw_h = img->height;
|
||||
|
||||
if (start_x >= ctx->width || start_y >= ctx->height) return;
|
||||
if (start_x + draw_w > ctx->width) draw_w = ctx->width - start_x;
|
||||
if (start_y + draw_h > ctx->height) draw_h = ctx->height - start_y;
|
||||
|
||||
for (u32 y = 0; y < draw_h; y++) {
|
||||
volatile u32 *dest_ptr = &ctx->fb[(start_y + y) * ctx->pitch + start_x];
|
||||
u32 *src_ptr = &img->buffer[y * img->width];
|
||||
for (u32 x = 0; x < draw_w; x++) {
|
||||
dest_ptr[x] = src_ptr[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sg_draw_rect(SG_Context *ctx, SG_Point *p, u32 w, u32 h, u32 color) {
|
||||
if (!ctx->fb) return;
|
||||
|
||||
u32 start_x = p->x;
|
||||
u32 start_y = p->y;
|
||||
u32 draw_w = w;
|
||||
u32 draw_h = h;
|
||||
|
||||
if (start_x >= ctx->width || start_y >= ctx->height) return;
|
||||
if (start_x + draw_w > ctx->width) draw_w = ctx->width - start_x;
|
||||
if (start_y + draw_h > ctx->height) draw_h = ctx->height - start_y;
|
||||
|
||||
|
||||
for (u32 y = 0; y < draw_h; y++) {
|
||||
volatile u32 *row_ptr = &ctx->fb[(start_y + y) * ctx->pitch + start_x];
|
||||
for (u32 x = 0; x < draw_w; x++) row_ptr[x] = color;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user