Changeset 89344d85 in mainline


Ignore:
Timestamp:
2005-09-03T00:19:23Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36b209a
Parents:
e4a6dda
Message:

Changes, that were needed to make it work on Bochs.

  • We CAN use the NX bit in paging tables, but we have

to initialize the NXE bit in EFER register first.

Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/Makefile.inc

    re4a6dda r89344d85  
    3434        arch/asm_utils.S \
    3535        arch/fmath.c \
    36         arch/mm/memory_init.c
     36        arch/mm/memory_init.c \
     37        arch/cpu/cpu.c
  • arch/amd64/include/cpu.h

    re4a6dda r89344d85  
    3030#define __amd64_CPU_H__
    3131
    32 #include <config.h>
    33 #include <proc/thread.h>
     32
     33#define EFER_MSR_NUM    0xc0000080
     34#define AMD_SCE_FLAG    0
     35#define AMD_LME_FLAG    8
     36#define AMD_LMA_FLAG    10
     37#define AMD_FFXSR_FLAG  14
     38#define AMD_NXE_FLAG    11
     39
     40#ifndef __ASM__
     41
    3442#include <typedefs.h>
    3543#include <arch/pm.h>
    36 #include <arch/asm.h>
    3744
    3845struct cpu_arch {
     
    4552
    4653
    47 void set_TS_flag(void);
    48 void reset_TS_flag(void);
     54extern void set_TS_flag(void);
     55extern void reset_TS_flag(void);
     56extern void set_efer_flag(int flag);
     57extern __u64 read_efer_flag(void);
     58
     59#endif /* __ASM__ */
    4960
    5061#endif
  • arch/amd64/include/cpuid.h

    re4a6dda r89344d85  
    3232#include <arch/types.h>
    3333
     34#define AMD_CPUID_EXTENDED 0x80000001
     35#define AMD_EXT_NOEXECUTE    20
     36
    3437struct cpu_info {
    3538        __u32 cpuid_eax;
     
    4144extern int has_cpuid(void);
    4245
    43 static inline void cpuid(__u32 cmd, cpu_info_t *info)
    44 {
    45         __asm__ (
    46                 "movl %1, %eax"
    47                 "cpuid"
    48                 "movl %eax, 0(%0)"
    49                 "movl %ebx, 4(%0)"
    50                 "movl %ecx, 8(%0)"
    51                 "movl %edx, 12(%0)"
    52                 : "=m"(info)
    53                 : "r"(cmd)
    54                 : "%eax","%ebx","%ecx","%edx"
    55                 );
    56 }
     46extern void cpuid(__u32 cmd, cpu_info_t *info);
     47
    5748
    5849extern __u64 rdtsc(void);
  • arch/amd64/include/mm/page.h

    re4a6dda r89344d85  
    4343#else
    4444# define KA2PA(x)      ((x) + 0x80000000)
    45 //# define PA2KA(x)      ((x)) - 0x80000000)
     45# define PA2KA(x)      ((x) - 0x80000000)
    4646#endif
    4747
  • arch/amd64/src/amd64.c

    re4a6dda r89344d85  
    4040#include <arch/bios/bios.h>
    4141#include <arch/mm/memory_init.h>
     42#include <arch/cpu.h>
     43#include <print.h>
     44#include <arch/cpuid.h>
    4245
    4346void arch_pre_mm_init(void)
    4447{
     48        struct cpu_info cpuid_s;
     49
     50        cpuid(AMD_CPUID_EXTENDED,&cpuid_s);
     51        if (! (cpuid_s.cpuid_edx & (1<<AMD_EXT_NOEXECUTE))) {
     52                printf("We do not support NX!!-----------\n");
     53                printf("%X------\n",cpuid_s.cpuid_edx);
     54                cpu_halt();
     55        }
     56        set_efer_flag(AMD_NXE_FLAG);
     57
    4558        pm_init();
    4659
  • arch/amd64/src/asm_utils.S

    re4a6dda r89344d85  
    4040.global interrupt_handlers
    4141.global panic_printf
     42.global cpuid
    4243
    4344panic_printf:
     
    4748.global has_cpuid
    4849.global rdtsc
    49 
    50 
     50.global read_efer_flag
     51.global set_efer_flag
     52       
    5153## Determine CPUID support
    5254#
     
    7173        ret
    7274
     75cpuid:
     76        movq %rbx, %r10  # we have to preserve rbx across function calls
     77
     78        movl %edi,%eax  # load the command into %eax
     79
     80        cpuid   
     81        movl %eax,0(%rsi)
     82        movl %ebx,4(%rsi)
     83        movl %ecx,8(%rsi)
     84        movl %edx,12(%rsi)
     85
     86        movq %r10, %rbx
     87        ret
    7388
    7489rdtsc:
     
    7691        rdtsc
    7792        ret
    78        
     93
     94set_efer_flag:
     95        movq $0xc0000080, %rcx
     96        rdmsr
     97        btsl %edi, %eax
     98        wrmsr
     99        ret
     100       
     101read_efer_flag:
     102        movq $0xc0000080, %rcx
     103        rdmsr
     104        ret             
    79105
    80106# Push all general purpose registers on stack except %rbp, %rsp
  • arch/amd64/src/boot/boot.S

    re4a6dda r89344d85  
    3232#include <arch/mm/ptl.h>
    3333#include <arch/pm.h>
     34#include <arch/cpu.h>
    3435
    3536#define START_STACK     0x7c00 
     
    102103               
    103104        # Enable long mode
    104         movl $0xc0000080, %ecx   # EFER MSR number
     105        movl $EFER_MSR_NUM, %ecx   # EFER MSR number
    105106        rdmsr                   # Read EFER
    106         btsl $8, %eax            # Set LME=1
     107        btsl $AMD_LME_FLAG, %eax            # Set LME=1
    107108        wrmsr                   # Write EFER
    108109       
  • arch/amd64/src/dummy.s

    re4a6dda r89344d85  
    3636.global cpu_print_report
    3737.global dummy
    38 .global reset_TS_flag
    3938.global fpu_init
    4039       
     
    4544cpu_sleep:
    4645cpu_print_report:
    47 reset_TS_flag:
    4846fpu_init:
    4947       
  • include/cpu.h

    re4a6dda r89344d85  
    7575
    7676extern void cpu_init(void);
    77 extern void cpu_halt(void);
    7877
    7978extern void cpu_arch_init(void);
  • src/mm/page.c

    re4a6dda r89344d85  
    8484                memsetb(newpt, PAGE_SIZE, 0);
    8585                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    86                 SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER);
     86                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC);
    8787        }
    8888
     
    9393                memsetb(newpt, PAGE_SIZE, 0);
    9494                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    95                 SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER);
     95                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC);
    9696        }
    9797
     
    102102                memsetb(newpt, PAGE_SIZE, 0);
    103103                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    104                 SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER);
     104                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC);
    105105        }
    106106
Note: See TracChangeset for help on using the changeset viewer.