fixed up some bad comments in boot.asm

This commit is contained in:
Gregory Kenneth Bowne 2024-03-24 19:38:29 -07:00
parent 6c4ee8ed02
commit a6f5bdb64c
8 changed files with 137 additions and 183 deletions

BIN
.vscode/browse.vc.db vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

11
.vscode/launch.json vendored
View File

@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "gcc-8 - Build and debug active file Level 1", "name": "gcc-8 - Build and debug active file Level 1",
"type": "cppdbg", "type": "cppdbg",
@ -27,6 +28,16 @@
"logging": { "logging": {
"engineLogging": true "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"
} }
] ]
} }

165
.vscode/settings.json vendored
View File

@ -1,113 +1,66 @@
{ {
"files.associations": { // General C/C++ settings
"*.c": "c", "C_Cpp.autoAddFileAssociations": true,
"*.h": "c", "C_Cpp.autocompleteAddParentheses": true,
"*.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",
"C_Cpp.clang_format_sortIncludes": 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.codeAnalysis.clangTidy.enabled": true,
"C_Cpp.configurationWarnings": "disabled", "C_Cpp.configurationWarnings": "enabled",
"cmake.configureOnOpen": false, "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.autoSelectActiveFolder": false,
"cmake.configureOnEdit": false, "cmake.configureOnEdit": false,
"c-cpp-flylint.flexelint.configFile": "", "cmake.configureOnOpen": false,
"c-cpp-flylint.flexelint.executable": "", "cmake.cmakePath": "/usr/bin/cmake",
"c-cpp-flylint.language": "c", "cmake.sourceDirectory": "${workspaceFolder}/",
"C_Cpp.autocompleteAddParentheses": true, // Language-specific settings
"C_Cpp.errorSquiggles": "enabled", "[c]": {
"C_Cpp_Runner.makePath": "", "editor.defaultFormatter": "ms-vscode.cpptools",
"cmake.sourceDirectory": "${workspaceFolder}", "editor.formatOnSave": true
"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"
}, },
"C_Cpp.default.intelliSenseMode": "linux-gcc-x86", "[cpp]": {
"cmake.cmakePath": "/usr/bin/cmake" "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",
} }

View File

@ -16,10 +16,10 @@ identify_drive:
cmp cl, 0x80 ; Check for hard disk interrupt vector (example) cmp cl, 0x80 ; Check for hard disk interrupt vector (example)
je is_harddrive je is_harddrive
; Handle invalid drive type (error handling) ; Handle invalid drive type (error handling)
... ; ...
is_floppy: 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 ah, 0x02 ; Read sectors
mov al, 1 ; Number of sectors to read (1) mov al, 1 ; Number of sectors to read (1)
@ -68,8 +68,8 @@ memory_error:
; ... (error handling or continue with limited memory) ; ... (error handling or continue with limited memory)
; Second stage loading (simplified example) ; 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: ; Here's an improved version of the load_second_stage section with the placeholder jump replaced by actual loading logic:
Code snippet ; Code snippet
load_second_stage: load_second_stage:
; Calculate address of second stage bootloader (assuming offset from boot sector) ; Calculate address of second stage bootloader (assuming offset from boot sector)

View File

@ -8,89 +8,82 @@ start:
MOV SP, 0xFFFF ; Stack grows downwards from the top of the segment MOV SP, 0xFFFF ; Stack grows downwards from the top of the segment
; Copy boot sector data to a safe location ; Copy boot sector data to a safe location
mCopyBootSector call mCopyBootSector
; Load the kernel ; Load the kernel
CALL load_kernel CALL load_kernel
switch_to_protected_mode: switch_to_protected_mode:
CLI ; Disable interrupts CLI ; Disable interrupts
lgdt [gdt_descriptor] ; Load the global descriptor table lgdt [gdt_descriptor] ; Load the global descriptor table
MOV EAX, CR0 MOV EAX, CR0
OR EAX, 0x1 ; Set the PE (Protection Enable) bit OR EAX, 0x1 ; Set the PE (Protection Enable) bit
MOV CR0, EAX MOV CR0, EAX
; Far jump to flush CPU queue after changing to protected mode ; 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 JMP CODE_SEG:init_pm ; CODE_SEG is the segment selector for code segment in GDT
init_pm: init_pm:
; Update segment registers here ; Update segment registers here
; Set code segment register (CS) to point to code segment descriptor (selector 1) ; Set code segment register (CS) to point to code segment descriptor (selector 1)
mov ax, 0x0001 mov ax, 0x0001
mov ds, ax ; Set data segment register (DS) to point to data segment descriptor (selector 2) 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 mov es, ax ; Set other segment registers (ES, SS, etc.) as needed
RET 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: ; Wait for keyboard controller to be ready
; Enable A20 gate a20wait:
cli ; Disable interrupts to prevent interference in al, 0x64 ; Read keyboard controller status port
call a20wait ; Wait for the keyboard controller to be ready test al, 0x02 ; Check if input buffer is full
mov al, 0xAD ; Command to disable keyboard jnz a20wait ; Wait until it's not full
out 0x64, al ; Send command to keyboard controller command port ret
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 ; Enter kernel space and jump to the kernel entry point
a20wait: JMP 0x1000:0x0000
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 ; Code to set up flat memory model for protected mode
JMP 0x1000:0x0000 ; 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 limit = 0x00CFFFFFh ; Define limit as a separate variable within gdt_struct
; This involves setting up the segment registers with selectors
; that point to descriptors in the GDT that define a flat memory model
; Define GDT structure ; Placeholder instruction to satisfy NASM
gdt_struct: dummy_instruction DB 0x90 ; NOP instruction as a placeholder
; Null descriptor (ignored)
dq 0x0000000000000000h
dq 0x0000000000000000h
; Code segment descriptor (flat memory model) gdt_struct:
; 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
; Data segment descriptor (flat memory model) base_addr equ 0x0000000
; Similar structure to code segment descriptor with Data segment flag set
dq 0x0000000000000000h
dq 0x00CFFFFFFFh
db 0x92
db 0xCF
; Jump to the kernel entry point ; Null descriptor (ignored)
JMP 0x1000:0x0000 ; Assuming the kernel is loaded at 0x1000:0x0000 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 ; Macro to copy boot sector data to a safe location
mCopyBootSector: mCopyBootSector:

View File

@ -28,7 +28,4 @@ SECTIONS {
bootloader_padding : { bootloader_padding : {
*(.bootloader_padding) *(.bootloader_padding)
} }
/* Set the bootloader size to 512 bytes */
= 512;
} }