Ignore:
File:
1 edited

Legend:

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

    r4a5ba372 r36df4109  
    3434
    3535#include <arch.h>
     36#include <arch/arch.h>
    3637#include <typedefs.h>
    3738#include <errno.h>
     
    4950#include <genarch/drivers/ega/ega.h>
    5051#include <genarch/drivers/i8042/i8042.h>
     52#include <genarch/drivers/ns16550/ns16550.h>
    5153#include <genarch/drivers/legacy/ia32/io.h>
    5254#include <genarch/fb/bfb.h>
    5355#include <genarch/kbrd/kbrd.h>
     56#include <genarch/srln/srln.h>
    5457#include <genarch/multiboot/multiboot.h>
    5558#include <genarch/multiboot/multiboot2.h>
     59#include <arch/pm.h>
     60#include <arch/vreg.h>
     61#include <arch/kseg.h>
    5662
    5763#ifdef CONFIG_SMP
     
    5965#endif
    6066
    61 /** Disable I/O on non-privileged levels
    62  *
    63  * Clean IOPL(12,13) and NT(14) flags in EFLAGS register
    64  */
    65 static 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  */
    81 static 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 }
     67static void amd64_pre_mm_init(void);
     68static void amd64_post_mm_init(void);
     69static void amd64_post_cpu_init(void);
     70static void amd64_pre_smp_init(void);
     71static void amd64_post_smp_init(void);
     72
     73arch_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
     81arch_ops_t *arch_ops = &amd64_ops;
    9082
    9183/** Perform amd64-specific initialization before main_bsp() is called.
     
    9587 *
    9688 */
    97 void arch_pre_main(uint32_t signature, void *info)
     89void amd64_pre_main(uint32_t signature, void *info)
    9890{
    9991        /* Parse multiboot information obtained from the bootloader. */
     
    108100}
    109101
    110 void arch_pre_mm_init(void)
     102void amd64_pre_mm_init(void)
    111103{
    112104        /* Enable no-execute pages */
    113         set_efer_flag(AMD_NXE_FLAG);
     105        write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_NXE);
    114106        /* Enable FPU */
    115107        cpu_setup_fpu();
     
    118110        pm_init();
    119111       
    120         /* Disable I/O on nonprivileged levels
    121          * clear the NT (nested-thread) flag
    122          */
    123         clean_IOPL_NT_flags();
     112        /* Disable I/O on nonprivileged levels, clear the nested-thread flag */
     113        write_rflags(read_rflags() & ~(RFLAGS_IOPL | RFLAGS_NT));
    124114        /* Disable alignment check */
    125         clean_AM_flag();
     115        write_cr0(read_cr0() & ~CR0_AM);
    126116       
    127117        if (config.cpu_active == 1) {
     
    134124}
    135125
    136 
    137 void arch_post_mm_init(void)
    138 {
     126void amd64_post_mm_init(void)
     127{
     128        vreg_init();
     129        kseg_init();
     130
    139131        if (config.cpu_active == 1) {
    140132                /* Initialize IRQ routing */
     
    168160}
    169161
    170 void arch_post_cpu_init()
     162void amd64_post_cpu_init(void)
    171163{
    172164#ifdef CONFIG_SMP
     
    178170}
    179171
    180 void arch_pre_smp_init(void)
     172void amd64_pre_smp_init(void)
    181173{
    182174        if (config.cpu_active == 1) {
     
    187179}
    188180
    189 void arch_post_smp_init(void)
     181void amd64_post_smp_init(void)
    190182{
    191183        /* Currently the only supported platform for amd64 is 'pc'. */
     
    212204        }
    213205#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
    214237       
    215238        if (irqs_info != NULL)
     
    229252}
    230253
    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  */
    239 sysarg_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 
    247254/** Construct function pointer
    248255 *
Note: See TracChangeset for help on using the changeset viewer.