├── Binaries.asm ├── CPUID.asm ├── DiskRead.asm ├── ExtendedProgram.asm ├── IDT.asm ├── IDT.cpp ├── IO.cpp ├── KBScanCodeSet1.cpp ├── Kernel.cpp ├── Keyboard.cpp ├── README.txt ├── SimplePaging.asm ├── TextModeColorCodes.cpp ├── TextPrint.cpp ├── Typedefs.cpp ├── bochsrc.bxrc ├── bootloader.asm ├── compileasm.bat ├── gdt.asm ├── link.ld └── print.asm /Binaries.asm: -------------------------------------------------------------------------------- 1 | %macro IncBin 2 2 | SECTION .rodata 3 | GLOBAL %1 4 | %1: 5 | incbin %2 6 | db 0 7 | %1_size: dq %1_size - %1 8 | %endmacro 9 | -------------------------------------------------------------------------------- /CPUID.asm: -------------------------------------------------------------------------------- 1 | 2 | DetectCPUID: 3 | 4 | pushfd 5 | pop eax 6 | 7 | mov ecx, eax 8 | 9 | xor eax, 1 << 21 10 | 11 | push eax 12 | popfd 13 | 14 | pushfd 15 | pop eax 16 | 17 | push ecx 18 | popfd 19 | 20 | xor eax,ecx 21 | jz NoCPUID 22 | ret 23 | 24 | DetectLongMode: 25 | mov eax, 0x80000001 26 | cpuid 27 | test edx, 1 << 29 28 | jz NoLongMode 29 | ret 30 | 31 | NoLongMode: 32 | hlt ; No Long Mode Support 33 | 34 | NoCPUID: 35 | 36 | hlt ; No CPUID support. -------------------------------------------------------------------------------- /DiskRead.asm: -------------------------------------------------------------------------------- 1 | 2 | PROGRAM_SPACE equ 0x8000 3 | 4 | ReadDisk: 5 | 6 | mov ah, 0x02 7 | mov bx, PROGRAM_SPACE 8 | mov al, 32 9 | mov dl, [BOOT_DISK] 10 | mov ch, 0x00 11 | mov dh, 0x00 12 | mov cl, 0x02 13 | 14 | int 0x13 15 | 16 | jc DiskReadFailed 17 | 18 | ret 19 | 20 | BOOT_DISK: 21 | db 0 22 | 23 | DiskReadErrorString: 24 | db 'Disk Read Failed',0 25 | 26 | DiskReadFailed: 27 | mov bx, DiskReadErrorString 28 | call PrintString 29 | 30 | jmp $ 31 | -------------------------------------------------------------------------------- /ExtendedProgram.asm: -------------------------------------------------------------------------------- 1 | 2 | jmp EnterProtectedMode 3 | 4 | %include "gdt.asm" 5 | %include "print.asm" 6 | 7 | 8 | EnterProtectedMode: 9 | call EnableA20 10 | cli 11 | lgdt [gdt_descriptor] 12 | mov eax, cr0 13 | or eax, 1 14 | mov cr0, eax 15 | jmp codeseg:StartProtectedMode 16 | 17 | EnableA20: 18 | in al, 0x92 19 | or al, 2 20 | out 0x92, al 21 | ret 22 | 23 | [bits 32] 24 | 25 | %include "CPUID.asm" 26 | %include "SimplePaging.asm" 27 | 28 | StartProtectedMode: 29 | 30 | mov ax, dataseg 31 | mov ds, ax 32 | mov ss, ax 33 | mov es, ax 34 | mov fs, ax 35 | mov gs, ax 36 | 37 | mov [0xb8000], byte 'H' 38 | mov [0xb8002], byte 'e' 39 | mov [0xb8004], byte 'l' 40 | mov [0xb8006], byte 'l' 41 | mov [0xb8008], byte 'o' 42 | mov [0xb800a], byte ' ' 43 | mov [0xb800c], byte 'W' 44 | mov [0xb800e], byte 'o' 45 | mov [0xb8010], byte 'r' 46 | mov [0xb8012], byte 'l' 47 | mov [0xb8014], byte 'd' 48 | 49 | call DetectCPUID 50 | call DetectLongMode 51 | call SetUpIdentityPaging 52 | call EditGDT 53 | jmp codeseg:Start64Bit 54 | 55 | [bits 64] 56 | 57 | [extern _start] 58 | 59 | %include "IDT.asm" 60 | 61 | Start64Bit: 62 | mov edi, 0xb8000 63 | mov rax, 0x1f201f201f201f20 64 | mov ecx, 500 65 | rep stosq 66 | 67 | call ActivateSSE 68 | call _start 69 | 70 | jmp $ 71 | 72 | ActivateSSE: 73 | mov rax, cr0 74 | and ax, 0b11111101 75 | or ax, 0b00000001 76 | mov cr0, rax 77 | 78 | mov rax, cr4 79 | or ax, 0b1100000000 80 | mov cr4, rax 81 | 82 | ret 83 | 84 | times 2048-($-$$) db 0 85 | -------------------------------------------------------------------------------- /IDT.asm: -------------------------------------------------------------------------------- 1 | 2 | [extern _idt] 3 | idtDescriptor: 4 | dw 4095 5 | dq _idt 6 | 7 | 8 | %macro PUSHALL 0 9 | push rax 10 | push rcx 11 | push rdx 12 | push r8 13 | push r9 14 | push r10 15 | push r11 16 | %endmacro 17 | 18 | %macro POPALL 0 19 | pop r11 20 | pop r10 21 | pop r9 22 | pop r8 23 | pop rdx 24 | pop rcx 25 | pop rax 26 | 27 | %endmacro 28 | 29 | [extern isr1_handler] 30 | 31 | isr1: 32 | PUSHALL 33 | call isr1_handler 34 | POPALL 35 | iretq 36 | GLOBAL isr1 37 | 38 | LoadIDT: 39 | lidt[idtDescriptor] 40 | sti 41 | ret 42 | GLOBAL LoadIDT 43 | -------------------------------------------------------------------------------- /IDT.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Typedefs.cpp" 3 | #include "KBScanCodeSet1.cpp" 4 | #include "IO.cpp" 5 | #include "TextPrint.cpp" 6 | 7 | struct IDT64{ 8 | uint_16 offset_low; 9 | uint_16 selector; 10 | uint_8 ist; 11 | uint_8 types_attr; 12 | uint_16 offset_mid; 13 | uint_32 offset_high; 14 | uint_32 zero; 15 | }; 16 | 17 | extern IDT64 _idt[256]; 18 | extern uint_64 isr1; 19 | extern "C" void LoadIDT(); 20 | 21 | void InitializeIDT(){ 22 | 23 | _idt[1].zero = 0; 24 | _idt[1].offset_low = (uint_16)(((uint_64)&isr1 & 0x000000000000ffff)); 25 | _idt[1].offset_mid = (uint_16)(((uint_64)&isr1 & 0x00000000ffff0000) >> 16); 26 | _idt[1].offset_high = (uint_32)(((uint_64)&isr1 & 0xffffffff00000000) >> 32); 27 | _idt[1].ist = 0; 28 | _idt[1].selector = 0x08; 29 | _idt[1].types_attr = 0x8e; 30 | 31 | RemapPic(); 32 | 33 | outb(0x21, 0xfd); 34 | outb(0xa1, 0xff); 35 | LoadIDT(); 36 | } 37 | 38 | void(*MainKeyboardHandler)(uint_8 scanCode, uint_8 chr); 39 | 40 | extern "C" void isr1_handler(){ 41 | uint_8 scanCode = inb(0x60); 42 | uint_8 chr = 0; 43 | 44 | if (scanCode < 0x3A){ 45 | chr = KBSet1::ScanCodeLookupTable[scanCode]; 46 | } 47 | if (MainKeyboardHandler != 0) { 48 | MainKeyboardHandler(scanCode, chr); 49 | } 50 | outb(0x20, 0x20); 51 | outb(0xa0, 0x20); 52 | } 53 | -------------------------------------------------------------------------------- /IO.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Typedefs.cpp" 3 | 4 | #define PIC1_COMMAND 0x20 5 | #define PIC1_DATA 0x21 6 | #define PIC2_COMMAND 0xA0 7 | #define PIC2_DATA 0xA1 8 | 9 | #define ICW1_INIT 0x10 10 | #define ICW1_ICW4 0x01 11 | #define ICW4_8086 0x01 12 | 13 | void outb(unsigned short port, unsigned char val){ 14 | asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port)); 15 | } 16 | 17 | unsigned char inb(unsigned short port){ 18 | unsigned char returnVal; 19 | asm volatile ("inb %1, %0" 20 | : "=a"(returnVal) 21 | : "Nd"(port)); 22 | return returnVal; 23 | } 24 | 25 | void RemapPic(){ 26 | uint_8 a1, a2; 27 | 28 | a1 = inb(PIC1_DATA); 29 | a2 = inb(PIC2_DATA); 30 | 31 | outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); 32 | outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4); 33 | outb(PIC1_DATA, 0); 34 | outb(PIC2_DATA, 8); 35 | outb(PIC1_DATA, 4); 36 | outb(PIC2_DATA, 2); 37 | outb(PIC1_DATA, ICW4_8086); 38 | outb(PIC2_DATA, ICW4_8086); 39 | 40 | outb(PIC1_DATA, a1); 41 | outb(PIC2_DATA, a2); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /KBScanCodeSet1.cpp: -------------------------------------------------------------------------------- 1 | namespace KBSet1{ 2 | const char ScanCodeLookupTable[] ={ 3 | 0, 0, '1', '2', 4 | '3', '4', '5', '6', 5 | '7', '8', '9', '0', 6 | '-', '=', 0, 0, 7 | 'q', 'w', 'e', 'r', 8 | 't', 'y', 'u', 'i', 9 | 'o', 'p', '[', ']', 10 | 0, 0, 'a', 's', 11 | 'd', 'f', 'g', 'h', 12 | 'j', 'k', 'l', ';', 13 | '\'', '`', 0, '\\', 14 | 'z', 'x', 'c', 'v', 15 | 'b', 'n', 'm', ',', 16 | '.', '/', 0, '*', 17 | 0, ' ' 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /Kernel.cpp: -------------------------------------------------------------------------------- 1 | #include "TextPrint.cpp" 2 | #include "IDT.cpp" 3 | 4 | #include "Keyboard.cpp" 5 | 6 | extern "C" void _start() { 7 | 8 | SetCursorPosition(PositionFromCoords(0, 0)); 9 | InitializeIDT(); 10 | 11 | MainKeyboardHandler = KeyboardHandler; 12 | 13 | PrintString(IntegerToString(500)); 14 | 15 | float testFloat = -672.938f; 16 | 17 | SetCursorPosition(PositionFromCoords(0, 1)); 18 | PrintString(FloatToString(testFloat, 10)); 19 | 20 | 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /Keyboard.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Typedefs.cpp" 3 | #include "TextPrint.cpp" 4 | 5 | bool LeftShiftPressed = false; 6 | bool RightShiftPressed = false; 7 | uint_8 LastScancode; 8 | 9 | void StandardKeyboardHandler(uint_8 scanCode, uint_8 chr) { 10 | if (chr != 0) { 11 | switch (LeftShiftPressed | RightShiftPressed) 12 | { 13 | case true: 14 | PrintChar(chr - 32); 15 | break; 16 | case false: 17 | PrintChar(chr); 18 | break; 19 | } 20 | 21 | } 22 | else { 23 | switch (scanCode) { 24 | case 0x8E: //Backspace 25 | SetCursorPosition(CursorPosition - 1); 26 | PrintChar(' '); 27 | SetCursorPosition(CursorPosition - 1); 28 | break; 29 | case 0x2A: //Left Shift 30 | LeftShiftPressed = true; 31 | break; 32 | case 0xAA: //Left Shift Released 33 | LeftShiftPressed = false; 34 | case 0x36: //Right Shift 35 | RightShiftPressed = true; 36 | break; 37 | case 0xB6: //Right Shift Released 38 | RightShiftPressed = false; 39 | break; 40 | case 0x9C: //Enter 41 | PrintString("\n\r"); 42 | break; 43 | } 44 | } 45 | } 46 | 47 | void KeyboardHandler0xE0(uint_8 scanCode) { 48 | switch (scanCode) 49 | { 50 | case 0x50: 51 | SetCursorPosition(CursorPosition + VGA_WIDTH); 52 | break; 53 | case 0x48: 54 | SetCursorPosition(CursorPosition - VGA_WIDTH); 55 | break; 56 | default: 57 | break; 58 | } 59 | 60 | } 61 | void KeyboardHandler(uint_8 scanCode, uint_8 chr) { 62 | 63 | switch (LastScancode) { 64 | case 0xE0: 65 | KeyboardHandler0xE0(scanCode); 66 | break; 67 | default: 68 | StandardKeyboardHandler(scanCode, chr); 69 | } 70 | 71 | LastScancode = scanCode; 72 | } -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is an Operating System that I'm developing for a Youtube Tutorial Series. 2 | Currently there is a 64 - bit GDT, PAE identity paging, some linker scripts, 3 | some batch scripts and simple text print functions. -------------------------------------------------------------------------------- /SimplePaging.asm: -------------------------------------------------------------------------------- 1 | 2 | PageTableEntry equ 0x1000 3 | 4 | SetUpIdentityPaging: 5 | 6 | mov edi, PageTableEntry 7 | mov cr3, edi 8 | 9 | mov dword [edi], 0x2003 10 | add edi, 0x1000 11 | mov dword [edi], 0x3003 12 | add edi, 0x1000 13 | mov dword [edi], 0x4003 14 | add edi, 0x1000 15 | 16 | mov ebx, 0x00000003 17 | mov ecx, 512 18 | 19 | .SetEntry: 20 | mov dword [edi], ebx 21 | add ebx, 0x1000 22 | add edi, 8 23 | loop .SetEntry 24 | 25 | mov eax, cr4 26 | or eax, 1 << 5 27 | mov cr4, eax 28 | 29 | mov ecx, 0xC0000080 30 | rdmsr 31 | or eax, 1 << 8 32 | wrmsr 33 | 34 | mov eax, cr0 35 | or eax, 1 << 31 36 | mov cr0, eax 37 | 38 | ret 39 | -------------------------------------------------------------------------------- /TextModeColorCodes.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FOREGROUND_BLACK 0x00 4 | #define FOREGROUND_BLUE 0x01 5 | #define FOREGROUND_GREEN 0x02 6 | #define FOREGROUND_CYAN 0x03 7 | #define FOREGROUND_RED 0x04 8 | #define FOREGROUND_MAGENTA 0x05 9 | #define FOREGROUND_BROWN 0x06 10 | #define FOREGROUND_LIGHTGRAY 0x07 11 | #define FOREGROUND_DARKGRAY 0x08 12 | #define FOREGROUND_LIGHTBLUE 0x09 13 | #define FOREGROUND_LIGHTGREEN 0x0A 14 | #define FOREGROUND_LIGHTCYAN 0x0B 15 | #define FOREGROUND_LIGHTRED 0x0C 16 | #define FOREGROUND_LIGHTMAGENTA 0x0D 17 | #define FOREGROUND_YELLOW 0x0E 18 | #define FOREGROUND_WHITE 0x0F 19 | 20 | #define BACKGROUND_BLACK 0x00 21 | #define BACKGROUND_BLUE 0x10 22 | #define BACKGROUND_GREEN 0x20 23 | #define BACKGROUND_CYAN 0x30 24 | #define BACKGROUND_RED 0x40 25 | #define BACKGROUND_MAGENTA 0x50 26 | #define BACKGROUND_BROWN 0x60 27 | #define BACKGROUND_LIGHTGRAY 0x70 28 | #define BACKGROUND_BLINKINGBLACK 0x80 29 | #define BACKGROUND_BLINKINGBLUE 0x90 30 | #define BACKGROUND_BLINKINGGREEN 0xA0 31 | #define BACKGROUND_BLINKINGCYAN 0xB0 32 | #define BACKGROUND_BLINKINGRED 0xC0 33 | #define BACKGROUND_BLINKINGMAGENTA 0xD0 34 | #define BACKGROUND_BLINKINGYELLOW 0xE0 35 | #define BACKGROUND_BLINKINGWHITE 0xF0 36 | -------------------------------------------------------------------------------- /TextPrint.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IO.cpp" 3 | #include "Typedefs.cpp" 4 | #include "TextModeColorCodes.cpp" 5 | #define VGA_MEMORY (uint_8*)0xb8000 6 | #define VGA_WIDTH 80 7 | 8 | uint_16 CursorPosition; 9 | void ClearScreen(uint_64 ClearColor = BACKGROUND_BLACK | FOREGROUND_WHITE) 10 | { 11 | uint_64 value =0; 12 | value += ClearColor << 8; 13 | value += ClearColor << 24; 14 | value += ClearColor << 40; 15 | value += ClearColor << 56; 16 | for (uint_64* i = (uint_64*)VGA_MEMORY; i < (uint_64*)(VGA_MEMORY + 4000); i++){ 17 | *i = value; 18 | } 19 | } 20 | 21 | void SetCursorPosition(uint_16 position){ 22 | 23 | outb(0x3D4, 0x0F); 24 | outb(0x3D5, (uint_8)(position & 0xFF)); 25 | outb(0x3D4, 0x0E); 26 | outb(0x3D5, (uint_8)((position >> 8) & 0xFF)); 27 | 28 | CursorPosition = position; 29 | } 30 | 31 | uint_16 PositionFromCoords(uint_8 x, uint_8 y){ 32 | return y * VGA_WIDTH + x; 33 | } 34 | 35 | void PrintString(const char* str, uint_8 color = BACKGROUND_BLACK | FOREGROUND_WHITE){ 36 | uint_8* charPtr = (uint_8*)str; 37 | uint_16 index = CursorPosition; 38 | while(*charPtr != 0) 39 | { 40 | switch (*charPtr) { 41 | case 10: 42 | index+= VGA_WIDTH; 43 | break; 44 | case 13: 45 | index -= index % VGA_WIDTH; 46 | break; 47 | default: 48 | *(VGA_MEMORY + index * 2) = *charPtr; 49 | *(VGA_MEMORY + index * 2 + 1) = color; 50 | index++; 51 | } 52 | 53 | charPtr++; 54 | } 55 | SetCursorPosition(index); 56 | } 57 | 58 | void PrintChar(char chr, uint_8 color = BACKGROUND_BLACK | FOREGROUND_WHITE) 59 | { 60 | *(VGA_MEMORY + CursorPosition * 2) = chr; 61 | *(VGA_MEMORY + CursorPosition * 2 + 1) = color; 62 | 63 | SetCursorPosition(CursorPosition + 1); 64 | } 65 | 66 | char hexToStringOutput[128]; 67 | template 68 | const char* HexToString(T value){ 69 | T* valPtr = &value; 70 | uint_8* ptr; 71 | uint_8 temp; 72 | uint_8 size = (sizeof(T)) * 2 - 1; 73 | uint_8 i; 74 | for (i = 0; i < size; i++){ 75 | ptr = ((uint_8*)valPtr + i); 76 | temp = ((*ptr & 0xF0) >> 4); 77 | hexToStringOutput[size - (i * 2 + 1)] = temp + (temp > 9 ? 55 : 48); 78 | temp = ((*ptr & 0x0F)); 79 | hexToStringOutput[size - (i * 2 + 0)] = temp + (temp > 9 ? 55 : 48); 80 | } 81 | hexToStringOutput[size + 1] = 0; 82 | return hexToStringOutput; 83 | } 84 | 85 | char integerToStringOutput[128]; 86 | template 87 | const char* IntegerToString(T value) { 88 | 89 | uint_8 isNegative = 0; 90 | 91 | if (value < 0) { 92 | isNegative = 1; 93 | value *= -1; 94 | integerToStringOutput[0] = '-'; 95 | } 96 | 97 | uint_8 size = 0; 98 | uint_64 sizeTester = (uint_64)value; 99 | while (sizeTester / 10 > 0) { 100 | sizeTester /= 10; 101 | size++; 102 | } 103 | 104 | uint_8 index = 0; 105 | uint_64 newValue = (uint_64)value; 106 | while (newValue / 10 > 0) { 107 | uint_8 remainder = newValue % 10; 108 | newValue /= 10; 109 | integerToStringOutput[isNegative + size - index] = remainder + 48; 110 | index++; 111 | } 112 | uint_8 remainder = newValue % 10; 113 | integerToStringOutput[isNegative + size - index] = remainder + 48; 114 | integerToStringOutput[isNegative + size + 1] = 0; 115 | return integerToStringOutput; 116 | } 117 | 118 | char floatToStringOutput[128]; 119 | const char* FloatToString(float value, uint_8 decimalPlaces) { 120 | char* intPtr = (char*)IntegerToString((int)value); 121 | char* floatPtr = floatToStringOutput; 122 | 123 | if (value < 0) { 124 | value *= -1; 125 | } 126 | 127 | while (*intPtr != 0) { 128 | *floatPtr = *intPtr; 129 | intPtr++; 130 | floatPtr++; 131 | } 132 | *floatPtr = '.'; 133 | floatPtr++; 134 | 135 | float newValue = value - (int)value; 136 | 137 | for (uint_8 i = 0; i < decimalPlaces; i++) { 138 | newValue *= 10; 139 | *floatPtr = (int)newValue + 48; 140 | newValue -= (int)newValue; 141 | floatPtr++; 142 | } 143 | 144 | *floatPtr = 0; 145 | 146 | return floatToStringOutput; 147 | } 148 | 149 | 150 | -------------------------------------------------------------------------------- /Typedefs.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | typedef unsigned char uint_8; 3 | typedef unsigned short uint_16; 4 | typedef unsigned int uint_32; 5 | typedef unsigned long long uint_64; 6 | -------------------------------------------------------------------------------- /bochsrc.bxrc: -------------------------------------------------------------------------------- 1 | # configuration file generated by Bochs 2 | plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, gameport=true 3 | config_interface: win32config 4 | display_library: win32 5 | memory: host=32, guest=32 6 | romimage: file="C:\Program Files\Bochs-2.6.11/BIOS-bochs-latest", address=0x00000000, options=none 7 | vgaromimage: file="C:\Program Files\Bochs-2.6.11/VGABIOS-lgpl-latest" 8 | boot: floppy 9 | floppy_bootsig_check: disabled=0 10 | floppya: type=1_2, 1_2="C:\Users\Generic Youtuber\Desktop\Operating System\bootloader.flp", status=inserted, write_protected=0 11 | # no floppyb 12 | ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 13 | ata0-master: type=none 14 | ata0-slave: type=none 15 | ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15 16 | ata1-master: type=none 17 | ata1-slave: type=none 18 | ata2: enabled=false 19 | ata3: enabled=false 20 | optromimage1: file=none 21 | optromimage2: file=none 22 | optromimage3: file=none 23 | optromimage4: file=none 24 | optramimage1: file=none 25 | optramimage2: file=none 26 | optramimage3: file=none 27 | optramimage4: file=none 28 | pci: enabled=1, chipset=i440fx 29 | vga: extension=vbe, update_freq=5, realtime=1 30 | cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 31 | cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU " 32 | cpuid: mmx=true, apic=xapic, simd=sse2, sse4a=false, misaligned_sse=false, sep=true 33 | cpuid: movbe=false, adx=false, aes=false, sha=false, xsave=false, xsaveopt=false, x86_64=true 34 | cpuid: 1g_pages=false, pcid=false, fsgsbase=false, smep=false, smap=false, mwait=true 35 | cpuid: vmx=1 36 | print_timestamps: enabled=0 37 | port_e9_hack: enabled=0 38 | private_colormap: enabled=0 39 | clock: sync=none, time0=local, rtc_sync=0 40 | # no cmosimage 41 | log: - 42 | logprefix: %t%e%d 43 | debug: action=ignore 44 | info: action=report 45 | error: action=report 46 | panic: action=ask 47 | keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none 48 | mouse: type=ps2, enabled=false, toggle=ctrl+mbutton 49 | sound: waveoutdrv=win, waveout=none, waveindrv=win, wavein=none, midioutdrv=win, midiout=none 50 | speaker: enabled=true, mode=sound 51 | parport1: enabled=true, file=none 52 | parport2: enabled=false 53 | com1: enabled=true, mode=null 54 | com2: enabled=false 55 | com3: enabled=false 56 | com4: enabled=false 57 | -------------------------------------------------------------------------------- /bootloader.asm: -------------------------------------------------------------------------------- 1 | 2 | [org 0x7c00] 3 | 4 | mov [BOOT_DISK], dl 5 | 6 | mov bp, 0x7c00 7 | mov sp, bp 8 | 9 | call ReadDisk 10 | 11 | jmp PROGRAM_SPACE 12 | 13 | %include "print.asm" 14 | %include "DiskRead.asm" 15 | 16 | times 510-($-$$) db 0 17 | 18 | dw 0xaa55 -------------------------------------------------------------------------------- /compileasm.bat: -------------------------------------------------------------------------------- 1 | nasm bootloader.asm -f bin -o bootloader.bin 2 | 3 | nasm ExtendedProgram.asm -f elf64 -o ExtendedProgram.o 4 | 5 | nasm Binaries.asm -f elf64 -o Binaries.o 6 | 7 | x86_64-elf-gcc -Ttext 0x8000 -ffreestanding -mno-red-zone -m64 -c "Kernel.cpp" -o "Kernel.o" 8 | 9 | custom-ld -T"link.ld" 10 | 11 | copy /b bootloader.bin+kernel.bin bootloader.flp 12 | 13 | pause 14 | -------------------------------------------------------------------------------- /gdt.asm: -------------------------------------------------------------------------------- 1 | 2 | gdt_nulldesc: 3 | dd 0 4 | dd 0 5 | gdt_codedesc: 6 | dw 0xFFFF ; Limit 7 | dw 0x0000 ; Base (low) 8 | db 0x00 ; Base (medium) 9 | db 10011010b ; Flags 10 | db 11001111b ; Flags + Upper Limit 11 | db 0x00 ; Base (high) 12 | gdt_datadesc: 13 | dw 0xFFFF 14 | dw 0x0000 15 | db 0x00 16 | db 10010010b 17 | db 11001111b 18 | db 0x00 19 | 20 | gdt_end: 21 | 22 | gdt_descriptor: 23 | gdt_size: 24 | dw gdt_end - gdt_nulldesc - 1 25 | dq gdt_nulldesc 26 | 27 | codeseg equ gdt_codedesc - gdt_nulldesc 28 | dataseg equ gdt_datadesc - gdt_nulldesc 29 | [bits 32] 30 | 31 | EditGDT: 32 | mov [gdt_codedesc + 6], byte 10101111b 33 | 34 | mov [gdt_datadesc + 6], byte 10101111b 35 | ret 36 | 37 | [bits 16] 38 | -------------------------------------------------------------------------------- /link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT(binary) 2 | 3 | ENTRY (_start) 4 | 5 | INPUT 6 | ( 7 | ExtendedProgram.o 8 | Kernel.o 9 | Binaries.o 10 | ) 11 | 12 | OUTPUT 13 | ( 14 | Kernel.bin 15 | ) 16 | 17 | SECTIONS 18 | { 19 | . = 0x8000; 20 | 21 | .text : ALIGN(0x1000) 22 | { 23 | *(.text) 24 | } 25 | .idt BLOCK(0x1000) : ALIGN(0x1000) 26 | { 27 | _idt = .; 28 | . = . + 0x1000; 29 | } 30 | .data : ALIGN(0x1000) 31 | { 32 | *(.data) 33 | } 34 | 35 | .rodata : ALIGN(0x1000) 36 | { 37 | *(.rodata) 38 | } 39 | 40 | .bss : ALIGN(0x1000) 41 | { 42 | *(COMMON) 43 | *(.bss) 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /print.asm: -------------------------------------------------------------------------------- 1 | PrintString: 2 | push ax 3 | push bx 4 | 5 | mov ah, 0x0e 6 | .Loop: 7 | cmp [bx], byte 0 8 | je .Exit 9 | mov al, [bx] 10 | int 0x10 11 | inc bx 12 | jmp .Loop 13 | .Exit: 14 | 15 | pop ax 16 | pop bx 17 | ret --------------------------------------------------------------------------------