changeset 94:d876c9a65239 default tip

impl mac os target
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 23 Oct 2019 14:31:38 +0900
parents 7d0ec88cdd22
children
files src/CMakeLists.txt src/arm.c src/context.h src/gearsTools/pmake.pl src/usr/CMakeLists.txt
diffstat 5 files changed, 117 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/src/CMakeLists.txt	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/CMakeLists.txt	Wed Oct 23 14:31:38 2019 +0900
@@ -1,10 +1,23 @@
 cmake_minimum_required(VERSION 3.8)
-project(xv6cbc C ASM)
+project(xv6cbc NONE)
 set(BUILD_DIR ${PROJECT_BINARY_DIR})
+
+
 add_subdirectory(tools)
 add_subdirectory(usr)
 enable_language(C ASM)
 
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  set(CMAKE_SYSROOT "${CBC_XV6_SYSROOT}")
+  set(CMAKE_OSX_SYSROOT "${CBC_XV6_SYSROOT}")
+  include_directories("${CMAKE_OSX_SYSROOT}")
+  include_directories("${CMAKE_OSX_SYSROOT}/usr/include")
+  include_directories("${CMAKE_OSX_SYSROOT}/usr/include/arm-linux-gnueabihf")
+  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+endif()
 
 set(USE_CUDA,0)
 # -DUSE_CUDA
@@ -39,6 +52,8 @@
 macro( GearsCommand )
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXV6KERNEL")
     set(CMAKE_C_COMPILER "${CBC_COM}")
+    set(CMAKE_ASM_COMPILER "${CBC_COM}")
+
     set(CMAKE_LINKER "${X_CMAKE_LINKER}")
     set(CMAKE_C_LINK_EXECUTABLE "${X_CMAKE_C_LINK_EXECUTABLE}")
     set( _OPTIONS_ARGS )
--- a/src/arm.c	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/arm.c	Wed Oct 23 14:31:38 2019 +0900
@@ -125,3 +125,4 @@
     }
 
 }
+
--- a/src/context.h	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/context.h	Wed Oct 23 14:31:38 2019 +0900
@@ -10,10 +10,18 @@
 #include "helper_cuda.h"
 #endif
 
-#include "types.h"
-#include "use_context_numbers.h"
-#include "fs.h"
-#include "defs.h"
+#ifndef NULL
+# if defined __GNUG__ && \
+    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define NULL (__null)
+# else
+#  if !defined(__cplusplus)
+#   define NULL ((void*)0)
+#  else
+#   define NULL (0)
+#  endif
+# endif
+#endif
 
 #ifdef XV6KERNEL
 #define calloc(a,b)  kmalloc((a)*(b))
@@ -463,21 +471,8 @@
         struct Context* lockContext;
     } SpinLock;
     /* CbCxv6 cbc_context*/
-    struct Inode {
-      uint    dev;        // Device number
-      uint    inum;       // Inode number
-      int     ref;        // Reference count
-      int     flags;      // I_BUSY, I_VALID
-
-      short   type;       // copy of disk inode
-      short   major;
-      short   minor;
-      short   nlink;
-      uint    size;
-      uint    addrs[NDIRECT+1];       
-    } Inode;
     struct Uinteger {
-        uint value;
+        unsigned int value;
     } Uinteger;
     struct Short {
        short value;
@@ -485,26 +480,6 @@
     struct String {
       char* string;
     } String;
-    // fs.h ---
-    struct SuperBlock {
-      uint    size;           // Size of file system image (blocks)
-      uint    nblocks;        // Number of data blocks
-      uint    ninodes;        // Number of inodes.
-      uint    nlog;           // Number of log blocks
-    } SuperBlock;
-    struct Dinode {
-      short   type;       // copy of disk inode
-      short   major;
-      short   minor;
-      short   nlink;
-      uint    size;
-      uint    addrs[NDIRECT+1];       
-    } Dinode;
-    struct Dirent {
-      ushort inum;
-      char   name[DIRSIZ];
-    } Dirent;
-    // --- fs.h
 }; // union Data end       this is necessary for cbc_context generator
 
 typedef union Data Data;
--- a/src/gearsTools/pmake.pl	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/gearsTools/pmake.pl	Wed Oct 23 14:31:38 2019 +0900
@@ -3,19 +3,67 @@
 use warnings;
 use FindBin;
 use Cwd 'getcwd';
+use File::Path 'rmtree';
 
 my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_ld_command);
 
+my $curdir = getcwd;
+
+if (@ARGV) {
+  if ($ARGV[0] =~ /--delete/) {
+    my @current_dir_file = glob "*";
+    map { print "$_\n";} @current_dir_file;
+    print "delete all files? > [y/n]\n";
+    my $ans = <STDIN>;
+    if ($ans =~ /y/) {
+      print "delete ...\n";
+      map { rmtree $_ } @current_dir_file;
+    }
+  }
+}
+
 $cmake = 'cmake';
