Skip to content

Commit

Permalink
FINALLY FFFFF
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandhu-Sahil committed Nov 23, 2023
1 parent b002e47 commit c1ba92f
Show file tree
Hide file tree
Showing 121 changed files with 4,903 additions and 0 deletions.
27 changes: 27 additions & 0 deletions SANDHU__OS/Makefile
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
42 changes: 42 additions & 0 deletions SANDHU__OS/README.md
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)
```
5 changes: 5 additions & 0 deletions SANDHU__OS/build.sh
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 added SANDHU__OS/build/bin/kernel.elf
Binary file not shown.
10 changes: 10 additions & 0 deletions SANDHU__OS/build/etc/bochsrc.txt
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 added SANDHU__OS/build/lib/libcommon.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libfs.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libgdt.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libidt.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libinitrd.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libio.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libkb.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libkheap.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/liblogger.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/liborderedarray.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libpaging.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libsched.a
Binary file not shown.
Binary file added SANDHU__OS/build/lib/libtimer.a
Binary file not shown.
6 changes: 6 additions & 0 deletions SANDHU__OS/iso/boot/grub/menu.lst
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 added SANDHU__OS/iso/boot/grub/stage2_eltorito
Binary file not shown.
Binary file added SANDHU__OS/iso/boot/kernel.elf
Binary file not shown.
Binary file added SANDHU__OS/iso/modules/initrd
Binary file not shown.
19 changes: 19 additions & 0 deletions SANDHU__OS/makeUtils/Makefile.defs
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
21 changes: 21 additions & 0 deletions SANDHU__OS/makeUtils/Makefile.include
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 += \
106 changes: 106 additions & 0 deletions SANDHU__OS/qemu.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
c[?7lSeaBIOS (version 1.15.0-1)


iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+BFF8B4A0+BFECB4A0 CA00
Press Ctrl-B to configure iPXE (PCI 00:03.0)...


Booting from Hard Disk...
Boot failed: could not read the boot disk

Booting from Floppy...
Boot failed: could not read the boot disk

Booting from DVD/CD...
Loading stage2 ....

GNU GRUB version 0.95 (639K lower / 3144576K upper memory)┌─────────────────────────────────────────────────────────────────────────┐││││││││││││││││││││││││└─────────────────────────────────────────────────────────────────────────┘
Use the ↑ and ↓ keys to select which entry is highlighted.
Press enter to boot the selected OS, 'e' to edit the
commands before booting, or 'c' for a command-line.  os               Booting 'os'

kernel /boot/kernel.elf
[Multiboot-elf, <0x100000:0x498b:0x0>, <0x105000:0x14e0:0x0>, <0x107000:0xa1
0:0x225c>, shtab=0x10a230, entry=0x100d7c]
module /modules/initrd
[Multiboot-module @ 0x10c000, 0x1349 bytes
==============================
Testing COM port... it works!!!

==============================
Testing Interrupt by raising interrupt 34
Recieved interrupt 34!!


==============================
Testing paging, trying to access address
Testing paging, trying to access address 1155104

Recieved interrupt 14!!
Page fault! ( ) at address = 1155104
Creating page at address 1155104
Out of page fault, page allocation works!!!

==============================
Testing kernel heap....
==============================
Testing kernel malloc....
Calling kmalloc() for allocating 8 bytes
kmalloc() allocated 8 bytes at address: 3221762116

Calling kmalloc() for allocating 10 bytes
kmalloc() allocated 10 bytes at address: 3221762144

Calling kmalloc() for allocating 8 bytes
kmalloc() allocated 8 bytes at address: 3221762174

==============================
Testing kernel free....
Calling kfree() to deallocate address: 3221762116

Calling kmalloc() for allocating 20 bytes
kmalloc() allocated 20 bytes at address: 3221762202

Calling kmalloc() for allocating 8 bytes
kmalloc() allocated 8 bytes at address: 3221762116

==============================
Testing Multiboot...
Mboot address loaded at 183680
Initrd loaded at address 1097728
Multiboot modules end at address 1102665
Number of modules loaded = 1

==============================
Testing virtual file system
reading contents of directory /dev

Found file -> file1.txt
contents: Hello, you just loaded first file from VFS!


Found file -> file2.txt
contents: This is the second file!



==============================
Testing multitasking
Calling process fork


==============================
fork() returned 2, and getpid() returned 1
============================================================================

==============================
Keyboard Enabled, type something!!!!


==============================
fork() returned 0, and getpid() returned 2
============================================================================

==============================
Keyboard Enabled, type something!!!!
qemu-system-i386: terminating on signal 15 from pid 1902 (/lib/systemd/systemd)
Expand Down
28 changes: 28 additions & 0 deletions SANDHU__OS/run.sh
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 added SANDHU__OS/sandhu.iso
Binary file not shown.
9 changes: 9 additions & 0 deletions SANDHU__OS/src/Makefile
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
10 changes: 10 additions & 0 deletions SANDHU__OS/src/drivers/Makefile
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
5 changes: 5 additions & 0 deletions SANDHU__OS/src/drivers/frame_buffer/Makefile
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
83 changes: 83 additions & 0 deletions SANDHU__OS/src/drivers/frame_buffer/frame_buffer.c
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;
}
Loading

0 comments on commit c1ba92f

Please sign in to comment.