| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- /* arch/x86/boot/setup64.S
- *
- * Copyright (C) 2021, 2022 intirain.
- *
- * 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) */
- /* finally I used the thing that I used, and this is better, I think.
- * initial 2m pages at 0 */
- /* clear them before using */
- xorl %eax, %eax
- xorl %edi, %edi
- movl $4096, %ecx
- cld
- rep stosl
- movl $0x1007, 0
- /* 0xffff800000000000 */
- movl $0x1007, 0x800
- movl $0x2007, 0x1000
- movl $0x000083, 0x2000
- movl $0x200083, 0x2008
- movl $0x400083, 0x2010
- movl $0x600083, 0x2018
- movl $0x800083, 0x2020
- ljmp $8, $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
|