On Jun 23, 2014, at 7:18 PM, Gao, Liming <[email protected]> wrote:

> Andrew:
>   I agree this is a generic feature. Your change is OK. If we add it, I think 
> we should apply them for all similar functions, and apply them in MSFT and 
> GCC assembly code both.
>  

That sounds like a good idea.

Thanks,

Andrew Fish

>   So far, I find the following APIs have the similar usage.
> SwitchStack()
> AsmEnablePaging32()
> AsmEnablePaging64()
> AsmDisablePaging32()
> AsmDisablePaging64()
>  
> Thanks
> Liming
> From: Andrew Fish [mailto:[email protected]] 
> Sent: Friday, June 20, 2014 11:57 PM
> To: [email protected]
> Subject: Re: [edk2] MdePkg maintainer: We need InternalX86EnablePaging64() to 
> work like SwitchStack CpuExceptionHandlerLib
>  
>  
> On Jun 20, 2014, at 3:15 AM, Gao, Liming <[email protected]> wrote:
> 
> 
> Andrew:
>   Seemly, this is a debug feature. Which debugger supports it? Or, this is a 
> generic function (stop walking the frame) in debugger?
>  
>  
> Xcode clang/lldb use this. This is what the C runtime does on OS X.
> The compiler maintains a frame pointer so you can unwind the stack without 
> symbols. 
>                 pushq      %rbp
>                 movq       %rsp, %rbp
>         ...
>                 popq        %rbp
>                 ret
>  
> If you know the PC and frame pointer (RBP) you can walk the stack, as the 
> stack has the PC and FP of the caller. Hitting a return address of zero is 
> used by the algorithm to terminate the stack walk. If you don’t hit the zero 
> the stack walk sees the return address from the call and keeps going. In any 
> frame pointer scheme you need a way to stop, and this is usually hitting a PC 
> of zero. So I think this is a generic feature. 
>  
> This means that a stack walk is possible without the debug information. For 
> example it is possible for a CpuExceptionHandlerLib to print the complete 
> stack frame on an exception, and lookup the module name, and offset in the 
> module of the PC for the entire frame.  This means you get a full stack trace 
> printed out for every ASSERT()! We have an lldb script that walks the frame 
> and loads symbols for only the modules in the frame. It is also a useful 
> feature for profiling, and leak detection. 
>  
> You can only walk the stack in Visual Studio if you have symbols. I’m 
> guessing that the stack unwind just stops when you hit an address that does 
> not have symbols. 
>  
> I assume there is a flag in GCC to emit a frame pointer for X64, so this 
> would be useful in that case too. 
>  
> Thanks,
>  
> Andrew Fish
>  
> ~/work/Compiler>cat a.c
> int
> main ()
> {
>   return 0;
> }
> ~/work/Compiler>clang -S -Os a.c
> ~/work/Compiler>cat a.S
>                 .section    __TEXT,__text,regular,pure_instructions
>                 .globl       _main
> _main:                                  ## @main
>                 .cfi_startproc
> ## BB#0:
>                 pushq      %rbp
> Ltmp2:
>                 .cfi_def_cfa_offset 16
> Ltmp3:
>                 .cfi_offset %rbp, -16
>                 movq       %rsp, %rbp
> Ltmp4:
>                 .cfi_def_cfa_register %rbp
>                 xorl          %eax, %eax
>                 popq        %rbp
>                 ret
>  
> 
> 
> Thanks
> Liming
> From: Andrew Fish [mailto:[email protected]] 
> Sent: Wednesday, June 18, 2014 10:55 PM
> To: [email protected]
> Subject: [edk2] MdePkg maintainer: We need InternalX86EnablePaging64() to 
> work like SwitchStack
>  
> InternalX86EnablePaging64() does a call to the new 64-bit entry point. This 
> call breaks our debugger stack walking code. We need it to be a push $0/jmp. 
> In place of a call. The push $0/jmp makes the return address from the call be 
> 0, and this tells the debugger to stop walking the frame. In clang and some 
> flavors of GCC all C functions spill enough state to the stack so that you 
> can walk the stack via an algorithm (on VC++ for X64 you need symbols). 
>  
> If this change is OK with folks I can submit a patch.
>  
> https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BaseLib/X64/SwitchStack.S
>     #
>     # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,
>     # in case the callee wishes to spill them.
>     #
>     lea     -0x20(%r9), %rsp
>     pushq   $0        // stop gdb stack unwind
>     jmp     *%rax     // call EntryPoint ()
>  
> https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BaseLib/Ia32/EnablePaging64.S
>     .byte   0x48
>     addl    $0x-0x20, %esp              # add rsp, -20h
>     call    *%ebx                       # call rbx
>     jmp     .                           # no one should get here
> So what we would like to see is:
>     .byte   0x48
>     addl    $0x-0x20, %esp              # add rsp, -20h
>     push    $0        // stop gdb stack unwind
>     jmp     *%ebx     // call EntryPoint ()
>  
>  
>  
> Thanks,
>  
> Andrew Fish
> ------------------------------------------------------------------------------
> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
> Find What Matters Most in Your Big Data with HPCC Systems
> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
> Leverages Graph Analysis for Fast Processing & Easy Data Exploration
> http://p.sf.net/sfu/hpccsystems_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>  
> ------------------------------------------------------------------------------
> Open source business process management suite built on Java and Eclipse
> Turn processes into business applications with Bonita BPM Community Edition
> Quickly connect people, data, and systems into organized workflows
> Winner of BOSSIE, CODIE, OW2 and Gartner awards
> http://p.sf.net/sfu/Bonitasoft_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to