qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

multiboot: Calculate upper_mem in the ROM

The upper_mem field of the Multiboot information struct doesn't really
contain the RAM size - 1 MB like we used to calculate it, but only the
memory from 1 MB up to the first (upper) memory hole.

In order to correctly retrieve this information, the multiboot ROM now
looks at the mmap it creates anyway and tries to find the size of
contiguous usable memory from 1 MB.

Drop the multiboot.c definition of lower_mem and upper_mem because both
are queried at runtime now.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Message-id: 1372018066-21822-3-git-send-email-mail@kevin-wolf.de
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

authored by

Kevin Wolf and committed by
Anthony Liguori
26a8ec07 390fb6b4

+40 -2
-2
hw/i386/multiboot.c
··· 315 315 | MULTIBOOT_FLAGS_CMDLINE 316 316 | MULTIBOOT_FLAGS_MODULES 317 317 | MULTIBOOT_FLAGS_MMAP); 318 - stl_p(bootinfo + MBI_MEM_LOWER, 640); 319 - stl_p(bootinfo + MBI_MEM_UPPER, (ram_size / 1024) - 1024); 320 318 stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */ 321 319 stl_p(bootinfo + MBI_MMAP_ADDR, ADDR_E820_MAP); 322 320
+40
pc-bios/optionrom/multiboot.S
··· 123 123 jnz mmap_loop 124 124 125 125 mmap_done: 126 + /* Calculate upper_mem field: The amount of memory between 1 MB and 127 + the first upper memory hole. Get it from the mmap. */ 128 + xor %di, %di 129 + mov $0x100000, %edx 130 + upper_mem_entry: 131 + cmp %fs:0x2c, %di 132 + je upper_mem_done 133 + add $4, %di 134 + 135 + /* Skip if type != 1 */ 136 + cmpl $1, %es:16(%di) 137 + jne upper_mem_next 138 + 139 + /* Skip if > 4 GB */ 140 + movl %es:4(%di), %eax 141 + test %eax, %eax 142 + jnz upper_mem_next 143 + 144 + /* Check for contiguous extension (base <= %edx < base + length) */ 145 + movl %es:(%di), %eax 146 + cmp %eax, %edx 147 + jb upper_mem_next 148 + addl %es:8(%di), %eax 149 + cmp %eax, %edx 150 + jae upper_mem_next 151 + 152 + /* If so, update %edx, and restart the search (mmap isn't ordered) */ 153 + mov %eax, %edx 154 + xor %di, %di 155 + jmp upper_mem_entry 156 + 157 + upper_mem_next: 158 + addl %es:-4(%di), %edi 159 + jmp upper_mem_entry 160 + 161 + upper_mem_done: 162 + sub $0x100000, %edx 163 + shr $10, %edx 164 + mov %edx, %fs:0x8 165 + 126 166 real_to_prot: 127 167 /* Load the GDT before going into protected mode */ 128 168 lgdt: