DELETED arch/posix.h Index: arch/posix.h ================================================================== --- arch/posix.h +++ arch/posix.h @@ -1,87 +0,0 @@ -/* arch/posix.h - posix constants - * ? this file defines posix magic numbers - * needed in syscalls, both cross-platform - * ones and os-dependent ones. note that - * the values may change depending on the - * OS specified! */ - -#ifndef KIplatform_posix -#define KIplatform_posix -#include -#include - -#if (!defined(KFplatform_define_constants)) && \ - (!defined(KFplatform_define_types)) && \ - (!defined(KFplatform_define_funcs)) -#define KFplatform_define_constants -#define KFplatform_define_types -#define KFplatform_define_funcs -#endif - -#ifdef KFplatform_define_constants - -enum posix_prot { - posix_prot_none = 0, - posix_prot_read = 1 << 0, - posix_prot_write = 1 << 1, - posix_prot_exec = 1 << 2 -}; - -enum posix_map { - posix_map_shared = 1, - posix_map_private = 2 -}; - -enum posix_flag { - posix_flag_fixed = 0x10, -#if KVos == KA_os_lin - posix_flag_anonymous = 0x20, -#elif KVos == KA_os_fbsd - posix_flag_anonymous = 0x1000, -#endif - - /* platform flags */ - posix_flag_linux_hugetlb = 0x40000 -}; - -#endif -#ifdef KFplatform_define_types - -/* platform types */ - -typedef s64 k_platform_syscall_return; -typedef u64 k_platform_syscall_error; - -#if KVos == KA_os_lin - typedef long k_platform_syscall_arg; -#elif KVos == KA_os_fbsd - typedef u64 k_platform_syscall_arg; -#else - /* we're going to just pick a sane - * fallback that's reasonably likely - * to work with most systems one way - * or another */ - typedef unsigned long long k_platform_syscall_arg; -#endif - -struct k_platform_syscall_answer { - k_platform_syscall_return ret; - k_platform_syscall_error error; -}; - -#endif - -#if defined(KFplatform_define_constants) ||\ - defined(KFplatform_define_funcs) -# include -#endif - -#ifdef KFplatform_define_funcs - -extern struct k_platform_syscall_answer -k_platform_syscall(enum k_platform_syscall call, u8 valency, - k_platform_syscall_arg args[]); - -#endif - -#endif ADDED arch/posix/posix.h Index: arch/posix/posix.h ================================================================== --- arch/posix/posix.h +++ arch/posix/posix.h @@ -0,0 +1,87 @@ +/* arch/posix.h - posix constants + * ? this file defines posix magic numbers + * needed in syscalls, both cross-platform + * ones and os-dependent ones. note that + * the values may change depending on the + * OS specified! */ + +#ifndef KIplatform_posix +#define KIplatform_posix +#include +#include + +#if (!defined(KFplatform_define_constants)) && \ + (!defined(KFplatform_define_types)) && \ + (!defined(KFplatform_define_funcs)) +#define KFplatform_define_constants +#define KFplatform_define_types +#define KFplatform_define_funcs +#endif + +#ifdef KFplatform_define_constants + +enum posix_prot { + posix_prot_none = 0, + posix_prot_read = 1 << 0, + posix_prot_write = 1 << 1, + posix_prot_exec = 1 << 2 +}; + +enum posix_map { + posix_map_shared = 1, + posix_map_private = 2 +}; + +enum posix_flag { + posix_flag_fixed = 0x10, +#if KVos == KA_os_lin + posix_flag_anonymous = 0x20, +#elif KVos == KA_os_fbsd + posix_flag_anonymous = 0x1000, +#endif + + /* platform flags */ + posix_flag_linux_hugetlb = 0x40000 +}; + +#endif +#ifdef KFplatform_define_types + +/* platform types */ + +typedef s64 k_platform_syscall_return; +typedef u64 k_platform_syscall_error; + +#if KVos == KA_os_lin + typedef long k_platform_syscall_arg; +#elif KVos == KA_os_fbsd + typedef u64 k_platform_syscall_arg; +#else + /* we're going to just pick a sane + * fallback that's reasonably likely + * to work with most systems one way + * or another */ + typedef unsigned long long k_platform_syscall_arg; +#endif + +struct k_platform_syscall_answer { + k_platform_syscall_return ret; + k_platform_syscall_error error; +}; + +#endif + +#if defined(KFplatform_define_constants) ||\ + defined(KFplatform_define_funcs) +# include +#endif + +#ifdef KFplatform_define_funcs + +extern struct k_platform_syscall_answer +k_platform_syscall(enum k_platform_syscall call, u8 valency, + k_platform_syscall_arg args[]); + +#endif + +#endif ADDED arch/posix/syscalls Index: arch/posix/syscalls ================================================================== --- arch/posix/syscalls +++ arch/posix/syscalls @@ -0,0 +1,5 @@ +exit +read +write +mmap +munmap ADDED arch/posix/x86.fbsd.32.s Index: arch/posix/x86.fbsd.32.s ================================================================== --- arch/posix/x86.fbsd.32.s +++ arch/posix/x86.fbsd.32.s @@ -0,0 +1,23 @@ +;; abi definition file for x86 linux 64-bit +; vim: ft=nasm + +; syscall numbers - syscall table must be created first! +%include "system_calls.s" + +; extremely stupid freebsd-ism: expects the syscall to +; come from a function +_syscall: int 0x80 + ret + +%define sys.call call _syscall + +; parameters are passed on the stack +%macro syscall 1-* + mov eax, %1 + %rep %0-1 + %rotate 1 + push %1 + %endrep + sys.call + add esp, 4*(%0-1) +%endmacro ADDED arch/posix/x86.fbsd.64.s Index: arch/posix/x86.fbsd.64.s ================================================================== --- arch/posix/x86.fbsd.64.s +++ arch/posix/x86.fbsd.64.s @@ -0,0 +1,8 @@ +;; abi definition file for x86 linux 64-bit +; vim: ft=nasm + +; syscall numbers - syscall table must be created first! +%include "system_calls.s" + +; freebsd uses the common x86-64 ABI +%include "x86.syscall.64.s" ADDED arch/posix/x86.lin.32.s Index: arch/posix/x86.lin.32.s ================================================================== --- arch/posix/x86.lin.32.s +++ arch/posix/x86.lin.32.s @@ -0,0 +1,11 @@ +; register order for syscall convention +%define sys.reg.n 6 +%define sys.reg.ret eax +%define sys.reg.0 eax +%define sys.reg.1 ebx +%define sys.reg.2 ecx +%define sys.reg.3 edx +%define sys.reg.4 esi +%define sys.reg.5 edi + +%define sys.call int 0x80 ADDED arch/posix/x86.lin.64.s Index: arch/posix/x86.lin.64.s ================================================================== --- arch/posix/x86.lin.64.s +++ arch/posix/x86.lin.64.s @@ -0,0 +1,9 @@ +;; abi definition file for x86 linux 64-bit +; vim: ft=nasm + +; syscall64 numbers - syscall table must be created first! +%include "system_calls.s" + +; linux uses the common x86-64 ABI +%include "../x86.syscall.64.s" + DELETED arch/x86.fbsd.32.s Index: arch/x86.fbsd.32.s ================================================================== --- arch/x86.fbsd.32.s +++ arch/x86.fbsd.32.s @@ -1,23 +0,0 @@ -;; abi definition file for x86 linux 64-bit -; vim: ft=nasm - -; syscall numbers - syscall table must be created first! -%include "system_calls.s" - -; extremely stupid freebsd-ism: expects the syscall to -; come from a function -_syscall: int 0x80 - ret - -%define sys.call call _syscall - -; parameters are passed on the stack -%macro syscall 1-* - mov eax, %1 - %rep %0-1 - %rotate 1 - push %1 - %endrep - sys.call - add esp, 4*(%0-1) -%endmacro DELETED arch/x86.fbsd.64.s Index: arch/x86.fbsd.64.s ================================================================== --- arch/x86.fbsd.64.s +++ arch/x86.fbsd.64.s @@ -1,8 +0,0 @@ -;; abi definition file for x86 linux 64-bit -; vim: ft=nasm - -; syscall numbers - syscall table must be created first! -%include "system_calls.s" - -; freebsd uses the common x86-64 ABI -%include "x86.syscall.64.s" DELETED arch/x86.lin.32.s Index: arch/x86.lin.32.s ================================================================== --- arch/x86.lin.32.s +++ arch/x86.lin.32.s @@ -1,11 +0,0 @@ -; register order for syscall convention -%define sys.reg.n 6 -%define sys.reg.ret eax -%define sys.reg.0 eax -%define sys.reg.1 ebx -%define sys.reg.2 ecx -%define sys.reg.3 edx -%define sys.reg.4 esi -%define sys.reg.5 edi - -%define sys.call int 0x80 DELETED arch/x86.lin.64.s Index: arch/x86.lin.64.s ================================================================== --- arch/x86.lin.64.s +++ arch/x86.lin.64.s @@ -1,9 +0,0 @@ -;; abi definition file for x86 linux 64-bit -; vim: ft=nasm - -; syscall64 numbers - syscall table must be created first! -%include "system_calls.s" - -; linux uses the common x86-64 ABI -%include "x86.syscall.64.s" - Index: build.sh ================================================================== --- build.sh +++ build.sh @@ -189,16 +189,16 @@ $gen/typesize > gen/typesize.m # generate syscall tables if test $posix = yes; then # on posix, we simply abuse CPP to garner a list of syscalls; - # the file arch/posix_syscalls contains a list of syscalls + # the file arch/posix/syscalls contains a list of syscalls # we wish to import; we use sed to transform this into a form # that cpp will fill out for us, producing a table that the # awk scripts can handle and turn into a list of constants. echo '#include ' > $gen/system_calls.t.1 # this is the magic part - cat arch/posix_syscalls > $gen/system_calls.t.2 + cat arch/posix/syscalls > $gen/system_calls.t.2 sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2 cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl else case $os in # lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;; Index: kcore/boot.rt.x86.lin.64.s ================================================================== --- kcore/boot.rt.x86.lin.64.s +++ kcore/boot.rt.x86.lin.64.s @@ -1,8 +1,8 @@ ; vim: ft=nasm bits 64 -%include "../arch/x86.lin.64.s" +%include "../arch/posix/x86.lin.64.s" global _start:function extern _boot extern entry _start: Index: kcore/platform.syscall.fn.c ================================================================== --- kcore/platform.syscall.fn.c +++ kcore/platform.syscall.fn.c @@ -9,11 +9,11 @@ #include #include #ifdef KFenv_posix -# include +# include #else Knoimpl(k_platform_syscall) #endif extern void k_platform_syscall_raw ( Index: kcore/stop.fn.c ================================================================== --- kcore/stop.fn.c +++ kcore/stop.fn.c @@ -7,13 +7,15 @@ #include // so we know what system this is #include #ifdef KFenv_posix # define KFplatform_define_types # define KFplatform_define_constants -# include +# include #endif +/* this manual redefinition is necessary to stop gcc + * bitching that kstop returns, which it def does not */ noreturn extern struct k_platform_syscall_answer k_platform_syscall(enum k_platform_syscall call, u8 valency, k_platform_syscall_arg args[]); noreturn void kstop(stat_long code) { Index: kcore/syscall.fn.x86.lin.64.s ================================================================== --- kcore/syscall.fn.x86.lin.64.s +++ kcore/syscall.fn.x86.lin.64.s @@ -9,11 +9,11 @@ ; ; void k_platform_syscall_raw(s64* result, u64* errno, ; syscall, u8 valency, s64[] args) bits 64 -%include "../arch/x86.lin.64.s" +%include "../arch/posix/x86.lin.64.s" %include "../arch/x86.cdecl.64.s" ; vim: ft=nasm %macro handle_arg 1 %assign v %1+1 Index: kio/send.fn.c ================================================================== --- kio/send.fn.c +++ kio/send.fn.c @@ -8,11 +8,11 @@ /* we define all platform functions here, * whether or not they're for the correct * platform - only the ones actually called * by the generated code will be linked */ -#include +#include #include kiocond kiosend(kiochan target, ksraw string, sz* len) { if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream; Index: kmem/heapa.fn.c ================================================================== --- kmem/heapa.fn.c +++ kmem/heapa.fn.c @@ -1,21 +1,24 @@ #include #include #include #include -#include /* heapa.c - kmheapa() "heap alloc" * ~ lexi hale * kmheapa() allocates a pointer on the heap à la libc malloc() * see also: kmheapf() "heap free" */ -/* we define all platform functions here, - * whether or not they're for the correct - * platform - only the ones actually called - * by the generated code will be linked, - * linker errors are our friend here! */ +/* arch specific headers */ +#ifdef KFenv_posix +# include +#endif + +/* we define all our platform functions here, whether or not + * they're for the correct platform - only the ones that are + * called by the preprocessed form of the code will actually + * be linked, linker errors are our friend here! */ extern void* kmem_platform_mmap(void* addr, unsigned long sz, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long off); void* kmheapa(sz len) { @@ -24,31 +27,33 @@ union { void* raw; ubyte* byte; kmbox* header; } region; - /* we need to allocate space for the header and - * for the actual object */ + /* we need to allocate space for the + * header and for the actual object */ sz region_size = sizeof(kmbox) + len; # ifdef KFenv_posix - /* posix APIs - we've got it easy. currently for nonlinear - * heap allocation kmheapa simply uses m(un)map and lets the - * kernel worry about it. it may ultimately be worth replacing - * this with a more sophisticated implementation, most likely - * an existing allocator like jemalloc, though i'm wary of - * including outside code - it creates a licensing mess and - * i'd prefer libk to be AGPLv3 across the board. possibility: - * include hooks for multiple allocators, allowing the user - * to select & link in her preferred allocator at compile time? */ + /* posix APIs - we've got it easy. currently for + * nonlinear heap allocation kmheapa simply uses + * m(un)map and lets the kernel worry about it. it + * may ultimately be worth replacing this with a + * more sophisticated implementation, most likely an + * existing allocator like jemalloc, though i'm wary + * of including outside code - it creates a licensing + * mess and i'd prefer libk to be AGPLv3 across the + * board. possibility: include hooks for multiple + * allocators, allowing the user to select & link in + * her preferred allocator at compile time? */ /* because munmap needs to be informed of the size of - * the region it is going to unmap, we need to store - * that information in the allocated region itself. - * the user will be given a pointer that can be - * adjusted to point a field of type size_t that - * contains the size of the allocate space.*/ + * the region we are going to unmap, we need to store + * that information in the region that we are mapping. + * the user will receive an adjusted pointer that can + * be adjusted to point a field of type size_t that + * contains the size of the allocated space.*/ region.byte = kmem_platform_mmap(null, region_size, posix_prot_read | posix_prot_write, posix_flag_anonymous | posix_map_shared, -1, 0); /* impl note: while per manpage fd is "ignored" Index: kmem/heapf.fn.c ================================================================== --- kmem/heapf.fn.c +++ kmem/heapf.fn.c @@ -1,21 +1,24 @@ #include #include #include #include -#include /* heapf.c - kmheapf() "heap free" * ~ lexi hale * kmheapf() frees a region on the heap à la libc free() * see also: kmheapa() "heap alloc" */ -/* we define all platform functions here, - * whether or not they're for the correct - * platform - only the ones actually called - * by the generated code will be linked, - * linker errors are our friend here! */ +/* arch specific headers */ +#ifdef KFenv_posix +# include +#endif + +/* we define all our platform functions here, whether or not + * they're for the correct platform - only the ones that are + * called by the preprocessed form of the code will actually + * be linked, linker errors are our friend here! */ extern int kmem_platform_munmap(void* addr, unsigned long sz); kmcond kmheapf(void* ptr) { /* take an object allocated on the heap and free it, * returning kmcond_ok on success or an appropriate @@ -36,10 +39,10 @@ * there's only one possible munmap error */ return kmcond_bad_address; } # else - Knoimpl(kmheapa,KVos); + Knoimpl(kmheapf,KVos); # error missing implementation # endif return kmcond_ok; } Index: kmem/platform.mmap.fn.x86.lin.64.s ================================================================== --- kmem/platform.mmap.fn.x86.lin.64.s +++ kmem/platform.mmap.fn.x86.lin.64.s @@ -1,7 +1,7 @@ bits 64 -%include "../arch/x86.lin.64.s" +%include "../arch/posix/x86.lin.64.s" %include "../arch/x86.cdecl.64.s" ; vim: ft=nasm global kmem_platform_mmap kmem_platform_mmap: Index: kmem/platform.munmap.fn.x86.lin.64.s ================================================================== --- kmem/platform.munmap.fn.x86.lin.64.s +++ kmem/platform.munmap.fn.x86.lin.64.s @@ -1,7 +1,7 @@ bits 64 -%include "../arch/x86.lin.64.s" +%include "../arch/posix/x86.lin.64.s" %include "../arch/x86.cdecl.64.s" ; vim: ft=nasm global kmem_platform_munmap kmem_platform_munmap: