Compare commits
No commits in common. "cc1bb63e27b82b8f634283bbdb219c7f0a6cb723" and "5902ef62b1c61e19187fc087a4352834175bb12f" have entirely different histories.
cc1bb63e27
...
5902ef62b1
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,4 +9,3 @@ rand/
|
|||||||
COM1.out
|
COM1.out
|
||||||
bx_enh_dbg.ini
|
bx_enh_dbg.ini
|
||||||
.vscode/
|
.vscode/
|
||||||
build/
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# 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.
|
|
@ -13,13 +13,12 @@ static u8* Frame_Buffer = (u8*)FRAME_BUFFER_ADDR;
|
|||||||
s32 Frame_Buffer_Cursor = 0x0000;
|
s32 Frame_Buffer_Cursor = 0x0000;
|
||||||
|
|
||||||
void frame_buffer_newline() {
|
void frame_buffer_newline() {
|
||||||
while(Frame_Buffer_Cursor != (AREA*8)) {
|
while(Frame_Buffer_Cursor != (AREA*2)) {
|
||||||
if((Frame_Buffer_Cursor % 160) == 0) {
|
if((Frame_Buffer_Cursor % 160) == 0) {
|
||||||
break;
|
break;
|
||||||
Frame_Buffer_Cursor+=160;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Frame_Buffer_Cursor+=2;
|
Frame_Buffer_Cursor++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef GDT_H
|
|
||||||
#define GDT_H
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
#define NO_GDT_ENTRIES 5
|
#define NO_GDT_ENTRIES 5
|
||||||
|
|
||||||
struct GDT_Entry {
|
struct GDT_Entry {
|
||||||
@ -28,5 +27,3 @@ extern void load_gdt();
|
|||||||
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran);
|
void gdt_configure_entry(u32 entry, u32 base, u32 limit, u8 access, u8 gran);
|
||||||
|
|
||||||
void gdt_configure();
|
void gdt_configure();
|
||||||
|
|
||||||
#endif
|
|
@ -151,7 +151,7 @@ common_irq_handler:
|
|||||||
|
|
||||||
; Remapped IRQ's for the APIC
|
; 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 0, 32
|
||||||
irq 1, 33
|
irq 1, 33
|
||||||
irq 2, 34
|
irq 2, 34
|
@ -6,21 +6,15 @@
|
|||||||
#include "kbd.h"
|
#include "kbd.h"
|
||||||
#include "stlio.h"
|
#include "stlio.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "tests.h"
|
||||||
#ifdef TESTING
|
#include "shell.h"
|
||||||
#include "tests.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "jank-shell/shell.h"
|
|
||||||
|
|
||||||
void kinit() {
|
void kinit() {
|
||||||
//gdt_configure();
|
//gdt_configure();
|
||||||
init_idt();
|
init_idt();
|
||||||
pit_install_timer();
|
pit_install_timer();
|
||||||
kbd_install_keyboard();
|
kbd_install_keyboard();
|
||||||
#ifdef TESTING
|
|
||||||
test_dispatcher();
|
test_dispatcher();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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
|
global loader
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ MAGIC_NUMBER equ 0x1BADB002
|
|||||||
FLAGS equ 0x0
|
FLAGS equ 0x0
|
||||||
CHECKSUM equ -MAGIC_NUMBER
|
CHECKSUM equ -MAGIC_NUMBER
|
||||||
|
|
||||||
; extern kmain
|
extern kmain
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
; align all instructions to 4 byte boundary by the x86 instruction set law
|
; align all instructions to 4 byte boundary by the x86 instruction set law
|
||||||
@ -19,13 +19,11 @@ align 4
|
|||||||
|
|
||||||
; sets up our gdt and segment selectors for later use
|
; sets up our gdt and segment selectors for later use
|
||||||
|
|
||||||
;loader:
|
|
||||||
; call kmain
|
|
||||||
|
|
||||||
loader:
|
loader:
|
||||||
.loop:
|
call kmain
|
||||||
|
|
||||||
|
.loop:
|
||||||
mov eax, 0xfeedbeef
|
mov eax, 0xfeedbeef
|
||||||
jmp .loop
|
jmp .loop
|
||||||
mov eax, 0xfeedbeef
|
mov eax, 0xfeedbeef
|
||||||
|
|
||||||
|
|
24
makefile
24
makefile
@ -3,21 +3,19 @@ ASM=nasm
|
|||||||
LINK=ld
|
LINK=ld
|
||||||
ISO=genisoimage
|
ISO=genisoimage
|
||||||
|
|
||||||
BUILD_DIR=build
|
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\
|
||||||
COMPONENTS=loader
|
shell.o
|
||||||
# Rebuild the components var to be usable in recipes
|
|
||||||
OBJECTS := $(addprefix build/,$(addsuffix .o,$(COMPONENTS)))
|
|
||||||
|
|
||||||
AFLAGS=-f elf32
|
AFLAGS=-f elf32
|
||||||
CFLAGS=-masm=intel -O2 -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \
|
CFLAGS=-masm=intel -O2 -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \
|
||||||
-nodefaultlibs -Wall -Wextra -c #-Werror -c
|
-nodefaultlibs -Wall -Wextra -c #-Werror -c
|
||||||
|
|
||||||
compile: kernel.elf
|
all: kernel.elf
|
||||||
|
|
||||||
# Link objects together to produce the kernel object
|
# Link objects together to produce the kernel object
|
||||||
kernel.elf: $(COMPONENTS)
|
kernel.elf: $(OBJECTS)
|
||||||
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o build/$@
|
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o kernel.elf
|
||||||
|
|
||||||
# Builds image of our os
|
# Builds image of our os
|
||||||
jos.iso: kernel.elf
|
jos.iso: kernel.elf
|
||||||
@ -32,15 +30,17 @@ jos.iso: kernel.elf
|
|||||||
-o jos.iso \
|
-o jos.iso \
|
||||||
iso
|
iso
|
||||||
|
|
||||||
# Components which make up the OS
|
# Builind asm objects
|
||||||
loader: loader/main.s
|
%.o: %.s
|
||||||
$(ASM) $(AFLAGS) $< -o $(BUILD_DIR)/$@.o
|
$(ASM) $(AFLAGS) $< -o $@
|
||||||
|
|
||||||
|
# Building C objecets
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
# Running (no recipes called)
|
# Running (no recipes called)
|
||||||
run: jos.iso
|
run: jos.iso
|
||||||
bochs -f bochsrc.conf -q
|
bochs -f bochsrc.conf -q
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f build/*
|
|
||||||
rm -rf *.o kernel.elf jos.iso bochslog.txt
|
rm -rf *.o kernel.elf jos.iso bochslog.txt
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
[ $(id -u) -ne 0 ] && echo Must run as root && exit 0
|
# Setup script to grab any and all dependancies needed to build this on any of my machines
|
||||||
|
bochs_=$(dpkg --list | grep bochs)
|
||||||
dpkg -s bochs
|
if [ "$bochs_" == "" ]
|
||||||
if [ $? -ne 0 ];then
|
then
|
||||||
apt install bochs-x
|
# install bochs shiz
|
||||||
fi
|
sudo apt-get update
|
||||||
|
sudo apt-get install bochs "bochs-x"
|
||||||
gen=`dpkg --list | grep genisoimage`
|
else
|
||||||
if [ -z "$gen" ]; then
|
echo 'Nothing to install'
|
||||||
apt-get install -y genisoimage
|
|
||||||
fi
|
|
||||||
|
|
||||||
nasm=`dpkg --list | grep nasm`
|
|
||||||
if [ -z "$nasm" ]; then
|
|
||||||
apt-get install -y nasm
|
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "../stlio.h"
|
#include "stlio.h"
|
||||||
#include "../mem.h"
|
#include "mem.h"
|
||||||
#include "../pit.h"
|
#include "pit.h"
|
||||||
|
|
||||||
char line[LINE_LENGTH];
|
char line[LINE_LENGTH];
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "../types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void strip_newline(char*);
|
void strip_newline(char*);
|
||||||
|
|
114
stlio.c
Normal file
114
stlio.c
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
#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
Normal file
23
stlio.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#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
|
Loading…
Reference in New Issue
Block a user