Merge remote branch 'origin/sparc-dev'
[akaros.git] / kern / src / kfs.c
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * Barret Rhoden <brho@cs.berkeley.edu>
4  * See LICENSE for details.
5  */
6
7 #ifdef __SHARC__
8 #pragma nosharc
9 #endif
10
11 #ifdef __DEPUTY__
12 #pragma nodeputy
13 #endif
14
15 #include <kfs.h>
16 #include <string.h>
17 #include <assert.h>
18 #include <ros/error.h>
19
20 #define DECL_PROG(x) \
21     extern uint8_t (COUNT(sizeof(size_t)) _binary_obj_user_apps_##x##_size)[],\
22         (COUNT(_binary_obj_user_apps_##x##_size)_binary_obj_user_apps_##x##_start)[];
23
24 #define KFS_ENTRY(x) {#x, _binary_obj_user_apps_##x##_start, (size_t) _binary_obj_user_apps_##x##_size},
25
26 /*
27  * Hardcode the files included in the KFS.  This needs to be in sync with the
28  * userapps in kern/src/Makefrag.
29  * Make sure to declare it, and add an entry.  Keep MAX_KFS_FILES big enough too
30  */
31 DECL_PROG(roslib_proctests);
32 DECL_PROG(roslib_fptest);
33 DECL_PROG(roslib_null);
34 DECL_PROG(roslib_spawn);
35 DECL_PROG(roslib_hello);
36 DECL_PROG(roslib_mhello);
37 DECL_PROG(roslib_mproctests);
38 DECL_PROG(roslib_measurements);
39 DECL_PROG(parlib_draw_nanwan_standalone);
40 DECL_PROG(parlib_channel_test_client);
41 DECL_PROG(parlib_channel_test_server);
42 DECL_PROG(parlib_hello);
43 DECL_PROG(parlib_matrix);
44 DECL_PROG(parlib_manycore_test);
45 DECL_PROG(parlib_pthread_pthread_test);
46 DECL_PROG(parlib_pthread_blackscholes);
47
48 #ifndef __i386__
49 DECL_PROG(usr_blackscholes);
50 DECL_PROG(usr_streamcluster);
51 DECL_PROG(usr_swaptions);
52 DECL_PROG(usr_bodytrack);
53 DECL_PROG(usr_fluidanimate);
54 DECL_PROG(usr_x264);
55 DECL_PROG(usr_synthetic_procobv_cacheobv_offbwobv);
56 DECL_PROG(usr_synthetic_procplus_cacheplus_offbwplus);
57 DECL_PROG(usr_cpptest);
58 DECL_PROG(usr_condtest);
59 #endif
60
61 struct kfs_entry kfs[MAX_KFS_FILES] = {
62         KFS_ENTRY(roslib_proctests)
63         KFS_ENTRY(roslib_fptest)
64         KFS_ENTRY(roslib_null)
65         KFS_ENTRY(roslib_spawn)
66         KFS_ENTRY(roslib_hello)
67         KFS_ENTRY(roslib_mhello)
68         KFS_ENTRY(roslib_mproctests)
69         KFS_ENTRY(roslib_measurements)
70         KFS_ENTRY(parlib_draw_nanwan_standalone)
71         KFS_ENTRY(parlib_channel_test_client)
72         KFS_ENTRY(parlib_channel_test_server)
73         KFS_ENTRY(parlib_hello)
74         KFS_ENTRY(parlib_matrix)
75         KFS_ENTRY(parlib_manycore_test)
76         KFS_ENTRY(parlib_pthread_pthread_test)
77         KFS_ENTRY(parlib_pthread_blackscholes)
78 #ifndef __i386__
79         KFS_ENTRY(usr_blackscholes)
80         KFS_ENTRY(usr_streamcluster)
81         KFS_ENTRY(usr_swaptions)
82         KFS_ENTRY(usr_bodytrack)
83         KFS_ENTRY(usr_fluidanimate)
84         KFS_ENTRY(usr_x264)
85         KFS_ENTRY(usr_synthetic_procobv_cacheobv_offbwobv)
86         KFS_ENTRY(usr_synthetic_procplus_cacheplus_offbwplus)
87         KFS_ENTRY(usr_cpptest)
88         KFS_ENTRY(usr_condtest)
89 #endif
90 };
91
92 ssize_t kfs_lookup_path(char* path)
93 {
94         for (int i = 0; i < MAX_KFS_FILES; i++)
95                 // need to think about how to copy-in something of unknown length
96                 if (!strncmp(kfs[i].name, path, strlen(path)))
97                         return i;
98         return -EINVAL;
99 }
100
101 /*
102  * Creates a process from the file pointed to by the KFS inode (index)
103  * This should take a real inode or something to point to the real location,
104  * and proc_create shouldn't assume everything is contiguous
105  */
106 struct proc *kfs_proc_create(int kfs_inode)
107 {
108         if (kfs_inode < 0 || kfs_inode >= MAX_KFS_FILES)
109                 panic("Invalid kfs_inode.  Check you error codes!");
110         return proc_create(kfs[kfs_inode].start, kfs[kfs_inode].size);
111 }