Repository navigation
boot 64
This document provides a detailed explanation of the BOOT-64.ASM file, which is responsible for initializing the CPU in 64-bit long mode. After jumping into 64-bit mode, it's essential to set up the CPU environment correctly to ensure proper operation. The code is written in assembly language and is crucial for setting up the environment before the operating system kernel takes over. This documentation aims to explain each instruction and its purpose.
GLOBAL long_mode_start
EXTERN _start
SECTION .text
BITS 64
long_mode_start:
; load null to all data segment registers (needed for the cpu to work as intended)
MOV ax, 0
MOV ss, ax
MOV ds, ax
MOV es, ax
MOV fs, ax
MOV gs, ax
CALL _start
HLT-
GLOBAL long_mode_start
- Makes the
long_mode_startlabel available to other files, allowing them to reference this entry point.
- Makes the
-
EXTERN _start
- Declares an external symbol
_start, which is the main function of the Rust kernel. This is where the kernel's execution begins.
- Declares an external symbol
-
SECTION .text
- Defines the beginning of a code section named
.text, where the executable code resides.
- Defines the beginning of a code section named
-
BITS 64
- Informs the assembler that the following code is intended for 64-bit mode.
-
long_mode_start:
- A label marking the entry point of the long mode setup code. At this point, the system has just transitioned into 64-bit mode.
-
MOV ax, 0
- Loads the value
0into theAXregister to prepare for initializing the segment registers.
- Loads the value
-
MOV ss, ax
- Sets the
SS(Stack Segment) register to0. In 64-bit mode, all segment registers need to be set to0for the CPU to function properly, ensuring correct memory addressing.
- Sets the
-
MOV ds, ax
- Sets the
DS(Data Segment) register to0, which is necessary for proper data access.
- Sets the
-
MOV es, ax
- Sets the
ES(Extra Segment) register to0.
- Sets the
-
MOV fs, ax
- Sets the
FS(Additional Data Segment) register to0.
- Sets the
-
MOV gs, ax
- Sets the
GS(Additional Data Segment) register to0. Initializing all these registers prevents segmentation errors and ensures the CPU operates as expected.
- Sets the
-
CALL _start
- Calls the
_startfunction, transferring control to the Rust kernel's main function.
- Calls the
-
HLT
- Halts the CPU, typically used if there is nothing else to execute.
The BOOT-64.ASM file is a critical component in the boot process of an operating system. After entering 64-bit long mode, setting all segment registers to 0 is essential for the CPU to function properly. This setup prepares the environment for the kernel's main function _start to take over. Each instruction serves a specific purpose to ensure the CPU operates correctly and transitions smoothly to the kernel.