source: trunk/softs/tsar_boot/src/reset.S @ 502

Last change on this file since 502 was 502, checked in by bouyer, 11 years ago

Print a version string at execution, dynamically computed at link time.
The version string includes: content of ./version, builder and date,
and svn revision.
This helps to know which version we're really executing ...

File size: 6.6 KB
Line 
1/**
2 * \file  : reset.S
3 * \date  : 01/12/2012
4 * \author: Cesar FUGUET & Manuel BOUYER & Alain Greiner
5 *
6 * This is a boot code for a generic multi-clusters / multi-processors
7 * TSAR architecture (up to 256 clusters / up to 4  processors per cluster).
8 * There is one XICU, one TTY, one DMA and one stack segment per cluster.
9 * segment base adresses = base + cluster_segment_increment*cluster_id
10 *
11 * - Each processor initializes the Status Register (SR) to disable interrupts.
12 * - Each processor initializes the Count Register.
13 * - Each processor initialises its private XICU Write Triggered Interruption
14 *   mask register.
15 * - Only processor 0 initializes the stack pointer ($29).
16 * - Only processor 0 (boot processor) executes the boot_load_elf function to
17 *   load in memory the boot loader stored in the block BOOT_LOADER_LBA of
18 *   the disk.
19 * - All non-boot processors wait in a low power consumption mode that the
20 *   processor 0 wakes them using the IPI (Inter Processor Interruption)
21 *   functionality of the XICU device.
22 */
23
24    #include <defs.h>
25    #include <mips32_registers.h>
26
27    .section .boot,"ax",@progbits
28
29    .extern seg_stack_base
30
31    .extern dtb_addr
32    .extern boot_putc
33    .extern boot_getc
34    .extern boot_ioc_read
35    .extern boot_elf_loader
36    .extern memcpy
37    .extern boot_puts
38    .extern boot_putx
39    .extern boot_putd
40    .extern boot_ioc_init
41    .extern versionstr
42
43    .globl  boot                    /* Make reset an external symbol */
44    .ent    boot
45
46    .align  2
47    .set noreorder
48
49boot:
50    b       _boot                   /* 0xbfc0000 */
51    nop                             /* 0xbfc0004 */
52
53    /*  Addresses of the functions provided by this pre-loader */
54
55    .word   BOOT_VERSION            /* 0xbfc0008 */
56    .word   dtb_addr                /* 0xbfc000c */
57    .word   boot_putc               /* 0xbfc0010 */
58    .word   boot_getc               /* 0xbfc0014 */
59    .word   boot_ioc_read           /* 0xbfc0018 */
60    .word   boot_elf_loader         /* 0xbfc001C */
61    .word   memcpy                  /* 0xbfc0020 */
62    .word   boot_puts               /* 0xbfc0024 */
63    .word   boot_putx               /* 0xbfc0028 */
64    .word   boot_putd               /* 0xbfc002C */
65
66_boot:
67    /* Disable interruptions, keep STATUSbev enabled */
68
69    li      k0,     (1 << 22)
70    mtc0    k0,     CP0_STATUS
71
72    /* Computes proc_id, local_id, cluster_id, and cluster_increment */
73
74    mfc0    k0,     CP0_EBASE
75    andi    t0,     k0,     0x3FF   /* t0 <= proc_id (at most 1024 processors)    */
76
77    move    t3,     t0
78
79    la      k0,     NB_PROCS        /* k0 <= number of processors per cluster     */
80    divu    t3,     k0
81    mfhi    t1                      /* t1 <= local_id   = proc_id % NB_PROCS      */
82    mflo    t2                      /* t2 <= cluster_id = proc_id / NB_PROCS      */
83
84    la      k0,     NB_CLUSTERS
85    li      t3,     0x80000000
86    divu    t3,     k0
87    mflo    t4
88    sll     t4,     1               /* t4 <= cluster_increment = 4G / NB_CLUSTERS */
89
90    mult    t4,     t2
91    mflo    t5                      /* t5 <= cluster_id * cluster_increment       */
92 
93    /* Initialization of the count register in the coprocessor 0 */
94
95    mtc0    zero,   CP0_COUNT
96
97    /* In each cluster, the ICU base address depends on the cluster_id */
98
99    la      t3,     ICU_BASE
100    addu    t3,     t3,     t5      /* t3 <= ICU_BASE +                       */
101                                    /*       (cluster_id * cluster_increment) */
102
103    /**
104     * Compute the output index for the Write Triggered Interruption mask.
105     * Each processor enable the WTI for its irq output
106     * Each processor may have IRQ_PER_PROC private irq outputs from
107     * the XICU
108     */
109
110    move    t4,     t1              /* t4 <= local_id                   */
111    li      t5,     IRQ_PER_PROC    /* t5 <= IRQ_PER_PROC               */
112    multu   t4,     t5             
113    mflo    t6                      /* t6 <= IRQ_PER_PROC * local_id    */
114    sll     t4,     t6,     2       /* t4 <= OUT_INDEX = t6 * 4         */
115
116    li      t5,     (0xC << 7)      /* t5 <= FUNC      = XICU_MSK_WTI   */
117    or      t4,     t4,     t5      /* t4 <= FUNC | INDEX | 00          */
118    or      t5,     t3,     t4      /* t5 <= &XICU[MSK_WTI][OUT_INDEX]  */
119   
120    /* Compute and set WTI mask */
121
122    li      t4,     1
123    sllv    t4,     t4,     t1      /* Set XICU[MSK_WTI][INDEX][local_id] */
124    sw      t4,     0(t5)           /* XICU[MSK_WTI][INDEX] <= t4         */
125
126    /**
127     * We have:
128     * t0: global id
129     * t1: local id
130     * t2: cluster id
131     * t3: xicu base address
132     *
133     * Only processor 0 in cluster 0 executes the boot loader
134     */
135
136    bne     zero,   t0,     _reset_wait
137    nop
138
139    /* Initializes stack pointer */
140
141    la      k1,     seg_stack_base
142    li      k0,     BOOT_STACK_SIZE
143    addu    sp,     k1,     k0      /* sp <= seg_stack_base + BOOT_STACK_SIZE */
144
145    la      a0,     versionstr
146    la      k0,     boot_puts
147    jalr    k0
148    nop
149
150#ifndef SOCLIB_IOC
151
152    /* Initialize the block device */
153
154    la      k0,     boot_ioc_init
155    jalr    k0
156    nop
157
158#endif
159
160    /**
161     * Jump to the boot elf loader routine
162     * Passing as argument the block number in which it must be
163     * the executable elf file to load
164     */
165
166    la      k0,     boot_elf_loader
167    li      a0,     BOOT_LOADER_LBA
168    jalr    k0
169    nop
170
171    /**
172     * We jump to the entry point address defined in the
173     * ELF file. This address is returned by boot_elf_loader function.
174     * All function arguments are 0
175     */
176
177    move    a0,     zero
178    move    a1,     zero
179    move    a2,     zero
180    move    a3,     zero
181    jr      v0
182    nop
183
184/**
185 * Wait in low power consumption mode until the application wakes us.
186 * The application wakes up the non-boot CPUs using a IPI with a non-0
187 * value in the mailbox. This non-0 value is the address to jump to.
188 */
189
190_reset_wait:
191    /**
192     * We have:
193     * t0: global id
194     * t1: local id
195     * t2: cluster id
196     * t3: xicu base address
197     */
198
199    sll     t4,     t1,     2       /* t4 <= local_id * 4             */
200    addu    t5,     t4,     t3      /* t5 <= &XICU[WTI_REG][local_id] */
201
202    wait
203
204    lw      k0,     0(t5)           /* k0 <= XICU[WTI_REG][local_id]  */
205    jr      k0
206    nop
207
208/* Exception entry point */
209.org 0x0380
210_excep:
211    mfc0    a0, CP0_STATUS          /* first arg is status */
212    mfc0    a1, CP0_CAUSE           /* second arg is cause */
213    mfc0    a2, CP0_EPC             /* third argc is epc   */
214    nop
215    j       handle_except
216    nop
217
218    .end boot
219
220    .set reorder
221
222/*
223 * vim: tabstop=4 : shiftwidth=4 : expandtab
224 */
Note: See TracBrowser for help on using the repository browser.