Skip to content

Commit

Permalink
ch 15
Browse files Browse the repository at this point in the history
  • Loading branch information
geon6 committed Nov 10, 2024
1 parent 2115458 commit ca0eac1
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 295 deletions.
146 changes: 5 additions & 141 deletions ch15/.clang-format
Original file line number Diff line number Diff line change
@@ -1,142 +1,6 @@
---
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
Language: Cpp
# BasedOnStyle: LLVM
# 访问说明符(public、private等)的偏移
AccessModifierOffset: -2
# Google C/C++ Code Style settings
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# Author: Kehan Xue, kehan.xue (at) gmail.com

# 允许函数声明的所有参数在放在下一行
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
Language: Cpp
BasedOnStyle: Google
5 changes: 4 additions & 1 deletion ch15/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OBJS = $(BUILD_DIR)/main.o $(BUILD_DIR)/init.o $(BUILD_DIR)/interrupt.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 $(BUILD_DIR)/fork.o $(BUILD_DIR)/shell.o \
$(BUILD_DIR)/assert.o $(BUILD_DIR)/builtin_cmd.o
$(BUILD_DIR)/assert.o $(BUILD_DIR)/builtin_cmd.o $(BUILD_DIR)/userprog/exec.o

boot: $(BUILD_DIR)/mbr.bin $(BUILD_DIR)/loader.bin
# mbr
Expand Down Expand Up @@ -118,6 +118,9 @@ $(BUILD_DIR)/assert.o: lib/user/assert.c
$(BUILD_DIR)/builtin_cmd.o: shell/builtin_cmd.c
$(CC) $(CFLAGS) $< -o $@

$(BUILD_DIR)/exec.o: userprog/exec.c
$(CC) $(CFLAGS) $< -o $@

# asm
$(BUILD_DIR)/kernel.o: kernel/kernel.S
$(AS) $(ASFLAGS) $< -o $@
Expand Down
11 changes: 11 additions & 0 deletions ch15/command/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BIN="prog_no_arg"
CFLAGS="-Wall -m32 -c -fno-builtin -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers"
LIB="../lib/"
OBJS="../build/string.o ../build/syscall.o ../build/stdio.o ../build/debug.o ../build/print.o"
DD_IN=$BIN
DD_OUT="/usr/local/bochs/hd60M.img"

gcc $CFLAGS -I $LIB -o $BIN".o" $BIN".c"
ld -m elf_i386 -Ttext 0x8060000 -e main $BIN".o" $OBJS -o $BIN
SEC_CNT=$(ls -l $BIN | awk '{printf("%d", ($5+511)/512)}')
dd if=./$DD_IN of=$DD_OUT bs=512 count=$SEC_CNT seek=300 conv=notrunc
6 changes: 6 additions & 0 deletions ch15/command/prog_no_arg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "stdio.h"
int main() {
printf("prog no arg from disk\n");
while (1);
return 0;
}
Binary file added ch15/command/prog_no_arg.o
Binary file not shown.
2 changes: 1 addition & 1 deletion ch15/kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void init_all() {
keyboard_init();
tss_init();
syscall_init();
intr_enable(); // ide init需要打开中断
intr_enable(); // ide init需要打开中断
ide_init();
filesys_init();
}
3 changes: 3 additions & 0 deletions ch15/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void init();
int main(void) {
put_str("I am kernel\n");
init_all();

uint32_t file_size = 4777;

cls_screen();
console_put_str("[geon6@localhost /]$ ");
while (1) {}
Expand Down
Loading

0 comments on commit ca0eac1

Please sign in to comment.