Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
603a3f3
updated make, string and kstring
CodeAnarchist Jul 18, 2025
8a70918
Update kstring.c
CodeAnarchist Jul 18, 2025
5578ed5
Update string.c
CodeAnarchist Jul 18, 2025
4cb9557
Update kstring.c
CodeAnarchist Jul 18, 2025
8211381
implemented linked list, chunked list, ring buffer
CodeAnarchist Jul 20, 2025
ad7568c
Merge branch 'hw' into hw
CodeAnarchist Jul 20, 2025
28c285f
Update Makefile
CodeAnarchist Jul 20, 2025
ed32ada
Update Makefile
CodeAnarchist Jul 20, 2025
9a229f0
queues and double linkedlist
CodeAnarchist Jul 21, 2025
f2c432d
Merge branch 'hw' into hw
CodeAnarchist Jul 24, 2025
582a73e
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
b9aa116
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
c7a2896
Update kconsole.h
CodeAnarchist Jul 25, 2025
2673f8e
Update kconsole.hpp
CodeAnarchist Jul 25, 2025
9a58907
Update fat32.cpp
CodeAnarchist Jul 25, 2025
38b04b7
Update kstring.c
CodeAnarchist Jul 25, 2025
c0e6bd8
Update chunked_list.cpp
CodeAnarchist Jul 25, 2025
6d5119b
Update chunked_list.hpp
CodeAnarchist Jul 25, 2025
18617b9
Update doubly_linked_list.cpp
CodeAnarchist Jul 25, 2025
b4c7d89
Update doubly_linked_list.hpp
CodeAnarchist Jul 25, 2025
3e0badc
Update linked_list.cpp
CodeAnarchist Jul 25, 2025
31aa644
Update linked_list.hpp
CodeAnarchist Jul 25, 2025
8711102
Update queue.cpp
CodeAnarchist Jul 25, 2025
6aaca80
Update queue.hpp
CodeAnarchist Jul 25, 2025
065b9d1
Update ring_buffer.cpp
CodeAnarchist Jul 25, 2025
1967c8f
Update ring_buffer.hpp
CodeAnarchist Jul 25, 2025
6cf11c5
Update string.c
CodeAnarchist Jul 25, 2025
1292655
Update doubly_linked_list.hpp
CodeAnarchist Jul 25, 2025
38b796c
Update Makefile
CodeAnarchist Jul 25, 2025
4ac1ef8
Update Makefile
CodeAnarchist Jul 25, 2025
4ad766f
Update Makefile
CodeAnarchist Jul 25, 2025
5bd3dfe
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
067282e
Update Makefile
CodeAnarchist Jul 25, 2025
0fb02c5
split data structures in .c/.h and .hpp
CodeAnarchist Jul 25, 2025
0d2d55f
rem xhci types h
CodeAnarchist Jul 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 58 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,97 @@
MODE ?= virt
LOAD_ADDR ?= 0x41000000
XHCI_CTX_SIZE ?= 32
QEMU ?= true
#top make
ARCH ?= aarch64-none-elf
CC := $(ARCH)-gcc
LD := $(ARCH)-ld
AR := $(ARCH)-ar
OBJCOPY := $(ARCH)-objcopy

OS := $(shell uname)
#common flags
CFLAGS_BASE ?= -g -O0 -std=c17 -nostdlib -ffreestanding \
-fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables \
-Wall -Wextra -mcpu=cortex-a72
LDFLAGS_BASE ?=

#build vars
LOAD_ADDR ?= 0x41000000
XHCI_CTX_SIZE ?= 32
QEMU ?= true
MODE ?= virt

#export
export ARCH CC LD AR OBJCOPY CFLAGS_BASE LDFLAGS_BASE LOAD_ADDR XHCI_CTX_SIZE QEMU

#config filesystem
OS := $(shell uname)
FS_DIRS := fs/redos/user

ifeq ($(OS),Darwin)
BOOTFS=/Volumes/bootfs
BOOTFS := /Volumes/bootfs
else
BOOTFS=/media/bootfs
BOOTFS := /media/bootfs
endif

.PHONY: all kernel user shared clean raspi virt run debug dump
#targets
.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install

all: shared user kernel
@echo "Build complete."
./createfs

dump:
aarch64-none-elf-objdump -D kernel.elf > dump

shared:
$(MAKE) -C shared

user:
user: prepare-fs
$(MAKE) -C user

kernel:
$(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) QEMU=$(QEMU)

clean:
$(MAKE) -C shared clean
$(MAKE) -C user clean
$(MAKE) -C kernel clean
$(MAKE) -C user clean
@echo "removing fs dirs"
rm -rf $(FS_DIRS)
@echo "removing images"
rm -f kernel.img kernel.elf disk.img dump

