[if gte mso 9]>

Re: [edk2] DuetPkg: st32_64.S mistakes

Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

From: "Sun, Rui" <rui.sun@intel.com>

To: "edk2-devel@lists.sourceforge.net" <edk2-devel@lists.sourceforge.net>

Date: 2012-03-09 10:31:18

Sergey,

 

For item 4, there is no such code logic after A20GateEnabled in st32_64.S.

 

From your description, I cant understand what is the root cause for the crash you met.

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru]
Sent: Friday, March 09, 2012 5:23 AM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Hi,

 

 

On 08.03.2012, at 13:15, Sun, Rui wrote:



Sergey,

 

1.       I agree that the near jump is redundant, but it should be harmless.

2.       This instruction is irrelevant. orb   $0x1,%al and orl %0x1,%eax have same effect.

for reduce binary size.

But I see second instruction has prefix 66 that works different in 16 and 32 bit modes.

3.       I suspect this is the root cause. Different between PS2 (actually KBC) and port 92 is that port 92 is built-in logic in Chipset, while KBC in is 3rdparty chip (typically SIO) and KBC may be absent in a legacy free platform. I wonder why INT15/2401 cant work. Could you confirm that KBC in your platform is not present?

KBC is present but non-standard chip. Really INT15 works. So this is also for reduce code size.

4.       Where is the code piece?

just after label A20GateEnabled: 

 

Rui

 

Sergey

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Wednesday, March 07, 2012 2:41 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Hi Rui,

 

I resolved the issue. Don't know exactly where is a final solution. The follow set of changes

1. Exclude near jump as discussed below.

2. Use orb   $0x1,%al       # Set PE=1 instead of orl %0x1,%eax

Byte code 0c01 instead of 6683c801

3. To enable A20 gate there are three methods: Int 15, PS2keyb and port92.

st32_64 uses int15 or PS2 while Thunk16 uses int15 or port92. What is the logic for this difference?

I exclude PS2 and use port92 in the st32_64

-------------

#

# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.

#

/*

        call    Empty8042InputBuffer        # Empty the Input Buffer on the 8042 controller

...

Timeout8042: 

 

*/

#fast A20gate

                        inb     $0x92, %al

                        orb       $2, %al

                        outb    %al, $0x92

 

 

A20GateEnabled: 

-------------

4.  Test BiosVideo that may also initialized it in proper way

--------

                        movl    $0x000F, %ebx

                        movl    $0x0E37, %eax

                        movl    $0x0010, %ecx

                        int        $0x10

 

---------

 

That's all. Now it works!

 

Sergey.

 

On 06.03.2012, at 10:12, Sergey Isakov wrote:




Hi Rui,

 

I excluded near jmp but no changes.

I got red screen

INT 06 INVALID OPCODE

RBX=20000 RDX=21B1D RSP=1FFF28 RBP=1FFF28 RDI=B8000 RFLAGS=10016

others are zero.

Setting an instruction somewhere

Cycle: jmp Cycle

I can prevent the crash. If the execution passed to the instruction then computer just stop.

If the instruction placed too far I see the red screen.

This way I found that the last place is  in efi64.S

---------

#Cyc: jmp Cyc

 

    .byte 0x48

    .byte 0xc7

    .byte 0xc0

EfiLdrOffset: 

    .long 0x00401000                    # Offset of EFILDR

#   mov rax, 401000h

    .byte 0x50

#   push rax

 

# ret

    .byte 0xc3

---------

So I think my CPU at this place is still in 32-bit mode. May be I am wrong.

Setting the same cycle in C-sources has no effect.

 

Sergey

 

On 06.03.2012, at 9:39, Sun, Rui wrote:




Hi, Sergey,

 

For your first concern, legacy boot is expected to start from real mode, where paging is disabled. So there is no need to clear CR0.PG.

 

For your second concern, it seems that

    jmp   GoToLongMode

GoToLongMode: 

 

Is redundant. Could you remove it to see if your problem is gone?

 

If your problem still remains, could you tell me the exact instruction where the crash happens? Thanks.

 

Rui

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Monday, March 05, 2012 9:48 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Hi Rui,

I still have problems with this file.

According to my debugging CPU Core2Duo T8300 (Penryn-M) doesn't want to switch to Long Mode. Crashes appeared when jump to Efildr.

I read Intel specification again and see the follow (253668.pdf Chapter 9.8.5).

1. Starting from protected mode, disable paging by setting CR0.PG = 0 

2. Enable physical-address extensions (PAE) by setting CR4.PAE = 1

But in the file I see no first step. It begins from step.2.

While specification says

----

64-bit mode consistency checks fail in the following circumstances:

           An attempt is made to enable or disable IA-32e mode while paging is enabled

-----

Don't know if it possible that the CPU already has the PG bit set. Previous codes didn't clear it.

 

And next doubt

---------------

    movl  %eax, %cr0      # Write CR0.

    jmp   GoToLongMode

GoToLongMode: 

 

    .byte 0x67

    .byte 0xea                  # Far Jump $+9:Selector to reload CS

OffsetInLongMode: 

    .long 00000000              #   $+9 Offset is ensuing instruction boundary

    .word 0x38                  #   Selector is our code selector, 38h

 

