0

Suppose I write boot loader on C. What happens when I create some global variable? What is it's logical address? How does it correspond to physical address? For example if I created some string (global)

const char* s = "some string";

Am I right that s stored in .data section? What would be the physical address of s and what would be a logical one? Should we do some extra work to make this addresses correspond each other.

My OS is Linux and I compile my code like this:

 as --32 boot.S -o boot.o
 gcc -c -m32 -g -Os -ffreestanding -Wall -Werror -I. -o mbr.o mbr.c
 ld -Tlinker.ld -nostdlib -o mbr boot.o mbr.o

boot.S is just where I initilize some registers and call c code:

.code16

.text
.global _start
_start:
    cli

    xor %ax, %ax
    mov %ax, %ds
    mov %ax, %es
    mov %ax, %ss
    mov $0x7c00, %sp

    ljmp $0, $mmain

mmain -- function in C code. My linker script is:

OUTPUT_FORMAT(binary)
OUTPUT_ARCH(i8086)
ENTRY(_start)

SECTIONS
{
    . = 0x7C00;
    .text : { *(.text) }
    .sig : AT(0x7DFE)
    {
        SHORT(0xaa55);
    }
}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
PepeHands
  • 1,368
  • 5
  • 20
  • 36
  • This question is not answerable unless you post which compiler you're using. Real mode compilation is dependent on both the compiler and the OS being used. If you want to compile for pure real mode without an OS, the question becomes entirely compiler dependent - if the compiler supports compiling for raw real mode. – Daniel Kamil Kozar Dec 08 '15 at 18:56
  • The linker should have an option to show you a memory map of where it puts everything. And if it's not going where you want it, there's probably an option to change it. – lurker Dec 08 '15 at 18:59
  • 1
    Logical vs physical address is a protected mode thing. Not sure what you're referring to in real mode. – interjay Dec 08 '15 at 19:00
  • @DanielKamilKozar updated my question – PepeHands Dec 08 '15 at 19:02
  • @chux updated my question – PepeHands Dec 08 '15 at 19:02

0 Answers0