This commit is contained in:
Benjamin Kyd
2019-04-25 21:39:31 +01:00
parent 4bc5392ca7
commit da858dfe76
14 changed files with 137 additions and 26 deletions

2
.gitignore vendored
View File

@@ -3,4 +3,4 @@ CMakeCache.txt
Makefile
cmake_install.cmake
.vscode/
./OwOS.bin
.vs/

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,12 +1,37 @@
#include <lib/std/stdlib.h>
#include <kernel/multiboot.h>
#include <kernel/drivers/terminal/terminal.h>
extern "C"
int kernel_main() {
int kernel_main(uint32_t magic, multibootInfo_t* multiboot) {
cls();
showCursor();
write("OwOS ");
setFGColour(VGA_GREEN);
write("Starting Up...");
setFGColour(VGA_WHITE);
nline();
write("OwO, What's This? ");
write("*notices ");
char* ram = "";
itoa((int)multiboot->mem_upper, ram);
write(ram);
write("mb of ram*");
setFGColour(VGA_BRIGHT_MAGENTA);
write(" OwO That's a lot of memory");
setFGColour(VGA_WHITE);
nline();
nline();
nline();
writeln("Okay, this is pretty epic");
for (;;)

View File

@@ -1,6 +1,7 @@
#include "terminal.h"
#include <kernel/kernio.h>
#include <lib/std/string.h>
static const int TERMINAL_WIDTH = 80;
static const int TERMINAL_HEIGHT = 24;
@@ -41,6 +42,12 @@ void puts(int x, int y, char c, char foreground, char background) {
frameBuffer[(y * TERMINAL_WIDTH) + x].background = background;
}
void nline() {
cursor.y++;
cursor.x = 0;
updateCursor(cursor);
}
void write(char* input) {
for (uint32_t i = 0; i < strlen(input); i++) {
if (cursor.x + 1 > TERMINAL_WIDTH) {
@@ -48,7 +55,8 @@ void write(char* input) {
}
if (input[i] == '\n') {
nline();
} else {
}
else {
puts(cursor.x, cursor.y, input[i], fgColour, bgColour);
cursor.x++;
}
@@ -61,12 +69,6 @@ void writeln(char* input) {
nline();
}
void nline() {
cursor.y++;
cursor.x = 0;
updateCursor(cursor);
}
void setClearColour(char col) {
clearColour = col;
}

View File

@@ -1,4 +1,5 @@
#include <lib/std/string.h>
#pragma once
#include <lib/stdint.h>
enum {
@@ -36,11 +37,11 @@ void cls();
void puts(char input);
void puts(int x, int y, char c, char foreground, char background);
void nline();
void write(char* input);
void writeln(char* input);
void nline();
void setClearColour(char col);
void setFGColour(char col);
void setBGColour(char col);

View File

@@ -1,3 +1,5 @@
#pragma once
#include <lib/stdint.h>
inline void outb(uint16_t port, uint8_t b) {

35
kernel/multiboot.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include <lib/stdint.h>
// Totally stolen from here https://forum.osdev.org/viewtopic.php?f=1&t=8881
struct multibootInfo_t {
uint32_t flags;
uint32_t mem_lower;
uint32_t mem_upper;
uint32_t boot_devices;
uint32_t cmdline;
uint32_t mods_count;
uint32_t mods_addr;
uint32_t syms_num;
uint32_t syms_size;
uint32_t syms_addr;
uint32_t syms_shndx;
uint32_t mmap_length;
uint32_t mmap_addr;
uint32_t drives_length;
uint32_t drives_addr;
uint32_t config_table;
char boot_loader_name[4];
uint32_t apm_table;
uint32_t vbe_control_info;
uint32_t vbe_mode_info;
uint16_t vbe_mode;
uint16_t vbe_interface_seg;
uint16_t vbe_interface_off;
uint16_t vbe_interface_len;
uint64_t framebuffer_addr;
uint32_t framebuffer_pitch;
uint32_t framebuffer_width;
uint32_t framebuffer_height;
};

View File

@@ -27,7 +27,7 @@ void* memmove(void* dst, const void* src, uint32_t size) {
for (uint32_t i = 0; i < size; i++)
d[i] = s[i];
else
for (uint32_t i = size; i--; )
for (uint32_t i = size; --i; )
d[i-1] = s[i-1];
return dst;
}

View File

@@ -1,3 +1,5 @@
#pragma once
#include <lib/stdint.h>
bool memcmp(const void* a, const void* b, uint32_t size);

37
lib/std/stdlib.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "stdlib.h"
#include "string.h"
void swap(int* x, int* y) {
int* t = x;
x = y;
y = t;
}
void reverse(char s[]) {
int i;
int j = strlen(s) - 1;
char c;
for (i = 0; i < j; i++) {
j--;
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
void itoa(int i, char[] s) {
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}

5
lib/std/stdlib.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
void swap(int* a, int* b);
void reverse(char s[])
void itoa(int i, char[] s);

View File

@@ -1,3 +1,5 @@
#pragma once
#include <lib/stdint.h>
uint32_t strlen(char* str);