Closed IlanVinograd closed 2 months ago
@IlanVinograd - WorkFlow.md: will be the work - flow meaning how development will be made, branching pushing, commiting..... TECHNICAL_GUIDE.md will be where all of the boot flow, kernal flow... all of the technical documentation
Register CS (Code Segment) Register IP (Instruction Pointer)
The CS:IP, in Briefly, the syntax is segment:offset A simple analogy could be chapter : verse.
Note:
this is not a general purpose register! the combination ( cs:ip ) represents the location where the CPU is currently fetching instructions to execute.
The physical address 0x7C00 is an address used for loading the boot sector because it's a long-standing convention from early IBM PC designs, ensuring compatibility. It's conveniently located within the first 1 MB of memory accessible in real mode, simplifying the boot process without complex memory management.
When the BIOS loads the boot sector into memory, it places it at address 0x0000:0x7C00 (segment 0x0000, offset 0x7C00) or 0x07C0:0x0000 (segment 0x07C0, offset 0x0000). These two variants point to the same physical address.
here's why:
Physical Address = Segment × 16 + Offset
Physical Address = 0x0000×16 + 0x7C00 = 0x00000 + 0x7C00 = 0x7C00 Physical Address = 0x07C0 × 16 + 0x0000 = 0x07C00 + 0x0000 = 0x7C00
We should explicit CS:IP, in some cases, the BIOS may load the boot sector using CS:IP as 0x07C0:0x0000, which also gives the physical address 0x7C00. However, the processor may interpret instructions and data differently if the segment is not explicitly set.
Caution:
Unpredictability: If CS:IP is not explicitly set in the boot sector, the BIOS may use its own value for the segment, leading to unpredictable program behavior. For example, if the code expects a certain offset relative to CS, but the segment turns out to be different, the program may start executing from the wrong address.
Execution Errors: The code might access the wrong area of memory, leading to crashes or improper functioning of the boot sector. This is particularly critical during the early stages of booting, where any deviation from expected behavior can disrupt the further loading of the operating system.
Compatibility: Different BIOS implementations may have varying loading methods, and explicitly setting CS:IP ensures that your boot sector will work correctly across different systems.
ljmp 0x07C0, start
start:
; Code to execute after the jump
This code is used to explicitly set a new code segment (CS) and instruction pointer (IP) to continue execution in segment 0x07C0 at the specified offset (start).
ljmp 0x07C0, start is used for explicitly setting the segment and offset during execution.
Use of org
not give explicitly set:
org 0x7C00
This code is used to instruct the assembler that the entire program is loaded at the physical address 0x7C00, and all offsets in the program will be calculated relative to this address. This simplifies the code as it doesn't require explicitly setting the segment.
org 0x7C00 does not change the segment during execution, it only informs the assembler about the starting address for calculating offsets. Therefore, ljmp is the explicit method for setting CS:IP during program execution.
@IlanVinograd - awesome job, add it to the technical guide under boot loader - > stage 1.
We should split the technical guide into multiple documents, like bootloader technical guide, kernal technical guide.... so add Bootloader_Technical_guide.md, and it will be all things related bootloader
This is just to keep things short....
ok, do we need BIOS guide?
@IlanVinograd - I don't want to make a tutorial on OS's And the Bios is not part of the os.
But you can write something about the interrupts and why we need protected mode,
For now, keep bios out of the docs
BOOT FLOW
BIOS
step 1. POST - (Power-On Self-Test) Done
step 2. MBR - (Master Boot Record)
Potential Issue:
Solution: -> cs:ip !?
Important Notes: