-
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
Showing
12 changed files
with
170 additions
and
42 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# options: https://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
BasedOnStyle: Mozilla | ||
IndentWidth: 4 | ||
ColumnLimit: 120 | ||
IndentWidth: 4 | ||
|
||
AlignAfterOpenBracket: BlockIndent | ||
AlignConsecutiveMacros: true | ||
AlignTrailingComments: | ||
Kind: Always | ||
AllowAllArgumentsOnNextLine: true | ||
AllowShortBlocksOnASingleLine: Empty | ||
AlwaysBreakAfterReturnType: AllDefinitions | ||
InsertBraces: true |
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
all: | ||
$(MAKE) -C blank | ||
$(MAKE) -C syscall | ||
|
||
clean: | ||
$(MAKE) -C blank clean | ||
$(MAKE) -C blank clean | ||
$(MAKE) -C syscall clean |
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,35 @@ | ||
TARGET = syscall.bin | ||
OBJ = syscall.o | ||
|
||
BUILD_DIR = ./build | ||
SRC_DIR = ./src | ||
|
||
LINKER_FILE = $(SRC_DIR)/linker.ld | ||
|
||
ASRCS = $(shell find $(SRC_DIR) -name *.asm) | ||
|
||
AOBJS = $(subst $(SRC_DIR),$(BUILD_DIR),$(ASRCS:.asm=.asm.o)) | ||
OBJS = $(AOBJS) | ||
|
||
CC = i686-elf-gcc | ||
ASM = nasm | ||
LD = i686-elf-ld | ||
|
||
AFLAGS = -f elf -g | ||
CFLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-labels -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parammeter -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc -std=gnu99 | ||
LDFLAGS = -g -relocatable | ||
|
||
all: build | ||
|
||
build: $(BUILD_DIR)/$(TARGET) | ||
|
||
$(BUILD_DIR)/$(TARGET): $(OBJS) | ||
$(LD) $(LDFLAGS) $(OBJS) -o $(BUILD_DIR)/$(OBJ) | ||
$(CC) $(CFLAGS) -T $(SRC_DIR)/linker.ld -o $(BUILD_DIR)/$(TARGET) $(BUILD_DIR)/$(OBJ) | ||
|
||
$(BUILD_DIR)/%.asm.o: $(SRC_DIR)/%.asm | ||
mkdir -p $(dir $@) | ||
$(ASM) $(AFLAGS) $< -o $@ | ||
|
||
clean: | ||
rm -rf $(BUILD_DIR) |
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,31 @@ | ||
ENTRY(_start) | ||
OUTPUT_FORMAT(binary) | ||
SECTIONS | ||
{ | ||
. = 0x400000; /* USER_PROGRAM_VIRTUAL_ADDRESS_START in config.h */ | ||
.text : ALIGN(4096) | ||
{ | ||
*(.text) | ||
} | ||
|
||
.rodata : ALIGN(4096) | ||
{ | ||
*(.rodata) | ||
} | ||
|
||
.data : ALIGN(4096) | ||
{ | ||
*(.data) | ||
} | ||
|
||
.bss : ALIGN(4096) | ||
{ | ||
*(COMMON) | ||
*(.bss) | ||
} | ||
|
||
.asm : ALIGN(4096) | ||
{ | ||
*(.asm) | ||
} | ||
} |
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 @@ | ||
[BITS 32] | ||
|
||
section .asm | ||
|
||
global _start | ||
|
||
_start: | ||
mov eax, 0 ; sys_print | ||
int 0x80 ; call kernel | ||
jmp $ |
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
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,50 @@ | ||
#include "syscall.h" | ||
#include "config.h" | ||
#include "kernel.h" | ||
#include "terminal/terminal.h" | ||
|
||
static SYSCALL_HANDLER syscall_handlers[TOTAL_SYSCALL_COUNT]; | ||
|
||
void* | ||
sys_print(struct interrupt_frame* frame) | ||
{ | ||
print("sys_print\n"); | ||
return 0; | ||
} | ||
|
||
static void | ||
register_syscall_handler(int command, SYSCALL_HANDLER handler) | ||
{ | ||
if (command < 0 || command >= TOTAL_SYSCALL_COUNT) { | ||
panic("Invalid syscall command"); | ||
} | ||
|
||
if (syscall_handlers[command]) { | ||
panic("Syscall already registered"); | ||
} | ||
|
||
syscall_handlers[command] = handler; | ||
} | ||
|
||
void | ||
initialize_syscall_handlers() | ||
{ | ||
register_syscall_handler(SYSCALL_COMMAND_0_PRINT, sys_print); | ||
} | ||
|
||
void* | ||
syscall(int command, struct interrupt_frame* frame) | ||
{ | ||
void* result = 0; | ||
|
||
if (command < 0 || command >= TOTAL_SYSCALL_COUNT) { | ||
return result; | ||
} | ||
|
||
SYSCALL_HANDLER handler = syscall_handlers[command]; | ||
if (handler) { | ||
result = handler(frame); | ||
} | ||
|
||
return result; | ||
} |
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,17 @@ | ||
#ifndef SYSCALL_H | ||
#define SYSCALL_H | ||
|
||
#include "idt/idt.h" | ||
#include <stdint.h> | ||
|
||
typedef void* (*SYSCALL_HANDLER)(struct interrupt_frame*); | ||
|
||
enum SYSCALL_COMMAND | ||
{ | ||
SYSCALL_COMMAND_0_PRINT = 0, | ||
}; | ||
|
||
void initialize_syscall_handlers(); | ||
void* syscall(int command, struct interrupt_frame* frame); | ||
|
||
#endif |