RTX: Main thread should not write MAGIC_WORD to stack
RTX: Main thread should not write MAGIC_WORD to stack

This is a fix for issue #285.  This fix is similar to that proposed by
@oresths in the original issue.

There is code in rt_init_stack() which compares the task_id against the
value of 1 before writing MAGIC_WORD to the bottom of the stack.  This
is supposed to stop the write from occurring for the main thread but
svcThreadCreate() doesn't initialize the P_TCB's task_id field until
after rt_init_stack() is executed.  If any dynamic memory allocation
has occurred before the main thread is started (from the standard C
startup code) then this write could overwrite data in that allocation.

This change:
* moves the task_id initialization in svcThreadCreate() to happen
  before the call to rt_init_context() is made.
* cleans up some comments in svcThreadCreate() which appear to
  reference older versions of the code which would automatically
  allocate stack memory if size == 0.
* still keeps the call to rt_dispatch() occurring after the call to
  rt_init_context() so that the task is not dispatched to the
  scheduler until the task fields have been populated.

I stepped through the rt_init_stack() code on my mbedLPC1768 after this
change was made to make sure that the write of MAGIC_WORD is now
skipped.
-----------------------------------------------------------------------
(gdb) break HAL_CM.c:95
Breakpoint 1 at 0x482c: file ../../external/mbed/libraries/rtos/rtx/TARGET_CORTEX_M/HAL_CM.c, line 95.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, rt_init_stack (p_TCB=0x10000774 <os_idle_TCB>, task_body=0x4899 <os_idle_demon>)
    at ../../external/mbed/libraries/rtos/rtx/TARGET_CORTEX_M/HAL_CM.c:95
95	  if (p_TCB->task_id != 0x01)
(gdb) p *p_TCB
$1 = {
  cb_type = 0 '\000',
  state = 1 '\001',
  prio = 0 '\000',
  task_id = 255 '\377',
  p_lnk = 0x0 <_reclaim_reent>,
  p_rlnk = 0x0 <_reclaim_reent>,
  p_dlnk = 0x0 <_reclaim_reent>,
  p_blnk = 0x0 <_reclaim_reent>,
  delta_time = 0,
  interval_time = 0,
  events = 0,
  waits = 0,
  msg = 0x0 <_reclaim_reent>,
  stack_frame = 0 '\000',
  reserved = 0 '\000',
  priv_stack = 128,
  tsk_stack = 268437480,
  stack = 0x100007a8 <idle_task_stack>,
  ptask = 0x4899 <os_idle_demon>
}
(gdb) c
Continuing.

Breakpoint 1, rt_init_stack (p_TCB=0x10000120 <os_thread_def_main+16>, task_body=0x620d <__wrap_main()>)
    at ../../external/mbed/libraries/rtos/rtx/TARGET_CORTEX_M/HAL_CM.c:95
95	  if (p_TCB->task_id != 0x01)
(gdb) p *p_TCB
$2 = {
  cb_type = 0 '\000',
  state = 1 '\001',
  prio = 4 '\004',
  task_id = 1 '\001',
  p_lnk = 0x0 <_reclaim_reent>,
  p_rlnk = 0x0 <_reclaim_reent>,
  p_dlnk = 0x0 <_reclaim_reent>,
  p_blnk = 0x0 <_reclaim_reent>,
  delta_time = 0,
  interval_time = 0,
  events = 0,
  waits = 0,
  msg = 0x0 <_reclaim_reent>,
  stack_frame = 0 '\000',
  reserved = 0 '\000',
  priv_stack = 26968,
  tsk_stack = 268467136,
  stack = 0x100012a8,
  ptask = 0x620d <__wrap_main()>
}
(gdb) n
97	}

When the p_TCB for ptask==__wrap_main() is encountered, the task_id
now has a value of 1 and the write of MAGIC_WORD on line 96 is
skipped.

