From d69e48450c7ea4be4a82c351b2d5dd0de3fc6241 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sat, 1 Dec 2012 16:45:31 +0800 Subject: [PATCH] Kernel - Imported userland strtoi file (and other minor changes) --- KernelLand/Kernel/arch/x86/include/arch.h | 1 - KernelLand/Kernel/include/acess.h | 5 +--- KernelLand/Kernel/include/errno.h | 25 +------------------ KernelLand/Kernel/include/syscalls.h | 2 -- KernelLand/Kernel/libc.c | 13 +++------- KernelLand/Modules/Storage/ATA/main.c | 4 +-- Usermode/Applications/ip_src/routes.c | 10 ++++---- .../libc.so_src/include_exp/errno.enum.h | 25 +++++++++++++++++++ .../Libraries/libc.so_src/include_exp/errno.h | 17 +------------ Usermode/Libraries/libc.so_src/strtoi.c | 15 ++++++----- 10 files changed, 46 insertions(+), 71 deletions(-) create mode 100644 Usermode/Libraries/libc.so_src/include_exp/errno.enum.h diff --git a/KernelLand/Kernel/arch/x86/include/arch.h b/KernelLand/Kernel/arch/x86/include/arch.h index 040e18bb..65868452 100644 --- a/KernelLand/Kernel/arch/x86/include/arch.h +++ b/KernelLand/Kernel/arch/x86/include/arch.h @@ -78,7 +78,6 @@ typedef signed char Sint8; typedef signed short Sint16; typedef signed long Sint32; typedef signed long long Sint64; -typedef Uint size_t; typedef char BOOL; typedef Uint32 tPAddr; diff --git a/KernelLand/Kernel/include/acess.h b/KernelLand/Kernel/include/acess.h index 27dbb2a6..24148e14 100644 --- a/KernelLand/Kernel/include/acess.h +++ b/KernelLand/Kernel/include/acess.h @@ -9,10 +9,9 @@ * \brief Acess2 Kernel API Core */ +#include #include -//! NULL Pointer -#define NULL ((void*)0) //! Pack a structure #define PACKED __attribute__((packed)) //! Mark a function as not returning @@ -23,8 +22,6 @@ #define DEPRECATED __attribute__((deprecated)) //! Mark a parameter as unused #define UNUSED(x) UNUSED_##x __attribute__((unused)) -//! Get the offset of a member in a structure -#define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 )) /** * \name Boolean constants diff --git a/KernelLand/Kernel/include/errno.h b/KernelLand/Kernel/include/errno.h index 31f68a0c..f6ec953e 100644 --- a/KernelLand/Kernel/include/errno.h +++ b/KernelLand/Kernel/include/errno.h @@ -5,29 +5,6 @@ #ifndef _ERRNO_H #define _ERRNO_H -enum eErrorNums -{ - EOK, - - ENOSYS, // Invalid Instruction - EINVAL, // Invalid Paramater - ENOMEM, // No free memory - EACCES, // Not permitted - EBUSY, // Resource is busy - ENOTFOUND, // Item not found - EREADONLY, // Read only - ENOTIMPL, // Not implemented - ENOENT, // No entry? - EEXIST, // Already exists - ENFILE, // Too many open files - ENOTDIR, // Not a directory - EIO, // IO Error - EINTR, // Operation interrupted (signal) - - EALREADY, // Operation was a NOP - EINTERNAL, // Internal Error - - NUM_ERRS -}; +#include "../../../Usermode/Libraries/libc.so_src/include_exp/errno.enum.h" #endif diff --git a/KernelLand/Kernel/include/syscalls.h b/KernelLand/Kernel/include/syscalls.h index 601a7f4f..4164e647 100644 --- a/KernelLand/Kernel/include/syscalls.h +++ b/KernelLand/Kernel/include/syscalls.h @@ -69,7 +69,6 @@ #define SYS_DEBUG 0x100 #ifndef __ASSEMBLER__ -#ifndef NO_SYSCALL_STRS static const char *cSYSCALL_NAMES[] = { "SYS_EXIT", "SYS_CLONE", @@ -163,6 +162,5 @@ static const char *cSYSCALL_NAMES[] = { "" }; #endif -#endif #endif diff --git a/KernelLand/Kernel/libc.c b/KernelLand/Kernel/libc.c index 67ce9b2e..a5f87e43 100644 --- a/KernelLand/Kernel/libc.c +++ b/KernelLand/Kernel/libc.c @@ -67,15 +67,10 @@ EXPORT(CheckString); EXPORT(CheckMem); // === CODE === -/** - * \brief Convert a string into an integer - */ -int atoi(const char *string) -{ - int ret = 0; - ParseInt(string, &ret); - return ret; -} +// - Import userland stroi.c file +#define _LIB_H_ +#include "../../Usermode/Libraries/libc.so_src/strtoi.c" + int ParseInt(const char *string, int *Val) { int ret = 0; diff --git a/KernelLand/Modules/Storage/ATA/main.c b/KernelLand/Modules/Storage/ATA/main.c index a131a445..050faad1 100644 --- a/KernelLand/Modules/Storage/ATA/main.c +++ b/KernelLand/Modules/Storage/ATA/main.c @@ -122,7 +122,7 @@ int ATA_ScanDisk(int Disk) /** * \fn Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk) */ -int ATA_ReadRaw(void *Ptr, Uint64 Address, Uint Count, void *Buffer) +int ATA_ReadRaw(void *Ptr, Uint64 Address, size_t Count, void *Buffer) { int Disk = (tVAddr)Ptr; int ret; @@ -160,7 +160,7 @@ int ATA_ReadRaw(void *Ptr, Uint64 Address, Uint Count, void *Buffer) /** * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk) */ -int ATA_WriteRaw(void *Ptr, Uint64 Address, Uint Count, const void *Buffer) +int ATA_WriteRaw(void *Ptr, Uint64 Address, size_t Count, const void *Buffer) { int Disk = (tVAddr)Ptr; int ret; diff --git a/Usermode/Applications/ip_src/routes.c b/Usermode/Applications/ip_src/routes.c index ba568135..a5f682ce 100644 --- a/Usermode/Applications/ip_src/routes.c +++ b/Usermode/Applications/ip_src/routes.c @@ -50,15 +50,15 @@ int Routes_main(int argc, char *argv[]) } // Destination IP - addrType = ParseIPAddress(argv[3], dest, &subnetBits); + addrType = ParseIPAddress(argv[2], dest, &subnetBits); if( subnetBits == -1 ) { subnetBits = Net_GetAddressSize(addrType)*8; } // Interface Name / Next Hop - if( (nextHopType = ParseIPAddress(argv[4], nextHop, &nextHopBits)) == 0 ) + if( (nextHopType = ParseIPAddress(argv[3], nextHop, &nextHopBits)) == 0 ) { // Interface name - ifaceName = argv[4]; + ifaceName = argv[3]; } else { @@ -78,8 +78,8 @@ int Routes_main(int argc, char *argv[]) // Metric if( argc - 3 >= 3 ) { - metric = atoi(argv[5]); - if( metric == 0 && argv[5][0] != '0' ) { + metric = atoi(argv[4]); + if( metric == 0 && argv[4][0] != '0' ) { fprintf(stderr, "ERROR: Metric should be a number\n"); return -1; } diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h new file mode 100644 index 00000000..090b06bf --- /dev/null +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h @@ -0,0 +1,25 @@ + +enum { + EOK, + ENOSYS, // Invalid Instruction + EINVAL, // Invalid Paramater + ENOMEM, // No free memory + EACCES, // Not permitted + EBUSY, // Resource is busy + ERANGE, // Value out of range + ENOTFOUND, // Item not found + EREADONLY, // Read only + ENOTIMPL, // Not implemented + ENOENT, // No entry? + EEXIST, // Already exists + ENFILE, // Too many open files + ENOTDIR, // Not a directory + EIO, // IO Error + EINTR, // Operation interrupted (signal) + + EALREADY, // Operation was a NOP + EINTERNAL, // Internal Error + + NUM_ERRNO +}; + diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.h b/Usermode/Libraries/libc.so_src/include_exp/errno.h index ea352f3b..cbe87490 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/errno.h +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.h @@ -8,21 +8,6 @@ extern int _errno; #define strerror(_x) "Unimplemented" -enum -{ - EOK, - EINVAL, - ERANGE, - ENODEV, - EBADF, - EINTR, - EAGAIN, - ENOMEM, - - EADDRNOTAVAIL, - EINPROGRESS, - - E_LAST -}; +#include "errno.enum.h" #endif diff --git a/Usermode/Libraries/libc.so_src/strtoi.c b/Usermode/Libraries/libc.so_src/strtoi.c index 53756dc8..9326fb8a 100644 --- a/Usermode/Libraries/libc.so_src/strtoi.c +++ b/Usermode/Libraries/libc.so_src/strtoi.c @@ -5,13 +5,12 @@ * strtoi.c * - strto[u][l]l/atoi implimentation */ -#include #include #include #include -#include "lib.h" +#include -EXPORT unsigned long long strtoull(const char *str, char **end, int base) +unsigned long long strtoull(const char *str, char **end, int base) { long long ret = 0; @@ -71,7 +70,7 @@ EXPORT unsigned long long strtoull(const char *str, char **end, int base) return ret; } -EXPORT unsigned long strtoul(const char *ptr, char **end, int base) +unsigned long strtoul(const char *ptr, char **end, int base) { unsigned long long tmp = strtoull(ptr, end, base); @@ -83,7 +82,7 @@ EXPORT unsigned long strtoul(const char *ptr, char **end, int base) return tmp; } -EXPORT long long strtoll(const char *str, char **end, int base) +long long strtoll(const char *str, char **end, int base) { int neg = 0; unsigned long long ret; @@ -110,7 +109,7 @@ EXPORT long long strtoll(const char *str, char **end, int base) return ret; } -EXPORT long strtol(const char *str, char **end, int base) +long strtol(const char *str, char **end, int base) { long long tmp = strtoll(str, end, base); if( tmp > LONG_MAX || tmp < LONG_MIN ) { @@ -121,10 +120,10 @@ EXPORT long strtol(const char *str, char **end, int base) } /** - * \fn EXPORT int atoi(const char *str) + * \fn int atoi(const char *str) * \brief Convert a string to an integer */ -EXPORT int atoi(const char *str) +int atoi(const char *str) { long long tmp = strtoll(str, NULL, 0); if( tmp > INT_MAX || tmp < INT_MIN ) { -- 2.20.1