Mercurial > hg > Members > anatofuz > CbC_xv6
changeset 61:b3a3224e1823
fix link arguments...
author | anatofuz |
---|---|
date | Thu, 11 Jul 2019 18:51:52 +0900 |
parents | e5f099108a6e |
children | a28580a75faa |
files | src/CMakeLists.txt src/gearsTools/pmake.pl src/lib/string.c src/string.c src/usr/CMakeLists.txt |
diffstat | 5 files changed, 156 insertions(+), 151 deletions(-) [+] |
line wrap: on
line diff
--- a/src/CMakeLists.txt Thu Jul 11 16:12:16 2019 +0900 +++ b/src/CMakeLists.txt Thu Jul 11 18:51:52 2019 +0900 @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.8) project(xv6cbc C ASM) add_subdirectory(tools) +add_subdirectory(usr) set(USE_CUDA,0) @@ -10,13 +11,11 @@ # -DCMAKE_BUILD_TYPE=Debug set(CMAKE_C_FLAGS_DEBUG "-O0") add_definitions(${PMAKE_ARGS}) -set(CMAKE_C_COMPILER "${CBC_COM}") #add_custom_command(OUTPUT tools # COMMAND "cd ${CMAKE_CURRENT_SOURCE_DIR}/tools && make run" #) # #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools -add_subdirectory(usr) if (${USE_CUDA}) @@ -32,8 +31,12 @@ endif() include_directories(".") +configure_file("${CMAKE_SOURCE_DIR}/kernel-cmake.ld" "${CMAKE_CURRENT_BINARY_DIR}/kernel-cmake.ld" COPYONLY) macro( GearsCommand ) + set(CMAKE_C_COMPILER "${CBC_COM}") + set(CMAKE_LINKER "${X_CMAKE_LINKER}") + set(CMAKE_C_LINK_EXECUTABLE "${X_CMAKE_C_LINK_EXECUTABLE}") set( _OPTIONS_ARGS ) set( _ONE_VALUE_ARGS TARGET ) set( _MULTI_VALUE_ARGS SOURCES ) @@ -64,6 +67,7 @@ endif() endforeach(i) + #target_link_libraries(syslib) add_custom_command ( OUTPUT c/${_Gears_TARGET}-context.c DEPENDS ${_Gears_CBC_SOURCES} @@ -78,8 +82,8 @@ TARGET kernel SOURCES - lib/string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc + string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c - lib/string.c entry.S + entry.S )
--- a/src/gearsTools/pmake.pl Thu Jul 11 16:12:16 2019 +0900 +++ b/src/gearsTools/pmake.pl Thu Jul 11 18:51:52 2019 +0900 @@ -23,15 +23,15 @@ chomp($libgcc = `$cc --print-libgcc-file-name`); $cflags .= " $libgcc"; $cmake .= 3; - $ldflags = " -L. -T kernel-cmake.ld $libgcc -b binary initcode fs.img"; + $ldflags = " -L. -T kernel-cmake.ld"; } $cflags =~ s/\n//g; create_link_script(); #cmake -DCMAKE_LINKER=/path/to/linker -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" -print_exec_system($cmake, "-DCBC_COM=$cc", "-DPMAKE_ARGS=\"$cflags\"","-DCMAKE_ASM_COMPILER=$cc","-DCMAKE_LINKER=$ld","-DCMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags <OBJECTS> -o kernel.elf\"","-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE",'.'); +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\"","-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE",'.'); system("make"); -system("sh","link.sh"); +#system("sh","link.sh"); sub create_link_script { my @link_script;
--- a/src/lib/string.c Thu Jul 11 16:12:16 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -#include "types.h" -#include "arm.h" - - -void* memset(void *dst, int v, int n) -{ - uint8 *p; - uint8 c; - uint32 val; - uint32 *p4; - - p = dst; - c = v & 0xff; - val = (c << 24) | (c << 16) | (c << 8) | c; - - // set bytes before whole uint32 - for (; (n > 0) && ((uint)p % 4); n--, p++){ - *p = c; - } - - // set memory 4 bytes a time - p4 = (uint*)p; - - for (; n >= 4; n -= 4, p4++) { - *p4 = val; - } - - // set leftover one byte a time - p = (uint8*)p4; - - for (; n > 0; n--, p++) { - *p = c; - } - - return dst; -} - - -int memcmp(const void *v1, const void *v2, uint n) -{ - const uchar *s1, *s2; - - s1 = v1; - s2 = v2; - - while(n-- > 0){ - if(*s1 != *s2) { - return *s1 - *s2; - } - - s1++, s2++; - } - - return 0; -} - -void* memmove(void *dst, const void *src, uint n) -{ - const char *s; - char *d; - - s = src; - d = dst; - - if(s < d && s + n > d){ - s += n; - d += n; - - while(n-- > 0) { - *--d = *--s; - } - - } else { - while(n-- > 0) { - *d++ = *s++; - } - } - - return dst; -} - -// memcpy exists to placate GCC. Use memmove. -void* memcpy(void *dst, const void *src, uint n) -{ - return memmove(dst, src, n); -} - -int strncmp(const char *p, const char *q, uint n) -{ - while(n > 0 && *p && *p == *q) { - n--, p++, q++; - } - - if(n == 0) { - return 0; - } - - return (uchar)*p - (uchar)*q; -} - -char* strncpy(char *s, const char *t, int n) -{ - char *os; - - os = s; - - while(n-- > 0 && (*s++ = *t++) != 0) - ; - - while(n-- > 0) { - *s++ = 0; - } - - return os; -} - -// Like strncpy but guaranteed to NUL-terminate. -char* safestrcpy(char *s, const char *t, int n) -{ - char *os; - - os = s; - - if(n <= 0) { - return os; - } - - while(--n > 0 && (*s++ = *t++) != 0) - ; - - *s = 0; - return os; -} - -int strlen(const char *s) -{ - int n; - - for(n = 0; s[n]; n++) - ; - - return n; -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/string.c Thu Jul 11 18:51:52 2019 +0900 @@ -0,0 +1,144 @@ +#include "types.h" +#include "arm.h" + + +void* memset(void *dst, int v, int n) +{ + uint8 *p; + uint8 c; + uint32 val; + uint32 *p4; + + p = dst; + c = v & 0xff; + val = (c << 24) | (c << 16) | (c << 8) | c; + + // set bytes before whole uint32 + for (; (n > 0) && ((uint)p % 4); n--, p++){ + *p = c; + } + + // set memory 4 bytes a time + p4 = (uint*)p; + + for (; n >= 4; n -= 4, p4++) { + *p4 = val; + } + + // set leftover one byte a time + p = (uint8*)p4; + + for (; n > 0; n--, p++) { + *p = c; + } + + return dst; +} + + +int memcmp(const void *v1, const void *v2, uint n) +{ + const uchar *s1, *s2; + + s1 = v1; + s2 = v2; + + while(n-- > 0){ + if(*s1 != *s2) { + return *s1 - *s2; + } + + s1++, s2++; + } + + return 0; +} + +void* memmove(void *dst, const void *src, uint n) +{ + const char *s; + char *d; + + s = src; + d = dst; + + if(s < d && s + n > d){ + s += n; + d += n; + + while(n-- > 0) { + *--d = *--s; + } + + } else { + while(n-- > 0) { + *d++ = *s++; + } + } + + return dst; +} + +// memcpy exists to placate GCC. Use memmove. +void* memcpy(void *dst, const void *src, uint n) +{ + return memmove(dst, src, n); +} + +int strncmp(const char *p, const char *q, uint n) +{ + while(n > 0 && *p && *p == *q) { + n--, p++, q++; + } + + if(n == 0) { + return 0; + } + + return (uchar)*p - (uchar)*q; +} + +char* strncpy(char *s, const char *t, int n) +{ + char *os; + + os = s; + + while(n-- > 0 && (*s++ = *t++) != 0) + ; + + while(n-- > 0) { + *s++ = 0; + } + + return os; +} + +// Like strncpy but guaranteed to NUL-terminate. +char* safestrcpy(char *s, const char *t, int n) +{ + char *os; + + os = s; + + if(n <= 0) { + return os; + } + + while(--n > 0 && (*s++ = *t++) != 0) + ; + + *s = 0; + return os; +} + +int strlen(const char *s) +{ + int n; + + for(n = 0; s[n]; n++) + ; + + return n; +} +
--- a/src/usr/CMakeLists.txt Thu Jul 11 16:12:16 2019 +0900 +++ b/src/usr/CMakeLists.txt Thu Jul 11 18:51:52 2019 +0900 @@ -50,6 +50,7 @@ endmacro() add_library(ulib STATIC ulib.c usys.S printf.c umalloc.c) +#add_library(syslib string.c) set(USRCOMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello)