none
One question about GDT in WEC7: RRS feed

  • Question

  • static ULONGLONG BspGDT[] = {
        0,                          // 0x00
        0x00CF9A000000FFFF,         // 0x08: Ring 0 code, Limit = 4G
        0x00CF92000000FFFF,         // 0x10: Ring 0 data, Limit = 4G
        0x00CFBA000000FFFF,         // 0x18: Ring 1 code, Limit = 4G
        0x00CFB2000000FFFF,         // 0x20: Ring 1 data, Limit = 4G
        0x00CFDA000000FFFF,         // 0x28: Ring 2 code, Limit = 4G
        0x00CFD2000000FFFF,         // 0x30: Ring 2 data, Limit = 4G
        0x00CFFA000000FFFF,         // 0x38: Ring 3 code, Limit = 4G
        0x00CFF2000000FFFF,         // 0x40: Ring 3 data, Limit = 4G
        0,                          // 0x48: Will be main TSS
        0,                          // 0x50: Will be NMI TSS
        0,                          // 0x58: Will be Double Fault TSS
        0x0040F20000000000+FS_LIMIT,// 0x60: PCR selector
        0x00CFBE000000FFFF,         // 0x68: Ring 1 (conforming) code, Limit = 4G
        0x0040F00000000000+sizeof(PCB), // 0x70: Ring 3 r/o Data, PCB selector
        0x0040B20000000000+sizeof(PCB), // 0x78: Ring 1 Data, PCB selector
    };
    const FWORDPtr BspGDTBase = {sizeof(BspGDT)-1, &BspGDT };
      __asm {
            lgdt    [BspGDTBase]
    }

    Hello, guys,

    The above code is from file sysinit.c in c:\wince700\private\winceos\coreos\nk\kernel\x86. I am trying to support ACPI S3 in WEC7. That's the reason why I concerns with GDT. For ACPI S3 only memory is powered. Before entering into S3 state I think I should saved the value of GDT from register to memory and tried to restore it at the first time when resume. For resume BIOS will jump to waking vector and at this time the system is in real mode. We should do some restoring work here before jumping from real mode to protected mode.
    Now my trouble is my code 

    OpPrefix db 0EAh PModeLbl dd 00000000h ; Jump to the place where protected mode begins

    dw 0008h ;CS_FALT_SEL

     didn't jump to the place where I am hoping. I hope the CS segment selector is 0x8. By hardware debugger tool, during resume the actual place the system stopped at 0x67f6bd26 and actual segment selector seemed to change to 0x38 from my original setting 0x8. 

    1. In real mode I checked the restored the value for GDT, CR3 and CR0 in memory. I can make sure the memory is ok and didn't be destroyed in sleep.

    2. After jump why the segment selector is not I hoped?

    3. In real mode I enabled paging. It can be checked by CR0 and CR3 registers. But by hardware debugger tool the stopped address 0x67f6bd26 can be accessed both by linear and physical mode. And the values are same by these two memory ways. I know that if the paging is disable the address of linear is the same as physical address. Did it mean the paging enabling work fail?

    4. The debug message from output window of WEC7 told me that ACPI tables were found at 0x67855028h. The physical memory for my platform is 2 GB. In my understanding the system will reserve the memory area between 0x67855028hB and 2048 MB for ACPI tables. But the stopped address 0x67f6bd26 is just located in this reserved area. How did it happen?

    Is there someone who has made some effort in this topic? Any suggestion will be very appreciated.

    Thanks and best regards


    Tuesday, May 15, 2012 9:51 AM

All replies

  • Have you taken a look at platform\cepc\src\boot\xldr\startup.asm which should give you a more closer sample for a boot strap scenario.
    Wednesday, May 16, 2012 2:11 AM
  • KMOS,

    Yes. I have tried to found all the asm files under wince700 tree. In my opnion I thought \cepc\src\bootloader\dos\loadcepc\transfer.ams would be a good example for me.

    This afternoon I did a test. In real mode I only set stack, restore GDT and set CR0 to be 1, then tried to jump to protected mode. The addresses of protected mode and the offset of GDT are both physical address. And the restored value for GDT is saved before entering into S3. This time I succeeded. This test proved that the issue was really memory mechanism restoring. I have to go on with researching CR3, page directory and page tables. How about your opinion about my test?

    Thanks a lot for your continuous help! Best regards to you!

    Wednesday, May 16, 2012 9:44 AM