Skip to content

Commit

Permalink
Merge pull request #2 from Sister20/setup
Browse files Browse the repository at this point in the history
feat: setup project
  • Loading branch information
Jimly-Firdaus authored Feb 22, 2023
2 parents 9937a8c + 60c9ac3 commit 47c86cc
Show file tree
Hide file tree
Showing 21 changed files with 686 additions and 502 deletions.
82 changes: 41 additions & 41 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bin/kernel",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Launch QEMU",
"postDebugTask": "Exit QEMU",
"targetArchitecture": "x86",
"customLaunchSetupCommands": [
{
"text": "target remote localhost:1234",
"description": "Connect to QEMU remote debugger"
},
{
"text": "symbol-file kernel",
"description": "Get kernel symbols"
},
{
"text": "set output-radix 16",
"description": "Use hexadecimal output"
}
],
"avoidWindowsConsoleRedirection": true
},
]
{
"version": "0.2.0",
"configurations": [
{
"name": "Kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bin/kernel",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Launch QEMU",
"postDebugTask": "Exit QEMU",
"targetArchitecture": "x86",
"customLaunchSetupCommands": [
{
"text": "target remote localhost:1234",
"description": "Connect to QEMU remote debugger"
},
{
"text": "symbol-file kernel",
"description": "Get kernel symbols"
},
{
"text": "set output-radix 16",
"description": "Use hexadecimal output"
}
],
"avoidWindowsConsoleRedirection": true
},
]
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"debug.onTaskErrors": "debugAnyway",
{
"debug.onTaskErrors": "debugAnyway",
}
98 changes: 49 additions & 49 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build OS",
"command": "make",
"args": [
"build",
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Launch QEMU",
"command": "echo Starting QEMU&qemu-system-i386 -s -S -cdrom os2023.iso",
"isBackground": true,
"dependsOn": "Build OS",
"options": {
"cwd": "${workspaceFolder}/bin"
},
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
},
{
"type": "shell",
"label": "Exit QEMU",
"command": "pkill -f qemu || test $? -eq 1"
}
],
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build OS",
"command": "make",
"args": [
"build",
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Launch QEMU",
"command": "echo Starting QEMU&qemu-system-i386 -s -S -cdrom os2023.iso",
"isBackground": true,
"dependsOn": "Build OS",
"options": {
"cwd": "${workspaceFolder}/bin"
},
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
},
{
"type": "shell",
"label": "Exit QEMU",
"command": "pkill -f qemu || test $? -eq 1"
}
],
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# kit-OS-2023
Kit untuk IF2230 - Sistem Operasi 2023
# kit-OS-2023
Kit untuk IF2230 - Sistem Operasi 2023
6 changes: 3 additions & 3 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.o
*.iso
*
*.o
*.iso
*
!.gitignore
88 changes: 46 additions & 42 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
# Compiler & linker
ASM = nasm
LIN = ld
CC = gcc

# Directory
SOURCE_FOLDER = src
OUTPUT_FOLDER = bin
ISO_NAME = os2023

# Flags
WARNING_CFLAG = -Wall -Wextra -Werror
DEBUG_CFLAG = -ffreestanding -fshort-wchar -g
STRIP_CFLAG = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs
CFLAGS = $(DEBUG_CFLAG) $(WARNING_CFLAG) $(STRIP_CFLAG) -m32 -c -I$(SOURCE_FOLDER)
AFLAGS = -f elf32 -g -F dwarf
LFLAGS = -T $(SOURCE_FOLDER)/linker.ld -melf_i386


run: all
@qemu-system-i386 -s -S -cdrom $(OUTPUT_FOLDER)/$(ISO_NAME).iso
all: build
build: iso
clean:
rm -rf *.o *.iso $(OUTPUT_FOLDER)/kernel



