merging from remote

Mainly adding support in write_cell() to use logical character indexes vs direct memory offsets
This commit is contained in:
Medium Fries 2019-01-23 17:45:00 -08:00
commit 88fad3c56e
8 changed files with 126 additions and 18 deletions

8
.gitignore vendored
View File

@ -1,5 +1,5 @@
*bochslog*
*.o
*.elf
./*o
./*elf
*o
*elf
*iso
*swp

35
framebuffer.c Normal file
View File

@ -0,0 +1,35 @@
// Driver implementation for Jank's text frame buffer
// Buffer can display 80 columns by 25 Rows
// Start of buffer is at (real)address 0x000B8000
// Memory at this section is divided into 16-bit cells
// | 15-8 | 7-4 | 0-3
// | Asci | FG | BG
#include "framebuffer.h"
static char* Frame_Buffer = (char*)FRAME_BUFFER_ADDR;
static char* Frame_Buffer_End = (char*)(FRAME_BUFFER_ADDR + AREA);
// Writes character to a given cell in the framebuffer
// @cell parameter is the logical (linear)index into the buffer
// _not_ the actual offset from the buffer addr
// also proper location is caller's responsibility
void write_cell(unsigned cell, char c, char fg, char bg) {
Frame_Buffer[cell*2] = c;
Frame_Buffer[cell+1] = (fg & 0x0f << 4) | (bg & 0x0f);
}
void clear_buffer() {
char* fp = Frame_Buffer;
while(fp!=Frame_Buffer_End) {
*fp = 0x00;
}
}
void print(char* str) {
for(unsigned i =0;i<strlen(str);i+=2) {
write_cell(i, str[i], Green, White);
}
}
void yote() {
print("asdf");
}

31
framebuffer.h Normal file
View File

@ -0,0 +1,31 @@
#include "stl/string.h"
#define COLUMNS 80
#define ROWS 25
#define AREA ( COLUMNS * ROWS )
#define FRAME_BUFFER_ADDR 0x000B8000
#define Black 0x01
#define Blue 0x02
#define Green 0x03
#define Cyan 0x04
#define Red 0x05
#define Magenta 0x05
#define Brown 0x06
#define LightGrey 0x07
#define DarkGrey 0x08
#define LightBlue 0x09
#define LightGreen 0x0a
#define LightCyan 0x0b
#define LightRed 0x0c
#define LightMagenta 0x0d
#define LightBrown 0x0e
#define White 0x0f
void write_cell(unsigned cell, char c , char fg, char bg);
void clear_buffer();
void print(char* str);
void yote();

View File

@ -5,6 +5,23 @@ MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
; size in bytes of stack
KERNEL_STACK_SIZE equ 4096
; external labels(cdecl) calling convention
extern yote
section .bss
align 4 ; aligning to bytes for x86(32-bit) reasons
; because this is the first thing we actually do (virual)address 0x00000000 will
; contain 4KB of memory for our stack
kernel_stack:
resb KERNEL_STACK_SIZE ; reserver bytes instruction
; point to what will be bottom of stack
; which will grow down towards (virtual)address 0x00000000
mov esp, kernel_stack + KERNEL_STACK_SIZE
section .text
; align all instructions to 4 byte boundary by the x86 instruction set law
align 4
@ -14,7 +31,7 @@ align 4
dd CHECKSUM
loader:
call yote
.loop:
jmp .loop

View File

@ -1,22 +1,22 @@
ASM=nasm
CC=gcc
ASM=nasm
LINK=ld
ISO=genisoimage
all: loader link iso
echo 'yeeting'
# build our loader
loader: loader.asm
# loading the kernel form loader.asm
# creates loader.o
$(ASM) -f elf32 loader.asm
OBJECTS=loader.o framebuffer.o
AFLAGS=-f elf32
CFLAGS=-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \
-nodefaultlibs -Wall -Wextra -Werror -c
# link the kernel to our loader
link: loader.o
$(LINK) -T link.ld -melf_i386 loader.o -o kernel.elf
all: kernel.elf
# build the iso file into our target directory
iso:
# Link objects together to produce the kernel object
kernel.elf: $(OBJECTS)
$(LINK) -T link.ld -melf_i386 $(OBJECTS) -o kernel.elf
# Builds image of our os
os.iso: kernel.elf
cp kernel.elf iso/boot/kernel.elf
$(ISO) -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
@ -27,3 +27,18 @@ iso:
-boot-info-table \
-o os.iso \
iso
# Building C objecets
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
# Builind asm objects
%.o: %.asm
$(ASM) $(AFLAGS) $< -o $@
# Running (no recipes called)
run: os.iso
bochs -f bochsrc.conf -q
clean:
rm -rf *.o kernel.elf os.iso bochslog.txt

BIN
os.iso

Binary file not shown.

2
scripts/run.sh Normal file
View File

@ -0,0 +1,2 @@
#!/zsh
bochs -f bochsrc.conf -q

8
stl/string.h Normal file
View File

@ -0,0 +1,8 @@
// our own stuff for stl utilities
unsigned strlen(const char* str) {
unsigned idx = 0;
while(str[idx])
idx++;
return idx;
}