Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .globl enter_longmode
- .type enter_longmode,@function
- enter_longmode:
- call 1f
- 1: popl %ebx
- addl $_GLOBAL_OFFSET_TABLE_ + (. - 1b), %ebx
- cli
- inb $0x70, %al
- orb $0x80, %al
- outb %al, $0x70
- movl $exception_handler, %eax
- movl %eax, %edx
- andl $0x0000FFFF, %eax
- orl $0x00180000, %eax
- andl $0xFFFF0000, %edx
- orl $0x00008E00, %edx
- movl $256, %ecx
- movl $idt, %esi
- 1:
- movl %eax, 0(%esi)
- movl %edx, 4(%esi)
- addl $8, %esi
- loopl 1b
- lidt (idtr)
- movl $(tss_end - tss), %ecx
- movl $tss, %edx
- movw %cx, _tss_dsc
- movw %dx, _tss_dsc + 2
- shrl $16, %edx
- movb %dl, _tss_dsc + 4
- movb %dh, _tss_dsc + 7
- lgdt (gdtr)
- ljmp $0x18, $1f
- 1:
- movl $0x10, %eax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %fs
- movw %ax, %gs
- movw %ax, %ss
- movw $0x20, %ax
- ltr %ax
- movl $(1 << 5), %eax
- movl %eax, %cr4
- movl $0xC0000080, %ecx
- rdmsr
- orl $(1 << 8), %eax
- wrmsr
- movl %cr0, %eax
- orl $(1 << 31), %eax
- movl %eax, %cr0
- leal long_exchange@GOTOFF(%ebx), %eax
- lidt (null_idtr)
- ljmp $0x08, $long_mode
- .size enter_longmode, . -enter_longmode
- .section ".rodata", "a"
- .balign 8
- .type null_idtr,@object
- null_idtr:
- .word 0
- .long 0
- .size null_idtr, . - null_idtr
- .balign 8
- .type idtr,@object
- idtr:
- .word idt_end - idt
- .long idt
- .size idtr, . - idtr
- .balign 8
- .type gdtr,@object
- gdtr:
- .word gdt_end - gdt
- .long gdt
- .size gdtr, . - gdtr
- .balign 8
- .type gdt,@object
- gdt:
- .word 0x0000, 0, 0x0000, 0x00
- // 64-bit code segment
- .word 0xFFFF, 0, 0x9A00, 0xAF
- // Data segment
- .word 0xFFFF, 0, 0x9200, 0xAF
- // 32-bit code segment
- .word 0xFFFF, 0, 0x9A00, 0xCF
- // Dummy TSS
- _tss_dsc:
- .word 0x0000, 0x0000, 0x8900, 0x40
- gdt_end:
- .size gdt, . - gdt
- .bss
- .balign 8
- .type tss,@object
- tss:
- .fill 104
- tss_end:
- .size tss, . - tss
- .balign 8
- .type idt,@object
- idt:
- .rept 256
- .quad 0
- .endr
- idt_end:
- .size idt, . - idt
- .code64
- .text
- .balign 16
- .globl long_mode
- .type long_mode,%function
- long_mode:
- xorq %rbx, %rbx
- movl %eax, %ebx
- movq 8(%rbx), %rax
- movq 0(%rbx), %rbx
- jmp *%rbx
- .size long_mode,. - long_mode
- .bss
- .balign 8
- .globl long_exchange
- .type long_exchange,object
- long_exchange:
- .quad 0
- .quad 0
- .size long_exchange,. - long_exchange
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement