electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » Instruments and Equipment » Chameleon
DSP Stack Push
Post new topic   Reply to topic
Page 1 of 2 [32 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Goto page: 1, 2 Next
Author Message
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 12:15 am    Post subject: DSP Stack Push
Subject description: I'm going downhill fast!
Reply with quote  Mark this post and the followings unread

Hi,

Ok I thought this one was going to be easy but it is proving otherwise!

I am writing some macros for debugging and want to save away registers I use so the caller doesn't have to worry about doing so.

Now usually I would just push the buggers onto the stack but as far as I can see the 56K doesn't seem to have push and pop functionality.

How do you go about this sort of thing on the 56K.

Cheers

Andy
Back to top
View user's profile Send private message
DrJustice



Joined: Sep 13, 2004
Posts: 2114
Location: Morokulien
Audio files: 4

PostPosted: Wed Jul 02, 2008 3:29 am    Post subject: Reply with quote  Mark this post and the followings unread

You can use a stack but you will have to set it all up yourself. It's easy though. Have a look at the 'interrupt.asm' in the dspthru example. It shows how to allocate space in memory for your stack and use common srtore load instructions to push and pop. Here's the essentials of that stack management, copied from the interrupt example:
Code:

  ;Reserve some stack space
  org L:$000000
InterruptStack:
  ds  17
  ; ... ... ...

 
my_interrupt:
  ; Set up stack pointer and start pushing registers....
  MOVE  R7,X:InterruptStack
  MOVEC M7,Y:InterruptStack
  MOVE  #InterruptStack+1,R7
  MOVEC #$FFFFFF,M7
  MOVE  X,L:(R7)+   ; InterruptStack + 00
  MOVE  Y,L:(R7)    ; InterruptStack + 01
  ; ... ... ...

  ; ... processing goes here ...

  ; ...pop registers as required....
  MOVE  L:(R7)-,Y   ; InterruptStack + 01
  MOVE  L:(R7),X    ; InterruptStack + 00
  ; ... ... ...
  MOVE  X:InterruptStack,R7
  MOVEC Y:InterruptStack,M7
  RTI


DJ

Edit: cleaned up example code
--

Last edited by DrJustice on Wed Jul 02, 2008 3:22 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 3:40 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi Are,

Thanks for the info.

The problem I have is that when I am in a macro I have no idea where to put my stack in memory as the macro has no understanding of the codes memory map that is using it.

Cheers

Andy
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 4:49 am    Post subject: Reply with quote  Mark this post and the followings unread

You could just make a global stack and have an init routine for it that's called on startup. The macro's would only have to know about what is used for the Stack Pointer then.
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 5:07 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi Jan,

Not sure I fully understand you here!

I am trying to make it so that the macro file is self contained and can be used without the calling code allocating any memory, which is why I went for the stack idea.

Cheers

Andy
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 5:23 am    Post subject: Reply with quote  Mark this post and the followings unread

Ok, I'm used to making a model that all my code is using always. I then have some init code to set up the pre condition. The macro's can (and must) then use implicit model knowledge.

Like on the 4th system I run on PICs somewhere in the first few instructions I set up two software stacks (one for parameters and one for loops/control structures) which all the stack macro's rely on. It's pretty clean that way.

The following is part of a 4th macro that defines some assembler macros to manage the model.

Code:

macro Initialization ( ) ( -- )           // Initialize code generation, contains target system initializtion code

; // macro Initialization ( ) ( -- )

False   equ  0
True    equ -1

; // ////////////////////////////////////////////////////////////////////////////
; // Forth memory layout
; //
; //   the following registers are all allocated in access RAM
; //   such that they are always accessible regardles of BSR

MaxRam  equ 0x05f                         ; // Shared memory over all banks,
                                          ; //   locate it in bank 0.
                                          ; //   using the Access bank mechanism

WTMP    equ MaxRam -  0                   ; // Temporary Wreg save for interrupts
LDP     equ MaxRam -  1                   ; // byte : Local Data Pointer,
                                          ; //        Base pointer for local variable access
EFP     equ MaxRam -  3                   ; // word : Except Frame Pointer,
                                          ; //        used for exception handling

tmp0    equ MaxRam -  4                   ; // First temporary register
tmp1    equ MaxRam -  5
tmp2    equ MaxRam -  6
tmp3    equ MaxRam -  7
tmp4    equ MaxRam -  8
tmp5    equ MaxRam -  9
tmp6    equ MaxRam - 10
tmp7    equ MaxRam - 11
tmp8    equ MaxRam - 12
tmp9    equ MaxRam - 13
tmp10   equ MaxRam - 14
tmp11   equ MaxRam - 15                   ; // Last temporary register

; // Loop stack, no real need to have it in access RAM

LZero   equ MaxRam - 16 + 1               ; // Top of Return/Loop Stack + 1
                                          ; // 80 bytes of loop stack, 20 nested DO loops's
                                          ; //   or 7 nested exception frames
                                          ; //   The loop stack grows downwards


; // Data stack, moved out of access RAM

SZero   equ 0x0ff                         ; // Top of data stack + 1, bank 1, 96 bytes stack
                                          ; //   The data stack grows upwards


// ==================================
// AsmHelpers ( ) Some helper macro's
// ==================================
//
fBranch macro aLabel
    bz      aLabel
  endm
//
// ===============================================
//
ncBranch macro aLabel
    bnc     alabel
  endm
//
// ===============================================
// // Parameter Stack macro's
// ===============================================
//
PopReg macro Reg
                                          ; // PopReg ( b -- )
    movwf   ( Reg)
    movf    postdec0, w
  endm
//
//
// ===============================================
//
Drop macro
    movf    postdec0, w                   ; // drop ( b -- )
  endm
//
//
// ===============================================
//
PushLit macro Arg
    movwf   preinc0                       ; // Push Arg ( -- b )
    movlw   ( Arg)
  endm
//
//
// ===============================================
//
PushReg macro Reg
    movwf   preinc0                       ; // Push Reg ( -- b )
    movf    ( Reg), w
  endm
//
//
// ===============================================
//
PushNothing macro
    movwf   preinc0                       ; // Push nothing, free wreg
  endm
//
//
// ===============================================
//
Dup macro
    movwf   preinc0                       ; // Dup ( b1 -- b1 b1 )
  endm
//
//
// ===============================================
//
SwapDrop macro
    decf    fsr0l, f                      ; // SwapDrop ( b1 b2 -- b2 )
  endm
//
//
// ===============================================
// // Return (loop) Stack macro's
// ===============================================
//
LsPushReg macro Reg
    decf    fsr1l                         ; // Push Reg [ -- b ] to loop stack
    movff   (Reg), indf1
  endm
//
//
// ===============================================
//
LsPushLit macro Arg
                                          ; // LsPushLit (Arg)
    PushNothing                           ; // Free wreg to be used
                                          ; // Arg into wreg
    movlw   (Arg)
    decf    fsr1l                         ; // Push Arg [ -- b ] to loop stack
    movwf   indf1
    Drop                                  ; // Restore wreg
  endm
//
//
// ===============================================
//
LsDrop macro
    incf    fsr1l                         ; // drop [ b -- ] from loop stack
  endm
//
//
// ===============================================
//
LsFree macro item_count
    PushNothing
    movlw   item_count
    addwf   fsr1l, f                      ; // drop [ n1 .. nn -- ] from loop stack
    Drop
  endm
//
//
// ===============================================
//
LsPopReg macro Reg
                                          ; // Pop Reg [ b -- ] from loop stack
    movff   postinc1, (Reg)
  endm
//
//
// ===============================================
//
AddExceptionFrame macro
                                          ; // AddExceptionFrame : link in a new exception frame
                                          ; // Push Except Frame Pointer
    LsPushReg ( EFP + 0)
    LsPushReg ( EFP + 1)

    movff     fsr1l, EFP + 0              ; // And set up a new Except Frame Pointer
    movff     fsr1h, EFP + 1
  endm
//
//
// ===============================================
//
RemoveExceptionFrame macro
                                          ; // RemoveExceptionFrame, unwind one exception level
    movff   EFP + 0, fsr1l                ; // Set loop stack back to EFP
    movff   EFP + 1, fsr1h
                                          ; // Pop back old Exception Frame Pointer
    LSPopReg  ( EFP + 1)
    LsPopReg  ( EFP + 0)
  endm
//



Edit the startup code looks like :

Code:



DoReset

    SetBSRDefault                         ; // Setup BSR
    AddressToFsr0 SZero                   ; // Setup data stack
    AddressToFsr1 LZero                   ; // Setup loop stack
    setf    rcon                          ; // Clear reset bits
                                          ; // Start executing the main word
    goto    <@" Main">

Last edited by blue hell on Wed Jul 02, 2008 5:28 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 5:27 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi Jan,

I see you use maxram and grow down, but how do you know nothing is already there?

Cheers

Andy
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 5:29 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
Hi Jan,

I see you use maxram and grow down, but how do you know nothing is already there?

Cheers

Andy


Because I did not put anything there ... Shocked

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 5:31 am    Post subject: Reply with quote  Mark this post and the followings unread

But in fact the loop stack and the data stack can grow into each other, a situation I have no checks on as those are too expensive. So I just reserve plenty of space, like 64 .. 128 bytes or something.
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 5:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Aha, maybe its a viewpoint type of thing.

I was after a totally generic macro that could be used in any system by any programmers without any knowledge of the internals of the macros.

I already have it working using memory defined in the main memory map of the code but didn't like it as it was not fully contained in the macros.

Maybe I just need a shift in my perspective! Some comments at the top of the macro file detailing memory requirements and a label needed in the memory map maybe.

I think my main problem is that I have worked for years in large C++ systems and the way my brain now works is probably based on dynamically allocated heap memory, stacks, threads etc. And where code I write can be used by anyone without any understanding of the internals of the classes.

Getting my mind back into assembler is actually a lot more difficult than I imagined, just writing a simple breakpoint handler is causing me severe headaches.

Currently I have the issue of handling breakpoints set in interrupt code where interrupts are tuned off.

My breakpoint code on the DSP sends a breakpoint id through the host interface to the coldfire processor from the DSP and then sits waiting for the coldfire to tell it to continue. This continue message is sent back via the host port when the user presses a button on the front panel of the chameleon.

When the value appears on the DSP an interrupt is fired and if it is a breakpoint continue message then the continue flag is set to signify that the DSP can continue from the breakpoint. This is done with interrupts as many different messages can come down the host port which may do different things.

Nice way of doing it I thought until you put a breakpoint in an interrupt handler that has turned interrupts off that is then it all goes pear shaped.

Piss simple in C++, just set up a thread semaphore and trigger that, don't have to worry about all this madness :)

Back to the drawing board!

Andy

P.S. Thanks for the help
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 6:09 am    Post subject: Reply with quote  Mark this post and the followings unread

The breakpoint handler should do a context save (basically all the registers used by the model and the interrupt status). This can be done on the stack, and then it should set up it's own context (with some interrupts enabled) and then you can pretty much do what you want .. but don't hit the breakpoint again Wink

You could have a look at the C startup code of your fav compiler, or write a simple DP program in C and the decompile it to see how the C environment sets up stuff, that will give you some ideas (or when you have source like crt.asm or crt.s just look at that).

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 6:26 am    Post subject: Reply with quote  Mark this post and the followings unread

So basically:

Code:

Breakpoint Macro:
  Save state including interrupts, already doing this.
  write breakpoint id to host port
  enable only interrupt for the host port.
  wait for flag to be set
  restore state


Nice one Jan, I hadn't thought about just re-instating the one interrupt. All I have to remember is not to put any breakpoints the the host port interrupt handler.

If you need any C++ help you know where to come to.

Andy
Back to top
View user's profile Send private message
DrJustice



Joined: Sep 13, 2004
Posts: 2114
Location: Morokulien
Audio files: 4

PostPosted: Wed Jul 02, 2008 6:37 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
Aha, maybe its a viewpoint type of thing.

I was after a totally generic macro that could be used in any system by any programmers without any knowledge of the internals of the macros.

I already have it working using memory defined in the main memory map of the code but didn't like it as it was not fully contained in the macros.

Maybe I just need a shift in my perspective! Some comments at the top of the macro file detailing memory requirements and a label needed in the memory map maybe.

You can have that macro, it only needs support of a macro that allocates stack space (and whatever else you need). So making a small set of macros that provides monitor/debug facilities is one way.

In my mind these things are much simpler than what a C++ compiler does. You don't need to manipulate the stack explicitly in C, but you need to know how it works to program safely and efficiently.

DJ
--
Back to top
View user's profile Send private message Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 6:58 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
So basically:

Yes!

Quote:
If you need any C++ help you know where to come to.


Thanks!

BTW I have Bjarne Stroustrup's bible "The C++ Programming Language" within reach here ... and as I hardly program any C at all these days I do need that book ...

Still not sure if I'll spend 500 bucks on a Chameleon ... it might be gone already ... Laughing

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
DrJustice



Joined: Sep 13, 2004
Posts: 2114
Location: Morokulien
Audio files: 4

PostPosted: Wed Jul 02, 2008 7:04 am    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:
Still not sure if I'll spend 500 bucks on a Chameleon ... it might be gone already ... Laughing

Aha, so you have your eye on one! Well, you're pretty much into it already... Wink

DJ
--
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 7:48 am    Post subject: Reply with quote  Mark this post and the followings unread

There is always the SoundBite board, pretty good value for $150, thats less than €100, basically a night out on the beer in the UK if you drink like me!
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 7:53 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
basically a night out on the beer in the UK if you drink like me!


I'm too old to drink like you, but still this tells me something about UK beer pricing as well ...

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 8:05 am    Post subject: Reply with quote  Mark this post and the followings unread

Actually your flash shiny Euros would do you some good here, around €2.8 for a beer in my local.

Red bull and double vodka, a personal favorite or mine would cost you €9.4, so 10 of them and you have a SoundBite rather than a very painful head.
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Wed Jul 02, 2008 8:11 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
Red bull and double vodka, a personal favorite or mine would cost you €9.4


Theft Exclamation you must be liking the wrong pub Laughing

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
seraph
Editor
Editor


Joined: Jun 21, 2003
Posts: 12398
Location: Firenze, Italy
Audio files: 33
G2 patch files: 2

PostPosted: Wed Jul 02, 2008 8:14 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:

Red bull and double vodka, a personal favorite or mine would cost you €9.4, so 10 of them and you have a SoundBite rather than a very painful head.

I wouldn't have this problem. I would fall asleep after the first one Wink

_________________
homepage - blog - forum - youtube

Quote:
Don't die with your music still in you - Wayne Dyer
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 8:15 am    Post subject: Reply with quote  Mark this post and the followings unread

For some reason Red Bull and vodka is very expensive here. A double vodka can set you back £5 and the Red Bull £2.50. Basically drinking spirits in bars in the UK is very expensive as is bottled beer.

There is a bar a few miles away that does a cheap no brand vodka and Red bull from a tap for £2.50 total but it doesn't taste the same!
Back to top
View user's profile Send private message
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 8:16 am    Post subject: Reply with quote  Mark this post and the followings unread

seraph wrote:
BobTheDog wrote:

Red bull and double vodka, a personal favorite or mine would cost you €9.4, so 10 of them and you have a SoundBite rather than a very painful head.

I wouldn't have this problem. I would fall asleep after the first one :wink:


No that Red Bull keeps you awake, a can is like a quadruple expresso.
Back to top
View user's profile Send private message
DrJustice



Joined: Sep 13, 2004
Posts: 2114
Location: Morokulien
Audio files: 4

PostPosted: Wed Jul 02, 2008 8:16 am    Post subject: Reply with quote  Mark this post and the followings unread

BobTheDog wrote:
There is always the SoundBite board, pretty good value for $150,...

Yep, good value. I have a stack of DSP dev kits, but the Chameleon is something entirely different Very Happy

BTW, I'm writing a simple monitor/debugger just as a refresher for myself. When I manage to dig up a Chami, I'll test it too.

Between us, perhaps we can make something available for others eventually? Need to search the net to see if there's something out there as well...

DJ
--
Back to top
View user's profile Send private message Visit poster's website
DrJustice



Joined: Sep 13, 2004
Posts: 2114
Location: Morokulien
Audio files: 4

PostPosted: Wed Jul 02, 2008 8:44 am    Post subject: Reply with quote  Mark this post and the followings unread

Found a project here which has the files debug.asm and debug.c to give some ideas for a fairly complete debugger. This is old Robert Bristow-Johnson code so it should be good stuff.

DJ
--
Back to top
View user's profile Send private message Visit poster's website
BobTheDog



Joined: Feb 28, 2005
Posts: 4044
Location: England
Audio files: 32
G2 patch files: 15

PostPosted: Wed Jul 02, 2008 8:49 am    Post subject: Reply with quote  Mark this post and the followings unread

That looks pretty interesting, just need to maybe change some of the console inputs to use the from panel buttons...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 2 [32 Posts]
View unread posts
View new posts in the last week
Goto page: 1, 2 Next
Mark the topic unread :: View previous topic :: View next topic
 Forum index » Instruments and Equipment » Chameleon
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use