Renamed KSTACK_SIZE to KERNEL_STACK_SIZE.

Fixed a bug in arch_init_tls() that did not support different stack sizes
(ie. didn't use the thread::user_stack_size variable).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10015 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-11-18 18:11:19 +00:00
parent 8bde4cf98c
commit b139f2481d
2 changed files with 23 additions and 14 deletions

View File

@ -63,7 +63,7 @@ dbg_stack_trace(int argc, char **argv)
dprintf("stack trace for thread 0x%lx \"%s\"\n", t->id, t->name); dprintf("stack trace for thread 0x%lx \"%s\"\n", t->id, t->name);
dprintf(" kernel stack: %p to %p\n", dprintf(" kernel stack: %p to %p\n",
(void *)t->kernel_stack_base, (void *)(t->kernel_stack_base + KSTACK_SIZE)); (void *)t->kernel_stack_base, (void *)(t->kernel_stack_base + KERNEL_STACK_SIZE));
if (t->user_stack_base != 0) { if (t->user_stack_base != 0) {
dprintf(" user stack: %p to %p\n", (void *)t->user_stack_base, dprintf(" user stack: %p to %p\n", (void *)t->user_stack_base,
(void *)(t->user_stack_base + t->user_stack_size)); (void *)(t->user_stack_base + t->user_stack_size));

View File

@ -1,10 +1,11 @@
/* /*
** Copyright 2002-2004, The Haiku Team. All rights reserved. * Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
** *
** Copyright 2001, Travis Geiselbrecht. All rights reserved. * Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License. * Distributed under the terms of the NewOS License.
*/ */
#include <thread.h> #include <thread.h>
#include <arch/thread.h> #include <arch/thread.h>
@ -121,15 +122,23 @@ status_t
arch_thread_init_kthread_stack(struct thread *t, int (*start_func)(void), void (*entry_func)(void), void (*exit_func)(void)) arch_thread_init_kthread_stack(struct thread *t, int (*start_func)(void), void (*entry_func)(void), void (*exit_func)(void))
{ {
addr_t *kstack = (addr_t *)t->kernel_stack_base; addr_t *kstack = (addr_t *)t->kernel_stack_base;
addr_t kstack_size = KSTACK_SIZE; addr_t *kstack_top = kstack + KERNEL_STACK_SIZE / sizeof(addr_t);
addr_t *kstack_top = kstack + kstack_size / sizeof(addr_t);
int i; int i;
TRACE(("arch_thread_initialize_kthread_stack: kstack 0x%p, start_func 0x%p, entry_func 0x%p\n", TRACE(("arch_thread_initialize_kthread_stack: kstack 0x%p, start_func 0x%p, entry_func 0x%p\n",
kstack, start_func, entry_func)); kstack, start_func, entry_func));
// clear the kernel stack // clear the kernel stack
memset(kstack, 0, kstack_size); #ifdef DEBUG_KERNEL_STACKS
# ifdef STACK_GROWS_DOWNWARDS
memset((void *)((addr_t)kstack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE), 0,
KERNEL_STACK_SIZE - KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE);
# else
memset(kstack, 0, KERNEL_STACK_SIZE - KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE);
# endif
#else
memset(kstack, 0, KERNEL_STACK_SIZE);
#endif
// set the final return address to be thread_kthread_exit // set the final return address to be thread_kthread_exit
kstack_top--; kstack_top--;
@ -172,7 +181,7 @@ arch_thread_init_tls(struct thread *thread)
{ {
uint32 *tls; uint32 *tls;
thread->user_local_storage = thread->user_stack_base + STACK_SIZE; thread->user_local_storage = thread->user_stack_base + thread->user_stack_size;
tls = (uint32 *)thread->user_local_storage; tls = (uint32 *)thread->user_local_storage;
tls[TLS_BASE_ADDRESS_SLOT] = thread->user_local_storage; tls[TLS_BASE_ADDRESS_SLOT] = thread->user_local_storage;
@ -206,7 +215,7 @@ arch_thread_context_switch(struct thread *t_from, struct thread *t_to)
for (i = 0; i < 11; i++) for (i = 0; i < 11; i++)
dprintf("*esp[%d] (0x%x) = 0x%x\n", i, ((unsigned int *)new_at->esp + i), *((unsigned int *)new_at->esp + i)); dprintf("*esp[%d] (0x%x) = 0x%x\n", i, ((unsigned int *)new_at->esp + i), *((unsigned int *)new_at->esp + i));
#endif #endif
i386_set_tss_and_kstack(t_to->kernel_stack_base + KSTACK_SIZE); i386_set_tss_and_kstack(t_to->kernel_stack_base + KERNEL_STACK_SIZE);
// set TLS GDT entry to the current thread - since this action is // set TLS GDT entry to the current thread - since this action is
// dependent on the current CPU, we have to do it here // dependent on the current CPU, we have to do it here
@ -269,7 +278,7 @@ arch_thread_enter_uspace(struct thread *t, addr_t entry, void *args1, void *args
disable_interrupts(); disable_interrupts();
i386_set_tss_and_kstack(t->kernel_stack_base + KSTACK_SIZE); i386_set_tss_and_kstack(t->kernel_stack_base + KERNEL_STACK_SIZE);
// set the CPU dependent GDT entry for TLS // set the CPU dependent GDT entry for TLS
set_tls_context(t); set_tls_context(t);
@ -434,7 +443,7 @@ arch_restore_fork_frame(struct arch_fork_arg *arg)
disable_interrupts(); disable_interrupts();
i386_set_tss_and_kstack(thread->kernel_stack_base + KSTACK_SIZE); i386_set_tss_and_kstack(thread->kernel_stack_base + KERNEL_STACK_SIZE);
// set the CPU dependent GDT entry for TLS (set the current %fs register) // set the CPU dependent GDT entry for TLS (set the current %fs register)
set_tls_context(thread); set_tls_context(thread);