4. STL port was done - WebKit porting to Mona OS

The prvious problem we fronted was bootstrap hunging up. I've never imagined I should dive into bootstrap code again!
Finally I found what was wrong.
The bootstrap sequence is

  1. firstboot reads and jumps into secondboot
  2. secondboot reads KERNEL.BIN, FILE.BIN, MONITOR.BIN and PROCESS.BIN to some location, and jumps into kernel.

The latest STL generates bigger binary, so PROCESS.BIN became bigger. Reading PROCESS.BIN to the location caused secondboot code overwritten.
Fixed the problem and bootstrap worked.


After a few fixes, Mona successfully worked with the latest STL port. I have to say the library is really great. It's easy to port and configure.
Okay the last errors on JavaScriptCore was "error: 'numeric_limits' is not a member of '_STL'", it disappeared with the latest STL.

The next errors were

../../../Source/JavaScriptCore/wtf/Atomics.h: In function ‘int WTF::atomicIncrement(volatile int*)’:
../../../Source/JavaScriptCore/wtf/Atomics.h:106: error: ‘__gnu_cxx’ has not been declared
../../../Source/JavaScriptCore/wtf/Atomics.h: In function ‘int WTF::atomicDecrement(volatile int*)’:
../../../Source/JavaScriptCore/wtf/Atomics.h:107: error: ‘__gnu_cxx’ has not been declared

It seems that we have to implement atomicIncrement for our OS. For now just wrote stub with assert.

/home/taro/mona/include/STLport-5.2.1/stlport/stl/_limits.h:198: error: ‘M_SCHAR_MIN’ was not declared in this scope
/home/taro/mona/include/STLport-5.2.1/stlport/stl/_limits.h:198: error: ‘M_UCHAR_MAX’ was not declared in this scope

Our limits.h missed these values, defined.

../../../Source/JavaScriptCore/wtf/RefCounted.h: In member function ‘void WTF::RefCountedBase::ref()’:
../../../Source/JavaScriptCore/wtf/RefCounted.h:53: error: ‘m_verifier’ was not declared in this scope
        // If this assert fires, it either indicates a thread safety issue or
        // that the verification needs to change. See ThreadRestrictionVerifier for
        // the different modes.
        ASSERT(m_verifier.isSafeToUse());

The problem is ASSERT is also defined on monapi.h. I think the name "ASSERT" should not be used as a macro name, since it's too common.
Renamed our ASSERT to MONA_ASSERT.

The next errors were

../../../Source/JavaScriptCore/wtf/CurrentTime.h: In function ‘void WTF::getLocalTime(const time_t*, tm*)’:
../../../Source/JavaScriptCore/wtf/CurrentTime.h:53: error: ‘localtime’ was not declared in this scope
../../../Source/JavaScriptCore/wtf/CurrentTime.cpp: In function ‘double WTF::currentTime()’:
../../../Source/JavaScriptCore/wtf/CurrentTime.cpp:303: error: ‘gettimeofday’ was not declared in this scope

Added stub functions of them.

../../../Source/JavaScriptCore/wtf/StringExtras.h:34:22: error: strings.h: No such file or directory

The file is required for strcasecmp. Added the file.
BTW, I saw some OS macros such as OS(ANDROID), we should define OS(MONA). If added a compiler option -D WTF_OS_MONA=1, OS(MONA) becomes true.

../../../Source/JavaScriptCore/wtf/MathExtras.h:258: error: ‘stlp_std::isfinite’ has not been declared
../../../Source/JavaScriptCore/wtf/MathExtras.h:259: error: ‘stlp_std::isinf’ has not been declared
../../../Source/JavaScriptCore/wtf/MathExtras.h:260: error: ‘stlp_std::isnan’ has not been declared
../../../Source/JavaScriptCore/wtf/MathExtras.h:261: error: ‘stlp_std::signbit’ has not been declared

Here were macros as following

#if !COMPILER(MSVC) && !(COMPILER(RVCT) && PLATFORM(BREWMP)) && !OS(SOLARIS) && !OS(SYMBIAN)

Added && !OS(MONA).

../../../Source/JavaScriptCore/wtf/PageBlock.cpp:88: error: ‘systemPageSize’ was not declared in this scope

Page size is OS (or architecture) dependent. Defined the function for Mona.

../../../Source/JavaScriptCore/wtf/StackBounds.cpp:284:2: error: #error Need a way to get the stack bounds on this platform

Is this required for GC?.
Added following. We should come back when thread support is enabled.

#elif OS(MONA)
void StackBounds::initialize()
{
    m_origin = (void*)0xF0000000;
    m_bound = estimateStackBound(m_origin);
}
../../../Source/JavaScriptCore/API/JSStringRef.cpp:39: error: invalid conversion from ‘const JSChar*’ to ‘const UChar*’
../../../Source/JavaScriptCore/API/JSStringRef.cpp:39: error:   initialising argument 1 of ‘static WTF::PassRefPtr<OpaqueJSString> OpaqueJSString::create(const UChar*, unsigned int)

A definition of JSChar is

#if !defined(WIN32) && !defined(_WIN32) && !defined(__WINSCW__) \
    && !((defined(__CC_ARM) || defined(__ARMCC__)) && !defined(__linux__)) /* RVCT */
/*!
@typedef JSChar
@abstract A Unicode character.
*/
    typedef unsigned short JSChar;
#else
    typedef wchar_t JSChar;
#endif

A defined of UChar is

// ugly hack to make UChar compatible with JSChar in API/JSStringRef.h
#if defined(Q_OS_WIN) || COMPILER(WINSCW) || (COMPILER(RVCT) && !OS(LINUX))
typedef wchar_t UChar;
#else
typedef uint16_t UChar;
#endif

JSChar and UChar should be the same size.


We need usleep, but we don't have.
The following is workaround.

#elif OS(MONA)

static void sleepForMicroseconds(unsigned us)
{
    sleep(1);
}


That's all for today.