diff --git a/src/sys/include/isa/ne2k.h b/src/sys/include/isa/ne2k.h index 913598d..70ac271 100644 --- a/src/sys/include/isa/ne2k.h +++ b/src/sys/include/isa/ne2k.h @@ -48,12 +48,6 @@ } ether_addr; -struct nicBuffer { - struct nicBuffer *next; - int length; - char *buffer; - }; - #define RSR_FO 0x08 #define RSR_PRX 0x01 #define DEF_ENABLED 0x200 diff --git a/src/sys/include/net/netif.h b/src/sys/include/net/netif.h index 3f7bb10..4b78a3e 100644 --- a/src/sys/include/net/netif.h +++ b/src/sys/include/net/netif.h @@ -44,6 +44,13 @@ #include "net/pbuf.h" +struct nicBuffer { + struct nicBuffer *next; + int length; + char *buffer; +}; + +struct nicBuffer *tmpBuf; struct netif { struct netif *next; @@ -95,5 +102,7 @@ void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr); void netif_set_netmask(struct netif *netif, struct ip_addr *netmast); void netif_set_gw(struct netif *netif, struct ip_addr *gw); +//static void ethernetif_input(struct netif *); +void ethernetif_input(struct netif *); #endif /* __LWIP_NETIF_H__ */ diff --git a/src/sys/include/pci/lnc.h b/src/sys/include/pci/lnc.h index a762cb9..c1ca306 100644 --- a/src/sys/include/pci/lnc.h +++ b/src/sys/include/pci/lnc.h @@ -66,6 +66,12 @@ #define CSR58 0x003A /* Structs */ +struct lncBuffer { + struct nicBuffer *next; + int length; + char *buffer; +}; + struct mds { uint16_t md0; uint16_t md1; @@ -138,6 +144,7 @@ int ntdre; int bufferSize; int txPtr; + int rxPtr; }; /* Functions */ @@ -163,6 +170,12 @@ int lnc_getMode(struct lncInfo *); void lnc_isr(); +int lnc_driverOwnsRX(struct lncInfo *); +int lnc_driverOwnsRX(struct lncInfo *); + +void lnc_INT(); +void lnc_rxINT(); +void lnc_txINT(); // OLD diff --git a/src/sys/include/sys/_types.h b/src/sys/include/sys/_types.h index e0b43be..9606b4f 100644 --- a/src/sys/include/sys/_types.h +++ b/src/sys/include/sys/_types.h @@ -27,7 +27,6 @@ #ifndef __TYPES_H #define __TYPES_H - typedef __signed char __int8_t; typedef unsigned char __uint8_t; typedef short __int16_t; @@ -45,4 +44,34 @@ typedef __uint32_t __blksize_t;/* file block size */ typedef __uint32_t __fflags_t;/* file flags */ +typedef __int8_t __int_fast8_t; +typedef __uint8_t __uint_fast8_t; +typedef __int16_t __int_fast16_t; +typedef __uint16_t __uint_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __uint32_t __uint_fast32_t; +typedef __int64_t __int_fast64_t; +typedef __uint64_t __uint_fast64_t; +typedef __int32_t __intptr_t; +typedef __uint32_t __uintptr_t; +typedef __uint32_t __size_t; +typedef __int64_t __intmax_t; +typedef __uint64_t __uintmax_t; +typedef __int32_t __ptrdiff_t; +typedef __uint8_t __uint_least8_t; +typedef __uint16_t __uint_least16_t; +typedef __uint32_t __uint_least32_t; +typedef __uint64_t __uint_least64_t; +typedef __int8_t __int_least8_t; +typedef __int16_t __int_least16_t; +typedef __int32_t __int_least32_t; +typedef __int64_t __int_least64_t; +typedef int ___wchar_t; + +#if !defined(__clang__) || !defined(__cplusplus) +typedef __uint_least16_t __char16_t; +typedef __uint_least32_t __char32_t; +#endif + + #endif diff --git a/src/sys/include/sys/cdefs.h b/src/sys/include/sys/cdefs.h index 89c12ec..4117232 100644 --- a/src/sys/include/sys/cdefs.h +++ b/src/sys/include/sys/cdefs.h @@ -1,42 +1,895 @@ -/***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project - All rights reserved. +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 + * $FreeBSD: releng/11.1/sys/sys/cdefs.h 317342 2017-04-23 20:32:46Z kib $ + */ - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ - Redistributions of source code must retain the above copyright notice, this list of - conditions, the following disclaimer and the list of authors. Redistributions in binary - form must reproduce the above copyright notice, this list of conditions, the following - disclaimer and the list of authors in the documentation and/or other materials provided - with the distribution. Neither the name of the UbixOS Project nor the names of its - contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - $Id: cdefs.h 79 2016-01-11 16:21:27Z reddawg $ - -*****************************************************************************************/ - -#ifndef _CDEFS_H -#define _CDEFS_H - -#include - -#define __dead2 __attribute__((__noreturn__)) - - +/* + * Testing against Clang-specific extensions. + */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#ifndef __has_extension +#define __has_extension __has_feature +#endif +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_builtin +#define __has_builtin(x) 0 #endif -/*** - END - ***/ +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * This code has been put in place to help reduce the addition of + * compiler specific defines in FreeBSD code. It helps to aid in + * having a compiler-agnostic source tree. + */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) +#define __GNUCLIKE_ASM 3 +#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS +#else +#define __GNUCLIKE_ASM 2 +#endif +#define __GNUCLIKE___TYPEOF 1 +#define __GNUCLIKE___OFFSETOF 1 +#define __GNUCLIKE___SECTION 1 + +#ifndef __INTEL_COMPILER +#define __GNUCLIKE_CTOR_SECTION_HANDLING 1 +#endif + +#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 +#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ + __INTEL_COMPILER < 800 +#undef __GNUCLIKE_BUILTIN_CONSTANT_P +#endif + +#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) +#define __GNUCLIKE_BUILTIN_VARARGS 1 +#define __GNUCLIKE_BUILTIN_STDARG 1 +#define __GNUCLIKE_BUILTIN_VAALIST 1 +#endif + +#if defined(__GNUC__) +#define __GNUC_VA_LIST_COMPATIBILITY 1 +#endif + +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#endif + +#ifndef __INTEL_COMPILER +#define __GNUCLIKE_BUILTIN_NEXT_ARG 1 +#define __GNUCLIKE_MATH_BUILTIN_RELOPS +#endif + +#define __GNUCLIKE_BUILTIN_MEMCPY 1 + +/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ +#define __CC_SUPPORTS_INLINE 1 +#define __CC_SUPPORTS___INLINE 1 +#define __CC_SUPPORTS___INLINE__ 1 + +#define __CC_SUPPORTS___FUNC__ 1 +#define __CC_SUPPORTS_WARNING 1 + +#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ + +#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI + * mode -- there must be no spaces between its arguments, and for nested + * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also + * concatenate double-quoted strings produced by the __STRING macro, but + * this only works with ANSI C. + * + * __XSTRING is like __STRING, but it expands any macros in its argument + * first. It is only available with ANSI C. + */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) +#define __inline inline /* convert to C++ keyword */ +#else +#if !(defined(__CC_SUPPORTS___INLINE)) +#define __inline /* delete GCC keyword */ +#endif /* ! __CC_SUPPORTS___INLINE */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !defined(__CC_SUPPORTS___INLINE) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * When using a compiler other than gcc, programs using the ANSI C keywords + * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. + * When using "gcc -traditional", we assume that this is the intent; if + * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. + */ +#ifndef NO_ANSI_KEYWORDS +#define const /* delete ANSI C keywords */ +#define inline +#define signed +#define volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !__CC_SUPPORTS___INLINE */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * Compiler-dependent macros to help declare dead (non-returning) and + * pure (no side effects) functions, and unused variables. They are + * null except for versions of gcc that are known to support the features + * properly (old versions of gcc-2 supported the dead and pure features + * in a different (wrong) way). If we do not provide an implementation + * for a given compiler, let the compile fail if it is told to use + * a feature that we cannot live without. + */ +#ifdef lint +#define __dead2 +#define __pure2 +#define __unused +#define __packed +#define __aligned(x) +#define __alloc_align(x) +#define __alloc_size(x) +#define __section(x) +#define __weak_symbol +#else +#define __weak_symbol __attribute__((__weak__)) +#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#define __dead2 +#define __pure2 +#define __unused +#endif +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused +/* XXX Find out what to do for __packed, __aligned and __section */ +#endif +#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __used __attribute__((__used__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif +#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) +#define __alloc_size(x) __attribute__((__alloc_size__(x))) +#else +#define __alloc_size(x) +#endif +#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) +#define __alloc_align(x) __attribute__((__alloc_align__(x))) +#else +#define __alloc_align(x) +#endif +#endif /* lint */ + +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + +/* + * Keywords added in C11. + */ + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) + +#if !__has_extension(c_alignas) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_alignas) +#define _Alignas(x) alignas(x) +#else +/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ +#define _Alignas(x) __aligned(x) +#endif +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(x) alignof(x) +#else +#define _Alignof(x) __alignof(x) +#endif + +#if !defined(__cplusplus) && !__has_extension(c_atomic) && \ + !__has_extension(cxx_atomic) +/* + * No native support for _Atomic(). Place object in structure to prevent + * most forms of direct non-atomic access. + */ +#define _Atomic(T) struct { T volatile __val; } +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Noreturn [[noreturn]] +#else +#define _Noreturn __dead2 +#endif + +#if !__has_extension(c_static_assert) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_static_assert) +#define _Static_assert(x, y) static_assert(x, y) +#elif __GNUC_PREREQ__(4,6) +/* Nothing, gcc 4.6 and higher has _Static_assert built-in */ +#elif defined(__COUNTER__) +#define _Static_assert(x, y) __Static_assert(x, __COUNTER__) +#define __Static_assert(x, y) ___Static_assert(x, y) +#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ + __unused +#else +#define _Static_assert(x, y) struct __hack +#endif +#endif + +#if !__has_extension(c_thread_local) +/* + * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode + * without actually supporting the thread_local keyword. Don't check for + * the presence of C++11 when defining _Thread_local. + */ +#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ + __has_extension(cxx_thread_local) +#define _Thread_local thread_local +#else +#define _Thread_local __thread +#endif +#endif + +#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + +/* + * Emulation of C11 _Generic(). Unlike the previously defined C11 + * keywords, it is not possible to implement this using exactly the same + * syntax. Therefore implement something similar under the name + * __generic(). Unlike _Generic(), this macro can only distinguish + * between a single type, so it requires nested invocations to + * distinguish multiple cases. + */ + +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + __has_extension(c_generic_selections) +#define __generic(expr, t, yes, no) \ + _Generic(expr, t: yes, default: no) +#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) +#define __generic(expr, t, yes, no) \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof(expr), t), yes, no) +#endif + +/* + * C99 Static array indices in function parameter declarations. Syntax such as: + * void bar(int myArray[static 10]); + * is allowed in C99 but not in C++. Define __min_size appropriately so + * headers using it can be compiled in either language. Use like this: + * void bar(int myArray[__min_size(10)]); + */ +#if !defined(__cplusplus) && \ + (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ + (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) +#define __min_size(x) static (x) +#else +#define __min_size(x) (x) +#endif + +#if __GNUC_PREREQ__(2, 96) +#define __malloc_like __attribute__((__malloc__)) +#define __pure __attribute__((__pure__)) +#else +#define __malloc_like +#define __pure +#endif + +#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __always_inline __attribute__((__always_inline__)) +#else +#define __always_inline +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __noinline __attribute__ ((__noinline__)) +#else +#define __noinline +#endif + +#if __GNUC_PREREQ__(3, 3) +#define __nonnull(x) __attribute__((__nonnull__(x))) +#define __nonnull_all __attribute__((__nonnull__)) +#else +#define __nonnull(x) +#define __nonnull_all +#endif + +#if __GNUC_PREREQ__(3, 4) +#define __fastcall __attribute__((__fastcall__)) +#define __result_use_check __attribute__((__warn_unused_result__)) +#else +#define __fastcall +#define __result_use_check +#endif + +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((__returns_twice__)) +#else +#define __returns_twice +#endif + +#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) +#define __unreachable() __builtin_unreachable() +#else +#define __unreachable() ((void)0) +#endif + +/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __func__ NULL +#endif + +#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 +#define __LONG_LONG_SUPPORTED +#endif + +/* C++11 exposes a load of C99 stuff */ +#if defined(__cplusplus) && __cplusplus >= 201103L +#define __LONG_LONG_SUPPORTED +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +#endif +#endif + +/* + * GCC 2.95 provides `__restrict' as an extension to C90 to support the + * C99-specific `restrict' type qualifier. We happen to use `__restrict' as + * a way to define the `restrict' type qualifier without disturbing older + * software that is unaware of C99 keywords. + */ +#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint) +#define __restrict +#else +#define __restrict restrict +#endif +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect((exp), 1) +#define __predict_false(exp) __builtin_expect((exp), 0) +#else +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +#if __GNUC_PREREQ__(4, 0) +#define __null_sentinel __attribute__((__sentinel__)) +#define __exported __attribute__((__visibility__("default"))) +#define __hidden __attribute__((__visibility__("hidden"))) +#else +#define __null_sentinel +#define __exported +#define __hidden +#endif + +/* + * We define this here since , , and + * require it. + */ +#if __GNUC_PREREQ__(4, 1) +#define __offsetof(type, field) __builtin_offsetof(type, field) +#else +#ifndef __cplusplus +#define __offsetof(type, field) \ + ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) +#else +#define __offsetof(type, field) \ + (__offsetof__ (reinterpret_cast <__size_t> \ + (&reinterpret_cast \ + (static_cast (0)->field)))) +#endif +#endif +#define __rangeof(type, start, end) \ + (__offsetof(type, end) - __offsetof(type, start)) + +/* + * Given the pointer x to the member m of the struct s, return + * a pointer to the containing structure. When using GCC, we first + * assign pointer x to a local variable, to check that its type is + * compatible with member m. + */ +#if __GNUC_PREREQ__(3, 1) +#define __containerof(x, s, m) ({ \ + const volatile __typeof(((s *)0)->m) *__x = (x); \ + __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ +}) +#else +#define __containerof(x, s, m) \ + __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) +#endif + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __printflike(fmtarg, firstvararg) +#define __scanflike(fmtarg, firstvararg) +#define __format_arg(fmtarg) +#define __strfmonlike(fmtarg, firstvararg) +#define __strftimelike(fmtarg, firstvararg) +#else +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) +#define __strfmonlike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) +#define __strftimelike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) +#endif + +/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ +#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ + defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __printf0like(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) +#else +#define __printf0like(fmtarg, firstvararg) +#endif + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#ifndef __INTEL_COMPILER +#define __strong_reference(sym,aliassym) \ + extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) +#endif +#ifdef __STDC__ +#define __weak_reference(sym,alias) \ + __asm__(".weak " #alias); \ + __asm__(".equ " #alias ", " #sym) +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning." #sym); \ + __asm__(".asciz \"" msg "\""); \ + __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@" #verid) +#define __sym_default(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@@" #verid) +#else +#define __weak_reference(sym,alias) \ + __asm__(".weak alias"); \ + __asm__(".equ alias, sym") +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning.sym"); \ + __asm__(".asciz \"msg\""); \ + __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver impl, sym@verid") +#define __sym_default(impl,sym,verid) \ + __asm__(".symver impl, sym@@verid") +#endif /* __STDC__ */ +#endif /* __GNUC__ || __INTEL_COMPILER */ + +#define __GLOBL1(sym) __asm__(".globl " #sym) +#define __GLOBL(sym) __GLOBL1(sym) + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") +#else +/* + * The following definition might not work well if used in header files, + * but it should be better than nothing. If you want a "do nothing" + * version, then it should generate some harmless declaration, such as: + * #define __IDSTRING(name,string) struct __hack + */ +#define __IDSTRING(name,string) static const char name[] __unused = string +#endif + +/* + * Embed the rcs id of a source file in the resulting library. Note that in + * more recent ELF binutils, we use .ident allowing the ID to be stripped. + * Usage: + * __FBSDID("$FreeBSD: releng/11.1/sys/sys/cdefs.h 317342 2017-04-23 20:32:46Z kib $"); + */ +#ifndef __FBSDID +#if !defined(lint) && !defined(STRIP_FBSDID) +#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __FBSDID(s) struct __hack +#endif +#endif + +#ifndef __RCSID +#ifndef NO__RCSID +#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __RCSID(s) struct __hack +#endif +#endif + +#ifndef __RCSID_SOURCE +#ifndef NO__RCSID_SOURCE +#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) +#else +#define __RCSID_SOURCE(s) struct __hack +#endif +#endif + +#ifndef __SCCSID +#ifndef NO__SCCSID +#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) +#else +#define __SCCSID(s) struct __hack +#endif +#endif + +#ifndef __COPYRIGHT +#ifndef NO__COPYRIGHT +#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) +#else +#define __COPYRIGHT(s) struct __hack +#endif +#endif + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) +#endif + +#ifndef __DEVOLATILE +#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) +#endif + +#ifndef __DEQUALIFY +#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) +#endif + +/*- + * The following definitions are an extension of the behavior originally + * implemented in , but with a different level of granularity. + * POSIX.1 requires that the macros we test be defined before any standard + * header file is included. + * + * Here's a quick run-down of the versions: + * defined(_POSIX_SOURCE) 1003.1-1988 + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option + * _POSIX_C_SOURCE == 199309 1003.1b-1993 + * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1: 1996 + * _POSIX_C_SOURCE == 200112 1003.1-2001 + * _POSIX_C_SOURCE == 200809 1003.1-2008 + * + * In addition, the X/Open Portability Guide, which is now the Single UNIX + * Specification, defines a feature-test macro which indicates the version of + * that specification, and which subsumes _POSIX_C_SOURCE. + * + * Our macros begin with two underscores to avoid namespace screwage. + */ + +/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 +#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ +#define _POSIX_C_SOURCE 199009 +#endif + +/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199209 +#endif + +/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +#ifdef _XOPEN_SOURCE +#if _XOPEN_SOURCE - 0 >= 700 +#define __XSI_VISIBLE 700 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809 +#elif _XOPEN_SOURCE - 0 >= 600 +#define __XSI_VISIBLE 600 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112 +#elif _XOPEN_SOURCE - 0 >= 500 +#define __XSI_VISIBLE 500 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506 +#endif +#endif + +/* + * Deal with all versions of POSIX. The ordering relative to the tests above is + * important. + */ +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 198808 +#endif +#ifdef _POSIX_C_SOURCE +#if _POSIX_C_SOURCE >= 200809 +#define __POSIX_VISIBLE 200809 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 200112 +#define __POSIX_VISIBLE 200112 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 199506 +#define __POSIX_VISIBLE 199506 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199309 +#define __POSIX_VISIBLE 199309 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199209 +#define __POSIX_VISIBLE 199209 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199009 +#define __POSIX_VISIBLE 199009 +#define __ISO_C_VISIBLE 1990 +#else +#define __POSIX_VISIBLE 198808 +#define __ISO_C_VISIBLE 0 +#endif /* _POSIX_C_SOURCE */ +#else +/*- + * Deal with _ANSI_SOURCE: + * If it is defined, and no other compilation environment is explicitly + * requested, then define our internal feature-test macros to zero. This + * makes no difference to the preprocessor (undefined symbols in preprocessing + * expressions are defined to have value zero), but makes it more convenient for + * a test program to print out the values. + * + * If a program mistakenly defines _ANSI_SOURCE and some other macro such as + * _POSIX_C_SOURCE, we will assume that it wants the broader compilation + * environment (and in fact we will never get here). + */ +#if defined(_ANSI_SOURCE) /* Hide almost everything. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1990 +#define __EXT1_VISIBLE 0 +#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1999 +#define __EXT1_VISIBLE 0 +#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 2011 +#define __EXT1_VISIBLE 0 +#else /* Default environment: show everything. */ +#define __POSIX_VISIBLE 200809 +#define __XSI_VISIBLE 700 +#define __BSD_VISIBLE 1 +#define __ISO_C_VISIBLE 2011 +#define __EXT1_VISIBLE 1 +#endif +#endif + +/* User override __EXT1_VISIBLE */ +#if defined(__STDC_WANT_LIB_EXT1__) +#undef __EXT1_VISIBLE +#if __STDC_WANT_LIB_EXT1__ +#define __EXT1_VISIBLE 1 +#else +#define __EXT1_VISIBLE 0 +#endif +#endif /* __STDC_WANT_LIB_EXT1__ */ + +#if defined(__mips) || defined(__powerpc64__) || defined(__riscv__) +#define __NO_TLS 1 +#endif + +/* + * Old versions of GCC use non-standard ARM arch symbols; acle-compat.h + * translates them to __ARM_ARCH and the modern feature symbols defined by ARM. + */ +#if defined(__arm__) && !defined(__ARM_ARCH) +#include +#endif + +/* + * Nullability qualifiers: currently only supported by Clang. + */ +#if !(defined(__clang__) && __has_feature(nullability)) +#define _Nonnull +#define _Nullable +#define _Null_unspecified +#define __NULLABILITY_PRAGMA_PUSH +#define __NULLABILITY_PRAGMA_POP +#else +#define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") +#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") +#endif + +/* + * Type Safety Checking + * + * Clang provides additional attributes to enable checking type safety + * properties that cannot be enforced by the C type system. + */ + +#if __has_attribute(__argument_with_type_tag__) && \ + __has_attribute(__type_tag_for_datatype__) && !defined(lint) +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ + __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) +#define __datatype_type_tag(kind, type) \ + __attribute__((__type_tag_for_datatype__(kind, type))) +#else +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) +#define __datatype_type_tag(kind, type) +#endif + +/* + * Lock annotations. + * + * Clang provides support for doing basic thread-safety tests at + * compile-time, by marking which locks will/should be held when + * entering/leaving a functions. + * + * Furthermore, it is also possible to annotate variables and structure + * members to enforce that they are only accessed when certain locks are + * held. + */ + +#if __has_extension(c_thread_safety_attributes) +#define __lock_annotate(x) __attribute__((x)) +#else +#define __lock_annotate(x) +#endif + +/* Structure implements a lock. */ +#define __lockable __lock_annotate(lockable) + +/* Function acquires an exclusive or shared lock. */ +#define __locks_exclusive(...) \ + __lock_annotate(exclusive_lock_function(__VA_ARGS__)) +#define __locks_shared(...) \ + __lock_annotate(shared_lock_function(__VA_ARGS__)) + +/* Function attempts to acquire an exclusive or shared lock. */ +#define __trylocks_exclusive(...) \ + __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) +#define __trylocks_shared(...) \ + __lock_annotate(shared_trylock_function(__VA_ARGS__)) + +/* Function releases a lock. */ +#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) + +/* Function asserts that an exclusive or shared lock is held. */ +#define __asserts_exclusive(...) \ + __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) +#define __asserts_shared(...) \ + __lock_annotate(assert_shared_lock(__VA_ARGS__)) + +/* Function requires that an exclusive or shared lock is or is not held. */ +#define __requires_exclusive(...) \ + __lock_annotate(exclusive_locks_required(__VA_ARGS__)) +#define __requires_shared(...) \ + __lock_annotate(shared_locks_required(__VA_ARGS__)) +#define __requires_unlocked(...) \ + __lock_annotate(locks_excluded(__VA_ARGS__)) + +/* Function should not be analyzed. */ +#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) + +/* Guard variables and structure members by lock. */ +#define __guarded_by(x) __lock_annotate(guarded_by(x)) +#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) + +#endif /* !_SYS_CDEFS_H_ */ diff --git a/src/sys/include/sys/uuid.h b/src/sys/include/sys/uuid.h index 041dd6e..965b0a7 100644 --- a/src/sys/include/sys/uuid.h +++ b/src/sys/include/sys/uuid.h @@ -30,6 +30,7 @@ #define _SYS_UUID_H_ #include +#include /* Length of a node address (an IEEE 802 address). */ #define _UUID_NODE_LEN 6 @@ -42,12 +43,12 @@ * A DCE 1.1 compatible source representation of UUIDs. */ struct uuid { - u_int32_t time_low; - u_int16_t time_mid; - u_int16_t time_hi_and_version; - u_int8_t clock_seq_hi_and_reserved; - u_int8_t clock_seq_low; - u_int8_t node[_UUID_NODE_LEN]; + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; }; #ifdef _KERNEL @@ -58,8 +59,8 @@ struct uuid *kern_uuidgen(struct uuid *, size_t); -int uuid_ether_add(const u_int8_t *); -int uuid_ether_del(const u_int8_t *); +int uuid_ether_add(const uint8_t *); +int uuid_ether_del(const uint8_t *); int snprintf_uuid(char *, size_t, struct uuid *); int printf_uuid(struct uuid *); diff --git a/src/sys/include/ubixos/ubthread.h b/src/sys/include/ubixos/ubthread.h index a1f86d8..0f01cfc 100644 --- a/src/sys/include/ubixos/ubthread.h +++ b/src/sys/include/ubixos/ubthread.h @@ -39,6 +39,15 @@ #define LOCKED 1 #define UNLOCKED 0 +/*MROLSEN TEMP BOOL*/ +#define false 0 +#define true 1 + +#define bool _Bool +#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 && !defined(__INTEL_COMPILER) +typedef int _Bool; +#endif + typedef struct ubthread *ubthread_t; typedef struct ubthread_cond *ubthread_cond_t; typedef struct ubthread_mutex *ubthread_mutex_t; @@ -49,12 +58,14 @@ struct ubthread_cond { int id; - uInt8 locked; + //uInt8 locked; + _Atomic bool lock; }; struct ubthread_mutex { int id; - uInt8 locked; + //uInt8 locked; + _Atomic bool lock; pidType pid; }; diff --git a/src/sys/init/main.c b/src/sys/init/main.c index baca89a..242c2af 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -111,8 +111,8 @@ if (init_tasks[i]() != 0x0) kpanic("Error: Initializing System Task[%i].\n", i); } - irqEnable(0x0); -while(1); + // irqEnable(0x0); +//while(1); /* New Root Mount Point */ //Old 2 new 10 @@ -148,6 +148,10 @@ execThread(systemTask, (uInt32) sysTask + 0x2000, 0x0); kprintf("Thread Start!\n"); + irqEnable(0x0); + while (0x1) + asm("hlt"); + execFile("sys:/bin/init", 0x0, 0x0, 0x0); /* OS Initializer */ //execFile( "sys:/bin/login", 0x0, 0x0, 0x0 ); /* OS Initializer */ diff --git a/src/sys/isa/8259.c b/src/sys/isa/8259.c index 4c72637..8f98456 100644 --- a/src/sys/isa/8259.c +++ b/src/sys/isa/8259.c @@ -64,7 +64,7 @@ * * \param irqNo IRQ to enable */ -void irqEnable(u_int16_t irqNo) { +void irqEnable_old(u_int16_t irqNo) { irqMask &= ~(1 << irqNo); if (irqNo >= 8) { irqMask &= ~(1 << 2); @@ -73,12 +73,27 @@ outportByte(sPic+1, (irqMask >> 8) & 0xFF); } +void irqEnable(uint16_t irqNo) { + uint16_t port; + uint8_t value; + + if(irqNo < 8) { + port = mImr; + } + else { + port = sImr; + irqNo -= 8; + } + value = inportByte(port) & ~(1 << irqNo); + outportByte(port, value); +} + /*! * \brief disable specified IRQ * * \param irqNo IRQ to disable */ -void irqDisable(u_int16_t irqNo) { +void irqDisable_old(u_int16_t irqNo) { irqMask |= (1 << irqNo); if ((irqMask & 0xFF00)==0xFF00) { irqMask |= (1 << 2); @@ -87,6 +102,21 @@ outportByte(sPic+1, (irqMask >> 8) & 0xFF); } +void irqDisable(uint16_t irqNo) { + uint16_t port; + uint8_t value; + + if (irqNo < 8) { + port = mImr; + } + else { + port = sImr; + irqNo -= 8; + } + value = inportByte(port) | (1 << irqNo); + outportByte(port, value); +} + /*** END ***/ diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index 30ed364..ade9cad 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -37,6 +37,7 @@ #include #include #include +#include struct ubthread_cond_list *conds = 0x0; struct ubthread_mutex_list *mutex = 0x0; @@ -47,16 +48,22 @@ int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr) { ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); + memset(ubcond, 0x0, sizeof(struct ubthread_cond)); ubcond->id = (int)cond; - ubcond->locked = UNLOCKED; + ubcond->lock = ATOMIC_VAR_INIT(0); + //atomic_exchange(&ubcond->locked, UNLOCKED); + //ubcond->locked = UNLOCKED; *cond = ubcond; return(0x0); } int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr) { ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); + memset(ubmutex, 0x0, sizeof(struct ubthread_mutex)); ubmutex->id = (int)mutex; - ubmutex->locked = UNLOCKED; + ubmutex->lock = ATOMIC_VAR_INIT(0); + //atomic_exchange(&ubcond->locked, UNLOCKED); + //ubmutex->locked = UNLOCKED; *mutex = ubmutex; return(0x0); } @@ -80,24 +87,33 @@ int ubthread_mutex_lock(ubthread_mutex_t *mutex) { ubthread_mutex_t ubmutex = *mutex; - if (ubmutex->locked == LOCKED) { + //if (ubmutex->locked == LOCKED) { + if (ubmutex->lock == true) { kprintf("Mutex Already Lock By %x Trying To Be Relocked By %x\n",ubmutex->pid,_current->id); - while (ubmutex->locked == LOCKED); + kpanic("WHAT"); + //while (ubmutex->locked == LOCKED); + while (ubmutex->lock == true) + sched_yield(); + } - ubmutex->locked = LOCKED; - ubmutex->pid = _current->id; + atomic_exchange(&ubmutex->lock, true); + //ubmutex->locked = LOCKED; + ubmutex->pid = _current->id; return(0x0); } int ubthread_mutex_unlock(ubthread_mutex_t *mutex) { ubthread_mutex_t ubmutex = *mutex; if (ubmutex->pid == _current->id) { - ubmutex->locked = UNLOCKED; + atomic_exchange(&ubmutex->lock, false); + //ubmutex->locked = UNLOCKED; return(0x0); } else { - //kprintf("Trying To Unlock Mutex From No Locking Thread\n"); - ubmutex->locked = UNLOCKED; + kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id,*ubmutex); + kpanic("FU"); + atomic_exchange(&ubmutex->lock, false); + //ubmutex->locked = UNLOCKED; return(-1); } } @@ -107,24 +123,27 @@ ubthread_mutex_t ubmutex = *mutex; uInt32 enterTime = systemVitals->sysUptime+20; while (enterTime > systemVitals->sysUptime) { - if (ubcond->locked == UNLOCKED) break; + if (ubcond->lock == false) break; sched_yield(); } - ubmutex->locked = UNLOCKED; + atomic_exchange(&ubmutex->lock, false); + //ubmutex->locked = UNLOCKED; return(0x0); } int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex) { ubthread_cond_t ubcond = *cond; ubthread_mutex_t ubmutex = *mutex; - while (ubcond->locked == LOCKED) sched_yield(); - ubmutex->locked = UNLOCKED; + while (ubcond->lock == true) sched_yield(); + atomic_exchange(&ubcond->lock, false); + //ubmutex->locked = UNLOCKED; return(0x0); } int ubthread_cond_signal(ubthread_cond_t *cond) { ubthread_cond_t ubcond = *cond; - ubcond->locked = UNLOCKED; + atomic_exchange(&ubcond->lock, false); + //ubcond->locked = UNLOCKED; return(0x0); } diff --git a/src/sys/lib/strtol.c b/src/sys/lib/strtol.c index becd0b7..3b7114f 100644 --- a/src/sys/lib/strtol.c +++ b/src/sys/lib/strtol.c @@ -97,7 +97,7 @@ cutoff = 0x0;//UBU } else if (neg) acc = -acc; - if (endptr != NULL) + if (endptr != 0x0) *endptr = (char *)(any ? s - 1 : nptr); return (acc); } diff --git a/src/sys/net/api/tcpip.c b/src/sys/net/api/tcpip.c index 1f7b593..acbb182 100644 --- a/src/sys/net/api/tcpip.c +++ b/src/sys/net/api/tcpip.c @@ -69,9 +69,11 @@ { struct tcpip_msg *msg; + kprintf("Started TCP THread"); ip_init(); udp_init(); tcp_init(); + kprintf("Started TCP THread"); sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL); @@ -80,7 +82,9 @@ } while(1) { /* MAIN Loop */ + kprintf("mbf1"); sys_mbox_fetch(mbox, (void *)&msg); + kprintf("mbf1"); switch(msg->type) { case TCPIP_MSG_API: //kprintf("tcpip_thread: API message %p\n", msg); @@ -104,11 +108,13 @@ msg = memp_mallocp(MEMP_TCPIP_MSG); if(msg == NULL) { - //kprintf("BAD MESSAGE!!!\n"); + kprintf("BAD MESSAGE!!!\n"); + while (1) + asm("nop"); pbuf_free(p); return ERR_MEM; } - //kprintf("GOOD MESSAGE\n"); + kprintf("GOOD MESSAGE\n"); msg->type = TCPIP_MSG_INPUT; msg->msg.inp.p = p; diff --git a/src/sys/net/core/sys.c b/src/sys/net/core/sys.c index 0994a5c..a31a1f7 100644 --- a/src/sys/net/core/sys.c +++ b/src/sys/net/core/sys.c @@ -61,18 +61,28 @@ again: + kprintf("timeout0"); timeouts = sys_arch_timeouts(); + kprintf("timeout1"); if(timeouts->next == NULL) { + kprintf("Z0"); sys_arch_mbox_fetch(mbox, msg, 0); + kprintf("Z0"); } else { + kprintf("Z1"); if(timeouts->next->time > 0) { + kprintf("Z2"); time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time); + kprintf("Z3"); } else { + kprintf("Z4"); time = 0; } + kprintf("Z5"); if(time == 0) { + kprintf("Z6"); /* If time == 0, a timeout occured before a message could be fetched. We should now call the timeout handler and deallocate the memory allocated for the timeout. */ @@ -81,7 +91,9 @@ h = tmptimeout->h; arg = tmptimeout->arg; memp_free(MEMP_SYS_TIMEOUT, tmptimeout); + kprintf("Z7"); h(arg); + kprintf("Z8"); /* We try again to fetch a message from the mbox. */ goto again; @@ -107,12 +119,11 @@ struct sys_timeout *tmptimeout; sys_timeout_handler h; void *arg; - - /* while(sys_arch_sem_wait(sem, 1000) == 0); - return;*/ + + while(sys_arch_sem_wait(sem, 1000) == 0); + return; again: - timeouts = sys_arch_timeouts(); if(timeouts->next == NULL) { diff --git a/src/sys/net/net/init.c b/src/sys/net/net/init.c index f62c9cd..3c85582 100644 --- a/src/sys/net/net/init.c +++ b/src/sys/net/net/init.c @@ -70,14 +70,16 @@ netif_init(); sem = sys_sem_new(0); tcpip_init(tcpip_init_done, &sem); + kprintf("WAIT: %i]",_current->id); sys_sem_wait(sem); + kprintf("FREE"); sys_sem_free(sem); kprintf("TCP/IP initialized.\n"); IP4_ADDR(&gw, 10,50,0,1); IP4_ADDR(&ipaddr, 10,50,0,7); - IP4_ADDR(&netmask, 255,255,0,0); + IP4_ADDR(&netmask, 255,255,255,0); netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); IP4_ADDR(&gw, 127,0,0,1); @@ -88,6 +90,7 @@ //udpecho_init(); shell_init(); //bot_init(); + irqEnable(0x9); endTask(_current->id); } @@ -95,7 +98,9 @@ static void tcpip_init_done(void *arg) { sys_sem_t *sem = 0x0; sem = arg; + kprintf("SIG"); sys_sem_signal(*sem); + kprintf("NAL"); } /*** diff --git a/src/sys/net/net/sys_arch.c b/src/sys/net/net/sys_arch.c index 9fdceba..2a21e6e 100644 --- a/src/sys/net/net/sys_arch.c +++ b/src/sys/net/net/sys_arch.c @@ -106,7 +106,7 @@ #define SYS_MBOX_SIZE 100 struct sys_mbox { - uInt16 first, last; + uint16_t first, last; void *msgs[SYS_MBOX_SIZE]; struct sys_sem *mail; struct sys_sem *mutex; @@ -130,19 +130,22 @@ static struct sys_sem *sys_sem_new_(uInt8 count); static void sys_sem_free_(struct sys_sem *sem); -static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout); +static uint16_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint16_t timeout); static struct sys_thread *current_thread(void) { struct sys_thread *st; kTask_t *pt; pt = ubthread_self(); + //kprintf("SL: %i-0x%X]", _current->id, &netThreadSpinlock); spinLock(&netThreadSpinlock); for(st = threads; st != NULL; st = st->next) { if(st->ubthread == pt) { + //kprintf("SUL: %i-0x%X]", _current->id, &netThreadSpinlock); spinUnlock(&netThreadSpinlock); return st; } } + //kprintf("SUL: %i-0x%X]", _current->id, &netThreadSpinlock); spinUnlock(&netThreadSpinlock); kprintf("sys: current_thread: could not find current thread!\n"); kprintf("This is due to a race condition in the LinuxThreads\n"); @@ -175,12 +178,15 @@ kprintf("sys_thread: [0x%X]\n",sizeof(struct sys_thread)); thread = kmalloc(sizeof(struct sys_thread)); + memset(thread,0x0,sizeof(struct sys_thread)); kprintf("THREAD: [0x%X]\n",thread); + //kprintf("SL: %i-0x%X]", _current->id, &netThreadSpinlock); spinLock(&netThreadSpinlock); thread->next = threads; thread->timeouts.next = NULL; thread->ubthread = 0x0; threads = thread; + //kprintf("SUL: %i-0x%X]", _current->id, &netThreadSpinlock); spinUnlock(&netThreadSpinlock); @@ -205,6 +211,7 @@ struct sys_mbox *mbox; mbox = kmalloc(sizeof(struct sys_mbox)); + memset(mbox,0x0,sizeof(struct sys_mbox)); mbox->first = mbox->last = 0; mbox->mail = sys_sem_new_(0); mbox->mutex = sys_sem_new_(1); @@ -251,31 +258,42 @@ sys_sem_signal(mbox->mutex); } -uInt16 sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, uInt16 timeout) { - uInt16 time = 1; +uint16_t sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, uint16_t timeout) { + uint16_t time = 1; /* The mutex lock is quick so we don't bother with the timeout stuff here. */ +kprintf("sem wait0"); sys_arch_sem_wait(mbox->mutex, 0); +kprintf("sem wait1"); while(mbox->first == mbox->last) { +kprintf("sem wait2"); sys_sem_signal(mbox->mutex); +kprintf("sem wait3"); /* We block while waiting for a mail to arrive in the mailbox. We must be prepared to timeout. */ if(timeout != 0) { +kprintf("sem wait4"); time = sys_arch_sem_wait(mbox->mail, timeout); +kprintf("sem wait5"); /* If time == 0, the sem_wait timed out, and we return 0. */ if(time == 0) { return 0; } } else { +kprintf("sem wait6"); sys_arch_sem_wait(mbox->mail, 0); +kprintf("sem wait7"); } +kprintf("sem wait8"); sys_arch_sem_wait(mbox->mutex, 0); +kprintf("sem wait9"); } +kprintf("sem wait10"); if(msg != NULL) { //kprintf("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg); @@ -300,15 +318,17 @@ struct sys_sem *sem; sem = kmalloc(sizeof(struct sys_sem)); + memset(sem,0x0,sizeof(struct sys_sem)); sem->c = count; ubthread_cond_init(&(sem->cond), NULL); ubthread_mutex_init(&(sem->mutex), NULL); + kprintf("C: 0x%X, M: 0x%X, ID: %i]",&(sem->cond),&(sem->mutex),_current->id); return sem; } -static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout) { +static uint16_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint16_t timeout) { unsigned int tdiff; unsigned long sec, usec; struct timeval rtime1, rtime2; @@ -348,8 +368,9 @@ } } -uInt16 sys_arch_sem_wait(struct sys_sem *sem, uInt16 timeout) { - uInt16 time = 1; +uint16_t sys_arch_sem_wait(struct sys_sem *sem, uint16_t timeout) { + kprintf("Or Here? %i:%i-0x%X]", _current->id, sem->mutex->pid,&(sem->mutex)); + uint16_t time = 1; ubthread_mutex_lock(&(sem->mutex)); while(sem->c <= 0) { if(timeout > 0) { @@ -368,6 +389,7 @@ } void sys_sem_signal(struct sys_sem *sem) { + kprintf("HERE: %i", _current->id); ubthread_mutex_lock(&(sem->mutex)); sem->c++; if(sem->c > 1) diff --git a/src/sys/net/netif/arp.c b/src/sys/net/netif/arp.c index ed1c4f5..31b87e2 100644 --- a/src/sys/net/netif/arp.c +++ b/src/sys/net/netif/arp.c @@ -206,12 +206,18 @@ } hdr = p->payload; + + //kprintf("HDR->OPCODE: [0x%X]\n", hdr->opcode); switch(htons(hdr->opcode)) { case ARP_REQUEST: + // kprintf("ARP_REQUEST"); +//ip_addr_debug_print(&hdr->dipaddr); +//ip_addr_debug_print(&netif->ip_addr); /* ARP request. If it asked for our address, we send out a reply. */ if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { +//kprintf("MATCHED!\n"); hdr->opcode = htons(ARP_REPLY); ip_addr_set(&(hdr->dipaddr), &(hdr->sipaddr)); @@ -235,6 +241,7 @@ } break; case ARP_REPLY: + kprintf("ARP_RREPLY"); /* ARP reply. We insert or update the ARP table. */ if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { add_arp_entry(&(hdr->sipaddr), &(hdr->shwaddr)); diff --git a/src/sys/net/netif/ethernetif.c b/src/sys/net/netif/ethernetif.c index 8f9a30f..0944148 100644 --- a/src/sys/net/netif/ethernetif.c +++ b/src/sys/net/netif/ethernetif.c @@ -73,7 +73,7 @@ static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; /* Forward declarations. */ -static void ethernetif_input(struct netif *netif); +//static void ethernetif_input(struct netif *netif); static err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); static void ethernetif_thread(); struct device *dev = 0x0; @@ -150,6 +150,7 @@ len = tmpBuf->length; bufptr = tmpBuf->buffer; + //kprintf("LEN: 0x%X", len); /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); @@ -169,6 +170,7 @@ } /* acknowledge that packet has been read(); */ } else { + kprintf("Couldn't Alloc PBUF!"); /* drop packet(); */ } return p; @@ -274,26 +276,37 @@ * */ /*-----------------------------------------------------------------------------------*/ -static void ethernetif_input(struct netif *netif) { +//static void ethernetif_input(struct netif *netif) { +void ethernetif_input(struct netif *netif) { struct ethernetif *ethernetif = 0x0; struct eth_hdr *ethhdr = 0x0; struct pbuf *p = 0x0; ethernetif = netif->state; + + // kprintf("tmpBuf->length: [0x%X]", tmpBuf->length); p = low_level_input(ethernetif); - if(p != NULL) { + //kprintf("p: [0x%X]", p); + if(p != NULL) { ethhdr = p->payload; +//kprintf("type-> [0x%X]\n", htons(ethhdr->type)); switch(htons(ethhdr->type)) { case ETHTYPE_IP: + kprintf("IP.................."); arp_ip_input(netif, p); pbuf_header(p, -14); netif->input(p, netif); + //MR Olsen I added this i am getting no ability to alloc pbuf + if (p != NULL) { + pbuf_free(p); + } break; case ETHTYPE_ARP: + //kprintf("ARP.................."); p = arp_arp_input(netif, ethernetif->ethaddr, p); if(p != NULL) { low_level_output(ethernetif, p); @@ -301,6 +314,7 @@ } break; default: + kprintf("Invalid Type: [0x%X]", htons(ethhdr->type)); pbuf_free(p); break; } diff --git a/src/sys/pci/lnc.c b/src/sys/pci/lnc.c index 99e0d99..48a74f4 100644 --- a/src/sys/pci/lnc.c +++ b/src/sys/pci/lnc.c @@ -33,6 +33,7 @@ #include #include #include +#include struct lncInfo *lnc = 0x0; @@ -89,7 +90,7 @@ memset(lnc, 0x0, sizeof(struct lncInfo)); lnc->bufferSize = 1548; - lnc->ioAddr = 0xD000; + lnc->ioAddr = 0xD020; lnc->nic.ic = lnc_probe(lnc); @@ -105,7 +106,7 @@ /* Extract MAC address from PROM */ for (i = 0; i < ETHER_ADDR_LEN; i++) { - lnc->arpcom.ac_enaddr[i] = inportByte(0xD000 + i); + lnc->arpcom.ac_enaddr[i] = inportByte(lnc->ioAddr + i); kprintf("[0x%X]", lnc->arpcom.ac_enaddr[i]); } } @@ -130,8 +131,8 @@ iW = lnc_readBCR32(lnc, 0x2); iW |= 0x2; - iW |= 0x40; lnc_writeBCR32(lnc, 0x2, iW); + //kprintf("BCR2: [0x%X]", lnc_readBCR32(lnc, 0x2)); lnc->init.mode = 0x0; @@ -165,8 +166,9 @@ break; if (lnc_readCSR32(lnc, CSR0) & IDON) { - setVector(&lnc_isr, mVec + 0x5, (dInt + dPresent + dDpl3)); - irqEnable(0x5); + setVector(&lnc_isr, sVec + 0x1, (dInt + dPresent + dDpl3)); + irqEnable(2); + //irqEnable(0x9); lnc_writeCSR32(lnc, CSR0, STRT | INEA); } else { @@ -174,21 +176,6 @@ return (-1); } - - kprintf("SENDING PACKET [0x%X]", lnc_readCSR32(lnc, CSR3)); - iW = lnc_sendPacket(lnc, &data, strlen(data), 0x0); - - while (1) - asm("nop"); - - while (1) { - iW = lnc_sendPacket(lnc, &data, strlen(data), 0x0); -/* - if (iW == 0) - kprintf("Sending Failed"); -*/ - } - return (0); } @@ -255,6 +242,98 @@ } } +void lnc_INT() { + uint16_t csr0 = 0x0; + + //kprintf("\nINTR\n"); + while ((csr0 = lnc_readCSR32(lnc, CSR0)) & INTR) { + //kprintf("CSR0: [0x%X]\n", csr0); + if (csr0 & ERR) { + kprintf("Error: [0x%X]\n", csr0); + } + if (csr0 & RINT) { + lnc_rxINT(); +/* +asm( + " mov $0xA0,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" + " mov $0x20,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" +); +*/ + } + if (csr0 & TINT) { + kprintf("TINT"); + //lnc_txINT(); +/* +asm( + " mov $0xA0,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" + " mov $0x20,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" +); +*/ + } + lnc_writeCSR32(lnc, CSR0, 0x7940);//csr0); + //kprintf("CSR0.1: [0x%X]\n", lnc_readCSR32(lnc, CSR0)); + } + + kprintf("INT DONE"); +} + +void lnc_rxINT() { + int i = 0; + + //kprintf("RINT\n"); + + if (tmpBuf == 0x0) { + tmpBuf = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer)); + memset(tmpBuf,0x0,sizeof(struct nicBuffer)); + } + else { + memset(tmpBuf,0x0,sizeof(struct nicBuffer)); + } + + while (lnc_driverOwnsRX(lnc)) { + //uint16_t plen = 0 + (uint16_t)lnc->rxRing[lnc->rxPtr].md[2]; + int plen = (lnc->rxRing[lnc->rxPtr].md[2] & 0x0fff ) - 4; +/* + if (plen > 0) + kprintf("plen.0: [0x%X]", plen); +*/ + + tmpBuf->length = plen; + tmpBuf->buffer = (void *)(lnc->rxBuffer + (lnc->rxPtr * lnc->bufferSize)); //(char *)kmalloc(length); + + ethernetif_input(netif_default); + lnc->rxRing[lnc->rxPtr].md[1] = 0x80; + lnc_nextRxPtr(lnc); + } + //kprintf("RINT-DONE[%i][0x%X]\n", lnc->rxPtr,lnc->rxRing[lnc->rxPtr].md[1]); + +} + +void lnc_txINT() { + uint16_t status = 0x0; + + + kprintf("TINT\n"); + status = lnc->txRing[lnc->txPtr].md[1] + (lnc->txRing[lnc->txPtr].md[1] << 16); + kprintf("Status: [0x%X]\n", status); + + while (!lnc_driverOwnsTX(lnc)) { + status = lnc->txRing[lnc->txPtr].md[1] + (lnc->txRing[lnc->txPtr].md[1] << 16); + kprintf("md[1]: 0x%X(%i)[0x%X]\n", lnc->txRing[lnc->txPtr].md[1], lnc->txPtr, status); + lnc->txRing[lnc->txPtr].md[1] = 0x0; + lnc_nextTxPtr(lnc); + } + kprintf("TINT-DONE\n"); +} + void lncInt() { while (1) { kprintf("Finished!!!\n"); @@ -274,6 +353,8 @@ if (csr0 & TINT) { kprintf("TINT\n"); } + outportWord(lnc->ioAddr + RDP, csr0); + kprintf("CSR0: [0x%X]\n", csr0); } kprintf("Finished!!!\n"); return; @@ -288,7 +369,13 @@ " push %es \n" " push %fs \n" " push %gs \n" - " call lncInt \n" + " call lnc_INT \n" + " mov $0xA0,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" + " mov $0x20,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" " pop %gs \n" " pop %fs \n" " pop %es \n" @@ -327,7 +414,7 @@ /* Setup the RX Ring */ for (i = 0; i < NDESC(lnc->nrdre); i++) { - lnc->rxRing[i].addr = (uint32_t) vmm_getRealAddr((uint32_t) lnc->rxRing + (i * lnc->bufferSize)); + lnc->rxRing[i].addr = (uint32_t) vmm_getRealAddr((uint32_t) lnc->rxBuffer + (i * lnc->bufferSize)); bcnt = (uint16_t) (-lnc->bufferSize); bcnt &= 0x0FFF; bcnt |= 0xF000; @@ -360,7 +447,7 @@ /* Setup the TX Ring */ for (i = 0; i < NDESC(lnc->ntdre); i++) { - lnc->txRing[i].addr = (uint32_t) vmm_getRealAddr((uint32_t) lnc->txRing + (i * lnc->bufferSize)); + lnc->txRing[i].addr = (uint32_t) vmm_getRealAddr((uint32_t) lnc->txBuffer + (i * lnc->bufferSize)); bcnt = (uint16_t) (-lnc->bufferSize); bcnt &= 0x0FFF; bcnt |= 0xF000; @@ -393,10 +480,14 @@ return (1); } -int lnc_driverOwns(struct lncInfo *lnc) { +int lnc_driverOwnsTX(struct lncInfo *lnc) { return (lnc->txRing[lnc->txPtr].md[1] & 0x80) == 0; } +int lnc_driverOwnsRX(struct lncInfo *lnc) { + return (lnc->rxRing[lnc->rxPtr].md[1] & 0x80) == 0; +} + int lnc_nextTxPtr(struct lncInfo *lnc) { int ret = lnc->txPtr + 1; @@ -409,10 +500,26 @@ return(0); } +int lnc_nextRxPtr(struct lncInfo *lnc) { + int ret = lnc->rxPtr + 1; + + if (ret == NDESC(lnc->nrdre)) { + ret = 0; + } + + lnc->rxPtr = ret; + + return(0); +} + + int lnc_sendPacket(struct lncInfo *lnc, void *packet, size_t len, uint8_t *dest) { - if (!lnc_driverOwns(lnc)) + kprintf("SEND PACKET1!\n"); + if (!lnc_driverOwnsTX(lnc)) return (0); + kprintf("SEND PACKET2!\n"); + memcpy((void *) (lnc->txBuffer + (lnc->txPtr * lnc->bufferSize)), packet, len); lnc->txRing[lnc->txPtr].md[1] |= 0x2; diff --git a/src/sys/pci/pci.c b/src/sys/pci/pci.c index ac9f307..7b44a9f 100644 --- a/src/sys/pci/pci.c +++ b/src/sys/pci/pci.c @@ -174,8 +174,10 @@ cfg->dev = dev; cfg->func = func; + /* if (cfg->vendorID == 0x1022) pciWrite(bus, dev, func, 0x3C, 0x5,1); + */ switch(cfg->headerType & 0x7F) { case 0x0: /* normal device */ @@ -186,7 +188,7 @@ kprintf("Device Info: /bus/pci/%d/%d/%d\n", bus, dev, func); kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n", cfg->vendorID, cfg->deviceID, cfg->classCode, cfg->subClass, cfg->progIf); kprintf(" * Status: %X Command: %X BIST/Type/Lat/CLS: %X/%X/%X/%X\n", cfg->status, cfg->command, cfg->bist, cfg->headerType, cfg->latencyTimer, cfg->cacheLineSize); - kprintf(" * IRQ: 0x%X.0x%X\n", cfg->intLine, cfg->intPin); + kprintf(" * IRQ: 0x%X.0x%X, BAR[0]: 0x%X\n", cfg->intLine, cfg->intPin, cfg->bar[0]); } break; case 0x1: