Skip to content

[process-scheduler] Boot OS with terminal running simple shell #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
05dcf9e
Add half baked shell app
scopeInfinity Jul 25, 2021
4a8d6eb
Remove mov 'esp, ebp' pattern
scopeInfinity Jul 25, 2021
102f9fd
Rename existing exec syscall with spawn
scopeInfinity Jul 26, 2021
0b1553f
Simple 1 sec timer
scopeInfinity Jul 26, 2021
12ada3b
IRQ0 fetching and populating cs:ip,ss:sp as per process_scheduler
scopeInfinity Jul 26, 2021
34c7f09
Improvising create_infant_process_irq0_stack and reorganized kernel/ …
scopeInfinity Aug 10, 2021
ea87258
Allow IRQ remapping on IDT
scopeInfinity Aug 11, 2021
bee831b
Add IDT exceptions handlers to PANIC
scopeInfinity Aug 11, 2021
3099b5a
Allow GDB to see symbol table in view_kernelmode
scopeInfinity Aug 12, 2021
7a133d0
Export debug info within nasm object
scopeInfinity Aug 13, 2021
cbe77a7
Bug fix: irq0_pit_handler_low should keep ss,sp,cs,ip values on stack…
scopeInfinity Aug 13, 2021
5383cfd
[process_scheduler] bug fix: iret should have correct return address
scopeInfinity Aug 13, 2021
59167b3
Add stdarg.h for va_arg and printf
scopeInfinity Aug 13, 2021
4f1bab7
Add SYSCALL_PROCESS_SUB_EXIT
scopeInfinity Aug 14, 2021
491fa96
Add /usr/bin/ to minimal_disk
scopeInfinity Aug 14, 2021
58b531a
Add process spawn by filename syscall
scopeInfinity Aug 14, 2021
4d6c8c9
[process_scheduler] Multiple process sequential computing using spawn…
scopeInfinity Aug 14, 2021
876251f
Fixed text VGA scroll, improve process unallocation in scheduler
scopeInfinity Aug 14, 2021
267d587
Remove kernel dependency on /usr/bin/* location in image.vmdk
scopeInfinity Aug 14, 2021
0fc5840
cleanup real_mode library stub as we are using stack from sometime
scopeInfinity Aug 14, 2021
70a8efd
Define INIT_APPNAME at compile-time and let tests use it
scopeInfinity Aug 14, 2021
5fee290
Remove concept of make configure; we know have simple FS
scopeInfinity Aug 14, 2021
2436232
Bug fix: Incorrect start data block for FFS partition
scopeInfinity Aug 14, 2021
6455d49
Update README.md; Add simple shell screenshot
scopeInfinity Aug 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set $SS_BASE = 0x20000

# config
set architecture i386:x86-64

set pagination off
set prompt \033[32mgdb$ \033[0m

Expand All @@ -21,7 +22,11 @@ define cprintdata
end

define casm
x/20i ($CS_BASE+$pc)
x/10i ($CS_BASE+$pc)
end

define ccode
list *$pc
end

define cstack
Expand All @@ -43,6 +48,8 @@ define clayout
echo \033c
_clayout_title ASM
casm
_clayout_title Code
ccode
_clayout_title Register
creg
_clayout_title Stack
Expand All @@ -60,20 +67,23 @@ define view_realmode
set $CS_BASE = 0x0000
set $DS_BASE = 0x0000
set $SS_BASE = 0x0000
symbol-file build/bootloader/stage2.elf
clayout
end

define view_kernelmode
set $CS_BASE = 0xC000
set $DS_BASE = 0xC000
set $SS_BASE = 0xC000
symbol-file build/kernel/core.elf
clayout
end

define view_usermode
set $CS_BASE = 0x20000
set $DS_BASE = 0x20000
set $SS_BASE = 0x20000
symbol-file
clayout
end

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
- name: Prerequisite
run: sudo bash before_install.sh

- name: make configure
run: make configure

- name: make
run: make

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
- name: Prerequisite
run: sudo bash before_install.sh

- name: make configure
run: make configure

- name: make
run: make

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.vmdk
*.o
configure
local_notes/
build/
src_test/
Expand Down
90 changes: 54 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Program to auto start when kernel is ready.
# List of program can be found at build/usr/bin/
# Some of them are
# sh.out
# ls.out
# tictactoe.out
# calc.out
INIT_APPNAME ?= sh.out

ROOT_DIR = .
BUILD_DIR = build
INCLUDE_DIR = include/fuzzy
Expand All @@ -9,6 +18,8 @@ SELF_BUILD_DIR = $(patsubst $(SRC_DIR)/%,$(BUILD_DIR)/%,$(SELF_SRC_DIR))

SELF_SRC_ALL_C = $(shell find $(SELF_SRC_DIR) -name '*.c')
SELF_BUILD_ALL_C = $(patsubst $(SELF_SRC_DIR)/%.c,$(SELF_BUILD_DIR)/%.o,$(SELF_SRC_ALL_C))
SELF_SRC_ALL_ASM = $(shell find $(SELF_SRC_DIR) -name '*.asm')
SELF_BUILD_ALL_ASM = $(patsubst $(SELF_SRC_DIR)/%.asm,$(SELF_BUILD_DIR)/%_asm.o,$(SELF_SRC_ALL_ASM))

SRC_BOOTLOADER = $(SRC_DIR)/bootloader
SRC_KERNEL = $(SRC_DIR)/kernel
Expand Down Expand Up @@ -38,20 +49,11 @@ rm_static = $(BUILD_REALMODE)/static_library
# Kernel
kernel_core = $(BUILD_DIR)/kernel/core

# Program to auto start when kernel is ready.
# 1 - Tic Tac Toe
# 2 - Calculator
# 3 - ls
# 4 - cat
RUN_APP_ID = 1
MINIMAL_DISK = $(BUILD_DIR)/minimal_disk

# Apps
SRC_APP = $(SRC_DIR)/usr/local/src
BUILD_APP = $(BUILD_DIR)/usr/local/bin
app_calc = $(BUILD_APP)/calc.out
app_tic_tac_toe = $(BUILD_APP)/tic_tac_toe.out
app_ls = $(BUILD_APP)/ls.out
app_cat = $(BUILD_APP)/cat.out

MEMORY_LOCATION_KERNEL = 0xC000

Expand All @@ -60,56 +62,66 @@ SOURCE_SNAPSHOT="\"$$(git rev-parse --short HEAD)$$(git diff --quiet || echo '_u
# General Assumptions
## Integer is 4 bytes

# Debugging controller
DEBUG?=
ifdef DEBUG
CC_DEBUG=-g
NASM_DEBUG=-g
LD_DEBUG=
else
CC_DEBUG=
NASM_DEBUG=
LD_DEBUG=--strip-all
endif

# Tools
CC=gcc -std=c11 -fno-builtin -Os -nostartfiles -nostdlib -static
HOST_CC = gcc -std=c11 -Iinclude

NASM=nasm -f elf32 $(NASM_DEBUG)

CC=gcc -std=c11 -fno-builtin -Os -nostartfiles -nostdlib -static $(CC_DEBUG)
KERNEL_CC = $(CC) -m32 -fno-pie -Isrc --sysroot=$(BUILD_DIR) -Iinclude -Isrc/usr/include
LD=ld -nostdlib -nostartfiles -nodefaultlibs --strip-all # --print-map
USER_CC = $(CC) -m32 -fno-pie -Isrc --sysroot=$(BUILD_DIR)

LD=ld -nostdlib -nostartfiles -nodefaultlibs $(LD_DEBUG)
KERNEL_LD=$(LD) -m elf_i386 -T linker.ld -Ttext 0x0
USER_LD= $(LD) -m elf_i386 -T linker.ld -Ttext 0x0

FLAT_FROM_ELF=objcopy -O binary

# Targets
all_artifacts: images binaries external

test: $(image_vmdk) $(wildcard tests/**/*)
bash tests/run.sh


