.arch i386
-#define CR0_PE 1
-
-/****************************************************************************
- * flatten_real_mode
- *
- * Set up 4GB segment limits
- *
- * Parameters:
- * none
- * Returns:
- * none
- * Corrupts:
- * none
- ****************************************************************************
- */
- /* GDT for protected-mode calls */
- .section ".text16.early.data", "aw", @progbits
- .align 16
-flatten_gdt:
-flatten_gdt_limit: .word flatten_gdt_length - 1
-flatten_gdt_base: .long 0
- .word 0 /* padding */
-flatten_cs: /* 16-bit protected-mode flat code segment */
- .equ FLAT_CS, flatten_cs - flatten_gdt
- .word 0xffff, 0
- .byte 0, 0x9b, 0x8f, 0
-flatten_ss: /* 16-bit protected-mode flat stack segment */
- .equ FLAT_SS, flatten_ss - flatten_gdt
- .word 0xffff, 0
- .byte 0, 0x93, 0x8f, 0
-flatten_gdt_end:
- .equ flatten_gdt_length, . - flatten_gdt
- .size flatten_gdt, . - flatten_gdt
-
- .section ".text16.early.data", "aw", @progbits
- .align 16
-flatten_saved_gdt:
- .long 0, 0
- .size flatten_saved_gdt, . - flatten_saved_gdt
-
- .section ".text16.early", "awx", @progbits
- .code16
-flatten_real_mode:
- /* Preserve registers and flags */
- pushfl
- pushl %eax
- pushw %si
- pushw %gs
- pushw %fs
- pushw %es
- pushw %ds
- pushw %ss
-
- /* Set %ds for access to .text16.early.data variables */
- pushw %cs
- popw %ds
-
- /* Preserve original GDT */
- sgdt flatten_saved_gdt
-
- /* Set up GDT bases */
- xorl %eax, %eax
- movw %cs, %ax
- shll $4, %eax
- addl $flatten_gdt, %eax
- movl %eax, flatten_gdt_base
- movw %cs, %ax
- movw $flatten_cs, %si
- call set_seg_base
- movw %ss, %ax
- movw $flatten_ss, %si
- call set_seg_base
-
- /* Switch temporarily to protected mode and set segment registers */
- pushw %cs
- pushw $2f
- cli
- data32 lgdt flatten_gdt
- movl %cr0, %eax
- orb $CR0_PE, %al
- movl %eax, %cr0
- ljmp $FLAT_CS, $1f
-1: movw $FLAT_SS, %ax
- movw %ax, %ss
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %fs
- movw %ax, %gs
- movl %cr0, %eax
- andb $0!CR0_PE, %al
- movl %eax, %cr0
- lret
-2: /* lret will ljmp to here */
-
- /* Restore GDT, registers and flags */
- data32 lgdt flatten_saved_gdt
- popw %ss
- popw %ds
- popw %es
- popw %fs
- popw %gs
- popw %si
- popl %eax
- popfl
- ret
- .size flatten_real_mode, . - flatten_real_mode
-
- .section ".text16.early", "awx", @progbits
- .code16
-set_seg_base:
- rolw $4, %ax
- movw %ax, 2(%si)
- andw $0xfff0, 2(%si)
- movb %al, 4(%si)
- andb $0x0f, 4(%si)
- ret
- .size set_seg_base, . - set_seg_base
-
/****************************************************************************
* test_a20_short, test_a20_long
*
/****************************************************************************
* access_highmem (real mode far call)
*
- * Open up access to high memory in flat real mode with A20 enabled
+ * Open up access to high memory with A20 enabled
*
* Parameters:
* none
access_highmem:
/* Enable A20 line */
call enable_a20
- /* Set up 4GB limits */
- call flatten_real_mode
lret
.size access_highmem, . - access_highmem