From a6f5bdb64c40eccc6178ef5ebdf5f555e5ca36eb Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Sun, 24 Mar 2024 19:38:29 -0700 Subject: [PATCH] fixed up some bad comments in boot.asm --- .vscode/browse.vc.db | Bin 33939456 -> 33939456 bytes .vscode/browse.vc.db-shm | Bin 32768 -> 32768 bytes .vscode/browse.vc.db-wal | Bin 0 -> 82192 bytes .vscode/launch.json | 11 +++ .vscode/settings.json | 165 ++++++++++++++------------------------- src/boot/boot.asm | 8 +- src/boot/boot2.asm | 133 +++++++++++++++---------------- src/boot/linker.ld | 3 - 8 files changed, 137 insertions(+), 183 deletions(-) diff --git a/.vscode/browse.vc.db b/.vscode/browse.vc.db index 5e5b21f8474ed14f192b3990a5ab4abaa152d058..0dd233d22fe6b1b65416e2b1c0c6b25d3716b07b 100644 GIT binary patch delta 5064 zcma*pd3Y1m8o=SqlFVe^lP1lcB6|x`D2tYYfC?65DIzFsfgnp)r~--G|7(p0$5y?2`@&RvmWP~yGG`Zie!#0isVkr9GO?tHaR&ZB^h3N zVoOHXPJw31$IV<5_Q9FTURJI-`@pQ+{87p$wtSKq@iXBvPjPD|RMxvVi3ygyT-;I_ z;M1K}>1J~#V0bL)v6d}I78JDd^XYbb*~Kk^Eq971`j!3!E}bb06bE4Xg7O4qDEfR_ zaX=ZwN72blVDs{Xoyx@u1*4L7Uk}=t9;KFUe-5C;8p3yKzFIBjLk4SAs`^?f?`P?ifLGl-HVWx-F??o{nohuM^rTGOM z#LM{w%7y)S|1oZ`tgKQV^20F|y3&)iO8I21s&!Sdf03e$Tdz<~_U~7w@&~x}T%D5R z=kgi6$3Mt#@tyQ7@;&SGcx$~Yyb*6R&vnmw&uC8|z9xQYd}e%t`Ld%QdBI`3NK z>hIFW9f+F~*DucDyx@Gt`Ha)<_}Vegk?zpi57?*L+t@DKBwKGAYyHgnlC_1U#@}=3%rHa@y$#I_dj0qM zBl->ch58Bl{`#=)4_%G!bDgA{q8qB~qH}9+X^&~QY8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wXarAc z0o*|<)R#gL9H2^JXHldREEFtoNqo|vyUG$AEEKOA-tc90^mxf;tFMIzDDW9pfA7{$> zZ$Oqq-h?zjRzOxlRzco^G(uKG)U6S51k8?pzo7xFP=A7nq|6Ue8K1CWD|Ly*rPpF<8q zjzEq={tY<>ISy%poPhiX@&)81eTjkF-EqBCU|t$bCo~DwXEX3&RG`4#_~;BOQ>ANGGH- z@*vU$$wab{hmfww!^k7ZqewQAgXALJknTtiq$kn~>5V*w^g;R}{gD310AwIC2pNnF zK^{kjBEyj3$P>s2C@)Ytk@(l7UG71@u`ApvA8G7c$5N|5o$ z1f&!xL&}i~B#2BzDv>HAgj6HXA(N2F$P{EM@;ovPc>$S@)F8FU4CF=RB_xczjBsQo zQis$dvyj=y9OM;bE;0|9k1Rl5MHV89kk^pKh=wddmLjhs%aAva<;a^z1F`~HiL652 zLK>0P$QtBr1SL&#^y=g48?2yztpH*yR)jx-@BkpCcGASaPi z$Z6yZ@+EQ>Ifs0O2;@9+0lA2Lja)*$LB2)4L%v5YBR?QlkgLd#$Tj3AdROJRc`6k&)&cZPF~bXvpz0K_Q@>;M1& diff --git a/.vscode/browse.vc.db-shm b/.vscode/browse.vc.db-shm index 8ba8ae9ff5b84254ff2d190184ef16800f39ac39..393371e9adfd62d87381ce987d3247ef5cc5a839 100644 GIT binary patch delta 211 zcmZo@U}|V!s+V}A%K!qbK+MR%puh#B^#vFh{vBCls1|eYz?vD6id)y)Y-QU%)w{t& zd^)M>L1u#h$lU)(04&JBFtMIfkp;*GS&x(6Twl}3yzv5))5Z&DSlJmFn1RaKH(zx6 T&cw+C)WycY!N9fgAfq7wQlB-5 delta 260 zcmZo@U}|V!s+V}A%K!orK+MR%pa5d)3otM&@orw?$@276p=7XM!ll9~|KEmXr0@O0 zPpW#5c`)!F2|&dr)^i#%0olwzECa-LKx_}hE diff --git a/.vscode/browse.vc.db-wal b/.vscode/browse.vc.db-wal index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a58895a7e3aaae2b5ce0f223c908db513acd7b10 100644 GIT binary patch literal 82192 zcmeI*PiUKE9Ki92sRv}FcCI8Qw{L4ZYa~E`009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7csfjtly(q6z^XWiY62kC`UrkpM2N`-W;oL|ajii?GOI#tZx*9-V`_U7{F z&DAfqdI8;9K&b42q?aH-fB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C6Bk(VK z0mtICBct8h@a3r6@U@F;^+tWIez|dcKzjijezVg=irJ2oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FoI>0)y8JIM$N_h@^J)v*bDdvIs9&r literal 0 HcmV?d00001 diff --git a/.vscode/launch.json b/.vscode/launch.json index deac87e..474aeea 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "gcc-8 - Build and debug active file Level 1", "type": "cppdbg", @@ -27,6 +28,16 @@ "logging": { "engineLogging": true } + }, + { + "name": "Debug with QEMU", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/boot.bin", + "miDebuggerPath": "/usr/bin/qemu-system-i386", + "miDebuggerArgs": "-kernel", + "cwd": "${workspaceFolder}", + "preLaunchTask": "build" } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 62261e3..1737686 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,113 +1,66 @@ { - "files.associations": { - "*.c": "c", - "*.h": "c", - "*.cpp": "cpp", - "*.hpp": "hpp", - "*.asm": "asm", - "*.bin": "bin" - }, - "files.fileAssociations": { - ".c": "c", - ".h": "c", - ".cpp": "cpp", - ".hpp": "cpp", - ".asm": "asm", - ".bin": "bin" - }, - "emmet.includeLanguages": { - "c": "c", - "cpp": "cpp", - "assembly": "asm" - }, - "C_Cpp_Runner.cCompilerPath": "/usr/bin", - "C_Cpp_Runner.cppCompilerPath": "/usr/bin", - "C_Cpp_Runner.debuggerPath": "/usr/bin", - "C_Cpp_Runner.cStandard": "c17", - "C_Cpp_Runner.cppStandard": "c++20", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wextra", - "-Wpedantic" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [ - "-dynamic-linker {/lib64/ld-linux-x86-64.so.2}" - ], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "c-cpp-flylint.enable": true, - "c-cpp-flylint.debug": true, - "c-cpp-flylint.flexelint.enable": false, - "c-cpp-flylint.cppcheck.enable": true, - "c-cpp-flylint.clang.enable": false, - "C_Cpp_Config.cCompilerPath": "gcc", - "C_Cpp_Config.cppCompilerPath": "g++", - "C_Cpp_Config.debuggerPath": "gdb", - "C_Cpp_Config.makePath": "make", + // General C/C++ settings + "C_Cpp.autoAddFileAssociations": true, + "C_Cpp.autocompleteAddParentheses": true, "C_Cpp.clang_format_sortIncludes": true, - "C_Cpp.vcFormat.indent.preserveComments": true, - "C_Cpp.vcFormat.indent.namespaceContents": false, - "C_Cpp.vcFormat.indent.caseContentsWhenBlock": true, - "C_Cpp.vcFormat.space.pointerReferenceAlignment": "right", - "C_Cpp.default.browse.limitSymbolsToIncludedHeaders": false, - "C_Cpp.default.cppStandard": "c++20", - "C_Cpp.default.cStandard": "c17", - "C_Cpp.formatting": "clangFormat", - "[c]": { - "editor.formatOnSave": true, - "editor.defaultFormatter": "ms-vscode.cpptools" - }, - "[cpp]": { - "editor.formatOnSave": true, - "editor.defaultFormatter": "ms-vscode.cpptools" - }, "C_Cpp.codeAnalysis.clangTidy.enabled": true, - "C_Cpp.configurationWarnings": "disabled", - "cmake.configureOnOpen": false, + "C_Cpp.configurationWarnings": "enabled", + "C_Cpp.default.browse.limitSymbolsToIncludedHeaders": false, + "C_Cpp.default.cStandard": "c11", + "C_Cpp.default.compilerPath": "", + "C_Cpp.default.cppStandard": "c++11", + "C_Cpp.default.enableConfigurationSquiggles": true, + "C_Cpp.errorSquiggles": "enabledIfIncludesResolve", + "C_Cpp.formatting": "default", + "C_Cpp.loggingLevel": "Debug", + "C_Cpp.vcFormat.indent.caseContentsWhenBlock": true, + "C_Cpp.vcFormat.indent.namespaceContents": false, + "C_Cpp.vcFormat.indent.preserveComments": true, + "C_Cpp.vcFormat.space.pointerReferenceAlignment": "right", + // CMake integration settings "cmake.autoSelectActiveFolder": false, "cmake.configureOnEdit": false, - "c-cpp-flylint.flexelint.configFile": "", - "c-cpp-flylint.flexelint.executable": "", - "c-cpp-flylint.language": "c", - "C_Cpp.autocompleteAddParentheses": true, - "C_Cpp.errorSquiggles": "enabled", - "C_Cpp_Runner.makePath": "", - "cmake.sourceDirectory": "${workspaceFolder}", - "C_Cpp.default.compilerPath": "/usr/bin", - "C_Cpp.loggingLevel": "Error", - "C_Cpp.default.enableConfigurationSquiggles": true, - "C_Cpp.default.includePath": [ - "${workspaceFolder}/**", // Include all files in the workspace folder - "/usr/include", // Standard system include path - "/usr/local/include", // Additional system include path - "/path/to/custom/includes" // Custom include path - ], - "workbench.editorAssociations": { - "*.bin": "default", - "*.h": "default", - "*.c": "default", - "*.json": "default", - "*.asm": "default" + "cmake.configureOnOpen": false, + "cmake.cmakePath": "/usr/bin/cmake", + "cmake.sourceDirectory": "${workspaceFolder}/", + // Language-specific settings + "[c]": { + "editor.defaultFormatter": "ms-vscode.cpptools", + "editor.formatOnSave": true }, - "C_Cpp.default.intelliSenseMode": "linux-gcc-x86", - "cmake.cmakePath": "/usr/bin/cmake" + "[cpp]": { + "editor.defaultFormatter": "ms-vscode.cpptools", + "editor.formatOnSave": true + }, + // File associations + "files.associations": { + "*.c": "c", + "*.cpp": "cpp", + "*.h": "c", + "*.hpp": "c" + }, + "workbench.editorAssociations": { + "*.c": "default", + "*.cpp": "default", + "*.h": "default", + "*.hpp": "default" + }, + // IntelliSense configuration + "C_Cpp.default.includePath": [ + "/usr/include", + "${workspaceFolder}/**", + "${workspaceFolder}/src/include", + "${workspaceFolder}/include" + ], + "C_Cpp.default.defines": [], + "C_Cpp.default.compileCommands": "build/compile_commands.json", + "C_Cpp.default.browse.path": [ + "/usr/include", + "${workspaceFolder}/**", + "${workspaceFolder}/src/include", + "${workspaceFolder}/include" + ], + "C_Cpp.default.browse.databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db", + "C_Cpp.default.configurationProvider": "ms-vscode.cpptools", + "C_Cpp.default.intelliSenseMode": "linux-gcc-x64", } \ No newline at end of file diff --git a/src/boot/boot.asm b/src/boot/boot.asm index 8baf464..9ed4f16 100644 --- a/src/boot/boot.asm +++ b/src/boot/boot.asm @@ -16,10 +16,10 @@ identify_drive: cmp cl, 0x80 ; Check for hard disk interrupt vector (example) je is_harddrive ; Handle invalid drive type (error handling) - ... + ; ... is_floppy: - Perform floppy disk access (assuming AH=0x02 for read sectors) + ; Perform floppy disk access (assuming AH=0x02 for read sectors) mov ah, 0x02 ; Read sectors mov al, 1 ; Number of sectors to read (1) @@ -68,8 +68,8 @@ memory_error: ; ... (error handling or continue with limited memory) ; Second stage loading (simplified example) -Here's an improved version of the load_second_stage section with the placeholder jump replaced by actual loading logic: -Code snippet +; Here's an improved version of the load_second_stage section with the placeholder jump replaced by actual loading logic: +; Code snippet load_second_stage: ; Calculate address of second stage bootloader (assuming offset from boot sector) diff --git a/src/boot/boot2.asm b/src/boot/boot2.asm index 098226c..fffde1f 100644 --- a/src/boot/boot2.asm +++ b/src/boot/boot2.asm @@ -8,89 +8,82 @@ start: MOV SP, 0xFFFF ; Stack grows downwards from the top of the segment ; Copy boot sector data to a safe location - mCopyBootSector - + call mCopyBootSector ; Load the kernel CALL load_kernel - switch_to_protected_mode: - CLI ; Disable interrupts - lgdt [gdt_descriptor] ; Load the global descriptor table - MOV EAX, CR0 - OR EAX, 0x1 ; Set the PE (Protection Enable) bit - MOV CR0, EAX - ; Far jump to flush CPU queue after changing to protected mode - JMP CODE_SEG:init_pm ; CODE_SEG is the segment selector for code segment in GDT - init_pm: - ; Update segment registers here - ; Set code segment register (CS) to point to code segment descriptor (selector 1) - mov ax, 0x0001 - mov ds, ax ; Set data segment register (DS) to point to data segment descriptor (selector 2) - mov es, ax ; Set other segment registers (ES, SS, etc.) as needed - RET +switch_to_protected_mode: + CLI ; Disable interrupts + lgdt [gdt_descriptor] ; Load the global descriptor table + MOV EAX, CR0 + OR EAX, 0x1 ; Set the PE (Protection Enable) bit + MOV CR0, EAX + ; Far jump to flush CPU queue after changing to protected mode + JMP CODE_SEG:init_pm ; CODE_SEG is the segment selector for code segment in GDT +init_pm: + ; Update segment registers here + ; Set code segment register (CS) to point to code segment descriptor (selector 1) + mov ax, 0x0001 + mov ds, ax ; Set data segment register (DS) to point to data segment descriptor (selector 2) + mov es, ax ; Set other segment registers (ES, SS, etc.) as needed + RET +enable_a20: + cli ; Disable interrupts to prevent interference + call a20wait ; Wait for the keyboard controller to be ready + mov al, 0xAD ; Command to disable keyboard + out 0x64, al ; Send command to keyboard controller command port + call a20wait ; Wait for the keyboard controller to be ready + mov al, 0xD0 ; Command to read output port + out 0x64, al ; Send command to keyboard controller command port + call a20wait ; Wait for the keyboard controller to be ready + in al, 0x60 ; Read current state of output port + or al, 0x02 ; Set A20 bit + out 0x64, al ; Send command to keyboard controller command port + call a20wait ; Wait for the keyboard controller to be ready + mov al, 0xD1 ; Command to write output port + out 0x64, al ; Send command to keyboard controller command port + call a20wait ; Wait for the keyboard controller to be ready + mov al, 0xAE ; Command to re-enable keyboard + out 0x64, al ; Send command to keyboard controller command port + sti ; Re-enable interrupts + ret - enable_a20: - ; Enable A20 gate - cli ; Disable interrupts to prevent interference - call a20wait ; Wait for the keyboard controller to be ready - mov al, 0xAD ; Command to disable keyboard - out 0x64, al ; Send command to keyboard controller command port - call a20wait ; Wait for the keyboard controller to be ready - mov al, 0xD0 ; Command to read output port - out 0x64, al ; Send command to keyboard controller command port - call a20wait ; Wait for the keyboard controller to be ready - in al, 0x60 ; Read current state of output port - or al, 0x02 ; Set A20 bit - call a20wait ; Wait for the keyboard controller to be ready - mov al, 0xD1 ; Command to write output port - out 0x64, al ; Send command to keyboard controller command port - call a20wait ; Wait for the keyboard controller to be ready - mov al, 0x02 ; New output port data with A20 enabled - out 0x60, al ; Write new output port data - call a20wait ; Wait for the keyboard controller to be ready - sti ; Re-enable interrupts - ret +; Wait for keyboard controller to be ready +a20wait: + in al, 0x64 ; Read keyboard controller status port + test al, 0x02 ; Check if input buffer is full + jnz a20wait ; Wait until it's not full + ret - ; Wait for keyboard controller to be ready - a20wait: - in al, 0x64 ; Read keyboard controller status port - test al, 0x02 ; Check if input buffer is full - jnz a20wait ; Wait until it's not full - ret +; Enter kernel space and jump to the kernel entry point +JMP 0x1000:0x0000 - ; Enter kernel space and jump to the kernel entry point - JMP 0x1000:0x0000 +; Code to set up flat memory model for protected mode +; This involves setting up the segment registers with selectors +; that point to descriptors in the GDT that define a flat memory model - ; Code to set up flat memory model for protected mode - ; This involves setting up the segment registers with selectors - ; that point to descriptors in the GDT that define a flat memory model +limit = 0x00CFFFFFh ; Define limit as a separate variable within gdt_struct - ; Define GDT structure - gdt_struct: - ; Null descriptor (ignored) - dq 0x0000000000000000h - dq 0x0000000000000000h +; Placeholder instruction to satisfy NASM +dummy_instruction DB 0x90 ; NOP instruction as a placeholder - ; Code segment descriptor (flat memory model) - ; Base address 0, limit 0xffffffff (full 4GB) - ; Present, Readable, Accessed, Code segment, 4KB granularity - ; Flags: 0x9A (Bits explained below) - dq 0x0000000000000000h - dq 0x00CFFFFFFFh - db 0x9A - db 0xCF +gdt_struct: - ; Data segment descriptor (flat memory model) - ; Similar structure to code segment descriptor with Data segment flag set - dq 0x0000000000000000h - dq 0x00CFFFFFFFh - db 0x92 - db 0xCF + base_addr equ 0x0000000 - ; Jump to the kernel entry point - JMP 0x1000:0x0000 ; Assuming the kernel is loaded at 0x1000:0x0000 + ; Null descriptor (ignored) + dd base_addr, 0 ; Both values are zero for a null descriptor + ; Code segment descriptor (flat memory model) + dd base_addr, limit + db 0x9A + db 0xCF + + ; Data segment descriptor (flat memory model) + dd base_addr, limit + db 0x92 + db 0xCF ; Macro to copy boot sector data to a safe location mCopyBootSector: diff --git a/src/boot/linker.ld b/src/boot/linker.ld index fda2a64..b93be98 100644 --- a/src/boot/linker.ld +++ b/src/boot/linker.ld @@ -28,7 +28,4 @@ SECTIONS { bootloader_padding : { *(.bootloader_padding) } - - /* Set the bootloader size to 512 bytes */ - = 512; } \ No newline at end of file