images: $(image_vmdk)

binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)

# Build dependecies for configure and $(image_vmdk) are ordered based on their position on disk.
# Note: Relying on default value doesn't guarantee bin size.
SECTOR_COUNT_BT_STAGE1 = 1
SECTOR_COUNT_SHARED_LIBRARY = 1
SECTOR_COUNT_BT_STAGE2 = 11
SECTOR_COUNT_KERNEL = 44

SECTOR_START_BT_STAGE1 = 0
SECTOR_COUNT_BT_STAGE1 = $(shell cut -d' ' -f1 configure 2> /dev/null || echo 1 )
SECTOR_START_SHARED_LIBRARY = $(shell expr $(SECTOR_START_BT_STAGE1) + $(SECTOR_COUNT_BT_STAGE1) )
SECTOR_COUNT_SHARED_LIBRARY = $(shell cut -d' ' -f2 configure 2> /dev/null || echo 1 )
SECTOR_START_BT_STAGE2 = $(shell expr $(SECTOR_START_SHARED_LIBRARY) + $(SECTOR_COUNT_SHARED_LIBRARY) )
SECTOR_COUNT_BT_STAGE2 = $(shell cut -d' ' -f3 configure 2> /dev/null || echo 30 )
SECTOR_START_KERNEL = $(shell expr $(SECTOR_START_BT_STAGE2) + $(SECTOR_COUNT_BT_STAGE2) )
SECTOR_COUNT_KERNEL = $(shell cut -d' ' -f4 configure 2> /dev/null || echo 30 )
SECTOR_START_APP_TTT = $(shell expr $(SECTOR_START_KERNEL) + $(SECTOR_COUNT_KERNEL) )
SECTOR_COUNT_APP_TTT = $(shell cut -d' ' -f5 configure 2> /dev/null || echo 30 )
SECTOR_START_APP_CALC = $(shell expr $(SECTOR_START_APP_TTT) + $(SECTOR_COUNT_APP_TTT) )
SECTOR_COUNT_APP_CALC = $(shell cut -d' ' -f6 configure 2> /dev/null || echo 30 )
SECTOR_START_APP_LS = $(shell expr $(SECTOR_START_APP_CALC) + $(SECTOR_COUNT_APP_CALC) )
SECTOR_COUNT_APP_LS = $(shell cut -d' ' -f7 configure 2> /dev/null || echo 30 )
SECTOR_START_APP_CAT = $(shell expr $(SECTOR_START_APP_LS) + $(SECTOR_COUNT_APP_LS) )
SECTOR_COUNT_APP_CAT = $(shell cut -d' ' -f7 configure 2> /dev/null || echo 30 )

