Orange ' s initialization segment register

Source: Internet
Author: User

Recently began to look at "Orange's: An operating system implementation", but because do not understand the assembly, look at the first boot sector code when there is confusion:

1. In order to copy the values in CS to DS and ES, we first need to copy the values from CS to ax, why can't I copy them directly?

2. mov ax, CS; mov ds, ax; mov es, ax; what is the meaning of the sentence that initializes the segment register?

1 org 07c00h2         mov ax, CS3         mov ds, ax4         mov es, ax5         PagerDispstr6         jmp     $7 Dispstr:8         movAx, Bootmessage9         movBP, AxTen         movCx - One         movAx, 01301h A         movBX, 000ch -         movDl0 -         int10h the         ret - Bootmessage:Db"Hello, OS world!" -Times510-($-$$) DB0 -DW 0xaa55

A basic understanding of the two issues was found, but very specific details were not explained because they did not understand the compendium.

For the problem 1,intel x86 architecture will not allow MOV operation number of two segment register, from NASM supported operation also can not find MOV reg_sreg Reg_sreg, as for why not support, Intel x86_64 Architecture manual too complicated, did not find.

For the problem 2,ds and ES registers are used to indicate the location of the data segment, so at the beginning of the program, they should be initialized to the correct segment address so that we can find the data correctly in the program. However, in small programs, data segments and code snippets are generally the same segment, so we copy the values in CS to DS and ES and initialize the DS and es correctly. (So based on this I guess that CS will automatically initialize to the correct code snippet location when the program loads, and the following actions on the string should also involve DS and ES.) There is no very clear information, disassembly Boot.bin after the following assembly I do not quite understand. However, this is when the previous segment register was also used to store the segment position, now in the x86 system, the number of bits in the Register is sufficient to address the entire memory, so the segment register will no longer need the bucket location.

We can debug this boot sector code in Bochs, and in x86_64 's hardware architecture, the value in Cs,ds,es is always 0.

es:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=1Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessedCS:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=1Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessedSS:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=7Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessedds:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=1Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessedFS:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=1Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessedGS:0x0000, dh=0x00009300, DL=0X0000FFFF, valid=1Data segment, base=0x00000000, LIMIT=0X0000FFFF, read/write, accessed

Then we can delete the statement of the initialization segment register, and then run it in the virtual machine after recompiling, we can see that the program runs successfully, and the initialization of the segment Register statement has no effect on the operation of the program on the x86_64 schema.

Orange ' s initialization segment register

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.