Compare commits
10 Commits
5902ef62b1
...
cc1bb63e27
Author | SHA1 | Date | |
---|---|---|---|
cc1bb63e27 | |||
044d5a75b5 | |||
![]() |
ee7e44fbaf | ||
![]() |
9f793bfd2a | ||
![]() |
814f361e8b | ||
![]() |
6062641ec1 | ||
![]() |
ff89ecc49c | ||
![]() |
4487ddc0c8 | ||
![]() |
0ded150732 | ||
![]() |
332fbdcee0 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ rand/
|
|||||||
COM1.out
|
COM1.out
|
||||||
bx_enh_dbg.ini
|
bx_enh_dbg.ini
|
||||||
.vscode/
|
.vscode/
|
||||||
|
build/
|
||||||
|
@ -13,12 +13,13 @@ 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*2)) {
|
while(Frame_Buffer_Cursor != (AREA*8)) {
|
||||||
if((Frame_Buffer_Cursor % 160) == 0) {
|
if((Frame_Buffer_Cursor % 160) == 0) {
|
||||||
break;
|
break;
|
||||||
|
Frame_Buffer_Cursor+=160;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Frame_Buffer_Cursor++;
|
Frame_Buffer_Cursor+=2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
|
#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 {
|
||||||
@ -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_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
components/readme.md
Normal file
6
components/readme.md
Normal 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.
|
@ -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*);
|
||||||
|
|
@ -6,15 +6,21 @@
|
|||||||
#include "kbd.h"
|
#include "kbd.h"
|
||||||
#include "stlio.h"
|
#include "stlio.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "tests.h"
|
|
||||||
#include "shell.h"
|
#ifdef TESTING
|
||||||
|
#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,11 +19,13 @@ 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:
|
||||||
call kmain
|
.loop:
|
||||||
|
mov eax, 0xfeedbeef
|
||||||
|
jmp .loop
|
||||||
|
mov eax, 0xfeedbeef
|
||||||
|
|
||||||
.loop:
|
|
||||||
mov eax, 0xfeedbeef
|
|
||||||
jmp .loop
|
|
||||||
mov eax, 0xfeedbeef
|
|
||||||
|
|
24
makefile
24
makefile
@ -3,19 +3,21 @@ ASM=nasm
|
|||||||
LINK=ld
|
LINK=ld
|
||||||
ISO=genisoimage
|
ISO=genisoimage
|
||||||
|
|
||||||
OBJECTS=mem.o kernel.o gdt_seg.o gdt.o interrupts.o loader.o serial.o \
|
BUILD_DIR=build
|
||||||
framebuffer.o ports.o stlio.o tests.o interrupt_entry.o pit.o kbd.o\
|
|
||||||
shell.o
|
COMPONENTS=loader
|
||||||
|
# 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
|
||||||
|
|
||||||
all: kernel.elf
|
compile: kernel.elf
|
||||||
|
|
||||||
# Link objects together to produce the kernel object
|
# Link objects together to produce the kernel object
|
||||||
kernel.elf: $(OBJECTS)
|
kernel.elf: $(COMPONENTS)
|
||||||
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o kernel.elf
|
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o build/$@
|
||||||
|
|
||||||
# Builds image of our os
|
# Builds image of our os
|
||||||
jos.iso: kernel.elf
|
jos.iso: kernel.elf
|
||||||
@ -30,17 +32,15 @@ jos.iso: kernel.elf
|
|||||||
-o jos.iso \
|
-o jos.iso \
|
||||||
iso
|
iso
|
||||||
|
|
||||||
# Builind asm objects
|
# Components which make up the OS
|
||||||
%.o: %.s
|
loader: loader/main.s
|
||||||
$(ASM) $(AFLAGS) $< -o $@
|
$(ASM) $(AFLAGS) $< -o $(BUILD_DIR)/$@.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,11 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Setup script to grab any and all dependancies needed to build this on any of my machines
|
[ $(id -u) -ne 0 ] && echo Must run as root && exit 0
|
||||||
bochs_=$(dpkg --list | grep bochs)
|
|
||||||
if [ "$bochs_" == "" ]
|
dpkg -s bochs
|
||||||
then
|
if [ $? -ne 0 ];then
|
||||||
# install bochs shiz
|
apt install bochs-x
|
||||||
sudo apt-get update
|
fi
|
||||||
sudo apt-get install bochs "bochs-x"
|
|
||||||
else
|
gen=`dpkg --list | grep genisoimage`
|
||||||
echo 'Nothing to install'
|
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
|
fi
|
||||||
|
114
stlio.c
114
stlio.c
@ -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
23
stlio.h
@ -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
|
|
Loading…
Reference in New Issue
Block a user