Changeset d6f9fff in mainline
- Timestamp:
- 2016-04-27T12:39:14Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1a5eca4
- Parents:
- 8a36bc1e
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/Makefile.inc
r8a36bc1e rd6f9fff 89 89 arch/$(KARCH)/src/smp/ipi.c \ 90 90 arch/$(KARCH)/src/ia32.c \ 91 arch/$(KARCH)/src/vreg.c \ 91 92 arch/$(KARCH)/src/interrupt.c \ 92 93 arch/$(KARCH)/src/pm.c \ -
kernel/arch/ia32/include/arch/asm.h
r8a36bc1e rd6f9fff 439 439 asm volatile ( 440 440 "ltr %[sel]" 441 :: [sel] "r" (sel) 442 ); 443 } 444 445 /** Load GS from descriptor table. 446 * 447 * @param sel Selector specifying descriptor of the GS segment. 448 * 449 */ 450 NO_TRACE static inline void gs_load(uint16_t sel) 451 { 452 asm volatile ( 453 "mov %[sel], %%gs" 441 454 :: [sel] "r" (sel) 442 455 ); -
kernel/arch/ia32/include/arch/context_struct.ag
r8a36bc1e rd6f9fff 66 66 }, 67 67 { 68 name : tp, 69 type : uint32_t 70 }, 71 72 { 68 73 name : ipl, 69 74 type : ipl_t -
kernel/arch/ia32/include/arch/pm.h
r8a36bc1e rd6f9fff 45 45 #define UDATA_DES 4 46 46 #define TSS_DES 5 47 #define TLS_DES 6 /* Pointer to Thread-Local-Storage data*/47 #define VREG_DES 6 /* Virtual registers */ 48 48 49 49 #ifdef CONFIG_FB … … 169 169 170 170 extern void tss_initialize(tss_t *t); 171 extern void set_tls_desc(uintptr_t tls);172 171 173 172 #endif /* __ASM__ */ -
kernel/arch/ia32/include/arch/proc/thread.h
r8a36bc1e rd6f9fff 39 39 40 40 typedef struct { 41 sysarg_t tls;42 41 } thread_arch_t; 43 42 -
kernel/arch/ia32/src/asm.S
r8a36bc1e rd6f9fff 183 183 184 184 /* 185 * Save TLS.186 */187 movl %gs, %edx188 movl %edx, ISTATE_OFFSET_GS(%esp)189 190 /*191 185 * Switch to kernel selectors. 192 186 */ 193 movw $(GDT_SELECTOR(KDATA_DES)), %ax 194 movw %ax, %ds 195 movw %ax, %es 187 movl $(GDT_SELECTOR(KDATA_DES)), %eax 188 movl %eax, %ds 189 movl %eax, %es 190 movl $(GDT_SELECTOR(VREG_DES)), %eax 191 movl %eax, %gs 196 192 197 193 /* … … 213 209 214 210 /* 215 * Restore TLS.216 */217 movl ISTATE_OFFSET_GS(%esp), %edx218 movl %edx, %gs219 220 /*221 211 * Prepare return address and userspace stack for SYSEXIT. 222 212 */ … … 252 242 253 243 /* 254 * Save the se lectorregisters.244 * Save the segment registers. 255 245 */ 256 246 movl %gs, %ecx … … 272 262 movl %eax, %ds 273 263 movl %eax, %es 264 movl $(GDT_SELECTOR(VREG_DES)), %eax 265 movl %eax, %gs 274 266 275 267 movl $0, ISTATE_OFFSET_EBP_FRAME(%esp) … … 284 276 285 277 /* 286 * Restore the se lectorregisters.278 * Restore the segment registers. 287 279 */ 288 280 movl ISTATE_OFFSET_GS(%esp), %ecx … … 354 346 355 347 /* 356 * Save the se lectorregisters.348 * Save the segment registers. 357 349 */ 358 350 movl %gs, %ecx … … 374 366 movl %eax, %ds 375 367 movl %eax, %es 368 movl $(GDT_SELECTOR(VREG_DES)), %eax 369 movl %eax, %gs 376 370 377 371 /* -
kernel/arch/ia32/src/context.S
r8a36bc1e rd6f9fff 29 29 #include <abi/asmtool.h> 30 30 #include <arch/context_struct.h> 31 #include <arch/vreg.h> 31 32 32 33 .text … … 48 49 movl %edi, CONTEXT_OFFSET_EDI(%edx) # %edi -> ctx->edi 49 50 movl %ebp, CONTEXT_OFFSET_EBP(%edx) # %ebp -> ctx->ebp 51 52 mov vreg_ptr, %ecx 53 movl %gs:VREG_TP(%ecx), %ecx 54 movl %ecx, CONTEXT_OFFSET_TP(%edx) 50 55 51 56 xorl %eax, %eax # context_save returns 1 … … 72 77 73 78 movl %edx, 0(%esp) # put saved pc on stack 79 80 mov vreg_ptr, %ecx 81 movl CONTEXT_OFFSET_TP(%eax), %edx 82 movl %edx, %gs:VREG_TP(%ecx) 83 74 84 xorl %eax, %eax # context_restore returns 0 75 85 ret 76 FUNCTION_END(context_restore_arch) -
kernel/arch/ia32/src/ia32.c
r8a36bc1e rd6f9fff 57 57 #include <genarch/multiboot/multiboot.h> 58 58 #include <genarch/multiboot/multiboot2.h> 59 #include <arch/pm.h> 60 #include <arch/vreg.h> 59 61 60 62 #ifdef CONFIG_SMP … … 96 98 void arch_post_mm_init(void) 97 99 { 100 vreg_init(); 101 98 102 if (config.cpu_active == 1) { 99 103 /* Initialize IRQ routing */ … … 122 126 zone_merge_all(); 123 127 } 128 124 129 } 125 130 … … 223 228 sysarg_t sys_tls_set(uintptr_t addr) 224 229 { 225 THREAD->arch.tls = addr;226 set_tls_desc(addr);227 228 230 return EOK; 229 231 } -
kernel/arch/ia32/src/pm.c
r8a36bc1e rd6f9fff 41 41 #include <panic.h> 42 42 #include <arch/mm/page.h> 43 #include <mm/km.h> 44 #include <mm/frame.h> 43 45 #include <mm/slab.h> 44 46 #include <memstr.h> … … 51 53 52 54 /* 53 * We have no use for segmentation so we set up flat mode. In this54 * mode, we use, for each privilege level, two segments spanning the55 * We don't have much use for segmentation so we set up flat mode. 56 * In this mode, we use, for each privilege level, two segments spanning the 55 57 * whole memory. One is for code and one is for data. 56 58 * 57 * One is for GS register which holds pointer to the TLS thread58 * structure in it's base.59 * One special segment apart of that is for the GS register which holds 60 * a pointer to the VREG page in its base. 59 61 */ 60 62 descriptor_t gdt[GDT_ITEMS] = { … … 71 73 /* TSS descriptor - set up will be completed later */ 72 74 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 73 /* TLS descriptor */74 { 0xffff, 0 , 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 },75 /* VREG descriptor - segment used for virtual registers, will be reinitialized later */ 76 { 0xffff, 0 , 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 }, 75 77 /* VESA Init descriptor */ 76 78 #ifdef CONFIG_FB … … 82 84 static idescriptor_t idt[IDT_ITEMS]; 83 85 84 static tss_t tss ;86 static tss_t tss0; 85 87 86 88 tss_t *tss_p = NULL; … … 95 97 { 96 98 d->base_0_15 = base & 0xffff; 97 d->base_16_23 = ( (base)>> 16) & 0xff;98 d->base_24_31 = ( (base)>> 24) & 0xff;99 d->base_16_23 = (base >> 16) & 0xff; 100 d->base_24_31 = (base >> 24) & 0xff; 99 101 } 100 102 … … 265 267 * the heap hasn't been initialized so far. 266 268 */ 267 tss_p = &tss; 268 } 269 else { 269 tss_p = &tss0; 270 } else { 270 271 tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC); 271 272 if (!tss_p) … … 292 293 } 293 294 294 void set_tls_desc(uintptr_t tls)295 {296 ptr_16_32_t cpugdtr;297 descriptor_t *gdt_p;298 299 gdtr_store(&cpugdtr);300 gdt_p = (descriptor_t *) cpugdtr.base;301 gdt_setbase(&gdt_p[TLS_DES], tls);302 /* Reload gdt register to update GS in CPU */303 gdtr_load(&cpugdtr);304 }305 306 295 /** @} 307 296 */ -
kernel/arch/ia32/src/proc/scheduler.c
r8a36bc1e rd6f9fff 70 70 CPU->arch.tss->esp0 = kstk; 71 71 CPU->arch.tss->ss0 = GDT_SELECTOR(KDATA_DES); 72 73 /* Set up TLS in GS register */74 set_tls_desc(THREAD->arch.tls);75 72 } 76 73 -
kernel/arch/ia32/src/proc/thread.c
r8a36bc1e rd6f9fff 41 41 void thread_create_arch(thread_t *t) 42 42 { 43 t->arch.tls = 0;44 43 } 45 44 -
kernel/arch/ia32/src/userspace.c
r8a36bc1e rd6f9fff 59 59 "popfl\n" 60 60 61 /* Set up GS register ( TLS) */62 "movl %[ tls_des], %%gs\n"61 /* Set up GS register (virtual register segment) */ 62 "movl %[vreg_des], %%gs\n" 63 63 64 64 "pushl %[udata_des]\n" … … 81 81 [entry] "r" (kernel_uarg->uspace_entry), 82 82 [uarg] "r" (kernel_uarg->uspace_uarg), 83 [ tls_des] "r" (GDT_SELECTOR(TLS_DES))83 [vreg_des] "r" (GDT_SELECTOR(VREG_DES)) 84 84 : "eax"); 85 85 -
uspace/lib/c/arch/ia32/Makefile.common
r8a36bc1e rd6f9fff 28 28 29 29 ifeq ($(PROCESSOR),i486) 30 GCC_CFLAGS += -march=i486 - fno-omit-frame-pointer30 GCC_CFLAGS += -march=i486 -mno-tls-direct-seg-refs -fno-omit-frame-pointer 31 31 else 32 GCC_CFLAGS += -march=pentium - fno-omit-frame-pointer32 GCC_CFLAGS += -march=pentium -mno-tls-direct-seg-refs -fno-omit-frame-pointer 33 33 endif 34 34 -
uspace/lib/c/arch/ia32/include/libarch/tls.h
r8a36bc1e rd6f9fff 47 47 static inline void __tcb_set(tcb_t *tcb) 48 48 { 49 __SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);49 asm volatile ("movl %0, %%gs:0" :: "r" (tcb)); 50 50 } 51 51 … … 54 54 void *retval; 55 55 56 asm ( 57 "movl %%gs:0, %0" 58 : "=r" (retval) 59 ); 56 asm volatile ("movl %%gs:0, %0" : "=r" (retval)); 60 57 61 58 return retval; -
uspace/lib/c/arch/ia32/src/fibril.S
r8a36bc1e rd6f9fff 77 77 78 78 # set thread local storage 79 pushl %edx80 79 movl CONTEXT_OFFSET_TLS(%eax), %edx # Set arg1 to TLS addr 81 movl $1, %eax # Syscall SYS_TLS_SET 82 int $0x30 83 popl %edx 80 movl %edx, %gs:0 84 81 85 82 xorl %eax, %eax # context_restore returns 0
Note:
See TracChangeset
for help on using the changeset viewer.