1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * This software may be distributed and modified according to the terms of 5 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 6 * See "LICENSE_GPLv2.txt" for details. 7 * 8 * @TAG(GD_GPL) 9 */ 10 11#include <machine/assembler.h> 12 13.section .boot.text 14 15BEGIN_FUNC(ia32_install_gdt) 16 movl 4(%esp), %eax 17 lgdt (%eax) # load gdtr register with gdt pointer 18 movw $0x10, %ax # load register ax with seg selector for kernel DS 19 movw %ax, %ds 20 movw %ax, %es 21 movw %ax, %ss 22 movw $0x0, %ax 23 movw %ax, %fs 24 movw %ax, %gs 25 ljmp $0x08, $1f # reload kernel CS with a far jump 261: ret 27END_FUNC(ia32_install_gdt) 28 29BEGIN_FUNC(ia32_install_idt) 30 movl 4(%esp), %eax 31 lidt (%eax) 32 ret 33END_FUNC(ia32_install_idt) 34 35BEGIN_FUNC(ia32_install_ldt) 36 lldt 4(%esp) 37 ret 38END_FUNC(ia32_install_ldt) 39 40BEGIN_FUNC(ia32_install_tss) 41 ltr 4(%esp) 42 ret 43END_FUNC(ia32_install_tss) 44 45 46BEGIN_FUNC(ia32_load_fs) 47 movl 4(%esp), %eax 48 movw %ax, %fs 49 ret 50END_FUNC(ia32_load_fs) 51 52BEGIN_FUNC(ia32_load_gs) 53 movl 4(%esp), %eax 54 movw %ax, %gs 55 ret 56END_FUNC(ia32_load_gs) 57 58BEGIN_FUNC(getCacheLineSize) 59 pushl %ebx 60 movl $1, %eax 61 cpuid 62 movl %ebx, %eax 63 shrl $8, %eax 64 andl $0xff, %eax 65 shll $3, %eax 66 popl %ebx 67 ret 68END_FUNC(getCacheLineSize) 69 70.section .text 71 72BEGIN_FUNC(out8) 73 movb 8(%esp), %al 74 movw 4(%esp), %dx 75 outb %al, %dx 76 ret 77END_FUNC(out8) 78 79BEGIN_FUNC(out16) 80 movw 8(%esp), %ax 81 movw 4(%esp), %dx 82 outw %ax, %dx 83 ret 84END_FUNC(out16) 85 86BEGIN_FUNC(out32) 87 movl 8(%esp), %eax 88 movw 4(%esp), %dx 89 outl %eax, %dx 90 ret 91END_FUNC(out32) 92 93BEGIN_FUNC(in8) 94 movw 4(%esp), %dx 95 inb %dx, %al 96 ret 97END_FUNC(in8) 98 99BEGIN_FUNC(in16) 100 movw 4(%esp), %dx 101 inw %dx, %ax 102 ret 103END_FUNC(in16) 104 105BEGIN_FUNC(in32) 106 movw 4(%esp), %dx 107 inl %dx, %eax 108 ret 109END_FUNC(in32) 110