Compare commits

..

10 Commits

Author SHA1 Message Date
cc1bb63e27 Moving components modules to a more proper directory 2023-03-30 22:40:08 -07:00
044d5a75b5 Loader moved into new build workflow 2023-03-30 22:17:49 -07:00
shockrah
ee7e44fbaf inlined a version of putch for better cache locality 2020-05-02 20:44:47 -07:00
shockrah
9f793bfd2a cursor should advance at proper rates now 2020-05-02 20:44:12 -07:00
shockrah
814f361e8b compile time tseting flags available in kernel_main 2020-05-02 20:43:50 -07:00
shockrah
6062641ec1 moved shell into its own projcet directory 2020-05-02 20:43:27 -07:00
shockrah
ff89ecc49c removing prompts 2020-04-22 20:52:26 -07:00
shockrah
4487ddc0c8 fixed merge in setup 2020-04-22 20:49:40 -07:00
shockrah
0ded150732 fixed check for bochs-x eumlator 2020-04-22 20:47:00 -07:00
shockrah
332fbdcee0 more comprehesive setup script
pulling in nasm and genisoimage packages for debian
2020-02-16 12:28:13 -08:00
32 changed files with 63 additions and 175 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ rand/
COM1.out
bx_enh_dbg.ini
.vscode/
build/

View File

