Сделал базовое ядро
This commit is contained in:
parent
f9c16f1bf1
commit
43fdee65b9
67
kernel/kernel.c
Normal file
67
kernel/kernel.c
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
// fether os kernel.
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// protecting compilation.
|
||||||
|
#if defined(__linux__)
|
||||||
|
#error "You should compile all with a cross-compiler. See project wiki."
|
||||||
|
#elif !defined(__i386__)
|
||||||
|
#error "This is an 32bit kernel. Please use i386 target."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
volatile uint16_t* vga_buffer = (uint16_t*)0xB8000; // defining VGA text mode.
|
||||||
|
|
||||||
|
// vga(2) settings
|
||||||
|
const int VGA_COLS = 80;
|
||||||
|
const int VGA_ROWS = 25;
|
||||||
|
|
||||||
|
// terminal settings
|
||||||
|
int term_col = 0;
|
||||||
|
int term_row = 0;
|
||||||
|
uint8_t term_color = 0x0F;
|
||||||
|
|
||||||
|
// clearing the terminal
|
||||||
|
void term_init() {
|
||||||
|
for(int col = 0; col < VGA_COLS; col++) {
|
||||||
|
for(int row = 0; row < VGA_ROWS; row++) {
|
||||||
|
const size_t index = (VGA_COLS * row) + col;
|
||||||
|
vga_buffer[index] = ((uint16_t)term_color << 8) | ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void term_put(char c) {
|
||||||
|
switch(c) {
|
||||||
|
case '\n': // newline implemintation
|
||||||
|
{
|
||||||
|
term_col = 0;
|
||||||
|
term_row++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: // if char doesn't match any special symbol
|
||||||
|
{
|
||||||
|
const size_t index = (VGA_COLS * term_row) + term_col;
|
||||||
|
vga_buffer[index] = ((uint16_t)term_color << 8) | c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(term_col >= VGA_COLS) {
|
||||||
|
term_col = 0;
|
||||||
|
term_row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(term_row >= VGA_ROWS) {
|
||||||
|
term_col = 0;
|
||||||
|
term_row = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void term_print(const char* str) { for(size_t i = 0; str[i] != '\0'; i++) { term_put(str[i]); } }
|
||||||
|
|
||||||
|
void kmain() {
|
||||||
|
term_init();
|
||||||
|
term_print("Kernel loaded.\nFether.");
|
||||||
|
}
|
||||||
24
kernel/linker.ld
Normal file
24
kernel/linker.ld
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
. = 1M;
|
||||||
|
.rodata BLOCK(4K) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
*(.multiboot)
|
||||||
|
}
|
||||||
|
.text BLOCK(4K) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
*(.text)
|
||||||
|
}
|
||||||
|
.rodata BLOCK(4K) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
*(.rodata)
|
||||||
|
}
|
||||||
|
.data BLOCK(4K) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
*(.data)
|
||||||
|
}
|
||||||
|
.bss BLOCK(4K) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
*(COMMON)
|
||||||
|
*(.bss)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
kernel/start.s
Normal file
26
kernel/start.s
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
.extern kmain // entry
|
||||||
|
.global start
|
||||||
|
.set MB_MAGIC, 0x1BADB002
|
||||||
|
.set MB_FLAGS, (1 << 0) | (1 << 1)
|
||||||
|
.set MB_CHECKSUM, (0 - (MB_MAGIC + MB_FLAGS))
|
||||||
|
|
||||||
|
.section .multiboot
|
||||||
|
.align 4
|
||||||
|
.long MB_MAGIC
|
||||||
|
.long MB_FLAGS
|
||||||
|
.long MB_CHECKSUM
|
||||||
|
|
||||||
|
.section .bss
|
||||||
|
.align 16
|
||||||
|
stack_bottom:
|
||||||
|
.skip 4096
|
||||||
|
stack_top:
|
||||||
|
|
||||||
|
.section .text
|
||||||
|
start:
|
||||||
|
mov $stack_top, %esp
|
||||||
|
|
||||||
|
hang:
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
jmp hang
|
||||||
Loading…
Reference in a new issue