+my @cmake_arg = ();
+my $xv6_src_dir = $FindBin::Bin;
+$xv6_src_dir =~  s|(.*)/gearsTools(.*)|$1|;
+
 
 if ($^O =~ /darwin/){
-    $cc      = $ENV{CBC_LANG_COMPILER};
-    $cflags  = qq|-Wall -g -arch arm -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 
-             -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare 
-             -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
-             -Wno-nullability-completeness -Wno-expansion-to-defined"|;
-    $ldflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-  
-             -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0|;
+    $cc      = "$ENV{CBC_LANG_COMPILER}-7.0";
+    $asm     = "$ENV{CBC_LANG_COMPILER}-7.0";
+    $cflags  = qq|-Wall -g --target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -DCBCXV6=1  -g -O0   -nodefaultlibs
+             -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare  
+             -Wno-nullability-completeness -Wno-expansion-to-defined |;
+    $cflags .= ' -B' . $ENV{HOME} .'/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0';
+    $cflags .= ' --gcc-toolchain=arm-linux-gnueabihf-raspbian';
+             #$ld = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/lld';
+             #$ld = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/ld.lld';
+    $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld';
+
+    #$libgcc = '/Users/anatofuz/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0/libgcc.a';
+    $libgcc = '/usr/local/lib/gcc/arm-none-eabi/7.3.1/libgcc.a';
+    #chomp($libgcc = `$cc --print-libgcc-file-name`);
+    $ldflags = " -L. -T kernel-cmake.ld";
+    $kernel_cflags   = '--target=armv6-linux-gnueabihf  -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../   -c';
+    # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags  -o kernel.elf <OBJECTS> $libgcc   -b binary initcode usr/fs.img\"
+    $kernel_ld_flags =  ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>  -L ../ ' . $libgcc;
+    #$kernel_ld_flags =  ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>' ;
+    $kernel_ld_command = "$ld $kernel_ld_flags";
+    $initcode_cflags = '--target=armv6-linux-gnueabihf   -nostdinc  -c';
+    $initcode_ld_command = "$ld -L.  -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>";
+
+    my $arm_library = '/Users/anatofuz/workspace/cr/arm_library';
+
+    push(@cmake_arg,
+      "-DCBC_XV6_SYSROOT=\"$arm_library\"",
+      # "-DCMAKE_OSX_SYSROOT=\"$arm_library\"",
+      #"-DCMAKE_AR=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"",
+      #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"",
+      "-DCMAKE_AR=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ar\"",
+      "-DCMAKE_RANLIB=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ranlib\"",
+      # "-DCMAKE_OSX_XV6_INCLUDE_DIR=\"$arm_library/usr/include\"",
+    );
+
 } else {
     $cc     = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc';
     $asm    = $cc;
@@ -31,26 +79,27 @@
     $kernel_ld_command = "$ld $kernel_ld_flags";
     $initcode_cflags = '-march=armv6   -nostdinc  -c';
     $initcode_ld_command = "$ld -L.  -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>";
+
+    $cflags =~ s/\n//g;
 }
 
-$cflags =~ s/\n//g;
-create_link_script();
-my $curdir = getcwd;
-my $xv6_src_dir = $FindBin::Bin;
-$xv6_src_dir =~  s|(.*)/gearsTools(.*)|$1|;
+push(@cmake_arg,
+   "-DCBC_COM=$cc",
+   "-DPMAKE_ARGS=\"$cflags\"",
+  "-DCBC_ASM_COMPILER=$cc",
+  "-DX_CMAKE_LINKER=$ld",
+  "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags  -o kernel.elf <OBJECTS> $libgcc   -b binary initcode fs.img\"",
+  "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"",
+  "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE",
+  "-DINITOCDE_CFLAGS=\"$initcode_cflags\"",
+  "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"",
+  "-S $xv6_src_dir",
+  $curdir);
 
-print_exec_system($cmake,
-     "-DCBC_COM=$cc",
-     "-DPMAKE_ARGS=\"$cflags\"",
-    "-DCMAKE_ASM_COMPILER=$cc",
-    "-DX_CMAKE_LINKER=$ld",
-    "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags  -o kernel.elf <OBJECTS> $libgcc   -b binary initcode fs.img\"",
-    "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"",
-    "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE",
-    "-DINITOCDE_CFLAGS=\"$initcode_cflags\"",
-    "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"",
-    "-S $xv6_src_dir",
-$curdir);
+unshift(@cmake_arg, $cmake);
+
+create_link_script();
+print_exec_system(@cmake_arg);
 
 system("make");
 #system("sh","link.sh");
@@ -127,17 +176,3 @@
 binary \
 initcode \
 fs.img 
-
-__END__
-
-=encoding utf-8
-
-=head1 NAME
-
-pmake.pl - pmake is a wrapper at cmake in xv6.
-
-=head1 SYNOPSIS
-
-     pmake.pl <build directory> <cbcxv6 src direcory>
-
-=cut
--- a/src/usr/CMakeLists.txt	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/usr/CMakeLists.txt	Wed Oct 23 14:31:38 2019 +0900
@@ -2,6 +2,18 @@
 set(CMAKE_C_COMPILER "/usr/bin/cc")
 project(usr C ASM)
 
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+  set(CMAKE_SYSROOT "${CBC_XV6_SYSROOT}")
+  set(CMAKE_OSX_SYSROOT "${CBC_XV6_SYSROOT}")
+  include_directories("${CMAKE_OSX_SYSROOT}")
+  include_directories(SYSTEM "${CMAKE_OSX_SYSROOT}/usr/include")
+  include_directories(SYSTEM "${CMAKE_OSX_SYSROOT}/usr/include/arm-linux-gnueabihf")
+  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+endif()
+
 
 set(CMAKE_C_FLAGS_DEBUG "-O0")
 add_definitions(${PMAKE_ARGS})
@@ -12,6 +24,7 @@
 set(CMAKE_C_LINK_EXECUTABLE "${KERNEL_LINK_EXECUTABLE}")
 set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LIB} -nostdlib")
 
+
 macro( GearsCommand )
     include_directories(${CMAKE_SOURCE_DIR})
     include_directories(${CMAKE_SOURCE_DIR}/usr)
@@ -61,7 +74,7 @@
 #add_library(syslib string.c)
 
 # set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello)
-set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh hello)
+set(USR_COMMANDS ls echo grep init kill ln cat mkdir rm sh hello)
 
 foreach(cmd ${USR_COMMANDS}) 
     GearsCommand (TARGET _${cmd} SOURCES ${cmd}.c)