# configure file stores the sector size of each sub images.
configure: $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(app_tic_tac_toe) $(app_calc) $(app_ls) $(app_cat)
bash scripts/build_image.sh /dev/null $^ > $@
rm -r $(BUILD_DIR)/ && "Cleared build directory" || echo "Build directory is clean."

$(image_vmdk): $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(app_tic_tac_toe) $(app_calc) $(app_ls) $(app_cat) $(BUILD_DIR)/external/bin/mbr_builder $(BUILD_DIR)/external/example/sample_fs
test -s configure || { echo -e "\033[0;31mFailed! Please execute 'make configure' first.\033[0m" >&2; exit 1; }
bash scripts/build_image.sh $(BUILD_DIR)/temp_vmdk $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(app_tic_tac_toe) $(app_calc) $(app_ls) $(app_cat)
./$(BUILD_DIR)/external/bin/mbr_builder $@ $(BUILD_DIR)/temp_vmdk $(BUILD_DIR)/external/example/sample_fs

$(image_vmdk): $(bt_stage1) $(rm_static) $(bt_stage2) $(kernel_core) $(BUILD_DIR)/external/bin/mbr_builder $(MINIMAL_DISK)
bash scripts/build_image.sh $(BUILD_DIR)/temp_vmdk \
$(bt_stage1) $(SECTOR_COUNT_BT_STAGE1) \
$(rm_static) $(SECTOR_COUNT_SHARED_LIBRARY) \
$(bt_stage2) $(SECTOR_COUNT_BT_STAGE2) \
$(kernel_core) $(SECTOR_COUNT_KERNEL)
./$(BUILD_DIR)/external/bin/mbr_builder $@ $(BUILD_DIR)/temp_vmdk $(MINIMAL_DISK)
@echo "Image Size : $$(stat -c %s $@) byte(s)"

clean:
rm -r $(BUILD_DIR)/ || echo "Build directory is clean."
rm -f configure

include emulator/Makefile.mk

Expand All @@ -118,13 +130,19 @@ include $(SRC_DIR)/usr/lib/Makefile.mk

