Modify segment in ld
-
Default
ld
I understand that he thinks he is.%ds
is 0 and therefore compiles a programme in C with this value. How to change it in the building of the componer to change%ds
Another value in the program (e.g. 0x07c0), did it work correctly?Just in case, I'll make it clear that it's about writing a program like a loader.
-
As I realized, I'd ask directly.
%ds
No, but for section .data, VMA can be indicated that it is deciphered as Virtual Memory Address. The componer will then download the LMA section (Load Memory Address), but the addresses of the variables in this section will begin with VMA rather than with LMA in handling these variables from the programme.Look at this example:
%ds
In the code 0x07c0, section .text is loaded at 0x7c00, .data is immediately after .text. It is then necessary to establish VMA as an equal size of section .text. After this, for example, the variable located at the beginning of section .data will have an address when it comes to it from the programme code.%ds*16+Размер секции .text=0x7c00+Размер секции .text
♪ This corresponds to the actual location of the variable. Componer's full crypt code:ENTRY(main); SECTIONS { . = 0x7C00; /*установлен только LMA, VMA такой же */ .text : AT(0x7C00) { _text = .; *(.text*); _text_end = .; } /*VMA=SIZEOF(.text) LMA=ADDR (.text) + SIZEOF (.text)*/ .data (SIZEOF(.text)) : AT(ADDR (.text) + SIZEOF (.text)) { _data = .; *(.bss); *(.bss*); *(.data); *(.rodata*); *(COMMON) _data_end = .; } .sig : AT(0x7DFE) { SHORT(0xaa55); } /DISCARD/ : { *(.note*); *(.iplt*); *(.igot*); *(.rel*); *(.comment); *(.eh_frame); } }
Details of LMA and VMA can be read from this reference https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html