raspi:
$(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=true all

virt:
$(MAKE) LOAD_ADDR=0x41000000 XHCI_CTX_SIZE=32 QEMU=true all

run:
$(MAKE) $(MODE)
./run_$(MODE)

debug:
$(MAKE) $(MODE)
./rundebug MODE=$(MODE) $(ARGS)


dump:
$(OBJCOPY) -O binary kernel.elf kernel.img
aarch64-none-elf-objdump -D kernel.elf > dump

install:
$(MAKE) clean
$(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=false all
cp kernel.img $(BOOTFS)/kernel8.img
cp kernel.img $(BOOTFS)/kernel_2712.img
cp config.txt $(BOOTFS)/config.txt

run:
$(MAKE) $(MODE)
./run_$(MODE)
prepare-fs:
@echo "creating dirs"
@mkdir -p $(FS_DIRS)

help:
@printf "usage:\n\
make all build the os\n\
make clean remove all build artifacts\n\
make raspi build for raspberry\n\
make virt build for qemu virt board\n\
make run build and run in virt mode\n\
make debug build and run with debugger\n\
make dump disassemble kernel.elf\n\
make install create raspi kernel and mount it on a bootable partition\n\
make prepare-fs create directories for the filesystem\n\n"
36 changes: 16 additions & 20 deletions kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
ARCH= aarch64-none-elf
CC = $(ARCH)-gcc
LD = $(ARCH)-ld
OBJCOPY = $(ARCH)-objcopy

CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -DXHCI_CTX_SIZE=$(XHCI_CTX_SIZE) -mcpu=cortex-a72 -I. -I../shared -I../user
#kernel
# toolchain (inherited from top-level)

CFLAGS := $(CFLAGS_BASE) -I. -I../shared -I../user -DXHCI_CTX_SIZE=$(XHCI_CTX_SIZE)
ifeq ($(QEMU),true)
CFLAGS += -DQEMU
CFLAGS += -DQEMU
endif

LDFLAGS = -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR)
LDFLAGS := $(LDFLAGS_BASE) -T $(shell ls *.ld) --defsym=LOAD_ADDR=$(LOAD_ADDR)

C_SRC = $(shell find . -name '*.c')
ASM_SRC = $(shell find . -name '*.S')
CPP_SRC = $(shell find . -name '*.cpp')
OBJ = $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) $(ASM_SRC:.S=.o)
OBJL = $(filter-out ./boot.o, $(OBJ))
CLEAN_OBJS := $(shell find . -name '*.o')
C_SRC := $(shell find . -name '*.c')
ASM_SRC := $(shell find . -name '*.S')
CPP_SRC := $(shell find . -name '*.cpp')
OBJ := $(C_SRC:.c=.o) $(ASM_SRC:.S=.o) $(CPP_SRC:.cpp=.o)
OBJL := $(filter-out ./boot.o,$(OBJ))

TARGET = kernel.img
ELF = kernel.elf
ELF := ../kernel.elf
TARGET := ../kernel.img

all: $(TARGET)

$(TARGET): ../shared/libshared.a $(OBJ)
$(LD) $(LDFLAGS) -o ../$(ELF) $(OBJL) ../shared/libshared.a
$(OBJCOPY) -O binary ../$(ELF) ../$(TARGET)
$(LD) $(LDFLAGS) -o $(ELF) $(OBJL) ../shared/libshared.a
$(OBJCOPY) -O binary $(ELF) $@

%.o: %.S
$(CC) $(CFLAGS) -c $< -o $@

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

%.o: %.cpp
$(CC) $(CFLAGS) -fno-rtti -c $< -o $@

clean:
rm -f $(shell find . -name '*.o') ../$(ELF) ../$(TARGET) $(TARGET)
Comment thread
CodeAnarchist marked this conversation as resolved.
rm -f $(CLEAN_OBJS) $(ELF) $(TARGET)
146 changes: 70 additions & 76 deletions kernel/console/kconsole/kconsole.cpp
Original file line number Diff line number Diff line change
@@ -1,123 +1,117 @@
#include "kconsole.hpp"
#include "memory/kalloc.h"
#include "graph/graphics.h"
#include "console/serial/uart.h"

