Changeset 46
- Timestamp:
- Jun 23, 2017, 1:31:23 PM (8 years ago)
- Location:
- trunk/hal/x86_64
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/hal_cpu.S
r35 r46 39 39 ret 40 40 41 ASM_ENTRY(rdmsr) 42 movq %rdi,%rcx 43 xorq %rax,%rax 44 rdmsr 45 shlq $32,%rdx 46 orq %rdx,%rax 47 ret 48 49 ASM_ENTRY(wrmsr) 50 movq %rdi,%rcx 51 movq %rsi,%rax 52 movq %rsi,%rdx 53 shrq $32,%rdx 54 wrmsr 55 ret 56 -
trunk/hal/x86_64/hal_init.c
r45 r46 47 47 uint8_t mb_mmap[PAGE_SIZE] __in_kdata; 48 48 49 #define offsetof(type, member) __builtin_offsetof(type, member)50 51 49 /* -------------------------------------------------------------------------- */ 52 50 … … 59 57 60 58 if (!(mb_info.mi_flags & MULTIBOOT_INFO_HAS_MMAP)) 61 x86_p rintf("SHIT!!\n");59 x86_panic("No mmap"); 62 60 63 61 i = 0; … … 104 102 x86_printf("[+] hal_gpt_bootstrap_reset called\n"); 105 103 106 hal_init_lapic(); 107 x86_printf("[+] hal_init_lapic called\n"); 104 hal_lapic_init(); 105 x86_printf("[+] hal_lapic_init called\n"); 106 107 hal_tls_init_cpu0(); 108 x86_printf("[+] hal_tls_init_cpu0 called\n"); 108 109 109 110 x86_printf("-> mytest = %z\n", mytest); … … 232 233 SDT_SYS386IGT, SEL_KPL, GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL)); 233 234 } 234 235 235 } 236 236 -
trunk/hal/x86_64/hal_internal.h
r45 r46 20 20 */ 21 21 22 #define offsetof(type, member) __builtin_offsetof(type, member) 22 23 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 23 24 #define rounddown(x,y) (((x)/(y))*(y)) … … 30 31 /* hal_cpu.S */ 31 32 void invlpg(vaddr_t va); 33 uint64_t rdmsr(uint32_t); 34 void wrmsr(uint32_t, uint64_t); 32 35 33 36 /* hal_gpt.c */ … … 41 44 void hal_gpt_init(paddr_t firstpa); 42 45 46 /* hal_special.c */ 47 void hal_tls_init_cpu0(); 48 43 49 /* x86_printf.c */ 44 50 void x86_panic(char *msg); -
trunk/hal/x86_64/hal_lapic.c
r45 r46 37 37 vaddr_t lapic_va __in_kdata = 0; 38 38 39 void lapic_write(uint32_t reg, uint32_t val)39 void hal_lapic_write(uint32_t reg, uint32_t val) 40 40 { 41 41 *((volatile uint32_t *)(lapic_va + reg)) = val; 42 42 } 43 43 44 uint32_t lapic_read(uint32_t reg)44 uint32_t hal_lapic_read(uint32_t reg) 45 45 { 46 46 return *((volatile uint32_t *)(lapic_va + reg)); 47 47 } 48 48 49 void hal_init_lapic()49 uint32_t hal_lapic_gid() 50 50 { 51 uint32_t id; 51 return hal_lapic_read(LAPIC_ID) >> LAPIC_ID_SHIFT; 52 } 52 53 54 void hal_lapic_init() 55 { 53 56 lapic_va = hal_gpt_bootstrap_valloc(1); // XXX: should be shared 54 57 55 58 hal_gpt_enter(lapic_va, lapic_pa); 56 59 57 lapic_write(LAPIC_TPR, 0); 58 lapic_write(LAPIC_SVR, LAPIC_SVR_ENABLE|LAPIC_SPURIOUS_VECTOR); 59 60 id = lapic_read(LAPIC_ID) >> LAPIC_ID_SHIFT; 61 62 x86_printf("-> LAPIC id: %d\n", id); 60 hal_lapic_write(LAPIC_TPR, 0); 61 hal_lapic_write(LAPIC_SVR, LAPIC_SVR_ENABLE|LAPIC_SPURIOUS_VECTOR); 63 62 } 64 63 -
trunk/hal/x86_64/hal_lapic.h
r45 r46 20 20 */ 21 21 22 void hal_init_lapic(); 22 uint32_t hal_lapic_gid(); 23 void hal_lapic_init(); 23 24 24 25 #define LAPIC_SPURIOUS_VECTOR LAPICVEC_MIN -
trunk/hal/x86_64/hal_register.h
r29 r46 72 72 #define EFER_TCE 0x00008000 /* Translation Cache Ext. */ 73 73 74 #define MSR_STAR 0xc0000081 /* 32 bit syscall gate addr */ 75 #define MSR_LSTAR 0xc0000082 /* 64 bit syscall gate addr */ 76 #define MSR_CSTAR 0xc0000083 /* compat syscall gate addr */ 77 #define MSR_SFMASK 0xc0000084 /* flags to clear on syscall */ 78 79 #define MSR_FSBASE 0xc0000100 /* 64bit offset for fs: */ 80 #define MSR_GSBASE 0xc0000101 /* 64bit offset for gs: */ 81 #define MSR_KERNELGSBASE 0xc0000102 /* storage for swapgs ins */ 82 -
trunk/hal/x86_64/hal_special.c
r25 r46 1 1 /* 2 * hal_special.c - implementation of Generic Special Register Access API for TSAR-MIPS322 * hal_special.c - implementation of TLS API for x86_64 3 3 * 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016) 4 * Copyright (c) 2017 Maxime Villard 5 * 6 * This file is part of ALMOS-MKH. 6 7 * 7 * Copyright (c) UPMC Sorbonne Universites 8 * 9 * This file is part of ALMOS-MKH.. 10 * 11 * ALMOS-MKH. is free software; you can redistribute it and/or modify it 8 * ALMOS-MKH is free software; you can redistribute it and/or modify it 12 9 * under the terms of the GNU General Public License as published by 13 10 * the Free Software Foundation; version 2.0 of the License. 14 11 * 15 * ALMOS-MKH .is distributed in the hope that it will be useful, but12 * ALMOS-MKH is distributed in the hope that it will be useful, but 16 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 17 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 23 20 */ 24 21 25 26 22 #include <hal_types.h> 23 #include <hal_lapic.h> 27 24 #include <hal_special.h> 28 29 /**** Forward declarations ****/ 25 #include <hal_register.h> 26 #include <hal_internal.h> 30 27 31 28 struct thread_s; 32 29 30 typedef struct cpu_info { 31 void *ci_self; 32 uint32_t ci_gid; 33 uint32_t ci_lid; 34 struct thread_s *ci_thr; 35 } cpu_info_t; 36 37 cpu_info_t cpu0 __in_kdata; 38 39 cpu_info_t *curcpu() 40 { 41 cpu_info_t *ci; 42 43 __asm volatile("movq %%gs:%1, %0" : 44 "=r" (ci) : 45 "m" 46 (*(cpu_info_t * const *)offsetof(cpu_info_t, ci_self))); 47 return ci; 48 } 49 50 static void hal_tls_load_cpu(cpu_info_t *ci) 51 { 52 wrmsr(MSR_FSBASE, 0); 53 wrmsr(MSR_GSBASE, (uint64_t)ci); 54 wrmsr(MSR_KERNELGSBASE, 0); 55 } 56 57 void hal_tls_init_cpu0() 58 { 59 cpu_info_t *ci = &cpu0; 60 61 memset(ci, 0, sizeof(cpu_info_t)); 62 63 ci->ci_self = ci; 64 ci->ci_gid = hal_lapic_gid(); 65 ci->ci_lid = 0; /* XXX */ 66 67 hal_tls_load_cpu(ci); 68 } 69 33 70 gid_t hal_get_gid() 34 71 { 35 return 0; 72 x86_panic((char *)__func__); 73 return curcpu()->ci_gid; 36 74 } 37 75 38 76 uint32_t hal_time_stamp() 39 77 { 78 x86_panic((char *)__func__); 40 79 return 0; 41 80 } … … 43 82 struct thread_s * hal_get_current_thread() 44 83 { 45 return NULL; 84 x86_panic((char *)__func__); 85 return curcpu()->ci_thr; 46 86 } 47 87 48 88 void hal_set_current_thread( struct thread_s * thread ) 49 89 { 90 x86_panic((char *)__func__); 91 curcpu()->ci_thr = thread; 92 } 50 93 51 } 94 /* -------------------------------------------------------------------------- */ 52 95 53 96 void hal_fpu_enable() 54 97 { 55 98 x86_panic((char *)__func__); 56 99 } 57 100 58 101 void hal_fpu_disable() 59 102 { 60 103 x86_panic((char *)__func__); 61 104 } 62 105 63 106 uint32_t hal_get_stack() 64 107 { 108 x86_panic((char *)__func__); 65 109 return 0; 66 110 } … … 68 112 uint32_t hal_set_stack( void * new_val ) 69 113 { 114 x86_panic((char *)__func__); 70 115 return 0; 71 116 } … … 73 118 uint32_t hal_get_bad_vaddr() 74 119 { 120 x86_panic((char *)__func__); 75 121 return 0; 76 122 } … … 78 124 uint32_t hal_uncached_read( uint32_t * ptr ) 79 125 { 126 x86_panic((char *)__func__); 80 127 return 0; 81 128 } … … 83 130 void hal_invalid_dcache_line( void * ptr ) 84 131 { 85 132 x86_panic((char *)__func__); 86 133 } 87 134 88 135 void hal_wbflush() 89 136 { 90 137 x86_panic((char *)__func__); 91 138 } 92 139 93 140 void hal_rdbar() 94 141 { 95 142 x86_panic((char *)__func__); 96 143 } 97 144 98 145 void hal_core_sleep() 99 146 { 100 147 x86_panic((char *)__func__); 101 148 } 102 149 103 150 void hal_fixed_delay( uint32_t delay ) 104 151 { 105 152 x86_panic((char *)__func__); 106 153 } 107 154 … … 111 158 intptr_t * mmu_dat_bad_vaddr ) 112 159 { 113 160 x86_panic((char *)__func__); 114 161 }
Note: See TracChangeset
for help on using the changeset viewer.