arostm/mbed-os,nabilbendafi/mbed,HeadsUpDisplayInc/mbed,ryankurte/mbed-os,Marcomissyou/mbed,Timmmm/mbed,betzw/mbed-os,naves-thiago/mbed-midi,Tiryoh/mbed,Shengliang/mbed,masaohamanaka/mbed,sam-geek/mbed,Shengliang/mbed,tung7970/mbed-os,andreaslarssonublox/mbed,getopenmono/mbed,K4zuki/mbed,NitinBhaskar/mbed,nRFMesh/mbed-os,struempelix/mbed,HeadsUpDisplayInc/mbed,Willem23/mbed,kpurusho/mbed,jpbrucker/mbed,jamesadevine/mbed,wodji/mbed,mnlipp/mbed,xcrespo/mbed,NXPmicro/mbed,radhika-raghavendran/mbed-os5.1-onsemi,DanKupiniak/mbed,K4zuki/mbed,hwfwgrp/mbed,YarivCol/mbed-os,fpiot/mbed-ats,JasonHow44/mbed,CalSol/mbed,Shengliang/mbed,sam-geek/mbed,bulislaw/mbed-os,jferreir/mbed,pradeep-gr/mbed-os5-onsemi,naves-thiago/mbed-midi,pi19404/mbed,autopulated/mbed,GustavWi/mbed,betzw/mbed-os,bentwire/mbed,Marcomissyou/mbed,nRFMesh/mbed-os,ban4jp/mbed,fvincenzo/mbed-os,jeremybrodt/mbed,fvincenzo/mbed-os,monkiineko/mbed-os,GustavWi/mbed,pbrook/mbed,HeadsUpDisplayInc/mbed,c1728p9/mbed-os,CalSol/mbed,mazimkhan/mbed-os,tung7970/mbed-os-1,RonEld/mbed,kl-cruz/mbed-os,adamgreen/mbed,jamesadevine/mbed,fanghuaqi/mbed,RonEld/mbed,ryankurte/mbed-os,geky/mbed,CalSol/mbed,c1728p9/mbed-os,mnlipp/mbed,maximmbed/mbed,andreaslarssonublox/mbed,tung7970/mbed-os,catiedev/mbed-os,logost/mbed,jpbrucker/mbed,fpiot/mbed-ats,Willem23/mbed,karsev/mbed-os,pedromes/mbed,infinnovation/mbed-os,ban4jp/mbed,betzw/mbed-os,screamerbg/mbed,cvtsi2sd/mbed-os,jrjang/mbed,jrjang/mbed,Willem23/mbed,monkiineko/mbed-os,andcor02/mbed-os,sam-geek/mbed,brstew/MBED-BUILD,karsev/mbed-os,ryankurte/mbed-os,alertby/mbed,adustm/mbed,adamgreen/mbed,EmuxEvans/mbed,infinnovation/mbed-os,Sweet-Peas/mbed,screamerbg/mbed,jferreir/mbed,DanKupiniak/mbed,svastm/mbed,jferreir/mbed,svogl/mbed-os,dbestm/mbed,pi19404/mbed,c1728p9/mbed-os,geky/mbed,arostm/mbed-os,EmuxEvans/mbed,theotherjimmy/mbed,jferreir/mbed,karsev/mbed-os,cvtsi2sd/mbed-os,arostm/mbed-os,bcostm/mbed-os,bikeNomad/mbed,devanlai/mbed,mikaleppanen/mbed-os,fpiot/mbed-ats,pi19404/mbed,brstew/MBED-BUILD,ban4jp/mbed,radhika-raghavendran/mbed-os5.1-onsemi,dbestm/mbed,pi19404/mbed,adustm/mbed,svastm/mbed,nvlsianpu/mbed,nabilbendafi/mbed,jrjang/mbed,masaohamanaka/mbed,infinnovation/mbed-os,mmorenobarm/mbed-os,catiedev/mbed-os,netzimme/mbed-os,mbedmicro/mbed,adustm/mbed,Marcomissyou/mbed,NXPmicro/mbed,wodji/mbed,rgrover/mbed,pbrook/mbed,pradeep-gr/mbed-os5-onsemi,hwfwgrp/mbed,svastm/mbed,kl-cruz/mbed-os,EmuxEvans/mbed,JasonHow44/mbed,svastm/mbed,JasonHow44/mbed,mazimkhan/mbed-os,andcor02/mbed-os,ryankurte/mbed-os,xcrespo/mbed,mmorenobarm/mbed-os,nRFMesh/mbed-os,jpbrucker/mbed,logost/mbed,mikaleppanen/mbed-os,ARM-software/mbed-beetle,devanlai/mbed,RonEld/mbed,Shengliang/mbed,theotherjimmy/mbed,adamgreen/mbed,Willem23/mbed,mbedmicro/mbed,mazimkhan/mbed-os,alertby/mbed,nvlsianpu/mbed,bulislaw/mbed-os,catiedev/mbed-os,mmorenobarm/mbed-os,mnlipp/mbed,FranklyDev/mbed,masaohamanaka/mbed,andcor02/mbed-os,Tiryoh/mbed,dbestm/mbed,netzimme/mbed-os,karsev/mbed-os,K4zuki/mbed,netzimme/mbed-os,rosterloh/mbed,mmorenobarm/mbed-os,theotherjimmy/mbed,fpiot/mbed-ats,bulislaw/mbed-os,DanKupiniak/mbed,jeremybrodt/mbed,bulislaw/mbed-os,autopulated/mbed,arostm/mbed-os,HeadsUpDisplayInc/mbed,adamgreen/mbed,adustm/mbed,jamesadevine/mbed,wodji/mbed,geky/mbed,Sweet-Peas/mbed,rosterloh/mbed,netzimme/mbed-os,maximmbed/mbed,bcostm/mbed-os,Timmmm/mbed,bentwire/mbed,struempelix/mbed,masaohamanaka/mbed,YarivCol/mbed-os,pedromes/mbed,autopulated/mbed,jrjang/mbed,devanlai/mbed,nabilbendafi/mbed,catiedev/mbed-os,wodji/mbed,adamgreen/mbed,monkiineko/mbed-os,fahhem/mbed-os,FranklyDev/mbed,RonEld/mbed,mmorenobarm/mbed-os,tung7970/mbed-os-1,getopenmono/mbed,dbestm/mbed,ban4jp/mbed,j-greffe/mbed-os,kl-cruz/mbed-os,bcostm/mbed-os,maximmbed/mbed,Archcady/mbed-os,nabilbendafi/mbed,nabilbendafi/mbed,fvincenzo/mbed-os,svogl/mbed-os,K4zuki/mbed,kpurusho/mbed,larks/mbed,mikaleppanen/mbed-os,fanghuaqi/mbed,mbedmicro/mbed,cvtsi2sd/mbed-os,kpurusho/mbed,mikaleppanen/mbed-os,tung7970/mbed-os,andcor02/mbed-os,al177/mbed,kpurusho/mbed,Archcady/mbed-os,brstew/MBED-BUILD,K4zuki/mbed,EmuxEvans/mbed,geky/mbed,kjbracey-arm/mbed,betzw/mbed-os,xcrespo/mbed,larks/mbed,arostm/mbed-os,brstew/MBED-BUILD,JasonHow44/mbed,Shengliang/mbed,wodji/mbed,Marcomissyou/mbed,fahhem/mbed-os,maximmbed/mbed,Willem23/mbed,CalSol/mbed,Shengliang/mbed,theotherjimmy/mbed,screamerbg/mbed,jpbrucker/mbed,struempelix/mbed,Archcady/mbed-os,alertby/mbed,devanlai/mbed,rosterloh/mbed,theotherjimmy/mbed,kpurusho/mbed,xcrespo/mbed,tung7970/mbed-os,infinnovation/mbed-os,jeremybrodt/mbed,RonEld/mbed,jpbrucker/mbed,rgrover/mbed,CalSol/mbed,karsev/mbed-os,alertby/mbed,Sweet-Peas/mbed,struempelix/mbed,jferreir/mbed,getopenmono/mbed,RonEld/mbed,ryankurte/mbed-os,NitinBhaskar/mbed,svogl/mbed-os,logost/mbed,jeremybrodt/mbed,jamesadevine/mbed,mnlipp/mbed,autopulated/mbed,bikeNomad/mbed,Sweet-Peas/mbed,svogl/mbed-os,sam-geek/mbed,Tiryoh/mbed,maximmbed/mbed,naves-thiago/mbed-midi,radhika-raghavendran/mbed-os5.1-onsemi,GustavWi/mbed,rgrover/mbed,nvlsianpu/mbed,YarivCol/mbed-os,rosterloh/mbed,al177/mbed,betzw/mbed-os,andreaslarssonublox/mbed,FranklyDev/mbed,bikeNomad/mbed,Archcady/mbed-os,dbestm/mbed,pedromes/mbed,pi19404/mbed,rgrover/mbed,Archcady/mbed-os,bikeNomad/mbed,Marcomissyou/mbed,kl-cruz/mbed-os,pradeep-gr/mbed-os5-onsemi,brstew/MBED-BUILD,jamesadevine/mbed,NitinBhaskar/mbed,andreaslarssonublox/mbed,mmorenobarm/mbed-os,mazimkhan/mbed-os,masaohamanaka/mbed,pbrook/mbed,pradeep-gr/mbed-os5-onsemi,netzimme/mbed-os,Sweet-Peas/mbed,struempelix/mbed,Archcady/mbed-os,fanghuaqi/mbed,kjbracey-arm/mbed,mbedmicro/mbed,devanlai/mbed,monkiineko/mbed-os,logost/mbed,andreaslarssonublox/mbed,mazimkhan/mbed-os,Marcomissyou/mbed,Tiryoh/mbed,alertby/mbed,fpiot/mbed-ats,j-greffe/mbed-os,fvincenzo/mbed-os,pbrook/mbed,catiedev/mbed-os,NitinBhaskar/mbed,NXPmicro/mbed,sam-geek/mbed,CalSol/mbed,adustm/mbed,xcrespo/mbed,hwfwgrp/mbed,andcor02/mbed-os,EmuxEvans/mbed,getopenmono/mbed,ARM-software/mbed-beetle,nvlsianpu/mbed,netzimme/mbed-os,NXPmicro/mbed,cvtsi2sd/mbed-os,brstew/MBED-BUILD,al177/mbed,larks/mbed,fahhem/mbed-os,kjbracey-arm/mbed,masaohamanaka/mbed,JasonHow44/mbed,larks/mbed,fanghuaqi/mbed,naves-thiago/mbed-midi,pedromes/mbed,autopulated/mbed,mazimkhan/mbed-os,jeremybrodt/mbed,c1728p9/mbed-os,pbrook/mbed,j-greffe/mbed-os,getopenmono/mbed,screamerbg/mbed,rosterloh/mbed,struempelix/mbed,bulislaw/mbed-os,maximmbed/mbed,hwfwgrp/mbed,NXPmicro/mbed,rosterloh/mbed,alertby/mbed,bentwire/mbed,mnlipp/mbed,ban4jp/mbed,tung7970/mbed-os-1,nRFMesh/mbed-os,tung7970/mbed-os-1,Sweet-Peas/mbed,ban4jp/mbed,karsev/mbed-os,j-greffe/mbed-os,DanKupiniak/mbed,bentwire/mbed,larks/mbed,al177/mbed,HeadsUpDisplayInc/mbed,mikaleppanen/mbed-os,jrjang/mbed,al177/mbed,j-greffe/mbed-os,screamerbg/mbed,Timmmm/mbed,autopulated/mbed,c1728p9/mbed-os,tung7970/mbed-os,devanlai/mbed,dbestm/mbed,andcor02/mbed-os,ARM-software/mbed-beetle,fpiot/mbed-ats,bulislaw/mbed-os,Timmmm/mbed,fahhem/mbed-os,pbrook/mbed,hwfwgrp/mbed,screamerbg/mbed,arostm/mbed-os,GustavWi/mbed,nvlsianpu/mbed,Timmmm/mbed,K4zuki/mbed,svastm/mbed,jrjang/mbed,getopenmono/mbed,radhika-raghavendran/mbed-os5.1-onsemi,YarivCol/mbed-os,monkiineko/mbed-os,ARM-software/mbed-beetle,pi19404/mbed,pradeep-gr/mbed-os5-onsemi,radhika-raghavendran/mbed-os5.1-onsemi,kpurusho/mbed,naves-thiago/mbed-midi,svogl/mbed-os,cvtsi2sd/mbed-os,HeadsUpDisplayInc/mbed,adustm/mbed,nRFMesh/mbed-os,mnlipp/mbed,fvincenzo/mbed-os,nabilbendafi/mbed,c1728p9/mbed-os,larks/mbed,xcrespo/mbed,mbedmicro/mbed,infinnovation/mbed-os,tung7970/mbed-os-1,mikaleppanen/mbed-os,j-greffe/mbed-os,EmuxEvans/mbed,infinnovation/mbed-os,pradeep-gr/mbed-os5-onsemi,al177/mbed,YarivCol/mbed-os,FranklyDev/mbed,YarivCol/mbed-os,jpbrucker/mbed,fanghuaqi/mbed,fahhem/mbed-os,monkiineko/mbed-os,cvtsi2sd/mbed-os,kjbracey-arm/mbed,ryankurte/mbed-os,NitinBhaskar/mbed,geky/mbed,bcostm/mbed-os,bentwire/mbed,FranklyDev/mbed,betzw/mbed-os,Timmmm/mbed,pedromes/mbed,catiedev/mbed-os,svogl/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,kl-cruz/mbed-os,Tiryoh/mbed,adamgreen/mbed,kl-cruz/mbed-os,nvlsianpu/mbed,jamesadevine/mbed,bcostm/mbed-os,fahhem/mbed-os,jferreir/mbed,JasonHow44/mbed,wodji/mbed,bcostm/mbed-os,GustavWi/mbed,pedromes/mbed,bikeNomad/mbed,NXPmicro/mbed,theotherjimmy/mbed,logost/mbed,nRFMesh/mbed-os,logost/mbed,Tiryoh/mbed,rgrover/mbed,naves-thiago/mbed-midi,hwfwgrp/mbed,bentwire/mbed