InLongMode: 

---------------

First jmp is "near jump" and its presenting here look to be redundant or even failure.

 

I will not asking about the doubts but this program really doesn't work. I have tested very carefully.

Yes, it works on some another hardware but not always.

 

Help, please.

Sergey.

 

 

On 18.01.2012, at 7:29, Sun, Rui wrote:





Sergey,

 

The diff is caused by the difference between st32_64.asm and st32_64.S:

 

st32_64.asm:

gdtr    dw GDT_END - GDT_BASE - 1   ; GDT limit

 

st32_64.S:

        gdtr:    .long  GDT_END - GDT_BASE - 1  # GDT limit

 

 

So it is a bug in st32_64.S. I fixed it in check in #12934.

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Wednesday, January 18, 2012 1:17 AM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Rui,

 

I showed you at January 11 that the sources is compiled into wrong binary. Looks like exceeded P2align statement.

 

Sergey

 

On 16.01.2012, at 6:04, Sun, Rui wrote:






Sergey,

 

No need to change st32_64.S.

 

Rui

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Friday, January 13, 2012 3:15 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Rui,

 

-----------

 svn up

U    DuetPkg/BootSector/Mbr.S

U    DuetPkg/BootSector/bs32.asm

G    DuetPkg/BootSector/start32.S

U    DuetPkg/BootSector/bin/bs32.com

U    DuetPkg/BootSector/bs32.S

U    DuetPkg/BootSector/efi64.S

Updated to revision 12930.

-----------

What about st32_64.S?

 

Sergey.

 

On 13.01.2012, at 10:33, Sun, Rui wrote:







Sergey,

 

You can verify the check in #12930.

 

Rui.

 

From: Sun, Rui [mailto:rui.sun@intel.com] 
Sent: Wednesday, January 11, 2012 9:25 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Sergey

 

I am looking at this issue, and hope I can have a patch tomorrow.

 

Rui

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Wednesday, January 11, 2012 2:43 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Hi Rui,

 

I found a diff in old and new binary files at offset 0x370.

Old (from 0x360)

--------

C3 B9 00 00 E7 ED E4 64 24 02 E0 F8 C3 90 47 00

00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00

--------

New

------

C3 B9 00 00 E7 ED E4 64 24 02 E0 F8 C3 90 47 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF

-------

Two bytes more.

It is in this place

-----

        ret

 

##############################################################################

# data

##############################################################################

 

        .p2align 1

 

        gdtr:    .long  GDT_END - GDT_BASE - 1  # GDT limit 

        .long 0                     # (GDT base gets set above)

##############################################################################

#   global descriptor table (GDT)

##############################################################################

 

        .p2align 1

 

GDT_BASE: 

# null descriptor

.equ                NULL_SEL, .-GDT_BASE    # Selector [0x0]

 

-----

Don't know why alignment works not as expected.

 

Sergey

 

On 11.01.2012, at 6:16, Sun, Rui wrote:

 

Sergey,

 

I just fixed the GCC build issue. I did not verify Duet64 built with GCC.

Could you debug it to see what is wrong?

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Tuesday, January 10, 2012 4:32 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] DuetPkg: st32_64.S mistakes

 

Hi Rui,

 

Your corrections are good. No more compiler's error and binary produced looks good.

But I still have a reboot with Duet64 at early stage of booting.

The same reboot I had with Duet32 until I corrected realMode->protectedMode switching. Now it was resolved.

But for Duet64 I don't know what it may be the issue.

 

Sergey.

 

On 10.01.2012, at 8:31, Sun, Rui wrote:








Hi, Sergey,

 

Please verify if the check in of #12921 fixes your problem.

 

Thanks,

Rui

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Monday, January 09, 2012 6:07 AM
To: edk2-devel@lists.sourceforge.net
Subject: [edk2] DuetPkg: st32_64.S mistakes

 

Hi,

Please find a difference

---------------------

--- st32_64.S   2011-11-17 21:56:01.000000000 +0400

+++ st32_64-new.S    2012-01-09 01:51:48.000000000 +0400

@@ -27,6 +27,10 @@

 .equ                        BLOCK_SHIFT, 9

 

        .org 0x0

+

+.global _start

+_start:

+              

 Ia32Jump: 

   jmp   BootSectorEntryPoint  # JMP inst    - 3 bytes

   nop

@@ -142,7 +146,7 @@

         .byte 0xea

 jumpOffset: 

         .word 0x200

-jumpSegment: 

+JumpSegment: 

         .word 0x2000

 

 @@ -446,7 +458,7 @@

     #

     # Enable Protect Mode (set CR0.PE=1)

     #

-    movl  $cr0, %eax      # Read CR0.

+    movl  %cr0, %eax      # Read CR0.

     orl   $0x1,%eax       # Set PE=1

     movl  %eax, %cr0      # Write CR0.

     .byte 0x66

@@ -518,7 +530,7 @@

     #

     # Enable paging to activate long mode (set CR0.PG=1)

     #

-    movl  $cr0, %eax      # Read CR0.

+    movl  %cr0, %eax      # Read CR0.

     .byte 0xf

     .byte 0xba

     .byte 0xe8

----------------------

Sergey

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel