diff options
author | Yuji Mano <yuji.mano@am.sony.com> | 2009-03-13 18:18:47 -0700 |
---|---|---|
committer | Yuji Mano <yuji.mano@am.sony.com> | 2009-03-17 11:09:51 -0700 |
commit | ebaf69ff04706f3e5d28567d98e57a259c190b2e (patch) | |
tree | 5d266e98c67c353888733c85bc5cd418f21e0bb6 | |
parent | 8420c9aa009332e710a890105544b32bf6eba20f (diff) | |
download | mars-src-ebaf69ff04706f3e5d28567d98e57a259c190b2e.tar.gz |
base: ASM sched func
Rewrite part of kernel in assembly language
This patch reimplement part of kernel in assembly language to
guarantee particular stack layout.
Signed-off-by: Kazunori Asayama <asayama@sm.sony.co.jp>
Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
-rw-r--r-- | base/src/common/kernel_internal_types.h | 3 | ||||
-rw-r--r-- | base/src/mpu/kernel/Makefile.am | 3 | ||||
-rw-r--r-- | base/src/mpu/kernel/kernel.c | 47 | ||||
-rw-r--r-- | base/src/mpu/kernel/switch.S | 80 | ||||
-rw-r--r-- | base/src/mpu/lib/Makefile.am | 1 | ||||
-rw-r--r-- | base/src/mpu/lib/entry.S | 50 | ||||
-rw-r--r-- | base/src/mpu/lib/module.c | 30 |
7 files changed, 161 insertions, 53 deletions
diff --git a/base/src/common/kernel_internal_types.h b/base/src/common/kernel_internal_types.h index eec536e..bf7b568 100644 --- a/base/src/common/kernel_internal_types.h +++ b/base/src/common/kernel_internal_types.h @@ -123,7 +123,4 @@ int dma_get(void *ls, uint64_t ea, uint32_t size, uint32_t tag); int dma_put(const void *ls, uint64_t ea, uint32_t size, uint32_t tag); int dma_wait(uint32_t tag); -/* mars module entry */ -void mars_module_entry(struct mars_kernel_syscalls *syscalls); - #endif diff --git a/base/src/mpu/kernel/Makefile.am b/base/src/mpu/kernel/Makefile.am index fde5540..3afc74a 100644 --- a/base/src/mpu/kernel/Makefile.am +++ b/base/src/mpu/kernel/Makefile.am @@ -98,6 +98,7 @@ mars_kernel_SOURCES = \ $(srcdir)/../../../src/common/*.h \ dma.c \ kernel.c \ - mutex.c + mutex.c \ + switch.S CLEANFILES = *.map diff --git a/base/src/mpu/kernel/kernel.c b/base/src/mpu/kernel/kernel.c index b37959c..b2de697 100644 --- a/base/src/mpu/kernel/kernel.c +++ b/base/src/mpu/kernel/kernel.c @@ -48,7 +48,6 @@ #include "workload_internal_types.h" /* kernel */ -void *__kernel_stack; union mars_kernel_buffer kernel_buffer; static struct mars_kernel_params kernel_params; @@ -75,6 +74,14 @@ static struct mars_workload_module cached_workload_module; typedef void (*module_entry)( const struct mars_kernel_syscalls *kernel_syscalls); +/* defined in switch.S */ +extern void workload_run(void); +extern void workload_exit(uint8_t state); + +/* called by switch.S */ +void __workload_run(void); +void __workload_exit(uint8_t state); + static int kernel_memcmp(const void *s1, const void *s2, int size) { __vector const int *vptr_1 = (__vector const int *)s1; @@ -329,22 +336,6 @@ static int change_state(uint16_t id, callback); } - -static void __attribute__((noinline)) save_workload_state(uint8_t state) -{ - workload_state = state; -} - -static void workload_exit(uint8_t state) -{ - register void *sp asm("$sp"); - - save_workload_state(state); - - /* restore kernel stack pointer */ - sp = __kernel_stack; -} - static int workload_query(uint16_t id, int query) { uint64_t bits = get_block_bits(id); @@ -545,6 +536,17 @@ static struct mars_kernel_syscalls kernel_syscalls = dma_wait }; +void __workload_run(void) +{ + /* call module entry function */ + ((module_entry)workload_module->entry)(&kernel_syscalls); +} + +void __workload_exit(uint8_t state) +{ + workload_state = state; +} + static int search_block(int block, int ready) { int i; @@ -773,17 +775,6 @@ static void workload_release(void) notify_host_bits(block_ea, index); } -static void __attribute__((noinline)) workload_run(void) -{ - register void *sp asm("$sp"); - - /* save kernel stack pointer */ - __kernel_stack = sp; - - /* call module entry function */ - ((module_entry)workload_module->entry)(&kernel_syscalls); -} - static void workload_module_load(void) { __vector unsigned char *bss_ptr, *bss_end; diff --git a/base/src/mpu/kernel/switch.S b/base/src/mpu/kernel/switch.S new file mode 100644 index 0000000..7ddfede --- /dev/null +++ b/base/src/mpu/kernel/switch.S @@ -0,0 +1,80 @@ +/* + * Copyright 2009 Sony Corporation of America + * + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this Library and associated documentation files (the + * "Library"), to deal in the Library without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Library, and to + * permit persons to whom the Library is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Library. + * + * If you modify the Library, you may copy and distribute your modified + * version of the Library in object code or as an executable provided + * that you also do one of the following: + * + * Accompany the modified version of the Library with the complete + * corresponding machine-readable source code for the modified version + * of the Library; or, + * + * Accompany the modified version of the Library with a written offer + * for a complete machine-readable copy of the corresponding source + * code of the modified version of the Library. + * + * + * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY. + */ + +.data + +/* void *__kernel_stack */ +.align 4 +.globl __kernel_stack +__kernel_stack: +.space 4 + + +.text + +/* void workload_run(void) */ +.global workload_run +.type workload_run, @function +workload_run: + stqd $LR, 16($SP) /* save link register */ + stqd $SP, -32($SP) /* save back chain */ + ai $SP, $SP, -32 /* push stack frame */ + + stqr $SP, __kernel_stack /* save kernel stack pointer */ + brsl $LR, __workload_run /* call body of workload_run */ + + ai $SP, $SP, 32 /* pop stack frame */ + lqd $LR, 16($SP) /* restore link register */ + bi $LR /* return */ +.size workload_run, .-workload_run + + +/* void workload_exit(uint8_t state) */ +.global workload_exit +.type workload_exit, @function +workload_exit: + stqd $LR, 16($SP) /* save link register */ + stqd $SP, -32($SP) /* save back chain */ + ai $SP, $SP, -32 /* push stack frame */ + + brsl $LR, __workload_exit /* call body of workload_exit */ + lqr $SP, __kernel_stack /* restore kernel stack */ + + ai $SP, $SP, 32 /* pop stack frame */ + lqd $LR, 16($SP) /* restore link register */ + bi $LR /* return */ +.size workload_exit, .-workload_exit diff --git a/base/src/mpu/lib/Makefile.am b/base/src/mpu/lib/Makefile.am index 643b5ed..f306e1d 100644 --- a/base/src/mpu/lib/Makefile.am +++ b/base/src/mpu/lib/Makefile.am @@ -92,4 +92,5 @@ lib_LTLIBRARIES = libmars_base.la libmars_base_la_SOURCES = \ $(srcdir)/../../../src/common/*.h \ + entry.S \ module.c diff --git a/base/src/mpu/lib/entry.S b/base/src/mpu/lib/entry.S new file mode 100644 index 0000000..353a55f --- /dev/null +++ b/base/src/mpu/lib/entry.S @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Sony Corporation of America + * + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this Library and associated documentation files (the + * "Library"), to deal in the Library without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Library, and to + * permit persons to whom the Library is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Library. + * + * If you modify the Library, you may copy and distribute your modified + * version of the Library in object code or as an executable provided + * that you also do one of the following: + * + * Accompany the modified version of the Library with the complete + * corresponding machine-readable source code for the modified version + * of the Library; or, + * + * Accompany the modified version of the Library with a written offer + * for a complete machine-readable copy of the corresponding source + * code of the modified version of the Library. + * + * + * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY. + */ + +.text + +/* void mars_module_entry(struct mars_kernel_syscalls *syscalls) */ +.global mars_module_entry +.type mars_module_entry, @function +mars_module_entry: + ila $SP, __stack /* switch to module stack */ + il $LR, 0 /* set module link register to NULL */ + stqd $LR, 0($SP) /* initialize back chain to NULL */ + stqd $SP, -32($SP) /* initialize stack frame */ + ai $SP, $SP, -32 /* push stack frame */ + brsl $LR, __module_entry /* call module entry body */ +.size mars_module_entry, .-mars_module_entry diff --git a/base/src/mpu/lib/module.c b/base/src/mpu/lib/module.c index af1ce15..8459f2b 100644 --- a/base/src/mpu/lib/module.c +++ b/base/src/mpu/lib/module.c @@ -42,32 +42,20 @@ #include "kernel_internal_types.h" #include "workload_internal_types.h" +/* global kernel syscalls pointer */ static struct mars_kernel_syscalls *kernel_syscalls; -void mars_module_entry(struct mars_kernel_syscalls *syscalls) -{ - kernel_syscalls = syscalls; - - asm volatile ( - /* switch to module stack */ - "ila $sp, __stack;" - - /* set module link register to NULL */ - "il $lr, 0;" +/* defined in crt */ +extern void _init(void); - /* initialize back chain to NULL */ - "stqd $lr, 0($sp);" +/* called by entry.S */ +void __module_entry(struct mars_kernel_syscalls *syscalls); - /* initialize module stack frame */ - "stqd $sp, -32($sp);" - "ai $sp, $sp, -32;" - - /* save link register in link register save area */ - "stqd $lr, 16($sp);" +void __module_entry(struct mars_kernel_syscalls *syscalls) +{ + kernel_syscalls = syscalls; - /* call _init function */ - "brsl $lr, _init;" - ); + _init(); mars_module_main(); |