Print this page
Use `iretq` method of jumping to 32-bit so VirtualBox (and maybe QEMU/KVM too?)
can cope and not get its `ljmp <mem48>` emulation bug(s) tickled.

Split Close
Expand all
Collapse all
          --- old/src/arch/x86/image/multiboot2_entry.S
          +++ new/src/arch/x86/image/multiboot2_entry.S
   1    1  /*
   2    2   * Parts copyright Michael Brown <mbrown@fensystems.co.uk>
   3    3   *
   4      - * Copyright (c) 2019, Joyent, Inc.
        4 + * Copyright 2020 Joyent, Inc.
   5    5   */
   6    6  
   7    7  FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
   8    8  
   9    9  /* CR0: protection enabled */
  10   10  #define CR0_PE ( 1 << 0 )
  11   11  
  12   12  /* CR0: paging */
  13   13  #define CR0_PG ( 1 << 31 )
  14   14  
↓ open down ↓ 40 lines elided ↑ open up ↑
  55   55  
  56   56          /* Load the mb2-mandated code and data segments.  */
  57   57          leaq    entry_gdt_base(%rip), %rcx
  58   58          leaq    entry_gdt(%rip), %rax
  59   59          movq    %rax, (%rcx)
  60   60  
  61   61          leaq    entry_gdtr(%rip), %rax
  62   62          lgdt    (%rax)
  63   63  
  64   64          /* Load our new %cs. */
  65      -        ljmp    *newcs_vector
       65 +        movq    %rsp, %rax
       66 +        pushq   $GDTSEL_DATA
       67 +        pushq   %rax
       68 +        pushf
       69 +        pushq   $GDTSEL_CODE
       70 +        lea     newcs(%rip), %rax
       71 +        pushq   %rax
       72 +        iretq
  66   73  
  67   74          .code32
  68   75  newcs:
  69   76  
  70   77          movw    $GDTSEL_DATA, %ax
  71   78          movw    %ax, %ds
  72   79          movw    %ax, %es
  73   80          movw    %ax, %fs
  74   81          movw    %ax, %gs
  75   82          movw    %ax, %ss
↓ open down ↓ 25 lines elided ↑ open up ↑
 101  108          .align 16
 102  109          .code64
 103  110          .globl multiboot2_bounce
 104  111  
 105  112  multiboot2_bounce:
 106  113          movq    %rsi, %rsp
 107  114          jmp     *%rdx
 108  115  
 109  116          .data
 110  117  
 111      -newcs_vector:
 112      -        .long   newcs, GDTSEL_CODE
 113      -
 114  118          .align 16
 115  119  entry_gdt:
 116  120          /* null entry */
 117  121          .word   0x0, 0x0
 118  122          .byte   0x0, 0x0, 0x0, 0x0
 119  123  
 120  124          /* 32 bit protected mode code segment */
 121  125          .word   0xffff, 0x0
 122  126          .byte   0x0, 0x9f, 0xcf, 0x0
 123  127  
↓ open down ↓ 14 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX