1#!/usr/bin/env omake
2#----------------------------------------------------------------------------
3# Project: Horizon
4# File:    debuggerdefs.partner.om
5#
6# Copyright 2007-2009 Nintendo.  All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law.  They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14# $Date:: 2010-09-15#$
15# $Rev: 25871 $
16# $Author: yoneyama_takashi $
17#----------------------------------------------------------------------------
18
19PYTHON = python
20RUBY   = ruby
21PARTNER_PARTNER = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)partner_partner.rb)
22private.RUNNER_CORE_0_2   = $(file $(ROOT_BUILD)/runner/run-core_0_2.py)
23LOADRUN = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)ctr_loadrunf32.exe)
24LOADRUN_SPI = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)ctr_loadrun32.exe)
25
26public.PartnerMCR(axf, process) =
27    export depend_files
28    depend_files =
29    if $(not $(SKIP_BUILD))
30        depend_files += $(axf) $(process)
31
32    export basefile
33    export axf_symbol
34    if $(not $(equal $(process), $(EMPTY)))
35        basefile = $(process)
36        axf_symbol = $(removesuffix $(process)).axf
37    else
38        basefile = $(axf)
39
40    mcr     = $(addsuffix .mcr,$(removesuffix $(basefile)))
41    log     = $(removesuffix $(absname $(basefile))).log
42    basedir = $(dirname $(absname $(basefile)))
43
44    $(mcr): $(dirname $(mcr)) $(ROOT_OMAKE)/debuggerdefs.partner.om $(depend_files)
45        section
46            f = $(fopen $(@), w)
47            fprintln($(f),ESC)
48            fprintln($(f),INITA)
49            fprintln($(f),CORE 0)
50            fprintln($(f),L "$(absname $(axf))")
51            if $(axf_symbol)
52                fprintln($(f),LSA "$(absname $(axf_symbol))")
53
54            fprintln($(f),CD "$(basedir)")
55            if $(not $(equal $(log),$(EMPTY)))
56                fprintln($(f),$">" "$(absname $(log))")
57            fprintln($(f),G)
58            close($(f))
59
60    if $(and $(defined TEST_ENVIRONMENT_PROCESSLIST), $(TEST_ENVIRONMENT_PROCESSLIST))
61        $(log): $(mcr) $(depend_files) $(RUNNER) :effects: $(RUNNER_LOCK)
62            bash $(RUNNER) $(mcr)
63
64    return $(mcr)
65
66private.IsEmpty(seq) =
67    return $(eq 0, $(length $(seq)))
68
69public.FilterTestAttributes(process) =
70
71    if $(not $(defined TEST_ATTRIBUTES))
72        TEST_ATTRIBUTES =
73        export
74
75    if $(not $(defined TEST_INCLUDE))
76        TEST_INCLUDE = BASIC
77        export
78    else
79        TEST_INCLUDE = $(split  $",",$(TEST_INCLUDE))
80        export
81
82    if $(not $(defined TEST_EXCLUDE))
83        TEST_EXCLUDE =
84        export
85    else
86        TEST_EXCLUDE = $(split  $",",$(TEST_EXCLUDE))
87        export
88
89    attributes = $(ParseDependProcess null, $(rootname $(process)), $(TEST_ATTRIBUTES))
90
91    if $(IsEmpty $(attributes))
92        attributes = BASIC
93        export
94
95    has_includes = $(filter $(TEST_INCLUDE), $(attributes))
96    has_excludes = $(filter $(TEST_EXCLUDE), $(attributes))
97
98    if $(and $(IsEmpty $(has_excludes)), $(not $(IsEmpty $(has_includes))))
99        return $(process)
100
101    return
102
103public.FilterTest(sources) =
104
105    filtered_sources = $(sources)
106
107    if $(defined TEST_FILTER)
108        regex = $(compileToRegex $(TEST_FILTER))
109
110        filtered_sources =
111
112        foreach( source, $(sources) )
113            if $(isFilterMatch $(regex), $(rootname $(basename $(source))))
114                filtered_sources += $(source)
115                export filtered_sources
116            export filtered_sources
117        export filtered_sources
118
119    return $(filtered_sources)
120
121private.RunProgramBeforeTest(options, logfile) =
122    if $(defined BEFORE_TEST)
123        BEFORE_TEST.run($(options), logfile)
124
125private.RunProgramAfterTest(options, logfile) =
126    if $(defined AFTER_TEST)
127        AFTER_TEST.run($(options), logfile)
128
129private.ParseDependProcesses(process, processlist) =
130    processes =
131    basedir = $(dirname $(absname $(process)))
132
133    foreach(proc, $(DEPEND_PROCESSES))
134        if $(not $(proc))
135            continue
136
137        if $(findstring $(proc),$"^@")
138            processes += $(removeprefix $"@", $(proc))
139            export
140
141        elseif $(findstring $(proc),$"^\.")
142            processes += $(absname $(proc))
143            export
144
145        else
146            tmp_image_dir = $(dirname $(proc))
147            tmp_image_dir = $(absname $(addprefix $(basedir)$(DIRSEP)..$(DIRSEP)..$(DIRSEP),$(tmp_image_dir)))
148            tmp_image     = $(addsuffix $(EXT_CDI),$(basename $(proc)))
149            tmp_image     = $(addprefix $(config.getTargetSubDirectory false)$(DIRSEP),$(tmp_image))
150            processes += $(addprefix $(tmp_image_dir)$(DIRSEP),$(tmp_image))
151            export
152        export
153
154    return $(processes)
155
156public.GetLoadrunOptions() =
157    options =
158
159    if $(and $(not $(defined RUN_TIMEOUT)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS)))))
160        RUN_TIMEOUT = 60
161        export RUN_TIMEOUT
162
163    if $(and $(not $(defined EXIT_PATTERN)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS)))))
164        EXIT_PATTERN="CU_TEST_EXIT|KernelPanic|nn::svc::Break\\("
165        export EXIT_PATTERN
166
167    if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT))
168        options += --no-wait
169        export options
170
171    if $(defined EXIT_PATTERN)
172        options += --exit-pattern $(EXIT_PATTERN)
173        export options
174
175    if $(defined RUN_TIMEOUT)
176        options += --timeout $(RUN_TIMEOUT)
177        export options
178
179    return $(options)
180
181public.GetLoadrunOptionsForTool() =
182    options =
183
184    if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT))
185        options += --no-wait
186        export options
187
188    return $(options)
189
190public.FilesToRunProcessList(config, process) =
191    process = $(filter %.cdi,$(process))
192    if $(eq 0,$(length $(process)))
193        return
194    process = $(nth 0,$(process))
195
196    export depend_files
197    depend_files =
198
199    export processes
200    processes =
201
202    kernel = $(config.getSuitableKernelFilename)
203    kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.)
204    kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.)
205
206    if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9)))
207        kernel_core2 = $(gsub $(kernel_core2),Development,Release)
208        kernel_core2 = $(gsub $(kernel_core2),Debug,Release)
209        export
210
211    log     = $(addsuffix .proclist.log,$(removesuffix $(process)))
212    setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process)))
213    teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process)))
214    basedir = $(dirname $(absname $(process)))
215
216    if $(defined DEPEND_PROCESSES)
217        DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES))
218        processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES))
219        export
220    processes += $(absname $(process))
221
222    if $(not $(SKIP_BUILD))
223        depend_files += $(kernel_core0) $(kernel_core2)
224        depend_files += $(processes)
225
226    processes = $(addprefix @,$(processes))
227
228    process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list
229
230    tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool)
231
232    if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN)))
233        if $(and $(defined TEST_ENVIRONMENT_PROCESSLIST), $(TEST_ENVIRONMENT_PROCESSLIST))
234            $(log): $(LOADRUN) $(depend_files) :effects: $(LOADRUN)
235                if $(and $(defined LOGLIST), $(LOGLIST))
236                    echo $(log) >> $(LOGLIST)
237                if $(defined RUN_HOSTPROGRAM)
238                    RUN_HOSTPROGRAM.run()
239                RunProgramBeforeTest($(tooloptions), $(setuplog))
240                section
241                    f = $(fopen $(process_list), w)
242                    foreach(filename, $(processes))
243                        fprintln($(f), $(filename))
244                    close($(f))
245
246                $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log))
247                RunProgramAfterTest($(tooloptions), $(teardownlog))
248            depend_files += $(log)
249
250        if $(filter run-proclist, $(TARGETS))
251            $(log): $(LOADRUN) $(depend_files) :effects: $(LOADRUN)
252                section
253                    f = $(fopen $(process_list), w)
254                    foreach(filename, $(processes))
255                        fprintln($(f), $(filename))
256                    close($(f))
257                $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log))
258            depend_files += $(log)
259            export
260        export
261    return $(depend_files)
262
263public.FilesToRunEmulationMemory(config, process) =
264
265    process = $(filter %.cci %.csu,$(process))
266    if $(eq 0,$(length $(process)))
267        return
268    process = $(nth 0,$(process))
269
270    kernel = $(config.getSuitableKernelFilename)
271    kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.)
272    kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.)
273
274    if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9)))
275        kernel_core2 = $(gsub $(kernel_core2),Development,Release)
276        kernel_core2 = $(gsub $(kernel_core2),Debug,Release)
277        export
278
279    export processes
280    processes =
281
282    export options
283    options =
284
285    export depend_files
286    depend_files =
287
288    if $(defined DEPEND_PROCESSES)
289        DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES))
290        processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES))
291        export
292
293    if $(not $(SKIP_BUILD))
294        depend_files += $(process) $(kernel_core0) $(kernel_core2)
295        depend_files += $(processes)
296
297    foreach(proc, $(processes))
298        options += -rp $(proc)
299
300    log     = $(addsuffix .emumem.log,$(removesuffix $(process)))
301    setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process)))
302    teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process)))
303    basedir = $(dirname $(absname $(process)))
304
305    process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list
306
307    tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool)
308
309    if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN)))
310        if $(or $(and $(defined TEST_ENVIRONMENT_EMUMEM), $(TEST_ENVIRONMENT_EMUMEM))\
311                $(and $(defined TEST_ENVIRONMENT_IMPORT), $(TEST_ENVIRONMENT_IMPORT)))
312            $(log): $(LOADRUN) $(depend_files) :effects: $(LOADRUN)
313                if $(and $(defined LOGLIST), $(LOGLIST))
314                    echo $(log) >> $(LOGLIST)
315                if $(defined RUN_HOSTPROGRAM)
316                    RUN_HOSTPROGRAM.run()
317                RunProgramBeforeTest($(tooloptions), $(setuplog))
318                $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) -re $(process) $(GetLoadrunOptions) | tee $(absname $(log))
319                RunProgramAfterTest($(tooloptions), $(teardownlog))
320            depend_files += $(log)
321            export
322        export
323
324        if $(filter run-emumem, $(TARGETS))
325            $(log): $(LOADRUN) $(depend_files) :effects: $(LOADRUN)
326                 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) -re $(process) $(GetLoadrunOptions) | tee $(absname $(log))
327            depend_files += $(log)
328            export
329        export
330
331    return $(depend_files)
332
333public.FilesToRunSPI(config, process) =
334    process = $(filter %.cci,$(process))
335    if $(eq 0,$(length $(process)))
336        return
337    process = $(nth 0,$(process))
338
339    export depend_files
340    depend_files =
341    if $(not $(SKIP_BUILD))
342        depend_files += $(process)
343
344    log     = $(addsuffix .spi.log,$(removesuffix $(process)))
345
346    commands = -c esc -c reset
347    commands += -c "RDC \"$(process)\",0"
348    commands += -c NEWP
349
350    if $(and $(defined TEST_ENVIRONMENT_SPI), $(TEST_ENVIRONMENT_SPI))
351        $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI)
352            $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log))
353        depend_files += $(log)
354
355    if $(filter run-spi, $(TARGETS))
356        $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI)
357            $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log))
358        depend_files += $(log)
359
360    return $(depend_files)
361
362public.UserRunProcess(config, name, files) =
363    TARGET_FILE = $(UserProcess $(config), $(name), $(files))
364    LIST_PREFIX = $(removesuffix $(basename $(TARGET_FILE)))
365    CCIFile = $(replacesuffixes $(EXT_ELF), $(EXT_CCI), $(TARGET_FILE))
366    CIPFile = $(replacesuffixes $(EXT_ELF), $(EXT_CIP), $(TARGET_FILE))
367
368    RUN_PROCLIST_FILES  = $(FilesToRunProcessList $(config),$(absname $(TARGET_FILE)))
369    RUN_EMUMEM_FILES    = $(FilesToRunEmulationMemory $(config),$(absname $(TARGET_FILE)))
370    RUN_SPI_FILES       = $(FilesToRunSPI $(config),$(absname $(TARGET_FILE)))
371
372    run-proclist:   $(RUN_PROCLIST_FILES)
373    run-scripts:    $(RUN_PROCLIST_FILES)
374    run-emumem:     $(RUN_EMUMEM_FILES)
375    run-spi:        $(RUN_SPI_FILES)
376
377    return $(TARGET_FILE)
378