Permalink
Browse files

add functions for directly binfing to newlib, and related C enums and…

… structs. add the option to turn off executable autodetection in embedded FS. fix hello.c to create /out if it doesn't exist.
  • Loading branch information...
wolfwood committed Oct 14, 2011
1 parent 815fa11 commit 6bbdd98edab6606f66ab8d68f71226ea0c2d0e81
Showing with 887 additions and 59 deletions.
  1. +10 −1 app/c/hello/hello.c
  2. +21 −6 app/d/init/embeddedfs.d
  3. +381 −0 user/c/c.d
  4. +475 −52 user/c/csyscall.d
View
@@ -34,7 +34,7 @@ int main(int argc, char** argv){
printf("\n");
- int wfd = open("/out", O_WRONLY);
+ int wfd = open("/out", O_WRONLY|O_CREAT);
char* moo = "The quick brown w0lfwood jumped over the lazy cl0ckw0rk.\n";
@@ -53,5 +53,14 @@ int main(int argc, char** argv){
printf("/ARGV\n");
+ printf("stat size: %d\n", sizeof(struct stat));
+ printf("dev_t size: %d\n", sizeof(dev_t));
+ printf("ino_t size: %d\n", sizeof(ino_t));
+ printf("mode_t size: %d\n", sizeof(mode_t));
+ printf("nlink_t size: %d\n", sizeof(nlink_t));
+ printf("uid_t size: %d\n", sizeof(uid_t));
+ printf("gid_t size: %d\n", sizeof(gid_t));
+ printf("off_t size: %d\n", sizeof(off_t));
+ printf("time_t size: %d\n", sizeof(time_t));
return 0;
}
View
@@ -30,21 +30,33 @@ struct EmbeddedFS{
return xsh;
}
- //private:
- File xsh;
-
- template makeFile(char[] filename){
+ template makeFile(char[] filename, bool autodetect = true, bool iself = true){
File makeFile(){
const char[] actualFilename = "/" ~ filename;
// import file
ubyte[] data = cast(ubyte[])import(filename);
// create minFS file
- File f = MinFS.open(actualFilename, AccessMode.Writable|AccessMode.AllocOnAccess|AccessMode.User|AccessMode.Executable, true);
+ File f;
+ bool elf;
+ AccessMode accessmode = AccessMode.Writable|AccessMode.AllocOnAccess|AccessMode.User;
+
+ // figure out if its an elf binary
+ static if(autodetect){
+ elf = Elf.isValid(data.ptr);
+ }else{
+ elf = iself;
+ }
+
+ if(elf){
+ accessmode |= AccessMode.Executable;
+ }
+
+ f = MinFS.open(actualFilename, accessmode, true);
// populate
- if(Elf.isValid(data.ptr)){
+ if(elf){
Loader.load(data, f);
}else{
int spacer = ulong.sizeof;
@@ -60,4 +72,7 @@ struct EmbeddedFS{
return f;
}
}
+
+private:
+ File xsh;
}
Oops, something went wrong.

0 comments on commit 6bbdd98

Please sign in to comment.