Hi all,

  Could someone help me to confirm that I understand how the QEMU cross page
boundary checking correctly or not? Below is the source code I am looking at, 

static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong eip)
{

    if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) ||        --- (1)
        (pc & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK))  {  --- (2)
    }

}

(a)                                (b)
   tb->pc -->  ________               tb->pc -->  ________
              |        |                         |        |
              |        |                      -----------------
              |        |                         |        |
              |________|               s->pc --> |________| 
          
           ----------------                   -----------------
               ________                           ________
              |        |                         |        |
       pc --> |        |                  pc --> |        |
              |        |                         |        |
              |________|                         |________|


  My understanding is, if tb itself doesn't cross guest page boundary (a), then
condition (1) is enough to check if the jump target (pc) is in the same guest
page as tb is. Or, tb itself spans two guest pages (b), then we have to use
condition (2) to check if the jump target (pc) is in the same guest page as tb
is. In summary, those check (1) and (2) are used to avoid block linking to cross
guest page boundary.

  Am I right? If so far so good, I am curious about why we need (s->pc - 1)
instead of just (s->pc). Could you shed some light on that? Thanks in advance!


Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

Reply via email to