diff --git a/include/comrogue/internals/trace.h b/include/comrogue/internals/trace.h index 6d93fa3..e237fc0 100644 --- a/include/comrogue/internals/trace.h +++ b/include/comrogue/internals/trace.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,7 @@ extern void TrWriteString8(PCSTR str); extern void TrWriteWord(UINT32 uiValue); extern HRESULT TrVPrintf8(PCSTR pszFormat, va_list pargs); extern HRESULT TrPrintf8(PCSTR pszFormat, ...); +extern HRESULT TrGetSequentialStream(ISequentialStream **ppstm); extern void TrAssertFailed(PCSTR pszFile, INT32 nLine); extern void TrInfiniBlink(void); diff --git a/include/comrogue/objhelp.h b/include/comrogue/objhelp.h index a5cd84d..02ec098 100644 --- a/include/comrogue/objhelp.h +++ b/include/comrogue/objhelp.h @@ -37,17 +37,20 @@ #include #include #include +#include CDECL_BEGIN /* QueryInterface helpers */ extern HRESULT ObjHlpStandardQueryInterface_IMalloc(IUnknown *pThis, REFIID riid, PPVOID ppvObject); +extern HRESULT ObjHlpStandardQueryInterface_ISequentialStream(IUnknown *pThis, REFIID riid, PPVOID ppvObject); /* AddRef/Release helpers */ extern UINT32 ObjHlpStaticAddRefRelease(IUnknown *pThis); /* Other helpers */ extern void ObjHlpDoNothingReturnVoid(IUnknown *pThis); +extern HRESULT ObjHlpNotImplemented(IUnknown *pThis); CDECL_END diff --git a/include/comrogue/scode.h b/include/comrogue/scode.h index 1178328..94ccbc6 100644 --- a/include/comrogue/scode.h +++ b/include/comrogue/scode.h @@ -81,30 +81,88 @@ #endif /* __ASM__ */ /* Basic success codes */ -#define S_OK SCODE_CAST(0x00000000) /* OK return */ -#define S_FALSE SCODE_CAST(0x00000001) /* "False" return */ +#define S_OK SCODE_CAST(0x00000000) /* OK return */ +#define S_FALSE SCODE_CAST(0x00000001) /* "False" return */ + +/* Storage success codes */ +#define STG_S_CONVERTED SCODE_CAST(0x00030200) /* storage converted transparently */ +#define STG_S_BLOCK SCODE_CAST(0x00030201) /* block until we get more data */ +#define STG_S_RETRYNOW SCODE_CAST(0x00030202) /* retry operation immediately */ +#define STG_S_MONITORING SCODE_CAST(0x00030203) /* notified event sink won't affect storage */ +#define STG_S_MULTIPLEOPENS SCODE_CAST(0x00030204) /* multiple opens prevent consolidation */ +#define STG_S_CONSOLIDATIONFAILED SCODE_CAST(0x00030205) /* consolidation failed but commit OK */ +#define STG_S_CANNOTCONSOLIDATE SCODE_CAST(0x00030206) /* cannot consolidate but commit OK */ /* Basic error codes */ -#define E_NOTIMPL SCODE_CAST(0x80000001) /* not implemented */ -#define E_OUTOFMEMORY SCODE_CAST(0x80000002) /* out of memory */ -#define E_INVALIDARG SCODE_CAST(0x80000003) /* invalid argument */ -#define E_NOINTERFACE SCODE_CAST(0x80000004) /* no such interface */ -#define E_POINTER SCODE_CAST(0x80000005) /* invalid pointer */ -#define E_HANDLE SCODE_CAST(0x80000006) /* invalid handle */ -#define E_ABORT SCODE_CAST(0x80000007) /* aborted operation */ -#define E_FAIL SCODE_CAST(0x80000008) /* unspecified failure */ -#define E_ACCESSDENIED SCODE_CAST(0x80000009) /* access denied */ -#define E_PENDING SCODE_CAST(0x8000000A) /* data not yet available */ -#define E_UNEXPECTED SCODE_CAST(0x8000FFFF) /* unexpected error */ +#define E_NOTIMPL SCODE_CAST(0x80000001) /* not implemented */ +#define E_OUTOFMEMORY SCODE_CAST(0x80000002) /* out of memory */ +#define E_INVALIDARG SCODE_CAST(0x80000003) /* invalid argument */ +#define E_NOINTERFACE SCODE_CAST(0x80000004) /* no such interface */ +#define E_POINTER SCODE_CAST(0x80000005) /* invalid pointer */ +#define E_HANDLE SCODE_CAST(0x80000006) /* invalid handle */ +#define E_ABORT SCODE_CAST(0x80000007) /* aborted operation */ +#define E_FAIL SCODE_CAST(0x80000008) /* unspecified failure */ +#define E_ACCESSDENIED SCODE_CAST(0x80000009) /* access denied */ +#define E_PENDING SCODE_CAST(0x8000000A) /* data not yet available */ +#define E_UNEXPECTED SCODE_CAST(0x8000FFFF) /* unexpected error */ + +/* Storage error codes */ +#define STG_E_INVALIDFUNCTION SCODE_CAST(0x80030001) /* invalid function */ +#define STG_E_FILENOTFOUND SCODE_CAST(0x80030002) /* file not found */ +#define STG_E_PATHNOTFOUND SCODE_CAST(0x80030003) /* path not found */ +#define STG_E_TOOMANYOPENFILES SCODE_CAST(0x80030004) /* too many open files */ +#define STG_E_ACCESSDENIED SCODE_CAST(0x80030005) /* access denied */ +#define STG_E_INVALIDHANDLE SCODE_CAST(0x80030006) /* invalid handle */ +#define STG_E_INSUFFICIENTMEMORY SCODE_CAST(0x80030008) /* insufficient memory */ +#define STG_E_INVALIDPOINTER SCODE_CAST(0x80030009) /* invalid pointer */ +#define STG_E_NOMOREFILES SCODE_CAST(0x80030012) /* no more files to return */ +#define STG_E_DISKISWRITEPROTECTED SCODE_CAST(0x80030013) /* disk is write protected */ +#define STG_E_SEEKERROR SCODE_CAST(0x80030019) /* error in seek operation */ +#define STG_E_WRITEFAULT SCODE_CAST(0x8003001D) /* disk error during write */ +#define STG_E_READFAULT SCODE_CAST(0x8003001E) /* disk error during read */ +#define STG_E_SHAREVIOLATION SCODE_CAST(0x80030020) /* sharing violation */ +#define STG_E_LOCKVIOLATION SCODE_CAST(0x80030021) /* lock violation */ +#define STG_E_FILEALREADYEXISTS SCODE_CAST(0x80030050) /* file already exists */ +#define STG_E_INVALIDPARAMETER SCODE_CAST(0x80030057) /* invalid parameter */ +#define STG_E_MEDIUMFULL SCODE_CAST(0x80030070) /* out of disk space */ +#define STG_E_PROPSETMISMATCHED SCODE_CAST(0x800300F0) /* illegal write of property to property set */ +#define STG_E_ABNORMALAPIEXIT SCODE_CAST(0x800300FA) /* API call exited abnormally */ +#define STG_E_INVALIDHEADER SCODE_CAST(0x800300FB) /* invalid file header */ +#define STG_E_INVALIDNAME SCODE_CAST(0x800300FC) /* invalid name */ +#define STG_E_UNKNOWN SCODE_CAST(0x800300FD) /* unknown/unexpected error */ +#define STG_E_UNIMPLEMENTEDFUNCTION SCODE_CAST(0x800300FE) /* unimplemented function */ +#define STG_E_INVALIDFLAG SCODE_CAST(0x800300FF) /* invalid flag */ +#define STG_E_INUSE SCODE_CAST(0x80030100) /* object is busy */ +#define STG_E_NOTCURRENT SCODE_CAST(0x80030101) /* not current */ +#define STG_E_REVERTED SCODE_CAST(0x80030102) /* object reverted and no longer exists */ +#define STG_E_CANTSAVE SCODE_CAST(0x80030103) /* can't save */ +#define STG_E_OLDFORMAT SCODE_CAST(0x80030104) /* older file format */ +#define STG_E_OLDDLL SCODE_CAST(0x80030105) /* newer file format */ +#define STG_E_SHAREREQUIRED SCODE_CAST(0x80030106) /* file sharing required */ +#define STG_E_NOTFILEBASEDSTORAGE SCODE_CAST(0x80030107) /* illegal operation on storage */ +#define STG_E_EXTANTMARSHALLINGS SCODE_CAST(0x80030108) /* illegal operation on extant marshallings */ +#define STG_E_DOCFILECORRUPT SCODE_CAST(0x80030109) /* docfile corrupt */ +#define STG_E_BADBASEADDRESS SCODE_CAST(0x80030110) /* invalid base address */ +#define STG_E_DOCFILETOOLARGE SCODE_CAST(0x80030111) /* docfile too large */ +#define STG_E_NOTSIMPLEFORMAT SCODE_CAST(0x80030112) /* docfile not a simple format */ +#define STG_E_INCOMPLETE SCODE_CAST(0x80030201) /* file incomplete */ +#define STG_E_TERMINATED SCODE_CAST(0x80030202) /* download terminated */ +#define STG_E_COPYPROTECTFAIL SCODE_CAST(0x80030305) /* copy protection failed */ +#define STG_E_CSSAUTHFAIL SCODE_CAST(0x80030306) /* CSS authentication failed */ +#define STG_E_CSSKEYNOTPRESENT SCODE_CAST(0x80030307) /* CSS key not present */ +#define STG_E_CSSKEYNOTESTABLISHED SCODE_CAST(0x80030308) /* CSS key not established */ +#define STG_E_CSSSCRAMBLED SCODE_CAST(0x80030309) /* encrypted sector */ +#define STG_E_CSSINVALIDREGION SCODE_CAST(0x8003030A) /* region identifier mismatch */ +#define STG_E_NOMOREREGIONRESETS SCODE_CAST(0x8003030B) /* can't reset drive region anymore */ /* Memory manager error codes */ -#define MEMMGR_E_NOPGTBL SCODE_CAST(0x86010001) /* no page tables available */ -#define MEMMGR_E_BADTTBFLG SCODE_CAST(0x86010002) /* bad TTB flags encountered */ -#define MEMMGR_E_COLLIDED SCODE_CAST(0x86010003) /* memory mapping collided */ -#define MEMMGR_E_ENDTTB SCODE_CAST(0x86010004) /* tried to "walk off" end of TTB */ -#define MEMMGR_E_NOSACRED SCODE_CAST(0x86010005) /* tried to demap a "sacred" entry */ -#define MEMMGR_E_NOKERNSPC SCODE_CAST(0x86010006) /* no kernel space */ -#define MEMMGR_E_RECURSED SCODE_CAST(0x86010007) /* tried to recurse into page allocation */ -#define MEMMGR_E_BADTAGS SCODE_CAST(0x86010008) /* invalid tags for freed page */ +#define MEMMGR_E_NOPGTBL SCODE_CAST(0x86010001) /* no page tables available */ +#define MEMMGR_E_BADTTBFLG SCODE_CAST(0x86010002) /* bad TTB flags encountered */ +#define MEMMGR_E_COLLIDED SCODE_CAST(0x86010003) /* memory mapping collided */ +#define MEMMGR_E_ENDTTB SCODE_CAST(0x86010004) /* tried to "walk off" end of TTB */ +#define MEMMGR_E_NOSACRED SCODE_CAST(0x86010005) /* tried to demap a "sacred" entry */ +#define MEMMGR_E_NOKERNSPC SCODE_CAST(0x86010006) /* no kernel space */ +#define MEMMGR_E_RECURSED SCODE_CAST(0x86010007) /* tried to recurse into page allocation */ +#define MEMMGR_E_BADTAGS SCODE_CAST(0x86010008) /* invalid tags for freed page */ #endif /* __SCODE_H_INCLUDED */ diff --git a/kernel/lib/objhelp.c b/kernel/lib/objhelp.c index 959856a..8ff2552 100644 --- a/kernel/lib/objhelp.c +++ b/kernel/lib/objhelp.c @@ -36,6 +36,7 @@ #include #include #include +#include #include /*-------------------------------------------- @@ -93,6 +94,7 @@ HRESULT ObjHlpStandardQueryInterface_ ## iface (IUnknown *pThis, REFIID riid, PP } MAKE_BASE_QI(IMalloc) +MAKE_BASE_QI(ISequentialStream) /* * "Dummy" version of AddRef/Release used for static objects. @@ -121,3 +123,17 @@ void ObjHlpDoNothingReturnVoid(IUnknown *pThis) { /* do nothing */ } + +/* + * Method that does nothing and returns E_NOTIMPL. + * + * Parameters: + * - pThis = Base interface pointer. + * + * Returns: + * E_NOTIMPL. + */ +HRESULT ObjHlpNotImplemented(IUnknown *pThis) +{ + return E_NOTIMPL; +} diff --git a/kernel/trace.c b/kernel/trace.c index 3bbd689..870315c 100644 --- a/kernel/trace.c +++ b/kernel/trace.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -258,6 +260,65 @@ void TrAssertFailed(PCSTR pszFile, INT32 nLine) TrPrintf8(szMessage, pszFile, nLine); } +/* + * Writes a buffer full of data (assumed 8-bit) to the trace output. + * + * Parameters: + * - pThis = ISequentialStream output pointer (ignored). + * - pv = Pointer to buffer to be written. + * - cb = Number of bytes to be written. + * - pcbWritten = If non-NULL, points to variable that will receive the number of bytes actually written. + * + * Returns: + * Standard HRESULT success/failure indicator. + */ +static HRESULT traceStreamWrite(ISequentialStream *pThis, PCVOID pv, UINT32 cb, UINT32 *pcbWritten) +{ + register PCHAR p1, p2; /* buffer pointers */ + + if (!pv) + return STG_E_INVALIDPOINTER; + p1 = (PCHAR)pv; + p2 = p1 + cb; + while (p1 < p2) + TrWriteChar8(*p1++); + if (pcbWritten) + *pcbWritten = cb; + return S_OK; +} + +/* VTable for an implementation of ISequentialStream that outputs to the trace output. */ +static const SEG_RODATA struct ISequentialStreamVTable vtblTraceStream = +{ + .QueryInterface = ObjHlpStandardQueryInterface_ISequentialStream, + .AddRef = ObjHlpStaticAddRefRelease, + .Release = ObjHlpStaticAddRefRelease, + .Read = (HRESULT (*)(ISequentialStream*, PVOID, UINT32, UINT32*))ObjHlpNotImplemented, + .Write = traceStreamWrite +}; + +/* Implementation of ISequentialStream that outputs to the trace output. */ +static const SEG_RODATA ISequentialStream traceStream = { &vtblTraceStream }; + +/* + * Stores a pointer to the ISequentialStream implementation that outputs to the trace output. When + * done with the pointer, be sure to call Release() on it. + * + * Parameters: + * - ppstm = Pointer to the variable to receive the ISequentialStream pointer. + * + * Returns: + * Standard HRESULT success/failure indicator. + */ +HRESULT TrGetSequentialStream(ISequentialStream **ppstm) +{ + if (!ppstm) + return E_POINTER; + *ppstm = (ISequentialStream *)(&traceStream); + IUnknown_AddRef(*ppstm); + return S_OK; +} + /* * Puts the CPU into a loop where it blinks the green ACTIVITY light forever. *