Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on boot and debugger #1624

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,50 @@ void CLR_DBG_Debugger::Debugger_WaitForCommands()
}
}

void CLR_DBG_Debugger::Debugger_Discovery()
{
NATIVE_PROFILE_CLR_DEBUGGER();

CLR_INT32 wait_sec = 5;

CLR_INT64 expire = HAL_Time_CurrentTime() + (wait_sec * TIME_CONVERSION__TO_SECONDS);

// Send "presence" ping.
Monitor_Ping_Command cmd;
cmd.m_source = Monitor_Ping_c_Ping_Source_NanoCLR;

while(true)
{
CLR_EE_DBG_EVENT_BROADCAST(CLR_DBG_Commands::c_Monitor_Ping, sizeof(cmd), &cmd, WP_Flags_c_NoCaching | WP_Flags_c_NonCritical);

// if we support soft reboot and the debugger is not stopped then we don't need to connect the debugger
if(!CLR_EE_DBG_IS(Stopped) && ::CPU_IsSoftRebootSupported())
{
break;
}

g_CLR_RT_ExecutionEngine.DebuggerLoop();

if(CLR_EE_DBG_IS(Enabled))
{
// Debugger on the other side, let's exit the discovery loop.
CLR_Debug::Printf( "Debugger found. Resuming boot sequence.\r\n" );
break;
}

CLR_INT64 now = HAL_Time_CurrentTime();

if(expire < now)
{
// no response after timeout...
CLR_Debug::Printf( "No debugger found...\r\n" );
break;
}
}

g_CLR_RT_ExecutionEngine.WaitForDebugger();
}

////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CLR_DBG_Debugger::CreateInstance()
Expand Down Expand Up @@ -884,10 +928,12 @@ bool CLR_DBG_Debugger::Monitor_Reboot( WP_Message* msg)
g_CLR_RT_ExecutionEngine.m_iReboot_Options = cmd->m_flags;
}

CLR_EE_DBG_SET( RebootPending );

WP_ReplyToCommand(msg, true, false, NULL, 0);

Events_WaitForEvents( 0, 100 ); // give message a little time to be flushed

CLR_EE_DBG_SET( RebootPending );

return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/CLR/Debugger/Debugger_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@


////////////////////////////////////////////////////////////////////////////////////////////////////
__nfweak void CLR_DBG_Debugger::Debugger_Discovery()
{
NATIVE_PROFILE_CLR_DEBUGGER();
}

__nfweak void CLR_DBG_Debugger::Debugger_WaitForCommands()
{
Expand Down
1 change: 1 addition & 0 deletions src/CLR/Include/WireProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ typedef enum Monitor_Ping_Source_Flags
{
Monitor_Ping_c_Ping_Source_NanoCLR = 0x00010000,
Monitor_Ping_c_Ping_Source_NanoBooter = 0x00010001,
Monitor_Ping_c_Ping_Source_Host = 0x00010002,

Monitor_Ping_c_Ping_DbgFlag_Stop = 0x00000001,
Monitor_Ping_c_Ping_DbgFlag_AppExit = 0x00000004,
Expand Down
1 change: 1 addition & 0 deletions src/CLR/Include/nanoCLR_Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ struct CLR_DBG_Debugger

//--//

static void Debugger_Discovery();
static void Debugger_WaitForCommands();

static HRESULT CreateInstance();
Expand Down
10 changes: 3 additions & 7 deletions src/CLR/Startup/CLRStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct Settings
CLR_Debug::Printf( "Started Hardware.\r\n" );
#endif

CLR_DBG_Debugger::Debugger_Discovery();

m_fInitialized = true;

NANOCLR_NOCLEANUP();
Expand Down Expand Up @@ -111,9 +113,8 @@ struct Settings
CLR_EE_DBG_CLR(StateResolutionFailed);

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Create TS.\r\n" );
CLR_Debug::Printf( "Create Type System.\r\n" );
#endif
//NANOCLR_CHECK_HRESULT(LoadKnownAssemblies( (char*)&__deployment_start__, (char*)&__deployment_end__ ));

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Loading Deployment Assemblies.\r\n" );
Expand Down Expand Up @@ -282,10 +283,6 @@ struct Settings
// we have good Assembly
CLR_RT_Assembly* assm;

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Attaching deployed file.\r\n" );
#endif

// Creates instance of assembly, sets pointer to native functions, links to g_CLR_RT_TypeSystem
if (FAILED(LoadAssembly(header, assm)))
{
Expand Down Expand Up @@ -384,7 +381,6 @@ void ClrStartup(CLR_SETTINGS params)
CLR_Debug::Printf( "Starting...\r\n" );
#endif


HRESULT hr;

if(SUCCEEDED(hr = s_ClrSettings.Initialize(params)))
Expand Down
16 changes: 6 additions & 10 deletions targets/os/win32/nanoCLR/CLRStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ struct Settings
CLR_Debug::Printf( "Started Hardware.\r\n" );
#endif

m_fInitialized = true;
CLR_DBG_Debugger::Debugger_Discovery();

m_fInitialized = true;

NANOCLR_NOCLEANUP();
}


HRESULT LoadAssembly( const CLR_RECORD_ASSEMBLY* header, CLR_RT_Assembly*& assm )
{
NANOCLR_HEADER();
Expand All @@ -95,7 +95,7 @@ struct Settings
// First verify that check sum in assembly object matches hardcoded check sum.
if ( assm->m_header->nativeMethodsChecksum != pNativeAssmData->m_checkSum )
{
CLR_Debug::Printf("***********************************************************************\r\n");
CLR_Debug::Printf("\r\n\r\n***********************************************************************\r\n");
CLR_Debug::Printf("* *\r\n");
CLR_Debug::Printf("* ERROR!!!! Firmware version does not match managed code version!!!! *\r\n");
CLR_Debug::Printf("* *\r\n");
Expand Down Expand Up @@ -193,7 +193,7 @@ struct Settings
#else

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Create TS.\r\n" );
CLR_Debug::Printf( "Create Type System.\r\n" );
#endif

NANOCLR_CHECK_HRESULT(LoadKnownAssemblies( nanoCLR_Dat_Start, nanoCLR_Dat_End ));
Expand Down Expand Up @@ -359,10 +359,6 @@ struct Settings
// we have good Assembly
CLR_RT_Assembly* assm;

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Attaching deployed file.\r\n" );
#endif

// Creates instance of assembly, sets pointer to native functions, links to g_CLR_RT_TypeSystem
if (FAILED(LoadAssembly( header, assm ) ))
{
Expand All @@ -376,7 +372,6 @@ struct Settings
NANOCLR_NOCLEANUP();
}


HRESULT LoadDeploymentAssemblies( unsigned int memoryUsage )
{
NANOCLR_HEADER();
Expand Down Expand Up @@ -661,9 +656,10 @@ void ClrStartup( CLR_SETTINGS params )

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "\r\nnanoCLR (Build %d.%d.%d.%d)\r\n\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION );
CLR_Debug::Printf( "\r\n%s\r\n\r\n", OEMSYSTEMINFOSTRING );
#endif

CLR_RT_Memory::Reset ();
CLR_RT_Memory::Reset();

#if !defined(BUILD_RTM)
CLR_Debug::Printf( "Starting...\r\n" );
Expand Down