Skip to content

Commit

Permalink
Cleaning up C Kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestonHager committed Dec 7, 2020
1 parent fbe0213 commit 2aee879
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -5,6 +5,10 @@
*.zip
*.tmp
*.img
*.elf

# debuging files that don't need to be added.
os.img.*

# stupid Apple files
.DS_Store
12 changes: 9 additions & 3 deletions bin/Makefile
@@ -1,7 +1,7 @@
# Default platform, change this to `win` for switching to some windows variables
platform=linux
# Default type of compilation, this affects the files we request later.
type=kernel
type=c

# Defining tools and commands.
# The Assembler (default=nasm):
Expand All @@ -22,6 +22,12 @@ else ifeq ($(type), c)
kernel=kernel/ckernel
files = $(bootloader).bin $(bootloader)_magic.binary $(kernel).bin
SYSTEM=arm
else ifeq ($(type), bare)
TOOL=arm-eabi
bootloader=startup
kerenl=bare_bones
files = $(kernel).bin
SYSTEM=arm
else
TOOL=
bootloader=bootloader_i386
Expand Down Expand Up @@ -56,9 +62,9 @@ endif
# run - makes `os.img` and runs it.
# clean - cleans all .o, .bin, .tmp files.

all: run clean
all: os.img clean

run: os.img
run: os.img clean
@ echo "Running the emulator using compiled image."
@ qemu-system-$(SYSTEM) -readconfig emulator_config.txt $(qemu_args)

Expand Down
17 changes: 10 additions & 7 deletions bin/bootloader/bootloader.c
Expand Up @@ -14,12 +14,15 @@ static void start_kernel(unsigned int pc, unsigned int sp) {
}

void main() {
unsigned int *kernel_code = (unsigned int *)__kernel_start__;
unsigned int kernel_sp = kernel_code[0];
unsigned int kernel_start = kernel_code[1];
unsigned char *video_mem = (unsigned char*) 0xb8000;
video_mem[80] = 'B';

start_kernel(kernel_start, kernel_sp);

// shouldn't be reached
while (1);
// unsigned int *kernel_code = (unsigned int *)__kernel_start__;
// unsigned int kernel_sp = kernel_code[0];
// unsigned int kernel_start = kernel_code[1];
//
// start_kernel(kernel_start, kernel_sp);
//
// // shouldn't be reached
// while (1);
}
6 changes: 4 additions & 2 deletions bin/kernel/ckernel.c
Expand Up @@ -7,6 +7,8 @@
#include "libs/stars.c"
#include "libs/planets.c"

#define VIDEO_MEMEORY 0x1c090000

// The list of registered stars, the number is the maximum number of stars that can be registered at once.
Star *KERNEL_STARS[64];
// A useful number to index the last free index of stars and to inquire about how full the registery is.
Expand Down Expand Up @@ -37,8 +39,8 @@ void kernel_start() {
}

void graphics_start() {
unsigned char *video_mem = (unsigned char*) 0xb8000;
video_mem[0] = 'A';
unsigned char *video_mem = (unsigned char*) VIDEO_MEMEORY;
video_mem[40] = 'A';
}

void star_planet_start() {
Expand Down
2 changes: 1 addition & 1 deletion bin/kernel/libs/graphics.c
Expand Up @@ -5,7 +5,7 @@
#include "graphics.h"
#include "io.c"

#define VIDEO_MEMORY_ADDRESS 0xb8000
#define VIDEO_MEMORY_ADDRESS 0x1c090000
#define COLUMNS 80
#define ROWS 25

Expand Down
1 change: 1 addition & 0 deletions bin/kernel/libs/planets.c
Expand Up @@ -8,6 +8,7 @@ Planet* new_planet(short id, void *on_next, void *on_error, void *on_complete) {
Planet *planet;
planet->id = id;
// Not sure if these do anything, it doesn't seem to actually set them.
// NOTE to future self: probably because you're dealing with pointers.
planet->on_next = on_next;
planet->on_error = on_error;
planet->on_complete = on_complete;
Expand Down
Binary file removed docs/.DS_Store
Binary file not shown.

0 comments on commit 2aee879

Please sign in to comment.