move stuff aroundd
This commit is contained in:
5
src/kernel/entry.asm
Normal file
5
src/kernel/entry.asm
Normal file
@@ -0,0 +1,5 @@
|
||||
section .text
|
||||
[bits 32]
|
||||
[extern init]
|
||||
call init
|
||||
jmp $
|
||||
7
src/kernel/kernel.c
Normal file
7
src/kernel/kernel.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "print.h"
|
||||
|
||||
void init(void)
|
||||
{
|
||||
print_init();
|
||||
println("Starting nub-os");
|
||||
}
|
||||
19
src/kernel/makefile
Normal file
19
src/kernel/makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
CC = i386-elf-gcc -ffreestanding -m32
|
||||
|
||||
kernel.bin: entry.o kernel.o mem.o print.o
|
||||
i386-elf-ld -o kernel.bin -Ttext 0x1000 entry.o kernel.o mem.o print.o --oformat binary
|
||||
|
||||
entry.o: entry.asm
|
||||
nasm -f elf -o entry.o entry.asm
|
||||
|
||||
kernel.o: kernel.c
|
||||
$(CC) -c -o kernel.o kernel.c
|
||||
|
||||
mem.o: mem.c
|
||||
$(CC) -c -o mem.o mem.c
|
||||
|
||||
print.o: print.c
|
||||
$(CC) -c -o print.o print.c
|
||||
|
||||
clean:
|
||||
@rm *.o *.bin 2>/dev/null || true
|
||||
26
src/kernel/mem.c
Normal file
26
src/kernel/mem.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "mem.h"
|
||||
|
||||
void* memcpy(void* dest, const void* src, long n)
|
||||
{
|
||||
char* d = dest;
|
||||
const char* s = src;
|
||||
for (long i = 0; i < n; i++)
|
||||
d[i] = s[i];
|
||||
return dest;
|
||||
}
|
||||
|
||||
void* memset(void* dest, int val, long n)
|
||||
{
|
||||
char* d = dest;
|
||||
for (long i = 0; i < n; i++)
|
||||
d[i] = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
long strlen(const char* str)
|
||||
{
|
||||
long len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
3
src/kernel/mem.h
Normal file
3
src/kernel/mem.h
Normal file
@@ -0,0 +1,3 @@
|
||||
void* memcpy(void* dest, const void* src, long n);
|
||||
void* memset(void* dest, int val, long n);
|
||||
long strlen(const char* str);
|
||||
41
src/kernel/print.c
Normal file
41
src/kernel/print.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "print.h"
|
||||
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
|
||||
char* vga_text_pos;
|
||||
|
||||
void print_init(void)
|
||||
{
|
||||
vga_text_pos = (char*)0xb8000;
|
||||
}
|
||||
|
||||
void print_newline(void)
|
||||
{
|
||||
vga_text_pos += 160 - ((vga_text_pos - (char*)0xb8000) % 160);
|
||||
}
|
||||
|
||||
void print_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color)
|
||||
{
|
||||
for (int i = 0; string[i]; i++)
|
||||
{
|
||||
*vga_text_pos++ = string[i];
|
||||
*vga_text_pos++ = (bg_color << 4) | fg_color;
|
||||
}
|
||||
}
|
||||
|
||||
void println_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color)
|
||||
{
|
||||
print_clr(string, fg_color, bg_color);
|
||||
print_newline();
|
||||
}
|
||||
|
||||
void print(const char* string)
|
||||
{
|
||||
print_clr(string, VGA_FG_WHITE, VGA_BG_BLACK);
|
||||
}
|
||||
|
||||
void println(const char* string)
|
||||
{
|
||||
println_clr(string, VGA_FG_WHITE, VGA_BG_BLACK);
|
||||
}
|
||||
41
src/kernel/print.h
Normal file
41
src/kernel/print.h
Normal file
@@ -0,0 +1,41 @@
|
||||
enum VGA_FG_COLOR
|
||||
{
|
||||
VGA_FG_BLACK = 0x0,
|
||||
VGA_FG_BLUE = 0x1,
|
||||
VGA_FG_GREEN = 0x2,
|
||||
VGA_FG_CYAN = 0x3,
|
||||
VGA_FG_RED = 0x4,
|
||||
VGA_FG_MAGENTA = 0x5,
|
||||
VGA_FG_BROWN = 0x6,
|
||||
VGA_FG_LIGHT_GRAY = 0x7,
|
||||
VGA_FG_DARK_GRAY = 0x8,
|
||||
VGA_FG_LIGHT_BLUE = 0x9,
|
||||
VGA_FG_LIGHT_GREEN = 0xA,
|
||||
VGA_FG_LIGHT_CYAN = 0xB,
|
||||
VGA_FG_LIGHT_RED = 0xC,
|
||||
VGA_FG_LIGHT_MAGENTA = 0xD,
|
||||
VGA_FG_YELLOW = 0xE,
|
||||
VGA_FG_WHITE = 0xF,
|
||||
};
|
||||
|
||||
enum VGA_BG_COLOR
|
||||
{
|
||||
VGA_BG_BLACK = 0x0,
|
||||
VGA_BG_BLUE = 0x1,
|
||||
VGA_BG_GREEN = 0x2,
|
||||
VGA_BG_CYAN = 0x3,
|
||||
VGA_BG_RED = 0x4,
|
||||
VGA_BG_MAGENTA = 0x5,
|
||||
VGA_BG_BROWN = 0x6,
|
||||
VGA_BG_LIGHT_GRAY = 0x7,
|
||||
};
|
||||
|
||||
void print_init(void);
|
||||
|
||||
void print_newline(void);
|
||||
|
||||
void print(const char* string);
|
||||
void println(const char* string);
|
||||
|
||||
void print_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color);
|
||||
void println_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color);
|
||||
Reference in New Issue
Block a user