ApplicationReportSPRA820–May20031OnlineStackOverflowDetectionontheTMS320C28xDSPDavidM.AlterDSPApplications–SemiconductorGroupABSTRACTAstackoverflowinanembeddedDSPapplicationgenerallyproducesacatastrophicsoftwarecrashduetodatacorruption,lostreturnaddresses,orboth.Traditionaloff-lineapproachestosizingastackduringdevelopment,suchasfillingwithaknowvalue,orestimatingbasedoncodecontent,arenot100%reliable.Therefore,programmersoftenfeelcompelledtoreservelargerstacksizesthanareactuallyneeded.Thiswastesvaluablememoryresources.FacilitiesexistontheTMS320C28x™DSPthat,whenproperlyconfigured,allowforruntimedetectionofastackoverflowbeforeitoccurs.Detectionofanimpendingstackoverflowtriggersamaskableinterrupt,andsoftwarecanthentakewhatevercorrectiveactionisdesiredbeforeasoftwarecrashoccurs.ThisapplicationreportpresentsthemethodologyforonlinestackoverflowdetectionontheTMS320C28xDSP.C-sourcecodeisprovidedthatcontainsfunctionsforimplementingtheoverflowdetectiononbothDSP/BIOS™andnon-DSP/BIOSapplications.TMS320C28xandDSP/BIOSaretrademarksofTexasInstruments.Trademarksarethepropertyoftheirrespectiveowners.SPRA8202OnlineStackOverflowDetectionontheTMS320C28xDSPContents1Introduction..................................................................................................................................32TheC28xEmulationAnalysisBlock...........................................................................................42.1AnalysisBlockWatchpointRegisters......................................................................................52.2WatchpointRegisterConfigurationProcedure........................................................................83ConfiguringaWatchpointforStackOverflowDetection..........................................................93.1DeterminingtheWatchpointLocationandRangeinMemory.................................................93.2WatchpointRegistersValues................................................................................................