exec.library->AddTask() stack handling...

This forum is for general developer support questions.

exec.library->AddTask() stack handling...

Postby Belxjander » Sat Jun 09, 2018 7:17 am

What would be the specific corrections needed to deal with the SPReg, SPLower and SPUpper in the "struct Task uTask;" as part of the "struct DEVICE_UNIT_CLASS *unit;" dyamically allocated within the following code ?

I'm looking at the example on the Amiga Developer CD 2.1 and trying to adapt from 68K Assembly into C... and apparently missing something during the translation?

Would like not to use dos.library for this one

Code: Select all
   struct DEVICE_UNIT_CLASS *unit=NULL;
   struct PCIResourceRange *Range=NULL;

   if(card)
      unit=Base->IExec->AllocVecTags(DEVICE_UNIT_SIZE,AVT_Type,MEMF_SHARED,AVT_ClearWithValue,0L,TAG_DONE,TAG_DONE);
   if(unit)
   {
      KDEBUG("XHCI::InitUnit()@unit=%lx\n",unit);
      Base->Library.lib_OpenCnt++;
      unit->Attrs[0].ti_Tag=AT_Param1;
      unit->Attrs[0].ti_Data=(uint32)unit;
      unit->Attrs[1].ti_Tag=AT_Param2;
      unit->Attrs[1].ti_Data=(uint32)Base;
      unit->Attrs[1].ti_Tag=TAG_END;
      unit->Attrs[2].ti_Data=(uint32)0L;
      card->Lock(PCI_LOCK_SHARED);
      HwCardReset((APTR)Base,card);
      Range=card->GetResourceRange(0UL);
      if(Range)
      {
         KDEBUG("XHCI::InitUnit() @Range=%lx\n",Range);
         KDEBUG("XHCI::InitUnit() @Range/BaseAddress=%lx\n",Range->BaseAddress);
         KDEBUG("XHCI::InitUnit() @Range/Size=%lx\n",Range->Size);
         KDEBUG("XHCI::InitUnit() @Range/Physical=%lx\n",Range->Physical);
         KDEBUG("XHCI::InitUnit() @Range/Flags=%lx\n",Range->Flags);

         card->FreeResourceRange(Range);
      }
      unit->InterruptService.is_Data=unit;
      unit->InterruptService.is_Code=(APTR)&HwInterruptService;
      unit->uStack=Base->IExec->AllocVecTags(UNIT_STACK_SIZE,AVT_Type,MEMF_SHARED,AVT_ClearWithValue,0L,TAG_DONE,TAG_DONE);
      if(unit->uStack)
      {
         unit->uTask.tc_IDNestCnt   = -1L;
         unit->uTask.tc_TDNestCnt   = -1L;
         unit->uTask.tc_SPReg      = unit->uStack;
         unit->uTask.tc_SPLower      = unit->uStack;
         unit->uTask.tc_SPUpper      = (APTR)((uint32)UNIT_STACK_SIZE +(uint32)(unit->uStack));
         Base->IExec->NewList(&unit->uTask.tc_MemEntry);
         unit->uTask.tc_UserData=(APTR)unit;
//         Base->IExec->AddTask(&unit->uTask, &ExecUnitTask, NULL, &unit->Attrs[0]);

         if(Base->IExec->AddIntServer(card->MapInterrupt(),&unit->InterruptService))
            KDEBUG("XHCI::InitUnit() @InterruptService = Mapped && Activated\n");
      }
      card->Unlock();
   }

   return;

Belxjander
 
Posts: 275
Joined: Mon May 14, 2012 11:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan

Re: exec.library->AddTask() stack handling...

Postby thomasrapp » Sat Jun 09, 2018 8:50 am

The stack grows downwards from high to low addresses. So to start with an empty stack SPReg must point to the end of the stack, not to the beginning.
User avatar
thomasrapp
 
Posts: 250
Joined: Sun Jun 19, 2011 12:22 am

Re: exec.library->AddTask() stack handling...

Postby Belxjander » Sat Jun 09, 2018 1:53 pm

