fixed up some bad comments in boot.asm

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

View File

@@ -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)

View File

@@ -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:

View File

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