summaryrefslogtreecommitdiff
path: root/arch/x86/lib/realmode_switch.S
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/lib/realmode_switch.S')
-rw-r--r--arch/x86/lib/realmode_switch.S61
1 files changed, 36 insertions, 25 deletions
diff --git a/arch/x86/lib/realmode_switch.S b/arch/x86/lib/realmode_switch.S
index 7ee709a..c4c4c43 100644
--- a/arch/x86/lib/realmode_switch.S
+++ b/arch/x86/lib/realmode_switch.S
@@ -44,12 +44,13 @@
* e40 ss;
*/
-#define a32 .byte 0x67; /* address size prefix 32 */
-#define o32 .byte 0x66; /* operand size prefix 32 */
+#define a32 .byte 0x67; /* address size prefix 32 */
+#define o32 .byte 0x66; /* operand size prefix 32 */
.section .realmode, "ax"
.code16
- /* 16bit protected mode code here */
+
+ /* 16bit protected mode code here */
.globl realmode_enter
realmode_enter:
o32 pusha
@@ -69,20 +70,23 @@ o32 pushf
movw %ax, %gs
lidt realmode_idt_ptr
- movl %cr0, %eax /* Go back into real mode by */
- andl $0x7ffffffe, %eax /* clearing PE to 0 */
+ /* Go back into real mode by clearing PE to 0 */
+ movl %cr0, %eax
+ andl $0x7ffffffe, %eax
movl %eax, %cr0
- ljmp $0x0,$do_realmode /* switch to real mode */
-do_realmode: /* realmode code from here */
+ /* switch to real mode */
+ ljmp $0x0,$do_realmode
+
+do_realmode:
+ /* realmode code from here */
movw %cs,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
- /* create a temporary stack */
-
+ /* create a temporary stack */
movw $0xc0, %ax
movw %ax, %ss
movw $0x200, %ax
@@ -114,26 +118,29 @@ o32 popf
popw %ss
movl %eax, %esp
cs movl temp_eax, %eax
- wbinvd /* self-modifying code,
- * better flush the cache */
+
+ /* self-modifying code, better flush the cache */
+ wbinvd
.byte 0x9a /* lcall */
temp_ip:
.word 0 /* new ip */
temp_cs:
.word 0 /* new cs */
+
realmode_ret:
- /* save eax, esp and ss */
+ /* save eax, esp and ss */
cs movl %eax, saved_eax
movl %esp, %eax
cs movl %eax, saved_esp
movw %ss, %ax
cs movw %ax, saved_ss
- /* restore the stack, note that we set sp to 0x244;
+ /*
+ * restore the stack, note that we set sp to 0x244;
* pt_regs is 0x44 bytes long and we push the structure
- * backwards on to the stack, bottom first */
-
+ * backwards on to the stack, bottom first
+ */
movw $0xc0, %ax
movw %ax, %ss
movw $0x244, %ax
@@ -169,12 +176,15 @@ cs movw temp_ip, %ax
pushl %ebx
o32 cs lidt saved_idt
-o32 cs lgdt saved_gdt /* Set GDTR */
+o32 cs lgdt saved_gdt
- movl %cr0, %eax /* Go back into protected mode */
- orl $1,%eax /* reset PE to 1 */
+ /* Go back into protected mode reset PE to 1 */
+ movl %cr0, %eax
+ orl $1,%eax
movl %eax, %cr0
- jmp next_line /* flush prefetch queue */
+
+ /* flush prefetch queue */
+ jmp next_line
next_line:
movw $return_ptr, %ax
movw %ax,%bp
@@ -182,12 +192,13 @@ o32 cs ljmp *(%bp)
.code32
protected_mode:
- movl $0x18,%eax /* reload GDT[3] */
- movw %ax,%fs /* reset FS */
- movw %ax,%ds /* reset DS */
- movw %ax,%gs /* reset GS */
- movw %ax,%es /* reset ES */
- movw %ax,%ss /* reset SS */
+ /* Reload segment registers */
+ movl $0x18, %eax
+ movw %ax, %fs
+ movw %ax, %ds
+ movw %ax, %gs
+ movw %ax, %es
+ movw %ax, %ss
movl saved_protected_mode_esp, %eax
movl %eax, %esp
popf