OpenCores
URL https://opencores.org/ocsvn/darkriscv/darkriscv/trunk

Subversion Repositories darkriscv

[/] [darkriscv/] [trunk/] [src/] [boot.s] - Diff between revs 2 and 4

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 4
Line 1... Line 1...
        .file   "boot.c"
/*
 
 * Copyright (c) 2018, Marcelo Samsoniuk
 
 * All rights reserved.
 
 *
 
 * Redistribution and use in source and binary forms, with or without
 
 * modification, are permitted provided that the following conditions are met:
 
 *
 
 * * Redistributions of source code must retain the above copyright notice, this
 
 *   list of conditions and the following disclaimer.
 
 *
 
 * * Redistributions in binary form must reproduce the above copyright notice,
 
 *   this list of conditions and the following disclaimer in the documentation
 
 *   and/or other materials provided with the distribution.
 
 *
 
 * * Neither the name of the copyright holder nor the names of its
 
 *   contributors may be used to endorse or promote products derived from
 
 *   this software without specific prior written permission.
 
 *
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 */
 
 
        .option nopic
        .option nopic
        .text
        .text
 
        .section .boot
        .align  2
        .align  2
        .globl  boot
        .globl  check4rv32i
        .type   boot, @function
 
 
/*
boot:
boot:
        lui     a5,%hi(threads)
        - read and increent thread counter
        lw      a4,%lo(threads)(a5)
        - case not zero, jump to multi thread boot
        addi    sp,sp,-16
        - otherwise continue
        sw      s0,8(sp)
*/
        addi    a3,a4,1
 
        sw      a3,%lo(threads)(a5)
_boot:
        lui     a5,%hi(io)
 
        sw      ra,12(sp)
        la      a0,threads
        sw      s1,4(sp)
        lw      a1,0(a0)
        andi    a4,a4,1
        addi    a2,a1,1
        addi    a3,a5,%lo(io)
        sw      a2,0(a0)
        li      a2,-128
        la      a3,io
        sw      a4,0(sp)
        bne     a1,x0,_multi_thread_boot
        sb      a2,3(a3)
 
        lui     s0,%hi(utimers)
/*
        beqz    a4,.L6
        normal boot here:
        li      a3,999424
        - set stack
        addi    a5,a5,%lo(io)
        - set global pointer
        addi    a3,a3,575
        - plot boot banner
.L2:
        - print memory setup
        lw      a4,%lo(utimers)(s0)
        - call main
        addi    a1,a4,-1
        - repeat forever
        sw      a1,%lo(utimers)(s0)
*/
        bnez    a4,.L4
 
        lhu     a4,8(a5)
_normal_boot:
        addi    a4,a4,1
 
        slli    a4,a4,16
        la      sp,_stack
        srli    a4,a4,16
        la      gp,_global
        sh      a4,8(a5)
 
        sw      a3,%lo(utimers)(s0)
 
.L4:
 
        sb      a2,3(a5)
 
        j       .L2
 
.L6:
 
        lui     s1,%hi(boot)
 
.L3:
 
        call    banner
        call    banner
        lui     a0,%hi(.LC0)
 
        addi    a3,sp,16
        la      a3,_stack
        addi    a2,s0,%lo(utimers)
        la      a2,_heap
        addi    a1,s1,%lo(boot)
        sub     a4,a3,a2
        addi    a0,a0,%lo(.LC0)
        la      a1,_boot
 
        la      a0,_boot0msg
        call    printf
        call    printf
 
 
        call    main
        call    main
        j       .L3
 
        .size   boot, .-boot
        j       _normal_boot
        .section        .rodata.str1.4,"aMS",@progbits,1
 
 
/*
 
        multi-thread boot:
 
        - set io base
 
        - write thread number to io.gpio
 
        - increent thread number
 
        - repeat forever
 
*/
 
 
 
_multi_thread_boot:
 
 
 
        sh      a1,10(a3)
 
        addi    a1,a1,1
 
        j       _multi_thread_boot
 
 
 
/*
 
        rv32e/rv32i detection:
 
        - set x15 0
 
        - set x31 1
 
        - sub x31-x15 and return the value
 
        why this works?!
 
        - the rv32i have separate x15 and x31, but the rv32e will make x15 = x31
 
        - this "feature" probably works only in the darkriscv! :)
 
*/
 
 
 
check4rv32i:
 
 
 
        .word   0x00000793      /* addi    x15,x0,0   */
 
        .word   0x00100f93      /* addi    x31,x0,1   */
 
        .word   0x40ff8533      /* sub     a0,x31,x15 */
 
 
 
        ret
 
 
 
/*
 
        data segment here!
 
*/
 
 
 
        .section .rodata
        .align  2
        .align  2
.LC0:
 
        .string "boot0: text@%d data@%d stack@%d\n"
_boot0msg:
        .ident  "GCC: (GNU) 9.0.0 20180818 (experimental)"
        .string "boot0: text@%d data@%d stack@%d (%d bytes free)\n"
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.