libk  Diff

Differences From Artifact [b5a70ac75f]:

  • Executable file build.sh — part of check-in [e50a476efe] at 2019-08-22 02:52:20 on branch trunk — removed sneaky segfault in x86-64 syscall fn where %r8 (the register that contains the pointer to the syscall arguments from the C syscall wrapper, which need to be copied into the correct registers before the kernel is invoked) gets overwritten if the syscall valency > 5, because of overlapping ccall and syscall ABI argument registers - r8 is clobbered by argument 5 and any further attempts to use it as a ptr segfault at best. also modified the report function so that it immediate cancels compilation if a sub-process reports failure. changed allocator function signatures so they can return a condition code if the kernel reports an error; updated example code so it compiles and runs without fault. (user: lexi, size: 9203) [annotate] [blame] [check-ins using]

To Artifact [4c9dbc8e12]:


   146    146   		if test ! "$output" -ot "$src"; then
   147    147   			return
   148    148   		fi
   149    149   	fi
   150    150   	if test "$debug" = yes; then
   151    151   		local dflag="-g dwarf2"
   152    152   	fi
   153         -	report $asm $flags $dflag "-f$bin_fmt" -i "$gen" -i "$PWD" "$src" -o "$output";
          153  +	report $asm $flags $dflag "-f$bin_fmt" -I "$gen" -I "$PWD" -I "arch/$target" "$src" -o "$output";
   154    154   }
   155    155   comp_co()  { comp_c $1 $2 "-c -fPIC"; }
   156    156   comp_c(){
   157    157   	local src=$1
   158    158   	local output=$2
   159    159   	local flags=$3
   160    160   	if test -e "$output"; then
................................................................................
   165    165   	# only rebuild the file if the source file is newer
   166    166   	if test "$debug" = yes; then
   167    167   		local dflag="-g"
   168    168   	else
   169    169   		local dflag="-O4"
   170    170   	fi
   171    171   	if test "$assembly" = yes; then
   172         -		report $cc $src $3 $dflag -std=c11 -isystem "$to" -isystem "$gen" -isystem "arch/" -ffreestanding -nostdlib "-L$to" -masm=intel -fverbose-asm -S "-o$output.s"
          172  +		report $cc $src $3 $dflag -std=c11 -isystem "$to" -isystem "$gen" -isystem "arch/$target" -isystem "$PWD" -ffreestanding -nostdlib "-L$to" -masm=intel -fverbose-asm -S "-o$output.s"
   173    173   	else
   174         -		report $cc $src $3 $dflag -std=c11 -isystem "$to" -isystem "$gen" -isystem "arch/" -ffreestanding -nostdlib "-L$to" "-o$output"
          174  +		report $cc $src $3 $dflag -std=c11 -isystem "$to" -isystem "$gen" -isystem "arch/$target" -isystem "$PWD" -ffreestanding -nostdlib "-L$to" "-o$output"
   175    175   	fi
   176    176   }
   177    177   
   178    178   say "commencing libk build $build at $(timestamp)"
   179    179   # set -x
   180    180   
   181    181   # get type data
   182    182   mkdir -p $gen
   183    183   report $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
   184    184   $gen/typesize > gen/typesize.m
   185    185   
   186         -# generate syscall tables
   187         -if test $posix = yes; then
   188         -	# on posix, we simply abuse CPP to garner a list of syscalls;
   189         -	# the file arch/posix/syscalls contains a list of syscalls
   190         -	# we wish to import; we use sed to transform this into a form
   191         -	# that cpp will fill out for us, producing a table that the
   192         -	# awk scripts can handle and turn into a list of constants.
   193         -	echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part
   194         -	cat arch/posix/syscalls > $gen/system_calls.t.2
   195         -	sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2
   196         -	cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl
   197         -
   198         -	# generate errno tables the same way
   199         -	echo '#include <errno.h>' > $gen/error_codes.t.1 # this is the magic part
   200         -	cat arch/posix/errnos > $gen/error_codes.t.2
   201         -	sed -e 's;^\(.*\)$;k_platform_error_\1 \1;' -i $gen/error_codes.t.2
   202         -	cat $gen/error_codes.t.1 $gen/error_codes.t.2 | cpp -P | grep "^k_platform_error" >$gen/error_codes.tbl # haaaack
   203         -else
   204         -	case $os in
   205         -		*) noimpl 'system call table generation';;
   206         -	esac
   207         -fi
   208         -
   209         -# take the OS-specific system call tables that have been prepared
   210         -# for us above and feed them into awk scripts to generate C headers
   211         -awk -f arch/syscall.awk -v out=s <$gen/system_calls.tbl>$gen/system_calls.s
   212         -awk -f arch/syscall.awk -v out=h <$gen/system_calls.tbl>$gen/system_calls.h
   213         -
   214         -# do the same with our error codes table
   215         -awk -f arch/errtbl.awk <$gen/error_codes.tbl >$gen/error_table.h
   216         -
   217    186   # generate symbol tables for error handling functions
   218    187   mkdir -p "$to/k"
   219    188   awk -f global/gen-conds.awk <global/modules >$to/k/internal.egroup.h
   220    189   awk -f global/gen-ident.awk <global/modules >$gen/internal.ident.c
   221    190   comp_co $gen/internal.ident.c $to/internal.ident.o
   222    191   
   223    192   # first pass: copy all headers into place,