Skip to content

Commit

Permalink
Merge pull request #3 from sasdallas/developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
sasdallas authored Mar 25, 2022
2 parents f3f5c2e + 65e637b commit 0f92257
Show file tree
Hide file tree
Showing 40 changed files with 1,374 additions and 169 deletions.
3 changes: 2 additions & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM gitpod/workspace-full-vnc


RUN sudo apt-get update && \
sudo apt-get install -y nasm grub-pc xorriso qemu-system-i386
sudo apt-get install -y nasm grub-pc xorriso qemu-system-i386
6 changes: 2 additions & 4 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

image:
file: .gitpod.Dockerfile

tasks:
- init: make
command: qemu-system-i386 build/reduce.bin

ports:
- port: 5900
onOpen: ignore
- port: 6080
onOpen: open-preview
onOpen: open-preview
208 changes: 73 additions & 135 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,135 +1,73 @@
# assembler
ASM = /usr/bin/nasm
# compiler
CC = /usr/bin/gcc
# linker
LD = /usr/bin/ld
GRUB = /usr/bin/grub-mkrescue
# sources
SRC = reduceOS
ASM_SRC = $(SRC)/assembly
# objects
OBJ = obj
ASM_OBJ = $(OBJ)/asm
CONFIG = ./config
OUT = build
INC = ./include
INCLUDE=-I$(INC)

MKDIR= mkdir -p
CP = cp -r
DEFINES=

# ASM flags
ASM_FLAGS = -f elf32
# CC flags
CC_FLAGS = $(INCLUDE) $(DEFINES) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
# Linker flags
LD_FLAGS = -m elf_i386 -T $(CONFIG)/linker.ld -nostdlib

#BIN file to create
TARGET=$(OUT)/reduce.bin
#ISO file to create - Not working currently, use bin file.
TARGET_ISO=$(OUT)/reduce.iso
ISO_DIR=$(OUT)/isodir

OBJECTS=$(ASM_OBJ)/boot.o $(ASM_OBJ)/load_gdt.o\
$(ASM_OBJ)/load_idt.o $(ASM_OBJ)/exception.o $(ASM_OBJ)/irq.o\
$(OBJ)/io_ports.o $(OBJ)/vga.o\
$(OBJ)/string.o $(OBJ)/console.o\
$(OBJ)/gdt.o $(OBJ)/idt.o $(OBJ)/isr.o $(OBJ)/8259_pic.o\
$(OBJ)/keyboard.o\
$(OBJ)/kernel.o


all: $(OBJECTS)
@printf "[ linking reduceOS... ]\n"
$(LD) $(LD_FLAGS) -o $(TARGET) $(OBJECTS)
grub-file --is-x86-multiboot $(TARGET)
@printf "\n"
@printf "[ building ISO... ]\n"
$(MKDIR) $(ISO_DIR)/boot/grub
$(CP) $(TARGET) $(ISO_DIR)/boot/
$(CP) $(CONFIG)/grub.cfg $(ISO_DIR)/boot/grub/
$(GRUB) -o $(TARGET_ISO) $(ISO_DIR)


$(ASM_OBJ)/boot.o : $(ASM_SRC)/boot.asm
@printf "[ $(ASM_SRC)/boot.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/boot.asm -o $(ASM_OBJ)/boot.o
@printf "\n"

$(ASM_OBJ)/load_gdt.o : $(ASM_SRC)/load_gdt.asm
@printf "[ $(ASM_SRC)/load_gdt.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/load_gdt.asm -o $(ASM_OBJ)/load_gdt.o
@printf "\n"

$(ASM_OBJ)/load_idt.o : $(ASM_SRC)/load_idt.asm
@printf "[ $(ASM_SRC)/load_idt.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/load_idt.asm -o $(ASM_OBJ)/load_idt.o
@printf "\n"

$(ASM_OBJ)/exception.o : $(ASM_SRC)/exception.asm
@printf "[ $(ASM_SRC)/exception.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/exception.asm -o $(ASM_OBJ)/exception.o
@printf "\n"

$(ASM_OBJ)/irq.o : $(ASM_SRC)/irq.asm
@printf "[ $(ASM_SRC)/irq.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/irq.asm -o $(ASM_OBJ)/irq.o
@printf "\n"

$(OBJ)/io_ports.o : $(SRC)/io_ports.c
@printf "[ $(SRC)/io_ports.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/io_ports.c -o $(OBJ)/io_ports.o
@printf "\n"

$(OBJ)/vga.o : $(SRC)/vga.c
@printf "[ $(SRC)/vga.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/vga.c -o $(OBJ)/vga.o
@printf "\n"

$(OBJ)/string.o : $(SRC)/string.c
@printf "[ $(SRC)/string.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/string.c -o $(OBJ)/string.o
@printf "\n"

$(OBJ)/console.o : $(SRC)/console.c
@printf "[ $(SRC)/console.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/console.c -o $(OBJ)/console.o
@printf "\n"

$(OBJ)/gdt.o : $(SRC)/gdt.c
@printf "[ $(SRC)/gdt.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/gdt.c -o $(OBJ)/gdt.o
@printf "\n"

$(OBJ)/idt.o : $(SRC)/idt.c
@printf "[ $(SRC)/idt.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/idt.c -o $(OBJ)/idt.o
@printf "\n"

