Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/amd64.c

    r36df4109 r4a5ba372  
    3434
    3535#include <arch.h>
    36 #include <arch/arch.h>
    3736#include <typedefs.h>
    3837#include <errno.h>
     
    5049#include <genarch/drivers/ega/ega.h>
    5150#include <genarch/drivers/i8042/i8042.h>
    52 #include <genarch/drivers/ns16550/ns16550.h>
    5351#include <genarch/drivers/legacy/ia32/io.h>
    5452#include <genarch/fb/bfb.h>
    5553#include <genarch/kbrd/kbrd.h>
    56 #include <genarch/srln/srln.h>
    5754#include <genarch/multiboot/multiboot.h>
    5855#include <genarch/multiboot/multiboot2.h>
    59 #include <arch/pm.h>
    60 #include <arch/vreg.h>
    61 #include <arch/kseg.h>
    6256
    6357#ifdef CONFIG_SMP
     
    6559#endif
    6660
    67 static void amd64_pre_mm_init(void);
    68 static void amd64_post_mm_init(void);
    69 static void amd64_post_cpu_init(void);
    70 static void amd64_pre_smp_init(void);
    71 static void amd64_post_smp_init(void);
    72 
    73 arch_ops_t amd64_ops = {
    74         .pre_mm_init = amd64_pre_mm_init,
    75         .post_mm_init = amd64_post_mm_init,
    76         .post_cpu_init = amd64_post_cpu_init,
    77         .pre_smp_init = amd64_pre_smp_init,
    78         .post_smp_init = amd64_post_smp_init
    79 };
    80 
    81 arch_ops_t *arch_ops = &amd64_ops;
     61/** Disable I/O on non-privileged levels
     62 *
     63 * Clean IOPL(12,13) and NT(14) flags in EFLAGS register
     64 */
     65static void clean_IOPL_NT_flags(void)
     66{
     67        asm volatile (
     68                "pushfq\n"
     69                "pop %%rax\n"
     70                "and $~(0x7000), %%rax\n"
     71                "pushq %%rax\n"
     72                "popfq\n"
     73                ::: "%rax"
     74        );
     75}
     76
     77/** Disable alignment check
     78 *
     79 * Clean AM(18) flag in CR0 register
     80 */
     81static void clean_AM_flag(void)
     82{
     83        asm volatile (
     84                "mov %%cr0, %%rax\n"
     85                "and $~(0x40000), %%rax\n"
     86                "mov %%rax, %%cr0\n"
     87                ::: "%rax"
     88        );
     89}
    8290
    8391/** Perform amd64-specific initialization before main_bsp() is called.
     
    8795 *
    8896 */
    89 void amd64_pre_main(uint32_t signature, void *info)
     97void arch_pre_main(uint32_t signature, void *info)
    9098{
    9199        /* Parse multiboot information obtained from the bootloader. */
     
    100108}
    101109
    102 void amd64_pre_mm_init(void)
     110void arch_pre_mm_init(void)
    103111{
    104112        /* Enable no-execute pages */
    105         write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_NXE);
     113        set_efer_flag(AMD_NXE_FLAG);
    106114        /* Enable FPU */
    107115        cpu_setup_fpu();
     
    110118        pm_init();
    111119       
    112         /* Disable I/O on nonprivileged levels, clear the nested-thread flag */
    113         write_rflags(read_rflags() & ~(RFLAGS_IOPL | RFLAGS_NT));
     120        /* Disable I/O on nonprivileged levels
     121         * clear the NT (nested-thread) flag
     122         */
     123        clean_IOPL_NT_flags();
    114124        /* Disable alignment check */
    115         write_cr0(read_cr0() & ~CR0_AM);
     125        clean_AM_flag();
    116126       
    117127        if (config.cpu_active == 1) {
     
    124134}
    125135
    126 void amd64_post_mm_init(void)
    127 {
    128         vreg_init();
    129         kseg_init();
    130 
     136
     137void arch_post_mm_init(void)
     138{
    131139        if (config.cpu_active == 1) {
    132140                /* Initialize IRQ routing */
     
    160168}
    161169
    162 void amd64_post_cpu_init(void)
     170void arch_post_cpu_init()
    163171{
    164172#ifdef CONFIG_SMP
     
    170178}
    171179
    172 void amd64_pre_smp_init(void)
     180void arch_pre_smp_init(void)
    173181{
    174182        if (config.cpu_active == 1) {
     
    179187}
    180188
    181 void amd64_post_smp_init(void)
     189void arch_post_smp_init(void)
    182190{
    183191        /* Currently the only supported platform for amd64 is 'pc'. */
     
    204212        }
    205213#endif
    206 
    207 #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
    208         /*
    209          * Initialize the ns16550 controller.
    210          */
    211 #ifdef CONFIG_NS16550_OUT
    212         outdev_t *ns16550_out;
    213         outdev_t **ns16550_out_ptr = &ns16550_out;
    214 #else
    215         outdev_t **ns16550_out_ptr = NULL;
    216 #endif
    217         ns16550_instance_t *ns16550_instance
    218             = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,
    219             ns16550_out_ptr);
    220         if (ns16550_instance) {
    221 #ifdef CONFIG_NS16550
    222                 srln_instance_t *srln_instance = srln_init();
    223                 if (srln_instance) {
    224                         indev_t *sink = stdin_wire();
    225                         indev_t *srln = srln_wire(srln_instance, sink);
    226                         ns16550_wire(ns16550_instance, srln);
    227                         trap_virtual_enable_irqs(1 << IRQ_NS16550);
    228                 }
    229 #endif
    230 #ifdef CONFIG_NS16550_OUT
    231                 if (ns16550_out) {
    232                         stdout_wire(ns16550_out);
    233                 }
    234 #endif
    235         }
    236 #endif
    237214       
    238215        if (irqs_info != NULL)
     
    252229}
    253230
     231/** Set thread-local-storage pointer
     232 *
     233 * TLS pointer is set in FS register. Unfortunately the 64-bit
     234 * part can be set only in CPL0 mode.
     235 *
     236 * The specs say, that on %fs:0 there is stored contents of %fs register,
     237 * we need not to go to CPL0 to read it.
     238 */
     239sysarg_t sys_tls_set(uintptr_t addr)
     240{
     241        THREAD->arch.tls = addr;
     242        write_msr(AMD_MSR_FS, addr);
     243       
     244        return EOK;
     245}
     246
    254247/** Construct function pointer
    255248 *
Note: See TracChangeset for help on using the changeset viewer.