1 |
198 |
zero_gravi |
; #################################################################################################
|
2 |
|
|
; # < crt0.asm - general neo430 application start-up code > #
|
3 |
|
|
; # ********************************************************************************************* #
|
4 |
|
|
; # BSD 3-Clause License #
|
5 |
|
|
; # #
|
6 |
|
|
; # Copyright (c) 2020, Stephan Nolting. All rights reserved. #
|
7 |
|
|
; # #
|
8 |
|
|
; # Redistribution and use in source and binary forms, with or without modification, are #
|
9 |
|
|
; # permitted provided that the following conditions are met: #
|
10 |
|
|
; # #
|
11 |
|
|
; # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
12 |
|
|
; # conditions and the following disclaimer. #
|
13 |
|
|
; # #
|
14 |
|
|
; # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
15 |
|
|
; # conditions and the following disclaimer in the documentation and/or other materials #
|
16 |
|
|
; # provided with the distribution. #
|
17 |
|
|
; # #
|
18 |
|
|
; # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
19 |
|
|
; # endorse or promote products derived from this software without specific prior written #
|
20 |
|
|
; # permission. #
|
21 |
|
|
; # #
|
22 |
|
|
; # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
23 |
|
|
; # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
24 |
|
|
; # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
25 |
|
|
; # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
26 |
|
|
; # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
27 |
|
|
; # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
28 |
|
|
; # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
29 |
|
|
; # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
30 |
|
|
; # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
31 |
|
|
; # ********************************************************************************************* #
|
32 |
|
|
; # The NEO430 Processor - https://github.com/stnolting/neo430 #
|
33 |
|
|
; #################################################################################################
|
34 |
|
|
|
35 |
|
|
.file "crt0.asm"
|
36 |
|
|
.section .text
|
37 |
|
|
.p2align 1,0
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
__crt0_begin:
|
41 |
|
|
; -----------------------------------------------------------
|
42 |
|
|
; Get required system info
|
43 |
|
|
; -----------------------------------------------------------
|
44 |
|
|
mov #0xC000, r8 ; = DMEM (RAM) base address
|
45 |
|
|
mov &0xFFFA, r1 ; = DMEM (RAM) size in byte
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
; -----------------------------------------------------------
|
49 |
|
|
; Minimal required hardware setup
|
50 |
|
|
; -----------------------------------------------------------
|
51 |
|
|
mov #0, r2 ; clear status register & disable interrupts
|
52 |
|
|
add r8, r1 ; r1 = stack pointer = end of RAM
|
53 |
|
|
sub #2, r1 ; address of last entry of stack
|
54 |
|
|
mov #0x4700, &0xFFB8 ; deactivate watchdog
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
; -----------------------------------------------------------
|
58 |
|
|
; Initialize all IO device registers (set to zero)
|
59 |
|
|
; -----------------------------------------------------------
|
60 |
|
|
; This loop does not trigger any operations as the CTRL registers, which are located
|
61 |
|
|
; at offset 0 of the according device, are set to zero resulting in disabling the
|
62 |
|
|
; specific device.
|
63 |
|
|
mov #0xFF80, r9 ; beginning of IO section
|
64 |
|
|
__crt0_clr_io:
|
65 |
|
|
tst r9 ; until the end -> wrap-around to 0
|
66 |
|
|
jeq __crt0_clr_io_end
|
67 |
|
|
mov #0, 0(r9) ; clear entry
|
68 |
|
|
incd r9
|
69 |
|
|
jmp __crt0_clr_io
|
70 |
|
|
__crt0_clr_io_end:
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
; -----------------------------------------------------------
|
74 |
|
|
; Clear complete DMEM (including .bss section)
|
75 |
|
|
; -----------------------------------------------------------
|
76 |
|
|
__crt0_clr_dmem:
|
77 |
|
|
cmp r8, r1 ; base address equal to end of RAM?
|
78 |
|
|
jeq __crt0_clr_dmem_end
|
79 |
|
|
mov #0, 0(r8) ; clear entry
|
80 |
|
|
incd r8
|
81 |
|
|
jmp __crt0_clr_dmem
|
82 |
|
|
__crt0_clr_dmem_end:
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
; -----------------------------------------------------------
|
86 |
|
|
; Copy initialized .data section from ROM to RAM
|
87 |
|
|
; -----------------------------------------------------------
|
88 |
|
|
mov #__data_start_rom, r5
|
89 |
|
|
mov #__data_end_rom, r6
|
90 |
|
|
mov #__data_start, r7
|
91 |
|
|
__crt0_cpy_data:
|
92 |
|
|
cmp r5, r6
|
93 |
|
|
jeq __crt0_cpy_data_end
|
94 |
|
|
mov @r5+, 0(r7)
|
95 |
|
|
incd r7
|
96 |
|
|
jmp __crt0_cpy_data
|
97 |
|
|
__crt0_cpy_data_end:
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
; -----------------------------------------------------------
|
101 |
|
|
; Re-init SR and clear all pending IRQs from buffer
|
102 |
|
|
; -----------------------------------------------------------
|
103 |
|
|
mov #(1<<14), r2 ; this flag auto clears
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
; -----------------------------------------------------------
|
107 |
|
|
; Initialize all remaining registers
|
108 |
|
|
; -----------------------------------------------------------
|
109 |
|
|
mov #0, r4
|
110 |
|
|
; mov #0, r5 ; -- is already initialized
|
111 |
|
|
; mov #0, r6 ; -- is already initialized
|
112 |
|
|
; mov #0, r7 ; -- is already initialized
|
113 |
|
|
; mov #0, r8 ; -- is already initialized
|
114 |
|
|
; mov #0, r9 ; -- is already initialized
|
115 |
|
|
mov #0, r10
|
116 |
|
|
mov #0, r11
|
117 |
|
|
mov #0, r12 ; set argc = 0
|
118 |
|
|
mov #0, r13
|
119 |
|
|
mov #0, r14
|
120 |
|
|
mov #0, r15
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
; -----------------------------------------------------------
|
124 |
|
|
; This is where the actual application is started
|
125 |
|
|
; -----------------------------------------------------------
|
126 |
|
|
__crt0_start_main:
|
127 |
|
|
call #main
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
; -----------------------------------------------------------
|
131 |
|
|
; Go to endless sleep mode if main returns
|
132 |
|
|
; -----------------------------------------------------------
|
133 |
|
|
__crt0_this_is_the_end:
|
134 |
|
|
mov #0, r2 ; deactivate IRQs
|
135 |
|
|
mov #0x4700, &0xFFB8 ; deactivate watchdog
|
136 |
|
|
mov #(1<<4), r2 ; set CPU to sleep mode
|
137 |
|
|
nop
|
138 |
|
|
|
139 |
|
|
.Lfe0:
|
140 |
|
|
.size __crt0_begin, .Lfe0-__crt0_begin
|