@ -13,12 +13,13 @@ static u8* Frame_Buffer = (u8*)FRAME_BUFFER_ADDR;
s32 Frame_Buffer_Cursor = 0x0000;
void frame_buffer_newline() {
while(Frame_Buffer_Cursor != (AREA*2)) {
while(Frame_Buffer_Cursor != (AREA*8)) {
if((Frame_Buffer_Cursor % 160) == 0) {
break;
Frame_Buffer_Cursor+=160;
}
else {
Frame_Buffer_Cursor++;
Frame_Buffer_Cursor+=2;
}
}
}

View File

@ -1,6 +1,7 @@
#ifndef GDT_H
#define GDT_H
#include "types.h"
#define NO_GDT_ENTRIES 5
struct GDT_Entry {
@ -27,3 +28,5 @@ extern void load_gdt();
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran);
void gdt_configure();
#endif

View File

@ -151,7 +151,7 @@ common_irq_handler:
; Remapped IRQ's for the APIC
# starting from irq 0 -> 15 but remapped to 32 -> 47
; starting from irq 0 -> 15 but remapped to 32 -> 47
irq 0, 32
irq 1, 33
irq 2, 34

6
components/readme.md Normal file
View File

@ -0,0 +1,6 @@
# Components Library
These are the smaller components that give the kernel actual behaviors.
These are pieces that are *practically* required for the OS to function at a
basic level but otherwise are not *technically* required for sheer load-level
operations.

View File

@ -1,7 +1,7 @@
#include "shell.h"
#include "stlio.h"
#include "mem.h"
#include "pit.h"
#include "../stlio.h"
#include "../mem.h"
#include "../pit.h"
char line[LINE_LENGTH];

View File

@ -1,4 +1,4 @@
#include "types.h"
#include "../types.h"
void strip_newline(char*);

View File

@ -6,15 +6,21 @@
#include "kbd.h"
#include "stlio.h"
#include "mem.h"
#include "tests.h"
#include "shell.h"
#ifdef TESTING
#include "tests.h"
#endif
#include "jank-shell/shell.h"
void kinit() {
//gdt_configure();
init_idt();
pit_install_timer();
kbd_install_keyboard();
#ifdef TESTING
test_dispatcher();
#endif
}

View File

@ -1,4 +1,4 @@
; since we have no stack we have to create one for the OS
; Since we have no stack we have to create one for the OS
global loader
@ -7,7 +7,7 @@ MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
extern kmain
; extern kmain
section .text
; align all instructions to 4 byte boundary by the x86 instruction set law
@ -19,11 +19,13 @@ align 4
; sets up our gdt and segment selectors for later use
;loader:
; call kmain
loader:
call kmain
.loop:
mov eax, 0xfeedbeef
jmp .loop
mov eax, 0xfeedbeef
.loop:
mov eax, 0xfeedbeef
jmp .loop
mov eax, 0xfeedbeef

View File

@ -3,19 +3,21 @@ ASM=nasm
LINK=ld
ISO=genisoimage
OBJECTS=mem.o kernel.o gdt_seg.o gdt.o interrupts.o loader.o serial.o \
framebuffer.o ports.o stlio.o tests.o interrupt_entry.o pit.o kbd.o\
shell.o
BUILD_DIR=build
COMPONENTS=loader
# Rebuild the components var to be usable in recipes
OBJECTS := $(addprefix build/,$(addsuffix .o,$(COMPONENTS)))
AFLAGS=-f elf32
CFLAGS=-masm=intel -O2 -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \
-nodefaultlibs -Wall -Wextra -c #-Werror -c
all: kernel.elf
compile: kernel.elf
# Link objects together to produce the kernel object
kernel.elf: $(OBJECTS)
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o kernel.elf
kernel.elf: $(COMPONENTS)
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o build/$@
# Builds image of our os
jos.iso: kernel.elf
@ -30,17 +32,15 @@ jos.iso: kernel.elf
-o jos.iso \
iso
# Builind asm objects
%.o: %.s
$(ASM) $(AFLAGS) $< -o $@
# Components which make up the OS
loader: loader/main.s
$(ASM) $(AFLAGS) $< -o $(BUILD_DIR)/$@.o
# Building C objecets
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
# Running (no recipes called)
run: jos.iso
bochs -f bochsrc.conf -q
clean:
rm -f build/*
rm -rf *.o kernel.elf jos.iso bochslog.txt

View File

@ -1,11 +1,17 @@
#!/bin/bash
# Setup script to grab any and all dependancies needed to build this on any of my machines
bochs_=$(dpkg --list | grep bochs)
if [ "$bochs_" == "" ]
then
# install bochs shiz
sudo apt-get update
sudo apt-get install bochs "bochs-x"
else
echo 'Nothing to install'
[ $(id -u) -ne 0 ] && echo Must run as root && exit 0
dpkg -s bochs
if [ $? -ne 0 ];then
apt install bochs-x
fi
gen=`dpkg --list | grep genisoimage`
if [ -z "$gen" ]; then
apt-get install -y genisoimage
fi
nasm=`dpkg --list | grep nasm`
if [ -z "$nasm" ]; then
apt-get install -y nasm
fi

114
stlio.c
View File

@ -1,114 +0,0 @@
#include "types.h"
#include "kbd.h"
#include "stlio.h"
#include "pit.h"
extern char kbd_key;
extern u8 kbd_state;
static u8 COLOR_FG = Green;
static u8 COLOR_BG = White;
#define write_char(c) write_cell_fb(c, COLOR_FG, COLOR_BG)
// We are assuming null-terminated strings here
u32 strlen(const char* buffer) {
u32 i = 0;
char c = buffer[i];
while(c != '\0') {
i++;
c = buffer[i];
}
return i;
}
u32 strcmp(const char* left, const char* right) {
u32 s = strlen(left);
for(u32 i = 0; i<s; i++) {
if(left[i] != right[i]) {
return 1;
}
}
return 0;
}
u32 write(const char* buffer, const u32 size) {
u32 i;
for(i = 0; i < size; i++) {
// cheesy but whatever
if(buffer[i] == '\n') {
frame_buffer_newline();
}
else {
write_char(buffer[i]);
}
}
return i;
}
// this is here to get around gcc's optimizations
static void __char_set(u8* dest, u8 desire) {
*dest = desire;
}
u32 read(char* buffer, u32 size) {
// try the timing thing again after this
u32 bytes = 0;
u8 state = 0;
while(bytes < size) {
// All of these calls to __char_set is to avoid gcc from optimizing things away and ruining intended behavior
// Basically gcc will tread all assignments here as one time deals so we have to cram that operation into a routine
// by itself, that way the compiler won't try to optimize and do the assignment once. instead it does the call
// every iteration
__char_set(&state, kbd_state);
if(pit_timer_ticks - kbd_time < 0x20 && state == KBD_RELEASE) {
__char_set(&(buffer[bytes]), (u8)kbd_key);
if(kbd_key == '\n') {
putch('\n');
return bytes;
}
bytes++;
__char_set(&kbd_state, KBD_WAITING); // reset the kbd_state since we've now used it
putch(kbd_key);
}
pit_timer_wait(1);
}
kbd_key = KBD_RELEASE;
buffer[size-1] = '\0';
return bytes;
}
void printf(const char* fmt) {
// Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working
u32 size = strlen(fmt);
for(u32 i = 0; i < size;i++) {
if(fmt[i] == '\n') {
frame_buffer_newline();
}
else {
write_char(fmt[i]);
}
}
}
void printhex(u32 num) {
// Prints our hex version of whatever is given
const char _chars[] = "0123456789abcdef";
u32 idx = 0; // used as hash into the _chars mapping
// iterate over each nibble
printf("0x");
for(u32 i = 0 ;i < 8;i++) {
idx = (num << (i * 4)) & 0xf0000000;
idx = idx >> 28;
putch(_chars[idx]);
}
}
void putch(const char c) {
if(c == '\n') {
frame_buffer_newline();
}
else {
write_char(c);
}
}

23
stlio.h
View File

@ -1,23 +0,0 @@
#ifndef STLIO_H
#define STLIO_H
#include "types.h"
#include "framebuffer.h"
// Frame buffer driver
// NOTE: not getting computed at compile time so we always have a call
#define LINE_LENGTH COLUMNS
u32 strlen(const char*);
u32 strcmp(const char*, const char*);
u32 write(const char*, const u32);
u32 read(char*, u32);
void printf(const char*);
void printhex(u32);
void putch(const char);
#endif