| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /* arch/x86/init/head64.S
- *
- * This file is part of evx.
- *
- * evx 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.
- *
- * evx 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 evx. If not, see <https://www.gnu.org/licenses/>
- */
- .code64
- .globl _start
- _start:
- /* we are now in the long-mode, just
- * do some initializes, and call main */
- call setup_stack
- call init_gdt
- call setup_paging
- movq $0xffff800000000000, %rax
- leaq 1f(%rip), %rcx
- orq %rcx, %rax
- pushq %rax
- movq $0xffff800000000000, %rax
- leaq init(%rip), %rcx
- orq %rcx, %rax
- pushq %rax
- retq
- 1: hlt
- jmp 1b
- init_gdt:
- lgdt gdt_descr(%rip)
- movq $0x10, %rax
- movq %rax, %ds
- movq %rax, %es
- movq %rax, %fs
- movq %rax, %gs
- movq %rax, %ss
- ret
- setup_stack:
- /* `setup_paging` used 0~0x80000, so we must
- * find a new space for stack (old stack at 0x7c00).
- *
- * but sadly, we can't use address above 1048576 because
- * the `arch_mm_init` will use them as the page and zone
- * structures. so, would you like to use someplace in
- * .data? :-) */
- movq (%rsp), %rax
- movq $0x90000, %rsp
- jmp *%rax
- setup_paging:
- /* setup pde, and reload segment registers */
- movq $3, %rax
- movq $0x3000, %rdi
- cld
- rspde: stosq
- addq $4096, %rax
- cmpq $0x80000, %rdi
- jbe rspde
- /* now pdpte */
-
- movq $0x3003, %rax
- movq $0x2000, %rdi
- rsppdp: stosq
- addq $4096, %rax
- cmpq $0x80003, %rax
- jbe rsppdp
- xorq %rax, %rax
- movq %rax, %cr3
- ret
-
- .data
- .align 16
- .globl gdt
- gdt: .quad 0x0000000000000000
- .quad 0x0020980000000000
- .quad 0x0000920000000000
- .globl gdt_descr
- gdt_descr:
- .word . - gdt
- .quad gdt
- .globl idt
- idt: .fill 512, 8, 0
- idt_descr:
- .word . - idt
- .quad idt
- .data
|