$(OBJ)/isr.o : $(SRC)/isr.c
@printf "[ $(SRC)/isr.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/isr.c -o $(OBJ)/isr.o
@printf "\n"

$(OBJ)/8259_pic.o : $(SRC)/8259_pic.c
@printf "[ $(SRC)/8259_pic.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/8259_pic.c -o $(OBJ)/8259_pic.o
@printf "\n"

$(OBJ)/keyboard.o : $(SRC)/keyboard.c
@printf "[ $(SRC)/keyboard.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/keyboard.c -o $(OBJ)/keyboard.o
@printf "\n"

$(OBJ)/kernel.o : $(SRC)/kernel.c
@printf "[ $(SRC)/kernel.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/kernel.c -o $(OBJ)/kernel.o
@printf "\n"

clean:
rm -f $(OBJ)/*.o
rm -f $(ASM_OBJ)/*.o
rm -rf $(OUT)/*
ASM = /usr/bin/nasm
CC = /usr/bin/cc
LD = /usr/bin/ld
RM = /usr/bin/rm
GRUB = /usr/bin/grub-mkrescue
MKDIR = /usr/bin/mkdir
CP = /usr/bin/cp

SRC = reduceOS
ASM_SRC = $(SRC)/assembly
OBJ = obj
ASM_OBJ = $(OBJ)/asm
INCLUDE = include
INCLUDE_FLAG = -I$(INCLUDE)
CONFIG = config
OUT = build
ISODIR = $(OUT)/isodir/

MKDIR = mkdir -p
CP = cp -f

ASM_FLAGS = -f elf32
CC_FLAGS = $(INCLUDE_FLAG) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
LD_FLAGS = -m elf_i386 -T $(CONFIG)/linker.ld -nostdlib


SRCS := $(wildcard $(SRC)/*.c)
OBJS := $(patsubst $(SRC)/%.c,$(OBJ)/%.o,$(SRCS))
ASMS := $(wildcard $(ASM_SRC)/*.asm)
ASMOBJS := $(patsubst $(ASM_SRC)/%.asm,$(ASM_OBJ)/%.o,$(ASMS))




TARGET = $(OUT)/reduce.bin
TARGET_ISO = $(OUT)/reduce.iso

all: $(TARGET)


$(TARGET) : $(OBJS) $(ASMOBJS)
@printf "[ linking into bin... ]\n"
@$(LD) $(LD_FLAGS) $(OBJS) $(ASMOBJS) -o $(TARGET)

@printf "[ testing for x86 multiboot... ]\n"
@grub-file --is-x86-multiboot $(TARGET)
@printf "[ packing into ISO... ]\n"
@$(MKDIR) -pv $(ISODIR)/boot/grub/
@$(CP) $(TARGET) $(ISODIR)/boot/
@$(CP) $(CONFIG)/grub.cfg $(ISODIR)/boot/grub/
@$(GRUB) /usr/lib/grub/i386-pc -o $(TARGET_ISO) $(ISODIR)
@printf "[ done compiling reduceOS ]\n"
@printf "\n"



$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)
@printf "[ Compiling C program $<... ]\n"
@$(CC) $(CC_FLAGS) -c $< -o $@
@printf "\n"
$(ASM_OBJ)/%.o: $(ASM_SRC)/%.asm | $(ASM_OBJ)
@printf "[ Compiling ASM program $<... ]\n"
@$(ASM) $(ASM_FLAGS) $< -o $@
@printf "\n"

clean:
@printf "[ deleting C objects... ]\n"
$(RM) $(OBJ)/*.o
@printf "[ deleting ASM objects... ]\n"
$(RM) $(ASM_OBJ)/*.o
@printf "[ deleting build files... ]\n"
$(RM) -rf $(OUT)/*
@printf "[ done ]\n"
3 changes: 0 additions & 3 deletions build/isodir/boot/grub/grub.cfg

This file was deleted.

Binary file removed build/isodir/boot/reduce.bin
Binary file not shown.
Binary file modified build/reduce.bin
100644 → 100755
Binary file not shown.
Binary file removed build/reduce.iso
Binary file not shown.
13 changes: 12 additions & 1 deletion include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

#include "vga.h"

#define MAXIMUM_PAGES 16


void clearConsole(VGA_COLOR_TYPE fore_color, VGA_COLOR_TYPE back_color);

//initialize console
void initConsole(VGA_COLOR_TYPE fore_color, VGA_COLOR_TYPE back_color);


void consolePutchar(char ch);
// revert back the printed character and add 0 to it
void consoleUngetchar();
Expand All @@ -19,10 +23,17 @@ void consoleGoXY(uint16 x, uint16 y);
void consolePrintString(const char *str);
void printf(const char *format, ...);

void consolePrintColorString(char *str, VGA_COLOR_TYPE fore_color, VGA_COLOR_TYPE back_color);

// Get string from console

void getString(char *buffer);
// Get string from console and erase/go back until bound occcurs
void getStringBound(char *buffer, uint8 bound);
#endif


// Change color of all text
void setColor(VGA_COLOR_TYPE fore_color, VGA_COLOR_TYPE back_color);


#endif
Loading

0 comments on commit 0f92257

Please sign in to comment.