Skip to content

Commit fb40491

Browse files
committed
Start a simple multiboot application
0 parents  commit fb40491

File tree

9 files changed

+256
-0
lines changed

9 files changed

+256
-0
lines changed

.clang-format

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
Language: Cpp
3+
AlignAfterOpenBracket: Align
4+
AlignConsecutiveMacros: false
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveBitFields: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: DontAlign
9+
AlignOperands: Align
10+
AlignTrailingComments: false
11+
AllowAllArgumentsOnNextLine: false
12+
AllowAllConstructorInitializersOnNextLine: false
13+
AllowAllParametersOfDeclarationOnNextLine: false
14+
AllowShortEnumsOnASingleLine: false
15+
AllowShortBlocksOnASingleLine: false
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: None
18+
AllowShortLambdasOnASingleLine: None
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: All
22+
AlwaysBreakAfterReturnType: TopLevelDefinitions
23+
AlwaysBreakBeforeMultilineStrings: false
24+
AlwaysBreakTemplateDeclarations: Yes
25+
BinPackArguments: false
26+
BinPackParameters: false
27+
BreakBeforeBinaryOperators: NonAssignment
28+
BreakBeforeBraces: Linux
29+
BreakBeforeTernaryOperators: true
30+
BreakStringLiterals: true
31+
ColumnLimit: 80
32+
CommentPragmas: '^ IWYU pragma:'
33+
ContinuationIndentWidth: 4
34+
Cpp11BracedListStyle: true
35+
DeriveLineEnding: true
36+
DerivePointerAlignment: false
37+
DisableFormat: false
38+
FixNamespaceComments: true
39+
ForEachMacros:
40+
- foreach
41+
- Q_FOREACH
42+
- BOOST_FOREACH
43+
IncludeBlocks: Preserve
44+
IncludeCategories:
45+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
46+
Priority: 2
47+
SortPriority: 0
48+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
49+
Priority: 3
50+
SortPriority: 0
51+
- Regex: '.*'
52+
Priority: 1
53+
SortPriority: 0
54+
IncludeIsMainRegex: '(Test)?$'
55+
IncludeIsMainSourceRegex: ''
56+
IndentCaseLabels: false
57+
IndentCaseBlocks: false
58+
IndentGotoLabels: true
59+
IndentPPDirectives: None
60+
IndentExternBlock: AfterExternBlock
61+
IndentWidth: 8
62+
IndentWrappedFunctionNames: false
63+
KeepEmptyLinesAtTheStartOfBlocks: false
64+
MacroBlockBegin: ''
65+
MacroBlockEnd: ''
66+
MaxEmptyLinesToKeep: 1
67+
NamespaceIndentation: None
68+
PenaltyBreakAssignment: 2
69+
PenaltyBreakBeforeFirstCallParameter: 19
70+
PenaltyBreakComment: 300
71+
PenaltyBreakFirstLessLess: 120
72+
PenaltyBreakString: 1000
73+
PenaltyBreakTemplateDeclaration: 10
74+
PenaltyExcessCharacter: 1000000
75+
PenaltyReturnTypeOnItsOwnLine: 60
76+
PointerAlignment: Right
77+
ReflowComments: true
78+
SortIncludes: true
79+
SortUsingDeclarations: true
80+
SpaceAfterCStyleCast: true
81+
SpaceAfterLogicalNot: false
82+
SpaceAfterTemplateKeyword: true
83+
SpaceBeforeAssignmentOperators: true
84+
SpaceBeforeCpp11BracedList: false
85+
SpaceBeforeCtorInitializerColon: true
86+
SpaceBeforeInheritanceColon: true
87+
SpaceBeforeParens: ControlStatements
88+
SpaceBeforeRangeBasedForLoopColon: true
89+
SpaceInEmptyBlock: false
90+
SpaceInEmptyParentheses: false
91+
SpacesBeforeTrailingComments: 1
92+
SpacesInAngles: false
93+
SpacesInConditionalStatement: false
94+
SpacesInContainerLiterals: true
95+
SpacesInCStyleCastParentheses: false
96+
SpacesInParentheses: false
97+
SpacesInSquareBrackets: false
98+
SpaceBeforeSquareBrackets: false
99+
Standard: Latest
100+
TabWidth: 8
101+
UseCRLF: false
102+
UseTab: AlignWithSpaces

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
compile_commands.json
2+
build/*/kernel
3+
.cache/clangd
4+
*.o

build/i386/GNUmakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.PHONY: qemu clean
2+
3+
SYSROOT=../../sys
4+
5+
CC=gcc
6+
CPPFLAGS=-I.
7+
CFLAGS=-m32 -ffreestanding -nostdlib -fno-builtin
8+
9+
AS=nasm
10+
ASFLAGS=-f elf32
11+
12+
LD=gcc
13+
LDFLAGS=-m32 -nostdlib -ffreestanding -static -T $(SYSROOT)/i386/conf/linker.ld
14+
15+
# Extend the Makefile
16+
vpath %.h machine
17+
vpath %.c $(SYSROOT)/i386/i386
18+
vpath %.c $(SYSROOT)/kernel
19+
vpath %.asm $(SYSROOT)/i386/i386
20+
vpath %.ld $(SYSROOT)/i386/conf
21+
%.o: %.asm
22+
$(AS) $(ASFLAGS) -o $@ $<
23+
#####################
24+
25+
kernel: linker.ld boot.o main.o console.o
26+
$(LD) $(LDFLAGS) -o $@ *.o
27+
28+
boot.o: boot.asm
29+
main.o: main.c platform.h
30+
console.o: console.c platform.h
31+
32+
qemu: kernel
33+
qemu-system-i386 -kernel kernel
34+
35+
clean:
36+
rm -f kernel *.o

build/i386/machine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../sys/i386/include

sys/i386/conf/linker.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
OUTPUT_ARCH(i386);
2+
OUTPUT_FORMAT(elf32-i386);
3+
4+
ENTRY(bootMain)
5+
6+
SECTIONS
7+
{
8+
. = 0x100000;
9+
.boot : { *(.boot) }
10+
.text : ALIGN(0x1000) { *(.text) }
11+
.bss : ALIGN(0x1000) { *(.bss) }
12+
}

sys/i386/i386/boot.asm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
section .boot
2+
3+
align 4
4+
5+
multibootMagic equ 0x1BADB002
6+
multibootFlags equ 0
7+
multibootCheck equ -(multibootMagic + multibootFlags)
8+
9+
multibootHeader:
10+
dd multibootMagic
11+
dd multibootFlags
12+
dd multibootCheck
13+
14+
15+
section .text
16+
17+
extern kernelMain
18+
19+
global bootMain
20+
bootMain:
21+
mov esp, stackTop
22+
mov ebp, esp
23+
call kernelMain
24+
25+
bootDie:
26+
hlt
27+
jmp bootDie
28+
29+
30+
section .bss
31+
32+
stackBottom:
33+
resb 8192
34+
stackTop:
35+
36+
; vim:ft=nasm

sys/i386/i386/console.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <machine/platform.h>
2+
#include <stdint.h>
3+
4+
#define VIDEO_BUFFER 0xb8000
5+
#define VIDEO_COLS 80
6+
#define VIDEO_LINES 25
7+
#define VIDEO_SIZE (VIDEO_COLS * VIDEO_LINES)
8+
9+
static uint16_t *video_region = (uint16_t *) VIDEO_BUFFER;
10+
static uint16_t video_pos = 0;
11+
12+
static void
13+
consolePrintChar(char ch)
14+
{
15+
// Print next character
16+
video_region[video_pos] = 0x0700 | ch;
17+
video_pos++;
18+
19+
// TODO: Maybe scroll if end of screen
20+
}
21+
22+
static void
23+
consoleNextLine()
24+
{
25+
video_pos = (video_pos + VIDEO_COLS) - (video_pos % VIDEO_COLS);
26+
}
27+
28+
void
29+
consolePrint(const char *str)
30+
{
31+
char *ptr = (char *) str;
32+
while (ptr && *ptr) {
33+
switch (*ptr) {
34+
case '\n':
35+
consoleNextLine();
36+
break;
37+
default:
38+
consolePrintChar(*ptr);
39+
break;
40+
}
41+
ptr++;
42+
}
43+
}
44+
45+
void
46+
consoleClear()
47+
{
48+
for (int i = 0; i < VIDEO_SIZE; i++) {
49+
video_region[i] = 0x0720;
50+
}
51+
video_pos = 0;
52+
}

sys/i386/i386/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <machine/platform.h>
2+
3+
void
4+
kernelMain(void)
5+
{
6+
consoleClear();
7+
consolePrint("Hola YouTube\n");
8+
consolePrint("Como estamos\n");
9+
}

sys/i386/include/platform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
void consoleClear();
4+
void consolePrint(const char *);

0 commit comments

Comments
 (0)