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

Last change on this file since 1042 was 1042, checked in by meunier, 8 years ago
  • Passing BLOCK_SIZE as a Makefile parameter in tsar bootloader
  • Adding a 32-bit version for the bootloader
File size: 9.7 KB
RevLine 
[586]1/*
[292]2 * \file  : reset.S
3 * \date  : 01/12/2012
4 * \author: Cesar FUGUET & Manuel BOUYER & Alain Greiner
5 *
[586]6 * This is a generic reset code for a generic multi-clusters / multi-processors
[755]7 * TSAR architecture (up to 256 clusters / up to 4 processors per cluster).
[292]8 *
[586]9 * There is one XICU, one TTY, one DMA, and one memory bank per cluster.
10 *
[755]11 * This preloader uses a stack segment allocated in cluster 0 for processor 0.
12 * The stack allocation is not performed for other processors as they do not
13 * need it during the preloader execution. Therefore, this allocation should be
14 * done by the loaded Operating System.
15 *
[586]16 * The replicated XICU is used to awake the sleeping processors:
[606]17 *      xicu_paddr_base = ICU_PADDR_BASE + (cluster_xy << 32)
[586]18 *
19 * It is intended to be used with various operating systems or nano kernels,
[755]20 * including NetBSD, Linux, ALMOS, and GIET_VM.
[586]21 *
22 * - Each processor initializes its Status Register (SR) to disable interrupts.
23 * - Each processor initializes its Count Register.
24 * - Each processor initialises its private XICU WTI mask register.
[755]25 * - Only processor 0 executes the reset_load_elf function to load into memory
[758]26 *   the system specific boot-loader stored on disk at RESET_LOADER_LBA
[586]27 * - All other processors wait in a low power consumption mode that the
28 *   processor 0 wakes them using an IPI (Inter Processor Interruption)
[292]29 */
30
31    #include <defs.h>
32    #include <mips32_registers.h>
33
[606]34    /* These define should be consistent with values defined in map.xml file  */
[292]35
[586]36    .section .reset,"ax",@progbits
37
38    .extern reset_putc
39    .extern reset_getc
40    .extern reset_ioc_read
41    .extern reset_elf_loader
[425]42    .extern memcpy
[586]43    .extern reset_puts
44    .extern reset_putx
45    .extern reset_putd
46    .extern reset_ioc_init
[502]47    .extern versionstr
[949]48    .extern dtb_start
49    .extern dtb_addr
[292]50
[586]51    .globl  reset                    /* Makes reset an external symbol */
52    .ent    reset
[292]53
54    .align  2
55    .set noreorder
56
[586]57reset:
[755]58    b       _reset                   /* 0xbfc0000 */
59    nop                              /* 0xbfc0004 */
[292]60
[586]61    /*  Addresses of the functions provided by this reset code */
[292]62
[634]63preloader_vector:
[755]64    .word   RESET_VERSION            /* 0xbfc0008 */
[949]65    .word   dtb_start                /* 0xbfc000c */
[755]66    .word   reset_putc               /* 0xbfc0010 */
67    .word   reset_getc               /* 0xbfc0014 */
68    .word   reset_ioc_read           /* 0xbfc0018 */
69    .word   reset_elf_loader         /* 0xbfc001C */
70    .word   memcpy                   /* 0xbfc0020 */
71    .word   reset_puts               /* 0xbfc0024 */
72    .word   reset_putx               /* 0xbfc0028 */
73    .word   reset_putd               /* 0xbfc002C */
[292]74
[586]75_reset:
[292]76
[586]77    /* All processors Disable interruptions, keep STATUSbev enabled */
78
[292]79    li      k0,     (1 << 22)
80    mtc0    k0,     CP0_STATUS
81
[801]82    /*
83     * All processors compute gpid, lpid, cluster_xy
[833]84     * gpid = ebase[11:0] = X_WIDTH : Y_WIDTH : P_WIDTH
[801]85     *                        x         y       lpid
86     * X, Y and LPID fields are left-aligned
87     */
[292]88
89    mfc0    k0,     CP0_EBASE
[833]90    andi    t0,     k0,     0xFFF            /* t0 <= gpid (<= 4096 procs)  */
[801]91    andi    t1,     t0,     ((1<<P_WIDTH)-1) /* t1 <= lpid                  */
92    srl     t2,     t0,     P_WIDTH          /* t2 <= cluster_xy            */
[292]93
[1042]94    /* All processors initialize the count register in CP0 */
[292]95
96    mtc0    zero,   CP0_COUNT
97
[1042]98#if USE_32BIT
99    /*** VERSION 1 : 32 bits ***/
100
[586]101    /*
[1042]102     * If the addresses are 32-bit wide, we need to compute the address
103     * if the XICU for each cluster
[755]104     * All processors enable the WTI for XICU
[586]105     * Each processor may have IRQ_PER_PROC irq outputs from the XICU
[755]106     * In each cluster, the XICU base address depends on the cluster_xy
[292]107     */
[1042]108    la      t3,     SEG_XCU_BASE      /* t3 <= ICU base address             */
109    li      t4,     1                 /* t4 <= 1                            */
110    sll     t4,     t4,     X_WIDTH   /* t4 <= 1 << X_WIDTH                 */
111    li      t5,     1                 /* t5 <= 1                            */
112    sll     t5,     t5,     Y_WIDTH   /* t5 <= 1 << Y_WIDTH                 */
113    multu   t4,     t5                /* X_WIDTH * Y_WIDTH                  */
114    mflo    t4                        /* t4 <= X_WIDTH * Y_WIDTH            */
115    lui     t5,     0x8000            /* t5 <= 0x80000000                   */
116    divu    t5,     t4                /* (Address increment per cluster) / 2*/
117    mflo    t4                        /* t4 <= Increment / 2                */
118    sll     t4,     t4,     1         /* t4 <= Address increment per clus.  */
119    mult    t4,     t2                /* Cluster increment * Cluster num.   */
120    mflo    t4                        /* Cluster base address               */
121    addu    t3,     t3,     t4        /* t3 <= XICU base address in clus.   */
[302]122
[1042]123    move    t4,     t1                /* t4 <= local_id                     */
124    li      t5,     IRQ_PER_PROCESSOR /* t5 <= IRQ_PER_PROCESSOR            */
125    multu   t4,     t5
126    mflo    t6                       /* t6 <= IRQ_PER_PROC * local_id       */
127    sll     t4,     t6,     2        /* t4 <= OUT_INDEX = t6 * 4            */
128
129    li      t5,     (0xC << 7)       /* t5 <= FUNC      = XICU_MSK_WTI      */
130    or      t4,     t4,     t5       /* t4 <= FUNC | INDEX | 00             */
131    or      t5,     t3,     t4       /* t5 <= &XICU[MSK_WTI][OUT_INDEX]     */
132
133    /* All processors set WTI mask */
134
135    li      t4,     1
136    sllv    t4,     t4,     t1       /* Set XICU[MSK_WTI][INDEX][local_id]  */
137    sw      t4,     0(t5)            /* XICU[MSK_WTI][INDEX] <= t4          */
138#else
139    /*** VERSION 2 : 40 bits ***/
140
141    /*
142     * All processors enable the WTI for XICU
143     * Each processor may have IRQ_PER_PROC irq outputs from the XICU
144     * In each cluster, the XICU base address depends on the cluster_xy
145     */
[758]146    la      t3,     SEG_XCU_BASE      /* t3 <= ICU base address             */
147    move    t4,     t1                /* t4 <= local_id                     */
148    li      t5,     IRQ_PER_PROCESSOR /* t5 <= IRQ_PER_PROCESSOR            */
[755]149    multu   t4,     t5
150    mflo    t6                       /* t6 <= IRQ_PER_PROC * local_id       */
151    sll     t4,     t6,     2        /* t4 <= OUT_INDEX = t6 * 4            */
[302]152
[755]153    li      t5,     (0xC << 7)       /* t5 <= FUNC      = XICU_MSK_WTI      */
154    or      t4,     t4,     t5       /* t4 <= FUNC | INDEX | 00             */
155    or      t5,     t3,     t4       /* t5 <= &XICU[MSK_WTI][OUT_INDEX]     */
[292]156
[755]157    /* All processors set WTI mask using the physical address extension */
158
[292]159    li      t4,     1
[755]160    sllv    t4,     t4,     t1       /* Set XICU[MSK_WTI][INDEX][local_id]  */
[292]161
[755]162    mtc2    t2,     CP2_PADDR_EXT    /* set PADDR extension                 */
163    sw      t4,     0(t5)            /* XICU[MSK_WTI][INDEX] <= t4          */
164    mtc2    zero,   CP2_PADDR_EXT    /* reset PADDR extension               */
[1042]165#endif
[567]166
[586]167    /*
[1042]168     * Only the bootstrap processor loads and executes the boot-loader
[292]169     * We have:
[755]170     * t0: global pid
171     * t1: local pid
[606]172     * t2: cluster_xy
[1042]173     * t3: xicu physical base address in bootstrap cluster
[292]174     */
175
[1042]176    li      t4,     BS_PROC
177    bne     t4,     t0,     _reset_wait
[292]178    nop
179
[1042]180    /* Bootstrap Processor initializes stack pointer */
[755]181
182    la      k0,     _stack
183    li      k1,     RESET_STACK_SIZE /* k1 <= P0 stack size                 */
184    addu    sp,     k0,     k1       /* P0 stack from base to (base + size) */
185
[1042]186    /* Bootstrap Processor displays version for this reset code */
[292]187
[587]188    la      a0,     versionstr
[758]189    jal     reset_puts
[587]190    nop
[292]191
[1042]192    /* Bootstrap Processor initializes the block device */
[502]193
[758]194    jal     reset_ioc_init
[292]195    nop
196
[586]197    /*
[1042]198     * Bootstrap Processor jumps to the reset_elf_loader routine passing as argument
[755]199     * the block number in which is loaded the .elf file
[292]200     */
201
[758]202    li      a0,     RESET_LOADER_LBA
203    jal     reset_elf_loader
[292]204    nop
205
[755]206    /*
[1042]207     * Bootstrap Processor jumps to the entry address defined in the .elf file, and
[755]208     * returned by reset_elf_loader function.
209     * First argument is pointer to the preloader function vectors other
210     * function arguments are 0
[292]211     */
212
[755]213    la      a0,     preloader_vector
[949]214    lw      a1,     dtb_addr
[292]215    move    a2,     zero
216    move    a3,     zero
217    jr      v0
218    nop
219
[586]220    /*
[755]221     * All processor (but processor 0) wait in low power mode until processor 0
222     * wakes them using an IPI.
[292]223     * We have:
224     * t0: global id
225     * t1: local id
226     * t2: cluster id
[586]227     * t3: xicu physical base address in cluster 0
[292]228     */
229
[586]230_reset_wait:
[292]231
[755]232    sll     t4,     t1,     2        /* t4 <= local_id * 4                  */
233    addu    t5,     t4,     t3       /* t5 <= &XICU[WTI_REG][local_id]      */
[586]234
[292]235    wait
236
[755]237    /*
238     * All other processors, when exiting wait mode, read from XICU the address
239     * to jump.
240     * This address is the boot-loader entry address that has been written in
241     * the mailbox by the IPI sent by processor 0
[586]242     */
[567]243
[755]244    mtc2    t2,     CP2_PADDR_EXT    /* set PADDR extension                 */
245    lw      k0,     0(t5)            /* k0 <= XICU[WTI_REG][local_id]       */
246    mtc2    zero,   CP2_PADDR_EXT    /* reset PADDR extension               */
[567]247
[292]248    jr      k0
249    nop
250
251/* Exception entry point */
[586]252
[292]253.org 0x0380
254_excep:
[755]255    mfc0    a0,     CP0_STATUS       /* first arg is status                 */
256    mfc0    a1,     CP0_CAUSE        /* second arg is cause                 */
257    mfc0    a2,     CP0_EPC          /* third argc is epc                   */
258    mfc2    a3,     CP2_DBVAR        /* fourth argc is dbvar                */
[292]259    nop
260    j       handle_except
261    nop
262
[586]263    .end reset
[292]264
265    .set reorder
[302]266
[755]267    .section .data
268
269_stack:
270
271    .space RESET_STACK_SIZE
272
[302]273/*
274 * vim: tabstop=4 : shiftwidth=4 : expandtab
275 */
Note: See TracBrowser for help on using the repository browser.