Overview
Comment: | partially unfuck x86-32, correct major error in syscall ABI |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f9bf0d662bf0f71e953e9e678cdf0118 |
User & Date: | lexi on 2019-08-20 02:03:37 |
Other Links: | manifest | tags |
Context
2019-08-20
| ||
03:04 | address case where syscall numbers in header derive from deeper includes check-in: 09a1767049 user: lexi tags: trunk | |
02:03 | partially unfuck x86-32, correct major error in syscall ABI check-in: f9bf0d662b user: lexi tags: trunk | |
2019-08-19
| ||
23:57 | add detection loop for syscall headers check-in: c7732c41c9 user: lexi tags: trunk | |
Changes
Modified arch/x86.lin.32.s from [a7ffc6f8bf] to [30df0fa7c9].
1 +; register order for syscall convention 2 +%define sys.reg.n 6 3 +%define sys.reg.ret eax 4 +%define sys.reg.0 eax 5 +%define sys.reg.1 ebx 6 +%define sys.reg.2 ecx 7 +%define sys.reg.3 edx 8 +%define sys.reg.4 esi 9 +%define sys.reg.5 edi 10 + 11 +%define sys.call int 0x80
Modified arch/x86.syscall.64.s from [b26026b9a4] to [43eb022a86].
25 25 26 26 ; syscall ops 27 27 %define sys.call syscall 28 28 29 29 ; register order for syscall convention 30 30 %define sys.reg.n 7 31 31 %define sys.reg.ret rax 32 -%define sys.reg.err rbx 33 32 %define sys.reg.0 rax 34 33 %define sys.reg.1 rdi 35 34 %define sys.reg.2 rsi 36 35 %define sys.reg.3 rdx 37 36 %define sys.reg.4 r10 38 37 %define sys.reg.5 r8 39 38 %define sys.reg.6 r9 40 39
Modified build.sh from [a37c2dbfb1] to [15fc50281c].
66 66 has gcc && _cc=gcc # prefer gcc 67 67 cc=${cc:-$_cc} 68 68 has m4 && _m4=m4 69 69 m4=${m4:-$_m4} 70 70 has nasm && asm=nasm 71 71 has yasm && asm=yasm # prefer yasm 72 72 export gen=${gen:-gen} 73 -library=${libkind:-static} # {static|shared|both} 73 +library=${library:-static} # {static|shared|both} 74 +export verbose=${verbose:-quiet} # {no|quiet|loud} 74 75 75 76 doc=${doc:-yes} 76 77 export doc_html=${doc_html:-yes} 77 78 export doc_pdf=${doc_pdf:-yes} 78 79 export doc_man=${doc_man:-yes} 79 80 80 81 case $library in ................................................................................ 131 132 macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix" 132 133 133 134 if test "$bits" != ""; then 134 135 macro_compile_env="$macro_compile_env -Datom_target_bits=$bits" 135 136 fi 136 137 137 138 138 -comp_mac() { $m4 $macro_compile_env -I "$gen" $3 "$1" > "$2"; } 139 -comp_asm() { $asm "-f$bin_fmt" -i "$gen" $1 -o "$2"; } 139 +if test "$COLORTERM" != ""; then 140 + announce() { 141 + test "$verbose" = "silent" && return 142 + color="$1" cmd="$2"; shift 2; 143 + printf " [1;95m→ [38;5;$color;1m$cmd[m" 144 + for a in "$@"; do 145 + if test ${a:0:1} = "-"; then 146 + printf " [91;3m$a[m"; 147 + else 148 + printf " [94;4m$a[m"; 149 + fi 150 + done 151 + echo 152 + } 153 +else 154 + announce() { shift; echo " --> " $@; } 155 +fi 156 + 157 +# the following function is called to report a command invocation 158 +# the person compiling the library. the first argument should be 159 +# an ansi format string; this is used to color-code the tool being 160 +# launched and thus should be different for each one. 161 +report() { announce $@; shift; $@; } 162 +comp_mac() { 163 + local src=$1 164 + local output=$2 165 + local flags=$3 166 + if test -e "$output"; then 167 + if test ! "$output" -ot "$src"; then 168 + return 169 + fi 170 + fi 171 + $m4 $macro_compile_env -I "$gen" $flags "$src" > "$output" 172 + announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output" 173 + # yes, this is incredibly stupid. if you know a better way, feel 174 + # free to submit a fix. the problem is there's no way to pass > 175 + # to report in such a way that it'll do the right thing, and if 176 + # you just write > it redirects *report's* output, instead of 177 + # m4's. piece of shit that it is, m4 doesn't have any way to emit 178 + # output into a fille - stdout only apparently. tl;dr i hate bash. 179 +} 180 +comp_asm() { 181 + local src=$1 182 + local output=$2 183 + local flags=$3 184 + if test -e "$output"; then 185 + if test ! "$output" -ot "$src"; then 186 + return 187 + fi 188 + fi 189 + report 198 $asm $flags "-f$bin_fmt" -i "$gen" "$src" -o "$output"; 190 +} 140 191 comp_co() { comp_c $1 $2 "-c -fPIC"; } 141 192 comp_c(){ 142 - src=$1 143 - output=$2 144 - flags=$3 145 - $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output" 193 + local src=$1 194 + local output=$2 195 + local flags=$3 196 + if test -e "$output"; then 197 + if test ! "$output" -ot "$src"; then 198 + return 199 + fi 200 + fi 201 + # only rebuild the file if the source file is newer 202 + report 213 $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output" 146 203 } 147 204 148 205 scan() { find "$1" -name "$2"; } 149 206 150 207 say "commencing libk build $build at $(timestamp)" 151 -set -x 208 +# set -x 152 209 153 210 # get type data 154 211 mkdir -p $gen 155 212 $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 156 213 $gen/typesize > gen/typesize.m 157 214 158 215 # generate syscall tables ................................................................................ 197 254 198 255 if test "$doc" = "yes"; then 199 256 global/build-manpage.sh libk.md 200 257 for mod in ${modules[@]}; do 201 258 for doc in $(scan $mod '*.md'); do 202 259 base="$(basename $doc)" 203 260 stem="${base%%.md}" 204 - global/build-manpage.sh "$doc" 261 + report 177 global/build-manpage.sh "$doc" 205 262 done 206 263 done 207 264 fi 208 265 209 266 # third pass: compile sources and save the 210 267 # resulting object files to $out, tracking 211 268 # which is a runtime or function unit. exe's ................................................................................ 245 302 done 246 303 247 304 # fourth pass: link the libraries that are 248 305 # configured to be built 249 306 250 307 if test $build_static_library == yes; then 251 308 for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do 252 - ar rc $out/libk.a $obj 309 + report 120 ar rc $out/libk.a $obj 253 310 done 254 - ranlib $out/libk.a 311 + report 105 ranlib $out/libk.a 255 312 fi 256 313 257 314 if test $build_shared_library == yes; then 258 - ld -r ${rt_objects[@]} -o $out/boot.o 259 - ld -shared ${fn_objects[@]} -o $out/libk.so 315 + report 216 ld -r ${rt_objects[@]} -o $out/boot.o 316 + report 216 ld -shared ${fn_objects[@]} -o $out/libk.so 260 317 fi 261 318 262 319 # fifth pass: compile the executable tools 263 320 # against the libraries created in pass 5 264 321 265 322 for mod in ${modules[@]}; do 266 323 for exe in $(scan $mod '*.exe.c'); do
Modified global/build-manpage.sh from [790e90297c] to [5a75b066a8].
51 51 echo >>"$fmt" ".SH DESCRIPTION" 52 52 53 53 tail -n+$(expr $descline + $offset) "$file" | cmark -t man >> "$fmt" 54 54 55 55 test "$doc_html" = "yes" && { 56 56 mkdir -p "$htmldest" 57 57 groff -Thtml -Kutf8 -m man "$fmt" > "$html" 58 + test "$verbose" != "loud" || 58 59 say "wrote html page for $stem to $html" 59 60 } 60 61 61 62 test "$doc_pdf" = "yes" && { 62 63 mkdir -p "$pdfdest" 63 64 groff -Tpdf -Kutf8 -m man "$fmt" > "$pdf" 65 + test "$verbose" != "loud" || 64 66 say "wrote pdf for $stem to $pdf" 65 67 } 66 68 67 69 test "$doc_man" = "yes" && { 68 70 mkdir -p "$mandest" 69 71 70 72 if has gzip; then 71 73 man="$man.gz" 72 74 gzip -c -f "$fmt" > "$man" 73 75 else 74 76 mv "$fmt" "$man" 75 77 fi 76 78 79 + test "$verbose" != "loud" || 77 80 say "wrote manpage for $stem to $man" 78 81 }
Modified kcore/syscall.fn.x86.lin.64.s from [f9a360108d] to [27d79c3e63].
49 49 %assign i 0 50 50 %rep 6 51 51 handle_arg i 52 52 %assign i i+1 53 53 %endrep 54 54 55 55 ; valency >= 7. this is not valid, so 56 - ; we set our return value to 0 and the 56 + ; we set our return value to -1 and the 57 57 ; error number to its maximum value in 58 58 ; order to indicate that the syscall 59 59 ; was invalid 60 - mov qword [rbx], 0 60 + mov qword [rbx], -1 61 61 mov qword [r12], -1 62 62 ret 63 63 64 64 ; we have a valency match - perform the 65 65 ; requested syscall already store in rax 66 66 .perform_call: sys.call 67 + 68 + ; check for an error - on x86, error is 69 + ; returned as a negative value in %rax 70 + test sys.reg.ret, sys.reg.ret 71 + js .error ; jump if sign flag set 67 72 68 73 ; move our return values into place and 69 74 ; return to the caller (which should 70 75 ; always be k_platform_syscall, btw) 71 - mov [rbx], sys.reg.ret 72 - mov [r12], sys.reg.err 76 + mov [rbx], sys.reg.ret 77 + mov qword [r12], 0 ; no error 73 78 ret 79 + 80 + ; an error was returned - we need to set 81 + ; the errno to its positive equivalent, 82 + ; and store -1 in the return variable 83 + .error: neg sys.reg.ret 84 + mov qword [rbx], -1 85 + mov [r12], sys.reg.ret 86 + ret
Name change from kcore/exit.fn.x86.lin.32.s to legacy/exit.fn.x86.lin.32.s.
Name change from kcore/exit.fn.x86.lin.64.s to legacy/exit.fn.x86.lin.64.s.
Modified libk.md from [a982938576] to [a1a4077789].
173 173 * `cc=<autodetect> {executable}` - the compiler to compile C sources with 174 174 * `m4=<autodetect> {executable}` - the m4 binary to compile the macro sources with 175 175 * `asm=<autodetect> {executable}` - the assembler to assemble the assembly listings with. it must take Intel-syntax input and handle nasm-style macros. only `yasm` and `nasm` are likely to be viable. 176 176 * `doc=yes {yes|no}` - whether to typeset the documentation (very slow with all three formats set to "yes") 177 177 * `doc_html=yes {yes|no}` - enable or disable html output of the documentation 178 178 * `doc_pdf=yes {yes|no}` - enable or disable pdf output of the documentation 179 179 * `doc_man=yes {yes|no}` - enable or disable manpage output of the documentation 180 + * `verbose=quiet {silent|quiet|loud}` - control level of verbosity. `silent` silences most output. 180 181 181 182 two other shell scripts complete the build system: 182 183 * `install.sh` - installs compiled libraries, objects, documentation, and headers into the appropriate directories. 183 184 184 185 # design principles 185 186 186 187 there are four overriding principles that guide the design of libk.