KernelConsole::KernelConsole()
: cursor_x(0), cursor_y(0), scroll_row_offset(0)
{
KernelConsole::KernelConsole() : cursor_x(0), cursor_y(0), is_initialized(false){
resize();
clear();
}

bool KernelConsole::check_ready(){
if (!gpu_ready()) return false;
if (!is_initialized){
is_initialized = true;
is_initialized= true;
resize();
clear();
}
return true;
}

void KernelConsole::resize() {
gpu_size screen = gpu_get_screen_size();
columns = screen.width / char_width;
rows = screen.height / char_height;
void KernelConsole::resize(){
gpu_size screen_size = gpu_get_screen_size();
columns = screen_size.width / char_width;
rows = screen_size.height / char_height;

if (buffer_header_size > 0)
temp_free(buffer,buffer_header_size);
if (buffer_data_size > 0)
temp_free(row_data,buffer_data_size);

buffer_header_size = rows * sizeof(char*);
buffer = (char**)talloc(rows * sizeof(char*));
buffer_data_size = rows * columns * sizeof(char);
if (row_data) temp_free(row_data, buffer_data_size);
buffer_data_size = rows * columns;
row_data = (char*)talloc(buffer_data_size);

for (unsigned int i = 0; i < rows; i++) {
buffer[i] = row_data + (i * columns);
}
}

void KernelConsole::put_char(char c) {
if (!check_ready())
return;

if (c == '\n') {
newline();
if (!row_data){
rows = columns = 0;
row_ring.clear();
return;
}

if (cursor_x >= columns)
newline();

buffer[(scroll_row_offset + cursor_y) % rows][cursor_x] = c;
gpu_draw_char({cursor_x * char_width, cursor_y * char_height}, c, 1, 0xFFFFFFFF);
cursor_x++;
row_ring.clear();
for (uint32_t i = 0; i < rows; i++) row_ring.push(i);
}

void KernelConsole::put_string(const char *str) {
if (!check_ready())
void KernelConsole::put_char(char c){
if (!check_ready()) return;
if (c == '\n'){
newline();
return;
for (uint32_t i = 0; str[i] != 0; i++) {
put_char(str[i]);
}
if (cursor_x >= columns) newline();

uint32_t row_index;
if (row_ring.pop(row_index)){
row_ring.push(row_index);
char* line = row_data + row_index * columns;
line[cursor_x] = c;
gpu_draw_char({cursor_x * char_width, cursor_y * char_height}, c, 1, 0xFFFFFFFF);
cursor_x++;
}
}

void KernelConsole::put_string(const char* str){
if (!check_ready()) return;
for (uint32_t i = 0; str[i]; i++) put_char(str[i]);
gpu_flush();
}

void KernelConsole::put_hex(uint64_t value) {
if (!check_ready())
return;
void KernelConsole::put_hex(uint64_t value){
if (!check_ready()) return;
put_char('0');
put_char('x');
bool started = false;
for (uint32_t i = 60;; i -= 4) {
for (uint32_t i = 60 ;; i -= 4){
uint8_t nibble = (value >> i) & 0xF;
char curr_char = nibble < 10 ? '0' + nibble : 'A' + (nibble - 10);
if (started || curr_char != '0' || i == 0) {
char current_char = nibble < 10 ? '0' + nibble : 'A' + (nibble - 10);
if (started || current_char != '0' || i == 0){
started = true;
put_char(curr_char);
put_char(current_char);
}
if (i == 0) break;
}

gpu_flush();
}

void KernelConsole::newline() {
if (!check_ready())
return;
for (unsigned x = cursor_x; x < columns; x++){
buffer[(scroll_row_offset + cursor_y) % rows][x] = 0;
void KernelConsole::newline(){
if (!check_ready()) return;
uint32_t row_index;
if (row_ring.pop(row_index)){
char* line = row_data + row_index * columns;
for (uint32_t x = cursor_x; x < columns; x++) line[x] = 0;
row_ring.push(row_index);
}
cursor_x = 0;
cursor_y++;
if (cursor_y >= rows) {
if (cursor_y >= rows){
scroll();
cursor_y = rows - 1;
}
}

void KernelConsole::scroll() {
if (!check_ready())
return;

scroll_row_offset = (scroll_row_offset + 1) % rows;

for (unsigned int x = 0; x < columns; x++) {
buffer[(scroll_row_offset + rows - 1) % rows][x] = 0;
void KernelConsole::scroll(){
if (!check_ready()) return;
uint32_t row_index;
if (row_ring.pop(row_index)){
char* line = row_data + row_index * columns;
for (uint32_t x = 0; x < columns; x++) line[x] = 0;
row_ring.push(row_index);
}

redraw();
}

void KernelConsole::redraw(){
screen_clear();
for (unsigned int y = 0; y < rows; y++) {
for (unsigned int x = 0; x < columns; x++) {
char c = buffer[(scroll_row_offset + y) % rows][x];
gpu_draw_char({x * char_width, y * char_height}, c, 1, 0xFFFFFFFF);
for (uint32_t y = 0; y < rows; y++){
uint32_t row_index;
if (row_ring.pop(row_index)){
row_ring.push(row_index);
char* line = row_data + row_index * columns;
for (uint32_t x = 0; x < columns; x++){
gpu_draw_char({x * char_width, y * char_height}, line[x], 1, 0xFFFFFFFF);
}
}
}
}
Expand All @@ -126,15 +120,15 @@ void KernelConsole::screen_clear(){
gpu_clear(0x0);
}

void KernelConsole::clear() {
void KernelConsole::clear(){
screen_clear();
for (unsigned int y = 0; y < rows; y++) {
for (unsigned int x = 0; x < columns; x++) {
buffer[y][x] = 0;
for (uint32_t i = 0; i < rows; i++){
uint32_t row_index;
if (row_ring.pop(row_index)){
char* line = row_data + row_index * columns;
for (uint32_t x = 0; x < columns; x++) line[x] = 0;
row_ring.push(row_index);
}
}
cursor_x = 0;
cursor_y = 0;
scroll_row_offset = 0;
gpu_flush();
}
cursor_x = cursor_y = 0;
}
2 changes: 1 addition & 1 deletion kernel/console/kconsole/kconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ void kconsole_clear();

#ifdef __cplusplus
}
#endif
#endif
Loading