Changeset 3396f59 in mainline


Ignore:
Timestamp:
2005-09-04T08:28:55Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8ff2f3f
Parents:
005384ad
Message:

Fixed gdtr naming issues after ia32 changes.
Fixed stack alignment on new thread to by multiple of 16,
we are now ABI-correct and we do not #GP on va_arg to boot.
Fixed bad exception register names reporting.
Fixed bad _hardcoded_load_addr, which caused allocation of kernel text
frames.

Files:
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • arch/amd64/_link.ld

    r005384ad r3396f59  
    3434                *(.rodata*);            /* string literals */
    3535                hardcoded_load_address = .;
    36                 QUAD(0xffffffff80008000);
     36                QUAD(ktext_start - SIZEOF(.unmapped));
    3737                hardcoded_ktext_size = .;
    3838                QUAD(ktext_end - ktext_start + (unmapped_ktext_end - unmapped_ktext_start));
     
    5656                kdata_end = .;
    5757        }
     58
     59        _hardcoded_kernel_size = (ktext_end - ktext_start) + (unmapped_ktext_end - unmapped_ktext_start) + (kdata_end - kdata_start) + (unmapped_kdata_end - unmapped_kdata_start);
    5860        _boot_offset = 0x100000;
    5961        _ka2pa_offset = 0xffffffff80000000;
    6062        _map_address = _ka2pa_offset + _boot_offset;
    6163
    62         _hardcoded_kernel_size = (ktext_end - ktext_start) + (unmapped_ktext_end - unmapped_ktext_start) + (kdata_end - kdata_start) + (unmapped_kdata_end - unmapped_kdata_start);
    6364
    6465        e820table_boot = e820table - _map_address;
    6566        e820counter_boot = e820counter - _map_address;
    66         ap_bootstrap_gdtr = ap_bootstrap_gdtr_boot + _ka2pa_offset;
     67        real_bootstrap_gdtr = real_bootstrap_gdtr_boot + _ka2pa_offset;
    6768}
  • arch/amd64/include/asm.h

    r005384ad r3396f59  
    141141}
    142142
     143/** Read CR0
     144 *
     145 * Return value in CR0
     146 *
     147 * @return Value read.
     148 */
     149static inline __u64 read_cr0(void)
     150{
     151        __u64 v;
     152        __asm__ volatile ("movq %%cr0,%0" : "=r" (v));
     153        return v;
     154}
     155
    143156/** Read CR2
    144157 *
     
    147160 * @return Value read.
    148161 */
    149 static inline __u64 read_cr2(void) { __u64 v; __asm__ volatile ("movq %%cr2,%0" : "=r" (v)); return v; }
     162static inline __u64 read_cr2(void)
     163{
     164        __u64 v;
     165        __asm__ volatile ("movq %%cr2,%0" : "=r" (v));
     166        return v;
     167}
    150168
    151169/** Write CR3
     
    155173 * @param v Value to be written.
    156174 */
    157 static inline void write_cr3(__u64 v) { __asm__ volatile ("movq %0,%%cr3\n" : : "r" (v)); }
     175static inline void write_cr3(__u64 v)
     176{
     177        __asm__ volatile ("movq %0,%%cr3\n" : : "r" (v));
     178}
    158179
    159180/** Read CR3
     
    163184 * @return Value read.
    164185 */
    165 static inline __u64 read_cr3(void) { __u64 v; __asm__ volatile ("movq %%cr3,%0" : "=r" (v)); return v; }
     186static inline __u64 read_cr3(void)
     187{
     188        __u64 v;
     189        __asm__ volatile ("movq %%cr3,%0" : "=r" (v));
     190        return v;
     191}
    166192
    167193
  • arch/amd64/include/context.h

    r005384ad r3396f59  
    3434#endif
    3535
    36 #define SP_DELTA     8
     36
     37/* According to ABI the stack MUST be aligned on
     38 * 16-byte boundary. If it is not, the va_arg calling will
     39 * panic sooner or later
     40 */
     41#define SP_DELTA     16
    3742
    3843struct context {
  • arch/amd64/include/cpu.h

    r005384ad r3396f59  
    5656extern void set_efer_flag(int flag);
    5757extern __u64 read_efer_flag(void);
     58void cpu_setup_fpu(void);
    5859
    5960#endif /* __ASM__ */
  • arch/amd64/include/cpuid.h

    r005384ad r3396f59  
    3030#define __CPUID_H__
    3131
    32 #define AMD_CPUID_EXTENDED 0x80000001
     32#define AMD_CPUID_EXTENDED   0x80000001
    3333#define AMD_EXT_NOEXECUTE    20
     34
     35#define INTEL_CPUID_STANDARD 0x1
     36#define INTEL_SSE2           26
     37#define INTEL_FXSAVE         24
    3438
    3539#ifndef __ASM__
  • arch/amd64/include/pm.h

    r005384ad r3396f59  
    146146
    147147extern struct ptr_16_64 gdtr;
    148 extern struct ptr_16_32 bsp_bootstrap_gdtr;
    149 extern struct ptr_16_32 ap_bootstrap_gdtr;
     148extern struct ptr_16_32 real_bootstrap_gdtr;
    150149
    151150extern void pm_init(void);
  • arch/amd64/src/amd64.c

    r005384ad r3396f59  
    4444#include <arch/cpuid.h>
    4545#include <arch/acpi/acpi.h>
     46#include <panic.h>
    4647
    4748void arch_pre_mm_init(void)
     
    5051
    5152        cpuid(AMD_CPUID_EXTENDED,&cpuid_s);
    52         if (! (cpuid_s.cpuid_edx & (1<<AMD_EXT_NOEXECUTE))) {
    53                 printf("We do not support NX!!-----------\n");
    54                 printf("%X------\n",cpuid_s.cpuid_edx);
    55                 cpu_halt();
    56         }
     53        if (! (cpuid_s.cpuid_edx & (1<<AMD_EXT_NOEXECUTE)))
     54                panic("Processor does not support No-execute pages.\n");
     55
     56        cpuid(INTEL_CPUID_STANDARD,&cpuid_s);
     57        if (! (cpuid_s.cpuid_edx & (1<<INTEL_FXSAVE)))
     58                panic("Processor does not support FXSAVE/FXRESTORE.\n");
     59       
     60        if (! (cpuid_s.cpuid_edx & (1<<INTEL_SSE2)))
     61                panic("Processor does not support SSE2 instructions.\n");
     62
     63        /* Enable No-execute pages */
    5764        set_efer_flag(AMD_NXE_FLAG);
     65        /* Enable FPU */
     66        cpu_setup_fpu();
    5867
    5968        pm_init();
  • arch/amd64/src/boot/boot.S

    r005384ad r3396f59  
    7171
    7272        # Load gdtr, idtr
    73         lgdt bsp_bootstrap_gdtr
     73        lgdt real_bootstrap_gdtr_boot
    7474       
    7575        movl %cr0,%eax
     
    167167        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    168168
    169 .global gdtr_inst                               
    170 bsp_bootstrap_gdtr:
     169.global real_bootstrap_gdtr_boot
     170real_bootstrap_gdtr_boot:
    171171        .word gdtselector(GDT_ITEMS)
    172172        .long KA2PA(gdt)-BOOT_OFFSET
  • arch/amd64/src/cpu/cpu.c

    r005384ad r3396f59  
    6161};
    6262
     63
     64/** Setup flags on processor so that we can use the FPU
     65 *
     66 * cr0.osfxsr = 1 -> we do support fxstor/fxrestor
     67 * cr0.em = 0 -> we do not emulate coprocessor
     68 * cr0.mp = 1 -> we do want lazy context switch
     69 */
     70void cpu_setup_fpu(void)
     71{
     72        __asm__ volatile (
     73                "movq %%cr0, %%rax;"
     74                "btsq $1, %%rax;" /* cr0.mp */
     75                "btrq $2, %%rax;"  /* cr0.em */
     76                "movq %%rax, %%cr0;"
     77
     78                "movq %%cr4, %%rax;"
     79                "bts $9, %%rax;" /* cr4.osfxsr */
     80                "movq %%rax, %%cr4;"
     81                :
     82                :
     83                :"%rax"
     84                );
     85}
     86
     87/** Set the TS flag to 1.
     88 *
     89 * If a thread accesses coprocessor, exception is run, which
     90 * does a lazy fpu context switch.
     91 *
     92 */
    6393void set_TS_flag(void)
    6494{
    6595        __asm__ volatile (
    6696                "mov %%cr0,%%rax;"
    67                 "or $8,%%rax;"
     97                "bts $3,%%rax;"
    6898                "mov %%rax,%%cr0;"
    6999                :
     
    77107        __asm__ volatile (
    78108                "mov %%cr0,%%rax;"
    79                 "btc $4,%%rax;"
     109                "btr $3,%%rax;"
    80110                "mov %%rax,%%cr0;"
    81111                :
  • arch/amd64/src/fpu_context.c

    r005384ad r3396f59  
    11/*
    2  * Copyright (C) 2005 Martin Decky
     2 * Copyright (C) 2005 Jakub Vana
    33 * All rights reserved.
    44 *
     
    2525 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 *
    2728 */
    2829
    29 #ifndef __amd64_FPU_CONTEXT_H__
    30 #define __amd64_FPU_CONTEXT_H__
     30#include <fpu_context.h>
     31#include <arch.h>
     32#include <cpu.h>
    3133
    32 #include <arch/types.h>
     34void fpu_context_save(fpu_context_t *fctx)
     35{
     36}
    3337
    34 struct fpu_context {
    35 };
     38void fpu_context_restore(fpu_context_t *fctx)
     39{
     40        if(THREAD==CPU->fpu_owner)
     41                reset_TS_flag();
     42        else {
     43                set_TS_flag();
     44                if (CPU->fpu_owner != NULL)
     45                        CPU->fpu_owner->fpu_context_engaged=1;
     46        }
     47}
    3648
    37 #endif
     49
     50void fpu_lazy_context_save(fpu_context_t *fctx)
     51{
     52        /* TODO: We need malloc that allocates on 16-byte boundary !! */
     53        if (((__u64)fctx) & 0xf)
     54                fctx = (fpu_context_t *)((((__u64)fctx) | 0xf) + 1);
     55
     56        __asm__ volatile (
     57                "fxsave %0"
     58                : "=m"(*fctx)
     59                );
     60}
     61
     62void fpu_lazy_context_restore(fpu_context_t *fctx)
     63{
     64        /* TODO: We need malloc that allocates on 16-byte boundary !! */
     65        if (((__u64)fctx) & 0xf)
     66                fctx = (fpu_context_t *)((((__u64)fctx) | 0xf) + 1);
     67        __asm__ volatile (
     68                "fxrstor %0"
     69                : "=m"(*fctx)
     70                );
     71}
     72
     73void fpu_init(void)
     74{
     75        __asm__ volatile (
     76                "fninit;"
     77        );
     78}
  • arch/amd64/src/interrupt.c

    r005384ad r3396f59  
    3838#include <arch.h>
    3939#include <symtab.h>
     40#include <arch/asm.h>
    4041
    41 #define PRINT_INFO_ERRCODE(x) { \
     42#define PRINT_INFO_ERRCODE(n,x) { \
    4243        char *symbol = get_symtab_entry(stack[1]); \
    4344        if (!symbol) \
    4445                symbol = ""; \
    45         printf("----------------EXCEPTION OCCURED----------------\n"); \
     46        printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \
    4647        printf("%%rip: %Q (%s)\n",x[1],symbol); \
    4748        printf("ERROR_WORD=%Q\n", x[0]); \
    48         printf("%%rcs=%Q,flags=%Q\n", x[2], x[3]); \
    49         printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",x[-1],x[-2],x[-3]); \
    50         printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",x[-4],x[-5],x[-6]); \
    51         printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",x[-7],x[-8],x[-9]); \
    52         printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",x[-10],x[-11],x[-12]); \
    53         printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",x[-13],x[-14],x); \
     49        printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", x[2], x[3],read_cr0()); \
     50        printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",x[-2],x[-3],x[-4]); \
     51        printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",x[-5],x[-6],x[-7]); \
     52        printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",x[-8],x[-9],x[-10]); \
     53        printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",x[-11],x[-12],x[-13]); \
     54        printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",x[-14],x[-15],x); \
     55        printf("%%rbp=%Q\n",x[-1]); \
    5456        printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]); \
    5557        printf("       %Q, %Q, %Q\n", x[8], x[9], x[10]); \
     58        printf("       %Q, %Q, %Q\n", x[11], x[12], x[13]); \
     59        printf("       %Q, %Q, %Q\n", x[14], x[15], x[16]); \
     60        printf("       %Q, %Q, %Q\n", x[17], x[18], x[19]); \
     61        printf("       %Q, %Q, %Q\n", x[20], x[21], x[22]); \
     62        printf("       %Q, %Q, %Q\n", x[23], x[24], x[25]); \
    5663        }
    5764
     
    9198void null_interrupt(__u8 n, __native stack[])
    9299{
    93         printf("----------------EXCEPTION OCCURED----------------\n");
    94         printf("int %d: null_interrupt\n", n);
     100        printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \
    95101        printf("stack: %L, %L, %L, %L\n", stack[0], stack[1], stack[2], stack[3]);
    96102        panic("unserviced interrupt\n");
     
    99105void gp_fault(__u8 n, __native stack[])
    100106{
    101         PRINT_INFO_ERRCODE(stack);
     107        PRINT_INFO_ERRCODE(n,stack);
    102108        panic("general protection fault\n");
    103109}
     
    105111void ss_fault(__u8 n, __native stack[])
    106112{
    107         PRINT_INFO_ERRCODE(stack);
     113        PRINT_INFO_ERRCODE(n,stack);
    108114        panic("stack fault\n");
    109115}
     
    113119{
    114120        reset_TS_flag();
    115         if ((CPU->fpu_owner)!=NULL) { 
    116                 fpu_lazy_context_save(&((CPU->fpu_owner)->saved_fpu_context));
    117                 (CPU->fpu_owner)->fpu_context_engaged=0; /* don't prevent migration */
     121        if (CPU->fpu_owner != NULL) { 
     122                fpu_lazy_context_save(&CPU->fpu_owner->saved_fpu_context);
     123                /* don't prevent migration */
     124                CPU->fpu_owner->fpu_context_engaged=0;
    118125        }
    119         if(THREAD->fpu_context_exists) fpu_lazy_context_restore(&(THREAD->saved_fpu_context));
    120         else {fpu_init();THREAD->fpu_context_exists=1;}
     126        if (THREAD->fpu_context_exists)
     127                fpu_lazy_context_restore(&THREAD->saved_fpu_context);
     128        else {
     129                fpu_init();
     130                THREAD->fpu_context_exists=1;
     131        }
    121132        CPU->fpu_owner=THREAD;
    122133}
     
    126137void page_fault(__u8 n, __native stack[])
    127138{
    128         PRINT_INFO_ERRCODE(stack);
     139        PRINT_INFO_ERRCODE(n,stack);
    129140        printf("Page fault address: %Q\n", read_cr2());
    130141        panic("page fault\n");
  • arch/amd64/src/smp/ap.S

    r005384ad r3396f59  
    5555        movw %ax, %ds
    5656
    57         lgdt ap_bootstrap_gdtr_boot     # initialize Global Descriptor Table register
     57        lgdt real_bootstrap_gdtr_boot   # initialize Global Descriptor Table register
    5858       
    5959        movl %cr0, %eax
     
    9797.code64
    9898start64:
    99         movq $ctx, %rax
    100         movq 0(%rax), %rsp
     99        movq (ctx), %rsp
    101100        call main_ap   # never returns
    102101       
    103 .global ap_bootstrap_gdtr_boot
    104 ap_bootstrap_gdtr_boot:
    105         .word gdtselector(GDT_ITEMS)
    106         .long KA2PA(gdt)
    107 
    108102       
    109103#endif /* __SMP__ */
  • arch/ia32/include/fpu_context.h

    r005384ad r3396f59  
    3333
    3434struct fpu_context {
    35         __u8 fpu[512];          /* FXSAVE & FXRSTOR storage area */
     35        /* TODO: We need malloc that aligns structures on 16-byte boundary */
     36        __u8 fpu[512+16];               /* FXSAVE & FXRSTOR storage area */
    3637};
    3738
  • arch/ia32/src/fpu_context.c

    r005384ad r3396f59  
    5555                : "=m"(*fctx)
    5656                );
    57         return;
    5857}
    5958
     
    6463                : "=m"(*fctx)
    6564                );
    66         return;
    6765}
    6866
  • src/build.amd64

    r005384ad r3396f59  
    99set -e
    1010cd ../arch
    11 for a in drivers bios fpu_context.c mm/frame.c mm/tlb.c mm/memory_init.c boot/memmap.S smp/apic.c smp/ipi.c smp/mps.c smp/smp.c acpi; do
     11for a in drivers bios mm/frame.c mm/tlb.c mm/memory_init.c boot/memmap.S smp/apic.c smp/ipi.c smp/mps.c smp/smp.c acpi; do
    1212  if [ \! -e amd64/src/$a ]; then
    1313    echo ln -sf `pwd`/ia32/src/$a amd64/src/$a
     
    1616done
    1717
    18 for a in atomic.h ega.h i8042.h i8259.h i8254.h interrupt.h bios mm/memory_init.h boot/memmap.h boot/memmapasm.h smp acpi; do
     18for a in atomic.h ega.h fpu_context.h i8042.h i8259.h i8254.h interrupt.h bios mm/memory_init.h boot/memmap.h boot/memmapasm.h smp acpi; do
    1919  if [ \! -e amd64/include/$a ]; then
    2020    echo ln -sf `pwd`/ia32/include/$a amd64/include/$a
Note: See TracChangeset for help on using the changeset viewer.