kernel:
@$(ASM) $(AFLAGS) $(SOURCE_FOLDER)/kernel_loader.s -o $(OUTPUT_FOLDER)/kernel_loader.o
# TODO: Compile C file with CFLAGS
@$(LIN) $(LFLAGS) bin/*.o -o $(OUTPUT_FOLDER)/kernel
@echo Linking object files and generate elf32...
@rm -f *.o

iso: kernel
@mkdir -p $(OUTPUT_FOLDER)/iso/boot/grub
@cp $(OUTPUT_FOLDER)/kernel $(OUTPUT_FOLDER)/iso/boot/
@cp other/grub1 $(OUTPUT_FOLDER)/iso/boot/grub/
@cp $(SOURCE_FOLDER)/menu.lst $(OUTPUT_FOLDER)/iso/boot/grub/
# TODO: Create ISO image
@rm -r $(OUTPUT_FOLDER)/iso/
# Compiler & linker
ASM = nasm
LIN = ld
CC = gcc

# Directory
SOURCE_FOLDER = src
OUTPUT_FOLDER = bin
ISO_NAME = os2023

# Flags
WARNING_CFLAG = -Wall -Wextra -Werror
DEBUG_CFLAG = -ffreestanding -fshort-wchar -g
STRIP_CFLAG = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs
CFLAGS = $(DEBUG_CFLAG) $(WARNING_CFLAG) $(STRIP_CFLAG) -m32 -c -I$(SOURCE_FOLDER)
AFLAGS = -f elf32 -g -F dwarf
LFLAGS = -T $(SOURCE_FOLDER)/linker.ld -melf_i386


run: all
@qemu-system-i386 -s -S -cdrom $(OUTPUT_FOLDER)/$(ISO_NAME).iso
all: build
build: iso
clean:
rm -rf *.o *.iso $(OUTPUT_FOLDER)/kernel



kernel:
@$(ASM) $(AFLAGS) $(SOURCE_FOLDER)/kernel_loader.s -o $(OUTPUT_FOLDER)/kernel_loader.o
@$(CC) $(CFLAGS) $(SOURCE_FOLDER)/kernel.c -o $(OUTPUT_FOLDER)/kernel.o
@$(CC) $(CFLAGS) $(SOURCE_FOLDER)/gdt.c -o $(OUTPUT_FOLDER)/gdt.o
@$(CC) $(CFLAGS) $(SOURCE_FOLDER)/portio.c -o $(OUTPUT_FOLDER)/portio.o
@$(CC) $(CFLAGS) $(SOURCE_FOLDER)/stdmem.c -o $(OUTPUT_FOLDER)/stdmem.o
@$(CC) $(CFLAGS) $(SOURCE_FOLDER)/framebuffer.c -o $(OUTPUT_FOLDER)/framebuffer.o
@$(LIN) $(LFLAGS) bin/*.o -o $(OUTPUT_FOLDER)/kernel
@echo Linking object files and generate elf32...
@rm -f *.o

iso: kernel
@mkdir -p $(OUTPUT_FOLDER)/iso/boot/grub
@cp $(OUTPUT_FOLDER)/kernel $(OUTPUT_FOLDER)/iso/boot/
@cp other/grub1 $(OUTPUT_FOLDER)/iso/boot/grub/
@cp $(SOURCE_FOLDER)/menu.lst $(OUTPUT_FOLDER)/iso/boot/grub/
@genisoimage -R -b boot/grub/grub1 -no-emul-boot -boot-load-size 4 -A os -input-charset utf8 -quiet -boot-info-table -o $(OUTPUT_FOLDER)/$(ISO_NAME).iso $(OUTPUT_FOLDER)/iso
@rm -r $(OUTPUT_FOLDER)/iso/
18 changes: 18 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
3.3
gcc -ffreestanding -fshort-wchar -g -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -Werror -m32 -c -Isrc src/kernel.c -o bin/kernel.o
nasm -f elf32 -g -F dwarf src/kernel_loader.s -o bin/kernel_loader.o
ld -T src/linker.ld -melf_i386 bin/kernel.o bin/kernel_loader.o -o bin/kernel
3.4
genisoimage -R \
-b boot/grub/grub1 \
-no-emul-boot \
-boot-load-size 4 \
-A os \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o OS2023.iso \
iso

3.6
qemu-system-i386 -s -cdrom OS2023.iso
46 changes: 46 additions & 0 deletions src/framebuffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "lib-header/framebuffer.h"
#include "lib-header/stdtype.h"
#include "lib-header/stdmem.h"
#include "lib-header/portio.h"

#define VGA_WIDTH 80
#define VGA_HEIGHT 25

static uint16_t* framebuffer = (uint16_t*) 0xB8000;
static uint8_t cursor_row = 0;
static uint8_t cursor_col = 0;
static uint8_t foreground_color = 0;
static uint8_t background_color = 0;

void framebuffer_set_cursor(uint8_t r, uint8_t c) {
// Ensure row and column are within bounds
if (r >= VGA_HEIGHT || c >= VGA_WIDTH) {
return;
}

// Calculate position in framebuffer
uint16_t pos = r * VGA_WIDTH + c;

// Set cursor position
out(0x3D4, 0x0F); // High byte
out(0x3D5, (uint8_t)(pos >> 8));
out(0x3D4, 0x0E); // Low byte
out(0x3D5, (uint8_t)(pos & 0xFF));
}

void framebuffer_write(uint8_t row, uint8_t col, char c, uint8_t fg, uint8_t bg) {
uint16_t attrib = (bg << 4) | (fg & 0x0F);
volatile uint16_t * where;
where = (volatile uint16_t *)0xB8000 + (row * 80 + col) ;
*where = c | (attrib << 8);
}

void framebuffer_clear(void) {
uint8_t blank = (background_color << 4) | (foreground_color & 0x0F);
uint16_t space = (blank << 8) | ' ';
for (int i = 0; i < 80 * 25; i++) {
framebuffer[i] = space;
}
cursor_row = 0;
cursor_col = 0;
}
Loading

0 comments on commit 47c86cc

Please sign in to comment.