Comment: | reorganize posix assembly code |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f85e6a07dd2dc8d917fc927dde153fdb |
User & Date: | lexi on 2019-08-20 22:54:49 |
Other Links: | manifest | tags |
2019-08-21
| ||
00:16 | switch ansi "bold off" code to "reset" for terminals that interpret "bold off" as "double underline"; remove (incorrect) test code from kiosend check-in: cef83f0167 user: lexi tags: trunk | |
2019-08-20
| ||
22:54 | reorganize posix assembly code check-in: f85e6a07dd user: lexi tags: trunk | |
04:04 | improve syscall collection mechanism check-in: 9dd8bab2ac user: lexi tags: trunk | |
Deleted arch/posix.h version [676bf37092].
1 -/* arch/posix.h - posix constants 2 - * ? this file defines posix magic numbers 3 - * needed in syscalls, both cross-platform 4 - * ones and os-dependent ones. note that 5 - * the values may change depending on the 6 - * OS specified! */ 7 - 8 -#ifndef KIplatform_posix 9 -#define KIplatform_posix 10 -#include <k/def.h> 11 -#include <k/type.h> 12 - 13 -#if (!defined(KFplatform_define_constants)) && \ 14 - (!defined(KFplatform_define_types)) && \ 15 - (!defined(KFplatform_define_funcs)) 16 -#define KFplatform_define_constants 17 -#define KFplatform_define_types 18 -#define KFplatform_define_funcs 19 -#endif 20 - 21 -#ifdef KFplatform_define_constants 22 - 23 -enum posix_prot { 24 - posix_prot_none = 0, 25 - posix_prot_read = 1 << 0, 26 - posix_prot_write = 1 << 1, 27 - posix_prot_exec = 1 << 2 28 -}; 29 - 30 -enum posix_map { 31 - posix_map_shared = 1, 32 - posix_map_private = 2 33 -}; 34 - 35 -enum posix_flag { 36 - posix_flag_fixed = 0x10, 37 -#if KVos == KA_os_lin 38 - posix_flag_anonymous = 0x20, 39 -#elif KVos == KA_os_fbsd 40 - posix_flag_anonymous = 0x1000, 41 -#endif 42 - 43 - /* platform flags */ 44 - posix_flag_linux_hugetlb = 0x40000 45 -}; 46 - 47 -#endif 48 -#ifdef KFplatform_define_types 49 - 50 -/* platform types */ 51 - 52 -typedef s64 k_platform_syscall_return; 53 -typedef u64 k_platform_syscall_error; 54 - 55 -#if KVos == KA_os_lin 56 - typedef long k_platform_syscall_arg; 57 -#elif KVos == KA_os_fbsd 58 - typedef u64 k_platform_syscall_arg; 59 -#else 60 - /* we're going to just pick a sane 61 - * fallback that's reasonably likely 62 - * to work with most systems one way 63 - * or another */ 64 - typedef unsigned long long k_platform_syscall_arg; 65 -#endif 66 - 67 -struct k_platform_syscall_answer { 68 - k_platform_syscall_return ret; 69 - k_platform_syscall_error error; 70 -}; 71 - 72 -#endif 73 - 74 -#if defined(KFplatform_define_constants) ||\ 75 - defined(KFplatform_define_funcs) 76 -# include <system_calls.h> 77 -#endif 78 - 79 -#ifdef KFplatform_define_funcs 80 - 81 -extern struct k_platform_syscall_answer 82 -k_platform_syscall(enum k_platform_syscall call, u8 valency, 83 - k_platform_syscall_arg args[]); 84 - 85 -#endif 86 - 87 -#endif
Added arch/posix/posix.h version [676bf37092].
1 +/* arch/posix.h - posix constants 2 + * ? this file defines posix magic numbers 3 + * needed in syscalls, both cross-platform 4 + * ones and os-dependent ones. note that 5 + * the values may change depending on the 6 + * OS specified! */ 7 + 8 +#ifndef KIplatform_posix 9 +#define KIplatform_posix 10 +#include <k/def.h> 11 +#include <k/type.h> 12 + 13 +#if (!defined(KFplatform_define_constants)) && \ 14 + (!defined(KFplatform_define_types)) && \ 15 + (!defined(KFplatform_define_funcs)) 16 +#define KFplatform_define_constants 17 +#define KFplatform_define_types 18 +#define KFplatform_define_funcs 19 +#endif 20 + 21 +#ifdef KFplatform_define_constants 22 + 23 +enum posix_prot { 24 + posix_prot_none = 0, 25 + posix_prot_read = 1 << 0, 26 + posix_prot_write = 1 << 1, 27 + posix_prot_exec = 1 << 2 28 +}; 29 + 30 +enum posix_map { 31 + posix_map_shared = 1, 32 + posix_map_private = 2 33 +}; 34 + 35 +enum posix_flag { 36 + posix_flag_fixed = 0x10, 37 +#if KVos == KA_os_lin 38 + posix_flag_anonymous = 0x20, 39 +#elif KVos == KA_os_fbsd 40 + posix_flag_anonymous = 0x1000, 41 +#endif 42 + 43 + /* platform flags */ 44 + posix_flag_linux_hugetlb = 0x40000 45 +}; 46 + 47 +#endif 48 +#ifdef KFplatform_define_types 49 + 50 +/* platform types */ 51 + 52 +typedef s64 k_platform_syscall_return; 53 +typedef u64 k_platform_syscall_error; 54 + 55 +#if KVos == KA_os_lin 56 + typedef long k_platform_syscall_arg; 57 +#elif KVos == KA_os_fbsd 58 + typedef u64 k_platform_syscall_arg; 59 +#else 60 + /* we're going to just pick a sane 61 + * fallback that's reasonably likely 62 + * to work with most systems one way 63 + * or another */ 64 + typedef unsigned long long k_platform_syscall_arg; 65 +#endif 66 + 67 +struct k_platform_syscall_answer { 68 + k_platform_syscall_return ret; 69 + k_platform_syscall_error error; 70 +}; 71 + 72 +#endif 73 + 74 +#if defined(KFplatform_define_constants) ||\ 75 + defined(KFplatform_define_funcs) 76 +# include <system_calls.h> 77 +#endif 78 + 79 +#ifdef KFplatform_define_funcs 80 + 81 +extern struct k_platform_syscall_answer 82 +k_platform_syscall(enum k_platform_syscall call, u8 valency, 83 + k_platform_syscall_arg args[]); 84 + 85 +#endif 86 + 87 +#endif
Added arch/posix/syscalls version [24a70b57fd].
1 +exit 2 +read 3 +write 4 +mmap 5 +munmap
Added arch/posix/x86.fbsd.32.s version [fb0cced6da].
1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall numbers - syscall table must be created first! 5 +%include "system_calls.s" 6 + 7 +; extremely stupid freebsd-ism: expects the syscall to 8 +; come from a function 9 +_syscall: int 0x80 10 + ret 11 + 12 +%define sys.call call _syscall 13 + 14 +; parameters are passed on the stack 15 +%macro syscall 1-* 16 + mov eax, %1 17 + %rep %0-1 18 + %rotate 1 19 + push %1 20 + %endrep 21 + sys.call 22 + add esp, 4*(%0-1) 23 +%endmacro
Added arch/posix/x86.fbsd.64.s version [8f1b903740].
1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall numbers - syscall table must be created first! 5 +%include "system_calls.s" 6 + 7 +; freebsd uses the common x86-64 ABI 8 +%include "x86.syscall.64.s"
Added arch/posix/x86.lin.32.s version [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
Added arch/posix/x86.lin.64.s version [58546ff139].
1 +;; abi definition file for x86 linux 64-bit 2 +; vim: ft=nasm 3 + 4 +; syscall64 numbers - syscall table must be created first! 5 +%include "system_calls.s" 6 + 7 +; linux uses the common x86-64 ABI 8 +%include "../x86.syscall.64.s" 9 +
Deleted arch/x86.fbsd.32.s version [fb0cced6da].
1 -;; abi definition file for x86 linux 64-bit 2 -; vim: ft=nasm 3 - 4 -; syscall numbers - syscall table must be created first! 5 -%include "system_calls.s" 6 - 7 -; extremely stupid freebsd-ism: expects the syscall to 8 -; come from a function 9 -_syscall: int 0x80 10 - ret 11 - 12 -%define sys.call call _syscall 13 - 14 -; parameters are passed on the stack 15 -%macro syscall 1-* 16 - mov eax, %1 17 - %rep %0-1 18 - %rotate 1 19 - push %1 20 - %endrep 21 - sys.call 22 - add esp, 4*(%0-1) 23 -%endmacro
Deleted arch/x86.fbsd.64.s version [8f1b903740].
1 -;; abi definition file for x86 linux 64-bit 2 -; vim: ft=nasm 3 - 4 -; syscall numbers - syscall table must be created first! 5 -%include "system_calls.s" 6 - 7 -; freebsd uses the common x86-64 ABI 8 -%include "x86.syscall.64.s"
Deleted arch/x86.lin.32.s version [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
Deleted arch/x86.lin.64.s version [a477b8d971].
1 -;; abi definition file for x86 linux 64-bit 2 -; vim: ft=nasm 3 - 4 -; syscall64 numbers - syscall table must be created first! 5 -%include "system_calls.s" 6 - 7 -; linux uses the common x86-64 ABI 8 -%include "x86.syscall.64.s" 9 -
Modified build.sh from [5f22a34160] to [520c125701].
187 187 mkdir -p $gen 188 188 $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 189 189 $gen/typesize > gen/typesize.m 190 190 191 191 # generate syscall tables 192 192 if test $posix = yes; then 193 193 # on posix, we simply abuse CPP to garner a list of syscalls; 194 - # the file arch/posix_syscalls contains a list of syscalls 194 + # the file arch/posix/syscalls contains a list of syscalls 195 195 # we wish to import; we use sed to transform this into a form 196 196 # that cpp will fill out for us, producing a table that the 197 197 # awk scripts can handle and turn into a list of constants. 198 198 echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part 199 - cat arch/posix_syscalls > $gen/system_calls.t.2 199 + cat arch/posix/syscalls > $gen/system_calls.t.2 200 200 sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2 201 201 cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl 202 202 else 203 203 case $os in 204 204 # lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;; 205 205 # fbsd) grep -h "#define SYS_" $p_headers_syscall | sed 's;^#define SYS_;;' | sed 's;[\t ]\+; ;' > $gen/system_calls.tbl;; 206 206 *) noimpl 'system call table generation';;
Modified kcore/boot.rt.x86.lin.64.s from [22c891476d] to [c4c48f7422].
1 1 ; vim: ft=nasm 2 2 bits 64 3 -%include "../arch/x86.lin.64.s" 3 +%include "../arch/posix/x86.lin.64.s" 4 4 global _start:function 5 5 extern _boot 6 6 extern entry 7 7 8 8 _start: 9 9 mov rbp, rsp 10 10 mov rdi, [rbp + 0] ; argc
Modified kcore/platform.syscall.fn.c from [4315e80d93] to [9c61e189e0].
7 7 * implementation may vary drastically. 8 8 */ 9 9 10 10 #include <k/def.h> 11 11 #include <k/type.h> 12 12 13 13 #ifdef KFenv_posix 14 -# include <posix.h> 14 +# include <posix/posix.h> 15 15 #else 16 16 Knoimpl(k_platform_syscall) 17 17 #endif 18 18 19 19 extern void k_platform_syscall_raw ( 20 20 k_platform_syscall_return* return_slot, 21 21 k_platform_syscall_error* error_no_slot,
Modified kcore/stop.fn.c from [092afab243] to [1f91f150ef].
5 5 6 6 #include <k/core.h> 7 7 #include <k/def.h> // so we know what system this is 8 8 #include <k/type.h> 9 9 #ifdef KFenv_posix 10 10 # define KFplatform_define_types 11 11 # define KFplatform_define_constants 12 -# include <posix.h> 12 +# include <posix/posix.h> 13 13 #endif 14 14 15 +/* this manual redefinition is necessary to stop gcc 16 + * bitching that kstop returns, which it def does not */ 15 17 noreturn extern struct k_platform_syscall_answer 16 18 k_platform_syscall(enum k_platform_syscall call, u8 valency, 17 19 k_platform_syscall_arg args[]); 18 20 19 21 noreturn void kstop(stat_long code) { 20 22 # ifdef KFenv_posix 21 23 k_platform_syscall_arg exit_code[] = { code }; 22 24 k_platform_syscall(k_platform_syscall_exit, 1, exit_code); 23 25 # else 24 26 Knoimpl(kstop) 25 27 # endif 26 28 } 27 29
Modified kcore/syscall.fn.x86.lin.64.s from [27d79c3e63] to [472ad3a7d3].
7 7 ; altogether and access the error value of a 8 8 ; syscall directly. invoke as: 9 9 ; 10 10 ; void k_platform_syscall_raw(s64* result, u64* errno, 11 11 ; syscall, u8 valency, s64[] args) 12 12 13 13 bits 64 14 -%include "../arch/x86.lin.64.s" 14 +%include "../arch/posix/x86.lin.64.s" 15 15 %include "../arch/x86.cdecl.64.s" 16 16 ; vim: ft=nasm 17 17 18 18 %macro handle_arg 1 19 19 %assign v %1+1 20 20 mov sys.reg. %+ v, [ccall.reg.4 + 8 * %1] 21 21 dec ccall.reg.3
Modified kio/send.fn.c from [f571b39492] to [3d6d32a7c0].
6 6 * kiosend() writes to a channel with an open out stream 7 7 */ 8 8 9 9 /* we define all platform functions here, 10 10 * whether or not they're for the correct 11 11 * platform - only the ones actually called 12 12 * by the generated code will be linked */ 13 -#include <posix.h> 13 +#include <posix/posix.h> 14 14 #include <error_table.h> 15 15 16 16 kiocond kiosend(kiochan target, ksraw string, sz* len) { 17 17 if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream; 18 18 19 19 # ifdef KFenv_posix 20 20 /* issue the write syscall here and now so we can
Modified kmem/heapa.fn.c from [8818444ab8] to [641176b71f].
1 1 #include <k/mem.h> 2 2 #include <k/core.h> 3 3 #include <k/def.h> 4 4 #include <k/type.h> 5 -#include <posix.h> 6 5 /* heapa.c - kmheapa() "heap alloc" 7 6 * ~ lexi hale <lexi@hale.su> 8 7 * kmheapa() allocates a pointer on the heap à la libc malloc() 9 8 * see also: kmheapf() "heap free" 10 9 */ 11 10 12 -/* we define all platform functions here, 13 - * whether or not they're for the correct 14 - * platform - only the ones actually called 15 - * by the generated code will be linked, 16 - * linker errors are our friend here! */ 11 +/* arch specific headers */ 12 +#ifdef KFenv_posix 13 +# include <posix/posix.h> 14 +#endif 15 + 16 +/* we define all our platform functions here, whether or not 17 + * they're for the correct platform - only the ones that are 18 + * called by the preprocessed form of the code will actually 19 + * be linked, linker errors are our friend here! */ 17 20 extern void* kmem_platform_mmap(void* addr, 18 21 unsigned long sz, unsigned long prot, unsigned long flags, 19 22 unsigned long fd, unsigned long off); 20 23 21 24 void* kmheapa(sz len) { 22 25 /* allocate an object on the heap and return 23 26 * a pointer, or NULL if the allocation failed. */ 24 27 union { 25 28 void* raw; 26 29 ubyte* byte; 27 30 kmbox* header; 28 31 } region; 29 - /* we need to allocate space for the header and 30 - * for the actual object */ 32 + /* we need to allocate space for the 33 + * header and for the actual object */ 31 34 sz region_size = sizeof(kmbox) + len; 32 35 33 36 # ifdef KFenv_posix 34 - /* posix APIs - we've got it easy. currently for nonlinear 35 - * heap allocation kmheapa simply uses m(un)map and lets the 36 - * kernel worry about it. it may ultimately be worth replacing 37 - * this with a more sophisticated implementation, most likely 38 - * an existing allocator like jemalloc, though i'm wary of 39 - * including outside code - it creates a licensing mess and 40 - * i'd prefer libk to be AGPLv3 across the board. possibility: 41 - * include hooks for multiple allocators, allowing the user 42 - * to select & link in her preferred allocator at compile time? */ 37 + /* posix APIs - we've got it easy. currently for 38 + * nonlinear heap allocation kmheapa simply uses 39 + * m(un)map and lets the kernel worry about it. it 40 + * may ultimately be worth replacing this with a 41 + * more sophisticated implementation, most likely an 42 + * existing allocator like jemalloc, though i'm wary 43 + * of including outside code - it creates a licensing 44 + * mess and i'd prefer libk to be AGPLv3 across the 45 + * board. possibility: include hooks for multiple 46 + * allocators, allowing the user to select & link in 47 + * her preferred allocator at compile time? */ 43 48 44 49 /* because munmap needs to be informed of the size of 45 - * the region it is going to unmap, we need to store 46 - * that information in the allocated region itself. 47 - * the user will be given a pointer that can be 48 - * adjusted to point a field of type size_t that 49 - * contains the size of the allocate space.*/ 50 + * the region we are going to unmap, we need to store 51 + * that information in the region that we are mapping. 52 + * the user will receive an adjusted pointer that can 53 + * be adjusted to point a field of type size_t that 54 + * contains the size of the allocated space.*/ 50 55 51 56 region.byte = kmem_platform_mmap(null, region_size, 52 57 posix_prot_read | posix_prot_write, 53 58 posix_flag_anonymous | posix_map_shared, -1, 0); 54 59 /* impl note: while per manpage fd is "ignored" 55 60 * for MAP_ANONYMOUS, "some implementations" require 56 61 * a value of -1 */
Modified kmem/heapf.fn.c from [6a14dc9781] to [3d67513f54].
1 1 #include <k/mem.h> 2 2 #include <k/core.h> 3 3 #include <k/def.h> 4 4 #include <k/type.h> 5 -#include <posix.h> 6 5 /* heapf.c - kmheapf() "heap free" 7 6 * ~ lexi hale <lexi@hale.su> 8 7 * kmheapf() frees a region on the heap à la libc free() 9 8 * see also: kmheapa() "heap alloc" 10 9 */ 11 10 12 -/* we define all platform functions here, 13 - * whether or not they're for the correct 14 - * platform - only the ones actually called 15 - * by the generated code will be linked, 16 - * linker errors are our friend here! */ 11 +/* arch specific headers */ 12 +#ifdef KFenv_posix 13 +# include <posix/posix.h> 14 +#endif 15 + 16 +/* we define all our platform functions here, whether or not 17 + * they're for the correct platform - only the ones that are 18 + * called by the preprocessed form of the code will actually 19 + * be linked, linker errors are our friend here! */ 17 20 extern int kmem_platform_munmap(void* addr, unsigned long sz); 18 21 19 22 kmcond kmheapf(void* ptr) { 20 23 /* take an object allocated on the heap and free it, 21 24 * returning kmcond_ok on success or an appropriate 22 25 * value on failure. */ 23 26 struct kmbox* header = (kmbox*) ................................................................................ 34 37 if(kmem_platform_munmap(header, total) == -1) { 35 38 /* we don't need to bother recovering errno; 36 39 * there's only one possible munmap error */ 37 40 return kmcond_bad_address; 38 41 } 39 42 40 43 # else 41 - Knoimpl(kmheapa,KVos); 44 + Knoimpl(kmheapf,KVos); 42 45 # error missing implementation 43 46 # endif 44 47 return kmcond_ok; 45 48 }
Modified kmem/platform.mmap.fn.x86.lin.64.s from [ceb93a428c] to [a05b3cdd12].
1 1 bits 64 2 -%include "../arch/x86.lin.64.s" 2 +%include "../arch/posix/x86.lin.64.s" 3 3 %include "../arch/x86.cdecl.64.s" 4 4 ; vim: ft=nasm 5 5 6 6 global kmem_platform_mmap 7 7 kmem_platform_mmap: 8 8 ; to call mmap, we need to translate the cdecl64 9 9 ; register arguments to their appropriate syscall64
Modified kmem/platform.munmap.fn.x86.lin.64.s from [6d9c3d5edf] to [7b471fc276].
1 1 bits 64 2 -%include "../arch/x86.lin.64.s" 2 +%include "../arch/posix/x86.lin.64.s" 3 3 %include "../arch/x86.cdecl.64.s" 4 4 ; vim: ft=nasm 5 5 6 6 global kmem_platform_munmap 7 7 kmem_platform_munmap: 8 8 ; to call munmap, we need to translate the cdecl64 9 9 ; register arguments to their appropriate syscall64