1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#include <machine/assembler.h> 8 9.section .boot.text 10 11/* user-level selectors from </arch/mode/object/structures.h> */ 12#define GDT_NULL 0 13#define GDT_CS_0 1 14#define GDT_DS_0 2 15#define GDT_CS_3 3 16#define GDT_DS_3 4 17#define GDT_TSS 5 18#define GDT_FS 6 19#define GDT_GS 7 20#define GDT_ENTRIES 8 21/* user-level selectors from </arch/object/structures.h> */ 22#define SEL_DS_0 (GDT_DS_0 << 3) 23#define SEL_CS_3 ((GDT_CS_3 << 3) | 3) 24#define SEL_DS_3 ((GDT_DS_3 << 3) | 3) 25#define SEL_FS ((GDT_FS << 3) | 3) 26#define SEL_GS ((GDT_GS << 3) | 3) 27 28BEGIN_FUNC(ia32_install_gdt) 29 movl 4(%esp), %eax 30 lgdt (%eax) # load gdtr register with gdt pointer 31 movw $SEL_DS_3, %ax # load register ax with seg selector DS 32 movw %ax, %ds 33 movw %ax, %es 34 movw $SEL_FS, %ax # load register ax with seg selector FS 35 movw %ax, %fs 36 movw $SEL_GS, %ax # load register ax with seg selector GS 37 movw %ax, %gs 38 movw $SEL_DS_0, %ax # load register ax with seg selector for kernel DS 39 movw %ax, %ss 40 ljmp $0x08, $1f # reload kernel CS with a far jump 411: ret 42END_FUNC(ia32_install_gdt) 43 44BEGIN_FUNC(ia32_install_idt) 45 movl 4(%esp), %eax 46 lidt (%eax) 47 ret 48END_FUNC(ia32_install_idt) 49 50BEGIN_FUNC(ia32_install_ldt) 51 lldt 4(%esp) 52 ret 53END_FUNC(ia32_install_ldt) 54 55BEGIN_FUNC(ia32_install_tss) 56 ltr 4(%esp) 57 ret 58END_FUNC(ia32_install_tss) 59 60BEGIN_FUNC(getCacheLineSize) 61 pushl %ebx 62 movl $1, %eax 63 cpuid 64 movl %ebx, %eax 65 shrl $8, %eax 66 andl $0xff, %eax 67 shll $3, %eax 68 popl %ebx 69 ret 70END_FUNC(getCacheLineSize) 71 72.section .text 73 74BEGIN_FUNC(out8) 75 movb 8(%esp), %al 76 movw 4(%esp), %dx 77 outb %al, %dx 78 ret 79END_FUNC(out8) 80 81BEGIN_FUNC(out16) 82 movw 8(%esp), %ax 83 movw 4(%esp), %dx 84 outw %ax, %dx 85 ret 86END_FUNC(out16) 87 88BEGIN_FUNC(out32) 89 movl 8(%esp), %eax 90 movw 4(%esp), %dx 91 outl %eax, %dx 92 ret 93END_FUNC(out32) 94 95BEGIN_FUNC(in8) 96 movw 4(%esp), %dx 97 inb %dx, %al 98 ret 99END_FUNC(in8) 100 101BEGIN_FUNC(in16) 102 movw 4(%esp), %dx 103 inw %dx, %ax 104 ret 105END_FUNC(in16) 106 107BEGIN_FUNC(in32) 108 movw 4(%esp), %dx 109 inl %dx, %eax 110 ret 111END_FUNC(in32) 112