IlanVinograd / OS_32Bit

GNU General Public License v3.0
2 stars 0 forks source link

Write Docs For Stage 1 #2

Closed IlanVinograd closed 1 week ago

IlanVinograd commented 2 weeks ago

To-Do Bonus

IlanVinograd commented 2 weeks ago

CS:IP Solution And Step 2

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.

here's why:

Physical Address = Segment × 16 + Offset

Physical Address = 0x0000×16 + 0x7C00 = 0x0000 + 0x7C00 = 0x7C00

Physical Address = 0x7C0×16 + 0x0000 = 0x7C00 + 0x0000 = 0x7C00

We should explicitly set CS:IP because, in some cases, the BIOS may load the boot sector using CS:IP as 0x07C0:0x0000, which also results in the physical address 0x7C00. However, if the segment is not explicitly defined, the processor may interpret instructions and data differently.

Example of code for explicitly set:

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 commented 2 weeks ago

[BITS 16] Directive

16 bits = Real Mode for example 32 bits = Protected Mode

Note: