diff options
author | Alan Korr <alkorr@rockbox.org> | 2002-04-21 12:21:14 +0000 |
---|---|---|
committer | Alan Korr <alkorr@rockbox.org> | 2002-04-21 12:21:14 +0000 |
commit | b7cf0602fd08f6a367d42f0b6adadb8322b3d35d (patch) | |
tree | abbfb87b615f4c01a5f56eedacd75acbd2e52b87 /firmware/test/memory | |
parent | 257d17da6d64d2e265df3c80192a01f47e1dd2b7 (diff) | |
download | rockbox-b7cf0602fd08f6a367d42f0b6adadb8322b3d35d.tar.gz rockbox-b7cf0602fd08f6a367d42f0b6adadb8322b3d35d.zip |
removing all that stuff permanently.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@159 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/memory')
-rw-r--r-- | firmware/test/memory/config.h | 27 | ||||
-rw-r--r-- | firmware/test/memory/defines.h | 39 | ||||
-rw-r--r-- | firmware/test/memory/functions.h | 94 | ||||
-rw-r--r-- | firmware/test/memory/inlines.h | 26 | ||||
-rw-r--r-- | firmware/test/memory/makefile | 23 | ||||
-rw-r--r-- | firmware/test/memory/memory-block.c | 76 | ||||
-rw-r--r-- | firmware/test/memory/memory-block.txt | 0 | ||||
-rw-r--r-- | firmware/test/memory/memory-misc.c | 48 | ||||
-rw-r--r-- | firmware/test/memory/memory-misc.txt | 0 | ||||
-rw-r--r-- | firmware/test/memory/memory-page.c | 408 | ||||
-rw-r--r-- | firmware/test/memory/memory-page.h | 59 | ||||
-rw-r--r-- | firmware/test/memory/memory-page.txt | 74 | ||||
-rw-r--r-- | firmware/test/memory/memory-slab.c | 409 | ||||
-rw-r--r-- | firmware/test/memory/memory-slab.h | 62 | ||||
-rw-r--r-- | firmware/test/memory/memory-slab.txt | 0 | ||||
-rw-r--r-- | firmware/test/memory/memory.h | 27 | ||||
-rw-r--r-- | firmware/test/memory/return_values.h | 31 | ||||
-rw-r--r-- | firmware/test/memory/test.l | 23 | ||||
-rw-r--r-- | firmware/test/memory/test.y | 180 | ||||
-rw-r--r-- | firmware/test/memory/types.h | 32 |
20 files changed, 0 insertions, 1638 deletions
diff --git a/firmware/test/memory/config.h b/firmware/test/memory/config.h deleted file mode 100644 index aba52b5599..0000000000 --- a/firmware/test/memory/config.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | #ifndef __LIBRARY_MEMORY_CONFIG_H__ | ||
23 | # define __LIBRARY_MEMORY_CONFIG_H__ | ||
24 | # define PACKAGE_NAME "memory" | ||
25 | # define PACKAGE_VERSION "0.1.1" | ||
26 | # define MEMORY_PAGE_USE_SPLAY_TREE 1 | ||
27 | #endif | ||
diff --git a/firmware/test/memory/defines.h b/firmware/test/memory/defines.h deleted file mode 100644 index 804731cea3..0000000000 --- a/firmware/test/memory/defines.h +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | #ifndef __LIBRARY_MEMORY_DEFINES_H__ | ||
23 | # define __LIBRARY_MEMORY_DEFINES_H__ | ||
24 | # ifndef MEMORY_PAGE_MINIMAL_ORDER | ||
25 | # define MEMORY_PAGE_MINIMAL_ORDER (9) /* 512 bytes */ | ||
26 | # endif | ||
27 | # ifndef MEMORY_PAGE_MAXIMAL_ORDER | ||
28 | # define MEMORY_PAGE_MAXIMAL_ORDER (21) /* 2 Mbytes */ | ||
29 | # endif | ||
30 | # ifndef MEMORY_PAGE_MINIMAL_SIZE | ||
31 | # define MEMORY_PAGE_MINIMAL_SIZE (1 << MEMORY_PAGE_MINIMAL_ORDER) | ||
32 | # endif | ||
33 | # ifndef MEMORY_PAGE_MAXIMAL_SIZE | ||
34 | # define MEMORY_PAGE_MAXIMAL_SIZE (1 << MEMORY_PAGE_MAXIMAL_ORDER) | ||
35 | # endif | ||
36 | # define MEMORY_TOTAL_PAGES (MEMORY_PAGE_MAXIMAL_SIZE / MEMORY_PAGE_MINIMAL_SIZE) | ||
37 | # define MEMORY_TOTAL_BYTES (MEMORY_PAGE_MAXIMAL_SIZE) | ||
38 | # define MEMORY_TOTAL_ORDERS (1 + MEMORY_PAGE_MAXIMAL_ORDER - MEMORY_PAGE_MINIMAL_ORDER) | ||
39 | #endif | ||
diff --git a/firmware/test/memory/functions.h b/firmware/test/memory/functions.h deleted file mode 100644 index c856a934cf..0000000000 --- a/firmware/test/memory/functions.h +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | # ifndef __LIBRARY_MEMORY_FUNCTIONS_H__ | ||
23 | # define __LIBRARY_MEMORY_FUNCTIONS_H__ | ||
24 | |||
25 | ///////////////////////////////////////////////////////////////////// | ||
26 | // MEMORY : | ||
27 | /////////// | ||
28 | |||
29 | extern void memory_copy (void *target,void const *source,unsigned int count); | ||
30 | extern void memory_set (void *target,int byte,unsigned int count); | ||
31 | |||
32 | ///////////////////////////////////////////////////////////////////// | ||
33 | // MEMORY PAGE : | ||
34 | //////////////// | ||
35 | // | ||
36 | // - memory_allocate_page : allocate a page | ||
37 | // - memory_release_page : release a page | ||
38 | // | ||
39 | |||
40 | extern int memory_release_page (void *address); | ||
41 | extern void *memory_allocate_page (int order); | ||
42 | extern void memory_setup (void); | ||
43 | |||
44 | // | ||
45 | ///////////////////////////////////////////////////////////////////// | ||
46 | |||
47 | ///////////////////////////////////////////////////////////////////// | ||
48 | // MEMORY SLAB : | ||
49 | //////////////// | ||
50 | // | ||
51 | // - memory_grow_cache : allocate a new slab for a cache | ||
52 | // - memory_shrink_cache : release free slabs from a cache | ||
53 | // - memory_create_cache : create a new cache of size-fixed blocks | ||
54 | // - memory_destroy_cache : destroy the cache and release all the slabs | ||
55 | // - memory_cache_allocate : allocate a block from the cache | ||
56 | // - memory_cache_release : release a block in the cache | ||
57 | // | ||
58 | |||
59 | extern struct memory_slab *memory_grow_cache (struct memory_cache *cache); | ||
60 | extern int memory_shrink_cache (struct memory_cache *cache,int all); | ||
61 | extern struct memory_cache *memory_create_cache (unsigned int size,int align,int flags); | ||
62 | extern int memory_destroy_cache (struct memory_cache *cache); | ||
63 | extern void *memory_cache_allocate (struct memory_cache *cache); | ||
64 | extern int memory_cache_release (struct memory_cache *cache,void *address); | ||
65 | |||
66 | // | ||
67 | ///////////////////////////////////////////////////////////////////// | ||
68 | |||
69 | /////////////////////////////////////////////////////////////////////////////// | ||
70 | // MEMORY BLOCK : | ||
71 | ///////////////// | ||
72 | // | ||
73 | // - memory_allocate_small_block : allocate a small block (no page) | ||
74 | // - memory_release_small_block : release a small block (no page) | ||
75 | // - memory_allocate_block : allocate a block (or a page) | ||
76 | // - memory_release_block : release a block (or a page) | ||
77 | // | ||
78 | |||
79 | extern void *memory_allocate_small_block (int order); | ||
80 | extern int memory_release_small_block (int order,void *address); | ||
81 | extern void *memory_allocate_block (unsigned int size); | ||
82 | extern int memory_release_block (void *address); | ||
83 | |||
84 | // | ||
85 | ///////////////////////////////////////////////////////////////////// | ||
86 | |||
87 | |||
88 | |||
89 | # ifdef TEST | ||
90 | void memory_spy_page (void *address); | ||
91 | void memory_dump (int order); | ||
92 | void memory_check (int order); | ||
93 | # endif | ||
94 | #endif | ||
diff --git a/firmware/test/memory/inlines.h b/firmware/test/memory/inlines.h deleted file mode 100644 index 003c611153..0000000000 --- a/firmware/test/memory/inlines.h +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | # ifndef __LIBRARY_MEMORY_INLINES_H__ | ||
23 | #define __LIBRARY_MEMORY_INLINES_H__ | ||
24 | |||
25 | |||
26 | #endif | ||
diff --git a/firmware/test/memory/makefile b/firmware/test/memory/makefile deleted file mode 100644 index 2878500e45..0000000000 --- a/firmware/test/memory/makefile +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | ############################################################################# | ||
2 | ## __________ __ ___. | ||
3 | ## Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | ## Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | ## Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | ## Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | ## \/ \/ \/ \/ \/ | ||
8 | ## Copyright Alan Korr, 2002. All rights reserved. | ||
9 | ## | ||
10 | ## Permission to use, copy, modify, and distribute this software for any | ||
11 | ## purpose is hereby granted without fee, provided that this copyright and | ||
12 | ## permissions notice appear in all copies and derivatives, and that no | ||
13 | ## charge may be made for the software and its documentation except to cover | ||
14 | ## cost of distribution. | ||
15 | ## | ||
16 | ## This software is provided "as is" without express or implied warranty. | ||
17 | ############################################################################# | ||
18 | ARCH = test | ||
19 | PACKAGE = memory | ||
20 | VERSION = 0.1.1 | ||
21 | -include ../makefile-vars | ||
22 | -include ../makefile-rules | ||
23 | |||
diff --git a/firmware/test/memory/memory-block.c b/firmware/test/memory/memory-block.c deleted file mode 100644 index c5cf3ce9f8..0000000000 --- a/firmware/test/memory/memory-block.c +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #if 0 | ||
20 | #include <memory.h> | ||
21 | #include "memory-page.h" | ||
22 | #include "memory-slab.h" | ||
23 | |||
24 | static struct memory_cache *__memory_free_block_cache[MEMORY_PAGE_MINIMAL_ORDER - 2]; | ||
25 | |||
26 | /////////////////////////////////////////////////////////////////////////////// | ||
27 | // MEMORY BLOCK : | ||
28 | ///////////////// | ||
29 | // | ||
30 | // - memory_allocate_block : allocate a power-of-2-sized block (or a page) | ||
31 | // - memory_release_block : release a power-of-2-sized block (or a page) | ||
32 | // | ||
33 | |||
34 | static inline void *__memory_allocate_block (int order) | ||
35 | { | ||
36 | struct memory_cache *cache = __memory_free_block_cache[order - 2]; | ||
37 | do | ||
38 | { | ||
39 | if (cache) | ||
40 | return memory_cache_allocate (cache); | ||
41 | } | ||
42 | while ((__memory_free_block_cache[order] = cache = memory_create_cache (size,0,0))); | ||
43 | return MEMORY_RETURN_FAILURE; | ||
44 | } | ||
45 | |||
46 | void *memory_allocate_block (int order) | ||
47 | { | ||
48 | if (order < 2) | ||
49 | order = 2; | ||
50 | if (order < MEMORY_PAGE_MINIMAL_ORDER) | ||
51 | return __memory_allocate_block (order); | ||
52 | if (order < MEMORY_PAGE_MAXIMAL_ORDER) | ||
53 | return memory_allocate_page (order); | ||
54 | return MEMORY_RETURN_FAILURE; | ||
55 | } | ||
56 | |||
57 | static inline int __memory_release_block (int order,void *address) | ||
58 | { | ||
59 | struct memory_cache *cache = __memory_free_block_cache[order - 2]; | ||
60 | if (cache) | ||
61 | return memory_cache_release (cache,address); | ||
62 | return MEMORY_RETURN_FAILURE; | ||
63 | } | ||
64 | |||
65 | int memory_release_block (int order,void *address) | ||
66 | { | ||
67 | if (order < 2) | ||
68 | order = 2; | ||
69 | if (order < MEMORY_PAGE_MINIMAL_ORDER) | ||
70 | return __memory_release_block (order); | ||
71 | if (order < MEMORY_PAGE_MAXIMAL_ORDER) | ||
72 | return memory_release_page (address); | ||
73 | return MEMORY_RETURN_FAILURE; | ||
74 | } | ||
75 | |||
76 | #endif | ||
diff --git a/firmware/test/memory/memory-block.txt b/firmware/test/memory/memory-block.txt deleted file mode 100644 index e69de29bb2..0000000000 --- a/firmware/test/memory/memory-block.txt +++ /dev/null | |||
diff --git a/firmware/test/memory/memory-misc.c b/firmware/test/memory/memory-misc.c deleted file mode 100644 index 765600765b..0000000000 --- a/firmware/test/memory/memory-misc.c +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <memory.h> | ||
20 | #include "memory-page.h" | ||
21 | #if 0 | ||
22 | #include "memory-slab.h" | ||
23 | #endif | ||
24 | |||
25 | /* NOT VERY OPTIMIZED AT ALL BUT WE WILL DO IT WHEN PRIORITY COMES */ | ||
26 | void memory_copy (void *target,void const *source,unsigned int count) | ||
27 | { | ||
28 | while (count--) | ||
29 | *((char *)target)++ = *((char const *)source)++; | ||
30 | } | ||
31 | |||
32 | /* NOT VERY OPTIMIZED AT ALL BUT WE WILL DO IT WHEN PRIORITY COMES */ | ||
33 | void memory_set (void *target,int byte,unsigned int count) | ||
34 | { | ||
35 | while (count--) | ||
36 | *((char *)target)++ = (char)byte; | ||
37 | } | ||
38 | |||
39 | void memory_setup (void) | ||
40 | { | ||
41 | #if 1 | ||
42 | memory_set (__memory_free_page,0,MEMORY_TOTAL_BYTES); | ||
43 | memory_set (__memory_free_page_bin,0,MEMORY_TOTAL_ORDERS *sizeof (struct memory_free_page *)); | ||
44 | memory_set (__memory_free_page_order + 1,0,MEMORY_TOTAL_PAGES); | ||
45 | #endif | ||
46 | __memory_free_page_order[0] = MEMORY_TOTAL_ORDERS - 1; | ||
47 | __memory_free_page_bin[MEMORY_TOTAL_ORDERS - 1] = __memory_free_page; | ||
48 | } | ||
diff --git a/firmware/test/memory/memory-misc.txt b/firmware/test/memory/memory-misc.txt deleted file mode 100644 index e69de29bb2..0000000000 --- a/firmware/test/memory/memory-misc.txt +++ /dev/null | |||
diff --git a/firmware/test/memory/memory-page.c b/firmware/test/memory/memory-page.c deleted file mode 100644 index 1327cf57c9..0000000000 --- a/firmware/test/memory/memory-page.c +++ /dev/null | |||
@@ -1,408 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <memory.h> | ||
20 | #include "memory-page.h" | ||
21 | #if 0 | ||
22 | #include "memory-slab.h" | ||
23 | #endif | ||
24 | |||
25 | #ifdef TEST | ||
26 | |||
27 | // IA32 has no problem with shift operation | ||
28 | static inline unsigned int __memory_get_size (int order) | ||
29 | { | ||
30 | return (MEMORY_PAGE_MINIMAL_SIZE << order); | ||
31 | } | ||
32 | |||
33 | // Arghhhh ! I cannot align 'free_page' on 512-byte boundary (max is 16-byte for Cygwin) | ||
34 | static inline struct memory_free_page *__memory_get_neighbour (struct memory_free_page *node,unsigned int size) | ||
35 | { | ||
36 | return ((struct memory_free_page *)((unsigned)__memory_free_page + (((unsigned)node - (unsigned)__memory_free_page) ^ size))); | ||
37 | } | ||
38 | |||
39 | #else | ||
40 | |||
41 | // SH1 has very poor shift instructions (only <<1,>>1,<<2,>>2,<<8,>>8,<<16 and >>16). | ||
42 | // so we should use a lookup table to speedup. | ||
43 | static inline unsigned int __memory_get_size (int order) | ||
44 | { | ||
45 | static unsigned short size [MEMORY_TOTAL_ORDERS] = | ||
46 | { | ||
47 | 1<<MEMORY_PAGE_MINIMAL_ORDER, | ||
48 | 2<<MEMORY_PAGE_MINIMAL_ORDER, | ||
49 | 4<<MEMORY_PAGE_MINIMAL_ORDER, | ||
50 | 8<<MEMORY_PAGE_MINIMAL_ORDER, | ||
51 | 16<<MEMORY_PAGE_MINIMAL_ORDER, | ||
52 | 32<<MEMORY_PAGE_MINIMAL_ORDER, | ||
53 | 64<<MEMORY_PAGE_MINIMAL_ORDER, | ||
54 | 128<<MEMORY_PAGE_MINIMAL_ORDER, | ||
55 | 256<<MEMORY_PAGE_MINIMAL_ORDER, | ||
56 | 512<<MEMORY_PAGE_MINIMAL_ORDER, | ||
57 | 1024<<MEMORY_PAGE_MINIMAL_ORDER, | ||
58 | 2048<<MEMORY_PAGE_MINIMAL_ORDER, | ||
59 | 4096<<MEMORY_PAGE_MINIMAL_ORDER | ||
60 | }; | ||
61 | return size[order]; | ||
62 | } | ||
63 | |||
64 | static inline struct memory_free_page *__memory_get_neighbour (struct memory_free_page *node,unsigned int size) | ||
65 | { | ||
66 | return ((struct memory_free_page *)((unsigned)node ^ size)); | ||
67 | } | ||
68 | |||
69 | #endif | ||
70 | |||
71 | static inline int __memory_get_order (struct memory_free_page *node) | ||
72 | { | ||
73 | return __memory_free_page_order[node - __memory_free_page]; | ||
74 | } | ||
75 | static inline void __memory_set_order (struct memory_free_page *node,int order) | ||
76 | { | ||
77 | __memory_free_page_order[node - __memory_free_page] = order; | ||
78 | } | ||
79 | |||
80 | #if MEMORY_PAGE_USE_SPLAY_TREE | ||
81 | |||
82 | static struct memory_free_page *__memory_splay_page (struct memory_free_page *root,struct memory_free_page *node) | ||
83 | { | ||
84 | struct memory_free_page *down; | ||
85 | struct memory_free_page *less; | ||
86 | struct memory_free_page *more; | ||
87 | struct memory_free_page head; | ||
88 | head.less = | ||
89 | head.more = 0; | ||
90 | less = | ||
91 | more = &head; | ||
92 | while (1) | ||
93 | { | ||
94 | if (node < root) | ||
95 | { | ||
96 | if ((down = root->less)) | ||
97 | { | ||
98 | if (node < down) | ||
99 | { | ||
100 | root->less = down->more; | ||
101 | down->more = root; | ||
102 | root = down; | ||
103 | if (!root->less) | ||
104 | break; | ||
105 | } | ||
106 | more->less = root; | ||
107 | more = root; | ||
108 | root = root->less; | ||
109 | continue; | ||
110 | } | ||
111 | break; | ||
112 | } | ||
113 | if (root < node) | ||
114 | { | ||
115 | if ((down = root->more)) | ||
116 | { | ||
117 | if (root < node) | ||
118 | { | ||
119 | root->more = down->less; | ||
120 | down->less = root; | ||
121 | root = down; | ||
122 | if (!root->more) | ||
123 | break; | ||
124 | } | ||
125 | less->more = root; | ||
126 | less = root; | ||
127 | root = root->more; | ||
128 | continue; | ||
129 | } | ||
130 | } | ||
131 | break; | ||
132 | } | ||
133 | less->more = root->less; | ||
134 | more->less = root->more; | ||
135 | root->less = head.more; | ||
136 | root->more = head.less; | ||
137 | return root; | ||
138 | } | ||
139 | |||
140 | static inline void __memory_insert_page (int order,struct memory_free_page *node) | ||
141 | { | ||
142 | struct memory_free_page *root = __memory_free_page_bin[order]; | ||
143 | if (!root) | ||
144 | { | ||
145 | node->less = | ||
146 | node->more = 0; | ||
147 | } | ||
148 | else if (node < (root = __memory_splay_page (root,node))) | ||
149 | { | ||
150 | node->less = root->less; | ||
151 | node->more = root; | ||
152 | root->less = 0; | ||
153 | } | ||
154 | else if (node > root) | ||
155 | { | ||
156 | node->less = root; | ||
157 | node->more = root->more; | ||
158 | node->more = 0; | ||
159 | } | ||
160 | __memory_free_page_bin[order] = node; | ||
161 | __memory_set_order (node,order); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | static inline struct memory_free_page *__memory_pop_page (int order,int want) | ||
166 | { | ||
167 | struct memory_free_page *root = __memory_free_page_bin[order]; | ||
168 | if (root) | ||
169 | { | ||
170 | root = __memory_splay_page (root,__memory_free_page); | ||
171 | __memory_free_page_bin[order] = root->more; | ||
172 | __memory_set_order (root,~want); | ||
173 | } | ||
174 | return root; | ||
175 | } | ||
176 | |||
177 | static inline void __memory_remove_page (int order,struct memory_free_page *node) | ||
178 | { | ||
179 | struct memory_free_page *root = __memory_free_page_bin[order]; | ||
180 | root = __memory_splay_page (root,node); | ||
181 | if (root->less) | ||
182 | { | ||
183 | node = __memory_splay_page (root->less,node); | ||
184 | node->more = root->more; | ||
185 | } | ||
186 | else | ||
187 | node = root->more; | ||
188 | __memory_free_page_bin[order] = node; | ||
189 | } | ||
190 | |||
191 | #else | ||
192 | |||
193 | static inline void __memory_insert_page (int order,struct memory_free_page *node) | ||
194 | { | ||
195 | struct memory_free_page *head = __memory_free_page_bin[order]; | ||
196 | node->less = 0; | ||
197 | node->more = head; | ||
198 | if (head) | ||
199 | head->less = node; | ||
200 | __memory_free_page_bin[order] = node; | ||
201 | __memory_set_order (node,order); | ||
202 | } | ||
203 | |||
204 | static inline struct memory_free_page *pop_page (int order,int want) | ||
205 | { | ||
206 | struct memory_free_page *node = __memory_free_page_bin[order]; | ||
207 | if (node) | ||
208 | { | ||
209 | __memory_free_page_bin[order] = node->more; | ||
210 | if (node->more) | ||
211 | node->more->less = 0; | ||
212 | __memory_set_order (node,~want); | ||
213 | } | ||
214 | return node; | ||
215 | } | ||
216 | |||
217 | static inline void __memory_remove_page (int order,struct memory_free_page *node) | ||
218 | { | ||
219 | if (node->less) | ||
220 | node->less->more = node->more; | ||
221 | else | ||
222 | __memory_free_page_bin[order] = node->more; | ||
223 | if (node->more) | ||
224 | node->more->less = node->less; | ||
225 | } | ||
226 | |||
227 | #endif | ||
228 | |||
229 | static inline void __memory_push_page (int order,struct memory_free_page *node) | ||
230 | { | ||
231 | node->less = 0; | ||
232 | node->more = 0; | ||
233 | __memory_free_page_bin[order] = node; | ||
234 | __memory_set_order (node,order); | ||
235 | } | ||
236 | |||
237 | static struct memory_free_page *__memory_allocate_page (unsigned int size,int order) | ||
238 | { | ||
239 | struct memory_free_page *node; | ||
240 | int min = order; | ||
241 | while ((unsigned)order <= (MEMORY_TOTAL_ORDERS - 1)) | ||
242 | // order is valid ? | ||
243 | { | ||
244 | if (!(node = __memory_pop_page (order,min))) | ||
245 | // no free page of this order ? | ||
246 | { | ||
247 | ++order; size <<= 1; | ||
248 | continue; | ||
249 | } | ||
250 | while (order > min) | ||
251 | // split our larger page in smaller pages | ||
252 | { | ||
253 | --order; size >>= 1; | ||
254 | __memory_push_page (order,(struct memory_free_page *)((unsigned int)node + size)); | ||
255 | } | ||
256 | return node; | ||
257 | } | ||
258 | return MEMORY_RETURN_FAILURE; | ||
259 | } | ||
260 | |||
261 | static inline void __memory_release_page (struct memory_free_page *node,unsigned int size,int order) | ||
262 | { | ||
263 | struct memory_free_page *neighbour; | ||
264 | while ((order <= (MEMORY_TOTAL_ORDERS - 1)) && | ||
265 | ((neighbour = __memory_get_neighbour (node,size)), | ||
266 | (__memory_get_order (neighbour) == order))) | ||
267 | // merge our released page with its contiguous page into a larger page | ||
268 | { | ||
269 | __memory_remove_page (order,neighbour); | ||
270 | ++order; size <<= 1; | ||
271 | if (neighbour < node) | ||
272 | node = neighbour; | ||
273 | } | ||
274 | __memory_insert_page (order,node); | ||
275 | } | ||
276 | |||
277 | |||
278 | /*****************************************************************************/ | ||
279 | /* PUBLIC FUNCTIONS */ | ||
280 | /*****************************************************************************/ | ||
281 | |||
282 | void *memory_allocate_page (int order) | ||
283 | { | ||
284 | if (order < 0) | ||
285 | return MEMORY_RETURN_FAILURE; | ||
286 | return __memory_allocate_page (__memory_get_size (order),order); | ||
287 | } | ||
288 | |||
289 | // release a page : | ||
290 | // when called, 'address' MUST be a valid address pointing | ||
291 | // to &dram[i], where i ranges from 0 to MEMORY_TOTAL_PAGES - 1. | ||
292 | // FAILURE if block is already freed. | ||
293 | int memory_release_page (void *address) | ||
294 | { | ||
295 | struct memory_free_page *node = (struct memory_free_page *)address; | ||
296 | int order = ~__memory_get_order (node); | ||
297 | if (order < 0) | ||
298 | return MEMORY_RETURN_FAILURE; | ||
299 | __memory_release_page (node,__memory_get_size (order),order); | ||
300 | return MEMORY_RETURN_SUCCESS; | ||
301 | } | ||
302 | |||
303 | |||
304 | #ifdef TEST | ||
305 | # include <stdio.h> | ||
306 | # include <stdlib.h> | ||
307 | # if MEMORY_PAGE_USE_SPLAY_TREE | ||
308 | |||
309 | void __memory_dump_splay_node (struct memory_free_page *node,int level) | ||
310 | { | ||
311 | if (!node) | ||
312 | return; | ||
313 | __memory_dump_splay_node (node->less,level+1); | ||
314 | printf ("\n%*s[%d-%d]",level,"",(node - __memory_free_page),(node - __memory_free_page) + (1 << __memory_get_order (node)) - 1); | ||
315 | __memory_dump_splay_node (node->more,level+1); | ||
316 | } | ||
317 | |||
318 | void __memory_dump_splay_tree (struct memory_free_page *root) | ||
319 | { | ||
320 | __memory_dump_splay_node (root,2); fflush (stdout); | ||
321 | } | ||
322 | |||
323 | # endif | ||
324 | |||
325 | void __memory_spy_page (void *address) | ||
326 | { | ||
327 | struct memory_free_page *node = (struct memory_free_page *)address; | ||
328 | int order,used; | ||
329 | if (node) | ||
330 | { | ||
331 | order = __memory_get_order (node); | ||
332 | used = order < 0; | ||
333 | if (used) | ||
334 | order = ~order; | ||
335 | printf("\n(%s,%2d,%7d)",(used ? "used" : "free"),order,__memory_get_size (order)); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | void __memory_dump (int order) | ||
340 | { | ||
341 | struct memory_free_page *node = __memory_free_page_bin[order]; | ||
342 | printf("\n(%s,%2d,%7d)",node ? "free" : "none",order,__memory_get_size (order)); | ||
343 | # if MEMORY_PAGE_USE_SPLAY_TREE | ||
344 | __memory_dump_splay_tree (node); | ||
345 | # else | ||
346 | while (node) | ||
347 | { | ||
348 | printf("[%d-%d]",(node - __memory_free_page),(node - __memory_free_page) + (1<<order) - 1); | ||
349 | node = node->more; | ||
350 | } | ||
351 | # endif | ||
352 | |||
353 | } | ||
354 | |||
355 | void __memory_check (int order) | ||
356 | { | ||
357 | struct memory_free_page *node[4096],*swap; | ||
358 | unsigned int i = 0,j = 0; | ||
359 | while (i <= 12) | ||
360 | __memory_dump (i++); | ||
361 | i = 0; | ||
362 | printf ("\nallocating...\n"); | ||
363 | while (order >= 0) | ||
364 | { | ||
365 | j = order; | ||
366 | while ((swap = memory_allocate_page (j))) | ||
367 | { | ||
368 | node[i++] = swap; | ||
369 | printf("[%d-%d]",(swap - __memory_free_page),(swap - __memory_free_page) + ((1 << j)-1)); | ||
370 | for (j += (rand () & 15); j > (unsigned int)order; j -= order); | ||
371 | } | ||
372 | --order; | ||
373 | } | ||
374 | node[i] = 0; | ||
375 | while (j <= 12) | ||
376 | __memory_dump (j++); | ||
377 | j = 0; | ||
378 | printf ("\nreleasing..."); | ||
379 | --i; | ||
380 | while (i > 0) | ||
381 | { | ||
382 | unsigned int k = 0; | ||
383 | # if 0 | ||
384 | printf ("\n"); | ||
385 | # endif | ||
386 | swap = node[k++]; | ||
387 | # if 0 | ||
388 | while (swap) | ||
389 | { | ||
390 | printf("[%d-%d]",(swap - __memory_free_page),(swap - __memory_free_page) + ((1 << ~__memory_get_order (swap))-1)); | ||
391 | swap = node[k++]; | ||
392 | } | ||
393 | # endif | ||
394 | for (j += 1 + (rand () & 15); j >= i; j -= i); | ||
395 | swap = node[j]; | ||
396 | node[j] = node[i]; | ||
397 | memory_release_page (swap); | ||
398 | node[i] = 0; | ||
399 | --i; | ||
400 | } | ||
401 | memory_release_page (node[0]); | ||
402 | i = 0; | ||
403 | while (i <= 12) | ||
404 | __memory_dump (i++); | ||
405 | printf("\n\n%s !",(__memory_get_order (__memory_free_page) == 12) ? "SUCCESS" : "FAILURE"); | ||
406 | } | ||
407 | |||
408 | #endif | ||
diff --git a/firmware/test/memory/memory-page.h b/firmware/test/memory/memory-page.h deleted file mode 100644 index ab360447d7..0000000000 --- a/firmware/test/memory/memory-page.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_PAGE_H__ | ||
20 | #define __LIBRARY_MEMORY_PAGE_H__ | ||
21 | |||
22 | struct memory_free_page | ||
23 | { | ||
24 | struct memory_free_page | ||
25 | *less,*more; | ||
26 | char | ||
27 | reserved[MEMORY_PAGE_MINIMAL_SIZE - 2*sizeof (struct memory_free_page *)]; | ||
28 | }; | ||
29 | |||
30 | #define LESS -1 | ||
31 | #define MORE +1 | ||
32 | |||
33 | #ifdef TEST | ||
34 | |||
35 | struct memory_free_page __memory_free_page[MEMORY_TOTAL_PAGES]; | ||
36 | |||
37 | #else | ||
38 | |||
39 | extern struct memory_free_page __memory_free_page[MEMORY_TOTAL_PAGES] asm("dram"); | ||
40 | |||
41 | #endif | ||
42 | |||
43 | char __memory_free_page_order[MEMORY_TOTAL_PAGES]; | ||
44 | struct memory_free_page *__memory_free_page_bin[MEMORY_TOTAL_ORDERS]; | ||
45 | |||
46 | #ifdef TEST | ||
47 | # if MEMORY_PAGE_USE_SPLAY_TREE | ||
48 | |||
49 | void __memory_dump_splay_node (struct memory_free_page *node,int level); | ||
50 | void __memory_dump_splay_tree (struct memory_free_page *root); | ||
51 | |||
52 | # endif | ||
53 | |||
54 | void __memory_spy_page (void *address); | ||
55 | void __memory_dump (int order); | ||
56 | void __memory_check (int order); | ||
57 | |||
58 | #endif | ||
59 | #endif \ No newline at end of file | ||
diff --git a/firmware/test/memory/memory-page.txt b/firmware/test/memory/memory-page.txt deleted file mode 100644 index 03811f9bde..0000000000 --- a/firmware/test/memory/memory-page.txt +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | Best-fit via binning represent the main ideas of the algorithm. | ||
21 | |||
22 | The memory-page allocator uses an array which contains the power-of-two | ||
23 | orders of each free or used pages to retrieve their sizes. | ||
24 | |||
25 | Available pages are maintained in bins, grouped by size. Depending on | ||
26 | its size, a free page is stored in the bin corresponding to the correct | ||
27 | size range (bins are detailed further): 512 B, 1 KB, 2 KB, 4 KB, 8 KB, | ||
28 | 16 KB, 32 KB, 64 KB, 128 KB, 256 KB, 512 KB, 1 MB or 2 MB. | ||
29 | |||
30 | Searches for available pages are processed in smallest-first, best-fit | ||
31 | order. | ||
32 | |||
33 | Two implementations to chain same-sized pages are provided: | ||
34 | * using doubly linked stack (unordered list) as bin, pages are left | ||
35 | unsorted within bins, so that the best-fit strategy should only be | ||
36 | approximate. | ||
37 | * using splay tree (ordered list) as bin, pages are instead sorted | ||
38 | by address within bins. | ||
39 | |||
40 | Using splay trees is slower than using doubly linked stacks but affords us | ||
41 | to allocate contiguous pages when possible : since doubly linked stack is | ||
42 | not ordered, it cannot warrant a contiguous allocation of pages. However, | ||
43 | there is no evidence that using splay trees really helps unfragmenting | ||
44 | much more than using doubly linked stack. | ||
45 | |||
46 | All procedures maintain the invariant that no free page physically | ||
47 | borders another one (two bordering unused pages are always coalesced | ||
48 | into one larger page). | ||
49 | |||
50 | * Alignment of pages: power-of-two, the same as their sizes. | ||
51 | * Minimum overhead per allocated pages: no overhead. | ||
52 | * Minimum allocated size: minimal page size, i.e, 512 bytes. | ||
53 | * Maximum allocated size: maximal page size, i.e, 2 megabytes. | ||
54 | |||
55 | -- ALGORITHMS ----------------------------------------------------------------- | ||
56 | |||
57 | Unoptimized and recursive algorithm to allocate an N-sized page : | ||
58 | |||
59 | * If there is no pages in the bin of N-sized pages, try to allocate | ||
60 | a (2xN)-sized page and split it into two N-sized pages and free | ||
61 | both if they are not N-sized pages or just free one and keep | ||
62 | the other to mark it used if they are N-sized pages. | ||
63 | |||
64 | Unoptimized and recursive algorithm to release an N-sized page : | ||
65 | |||
66 | * If there is a "contiguous" page, merge it with our N-sized page and | ||
67 | try to release it as a (2xN)-sized page. Otherwise mark it free. | ||
68 | |||
69 | Notes: | ||
70 | * Two pages are "contiguous" if they are also N-aligned and mergeable | ||
71 | as a 2xN-aligned page. | ||
72 | * The address of a "contiguous" page is quickly given by : | ||
73 | |||
74 | address("contiguous" page) = (address(page) ^ size(page)) | ||
diff --git a/firmware/test/memory/memory-slab.c b/firmware/test/memory/memory-slab.c deleted file mode 100644 index 35ab96f787..0000000000 --- a/firmware/test/memory/memory-slab.c +++ /dev/null | |||
@@ -1,409 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #if 0 | ||
20 | #include <memory.h> | ||
21 | #include "memory-page.h" | ||
22 | #include "memory-slab.h" | ||
23 | |||
24 | /////////////////////////////////////////////////////////////////////////////// | ||
25 | // MEMORY SLAB : | ||
26 | //////////////// | ||
27 | // | ||
28 | // | ||
29 | |||
30 | static inline struct memory_slab *__memory_push_slab (struct memory_slab *head,struct memory_slab *node) | ||
31 | { | ||
32 | node->less = head; | ||
33 | if (head) | ||
34 | { | ||
35 | node->more = head->more; | ||
36 | head->more = node; | ||
37 | } | ||
38 | else | ||
39 | node->more = 0; | ||
40 | return node; | ||
41 | } | ||
42 | |||
43 | static inline struct memory_slab *__memory_pop_slab (struct memory_slab *head,struct memory_slab *node) | ||
44 | { | ||
45 | if (head) | ||
46 | head->more = node->more; | ||
47 | return node->more; | ||
48 | } | ||
49 | |||
50 | static inline struct memory_slab *__memory_move_slab (struct memory_slab **from,struct memory_slab **to) | ||
51 | { | ||
52 | struct memory_slab *head = *from; | ||
53 | *from = (*from)->more; | ||
54 | if (*from) | ||
55 | (*from)->less = head->less; | ||
56 | head->less = 0; | ||
57 | head->more = (*to); | ||
58 | if (*to) | ||
59 | (*to)->prev = head; | ||
60 | *to = head; | ||
61 | return head; | ||
62 | } | ||
63 | |||
64 | // | ||
65 | /////////////////////////////////////////////////////////////////////////////// | ||
66 | |||
67 | /////////////////////////////////////////////////////////////////////////////// | ||
68 | // MEMORY CACHE : | ||
69 | ///////////////// | ||
70 | // | ||
71 | // | ||
72 | |||
73 | static struct memory_cache *cache_tree; | ||
74 | |||
75 | static inline int __memory_get_order (unsigned size) | ||
76 | { | ||
77 | int order = 0; | ||
78 | size = (size + sizeof(struct memory_free_block) - 1) & - sizeof(struct memory_free_block); | ||
79 | while (size > 0) | ||
80 | { | ||
81 | ++order; size <<= 1; | ||
82 | } | ||
83 | return order; | ||
84 | } | ||
85 | |||
86 | static inline struct memory_slab *__memory_get_slab (struct memory_cache *cache,void *address) | ||
87 | { | ||
88 | #ifdef TEST | ||
89 | return (struct memory_slab *)((((unsigned)address + cache->page_size) & -cache->page_size) - sizeof (struct memory_slab)); | ||
90 | #else | ||
91 | return (struct memory_slab *)((free_page + (((unsigned)address - free_page + cache->page_size) & -cache->page_size) - sizeof (struct memory_slab))); | ||
92 | #endif | ||
93 | } | ||
94 | |||
95 | static struct memory_cache *__memory_splay_cache (struct memory_cache *root,unsigned int left) | ||
96 | { | ||
97 | struct memory_cache *down; | ||
98 | struct memory_cache *less; | ||
99 | struct memory_cache *more; | ||
100 | struct memory_cache head; | ||
101 | head.less = | ||
102 | head.more = 0; | ||
103 | less = | ||
104 | more = &head; | ||
105 | while (1) | ||
106 | { | ||
107 | if (left < root->left) | ||
108 | { | ||
109 | if ((down = root->less)) | ||
110 | { | ||
111 | if (left < down->left) | ||
112 | { | ||
113 | root->less = down->more; | ||
114 | down->more = root; | ||
115 | root = down; | ||
116 | if (!root->less) | ||
117 | break; | ||
118 | } | ||
119 | more->less = root; | ||
120 | more = root; | ||
121 | root = root->less; | ||
122 | continue; | ||
123 | } | ||
124 | break; | ||
125 | } | ||
126 | if (root->left < left) | ||
127 | { | ||
128 | if ((down = root->more)) | ||
129 | { | ||
130 | if (root->left < left) | ||
131 | { | ||
132 | root->more = down->less; | ||
133 | down->less = root; | ||
134 | root = down; | ||
135 | if (!root->more) | ||
136 | break; | ||
137 | } | ||
138 | less->more = root; | ||
139 | less = root; | ||
140 | root = root->more; | ||
141 | continue; | ||
142 | } | ||
143 | } | ||
144 | break; | ||
145 | } | ||
146 | less->more = root->less; | ||
147 | more->less = root->more; | ||
148 | root->less = head.more; | ||
149 | root->more = head.less; | ||
150 | return root; | ||
151 | } | ||
152 | |||
153 | static inline struct memory_cache *__memory_insert_cache (struct memory_cache *root,struct memory_cache *node) | ||
154 | { | ||
155 | node->less = | ||
156 | node->more = | ||
157 | node->same = 0; | ||
158 | if (root) | ||
159 | { | ||
160 | if (node->left == ((root = __memory_splay_cache (root,node))->left)) | ||
161 | { | ||
162 | node->less = root.less; | ||
163 | node->more = root.more; | ||
164 | node->same = root; | ||
165 | root->less = node; | ||
166 | } | ||
167 | else if (node < root) | ||
168 | { | ||
169 | node->less = root->less; | ||
170 | node->more = root; | ||
171 | root->less = 0; | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | node->less = root; | ||
176 | node->more = root->more; | ||
177 | node->more = 0; | ||
178 | } | ||
179 | } | ||
180 | return node; | ||
181 | } | ||
182 | |||
183 | static inline struct memory_cache *__memory_remove_cache (struct memory_cache *root,struct memory_cache *node) | ||
184 | { | ||
185 | if (root) | ||
186 | { | ||
187 | root = __memory_splay_cache (root,node); | ||
188 | if (root != node) | ||
189 | { | ||
190 | node->less->same = node->same; | ||
191 | if (node->same) | ||
192 | node->same->less = node->less; | ||
193 | return root; | ||
194 | } | ||
195 | if (root->less) | ||
196 | { | ||
197 | node = __memory_splay_page (root->less,node); | ||
198 | node->more = root->more; | ||
199 | } | ||
200 | else | ||
201 | node = root->more; | ||
202 | } | ||
203 | return root; | ||
204 | } | ||
205 | |||
206 | static inline struct memory_cache *__memory_move_cache (struct memory_cache *root,struct memory_cache *node,int delta) | ||
207 | { | ||
208 | if ((root = __memory_remove_cache (root,node))) | ||
209 | { | ||
210 | node->left += delta; | ||
211 | root = __memory_insert_cache (root,node); | ||
212 | } | ||
213 | return root; | ||
214 | } | ||
215 | |||
216 | // | ||
217 | ///////////////////// | ||
218 | // PUBLIC FUNCTIONS : | ||
219 | ///////////////////// | ||
220 | // | ||
221 | // - memory_grow_cache : allocate a new slab for a cache | ||
222 | // - memory_shrink_cache : release free slabs from a cache | ||
223 | // - memory_create_cache : create a new cache of size-fixed blocks | ||
224 | // - memory_destroy_cache : destroy the cache and release all the slabs | ||
225 | // - memory_cache_allocate : allocate a block from the cache | ||
226 | // - memory_cache_release : release a block in the cache | ||
227 | // | ||
228 | |||
229 | struct memory_slab *memory_grow_cache (struct memory_cache *cache) | ||
230 | { | ||
231 | struct memory_slab *slab; | ||
232 | unsigned int page; | ||
233 | if (cache) | ||
234 | { | ||
235 | page = (unsigned int)memory_allocate_page (cache->page_order); | ||
236 | if (page) | ||
237 | { | ||
238 | struct memory_free_block *block,**link; | ||
239 | slab = (struct memory_slab *)(page + cache->page_size - sizeof (struct memory_slab)); | ||
240 | slab->free = 0; | ||
241 | slab->left = 0; | ||
242 | link = &slab->free; | ||
243 | for ((unsigned int)block = page; | ||
244 | (unsigned int)block + cache->size < (unsigned int)slab; | ||
245 | (unsigned int)block += cache->size) | ||
246 | { | ||
247 | *link = block; | ||
248 | link = &block->link; | ||
249 | ++slab->free; | ||
250 | } | ||
251 | *link = 0; | ||
252 | cache->blocks_per_slab = slab->free; | ||
253 | cache->reap = __memory_push_slab (cache->reap,slab); | ||
254 | cache_tree = __memory_move_cache (cache_tree,cache,+1); | ||
255 | return slab; | ||
256 | } | ||
257 | } | ||
258 | return MEMORY_RETURN_FAILURE; | ||
259 | } | ||
260 | |||
261 | static int __memory_shrink_cache (struct memory_cache *cache,int all,int move) | ||
262 | { | ||
263 | struct memory_slab *slab; | ||
264 | unsigned int slabs = 0; | ||
265 | if (cache) | ||
266 | { | ||
267 | while ((slab = cache->reap)) | ||
268 | { | ||
269 | ++slabs; | ||
270 | cache->reap = __memory_pop_slab (cache->reap,slab); | ||
271 | memory_release_page ((void *)slab); | ||
272 | if (all) | ||
273 | continue; | ||
274 | if (move) | ||
275 | cache_tree = __memory_move_cache (cache_tree,cache,-slabs); | ||
276 | return MEMORY_RETURN_SUCCESS; | ||
277 | } | ||
278 | } | ||
279 | return MEMORY_RETURN_FAILURE; | ||
280 | } | ||
281 | |||
282 | int memory_shrink_cache (struct memory_cache *cache,int all) | ||
283 | { | ||
284 | return __memory_shrink_cache (cache,all,1 /* move cache in cache_tree */); | ||
285 | } | ||
286 | |||
287 | struct memory_cache *memory_create_cache (unsigned int size,int align,int flags) | ||
288 | { | ||
289 | struct memory_cache *cache; | ||
290 | unsigned int waste = 0,blocks_per_page; | ||
291 | int page_order; | ||
292 | unsigned int page_size; | ||
293 | unsigned int original_size = size; | ||
294 | |||
295 | // Align size on 'align' bytes ('align' should equal 1<<n) | ||
296 | // if 'align' is inferior to 4, 32-bit word alignment is done by default. | ||
297 | size = (align > 4) ? ((size + align - 1) & -align) : ((size + sizeof (int) - 1) & -sizeof (int)); | ||
298 | if (!(cache = memory_cache_allocate (&cache_cache)) | ||
299 | return MEMORY_RETURN_FAILURE; | ||
300 | |||
301 | cache->flags = | ||
302 | cache->left = 0; | ||
303 | |||
304 | cache->used = | ||
305 | cache->free = | ||
306 | cache->reap = 0; | ||
307 | |||
308 | cache->original_size = original_size; | ||
309 | cache->size = size; | ||
310 | |||
311 | page_size = 0; | ||
312 | page_order = MEMORY_PAGE_MINIMAL_SIZE;; | ||
313 | |||
314 | // Trying to determine what is the best number of pages per slab | ||
315 | for (;; ++order,(page_size <<= 1)) | ||
316 | { | ||
317 | if (page_order >= MEMORY_MAXIMUM_PAGE_ORDER_PER_SLAB) | ||
318 | { | ||
319 | memory_cache_release (&cache_cache,cache); | ||
320 | return MEMORY_RETURN_FAILURE; | ||
321 | } | ||
322 | |||
323 | waste = page_size; | ||
324 | waste -= sizeof (struct memory_slab); | ||
325 | |||
326 | blocks_per_slab = waste / size; | ||
327 | waste -= block_per_slab * size; | ||
328 | |||
329 | if (blocks_per_slab < MEMORY_MINIMUM_BLOCKS_PER_SLAB) | ||
330 | { | ||
331 | ++page_order; page_size <<= 1; | ||
332 | continue; | ||
333 | } | ||
334 | |||
335 | // below 3% of lost space is correct | ||
336 | if ((waste << 16) / page_size) < 1967) | ||
337 | break; | ||
338 | ++page_order; page_size <<= 1; | ||
339 | } | ||
340 | |||
341 | cache->page_size = page_size; | ||
342 | cache->page_order = page_order; | ||
343 | |||
344 | cache_tree = __memory_insert_cache (cache_tree,cache); | ||
345 | |||
346 | return cache; | ||
347 | } | ||
348 | |||
349 | int memory_destroy_cache (struct memory_cache *cache) | ||
350 | { | ||
351 | /* FIX ME : this function shouldn't be called if there are still used blocks */ | ||
352 | if (cache && !cache->free && !cache->used) | ||
353 | { | ||
354 | cache_tree = __memory_remove_cache (cache_tree,cache); | ||
355 | if (__memory_shrink_cache (cache,1 /* release all free slabs */,0 /* don't move in cache_tree */)) | ||
356 | return memory_cache_release (&cache_cache,cache); | ||
357 | } | ||
358 | return MEMORY_RETURN_FAILURE; | ||
359 | } | ||
360 | |||
361 | void *memory_cache_allocate (struct memory_cache *cache) | ||
362 | { | ||
363 | if (cache) | ||
364 | { | ||
365 | do | ||
366 | { | ||
367 | struct memory_slab *slab; | ||
368 | if ((slab = cache->free)) | ||
369 | { | ||
370 | if (slab->left > 0) | ||
371 | { | ||
372 | ok: struct memory_free_block *block = slab->free; | ||
373 | slab->free = block->link; | ||
374 | if (--slab->left == 0) | ||
375 | __memory_move_slab (&cache->free,&cache->used); | ||
376 | return block; | ||
377 | } | ||
378 | } | ||
379 | if (cache->reap) | ||
380 | { | ||
381 | slab = __memory_move_slab (&cache->reap,&cache->free); | ||
382 | cache_tree = __memory_move_cache (cache_tree,cache,-1); | ||
383 | goto ok; | ||
384 | } | ||
385 | } | ||
386 | while (__memory_grow_cache (cache)); | ||
387 | } | ||
388 | return MEMORY_RETURN_FAILURE; | ||
389 | } | ||
390 | |||
391 | int memory_cache_release (struct memory_cache *cache,void *address) | ||
392 | { | ||
393 | struct memory_slab *slab = __memory_get_slab (cache,address); | ||
394 | ((struct memory_free_block *)address)->link = slab->free; | ||
395 | slab->free = (struct memory_free_block *)address; | ||
396 | if (slab->left++ == 0) | ||
397 | __memory_move_slab (&cache->used,&cache->free); | ||
398 | else if (slab->left == cache->blocks_per_slab) | ||
399 | { | ||
400 | __memory_move_slab (&cache->free,&cache->reap); | ||
401 | cache_tree = __memory_move_cache (cache_tree,cache,+1); | ||
402 | } | ||
403 | return MEMORY_RETURN_SUCCESS; | ||
404 | } | ||
405 | |||
406 | // | ||
407 | /////////////////////////////////////////////////////////////////////////////// | ||
408 | |||
409 | #endif | ||
diff --git a/firmware/test/memory/memory-slab.h b/firmware/test/memory/memory-slab.h deleted file mode 100644 index f58897c3ec..0000000000 --- a/firmware/test/memory/memory-slab.h +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_SLAB_H__ | ||
20 | #define __LIBRARY_MEMORY_SLAB_H__ | ||
21 | |||
22 | struct memory_free_block | ||
23 | { | ||
24 | struct memory_free_block | ||
25 | *link; | ||
26 | }; | ||
27 | |||
28 | struct memory_slab | ||
29 | { | ||
30 | struct memory_slab | ||
31 | *less,*more; | ||
32 | unsigned int // left == number of free blocks left | ||
33 | left; | ||
34 | struct memory_free_block | ||
35 | *free; | ||
36 | }; | ||
37 | |||
38 | struct memory_cache | ||
39 | { | ||
40 | struct memory_cache | ||
41 | *less,*more,*same; | ||
42 | unsigned int | ||
43 | left; // number of free slabs | ||
44 | struct memory_slab | ||
45 | *used; | ||
46 | struct memory_slab | ||
47 | *free; | ||
48 | struct memory_slab | ||
49 | *reap; | ||
50 | unsigned int | ||
51 | size,original_size; | ||
52 | unsigned int | ||
53 | page_size; | ||
54 | unsigned int | ||
55 | blocks_per_slab; | ||
56 | int | ||
57 | page_order; | ||
58 | unsigned int | ||
59 | flags; | ||
60 | }; | ||
61 | |||
62 | #endif | ||
diff --git a/firmware/test/memory/memory-slab.txt b/firmware/test/memory/memory-slab.txt deleted file mode 100644 index e69de29bb2..0000000000 --- a/firmware/test/memory/memory-slab.txt +++ /dev/null | |||
diff --git a/firmware/test/memory/memory.h b/firmware/test/memory/memory.h deleted file mode 100644 index fde6ac3ad1..0000000000 --- a/firmware/test/memory/memory.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # define __LIBRARY_MEMORY_H__ | ||
21 | # include <memory/config.h> | ||
22 | # include <memory/defines.h> | ||
23 | # include <memory/types.h> | ||
24 | # include <memory/return_values.h> | ||
25 | # include <memory/inlines.h> | ||
26 | # include <memory/functions.h> | ||
27 | #endif | ||
diff --git a/firmware/test/memory/return_values.h b/firmware/test/memory/return_values.h deleted file mode 100644 index fe3cf8f88d..0000000000 --- a/firmware/test/memory/return_values.h +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | # ifndef __LIBRARY_MEMORY_RETURN_VALUES_H__ | ||
23 | #define __LIBRARY_MEMORY_RETURN_VALUES_H__ | ||
24 | |||
25 | enum | ||
26 | { | ||
27 | MEMORY_RETURN_SUCCESS = 1, | ||
28 | MEMORY_RETURN_FAILURE = 0 | ||
29 | }; | ||
30 | |||
31 | #endif | ||
diff --git a/firmware/test/memory/test.l b/firmware/test/memory/test.l deleted file mode 100644 index 7b938e9330..0000000000 --- a/firmware/test/memory/test.l +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | %{ | ||
2 | #include "test.tab.h" | ||
3 | #define YY_INPUT(buf,result,max_size) \ | ||
4 | result = read_input (buf,max_size); | ||
5 | %} | ||
6 | |||
7 | %s GETNUMBER | ||
8 | |||
9 | %% | ||
10 | |||
11 | <GETNUMBER>[0-9]+ { yylval = atoi(yytext); return NUMBER;} | ||
12 | |||
13 | <INITIAL>"a"|"allocate" { BEGIN GETNUMBER; return ALLOCATE; } | ||
14 | <INITIAL>"r"|"release" { BEGIN GETNUMBER; return RELEASE; } | ||
15 | <INITIAL>"s"|"spy" { BEGIN GETNUMBER; return SPY; } | ||
16 | <INITIAL>"c"|"check" { BEGIN GETNUMBER; return CHECK; } | ||
17 | <INITIAL>"i"|"init" { return INIT; } | ||
18 | <INITIAL>"d"|"dump" { return DUMP; } | ||
19 | <INITIAL>"q"|"quit" { return QUIT; } | ||
20 | [ \t] ; | ||
21 | \n|. { BEGIN 0; return yytext[0]; } | ||
22 | %% | ||
23 | |||
diff --git a/firmware/test/memory/test.y b/firmware/test/memory/test.y deleted file mode 100644 index b3b39acc26..0000000000 --- a/firmware/test/memory/test.y +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | %{ | ||
2 | #include "memory.h" | ||
3 | #include "memory-page.h" | ||
4 | #include <stdlib.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | void allocate (int); | ||
8 | void release (int); | ||
9 | void spy (int); | ||
10 | void dump (void); | ||
11 | void prompt (void); | ||
12 | %} | ||
13 | |||
14 | %token NUMBER | ||
15 | %token ALLOCATE | ||
16 | %token RELEASE | ||
17 | %token DUMP | ||
18 | %token SPY | ||
19 | %token CHECK | ||
20 | %token INIT | ||
21 | %token QUIT | ||
22 | |||
23 | %left '+' '-' | ||
24 | %left '*' '/' | ||
25 | %nonassoc UMINUS | ||
26 | |||
27 | %% | ||
28 | commands | ||
29 | : command ';' | ||
30 | { } | ||
31 | | commands command ';' | ||
32 | { } | ||
33 | | error ';' | ||
34 | { yyerrok; } | ||
35 | ; | ||
36 | |||
37 | command | ||
38 | : allocate | ||
39 | | release | ||
40 | | spy | ||
41 | | check | ||
42 | | INIT | ||
43 | { memory_setup (); } | ||
44 | | DUMP | ||
45 | { dump (); } | ||
46 | | QUIT | ||
47 | { return 0; } | ||
48 | ; | ||
49 | |||
50 | allocate | ||
51 | : ALLOCATE expression | ||
52 | { allocate (yylval); } | ||
53 | ; | ||
54 | |||
55 | release | ||
56 | : RELEASE expression | ||
57 | { release (yylval); } | ||
58 | ; | ||
59 | |||
60 | spy | ||
61 | : SPY expression | ||
62 | { spy (yylval); } | ||
63 | ; | ||
64 | |||
65 | check | ||
66 | : CHECK expression | ||
67 | { __memory_check (yylval); } | ||
68 | ; | ||
69 | |||
70 | expression | ||
71 | : expression '+' expression | ||
72 | { $$ = $1 + $3; } | ||
73 | | expression '-' expression | ||
74 | { $$ = $1 - $3; } | ||
75 | | expression '*' expression | ||
76 | { $$ = $1 * $3; } | ||
77 | | expression '/' expression | ||
78 | { | ||
79 | if($3 == 0) | ||
80 | yyerror("divide by zero"); | ||
81 | else | ||
82 | $$ = $1 / $3; | ||
83 | } | ||
84 | | '-' expression %prec UMINUS | ||
85 | { | ||
86 | $$ = -$2; | ||
87 | } | ||
88 | | '(' expression ')' | ||
89 | { | ||
90 | $$ = $2; | ||
91 | } | ||
92 | | NUMBER | ||
93 | { | ||
94 | $$ = $1; | ||
95 | } | ||
96 | ; | ||
97 | |||
98 | %% | ||
99 | |||
100 | #include <readline/readline.h> | ||
101 | #include <readline/history.h> | ||
102 | |||
103 | int yyerror(char *s) | ||
104 | { | ||
105 | fprintf(stderr,"\nBad command"); | ||
106 | return 1; | ||
107 | } | ||
108 | |||
109 | void prompt (void) | ||
110 | { | ||
111 | printf("\n>"); fflush (stdout); | ||
112 | } | ||
113 | |||
114 | void allocate (int order) | ||
115 | { | ||
116 | void *address; | ||
117 | printf("\nallocating a page of %d bytes...",512<<order); | ||
118 | if ((unsigned)order > 21) | ||
119 | printf (" bad order !"); | ||
120 | else if ((address = memory_allocate_page (order))) | ||
121 | printf (" page #%d allocated !",((char *)address - (char *)__memory_free_page) >> 9); | ||
122 | else | ||
123 | printf (" cannot allocate a page !"); | ||
124 | } | ||
125 | |||
126 | void release (int page) | ||
127 | { | ||
128 | void *address = (void *)((char *)__memory_free_page + (page << 9)); | ||
129 | printf("\nreleasing page #%d...",page); | ||
130 | if ((unsigned)page >= (2*1024*1024/512)) | ||
131 | printf (" bad page number !"); | ||
132 | else if (memory_release_page (address)) | ||
133 | printf (" page #%d released !",page); | ||
134 | else | ||
135 | printf (" cannot release this page !"); | ||
136 | } | ||
137 | |||
138 | void spy (int page) | ||
139 | { | ||
140 | void *address = (void *)((char *)__memory_free_page + (page << 9)); | ||
141 | printf("\nspying page #%d...",page); | ||
142 | if ((unsigned)page >= (2*1024*1024/512)) | ||
143 | printf (" bad page number !"); | ||
144 | else | ||
145 | __memory_spy_page (address); | ||
146 | } | ||
147 | |||
148 | void dump (void) | ||
149 | { | ||
150 | int order; | ||
151 | printf("\ndumping free pages list..."); | ||
152 | for (order = 0; order < 13; ++order) | ||
153 | __memory_dump (order); | ||
154 | } | ||
155 | |||
156 | int main () | ||
157 | { | ||
158 | yyparse(); | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | int read_input (char *buffer,int max) | ||
163 | { | ||
164 | char *line = 0; | ||
165 | while (1) | ||
166 | { | ||
167 | line = readline ("\n>"); | ||
168 | if (!line) | ||
169 | break; | ||
170 | if (*line) | ||
171 | add_history(line); | ||
172 | strncpy (buffer,line,max); | ||
173 | strcat (buffer,";"); | ||
174 | free (line); | ||
175 | return strlen (buffer); | ||
176 | } | ||
177 | buffer[0] = ';'; | ||
178 | return 1; | ||
179 | } | ||
180 | |||
diff --git a/firmware/test/memory/types.h b/firmware/test/memory/types.h deleted file mode 100644 index 4d2be940b5..0000000000 --- a/firmware/test/memory/types.h +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_H__ | ||
20 | # error "This header file must be included ONLY from memory.h." | ||
21 | #endif | ||
22 | #ifndef __LIBRARY_MEMORY_TYPES_H__ | ||
23 | # define __LIBRARY_MEMORY_TYPES_H__ | ||
24 | |||
25 | struct memory_free_page; | ||
26 | struct memory_free_block; | ||
27 | struct memory_slab; | ||
28 | struct memory_cache; | ||
29 | |||
30 | |||
31 | |||
32 | #endif | ||