[haiku-commits] r41810 - in haiku/branches/developer/bonefish/signals: headers/private/kernel/arch src/system/kernel src/system/kernel/arch/arm src/system/kernel/arch/m68k src/system/kernel/arch/mipsel ...

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 29 May 2011 19:40:46 +0200 (CEST)

Author: bonefish
Date: 2011-05-29 19:40:46 +0200 (Sun, 29 May 2011)
New Revision: 41810
Changeset: https://dev.haiku-os.org/changeset/41810

Modified:
   
haiku/branches/developer/bonefish/signals/headers/private/kernel/arch/thread.h
   
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/arm/arch_thread.cpp
   
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/m68k/arch_thread.cpp
   
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/mipsel/arch_thread.cpp
   
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/ppc/arch_thread.cpp
   
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/x86/arch_thread.cpp
   haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp
Log:
arch_thread_init_kthread_stack():
* Moved the generic part of the x86 implementation to thread.cpp static function
  init_thread_kernel_stack(). The data are copied to the stack there already.
* Changed the interface accordingly. The stack top and bottom are passed as well
  now. The data size is no longer needed.


Modified: 
haiku/branches/developer/bonefish/signals/headers/private/kernel/arch/thread.h
===================================================================
--- 
haiku/branches/developer/bonefish/signals/headers/private/kernel/arch/thread.h  
    2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/headers/private/kernel/arch/thread.h  
    2011-05-29 17:40:46 UTC (rev 41810)
@@ -21,8 +21,8 @@
 status_t arch_thread_init_thread_struct(Thread *t);
 status_t arch_thread_init_tls(Thread *thread);
 void arch_thread_context_switch(Thread *t_from, Thread *t_to);
-status_t arch_thread_init_kthread_stack(Thread *thread,
-       void (*function)(void*), const void *data, size_t dataSize);
+void arch_thread_init_kthread_stack(Thread *thread, void *stack,
+       void *stackTop, void (*function)(void*), const void *data);
 void arch_thread_dump_info(void *info);
 status_t arch_thread_enter_userspace(Thread *t, addr_t entry,
        void *args1, void *args2);

Modified: 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/arm/arch_thread.cpp
===================================================================
--- 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/arm/arch_thread.cpp
        2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/arm/arch_thread.cpp
        2011-05-29 17:40:46 UTC (rev 41810)
@@ -62,12 +62,11 @@
 }
 
 
-status_t
-arch_thread_init_kthread_stack(Thread* thread, void (*function)(void*),
-       const void* data, size_t dataSize)
+void
+arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
+       void (*function)(void*), const void* data)
 {
 #warning ARM:WRITEME
-       return B_NOT_SUPPORTED;
 }
 
 

Modified: 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/m68k/arch_thread.cpp
===================================================================
--- 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/m68k/arch_thread.cpp
       2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/m68k/arch_thread.cpp
       2011-05-29 17:40:46 UTC (rev 41810)
@@ -146,9 +146,9 @@
 }
 
 
-status_t
-arch_thread_init_kthread_stack(Thread* thread, void (*function)(void*),
-       const void* data, size_t dataSize)
+void
+arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
+       void (*function)(void*), const void* data)
 {
 #if 0
        addr_t *kstack = (addr_t *)t->kernel_stack_base;
@@ -188,7 +188,7 @@
 
        return B_OK;
 #else
-       return B_NOT_SUPPORTED;
+       panic("arch_thread_init_kthread_stack(): Implement me!");
 #endif
 }
 

Modified: 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/mipsel/arch_thread.cpp
===================================================================
--- 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/mipsel/arch_thread.cpp
     2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/mipsel/arch_thread.cpp
     2011-05-29 17:40:46 UTC (rev 41810)
@@ -86,12 +86,11 @@
 }
 
 
-status_t
-arch_thread_init_kthread_stack(Thread* thread, void (*function)(void*),
-       const void* data, size_t dataSize)
+void
+arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
+       void (*function)(void*), const void* data)
 {
 #warning IMPLEMENT arch_thread_init_kthread_stack
-       return B_ERROR;
 }
 
 

Modified: 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/ppc/arch_thread.cpp
===================================================================
--- 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/ppc/arch_thread.cpp
        2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/ppc/arch_thread.cpp
        2011-05-29 17:40:46 UTC (rev 41810)
@@ -116,9 +116,9 @@
 }
 
 
-status_t
-arch_thread_init_kthread_stack(Thread* thread, void (*function)(void*),
-       const void* data, size_t dataSize)
+void
+arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
+       void (*function)(void*), const void* data)
 {
 #if 0
        addr_t *kstack = (addr_t *)t->kernel_stack_base;
@@ -158,7 +158,7 @@
 
        return B_OK;
 #else
-       return B_NOT_SUPPORTED;
+       panic("arch_thread_init_kthread_stack(): Implement me!");
 #endif
 }
 

Modified: 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/x86/arch_thread.cpp
===================================================================
--- 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/x86/arch_thread.cpp
        2011-05-29 16:55:43 UTC (rev 41809)
+++ 
haiku/branches/developer/bonefish/signals/src/system/kernel/arch/x86/arch_thread.cpp
        2011-05-29 17:40:46 UTC (rev 41810)
@@ -305,48 +305,23 @@
 
 /*!    Prepares the given thread's kernel stack for executing its entry 
function.
 
-       The data pointed to by \a data of size \a dataSize are copied to the
-       thread's kernel stack. A pointer to the copy's data is passed to the 
entry
-       function.
-
        \param thread The thread.
+       \param stack The usable bottom of the thread's kernel stack.
+       \param stackTop The usable top of the thread's kernel stack.
        \param function The entry function the thread shall execute.
-       \param data Pointer to data to be copied to the thread's stack and 
passed
-               to the entry function.
-       \param dataSize The size of \a data.
-       \return \c B_OK, if everything went fine, another error code otherwise.
+       \param data Pointer to be passed to the entry function.
 */
