[coreboot-gerrit] New patch to review for coreboot: 960e7f5 cbfstool:linux_trampoline: config CS and DS segment descriptors

Curt Brune (curt@cumulusnetworks.com) gerrit at coreboot.org
Fri Aug 29 19:48:14 CEST 2014


Curt Brune (curt at cumulusnetworks.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6796

-gerrit

commit 960e7f56b1abd277fa1173a9d1c986e882d52537
Author: Curt Brune <curt at cumulusnetworks.com>
Date:   Fri Aug 29 10:43:36 2014 -0700

    cbfstool:linux_trampoline: config CS and DS segment descriptors
    
    The Linux trampoline code does not set up the segment descriptors for
    __BOOT_CS and __BOOT_DS as described in the Linux kernel
    documentation:
    
      ... a GDT must be loaded with the descriptors for selectors
      __BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G
      flat segment; __BOOT_CS must have execute/read permission, and
      __BOOT_DS must have read/write permission;
    
    This is not a problem when launching a Linux payload from coreboot, as
    coreboot configures the segment descriptors at selectors 0x10 and
    0x18.  Coreboot configures these selectors in the ramstage to match
    what the Linux kernel expects (see
    coreboot/src/arch/x86/lib/c_start.S).
    
    When the cbfs payload is launched in other environments, SeaBIOS for
    example, the segment descriptors are configured differently and the
    cbfs Linux payload does not work.
    
    If the cbfs Linux payload is to be used in multiple environments
    should the trampoline needs to take care of the descriptors that Linux
    requires.
    
    This patch updates the Linux trampoline code to configure the 4G flat
    descriptors that Linux expects.  The configuration is borrowed from
    the descriptor configs in coreboot/src/arch/x86/lib/c_start.S for
    selectors 0x10 and 0x18.
    
    Testing Done:
    
    Verified the Linux payload is booted correctly in the following
    environments:
    
    1.  Coreboot -> Linux Payload
    
    2.  Coreboot -> SeaBIOS -> Linux Payload: (previously did not work)
    
    Change-Id: I888f74ff43073a6b7318f6713a8d4ecb804c0162
    Signed-off-by: Curt Brune <curt at cumulusnetworks.com>
---
 util/cbfstool/linux_trampoline.c | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/util/cbfstool/linux_trampoline.c b/util/cbfstool/linux_trampoline.c
index 368d63a..1a1dccf 100644
--- a/util/cbfstool/linux_trampoline.c
+++ b/util/cbfstool/linux_trampoline.c
@@ -101,6 +101,28 @@ add 4(%ebx), %ebx
 dec %ecx
 jnz .tableScan
 
+/* Setup basic code and data segment selectors for Linux
+**
+** Flat code segment descriptor:
+**   selector: 0x10
+**   base    : 0x00000000
+**   limit   : 0xFFFFFFFF
+**   type    : code, execute, read
+**
+** Flat data segment descriptor:
+**   selector: 0x18
+**   base    : 0x00000000
+**   limit   : 0xFFFFFFFF
+**   type    : data, read/write
+*/
+mov  %esp, %eax
+sgdt (%eax)
+mov  2(%eax), %ebx
+movl  $0x0000ffff, 16(%ebx)
+movl  $0x00cf9b00, 20(%ebx)
+movl  $0x0000ffff, 24(%ebx)
+movl  $0x00cf9300, 28(%ebx)
+
 /* finally: jump to kernel */
 mov $LINUX_PARAM_LOC, %esi
 jmp *(LINUX_PARAM_LOC + LINUX_ENTRY_OFFSET)
@@ -128,13 +150,15 @@ trampoline_size:
 const unsigned char trampoline[] = {
 0xfc, 0x31, 0xd2, 0xb9, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x00, 0x00, 0x01, 0x00, 0x01, 0xcb, 0x8b,
 0x01, 0x3d, 0x4c, 0x42, 0x49, 0x4f, 0x74, 0x07, 0x83, 0xc1, 0x10, 0x39, 0xcb, 0x75, 0xe9, 0x39,
-0xcb, 0x74, 0x60, 0x8b, 0x59, 0x04, 0x01, 0xcb, 0x8b, 0x49, 0x14, 0x83, 0x3b, 0x11, 0x75, 0x05,
-0x8b, 0x4b, 0x08, 0xeb, 0xd3, 0x83, 0x3b, 0x01, 0x75, 0x33, 0x8b, 0x43, 0x04, 0x83, 0xe8, 0x08,
-0xc1, 0xe8, 0x02, 0x3d, 0xa0, 0x00, 0x00, 0x00, 0x7e, 0x05, 0xb8, 0xa0, 0x00, 0x00, 0x00, 0x89,
-0xc6, 0xbf, 0x05, 0x00, 0x00, 0x00, 0xf7, 0xf7, 0xa3, 0xe8, 0x01, 0x09, 0x00, 0x89, 0xf0, 0x91,
-0x8d, 0x73, 0x08, 0xbf, 0xd0, 0x02, 0x09, 0x00, 0xf3, 0xa5, 0x91, 0xeb, 0x05, 0x83, 0x3b, 0x12,
-0x75, 0x00, 0x03, 0x5b, 0x04, 0x49, 0x75, 0xb3, 0xbe, 0x00, 0x00, 0x09, 0x00, 0xff, 0x25, 0x14,
-0x02, 0x09, 0x00, 0xf4, 0xeb, 0xfd
+0xcb, 0x0f, 0x84, 0x85, 0x00, 0x00, 0x00, 0x8b, 0x59, 0x04, 0x01, 0xcb, 0x8b, 0x49, 0x14, 0x83,
+0x3b, 0x11, 0x75, 0x05, 0x8b, 0x4b, 0x08, 0xeb, 0xcf, 0x83, 0x3b, 0x01, 0x75, 0x33, 0x8b, 0x43,
+0x04, 0x83, 0xe8, 0x08, 0xc1, 0xe8, 0x02, 0x3d, 0xa0, 0x00, 0x00, 0x00, 0x7e, 0x05, 0xb8, 0xa0,
+0x00, 0x00, 0x00, 0x89, 0xc6, 0xbf, 0x05, 0x00, 0x00, 0x00, 0xf7, 0xf7, 0xa3, 0xe8, 0x01, 0x09,
+0x00, 0x89, 0xf0, 0x91, 0x8d, 0x73, 0x08, 0xbf, 0xd0, 0x02, 0x09, 0x00, 0xf3, 0xa5, 0x91, 0xeb,
+0x05, 0x83, 0x3b, 0x12, 0x75, 0x00, 0x03, 0x5b, 0x04, 0x49, 0x75, 0xb3, 0x89, 0xe0, 0x0f, 0x01,
+0x00, 0x8b, 0x58, 0x02, 0xc7, 0x43, 0x10, 0xff, 0xff, 0x00, 0x00, 0xc7, 0x43, 0x14, 0x00, 0x9b,
+0xcf, 0x00, 0xc7, 0x43, 0x18, 0xff, 0xff, 0x00, 0x00, 0xc7, 0x43, 0x1c, 0x00, 0x93, 0xcf, 0x00,
+0xbe, 0x00, 0x00, 0x09, 0x00, 0xff, 0x25, 0x14, 0x02, 0x09, 0x00, 0xf4, 0xeb, 0xfd
 };
 
 const void * const trampoline_start = &trampoline;



More information about the coreboot-gerrit mailing list