简体   繁体   中英

mov instruction strange destination operand

I am trying to understand the code for the Pintos bootloader and something struck me as strange in a certain line.

addr32 movl %eax, init_ram_pages - LOADER_PHYS_BASE - 0x20000 This line here is supposed to put the number of 4K pages in the variable init_ram_pages defined in a header file as:
extern uint32_t init_ram_pages;

What I do not understand is why are we subtracting from the init_ram_pages these values? What does it mean to have a subtraction operation in the destination operand of a mov ?

For further details:

The code which sets the size of the ram (in 4K pages) in %eax follows: (if my understanding is correct)

    movb $0x88, %ah
    int $0x15
    addl $1024, %eax    # Total kB memory
    cmp $0x10000, %eax  # Cap at 64 MB
    jbe 1f
    mov $0x10000, %eax
1:  shrl $2, %eax       # (shift right by two = divide by 4)
                # now eax contains the number of 4K pages I guess?

The constant are defined as:

/* Kernel virtual address at which all physical memory is mapped.
   Must be aligned on a 4 MB boundary. */
#define LOADER_PHYS_BASE 0xc0000000     /* 3 GB. */

Edit
The variable itself is defined in the same file as follows: (in the section of the file which follows the .code32)

#### Physical memory size in 4 kB pages.  This is exported to the rest
#### of the kernel.d
.globl init_ram_pages
init_ram_pages:
    .long 0

Subtraction there is nothing special, it's just a simple assembly or link time operation. In the final binary, the result of the calculation will be present.

I assume this is the real-mode portion of the bootloader which is nevertheless assembled/linked using the protected mode memory map. The adjustment presumably translates between the protected mode address that the assembler generates the code for and the real mode addresses that the cpu will actually use when running this code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM