b167f00d0977cff895fbf670d29abff3ce882544
[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_measurements);
38 DECL_PROG(parlib_draw_nanwan_standalone);
39 DECL_PROG(parlib_channel_test_client);
40 DECL_PROG(parlib_channel_test_server);
41 DECL_PROG(parlib_hello);
42 DECL_PROG(parlib_matrix);
43 DECL_PROG(parlib_manycore_test);
44 DECL_PROG(parlib_pthread_pthread_test);
45 DECL_PROG(parlib_pthread_blackscholes);
46
47 #ifndef __i386__
48 DECL_PROG(usr_blackscholes);
49 DECL_PROG(usr_streamcluster);
50 DECL_PROG(usr_swaptions);
51 DECL_PROG(usr_bodytrack);
52 DECL_PROG(usr_fluidanimate);
53 DECL_PROG(usr_x264);
54 DECL_PROG(usr_synthetic_procobv_cacheobv_offbwobv);
55 DECL_PROG(usr_synthetic_procplus_cacheplus_offbwplus);
56 DECL_PROG(usr_cpptest);
57 DECL_PROG(usr_condtest);
58 #endif
59
60 struct kfs_entry kfs[MAX_KFS_FILES] = {
61         KFS_ENTRY(roslib_proctests)
62         KFS_ENTRY(roslib_fptest)
63         KFS_ENTRY(roslib_null)
64         KFS_ENTRY(roslib_spawn)
65         KFS_ENTRY(roslib_hello)
66         KFS_ENTRY(roslib_mhello)
67         KFS_ENTRY(roslib_measurements)
68         KFS_ENTRY(parlib_draw_nanwan_standalone)
69         KFS_ENTRY(parlib_channel_test_client)
70         KFS_ENTRY(parlib_channel_test_server)
71         KFS_ENTRY(parlib_hello)
72         KFS_ENTRY(parlib_matrix)
73         KFS_ENTRY(parlib_manycore_test)
74         KFS_ENTRY(parlib_pthread_pthread_test)
75         KFS_ENTRY(parlib_pthread_blackscholes)
76 #ifndef __i386__
77         KFS_ENTRY(usr_blackscholes)
78         KFS_ENTRY(usr_streamcluster)
79         KFS_ENTRY(usr_swaptions)
80         KFS_ENTRY(usr_bodytrack)
81         KFS_ENTRY(usr_fluidanimate)
82         KFS_ENTRY(usr_x264)
83         KFS_ENTRY(usr_synthetic_procobv_cacheobv_offbwobv)
84         KFS_ENTRY(usr_synthetic_procplus_cacheplus_offbwplus)
85         KFS_ENTRY(usr_cpptest)
86         KFS_ENTRY(usr_condtest)
87 #endif
88 };
89
90 ssize_t kfs_lookup_path(char* path)
91 {
92         for (int i = 0; i < MAX_KFS_FILES; i++)
93                 // need to think about how to copy-in something of unknown length
94                 if (!strncmp(kfs[i].name, path, strlen(path)))
95                         return i;
96         return -EINVAL;
97 }
98
99 /*
100  * Creates a process from the file pointed to by the KFS inode (index)
101  * This should take a real inode or something to point to the real location,
102  * and env_create shouldn't assume everything is contiguous
103  */
104 struct proc *kfs_proc_create(int kfs_inode)
105 {
106         if (kfs_inode < 0 || kfs_inode >= MAX_KFS_FILES)
107                 panic("Invalid kfs_inode.  Check you error codes!");
108         struct proc* p = env_create();
109         if(p != NULL)
110                 env_load_icode(p,NULL,kfs[kfs_inode].start, kfs[kfs_inode].size);
111         return p;
112 }