include $(SRC_BOOTLOADER)/Makefile.mk
include $(SRC_REALMODE)/Makefile.mk

include $(SRC_KERNEL)/Makefile.mk
include $(SRC_KERNEL)/interrupts/Makefile.mk
include $(SRC_KERNEL)/process/Makefile.mk
include $(SRC_KERNEL)/syscall/Makefile.mk

include $(SRC_DRIVERS)/disk/Makefile.mk
include $(SRC_DRIVERS)/display/Makefile.mk
include $(SRC_DRIVERS)/keyboard/Makefile.mk
include $(SRC_DRIVERS)/pic/Makefile.mk

include $(SRC_DIR)/fs/Makefile.mk
include $(SRC_DIR)/memmgr/tables/Makefile.mk

include $(SRC_LIB)/app/Makefile.mk
include $(SRC_LIB_DS)/Makefile.mk
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ The VMDK image can be found under `Assets` for the corresponding release.

The screenshots can be located as `Artifacts` under completed run on [Actions/CI](https://github.com/scopeInfinity/FuzzyOS/actions/workflows/ci.yaml?query=branch%3Amaster+event%3Apush+is%3Asuccess).

Bootloader | Kernel Turnup | Simple Application
-------------|----------------|-------------------
![image](https://user-images.githubusercontent.com/9819066/119272271-12b67700-bbfd-11eb-8036-1466d39ebe8e.png) | ![image](https://user-images.githubusercontent.com/9819066/119273658-ca4e8780-bc03-11eb-8353-2dcf41354c82.png) | ![image](https://user-images.githubusercontent.com/9819066/119272299-2bbf2800-bbfd-11eb-9e8a-350946e1218b.png)

Bootloader | Kernel Turnup
-------------|----------------
![image](https://user-images.githubusercontent.com/9819066/119272271-12b67700-bbfd-11eb-8036-1466d39ebe8e.png) | ![image](https://user-images.githubusercontent.com/9819066/129453488-1950ca70-25cc-4801-842f-b25ea88ab25f.png)


Simple Shell | TicTacToe Game
--------------| ------------------
![image](https://user-images.githubusercontent.com/9819066/129453427-41e9322f-5e87-4d46-a4dc-0fd70b68e4a7.png) | ![image](https://user-images.githubusercontent.com/9819066/119272299-2bbf2800-bbfd-11eb-9e8a-350946e1218b.png)

### Boot OS

#### How to get boot image?
- Download image from one of the [Release](#Release).
- Or directly build image using `make configure && make images` after cloning the repository.
- Or directly build image using `make images` after cloning the repository.

#### Boot on VMware
- Create *Virtual Machine Disk* with fixed size of *4MB*.
Expand All @@ -33,7 +39,7 @@ The screenshots can be located as `Artifacts` under completed run on [Actions/CI
##### Boot on a real machine
- Use `dd` or `scripts/burn.sh` to burn image into the disk (potentially destructive).
- `bash scripts/burn.sh build/image.vmdk /path/to/devicefile`

###### If boot from Flash Drive doesn't work
- Try formatting device MBR with a FAT partition.
- And then burn the image again.
Expand All @@ -46,7 +52,6 @@ The screenshots can be located as `Artifacts` under completed run on [Actions/CI
```
bash before_install.sh
make clean
make configure
```

#### QEMU Quick Launch
Expand Down
16 changes: 9 additions & 7 deletions external/src/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
external: $(BUILD_DIR)/external/bin/mkfs.ffs $(BUILD_DIR)/external/example/sample_fs
external: $(BUILD_DIR)/external/bin/mkfs.ffs $(MINIMAL_DISK)

$(BUILD_DIR)/external/bin/mkfs.ffs: external/src/mkfs_ffs.c
mkdir -p $(dir $@)
Expand All @@ -8,11 +8,13 @@ $(BUILD_DIR)/external/bin/mbr_builder: external/src/mbr_builder.c
mkdir -p $(dir $@)
$(HOST_CC) -o $@ $<

$(BUILD_DIR)/external/out/minimal_fs: $(BUILD_DIR)/external/bin/mkfs.ffs $(wildcard tests/**/*)
mkdir -p $(dir $@)
$< tests/ $@
$(BUILD_DIR)/external/out/fuzzy_mount: $(patsubst $(SRC_APP)/%.c,$(BUILD_APP)/%.out,$(shell find $(SRC_APP)/ -name '*.c')) \
README.md \
.gdbinit
# not a mount
mkdir -p $@
cp -f -t $@ $^

$(BUILD_DIR)/external/example/sample_fs: $(BUILD_DIR)/external/out/minimal_fs $(BUILD_DIR)/external/bin/mkfs.ffs
$(MINIMAL_DISK): $(BUILD_DIR)/external/bin/mkfs.ffs $(BUILD_DIR)/external/out/fuzzy_mount
mkdir -p $(dir $@)
echo "TODO: Append new files to filesystem"
cp -f $< $@
$< $(BUILD_DIR)/external/out/fuzzy_mount/ $@
2 changes: 1 addition & 1 deletion external/src/mkfs_ffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void write_nofile(int file_id, FILE *out) {


int create_partition(char *src_dir, char *out_filepath) {
printf("%s, %s\n", src_dir, out_filepath);
printf("dir:%s partition: %s\n", src_dir, out_filepath);
FILE *src = opendir(src_dir);
FILE *out = fopen(out_filepath, "wb");
if (!out) {
Expand Down
15 changes: 15 additions & 0 deletions include/fuzzy/drivers/pic/pic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#define PIC_PIT_FREQ 1193182 // hz
#define PIC_PIT_MAX_COUNTER 0xFFFF

#define PIC_IRQ_PIT 0

void interrupt_pit_enable();

void pic_irq_enable(int irq);
void pic_irq_disable(int irq);

void pic_pit_set_counter(unsigned short counter);
unsigned short pic_pit_get_counter();
void pic_pit_reset();
5 changes: 4 additions & 1 deletion include/fuzzy/fs/ffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Number of file which can be stored: 64
#include <stdint.h>

#define FS_FFS_FILENAME_LIMIT 120 // including NULL
#define FFS_UNIQUE_PARITION_ID 0 // only paritition 0 is supported for now

union FFSMetaData {
struct {
Expand All @@ -37,14 +38,16 @@ union FFSFileEntry {

#define FS_FFS_FIRST_BLOCK_SIZE sizeof(union FFSMetaData)
#define FS_FFS_FILEENTRY_SIZE sizeof(union FFSFileEntry)
#define FS_FFS_FILEENTRY_COUNT 127
#define FS_FFS_FILEENTRY_COUNT 128

#define FS_BLOCK_SIZE 512
#define FS_FFS_BLOCK_DATA_START ((FS_FFS_FIRST_BLOCK_SIZE+FS_FFS_FILEENTRY_SIZE*FS_FFS_FILEENTRY_COUNT)/FS_BLOCK_SIZE)

#define FS_FFS_SIGNATURE "__FuzzyOS__FFS__" // 16 chars


int resolve_abs_lba(int parition_id, int partition_relative_lba);

int partition_read_block(int block_index, void *wr_buffer);

int fetch_first_block(
Expand Down
3 changes: 3 additions & 0 deletions include/fuzzy/kernel/interrupts/exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void interrupt_register_0x00_0x1F_exceptions();
22 changes: 22 additions & 0 deletions include/fuzzy/kernel/interrupts/interrupts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

/*
* Interrupt descriptive table
* [00:32) ; [0x00:0x20) ; Exceptions: faults, traps, aborts
* [32:48) ; [0x20:0x30) ; IRQ0-15
* 80 ; 0x32 ; syscall
*/
#define IDT_SIZE 256
#define IDT_IRQ_OFFSET 0x20

// Used by /usr/lib/process.c
#define IDT_IRQ0_PIC (IDT_IRQ_OFFSET+0)
// Used by /usr/lib/sys/syscall.asm
#define IDT_SYSCALL 0x32


extern void populate_idt_entry_32bit(int id,
unsigned int address,
unsigned char dpl, // 2-bit
int is_trap
);
7 changes: 7 additions & 0 deletions include/fuzzy/kernel/interrupts/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

void interrupt_pit_enable();

void interrupt_register_0x20_irq0_pit();

void create_infant_process_irq0_stack(int ds_ss_es_fs);
Loading