|
@@ -0,0 +1,185 @@
|
|
|
|
|
+/* arch/x86/boot/setup64.S
|
|
|
|
|
+ *
|
|
|
|
|
+ * This file is part of xnix.
|
|
|
|
|
+ *
|
|
|
|
|
+ * XNIX is free software: you can redistribute it and/or modify
|
|
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
|
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
+ * (at your option) any later version.
|
|
|
|
|
+ *
|
|
|
|
|
+ * XNIX is distributed in the hope that it will be useful,
|
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
|
+ *
|
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
|
+ * along with XNIX. If not, see <https://www.gnu.org/licenses/>
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+.code16
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/* switch to the long-mode, and to real system */
|
|
|
|
|
+
|
|
|
|
|
+.globl _start
|
|
|
|
|
+
|
|
|
|
|
+_start: xorw %ax, %ax
|
|
|
|
|
+
|
|
|
|
|
+ movw %ax, %ds
|
|
|
|
|
+ movw %ax, %es
|
|
|
|
|
+ movw %ax, %ss
|
|
|
|
|
+
|
|
|
|
|
+ /* yeah, we should move it again. */
|
|
|
|
|
+ movw $0x7e00, %di
|
|
|
|
|
+ movw $0x8000, %si
|
|
|
|
|
+
|
|
|
|
|
+ movw $512, %cx
|
|
|
|
|
+
|
|
|
|
|
+ cld
|
|
|
|
|
+ rep
|
|
|
|
|
+ movsb
|
|
|
|
|
+
|
|
|
|
|
+ movw $0x7c00, %sp
|
|
|
|
|
+
|
|
|
|
|
+ ljmp $0, $real_start
|
|
|
|
|
+
|
|
|
|
|
+real_start:
|
|
|
|
|
+ /* open a20 */
|
|
|
|
|
+ cli
|
|
|
|
|
+
|
|
|
|
|
+ inb $0x92, %al
|
|
|
|
|
+ orb $0x02, %al
|
|
|
|
|
+ outb %al, $0x92
|
|
|
|
|
+
|
|
|
|
|
+ /* setup gdt */
|
|
|
|
|
+ lgdt gdt32_descr
|
|
|
|
|
+
|
|
|
|
|
+ movl %cr0, %eax
|
|
|
|
|
+ orl $1, %eax
|
|
|
|
|
+
|
|
|
|
|
+ /* that's it! */
|
|
|
|
|
+ movl %eax, %cr0
|
|
|
|
|
+
|
|
|
|
|
+ /* setup paging (for long mode) */
|
|
|
|
|
+
|
|
|
|
|
+ movl $0, %edi
|
|
|
|
|
+ movl $512, %ecx
|
|
|
|
|
+ xorl %eax, %eax
|
|
|
|
|
+
|
|
|
|
|
+ cld
|
|
|
|
|
+
|
|
|
|
|
+rsetpt: rep
|
|
|
|
|
+ stosl
|
|
|
|
|
+
|
|
|
|
|
+ movl $0x00001003, 0
|
|
|
|
|
+ movl $0x00001003, 0x800
|
|
|
|
|
+
|
|
|
|
|
+ movl $0x00002003, 0x1000
|
|
|
|
|
+ movl $0x00003003, 0x2000
|
|
|
|
|
+
|
|
|
|
|
+ movl $0x3000, %edi
|
|
|
|
|
+ movl $0x00000083, %eax
|
|
|
|
|
+
|
|
|
|
|
+rsetp: movl %eax, (%edi)
|
|
|
|
|
+ movl $0, 4(%edi)
|
|
|
|
|
+
|
|
|
|
|
+ addl $8, %edi
|
|
|
|
|
+ addl $4096, %eax
|
|
|
|
|
+
|
|
|
|
|
+ cmpl $0x800000, %eax
|
|
|
|
|
+ jbe rsetp
|
|
|
|
|
+
|
|
|
|
|
+ ljmp $0x08, $init_prot
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+.code32
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+init_prot:
|
|
|
|
|
+ movl $0x10, %eax
|
|
|
|
|
+
|
|
|
|
|
+ movl %eax, %ds
|
|
|
|
|
+ movl %eax, %es
|
|
|
|
|
+ movl %eax, %fs
|
|
|
|
|
+ movl %eax, %gs
|
|
|
|
|
+
|
|
|
|
|
+ movl %eax, %ss
|
|
|
|
|
+
|
|
|
|
|
+ movl $0x7c00, %esp
|
|
|
|
|
+
|
|
|
|
|
+ /* move it to 1mb */
|
|
|
|
|
+
|
|
|
|
|
+ movl $1048576, %edi
|
|
|
|
|
+ movl $0x8200, %esi
|
|
|
|
|
+
|
|
|
|
|
+ movl $131072, %ecx
|
|
|
|
|
+
|
|
|
|
|
+ cld
|
|
|
|
|
+
|
|
|
|
|
+ rep
|
|
|
|
|
+ movsl
|
|
|
|
|
+
|
|
|
|
|
+to_long:
|
|
|
|
|
+ lgdt gdt64_descr
|
|
|
|
|
+
|
|
|
|
|
+ movl $0x000000a0, %eax
|
|
|
|
|
+ movl %eax, %cr4
|
|
|
|
|
+
|
|
|
|
|
+ xorl %eax, %eax
|
|
|
|
|
+ movl %eax, %cr3
|
|
|
|
|
+
|
|
|
|
|
+ movl $0xc0000080, %ecx
|
|
|
|
|
+ rdmsr
|
|
|
|
|
+
|
|
|
|
|
+ orl $0x100, %eax
|
|
|
|
|
+ wrmsr
|
|
|
|
|
+
|
|
|
|
|
+ /* PG and PE */
|
|
|
|
|
+ movl %cr0, %eax
|
|
|
|
|
+ orl $0x80000001, %eax
|
|
|
|
|
+ movl %eax, %cr0
|
|
|
|
|
+
|
|
|
|
|
+ ljmp $0x08, $init_lm
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+.code64
|
|
|
|
|
+
|
|
|
|
|
+init_lm:
|
|
|
|
|
+ movq $0x10, %rax
|
|
|
|
|
+
|
|
|
|
|
+ movq %rax, %ds
|
|
|
|
|
+ movq %rax, %es
|
|
|
|
|
+ movq %rax, %fs
|
|
|
|
|
+ movq %rax, %gs
|
|
|
|
|
+ movq %rax, %ss
|
|
|
|
|
+
|
|
|
|
|
+ movq $0x7c00, %rsp
|
|
|
|
|
+
|
|
|
|
|
+ pushq $1048576
|
|
|
|
|
+ retq
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+.globl gdt32
|
|
|
|
|
+
|
|
|
|
|
+gdt32: .long 0x00000000, 0x00000000
|
|
|
|
|
+ .long 0x0000ffff, 0x00cf9a00
|
|
|
|
|
+ .long 0x0000ffff, 0x00cf9200
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+.globl gdt32_descr
|
|
|
|
|
+
|
|
|
|
|
+gdt32_descr:
|
|
|
|
|
+ .word . - gdt32
|
|
|
|
|
+ .long gdt32
|
|
|
|
|
+
|
|
|
|
|
+gdt64: .quad 0x0000000000000000
|
|
|
|
|
+ .quad 0x0020980000000000
|
|
|
|
|
+ .quad 0x0000920000000000
|
|
|
|
|
+
|
|
|
|
|
+gdt64_descr:
|
|
|
|
|
+ .word . - gdt64
|
|
|
|
|
+ .long gdt64
|
|
|
|
|
+
|