Changeset aecf79f in mainline for kernel/arch/xen32/src


Ignore:
Timestamp:
2006-07-24T16:07:15Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c59dd1a2
Parents:
7b0599b
Message:

xen memory initialization

Location:
kernel/arch/xen32/src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/xen32/src/boot/boot.S

    r7b0599b raecf79f  
    3535        .ascii  "GUEST_OS=HelenOS,"
    3636        .ascii  "XEN_VER=xen-3.0,"
    37         .ascii  "HYPERCALL_PAGE=0x0002,"
     37        .ascii  "HYPERCALL_PAGE=0x0000,"
    3838        .ascii  "LOADER=generic,"
    3939        .ascii  "PT_MODE_WRITABLE"
     
    6161        hlt
    6262
     63.section K_TEXT_START, "aw", @progbits
    6364.global hypercall_page
    64 
    65 .org (0x0002 * PAGE_SIZE)
     65.org 0
    6666hypercall_page:
    6767        .space PAGE_SIZE
  • kernel/arch/xen32/src/interrupt.c

    • Property mode changed from 120000 to 100644
    r7b0599b raecf79f  
    1 ../../ia32/src/interrupt.c
     1/*
     2 * Copyright (C) 2006 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** @addtogroup xen32interrupt
     30 * @{
     31 */
     32/** @file
     33 */
     34
     35#include <arch/interrupt.h>
     36#include <syscall/syscall.h>
     37#include <print.h>
     38#include <debug.h>
     39#include <panic.h>
     40#include <func.h>
     41#include <cpu.h>
     42#include <arch/asm.h>
     43#include <mm/tlb.h>
     44#include <mm/as.h>
     45#include <arch.h>
     46#include <symtab.h>
     47#include <proc/thread.h>
     48#include <proc/task.h>
     49#include <synch/spinlock.h>
     50#include <arch/ddi/ddi.h>
     51#include <ipc/sysipc.h>
     52#include <interrupt.h>
     53
     54/*
     55 * Interrupt and exception dispatching.
     56 */
     57
     58void (* disable_irqs_function)(uint16_t irqmask) = NULL;
     59void (* enable_irqs_function)(uint16_t irqmask) = NULL;
     60void (* eoi_function)(void) = NULL;
     61
     62void PRINT_INFO_ERRCODE(istate_t *istate)
     63{
     64        char *symbol = get_symtab_entry(istate->eip);
     65
     66        if (!symbol)
     67                symbol = "";
     68
     69        if (CPU)
     70                printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
     71        else
     72                printf("----------------EXCEPTION OCCURED----------------\n");
     73               
     74        printf("%%eip: %#x (%s)\n",istate->eip,symbol);
     75        printf("ERROR_WORD=%#x\n", istate->error_word);
     76        printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
     77        printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
     78#ifdef CONFIG_DEBUG_ALLREGS
     79        printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
     80#endif
     81        printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
     82        printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
     83}
     84
     85void null_interrupt(int n, istate_t *istate)
     86{
     87        fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
     88
     89        PRINT_INFO_ERRCODE(istate);
     90        panic("unserviced interrupt: %d\n", n);
     91}
     92
     93/** General Protection Fault. */
     94void gp_fault(int n, istate_t *istate)
     95{
     96        if (TASK) {
     97                count_t ver;
     98               
     99                spinlock_lock(&TASK->lock);
     100                ver = TASK->arch.iomapver;
     101                spinlock_unlock(&TASK->lock);
     102       
     103                if (CPU->arch.iomapver_copy != ver) {
     104                        /*
     105                         * This fault can be caused by an early access
     106                         * to I/O port because of an out-dated
     107                         * I/O Permission bitmap installed on CPU.
     108                         * Install the fresh copy and restart
     109                         * the instruction.
     110                         */
     111                        io_perm_bitmap_install();
     112                        return;
     113                }
     114                fault_if_from_uspace(istate, "general protection fault");
     115        }
     116
     117        PRINT_INFO_ERRCODE(istate);
     118        panic("general protection fault\n");
     119}
     120
     121void ss_fault(int n, istate_t *istate)
     122{
     123        fault_if_from_uspace(istate, "stack fault");
     124
     125        PRINT_INFO_ERRCODE(istate);
     126        panic("stack fault\n");
     127}
     128
     129void simd_fp_exception(int n, istate_t *istate)
     130{
     131        uint32_t mxcsr;
     132        asm
     133        (
     134                "stmxcsr %0;\n"
     135                :"=m"(mxcsr)
     136        );
     137        fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zx",
     138                             (unative_t)mxcsr);
     139
     140        PRINT_INFO_ERRCODE(istate);
     141        printf("MXCSR: %#zx\n",(unative_t)(mxcsr));
     142        panic("SIMD FP exception(19)\n");
     143}
     144
     145void nm_fault(int n, istate_t *istate)
     146{
     147#ifdef CONFIG_FPU_LAZY     
     148        scheduler_fpu_lazy_request();
     149#else
     150        fault_if_from_uspace(istate, "fpu fault");
     151        panic("fpu fault");
     152#endif
     153}
     154
     155void syscall(int n, istate_t *istate)
     156{
     157        panic("Obsolete syscall handler.");
     158}
     159
     160void tlb_shootdown_ipi(int n, istate_t *istate)
     161{
     162        trap_virtual_eoi();
     163        tlb_shootdown_ipi_recv();
     164}
     165
     166void trap_virtual_enable_irqs(uint16_t irqmask)
     167{
     168        if (enable_irqs_function)
     169                enable_irqs_function(irqmask);
     170        else
     171                panic("no enable_irqs_function\n");
     172}
     173
     174void trap_virtual_disable_irqs(uint16_t irqmask)
     175{
     176        if (disable_irqs_function)
     177                disable_irqs_function(irqmask);
     178        else
     179                panic("no disable_irqs_function\n");
     180}
     181
     182void trap_virtual_eoi(void)
     183{
     184        if (eoi_function)
     185                eoi_function();
     186        else
     187                panic("no eoi_function\n");
     188
     189}
     190
     191static void ipc_int(int n, istate_t *istate)
     192{
     193        ipc_irq_send_notif(n-IVT_IRQBASE);
     194        trap_virtual_eoi();
     195}
     196
     197
     198/* Reregister irq to be IPC-ready */
     199void irq_ipc_bind_arch(unative_t irq)
     200{
     201        if (irq == IRQ_CLK)
     202                return;
     203        exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int);
     204        trap_virtual_enable_irqs(1 << irq);
     205}
     206
     207/** @}
     208 */
     209
  • kernel/arch/xen32/src/mm/frame.c

    r7b0599b raecf79f  
    5252void frame_arch_init(void)
    5353{
    54         static pfn_t minconf;
    55 
    5654        if (config.cpu_active == 1) {
    57                 minconf = 1;
    58 #ifdef CONFIG_SIMICS_FIX
    59                 minconf = max(minconf, ADDR2PFN(0x10000));
    60 #endif
    61 
    62                 /* Reserve frame 0 (BIOS data) */
    63                 frame_mark_unavailable(0, 1);
     55                pfn_t start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.pt_base), PAGE_SIZE)) + start_info.nr_pt_frames;
     56                size_t size = start_info.nr_pages - start;
    6457               
    65 #ifdef CONFIG_SIMICS_FIX
    66                 /* Don't know why, but these addresses help */
    67                 frame_mark_unavailable(0xd000 >> FRAME_WIDTH,3);
    68 #endif
     58                zone_create(start, size, start, 0);
     59                last_frame = start + size;
    6960        }
    7061}
  • kernel/arch/xen32/src/mm/page.c

    r7b0599b raecf79f  
    7878}
    7979
    80 
    81 uintptr_t hw_map(uintptr_t physaddr, size_t size)
    82 {
    83         if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
    84                 panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
    85        
    86         uintptr_t virtaddr = PA2KA(last_frame);
    87         pfn_t i;
    88         for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
    89                 page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE);
    90        
    91         last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
    92        
    93         return virtaddr;
    94 }
    95 
    9680void page_fault(int n, istate_t *istate)
    9781{
    98         uintptr_t page;
     82        uintptr_t page;
    9983        pf_access_t access;
    10084       
    101         page = read_cr2();
    102                
    103         if (istate->error_word & PFERR_CODE_RSVD)
     85        page = read_cr2();
     86       
     87        if (istate->error_word & PFERR_CODE_RSVD)
    10488                panic("Reserved bit set in page directory.\n");
    105 
     89       
    10690        if (istate->error_word & PFERR_CODE_RW)
    10791                access = PF_ACCESS_WRITE;
    10892        else
    10993                access = PF_ACCESS_READ;
    110 
    111         if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
     94       
     95        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
    11296                fault_if_from_uspace(istate, "Page fault: %#x", page);
    113 
    114                 PRINT_INFO_ERRCODE(istate);
    115                 printf("page fault address: %#x\n", page);
    116                 panic("page fault\n");
    117         }
     97               
     98                PRINT_INFO_ERRCODE(istate);
     99                printf("page fault address: %#x\n", page);
     100                panic("page fault\n");
     101        }
    118102}
    119103
  • kernel/arch/xen32/src/pm.c

    r7b0599b raecf79f  
    7474        /* TLS descriptor */
    7575        { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 },
    76         /* VESA Init descriptor */
    77 #ifdef CONFIG_FB
    78         { 0xffff, 0, VESA_INIT_SEGMENT>>12, AR_PRESENT | AR_CODE | DPL_KERNEL, 0xf, 0, 0, 0, 0, 0 }
    79 #endif 
    8076};
    8177
     
    153149static void clean_IOPL_NT_flags(void)
    154150{
    155         __asm__ volatile (
    156                 "pushfl\n"
    157                 "pop %%eax\n"
    158                 "and $0xffff8fff, %%eax\n"
    159                 "push %%eax\n"
    160                 "popfl\n"
    161                 : : : "eax"
    162         );
     151//      __asm__ volatile (
     152//              "pushfl\n"
     153//              "pop %%eax\n"
     154//              "and $0xffff8fff, %%eax\n"
     155//              "push %%eax\n"
     156//              "popfl\n"
     157//              : : : "eax"
     158//      );
    163159}
    164160
     
    166162static void clean_AM_flag(void)
    167163{
    168         __asm__ volatile (
    169                 "mov %%cr0, %%eax\n"
    170                 "and $0xfffbffff, %%eax\n"
    171                 "mov %%eax, %%cr0\n"
    172                 : : : "eax"
    173         );
     164//      __asm__ volatile (
     165//              "mov %%cr0, %%eax\n"
     166//              "and $0xfffbffff, %%eax\n"
     167//              "mov %%eax, %%cr0\n"
     168//              : : : "eax"
     169//      );
    174170}
    175171
     
    184180        idtr.limit = sizeof(idt);
    185181        idtr.base = (uintptr_t) idt;
    186         gdtr_load(&gdtr);
    187         idtr_load(&idtr);
     182//      gdtr_load(&gdtr);
     183//      idtr_load(&idtr);
    188184       
    189185        /*
     
    192188         */
    193189
    194         if (config.cpu_active == 1) {
    195                 idt_init();
    196                 /*
    197                  * NOTE: bootstrap CPU has statically allocated TSS, because
    198                  * the heap hasn't been initialized so far.
    199                  */
     190//      if (config.cpu_active == 1) {
     191//              idt_init();
     192//              /*
     193//               * NOTE: bootstrap CPU has statically allocated TSS, because
     194//               * the heap hasn't been initialized so far.
     195//               */
    200196                tss_p = &tss;
    201         }
    202         else {
    203                 tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC);
    204                 if (!tss_p)
    205                         panic("could not allocate TSS\n");
    206         }
    207 
    208         tss_initialize(tss_p);
     197//      }
     198//      else {
     199//              tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC);
     200//              if (!tss_p)
     201//                      panic("could not allocate TSS\n");
     202//      }
     203
     204//      tss_initialize(tss_p);
    209205       
    210206        gdt_p[TSS_DES].access = AR_PRESENT | AR_TSS | DPL_KERNEL;
     
    219215         * to its own TSS. We just need to load the TR register.
    220216         */
    221         tr_load(selector(TSS_DES));
     217//      tr_load(selector(TSS_DES));
    222218       
    223219        clean_IOPL_NT_flags();    /* Disable I/O on nonprivileged levels and clear NT flag. */
  • kernel/arch/xen32/src/smp/smp.c

    r7b0599b raecf79f  
    5454#include <print.h>
    5555#include <memstr.h>
    56 #include <arch/drivers/i8259.h>
    5756
    5857#ifdef CONFIG_SMP
     
    119118        outb(0x71,0xa);
    120119
    121         pic_disable_irqs(0xffff);
     120//      pic_disable_irqs(0xffff);
    122121        apic_init();
    123122
  • kernel/arch/xen32/src/xen32.c

    r7b0599b raecf79f  
    4040#include <arch/pm.h>
    4141
    42 #include <arch/drivers/ega.h>
    43 #include <arch/drivers/vesa.h>
    44 #include <genarch/i8042/i8042.h>
    45 #include <arch/drivers/i8254.h>
    46 #include <arch/drivers/i8259.h>
     42#include <arch/drivers/xconsole.h>
    4743
    4844#include <arch/context.h>
     
    6864void arch_pre_mm_init(void)
    6965{
    70 //      pm_init();
     66        pm_init();
    7167
    7268        if (config.cpu_active == 1) {
    7369//              bios_init();
    74 //              i8259_init();   /* PIC */
    75 //              i8254_init();   /* hard clock */
    7670               
    7771//              exc_register(VECTOR_SYSCALL, "syscall", (iroutine) syscall);
     
    8781{
    8882        if (config.cpu_active == 1) {
    89 
    90 #ifdef CONFIG_FB
    91                 if (vesa_present())
    92                         vesa_init();
    93                 else
    94 #endif
    95                         ega_init();     /* video */
    96                
    97                
     83                /* video */
     84                xen_console_init();
    9885                /* Enable debugger */
    9986                debugger_init();
     
    116103void arch_post_smp_init(void)
    117104{
    118         i8042_init();   /* keyboard controller */
    119105}
    120106
    121107void calibrate_delay_loop(void)
    122108{
    123         i8254_calibrate_delay_loop();
     109//      i8254_calibrate_delay_loop();
    124110        if (config.cpu_active == 1) {
    125111                /*
     
    127113                 * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
    128114                 */
    129                 i8254_normal_operation();
     115//              i8254_normal_operation();
    130116        }
    131117}
     
    149135void arch_grab_console(void)
    150136{
    151         i8042_grab();
    152137}
     138
    153139/** Return console to userspace
    154140 *
     
    156142void arch_release_console(void)
    157143{
    158         i8042_release();
    159144}
    160145
Note: See TracChangeset for help on using the changeset viewer.