thomasrapp wrote:The stack grows downwards from high to low addresses. So to start with an empty stack SPReg must point to the end of the stack, not to the beginning.


so then ...

Code: Select all
unit->uTask.tc_SPReg      = (APTR)((uint32)UNIT_STACK_SIZE +(uint32)(unit->uStack));
unit->uTask.tc_SPLower      = unit->uStack;
unit->uTask.tc_SPUpper      = (APTR)((uint32)UNIT_STACK_SIZE +(uint32)(unit->uStack));


is more correct ?
Belxjander
 
Posts: 275
Joined: Mon May 14, 2012 11:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan

Re: exec.library->AddTask() stack handling...

Postby thomasrapp » Sat Jun 09, 2018 9:51 pm

Yes.

I would do it like this:

Code: Select all
unit->uTask.tc_SPLower    = unit->uStack;
unit->uTask.tc_SPUpper    = ((uint8 *)unit->uStack) + UNIT_STACK_SIZE;
unit->uTask.tc_SPReg      = unit->uTask.tc_SPUpper;
User avatar
thomasrapp
 
Posts: 250
Joined: Sun Jun 19, 2011 12:22 am

Re: exec.library->AddTask() stack handling...

Postby Belxjander » Sat Jun 09, 2018 11:26 pm

@ThomasRapp: Thank you for clarifying that.

Will try it and see what happens next...

It will be nice to actually have a working XHCI USB3 controller added to my setup ...

@Everyone... if anyone wants the sources I'll be publishing them in full as an example device driver,
that works against *real* PCI hardware... maybe it can be used towards encouraging more devices to be supportable with less barrier to entry for making it happen ?

I missed seeing the specific points in the example ramdev.device assembly up until now
despite actually having a physical book for quite a long time (and only have a PDF version now)

EDIT: Output in Sashimi now has this...
Code: Select all
XHCI::HwCardReset(0x5ff8c69c)
XHCI::InitUnit() @Range=5fffd920
XHCI::InitUnit() @Range/BaseAddress=a0100000
XHCI::InitUnit() @Range/Size=2000
XHCI::InitUnit() @Range/Physical=a0100000
XHCI::InitUnit() @Range/Flags=2
XHCI::InitUnit() // IExec->AddTask(&unit->uTask,...);
XHCI::InitUnit() uTask Launched!!!
XHCI::InitUnit() @InterruptService = Mapped && Activated
XHCI::ExecUnitTaskMain(5fdd9000, 0)
XHCI::CloseDevice()
XHCI::HwInterruptService(20b9230,5fdd9000)
XHCI::HwInterruptService() Happening
XHCI::HwInterruptService(20b9230,5fdd9000)
XHCI::HwInterruptService() Happening
Belxjander
 
Posts: 275
Joined: Mon May 14, 2012 11:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan

Re: exec.library->AddTask() stack handling...

Postby Belxjander » Sun Jun 10, 2018 3:34 am

Not a redeemable choice in following the example so closely...

changed from using AddTask() over to using CreateTask() [CreateTaskTags() variant] instead...

using AddTask() turns out to only be safe as long as code is hand-written assembly at that point.

otherwise *every* syscall will trigger DSI and ISI exception pairs...regardless
Belxjander
 
Posts: 275
Joined: Mon May 14, 2012 11:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan

Re: exec.library->AddTask() stack handling...

Postby thomasrapp » Sun Jun 10, 2018 1:56 pm

Belxjander wrote:otherwise *every* syscall will trigger DSI and ISI exception pairs...regardless


You have to make sure that all interface pointers are set up correctly. Don't use global variables.

Here is an example which works on OS3 as well as OS4: http://thomas-rapp.homepage.t-online.de ... s/task.lha
User avatar
thomasrapp
 
Posts: 250
Joined: Sun Jun 19, 2011 12:22 am

Re: exec.library->AddTask() stack handling...

Postby Belxjander » Sun Jun 10, 2018 7:27 pm

well... everything I was doing before reworking that section was entirely localized for variable usage.

so I am not actually sure where the globals came from at all
Belxjander
 
Posts: 275
Joined: Mon May 14, 2012 11:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 6 guests