From 5d355504bc6f59f9de30889d7203fbee3ce1fd0d Mon Sep 17 00:00:00 2001 From: Ghostie Date: Thu, 3 Mar 2022 00:47:41 +0000 Subject: [PATCH] Initial commit. Still a lot to do --- .clang-format | 149 +++ .gitignore | 6 + Makefile | 92 ++ boot/bios.asm | 142 ++ build/.gitkeep | 0 build/boot/.gitkeep | 0 build/drivers/.gitkeep | 0 build/drivers/vesa/.gitkeep | 0 build/drivers/vesa/fonts/.gitkeep | 0 build/idt/.gitkeep | 0 build/io/.gitkeep | 0 build/mm/.gitkeep | 0 build/string/.gitkeep | 0 compile_flags.txt | 8 + drivers/vesa/fonts/fonts.h | 9 + drivers/vesa/fonts/vga.c | 2058 +++++++++++++++++++++++++++++ drivers/vesa/terminal.c | 71 + drivers/vesa/vesa.c | 105 ++ drivers/vesa/vesa.h | 66 + linker.ld | 31 + sys/config.h | 9 + sys/idt/idt.asm | 13 + sys/idt/idt.c | 41 + sys/idt/idt.h | 24 + sys/io/io.asm | 51 + sys/io/io.h | 12 + sys/kernel.asm | 29 + sys/kernel.c | 17 + sys/kernel.h | 16 + sys/mm/mem.c | 14 + sys/mm/mem.h | 8 + sys/string/string.c | 36 + sys/string/string.h | 8 + 33 files changed, 3015 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 boot/bios.asm create mode 100644 build/.gitkeep create mode 100644 build/boot/.gitkeep create mode 100644 build/drivers/.gitkeep create mode 100644 build/drivers/vesa/.gitkeep create mode 100644 build/drivers/vesa/fonts/.gitkeep create mode 100644 build/idt/.gitkeep create mode 100644 build/io/.gitkeep create mode 100644 build/mm/.gitkeep create mode 100644 build/string/.gitkeep create mode 100644 compile_flags.txt create mode 100644 drivers/vesa/fonts/fonts.h create mode 100644 drivers/vesa/fonts/vga.c create mode 100644 drivers/vesa/terminal.c create mode 100644 drivers/vesa/vesa.c create mode 100644 drivers/vesa/vesa.h create mode 100644 linker.ld create mode 100644 sys/config.h create mode 100644 sys/idt/idt.asm create mode 100644 sys/idt/idt.c create mode 100644 sys/idt/idt.h create mode 100644 sys/io/io.asm create mode 100644 sys/io/io.h create mode 100644 sys/kernel.asm create mode 100644 sys/kernel.c create mode 100644 sys/kernel.h create mode 100644 sys/mm/mem.c create mode 100644 sys/mm/mem.h create mode 100644 sys/string/string.c create mode 100644 sys/string/string.h diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..65928d5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,149 @@ +--- +Language: Cpp +# BasedOnStyle: GNU +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: true + IndentBraces: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: GNU +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 79 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Always +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: c++03 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE +... + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c04f0a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.bin +*~ +\#*\# +.\#* +*.out \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c05433f --- /dev/null +++ b/Makefile @@ -0,0 +1,92 @@ +CROSS_PATH=$(HOME)/opt/cross/bin + +LD=$(CROSS_PATH)/i686-elf-ld +CC=$(CROSS_PATH)/i686-elf-gcc + +ASM=nasm +ECHO=echo -e +QEMU=qemu-system-i386 +GDB=gdb + +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-parameter -nostdlib \ + -nostartfiles -nodefaultlibs -Wall -O0 +INCLUDES=-I. + +NO_SECTORS=100 + +OBJS=build/kernel.asm.o build/kernel.o build/idt/idt.asm.o build/idt/idt.o \ + build/mm/mem.o build/io/io.asm.o build/string/string.o + +# VESA Driver +OBJS+=build/drivers/vesa/vesa.o build/drivers/vesa/terminal.o \ + build/drivers/vesa/fonts/vga.o + +all: build/boot/boot.bin build/kernel.out + @dd if=build/boot/boot.bin > kinl.bin + @dd if=build/kernel.out >> kinl.bin + @dd if=/dev/zero bs=512 count=$(NO_SECTORS) >> kinl.bin + +build/kernel.out: $(OBJS) + @$(LD) -g -relocatable $(OBJS) -o build/kernelfull.o + @$(CC) $(CFLAGS) -T linker.ld -o $@ -ffreestanding -O0 -nostdlib \ + build/kernelfull.o + +build/boot/boot.bin: boot/bios.asm + @$(ECHO) "ASM\t\t"$< + @$(ASM) -f bin $< -o $@ + +build/kernel.asm.o: sys/kernel.asm + @$(ECHO) "ASM\t\t"$< + @$(ASM) -f elf -g $< -o $@ + +build/kernel.o: sys/kernel.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +build/idt/idt.asm.o: sys/idt/idt.asm + @$(ECHO) "ASM\t\t"$< + @$(ASM) -f elf -g $< -o $@ + +build/idt/idt.o: sys/idt/idt.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +build/mm/mem.o: sys/mm/mem.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +build/io/io.asm.o: sys/io/io.asm + @$(ECHO) "ASM\t\t"$< + @$(ASM) -f elf -g $< -o $@ + +build/string/string.o: sys/string/string.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +# VESA Driver +build/drivers/vesa/vesa.o: drivers/vesa/vesa.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +build/drivers/vesa/terminal.o: drivers/vesa/terminal.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +build/drivers/vesa/fonts/vga.o: drivers/vesa/fonts/vga.c + @$(ECHO) "CC\t\t"$< + @$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@ + +gdb: all + @$(GDB) -ex "set confirm off" \ + -ex "add-symbol-file build/kernelfull.o 0x0100000" \ + -ex "target remote | qemu-system-i386 -hda kinl.bin -S -gdb stdio" + +run: all + @$(QEMU) -hda kinl.bin + +clean: + @rm -Rf build/boot/boot.bin build/kernel.out \ + build/kernelfull.o $(OBJS) diff --git a/boot/bios.asm b/boot/bios.asm new file mode 100644 index 0000000..1f3e113 --- /dev/null +++ b/boot/bios.asm @@ -0,0 +1,142 @@ + ORG 0x7c00 + BITS 16 + + CODE_SEG equ gdt_code - gdt_start + DATA_SEG equ gdt_data - gdt_start + +_start: + jmp short start + nop + + times 33 db 0 + +start: + jmp 0:step2 + +step2: + cli ; Disable interrupts + mov ax, 0x00 + mov ds, ax + mov es, ax + + mov ss, ax + mov sp, 0x7c00 + sti ; Enable interrupts + + mov ax, 0x4F01 + mov cx, 0x118 + mov di, 0x500 + int 0x10 + + mov ax, 0x4F02 + mov bx, 0x118 + int 0x10 + + .load_protected: + cli + lgdt [gdt_descriptor] + mov eax, cr0 + or eax, 1 + mov cr0, eax + jmp CODE_SEG:load32 + + ;; GDT +gdt_start: +gdt_null: + dd 0x0 + dd 0x0 + + ;; offset 0x8 +gdt_code: ; CS Should point to this + dw 0xffff ; Segment limit first 0-15 bits + dw 0 ; Base first 0-15 bits + db 0 ; Base 16-23 bits + db 0x9a ; Access bytes + db 11001111b ; High 4 bit flags and the low 4 bit flags + db 0 ; Base 24-31 bits + + ;; offset 0x10 +gdt_data: ; DS, SS, ES, FS, GS + dw 0xffff ; Segment limit, first 0-15 bits + dw 0 ; Base first 0-15 bits + db 0 ; Base 16-23 bits + db 0x92 ; Access byte + db 11001111b ; High 4 bit flags and the low 4 bit flags + db 0 ; Base 24-31 bits +gdt_end: +gdt_descriptor: + dw gdt_end - gdt_start - 1 + dd gdt_start + + [BITS 32] +load32: + mov eax, 1 + mov ecx, 100 + mov edi, 0x0100000 + call ata_lba_read + jmp CODE_SEG:0x0100000 + + +ata_lba_read: + mov ebx, eax ; Backup the LBA + + ;; Send the highest 8 bits of the LBA to the hard disk controller + shr eax, 24 + or eax, 0xE0 + mov dx, 0x1F6 + out dx, al + ;; Finished sending the highest 8 bits of the LBA + + ;; Send the total sectors to read + mov eax, ecx + mov dx, 0x1F2 + out dx, al + ;; Finished sending the total sectors to read + + ;; Send more bits of the LBA + mov eax, ebx ; Restore the backup LBA + mov dx, 0x1F3 + out dx, al + ;; Finished sending more bits of the LBA + + ;; Send more bits of the LBA + mov dx, 0x1F4 + mov eax, ebx ; Restore the backup LBA + shr eax, 8 + out dx, al + ;; Finished sending more bits of the LBA + + ;; Send upper 16 bits of the LBA + mov dx, 0x1F5 + mov eax, ebx ; Restore the backup LBA + shr eax, 16 + out dx, al + ;; Finished sending upper 16 bits of the LBA + + mov dx, 0x1F7 + mov al, 0x20 + out dx, al + + ;; Read all sectors into memory + .next_sector: + push ecx + + ;; Checking if we need to read + .try_again: + mov dx, 0x1F7 + in al, dx + test al, 8 + jz .try_again + + ;; We need to read 256 words at a time + mov ecx, 256 + mov dx, 0x1F0 + rep insw + pop ecx + loop .next_sector + ;; End of reading sectors into memory + + ret + + times 510-($-$$) db 0 + dw 0xAA55 diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/boot/.gitkeep b/build/boot/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/drivers/.gitkeep b/build/drivers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/drivers/vesa/.gitkeep b/build/drivers/vesa/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/drivers/vesa/fonts/.gitkeep b/build/drivers/vesa/fonts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/idt/.gitkeep b/build/idt/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/io/.gitkeep b/build/io/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/mm/.gitkeep b/build/mm/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/build/string/.gitkeep b/build/string/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..a854666 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,8 @@ +-Wno-unused-function +-Wno-unused-label +-Wno-cpp +-Wno-unused-parameter +-nostdlib +-nodefaultlibs +-Wall +-I. diff --git a/drivers/vesa/fonts/fonts.h b/drivers/vesa/fonts/fonts.h new file mode 100644 index 0000000..e380509 --- /dev/null +++ b/drivers/vesa/fonts/fonts.h @@ -0,0 +1,9 @@ +#ifndef __VESA_FONTS_H +#define __VESA_FONTS_H + +#define FONT_VGA_WIDTH 12 +#define FONT_VGA_HEIGHT 18 + +int font_vga (int index, int y); + +#endif diff --git a/drivers/vesa/fonts/vga.c b/drivers/vesa/fonts/vga.c new file mode 100644 index 0000000..95b6a1d --- /dev/null +++ b/drivers/vesa/fonts/vga.c @@ -0,0 +1,2058 @@ +int +font_vga (int index, int y) +{ + unsigned int characters_vga_0[][150] = { + { + // " " + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + }, + { + // "!" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b111000000000, + 0b111000000000, + 0b111000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + }, + { + // '"' + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b010100000000, + 0b010100000000, + }, + { + // "#" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b011110000000, + 0b111111000000, + 0b011110000000, + 0b011110000000, + 0b011110000000, + 0b011110000000, + 0b111111000000, + 0b011110000000, + 0b011110000000, + }, + { + // "$" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b011110000000, + 0b110011000000, + 0b110001000000, + 0b110000000000, + 0b011110000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b100011000000, + 0b110011000000, + 0b011110000000, + 0b001100000000, + 0b001100000000, + }, + { + // "%" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011100000, + 0b100001000000, + 0b000101000000, + 0b000110000000, + 0b000110000000, + 0b011000000000, + 0b011000000000, + 0b110001100000, + 0b100001000000, + }, + { + // "&" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011100000000, + 0b011110000000, + 0b011110000000, + 0b001100000000, + 0b001101000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011011000000, + }, + { + // "'" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + }, + { + // "(" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b011000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b011000000000, + 0b001100000000, + }, + { + // ")" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b011000000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b011000000000, + 0b110000000000, + }, + { + // "*" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011011000000, + 0b001110000000, + 0b111111100000, + 0b001110000000, + 0b011111000000, + 0b011011000000, + }, + { + // "+" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b111111000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + }, + { + // "," + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b110000000000, + }, + }; + + unsigned int characters_vga_1[][150] = { + { + // "-" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111110000000, + }, + { + // "." + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + }, + { + // "/" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000001100000, + 0b000001100000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b011000000000, + 0b011000000000, + 0b110000000000, + 0b100000000000, + }, + { + // "0" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011100000000, + 0b011011000000, + 0b110011000000, + 0b110011000000, + 0b110111000000, + 0b110111000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011011000000, + 0b011100000000, + }, + { + // "1" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011000000000, + 0b011000000000, + 0b111000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b111110000000, + }, + { + // "2" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011111000000, + 0b110001100000, + 0b000001100000, + 0b000011000000, + 0b000011000000, + 0b001100000000, + 0b011000000000, + 0b011000000000, + 0b110000000000, + 0b110001100000, + 0b111111100000, + }, + { + // "3" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b000011000000, + 0b000011000000, + 0b001110000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "4" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000110000000, + 0b000110000000, + 0b001110000000, + 0b011110000000, + 0b110110000000, + 0b111111000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b000111000000, + }, + { + // "5" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111110000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "6" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b011000000000, + 0b110000000000, + 0b110000000000, + 0b111110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "7" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111000000, + 0b110011000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b001111000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + }, + { + // "8" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "9" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011111000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b000011000000, + 0b000110000000, + 0b011100000000, + }, + }; + + unsigned int characters_vga_2[][150] = { + { + // ":" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + }, + { + // ";" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011000000000, + 0b011000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011000000000, + 0b011000000000, + 0b110000000000, + }, + { + // "<" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000011000000, + 0b001100000000, + 0b001100000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b001100000000, + 0b001100000000, + 0b000011000000, + }, + { + // "=" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111100000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111100000000, + }, + { + // ">" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b001100000000, + 0b001100000000, + 0b000010000000, + 0b000011000000, + 0b001100000000, + 0b011000000000, + 0b110000000000, + 0b110000000000, + }, + { + // "?" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b000110000000, + 0b000110000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + }, + { + // "@" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011100000000, + 0b110011000000, + 0b110011000000, + 0b111111000000, + 0b111111000000, + 0b111111000000, + 0b111111000000, + 0b111100000000, + 0b110000000000, + 0b011100000000, + }, + { + // "A" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b011011000000, + 0b110011000000, + 0b110011000000, + 0b111111000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + }, + { + // "B" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b111110000000, + }, + { + // "C" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b011011000000, + 0b110001000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110001000000, + 0b011011000000, + 0b001110000000, + }, + { + // "D" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111100000000, + 0b011110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011110000000, + 0b111100000000, + }, + { + // "E" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111000000, + 0b011011000000, + 0b011010000000, + 0b011100000000, + 0b011100000000, + 0b011100000000, + 0b011000000000, + 0b011000000000, + 0b011001000000, + 0b011011000000, + 0b111111000000, + }, + { + // "F" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111000000, + 0b011011000000, + 0b011001000000, + 0b011100000000, + 0b011100000000, + 0b011100000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b111000000000, + }, + }; + + unsigned int characters_vga_3[][150] = { + { + // "G" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b011011000000, + 0b110001000000, + 0b110000000000, + 0b110000000000, + 0b110111000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011011000000, + 0b001101000000, + }, + { + // "H" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b111111000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + }, + { + // "I" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111000000000, + }, + { + // "J" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001111000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011100000000, + }, + { + // "K" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110110000000, + 0b110110000000, + 0b111100000000, + 0b110110000000, + 0b110110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + }, + { + // "L" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011001000000, + 0b011011000000, + 0b111111000000, + }, + { + // "M" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b110110000000, + 0b111110000000, + 0b111110000000, + 0b111110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + }, + { + // "N" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b110110000000, + 0b111110000000, + 0b111110000000, + 0b111110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + }, + { + // "O" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "P" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011110000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b111000000000, + }, + { + // "Q" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b111111000000, + 0b111111000000, + 0b011110000000, + 0b000110000000, + 0b000111000000, + }, + { + // "R" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b111110000000, + 0b110110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + }, + { + // "S" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b011000000000, + 0b011000000000, + 0b000110000000, + 0b000110000000, + 0b000011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + }; + + unsigned int characters_vga_4[][150] = { + { + // "T" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111100000000, + 0b111100000000, + 0b111100000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + }, + { + // "U" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "V" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011011000000, + 0b001100000000, + 0b000100000000, + }, + { + // "W" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110111000000, + 0b110111000000, + 0b110111000000, + 0b111111000000, + 0b111011000000, + 0b011011000000, + }, + { + // "X" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + 0b011110000000, + 0b011110000000, + 0b001100000000, + 0b011110000000, + 0b011110000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + }, + { + // "Y" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b011100000000, + }, + { + // "Z" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111100000, + 0b100001100000, + 0b100001100000, + 0b000110000000, + 0b000110000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b100001100000, + 0b100001100000, + 0b111111100000, + }, + { + // "[" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111000000000, + }, + { + // "\" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b100000000000, + 0b110000000000, + 0b110000000000, + 0b011000000000, + 0b001000000000, + 0b001100000000, + 0b001100000000, + 0b000110000000, + 0b000110000000, + 0b000010000000, + }, + { + // "]" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b111000000000, + }, + { + // "^" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b011011000000, + 0b110011000000, + }, + { + // "_" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111000000, + }, + { + // "`" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b011000000000, + 0b001100000000, + }, + }; + + unsigned int characters_vga_5[][150] = { + { + // "a" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011100000000, + 0b000110000000, + 0b000110000000, + 0b011110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011011000000, + }, + { + // "b" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111100000000, + 0b110110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b111110000000, + }, + { + // "c" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110011000000, + 0b011110000000, + }, + { + // "d" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000110000000, + 0b000110000000, + 0b000110000000, + 0b001110000000, + 0b011110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011011000000, + }, + { + // "e" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b111111000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110011000000, + 0b011110000000, + }, + { + // "f" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011100000000, + 0b110110000000, + 0b110010000000, + 0b110000000000, + 0b111000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111000000000, + }, + { + // "g" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011011000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011110000000, + 0b000110000000, + 0b110110000000, + 0b011100000000, + }, + { + // "h" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110110000000, + 0b111011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + }, + { + // "i" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111000000000, + }, + { + // "j" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b000000000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b111100000000, + 0b111100000000, + 0b011000000000, + }, + { + // "k" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110011000000, + 0b110110000000, + 0b111110000000, + 0b111100000000, + 0b111100000000, + 0b110110000000, + 0b110011000000, + 0b110011000000, + }, + { + // "l" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b111000000000, + }, + { + // "m" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b111111000000, + 0b111011000000, + 0b111011000000, + 0b111011000000, + 0b111011000000, + 0b111011000000, + 0b110011000000, + }, + }; + + unsigned int characters_vga_6[][150] = { + { + // "n" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + }, + { + // "o" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + }, + { + // "p" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011011000000, + 0b011110000000, + 0b011000000000, + 0b111000000000, + }, + { + // "q" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011110000000, + 0b000110000000, + 0b000110000000, + 0b001110000000, + }, + { + // "r" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b011011000000, + 0b011011000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b111000000000, + }, + { + // "s" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011110000000, + 0b110011000000, + 0b111010000000, + 0b001100000000, + 0b001100000000, + 0b000110000000, + 0b110011000000, + 0b011110000000, + }, + { + // "t" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000100000000, + 0b001100000000, + 0b001100000000, + 0b111110000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001101100000, + 0b000110000000, + }, + { + // "u" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b110110000000, + 0b011011000000, + }, + { + // "v" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011110000000, + 0b001100000000, + }, + { + // "w" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b111111000000, + 0b110111000000, + 0b111011000000, + 0b111011000000, + 0b111111000000, + 0b011011000000, + }, + { + // "x" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b011110000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b011110000000, + 0b110011000000, + }, + { + // "y" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b110011000000, + 0b011111000000, + 0b000011000000, + 0b000110000000, + 0b111100000000, + }, + { + // "z" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b111111100000, + 0b110011000000, + 0b000110000000, + 0b001100000000, + 0b001100000000, + 0b011000000000, + 0b110011100000, + 0b111111100000, + }, + }; + + unsigned int characters_vga_7[][150] = { + { + // "{" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000110000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b111100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b001100000000, + 0b000110000000, + }, + { + // "|" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + 0b110000000000, + }, + { + // "}" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b110000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011110000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b011000000000, + 0b110000000000, + }, + { + // "~" + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b000000000000, + 0b011011000000, + 0b110110000000, + }, + }; + + int start = (int)(' '); + if (index >= start && index < start + 13) + { + return characters_vga_0[index - start][y]; + } + else if (index >= start + 13 && index < start + 13 * 2) + { + return characters_vga_1[index - (start + 13)][y]; + } + else if (index >= start + 13 * 2 && index < start + 13 * 3) + { + return characters_vga_2[index - (start + 13 * 2)][y]; + } + else if (index >= start + 13 * 3 && index < start + 13 * 4) + { + return characters_vga_3[index - (start + 13 * 3)][y]; + } + else if (index >= start + 13 * 4 && index < start + 13 * 5) + { + return characters_vga_4[index - (start + 13 * 4)][y]; + } + else if (index >= start + 13 * 5 && index < start + 13 * 6) + { + return characters_vga_5[index - (start + 13 * 5)][y]; + } + else if (index >= start + 13 * 6 && index < start + 13 * 7) + { + return characters_vga_6[index - (start + 13 * 6)][y]; + } + else if (index >= start + 13 * 7 && index < start + 13 * 8) + { + return characters_vga_7[index - (start + 13 * 7)][y]; + } + + return 0; +} diff --git a/drivers/vesa/terminal.c b/drivers/vesa/terminal.c new file mode 100644 index 0000000..a63fb02 --- /dev/null +++ b/drivers/vesa/terminal.c @@ -0,0 +1,71 @@ +#include "vesa.h" + +#include "fonts/fonts.h" + +#include +#include + +#define TERMINAL_DEFAULT_FONT font_vga + +u16 _row = 0; +u16 _col = 0; + +static void +terminal_putchar (char c, u32 col) +{ + if (c == '\n') + { + _row += 1; + _col = 0; + return; + } + + vesa_putchar (TERMINAL_DEFAULT_FONT, FONT_VGA_WIDTH, FONT_VGA_HEIGHT, c, + _col * (FONT_VGA_WIDTH / 1.5), _row * FONT_VGA_HEIGHT, col); + + _col += 1; + if (_col * (FONT_VGA_WIDTH / 1.5) >= vesa_get_width ()) + { + _col = 0; + _row += 1; + } +} + +void +terminal_print (const char *str) +{ + int len = strlen (str); + for (int i = 0; i < len; i++) + { + terminal_putchar (str[i], vesa_make_colour (255, 255, 255)); + } +} + +void +terminal_print_ext (const char *str, u32 col) +{ + int len = strlen (str); + + for (int i = 0; i < len; i++) + { + terminal_putchar (str[i], col); + } +} + +// This is a function that will write "* PENDING `task'" to the screen +void +terminal_print_pending (const char *task) +{ + terminal_print_ext ("\n*", vesa_make_colour (255, 105, 147)); + terminal_print_ext (" PENDING ", vesa_make_colour (255, 20, 147)); + terminal_print (task); +} + +// This is a function that will write "* DONE `task'" to the screen +void +terminal_print_done (const char *task) +{ + terminal_print_ext ("\n*", vesa_make_colour (0, 255, 0)); + terminal_print_ext (" DONE ", vesa_make_colour (34, 139, 34)); + terminal_print (task); +} diff --git a/drivers/vesa/vesa.c b/drivers/vesa/vesa.c new file mode 100644 index 0000000..01e5b33 --- /dev/null +++ b/drivers/vesa/vesa.c @@ -0,0 +1,105 @@ +#include "vesa.h" + +struct vbe_info *info = (struct vbe_info *)VBE_INFO_ADDR; + +u32 +vesa_make_colour (u8 r, u8 g, u8 b) +{ + return r << info->red_position | g << info->green_position + | b << info->blue_position; +} + +void +vesa_putpixel (u16 x, u16 y, u32 col) +{ + void *framebuffer = (void *)(unsigned long)info->framebuffer; + + switch (info->bpp) + { + case 8: + { + u8 *pixel = framebuffer + info->pitch * y + x; + *pixel = col; + } + break; + + case 15: + case 16: + { + u16 *pixel = framebuffer + info->pitch * y + 2 * x; + *pixel = col; + } + break; + + case 24: + { + u32 *pixel = framebuffer + info->pitch * y + 3 * x; + *pixel = (col & 0xffffff) | (*pixel & 0xff000000); + } + break; + + case 32: + { + u32 *pixel = framebuffer + info->pitch * y + 4 * x; + *pixel = col; + } + break; + } +} + +void +vesa_cls (u32 col) +{ + for (u16 y = 0; y < info->height; y++) + { + for (u16 x = 0; x < info->width; x++) + { + vesa_putpixel (x, y, col); + } + } +} + +void +vesa_draw_rect (u16 x, u16 y, u16 w, u16 h, u32 col) +{ + for (u16 j = y; j < (y + h); j++) + { + for (u16 i = x; i < (x + w); i++) + { + vesa_putpixel (i, j, col); + } + } +} + +u16 +vesa_get_width () +{ + return info->width; +} + +u16 +vesa_get_height () +{ + return info->height; +} + +void +vesa_putchar (int (*font) (int, int), u8 font_width, u8 font_height, char c, + u16 x, u16 y, u32 col) +{ + for (u8 j = 0; j < font_height; j++) + { + u32 row = (*font) ((i32)c, j); + i32 shift = font_width - 1; + i32 bit_val = 0; + + for (u8 i = 0; i < font_width; i++) + { + bit_val = (row >> shift) & 1; + if (bit_val) + vesa_putpixel (x + i, y + j, col); + + shift -= 1; + } + } +} diff --git a/drivers/vesa/vesa.h b/drivers/vesa/vesa.h new file mode 100644 index 0000000..00e5fb3 --- /dev/null +++ b/drivers/vesa/vesa.h @@ -0,0 +1,66 @@ +#ifndef __VESA_H +#define __VESA_H + +#include + +#define VBE_INFO_ADDR 0x500 + +struct vbe_info +{ + u16 attributes; + u8 window_a; + u8 window_b; + u16 granularity; + u16 window_size; + u16 segment_a; + u16 segment_b; + u32 win_func_ptr; + u16 pitch; + u16 width; + u16 height; + u8 w_char; + u8 y_char; + u8 planes; + u8 bpp; + u8 banks; + u8 memory_model; + u8 bank_size; + u8 image_pages; + u8 reserved0; + + u8 red_mask; + u8 red_position; + u8 green_mask; + u8 green_position; + u8 blue_mask; + u8 blue_position; + u8 reserved_mask; + u8 reserved_position; + u8 direct_colour_attributes; + + u32 framebuffer; + + u32 off_screen_mem_off; + u16 off_screen_mem_size; + + u8 reserved1[206]; +} __attribute__ ((packed)); + +u32 vesa_make_colour (u8 r, u8 g, u8 b); +void vesa_putpixel (u16 x, u16 y, u32 col); +void vesa_cls (u32 col); +void vesa_draw_rect (u16 x, u16 y, u16 w, u16 h, u32 col); +void vesa_putchar (int (*font) (int, int), u8 font_width, u8 font_height, + char c, u16 x, u16 y, u32 col); + +// "terminal" +void terminal_print (const char *str); +void terminal_print_ext (const char *str, u32 col); + +void terminal_print_pending (const char *task); +void terminal_print_done (const char *task); + +u16 vesa_get_width (); +u16 vesa_get_height (); + +#endif diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..a088da2 --- /dev/null +++ b/linker.ld @@ -0,0 +1,31 @@ +ENTRY (_start) +OUTPUT_FORMAT(binary) +SECTIONS +{ + . = 1M; + .text : ALIGN (4096) + { + *(.text) + } + + .rodata : ALIGN (4096) + { + *(.rodata) + } + + .data : ALIGN (4096) + { + *(.data) + } + + .bss : ALIGN (4096) + { + *(COMMON) + *(.bss) + } + + .asm : + { + *(.asm) + } +} diff --git a/sys/config.h b/sys/config.h new file mode 100644 index 0000000..d931391 --- /dev/null +++ b/sys/config.h @@ -0,0 +1,9 @@ +#ifndef __CONFIG_H +#define __CONFIG_H + +#define KERNEL_CODE_SELECTOR 0x08 +#define KERNEL_DATA_SELECTOR 0x10 + +#define KINL_TOTAL_INTERRUPTS 512 + +#endif diff --git a/sys/idt/idt.asm b/sys/idt/idt.asm new file mode 100644 index 0000000..a8e1f11 --- /dev/null +++ b/sys/idt/idt.asm @@ -0,0 +1,13 @@ + section .asm + + global idt_load + +idt_load: + push ebp + mov ebp, esp + + mov ebx, [ebp + 8] + lidt [ebx] + + pop ebp + ret diff --git a/sys/idt/idt.c b/sys/idt/idt.c new file mode 100644 index 0000000..cf7c5a6 --- /dev/null +++ b/sys/idt/idt.c @@ -0,0 +1,41 @@ +#include "idt.h" +#include + +#include + +#include + +struct idt_desc idt_descriptors[KINL_TOTAL_INTERRUPTS]; +struct idtr_desc idtr_descriptor; + +extern void idt_load (void *ptr); + +void +idt_zero () +{ + terminal_print ("Divide by zero error\n"); +} + +void +idt_set (int interrupt_no, void *address) +{ + struct idt_desc *desc = &idt_descriptors[interrupt_no]; + desc->offset_1 = (u32)address & 0x0000ffff; + desc->selector = KERNEL_CODE_SELECTOR; + desc->zero = 0x00; + desc->type_attribute = 0xee; + desc->offset_2 = (u32)address >> 16; +} + +void +idt_init () +{ + memset (idt_descriptors, 0, sizeof (idt_descriptors)); + idtr_descriptor.limit = sizeof (idt_descriptors) - 1; + idtr_descriptor.base = (u32)idt_descriptors; + + idt_set (0, idt_zero); + + // Load the interrupt descriptor table + idt_load (&idtr_descriptor); +} diff --git a/sys/idt/idt.h b/sys/idt/idt.h new file mode 100644 index 0000000..782c4f6 --- /dev/null +++ b/sys/idt/idt.h @@ -0,0 +1,24 @@ +#ifndef __IDT_H +#define __IDT_H + +#include + +struct idt_desc +{ + u16 offset_1; // Offset bits 0 - 16 + u16 selector; // Selector that's in our GDT + u8 zero; + u8 type_attribute; // Descriptor type attribute + u16 offset_2; // Offset bits 16-31 +} __attribute__ ((packed)); + +struct idtr_desc +{ + u16 limit; // Size of descriptor tabe + u32 base; // Base address of the start of the interrupt table +} __attribute__ ((packed)); + +void idt_init (); +void idt_set (int interrupt_no, void *address); + +#endif diff --git a/sys/io/io.asm b/sys/io/io.asm new file mode 100644 index 0000000..ae96417 --- /dev/null +++ b/sys/io/io.asm @@ -0,0 +1,51 @@ + section .asm + + global insb + global insw + + global outb + global outw + +insb: + push ebp + mov ebp, esp + + xor eax, eax + mov edx, [ebp + 8] + in al, dx + + pop ebp + ret + +insw: + push ebp + mov ebp, esp + + xor eax, eax + mov edx, [ebp + 8] + in ax, dx + + pop ebp + ret + +outb: + push ebp + mov ebp, esp + + mov eax, [ebp + 12] + mov edx, [ebp + 8] + out dx, al + + pop ebp + ret + +outw: + push ebp + mov ebp, esp + + mov eax, [ebp + 12] + mov edx, [ebp + 8] + out dx, ax + + pop ebp + ret diff --git a/sys/io/io.h b/sys/io/io.h new file mode 100644 index 0000000..884c4a0 --- /dev/null +++ b/sys/io/io.h @@ -0,0 +1,12 @@ +#ifndef __IO_H +#define __IO_H + +#include + +u8 insb (u16 port); +u16 insw (u16 port); + +void outb (u16 port, u8 val); +void outw (u16 port, u16 val); + +#endif diff --git a/sys/kernel.asm b/sys/kernel.asm new file mode 100644 index 0000000..e2797e9 --- /dev/null +++ b/sys/kernel.asm @@ -0,0 +1,29 @@ + [BITS 32] + + extern kmain + + global _start + + CODE_SEG equ 0x08 + DATA_SEG equ 0x10 + +_start: + mov ax, DATA_SEG + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + mov ebp, 0x00200000 + mov esp, ebp + + ;; Enable A20 line + in al, 0x92 + or al, 2 + out 0x92, al + + call kmain + + jmp $ + + times 512-($-$$) db 0 diff --git a/sys/kernel.c b/sys/kernel.c new file mode 100644 index 0000000..14ef949 --- /dev/null +++ b/sys/kernel.c @@ -0,0 +1,17 @@ +#include + +#include + +#include +#include + +void +kmain () +{ + terminal_print ("Welcome to the Kinl operating system!\n"); + + // Initialise the IDT + terminal_print_pending ("Initialise IDT"); + idt_init (); + terminal_print_done ("Initialised IDT"); +} diff --git a/sys/kernel.h b/sys/kernel.h new file mode 100644 index 0000000..a66f575 --- /dev/null +++ b/sys/kernel.h @@ -0,0 +1,16 @@ +#ifndef __KERNEL_H +#define __KERNEL_H + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef char i8; +typedef short i16; +typedef int i32; +typedef long long i64; + +void kmain (); + +#endif diff --git a/sys/mm/mem.c b/sys/mm/mem.c new file mode 100644 index 0000000..f68107f --- /dev/null +++ b/sys/mm/mem.c @@ -0,0 +1,14 @@ +#include "mem.h" + +void * +memset (void *ptr, int c, u32 size) +{ + char *c_ptr = (char *)ptr; + + for (u32 i = 0; i < size; i++) + { + c_ptr[i] = (char)c; + } + + return ptr; +} diff --git a/sys/mm/mem.h b/sys/mm/mem.h new file mode 100644 index 0000000..cd8d376 --- /dev/null +++ b/sys/mm/mem.h @@ -0,0 +1,8 @@ +#ifndef __MEM_H_ +#define __MEM_H + +#include + +void *memset (void *ptr, int c, u32 size); + +#endif diff --git a/sys/string/string.c b/sys/string/string.c new file mode 100644 index 0000000..8f0b035 --- /dev/null +++ b/sys/string/string.c @@ -0,0 +1,36 @@ +#include "string.h" + +char +tolower (char s1) +{ + if (s1 >= 65 && s1 <= 90) + s1 += 32; + + return s1; +} + +int +strlen (const char *str) +{ + int i = 0; + while (*str != 0) + { + i++; + str += 1; + } + + return i; +} + +int +strnlen (const char *str, int max) +{ + int i = 0; + for (int i = 0; i < max; i++) + { + if (str[i] == 0) + break; + } + + return i; +} diff --git a/sys/string/string.h b/sys/string/string.h new file mode 100644 index 0000000..dc43e7f --- /dev/null +++ b/sys/string/string.h @@ -0,0 +1,8 @@ +#ifndef __STRING_H +#define __STRING_H + +char tolower (char s1); +int strlen (const char *str); +int strnlen (const char *str, int max); + +#endif