-
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
95 changed files
with
7,485 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,142 @@ | ||
--- | ||
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto | ||
Language: Cpp | ||
# BasedOnStyle: LLVM | ||
# 访问说明符(public、private等)的偏移 | ||
AccessModifierOffset: -2 | ||
|
||
# 允许函数声明的所有参数在放在下一行 | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
# 允许短的块放在同一行 | ||
AllowShortBlocksOnASingleLine: true | ||
# 允许短的case标签放在同一行 | ||
AllowShortCaseLabelsOnASingleLine: true | ||
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All | ||
AllowShortFunctionsOnASingleLine: Empty | ||
# 允许短的if语句保持在同一行 | ||
AllowShortIfStatementsOnASingleLine: true | ||
# 允许短的循环保持在同一行 | ||
AllowShortLoopsOnASingleLine: true | ||
# AlignConsecutiveDeclarations: true | ||
AlignTrailingComments: true | ||
# 总是在定义返回类型后换行(deprecated) | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), | ||
# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) | ||
AlwaysBreakAfterReturnType: None | ||
# 总是在多行string字面量前换行 | ||
AlwaysBreakBeforeMultilineStrings: false | ||
# 总是在template声明后换行 | ||
AlwaysBreakTemplateDeclarations: false | ||
|
||
AlignAfterOpenBracket: Align | ||
# AlignConsecutiveAssignments: false | ||
AlignEscapedNewlines: Left | ||
|
||
|
||
# false表示函数实参要么都在同一行,要么都各自一行 | ||
BinPackArguments: true | ||
# false表示所有形参要么都在同一行,要么都各自一行 | ||
BinPackParameters: false | ||
# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 | ||
BraceWrapping: | ||
# class定义后面 | ||
AfterClass: false | ||
# 控制语句后面 | ||
AfterControlStatement: false | ||
# enum定义后面 | ||
AfterEnum: false | ||
# 函数定义后面 | ||
AfterFunction: false | ||
# 命名空间定义后面 | ||
AfterNamespace: false | ||
# ObjC定义后面 | ||
AfterObjCDeclaration: false | ||
# struct定义后面 | ||
AfterStruct: false | ||
# union定义后面 | ||
AfterUnion: false | ||
|
||
AfterExternBlock: false | ||
# catch之前 | ||
BeforeCatch: false | ||
# else之前 | ||
BeforeElse: false | ||
# 缩进大括号 | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
|
||
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) | ||
BreakBeforeBinaryOperators: None | ||
# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), | ||
# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), | ||
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom | ||
# 注:这里认为语句块也属于函数 | ||
BreakBeforeBraces: Custom | ||
# 在三元运算符前换行 | ||
BreakBeforeTernaryOperators: false | ||
|
||
# 在构造函数的初始化列表的逗号前换行 | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: BeforeColon | ||
# 每行字符的限制,0表示没有限制 | ||
ColumnLimit: 80 | ||
# 构造函数的初始化列表要么都在同一行,要么都各自一行 | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
# 构造函数的初始化列表的缩进宽度 | ||
ConstructorInitializerIndentWidth: 4 | ||
# 延续的行的缩进宽度 | ||
ContinuationIndentWidth: 4 | ||
# 去除C++11的列表初始化的大括号{后和}前的空格 | ||
Cpp11BracedListStyle: true | ||
# 继承最常用的指针和引用的对齐方式 | ||
DerivePointerAlignment: false | ||
|
||
# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) | ||
ExperimentalAutoDetectBinPacking: false | ||
|
||
# 缩进case标签 | ||
IndentCaseLabels: true | ||
|
||
IndentPPDirectives: AfterHash | ||
# 缩进宽度 | ||
IndentWidth: 4 | ||
|
||
# 指针和引用的对齐: Left, Right, Middle | ||
PointerAlignment: Left | ||
# 允许重新排版注释 | ||
ReflowComments: false | ||
# 允许排序#include | ||
SortIncludes: true | ||
|
||
# 在C风格类型转换后添加空格 | ||
SpaceAfterCStyleCast: false | ||
|
||
SpaceAfterTemplateKeyword: true | ||
|
||
# 在赋值运算符之前添加空格 | ||
SpaceBeforeAssignmentOperators: true | ||
# 开圆括号之前添加一个空格: Never, ControlStatements, Always | ||
SpaceBeforeParens: ControlStatements | ||
# 在空的圆括号中添加空格 | ||
SpaceInEmptyParentheses: false | ||
# 在尾随的评论前添加的空格数(只适用于//) | ||
SpacesBeforeTrailingComments: 2 | ||
# 在尖括号的<后和>前添加空格 | ||
SpacesInAngles: false | ||
# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 | ||
SpacesInContainerLiterals: false | ||
# 在C风格类型转换的括号中添加空格 | ||
SpacesInCStyleCastParentheses: false | ||
# 在圆括号的(后和)前添加空格 | ||
SpacesInParentheses: false | ||
# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 | ||
SpacesInSquareBrackets: false | ||
# 标准: Cpp03, Cpp11, Auto | ||
Standard: Cpp11 | ||
# tab宽度 | ||
TabWidth: 4 | ||
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always | ||
UseTab: Never |
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,25 @@ | ||
{ | ||
"files.associations": { | ||
"random": "c", | ||
"syscall.h": "c", | ||
"*.tcc": "c", | ||
"exception": "c", | ||
"memory_resource": "c", | ||
"iosfwd": "c", | ||
"new": "c", | ||
"ostream": "c", | ||
"stop_token": "c", | ||
"streambuf": "c", | ||
"stdio.h": "c", | ||
"init.h": "c", | ||
"thread.h": "c", | ||
"memory.h": "c", | ||
"ide.h": "c", | ||
"io.h": "c", | ||
"fs.h": "c", | ||
"string.h": "c", | ||
"dir.h": "c", | ||
"console.h": "c", | ||
"syscall-init.h": "c" | ||
} | ||
} |
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,137 @@ | ||
BUILD_DIR = ./build | ||
ENTRY_POINT = 0xc0001500 | ||
AS = nasm | ||
CC = gcc | ||
LD = ld | ||
LIB = -I lib/ -I lib/kernel/ -I lib/user/ -I kernel/ \ | ||
-I device/ -I thread/ -I userprog/ -I fs/ | ||
ASFLAGS = -f elf | ||
ASBINLIB = -I boot/include/ | ||
CFLAGS = -m32 -fno-stack-protector -Wall $(LIB) -c -fno-builtin -W -Wstrict-prototypes -Wmissing-prototypes | ||
LDFLAGS = -m elf_i386 -Ttext $(ENTRY_POINT) -e main -Map $(BUILD_DIR)/kernel.map | ||
OBJS = $(BUILD_DIR)/main.o $(BUILD_DIR)/init.o $(BUILD_DIR)/interrupt.o \ | ||
$(BUILD_DIR)/timer.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/print.o \ | ||
$(BUILD_DIR)/debug.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/bitmap.o \ | ||
$(BUILD_DIR)/string.o $(BUILD_DIR)/thread.o $(BUILD_DIR)/list.o \ | ||
$(BUILD_DIR)/switch.o $(BUILD_DIR)/sync.o $(BUILD_DIR)/console.o \ | ||
$(BUILD_DIR)/keyboard.o $(BUILD_DIR)/ioqueue.o $(BUILD_DIR)/tss.o \ | ||
$(BUILD_DIR)/process.o $(BUILD_DIR)/syscall.o $(BUILD_DIR)/syscall-init.o \ | ||
$(BUILD_DIR)/stdio.o $(BUILD_DIR)/ide.o $(BUILD_DIR)/stdio-kernel.o \ | ||
$(BUILD_DIR)/fs.o $(BUILD_DIR)/inode.o $(BUILD_DIR)/file.o \ | ||
$(BUILD_DIR)/dir.o | ||
|
||
boot: $(BUILD_DIR)/mbr.bin $(BUILD_DIR)/loader.bin | ||
# mbr | ||
$(BUILD_DIR)/mbr.bin: boot/mbr.S | ||
$(AS) $(ASBINLIB) $< -o $@ | ||
|
||
# bootloader | ||
$(BUILD_DIR)/loader.bin: boot/loader.S | ||
$(AS) $(ASBINLIB) $< -o $@ | ||
|
||
# c | ||
$(BUILD_DIR)/main.o: kernel/main.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/init.o: kernel/init.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/interrupt.o: kernel/interrupt.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/timer.o: device/timer.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/debug.o: kernel/debug.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/string.o: lib/string.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/bitmap.o: lib/kernel/bitmap.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/memory.o: kernel/memory.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/thread.o: thread/thread.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/list.o: lib/kernel/list.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/sync.o: thread/sync.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/console.o: device/console.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/keyboard.o: device/keyboard.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/ioqueue.o: device/ioqueue.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/tss.o: userprog/tss.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/process.o: userprog/process.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/syscall.o: lib/user/syscall.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/syscall-init.o: userprog/syscall-init.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/stdio.o: lib/stdio.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/ide.o: device/ide.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/stdio-kernel.o: lib/kernel/stdio-kernel.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/fs.o: fs/fs.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/inode.o: fs/inode.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/file.o: fs/file.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/dir.o: fs/dir.c | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
# asm | ||
$(BUILD_DIR)/kernel.o: kernel/kernel.S | ||
$(AS) $(ASFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/print.o: lib/kernel/print.S | ||
$(AS) $(ASFLAGS) $< -o $@ | ||
|
||
$(BUILD_DIR)/switch.o: thread/switch.S | ||
$(AS) $(ASFLAGS) $< -o $@ | ||
|
||
# ld | ||
$(BUILD_DIR)/kernel.bin: $(OBJS) | ||
$(LD) $(LDFLAGS) $^ -o $@ | ||
|
||
.PHONY : mk_dir hd clean build all boot | ||
|
||
mk_dir: | ||
if [[! -d $(BUILD_DIR) ]]; then mkdir $(BUILD_DIR); fi | ||
|
||
hd: | ||
dd if=$(BUILD_DIR)/mbr.bin of=/usr/local/bochs/hd60M.img bs=512 count=1 conv=notrunc && \ | ||
dd if=$(BUILD_DIR)/loader.bin of=/usr/local/bochs/hd60M.img bs=512 count=4 seek=2 conv=notrunc && \ | ||
dd if=$(BUILD_DIR)/kernel.bin of=/usr/local/bochs/hd60M.img bs=512 count=200 seek=9 conv=notrunc | ||
|
||
clean: | ||
cd $(BUILD_DIR) && rm -f ./* | ||
|
||
build: $(BUILD_DIR)/kernel.bin $(BUILD_DIR)/mbr.bin $(BUILD_DIR)/loader.bin | ||
|
||
all: mk_dir boot build hd |
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,56 @@ | ||
;------------- loader和kernel ---------- | ||
|
||
LOADER_BASE_ADDR equ 0x900 | ||
LOADER_STACK_TOP equ LOADER_BASE_ADDR | ||
LOADER_START_SECTOR equ 0x2 | ||
|
||
KERNEL_BIN_BASE_ADDR equ 0x70000 | ||
KERNEL_START_SECTOR equ 0x9 | ||
KERNEL_ENTRY_POINT equ 0xc0001500 | ||
|
||
;------------- 页表配置 ---------------- | ||
PAGE_DIR_TABLE_POS equ 0x100000 | ||
|
||
;-------------- gdt描述符属性 ----------- | ||
DESC_G_4K equ 1_00000000000000000000000b | ||
DESC_D_32 equ 1_0000000000000000000000b | ||
DESC_L equ 0_000000000000000000000b ; 64位代码标记,此处标记为0便可。 | ||
DESC_AVL equ 0_00000000000000000000b ; cpu不用此位,暂置为0 | ||
DESC_LIMIT_CODE2 equ 1111_0000000000000000b | ||
DESC_LIMIT_DATA2 equ DESC_LIMIT_CODE2 | ||
DESC_LIMIT_VIDEO2 equ 0000_000000000000000b | ||
DESC_P equ 1_000000000000000b | ||
DESC_DPL_0 equ 00_0000000000000b | ||
DESC_DPL_1 equ 01_0000000000000b | ||
DESC_DPL_2 equ 10_0000000000000b | ||
DESC_DPL_3 equ 11_0000000000000b | ||
DESC_S_CODE equ 1_000000000000b | ||
DESC_S_DATA equ DESC_S_CODE | ||
DESC_S_sys equ 0_000000000000b | ||
DESC_TYPE_CODE equ 1000_00000000b ;x=1,c=0,r=0,a=0 代码段是可执行的,非依从的,不可读的,已访问位a清0. | ||
DESC_TYPE_DATA equ 0010_00000000b ;x=0,e=0,w=1,a=0 数据段是不可执行的,向上扩展的,可写的,已访问位a清0. | ||
|
||
DESC_CODE_HIGH4 equ (0x00 << 24) + DESC_G_4K + DESC_D_32 + DESC_L + DESC_AVL + DESC_LIMIT_CODE2 + DESC_P + DESC_DPL_0 + DESC_S_CODE + DESC_TYPE_CODE + 0x00 | ||
DESC_DATA_HIGH4 equ (0x00 << 24) + DESC_G_4K + DESC_D_32 + DESC_L + DESC_AVL + DESC_LIMIT_DATA2 + DESC_P + DESC_DPL_0 + DESC_S_DATA + DESC_TYPE_DATA + 0x00 | ||
DESC_VIDEO_HIGH4 equ (0x00 << 24) + DESC_G_4K + DESC_D_32 + DESC_L + DESC_AVL + DESC_LIMIT_VIDEO2 + DESC_P + DESC_DPL_0 + DESC_S_DATA + DESC_TYPE_DATA + 0x0b | ||
|
||
;-------------- 选择子属性 --------------- | ||
RPL0 equ 00b | ||
RPL1 equ 01b | ||
RPL2 equ 10b | ||
RPL3 equ 11b | ||
TI_GDT equ 000b | ||
TI_LDT equ 100b | ||
|
||
|
||
;---------------- 页表相关属性 -------------- | ||
PG_P equ 1b | ||
PG_RW_R equ 00b | ||
PG_RW_W equ 10b | ||
PG_US_S equ 000b | ||
PG_US_U equ 100b | ||
|
||
|
||
;------------- program type 定义 -------------- | ||
PT_NULL equ 0 | ||
|
Oops, something went wrong.