-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b002e47
commit c1ba92f
Showing
121 changed files
with
4,903 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
MKDIR_P := mkdir -p | ||
OUT_DIR := $(PWD)/build | ||
export TOP_DIR=$(PWD) | ||
export LIB_DIR=${OUT_DIR}/lib | ||
export BIN_DIR=${OUT_DIR}/bin | ||
export ETC_DIR=${OUT_DIR}/etc | ||
export LD_LIBRARY_PATH:=${LIB_DIR}:$(LD_LIBRARY_PATH) | ||
|
||
SUBDIRS = \ | ||
src | ||
|
||
MAKE_UTILS_DIR := $(PWD)/makeUtils | ||
export MAKE_UTILS_DIR | ||
|
||
all: $(OUT_DIR) | ||
|
||
$(OUT_DIR): | ||
${MKDIR_P} $(LIB_DIR) $(BIN_DIR) $(ETC_DIR) | ||
|
||
clean: rmBuild | ||
|
||
rmBuild: | ||
rm -rf build iso/boot/kernel.elf bochsrc.txt bochslog.txt vivitsa.iso os.iso \ | ||
.DS_Store com1.out *.o *.so; | ||
|
||
# Include Common Makefile | ||
-include ${MAKE_UTILS_DIR}/Makefile.defs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Details | ||
|
||
Currently this operating system has kernel with interrupt, paging, hea0p, | ||
virtual file system support and multitasking. Yet to enable support for user | ||
space applications. | ||
(More information in Sandbox) | ||
|
||
## Usage | ||
|
||
### To build project | ||
|
||
```shell | ||
# -s for make quite | ||
$ ./build.sh -s | ||
``` | ||
|
||
### To run project | ||
|
||
```shell | ||
$ ./run.sh | ||
``` | ||
|
||
### To build with debug symbols | ||
|
||
```shell | ||
# -s for make quite, -g for debug | ||
$ ./build.sh -s -g | ||
``` | ||
|
||
### To run project in debug mode | ||
|
||
```shell | ||
$ ./run.sh -d | ||
``` | ||
|
||
#### Note: Make sure to build with debug symbols | ||
|
||
```shell | ||
$ gdb or gdbtui | ||
$ target remote localhost:1234 | ||
$ file build/bin/kernel.elf (loads debugging symbols from the file) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
make $1 clean | ||
|
||
make $1 D=$2 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
megs: 32 | ||
display_library: sdl2 | ||
romimage: file=/usr/share/bochs/BIOS-bochs-legacy | ||
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest | ||
ata0-master: type=cdrom, path=os.iso, status=inserted | ||
boot: cdrom | ||
log: bochslog.txt | ||
clock: sync=realtime, time0=local | ||
cpu: count=1, ips=1000000 | ||
com1: enabled=1, mode=file, dev=sandhu.out |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
default=0 | ||
timeout=0 | ||
|
||
title os | ||
kernel /boot/kernel.elf | ||
module /modules/initrd |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.PHONY: all clean install | ||
|
||
all: $(SUBDIRS) | ||
for subdir in $(SUBDIRS) ; do \ | ||
make -C $$subdir all || exit 1; \ | ||
done | ||
|
||
clean: $(SUBDIRS) rmOBJS | ||
for subdir in $(SUBDIRS) ; do \ | ||
make -C $$subdir clean ; \ | ||
done | ||
|
||
install: $(SUBDIRS) | ||
for subdir in $(SUBDIRS) ; do \ | ||
make -C $$subdir install || exit 1; \ | ||
done | ||
|
||
rmOBJS: | ||
rm -rf .DS_Store *.o *.so *.a *.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CC = gcc | ||
|
||
# Pass gdb debug flag from command line | ||
# Usage `make D=-g` | ||
CC += $(D) | ||
|
||
CFLAGS += -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \ | ||
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror | ||
|
||
AS = nasm | ||
ASFLAGS = -f elf | ||
|
||
C_SOURCES += $(wildcard *.c) | ||
S_SOURCES += $(wildcard *.s) | ||
C_OBJECTS += $(C_SOURCES:.c=.o) | ||
S_OBJECTS += $(S_SOURCES:.s=.o) | ||
|
||
LDFLAGS += \ | ||
-L$(LIB_DIR) \ | ||
|
||
INCLUDE += \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ "$#" -eq 1 ]; then | ||
if [ $1 = "-d" ]; then | ||
debug="-S"; | ||
echo "Running in debug mode" | ||
else | ||
echo " './run.sh -d' to run in debug mode" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
cp build/bin/kernel.elf iso/boot/kernel.elf | ||
|
||
genisoimage -R \ | ||
-b boot/grub/stage2_eltorito \ | ||
-no-emul-boot \ | ||
-boot-load-size 4 \ | ||
-A os \ | ||
-input-charset utf8 \ | ||
-quiet \ | ||
-boot-info-table \ | ||
-o sandhu.iso \ | ||
iso | ||
|
||
unset GTK_PATH # This is needed to run qemu on my system | ||
|
||
qemu-system-i386 -cdrom sandhu.iso -m 4G -s -serial stdio $debug |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SUBDIRS = \ | ||
drivers \ | ||
mm \ | ||
utils \ | ||
kernel \ | ||
|
||
|
||
# Include Common Makefile | ||
-include ${MAKE_UTILS_DIR}/Makefile.defs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SUBDIRS = \ | ||
frame_buffer \ | ||
interrupts \ | ||
io \ | ||
keyboard \ | ||
serial_port \ | ||
timer | ||
|
||
# Include Common Makefile | ||
-include ${MAKE_UTILS_DIR}/Makefile.defs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Include Common Makefile | ||
-include ${MAKE_UTILS_DIR}/Makefile.include | ||
|
||
# Include Common Makefile | ||
-include ${MAKE_UTILS_DIR}/Makefile.defs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "frame_buffer.h" | ||
#include <io.h> | ||
|
||
static int8_t *fb = (int8_t *)FB_BASE_ADDRESS; | ||
static uint16_t CURSOR_POS = 0; | ||
static uint16_t CURSOR_POS_MAX = 2000; | ||
static uint16_t BACKGROUND_COLOR = FB_GREEN; | ||
static uint16_t FOREGROUND_COLOR = FB_DARK_GREY; | ||
|
||
/* fb_move_cursor: | ||
* Moves the cursor of the framebuffer to the CURSOR_POS global variable | ||
*/ | ||
void fb_move_cursor() { | ||
outb(FB_COMMAND_PORT, FB_HIGH_BYTE_COMMAND); | ||
outb(FB_DATA_PORT, ((CURSOR_POS >> 8) & 0x00FF)); | ||
outb(FB_COMMAND_PORT, FB_LOW_BYTE_COMMAND); | ||
outb(FB_DATA_PORT, CURSOR_POS & 0x00FF); | ||
} | ||
|
||
/* fb_clear: | ||
* Clear the contents on screen between start position and end position | ||
* | ||
* @param start Starting position | ||
* @param end End position | ||
*/ | ||
|
||
void fb_clear(uint16_t start, uint16_t end) { | ||
for (uint16_t i = start; i < end; i++) { | ||
fb[2 * i] = ' '; | ||
fb[2 * i + 1] = ((FB_BLACK & 0x0F) << 4) | (FB_WHITE & 0x0F); | ||
} | ||
} | ||
|
||
void fb_clear_all() { | ||
fb_clear(0, CURSOR_POS_MAX); | ||
CURSOR_POS = 0; | ||
fb_move_cursor(); | ||
} | ||
|
||
/* fb_write_cell: | ||
* Writes a character with the given foreground and background to position i | ||
* in the framebuffer. | ||
* | ||
* @param i The location in the framebuffer | ||
* @param c The character | ||
* @param fg The foreground color | ||
* @param bg The background color | ||
*/ | ||
void fb_write_cell(int8_t c, uint8_t fg, uint8_t bg) { | ||
if (c == '\n') { | ||
uint16_t cursor_temp_pos = CURSOR_POS; | ||
CURSOR_POS = ((CURSOR_POS / 79) + 1) * 80; | ||
if (CURSOR_POS >= CURSOR_POS_MAX) { | ||
fb_clear(0, CURSOR_POS_MAX); | ||
CURSOR_POS = 0; | ||
} else { | ||
fb_clear(cursor_temp_pos, CURSOR_POS); | ||
} | ||
} else if (c != '\0') { | ||
if (CURSOR_POS >= CURSOR_POS_MAX) { | ||
fb_clear(0, CURSOR_POS_MAX); | ||
CURSOR_POS = 0; | ||
} | ||
fb[2 * CURSOR_POS] = c; | ||
fb[2 * CURSOR_POS + 1] = ((fg & 0x0F) << 4) | (bg & 0x0F); | ||
CURSOR_POS++; | ||
} | ||
} | ||
|
||
int32_t fb_write(int8_t *buf, uint32_t len) { | ||
uint32_t index_to_buffer = 0; | ||
while (index_to_buffer < len) { | ||
fb_write_cell(buf[index_to_buffer], BACKGROUND_COLOR, FOREGROUND_COLOR); | ||
fb_move_cursor(); | ||
index_to_buffer++; | ||
} | ||
return 0; | ||
} | ||
|
||
void fb_set_color(uint16_t background, uint16_t foreground) { | ||
BACKGROUND_COLOR = background; | ||
FOREGROUND_COLOR = foreground; | ||
} |
Oops, something went wrong.