X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fhelpers.c;h=6396d1666c755eb92d7d99e1466604509c60ebfa;hb=72a6cd13feb274ef597501c6959d62f1382b8f7c;hp=2209b05f22e518a8e2c52a636430f1185a99f075;hpb=602ba046995f564d8ca4b85c873cbfcafed72d42;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/helpers.c b/AcessNative/acesskernel_src/helpers.c index 2209b05f..6396d166 100644 --- a/AcessNative/acesskernel_src/helpers.c +++ b/AcessNative/acesskernel_src/helpers.c @@ -4,11 +4,14 @@ * * Kernel Main */ -#include +#include #include #include +#include #include +#include +#if 0 void LogF(const char *Fmt, ...) { va_list args; @@ -50,12 +53,58 @@ void Panic(const char *Format, ...) void Debug_SetKTerminal(const char *Path) { - // Ignored, kernel debug goes to stdout + // Ignored, kernel debug goes to stdout instead of a virtual terminal } +#endif -void *Heap_Allocate(int Count, const char *File, int Line) +void KernelPanic_SetMode(void) +{ + // NOP - No need +} +void KernelPanic_PutChar(char ch) +{ + fprintf(stderr, "%c", ch); +} +void Debug_PutCharDebug(char ch) +{ + printf("%c", ch); + if( ch == '\n' ) + fflush(stdout); +} +void Debug_PutStringDebug(const char *String) +{ + printf("%s", String); + if( strchr(String, '\n') ) + fflush(stdout); +} + +void *Heap_Allocate(const char *File, int Line, int ByteCount) +{ + return malloc(ByteCount); +} + +void *Heap_AllocateZero(const char *File, int Line, int ByteCount) +{ + return calloc(ByteCount, 1); +} + +void *Heap_Reallocate(const char *File, int Line, void *Ptr, int Bytes) +{ + return realloc(Ptr, Bytes); +} + +void Heap_Deallocate(void *Ptr) +{ + free(Ptr); +} + +char *Heap_StringDup(const char *File, int Line, const char *Str) +{ + return strdup(Str); +} + +void Heap_Dump(void) { - return malloc(Count); } tPAddr MM_GetPhysAddr(tVAddr VAddr) @@ -63,6 +112,11 @@ tPAddr MM_GetPhysAddr(tVAddr VAddr) return VAddr; // HACK! } +int MM_IsValidBuffer(tVAddr Base, int Size) +{ + return 1; +} + Uint MM_GetFlags(tVAddr VAddr) { return 0; @@ -81,3 +135,64 @@ Sint64 now(void) return tv.tv_sec * 1000 + tv.tv_usec/1000; } +void IPStack_SendDebugText(const char *str) +{ + // nop +} + +int strpos(const char *str, char ch) +{ + const char *retptr = strchr(str, ch); + int rv = retptr ? retptr - str : -1; + return rv; +} + +int CheckString(const char *string) +{ + if( (intptr_t)string < 0x1000 ) + return 0; + return 1; +} + +int CheckMem(const void *buf, size_t len) +{ + if( (intptr_t)buf < 0x1000 ) + return 0; + return 1; +} + +void itoa(char *buf, Uint64 num, int base, int minLength, char pad) +{ + static const char cUCDIGITS[] = "0123456789ABCDEF"; + char tmpBuf[64+1]; + int pos=0, i; + Uint64 rem; + + // Sanity check + if(!buf) return; + + // Sanity Check + if(base > 16 || base < 2) { + buf[0] = 0; + return; + } + + // Convert + while(num > base-1) { + rem = num % base; + num = num / base; // Shift `num` and get remainder + tmpBuf[pos] = cUCDIGITS[ rem ]; + pos++; + } + tmpBuf[pos++] = cUCDIGITS[ num ]; // Last digit of `num` + + // Put in reverse + i = 0; + minLength -= pos; + while(minLength-- > 0) + buf[i++] = pad; + while(pos-- > 0) + buf[i++] = tmpBuf[pos]; // Reverse the order of characters + buf[i] = 0; +} +