summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRegia König2022-08-25 15:08:09 +0200
committerRegia König2022-08-25 15:08:09 +0200
commite7897de9471e1d94ad79e2b03fcb8afc685760f1 (patch)
tree567f08f0754d65f0fd7865efa88c4809fdc890b4
parentAnalyse memtest86 binary structure (diff)
downloadmemtest86-e7897de9471e1d94ad79e2b03fcb8afc685760f1.tar.gz
memtest86-e7897de9471e1d94ad79e2b03fcb8afc685760f1.tar.xz
memtest86-e7897de9471e1d94ad79e2b03fcb8afc685760f1.zip
Setup.S documentation and new command in create_debug.sh
-rw-r--r--Makefile_for_memtest_gdb2
-rwxr-xr-xcreate_debug.sh13
-rw-r--r--documentation/memtest86_build_process/24_08_22_memtest_build_process39
-rw-r--r--memtest_efi_modified.lds57
4 files changed, 103 insertions, 8 deletions
diff --git a/Makefile_for_memtest_gdb b/Makefile_for_memtest_gdb
index 58025f7..3413741 100644
--- a/Makefile_for_memtest_gdb
+++ b/Makefile_for_memtest_gdb
@@ -91,7 +91,7 @@ boot/startup.s: ../boot/startup64.S ../boot/boot.h
boot/%.s: ../boot/%.S ../boot/boot.h
@mkdir -p boot
- $(CC) -E -traditional -I../boot -o $@ $<
+ $(CC) -E -traditional -fPIC -I../boot -o $@ $<
boot/efisetup.o: ../boot/efisetup.c
@mkdir -p boot
diff --git a/create_debug.sh b/create_debug.sh
index ada21f9..45f4c1f 100755
--- a/create_debug.sh
+++ b/create_debug.sh
@@ -8,6 +8,15 @@ BSS_SIZE=$(size -B -d memtest_shared | grep memtest_shared | tr -s ' ' | cut -d'
echo $BSS_SIZE
echo "bss_size: $BSS_SIZE"
+ld --defsym=_bss_size=$(size -B -d memtest_shared | grep memtest_shared | tr -s ' ' | cut -d ' ' -f3) \
+ -shared \
+ --print-memory-usage \
+ --print-output-format \
+ -Bsymbolic \
+ -M \
+ -nostdlib \
+ -T linker_modified.lds \
+ -o memtest_modified.efi \
+ boot/setup.o boot/startup.o boot/efisetup.o app/*.o lib/*.o system/*.o tests/*.o
-
-ld --defsym=_bss_size=$BSS_SIZE -T memtest_efi_modified.lds boot/header.o boot/setup.o -b memtest_shared -o memtest_modified.efi
+# ld -N --defsym=_bss_size=$BSS_SIZE -T linker_modified.lds boot/header.o boot/setup.o -b elf64-x86-64 memtest_shared -o memtest_modified.efi
diff --git a/documentation/memtest86_build_process/24_08_22_memtest_build_process b/documentation/memtest86_build_process/24_08_22_memtest_build_process
index 9847a5b..fc8f33c 100644
--- a/documentation/memtest86_build_process/24_08_22_memtest_build_process
+++ b/documentation/memtest86_build_process/24_08_22_memtest_build_process
@@ -203,3 +203,42 @@ coff_header:
#
# setup.S
#
+Collects memory map information from the BIOS, disables APM, enables A20 and performs
+the switch from real mode to protected mode before jumping to the main program entry
+point.
+
+The memory map information is stored in the 4KB block of memory immediately following
+the setup code. The layout of the information matches the Linux boot_params struct.
+A pointer to this block is passed to the main program, for compatibility with the Linux
+32-bit boot protocol.
+
+. # define BOOT_PARAMS_START (SETUP_SECS * 512) || SETUP_SEC is defined in boot.h
+. # define BOOT_PARAMS_END (BOOT_PARAMS_START + 4096) <--- here are the 4K
+
+ .section ".setup", "ax", @progbits
+ .code16
+
+Emulate the Linux boot header, to allow loading by other boot loaders. Indicate that the
+main program code should be loaded in high memory.
+
+ .globl setup
+setup: jmp do_setup
+
+101: do_setup:
+ Reload the segment registers, except for the stack
+ Get the memory map and disable APM
+ Disable interrupts
+ Enable A20
+ ...
+
+179: flush:
+ Reload the segment registers and jump to the main test program <------------!!!!
+
+ ...
+188: jump:
+ data32 ljmp $KERNEL_CS, $0
+
+
+
+389: Pad to the declared size
+ .org (ESTUP_SECS*512)
diff --git a/memtest_efi_modified.lds b/memtest_efi_modified.lds
index 179fe93..6f035c8 100644
--- a/memtest_efi_modified.lds
+++ b/memtest_efi_modified.lds
@@ -1,5 +1,6 @@
-OUTPUT_FORMAT("binary")
-OUTPUT_ARCH(i386:x86-64)
+OUTPUT_FORMAT("elf64-x86-64");
+OUTPUT_ARCH(i386:x86-64);
+
ENTRY(boot);
SECTIONS {
@@ -13,14 +14,60 @@ SECTIONS {
. = ALIGN(512);
.text : {
_text_start = . ;
- *(.data)
- . = ALIGN(512);
+ _start = .;
+ *(.text)
+ *(.text.*)
+ *(.plt)
+ _etext = . ;
_text_end = . ;
+ }= 0x9090
+
+ .rodata : {
+ *(.rodata)
+ *(.rodata.*)
}
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .hash : { *(.hash) }
+ .gnu.hash : { *(.gnu.hash) }
+ .dynamic : { *(.dynamic) }
+
+ .rela.text : { *(.rela.text .rela.text.*) }
+ .rela.rodata : { *(.rela.rodata .rela.rodata.*) }
+ .rela.data : { *(.rela.data .rela.data.*) }
+ .rela.got : { *(.rela.got .rela.got.*) }
+ .rela.plt : { *(.rela.plt .rela.plt.*) }
+
+ . = ALIGN(4);
+ .data : {
+ _data = .;
+ *(.data)
+ *(.data.*)
+ }
+ .got : {
+ *(.got.plt)
+ *(.got)
+ _edata = . ;
+ }
+ . = ALIGN(4);
+ .bss : {
+ _bss = .;
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(COMMON)
+ . = ALIGN(16);
+ _stacks = .;
+ *(.stacks)
+ /* _end must be at least 256 byte aligned */
+ . = ALIGN(256);
+ _end = .;
+ }
+
.debug : {
*(.debug*)
}
-
+
_text_size = (_text_end - _text_start);
_sys_size = _text_size >> 4;