Overview
Comment: | updates |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
21467a6dc94ca02c7826385aa0f5df25 |
User & Date: | lexi on 2019-06-27 12:13:43 |
Other Links: | manifest | tags |
Context
2019-06-27
| ||
12:17 | fix embarassing example check-in: 3e3a628048 user: lexi tags: trunk | |
12:13 | updates check-in: 21467a6dc9 user: lexi tags: trunk | |
09:57 | add in mechanism to generate syscall tables for x86 linux check-in: 860229e8ce user: lexi tags: trunk | |
Changes
Modified arch/makefile from [8e0dfa3404] to [657c34aa94].
1 -calls.x86.lin.32.s: /usr/include/asm/unistd_32.h 1 +linux-headers = /usr/include/asm/ 2 +calls.x86.lin.32.s: $(linux-headers)/unistd_32.h 2 3 grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@ 3 -calls.x86.lin.64.s: /usr/include/asm/unistd_64.h 4 +calls.x86.lin.64.s: $(linux-headers)/unistd_64.h 4 5 grep "#define __NR_" $< | sed "s;^#define __NR_;%define sys.;" > $@
Modified arch/x86.lin.64.s from [1f6b1a0933] to [2b600a2718].
5 5 %include "calls.x86.lin.64.s" 6 6 7 7 ; syscall ops 8 8 %define sys.call syscall 9 9 10 10 ; register order for syscall convention 11 11 %define sys.reg.n 7 12 +%define sys.reg.ret rax 12 13 %define sys.reg.0 rax 13 14 %define sys.reg.1 rdi 14 15 %define sys.reg.2 rsi 15 16 %define sys.reg.3 rdx 16 17 %define sys.reg.4 r10 17 18 %define sys.reg.5 r8 18 19 %define sys.reg.6 r9 19 20 20 21 ; register order for ccall convention 21 22 %define ccall.reg.ct 6 23 +%define ccall.reg.ret rdi 22 24 %define ccall.reg.0 rdi 23 25 %define ccall.reg.1 rsi 24 26 %define ccall.reg.2 rdx 25 27 %define ccall.reg.3 rcx 26 28 %define ccall.reg.4 r8 27 29 %define ccall.reg.5 r9 28 30
Added kcli/kcli.md version [91db6a8cad].
1 +# kcli 2 +**kcli** is a module that implements common routines used by command-line utilities, such as option parsing, usage display, and more. 3 + 4 +## functions 5 + 6 +### kcli_usage(kcli_set, kiochan) 7 +kcli_usage() takes a `kcli_set` and prints a succinct usage summary to a [kiochan](../kio/kio.md). 8 + 9 +## types 10 + 11 +### struct kcli_set 12 +`kcli_set` is a struct containing information about your program, such as its name, a synopsis of its function, a pointer to `argv`, and a list of `kcli_opt`s. 13 + 14 + * `const char* name` - program name (if null, will be determined from argv instead) 15 + * `size_t argc` - the number of arguments in the `argv` array. 16 + * `const char** argv` - the `argv` pointer passed to the `entry` function, representing the command-line arguments passed to the program. 17 + * `const char* desc` - program description 18 + * `const kcli_param* params` - a list of options expected by the program. 19 + * `size_t paramc` - the number of params in the list to process. 20 + * `const kcli_opt* opts` - a list of options expected by the program. 21 + * `size_t optc` - the number of options in the list to process. 22 + 23 +a kcli_set might be used like so: 24 + 25 + #include <k/core.h> 26 + #include <k/io.h> 27 + #include <k/cli.h> 28 + u8 entry(kenv e) { 29 + kcli_flag aardvark; 30 + kcli_flag zebra; 31 + char* user; 32 + char* password; 33 + long age; 34 + kcli_param* params = { 35 + { "user", kcli_param_string, kcli_class_required, 36 + &user, "the user to log in as" } 37 + // or Kcli_param(user,string,required,"the user to log in as"), 38 + 39 + { "age", kcli_param_dec, kcli_class_optional, 40 + &age, "the age of the user" } 41 + // or Kcli_param(age,dec,optional,"the age of the user"), 42 + }; 43 + kcli_opt* options = { 44 + { 'a', "aardvark", kcli_opt_flag, &aardvark, 45 + "a nocturnal burrowing mammal" }, 46 + // or Kcli_opt(aardvark, 'a', flag, "a nocturnal burrowing mammal") 47 + { 'z', "zebra", kcli_opt_flag, &zebra, 48 + "a striped equine" }, 49 + { 'p', "password", kcli_opt_string, &password, 50 + "the password to log in with" } 51 + }; 52 + kcli_set me = { 53 + "demo", e.argc, e.argv, 54 + "a demonstration of the kcli_set type", 55 + params, Kmsz(params), 56 + options, Kmsz(options) 57 + }, 58 + size_t args_parsed = kcli_parse(&me); 59 + if (args_parsed == 0) { kcli_usage(&me, e.err); return 1; } 60 + 61 + return 0; 62 + } 63 + 64 +### struct kcli_opt 65 +a `kcli_opt` is a representation of a command-line flag and its function. each option must have a unique `id` and/or a unique `name`. 66 + 67 + * `char id` - the short single-character form of the flag (or NUL for no short form) 68 + * `const char* name` - the long string form of the flag (or NULL for no long form) 69 + * `kcli_opt_kind kind` - enum that describes how the flag will function 70 + * `void* val` - a pointer to an appropriate type to store the return value in. 71 + * `const char* desc` - a description of the flag's purpose and function (or NULL for no description) 72 + 73 +#### enum kcli_opt_kind 74 + 75 + * `kcli_opt_none` - flag is disabled and will not be shown in usage 76 + * `kcli_opt_string` - flag tells kcli to add a string to the list of expected parameters; appropriate string will be returned 77 + * `kcli_opt_oct` - flag tells kcli to add an octal number to the list of expected parameters 78 + * `kcli_opt_dec` - flag tells kcli to add a decimal number to the list of expected parameters 79 + * `kcli_opt_hex` - flag tells kcli to add a hexdecimal number to the list of expected parameters 80 + * `kcli_opt_flag` - flag is an option: will return `kcli_flag_on` if entered at least once, `kcli_flag_off` otherwise. 81 + * `kcli_opt_toggle` - flag toggles value on and off: will return `kcli_flag_on` if entered an odd number of times, `kcli_flag_off` otherwise. 82 + * `kcli_opt_accumulate` - flag increments a value every time it is entered; often used to implement `-v (--verbose)`-style options (e.g. `-vvvv` would return a value of `4`). 83 + 84 +### struct kcli_param 85 +`kcli_param` describes a parameter that may be passed to the program whether or not any flags are passed. 86 + 87 + * `const char* name` - a short name for the parameter 88 + * `kcli_param_kind kind` - the kind of parameter passed 89 + * `kcli_class class` - whether or not the parameter is optional 90 + * `void* val` - a pointer to an appropriate type of variable to fill 91 + * `const char* desc` - a description of the parameter's function 92 + 93 +#### enum kcli_param_kind 94 + * `kcli_param_none` - parameter is disabled and will not be expected or accepted 95 + * `kcli_param_string` - parameter will not be parsed; a raw string will be returned 96 + * `kcli_param_oct` - parameter will be parsed as an octal number 97 + * `kcli_param_dec` - parameter will be parsed as a decimal number 98 + * `kcli_param_hex` - parameter will be parsed as a hexadecimal number 99 + 100 +### enum kcli_class 101 + * `kcli_class_forbidden` - parameter may not be passed 102 + * `kcli_class_optional` - parameter may or may not be passed 103 + * `kcli_class_required` - parameter must be passed 104 + 105 +### enum kcli_flag 106 +results that an option of kind `kcli_opt_flag` can return. 107 + 108 + * `kcli_flag_off = 0` - flag is off 109 + * `kcli_flag_on = 1` - flag is on 110 + 111 +## macros 112 + 113 +### Kcli_param(field, kind, class, description) 114 +a convenience macro for filling out parameter lists. 115 + 116 +`Kcli_param(field,a,b,"description")` is transformed into: 117 + 118 + { "field", kcli_param_a, kcli_class_b, &field, "description" } 119 + 120 +### Kcli_opt(field, kind, class, description) 121 +a convenience macro for filling out option lists. 122 + 123 +`Kcli_opt(name,'n',string,"description")` is transformed into: 124 + 125 + { 'n', "name", kcli_opt_string, &name, "description" }
Added kcore/boot.c version [878278ef2e].
1 +#include "core.h" 2 +extern stat entry(kenv); 3 + 4 +stat _boot(unsigned int argc, char** argv) { 5 + kenv e = { argc, argv }; 6 + return entry(e); 7 +} 8 +
Added kcore/core.h version [bb457bb91b].
1 +#ifndef KIcore 2 +#define KIcore 3 + 4 +typedef unsigned long long sz; 5 +typedef unsigned char stat; 6 + 7 +typedef struct kenv { 8 + sz argc; 9 + char** argv; 10 +} kenv; 11 + 12 +#endif
Added kcore/kcore.md version [28c0315020].
1 +# kcore 2 +**kcore** is the foundation for the rest of libk. it defines types and structs that are needed by every program, and provides the stub that launches a program's "entry" function. 3 + 4 +## entry 5 +when using libk, your program's entry point will not be the `int main(int,char**)` function that libc opens into. libk will call the function `stat entry(kenv)` instead. like libc, the value returned by `entry` will be returned to the host platform. 6 + 7 +## types 8 +kcore contains fixed-width integer types. note that the available of each depends on your platform; compilation will fail if e.g. you try to use a u64 or a u128 on a 32-bit platform, so where exact lengths are not required, you may wish to use the built-in C types instead. 9 + 10 + * `u8` - an unsigned 8-bit integer 11 + * `s8` - a signed 8-bit integer 12 + * `u16` - an unsigned 16-bit integer 13 + * `s16` - a signed 16-bit integer 14 + * `u32` - an unsigned 32-bit integer 15 + * `s32` - a signed 32-bit integer 16 + * `u64` - an unsigned 64-bit integer 17 + * `s64` - a signed 64-bit integer 18 + * `u128` - an unsigned 128-bit integer 19 + * `s128` - a signed 128-bit integer 20 + * `word` - an unsigned integer of platform word-length (e.g. 32 bits on x86.32; 64 on x86.64) 21 + * `sword` - a signed integer of platform word-length (e.g. 32 bits on x86.32; 64 on x86.64) 22 + * `stat` - the type of process return values expected by the platform (usually u8 on linux) 23 + 24 +### struct kenv 25 +`kenv` is a struct that encompasses the environment the program was launched in. 26 + * `kiochan std` - a stereo IO channel for reading and writing to and from stdout. 27 + * `kiochan err` - a mono IO channel for writing to stderr. 28 + * `kvar* env` - a pointer into the program's environment 29 + 30 +### struct kvar 31 +`kvar` is a struct that abstracts over platform environment variables. 32 + * `kstr name` - the name of an environment variable 33 + * `kstr val` - the value of an environment variable 34 + * `char* platform` - a pointer into the platform's underlying representation
Added kcore/makefile version [f0df06fe05].
1 +include ../modmake
Added kcore/start.x86.lin.64.s version [fc26b36617].
1 +; vim: ft=nasm 2 +bits 64 3 +%include "../arch/x86.lin.64.s" 4 +global _start 5 +extern _boot 6 +extern entry; 7 + 8 +_start: 9 + mov rbp, rsp 10 + mov rdi, [rbp + 0] ; argc 11 + lea rsi, [rbp + 8] ; argv 12 + 13 + call _boot; 14 + 15 + mov sys.reg.1, sys.reg.ret 16 + mov sys.reg.0, sys.exit 17 + sys.call
Modified libk.md from [d44feffbdd] to [f5443bdd6c].
178 178 179 179 the AGPL may seem like an inappropriately restrictive license for a project with such grandiose ambitions. it is an ideological choice. i selected it because libk is intended very specifically as a contribution to the *free software* community, a community that i hope will continue to grow at the expense of closed-source ecosystems. i have no interest in enabling people or corporations to profit from keeping secrets, especially not with my own free labor (or anyone else's, for that matter). 180 180 181 181 if you disagree with this philosophy, you are welcome to continue using libc. 182 182 183 183 ## what does the k stand for? 184 184 185 -nothing. it was chosen in reference to libc - the letter C was part of the original roman alphabet, while K was added later by analogy to the Greek kappa ‹κ›. in my native language, the older letter ‹c› can make a number of different sounds based on context, including [k] and [s], while ‹k› is fairly consistently used for the sound [k]. hopefully the analogy is obvious. 185 +nothing. it was chosen in reference to libc - the letter C was part of the original roman alphabet, while K was added later by analogy to the Greek kappa ‹κ›. in my native language, the older letter ‹c› can make a number of different sounds based on context, including [k] and [s], while ‹k› is fairly consistently used for the sound [k]. and for orthographical reasons, [k] is often represented by the digraph ‹ck› - that is, a C followed by a K. hopefully the analogies are obvious. 186 186 187 187 this project has nothing to do with KDE.
Modified modmake from [247b2f15bf] to [e72fb78502].
51 51 #-- linux 52 52 # linux uses the ELF{32,64} binary format, and generating these 53 53 # from yasm is trivial. linux only supports one ABI per format, 54 54 # at least with ELF, so that's all we need to do. 55 55 56 56 #${OUT}/$(mod).%.x86.lin.32.o: %.x86.lin.32.s 57 57 $(call arch,x86.lin.32) 58 - yasm -felf32 $< -o $@ 58 + yasm -gdwarf2 -felf32 $< -o $@ 59 59 60 60 #${OUT}/$(mod).%.x86.lin.64.o: %.x86.lin.64.s 61 61 $(call arch,x86.lin.64) 62 - yasm -felf64 $< -o $@ 62 + yasm -gdwarf2 -felf64 $< -o $@ 63 63 64 64 #-- freebsd 65 65 # the freebsd ABI is different, so it will require different code 66 66 # (though there might be ways to minimize that). freebsd uses the 67 67 # same binary format as Linux (though it also supports a.out and 68 68 # COFF) but because freebsd can interpret multiple different ABIs 69 69 # the object files need to be "branded" with the correct one