-status_t
-arch_thread_init_kthread_stack(Thread* thread, void (*function)(void*),
-       const void* data, size_t dataSize)
+void
+arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
+       void (*function)(void*), const void* data)
 {
-       addr_t* stack = (addr_t*)thread->kernel_stack_base;
-       addr_t* stackTop = (addr_t*)thread->kernel_stack_top;
+       addr_t* stackTop = (addr_t*)_stackTop;
 
-       TRACE(("arch_thread_init_kthread_stack: stack %p, function %, data: %p,"
-               "size: %" B_PRIuSIZE "\n", stack, function, data, dataSize));
+       TRACE(("arch_thread_init_kthread_stack: stack top %p, function %, data: 
"
+               "%p\n", stackTop, function, data));
 
-       // clear (or rather invalidate) the kernel stack contents, if compiled 
with
-       // debugging
-#if DEBUG > 0
-#      if defined(DEBUG_KERNEL_STACKS) && defined(STACK_GROWS_DOWNWARDS)
-       memset((void*)((addr_t)stack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE),
-               0xcc, KERNEL_STACK_SIZE);
-#      else
-       memset(stack, 0xcc, KERNEL_STACK_SIZE);
-#      endif
-#else
-       (void)stack;
-#endif
-
-       // copy the data onto the stack, with 8-byte alignment to be on the safe
-       // side
-       void* clonedData = (void*)(((addr_t)stackTop - dataSize) / 8 * 8);
-       memcpy(clonedData, data, dataSize);
-       stackTop = (addr_t*)clonedData;
-
        // push the function argument, a pointer to the data
-       *--stackTop = (addr_t)clonedData;
+       *--stackTop = (addr_t)data;
 
        // push a dummy return address for the function
        *--stackTop = 0;
@@ -355,15 +330,13 @@
        // context switch
        *--stackTop = (addr_t)function;
 
-       // simulate initial popad
+       // simulate pushad as done by x86_context_switch()
        for (int i = 0; i < 8; i++)
                *--stackTop = 0;
 
        // save the stack position
        thread->arch_info.current_stack.esp = stackTop;
        thread->arch_info.current_stack.ss = (addr_t*)KERNEL_DATA_SEG;
-
-       return B_OK;
 }
 
 

Modified: haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp
===================================================================
--- haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp      
2011-05-29 16:55:43 UTC (rev 41809)
+++ haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp      
2011-05-29 17:40:46 UTC (rev 41810)
@@ -661,6 +661,53 @@
 }
 
 
+/*!    Prepares the given thread's kernel stack for executing its entry 
function.
+
+       The data pointed to by \a data of size \a dataSize are copied to the
+       thread's kernel stack. A pointer to the copy's data is passed to the 
entry
+       function. The entry function is thread_thread_entry().
+
+       \param thread The thread.
+       \param data Pointer to data to be copied to the thread's stack and 
passed
+               to the entry function.
+       \param dataSize The size of \a data.
+ */
+static void
+init_thread_kernel_stack(Thread* thread, const void* data, size_t dataSize)
+{
+//     &thread_thread_entry
+       uint8* stack = (uint8*)thread->kernel_stack_base;
+       uint8* stackTop = (uint8*)thread->kernel_stack_top;
+
+       // clear (or rather invalidate) the kernel stack contents, if compiled 
with
+       // debugging
+#if DEBUG > 0
+#      if defined(DEBUG_KERNEL_STACKS) && defined(STACK_GROWS_DOWNWARDS)
+       memset((void*)(stack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE), 0xcc,
+               KERNEL_STACK_SIZE);
+#      else
+       memset(stack, 0xcc, KERNEL_STACK_SIZE);
+#      endif
+#endif
+
+       // copy the data onto the stack, with 16-byte alignment to be on the 
safe
+       // side
+       void* clonedData;
+#ifdef STACK_GROWS_DOWNWARDS
+       clonedData = (void*)ROUNDDOWN((addr_t)stackTop - dataSize, 16);
+       stackTop = (uint8*)clonedData;
+#else
+       clonedData = (void*)ROUNDUP((addr_t)stack, 16);
+       stack = (uint8*)clonedData + ROUNDUP(dataSize, 16);
+#endif
+
+       memcpy(clonedData, data, dataSize);
+
+       arch_thread_init_kthread_stack(thread, stack, stackTop,
+               &thread_thread_entry, clonedData);
+}
+
+
 /*!    Creates a new thread.
 
        \param attributes The thread creation attributes, specifying the team in
@@ -738,8 +785,7 @@
                entryArgs.argument = attributes.args1;
                entryArgs.enterUserland = false;
 
-               arch_thread_init_kthread_stack(thread, &thread_thread_entry,
-                       &entryArgs, sizeof(entryArgs));
+               init_thread_kernel_stack(thread, &entryArgs, sizeof(entryArgs));
        } else {
                // create the userland stack
 
@@ -823,8 +869,7 @@
                entryArgs.userlandArgument2 = attributes.args2;
                entryArgs.pthread = attributes.pthread;
 
-               arch_thread_init_kthread_stack(thread, &thread_thread_entry,
-                       &entryArgs, sizeof(entryArgs));
+               init_thread_kernel_stack(thread, &entryArgs, sizeof(entryArgs));
        }
 
        // lock the team and see, if it is still alive


Other related posts:

  • » [haiku-commits] r41810 - in haiku/branches/developer/bonefish/signals: headers/private/kernel/arch src/system/kernel src/system/kernel/arch/arm src/system/kernel/arch/m68k src/system/kernel/arch/mipsel ... - ingo_weinhold