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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [libgloss/] [scarts_32/] [crt0.S] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
/* Startup code for SCARTS (32-bit).
2
 * Copyright (C) 2010, 2011 Embedded Computing Systems Group,
3
 * Department of Computer Engineering, Vienna University of Technology.
4
 * Contributed by Martin Walter 
5
 *
6
 * The authors hereby grant permission to use, copy, modify, distribute,
7
 * and license this software and its documentation for any purpose, provided
8
 * that existing copyright notices are retained in all copies and that this
9
 * notice is included verbatim in any distributions. No written agreement,
10
 * license, or royalty fee is required for any of the authorized uses.
11
 * Modifications to this software may be copyrighted by their authors
12
 * and need not follow the licensing terms described here, provided that
13
 * the new terms are clearly indicated on the first page of each file where
14
 * they apply.
15
 */
16
 
17
        .file   "crt0.S"
18
 
19
.macro CLEAR_REG reg
20
        ldhi \reg, 0
21
        ldliu \reg, 0
22
.endm
23
 
24
.macro CLEAR_MEM_REG addr
25
        ldli r7, \addr
26
        CLEAR_REG r13
27
        stw r13, r7
28
.endm
29
 
30
.macro STORE_MEM_REG addr
31
        ldli r7, \addr
32
        stw r13, r7
33
.endm
34
 
35
.macro LOAD_SYM_TO_REG reg symbol
36
        .global \symbol
37
        ldhi    \reg, 4th(\symbol)
38
        ldliu   \reg, 3rd(\symbol)
39
        sli     \reg, 8
40
        ldliu   \reg, hi(\symbol)
41
        sli     \reg, 8
42
        ldliu   \reg, lo(\symbol)
43
.endm
44
 
45
        .section .text
46
        .global _start
47
        .type start, @function
48
_start: ; the linker script defines start as the application entry point
49
        ; clear the bss section ('__bss_start' and '_end' are provided through the linker script)
50
        LOAD_SYM_TO_REG r5 __bss_start  ; store symbol '__bss_start' in r5
51
        LOAD_SYM_TO_REG r6 _end         ; store symbol '_end' in r6
52
        cmp_eq r5, r6                   ; check if address in r5 equals address in r6 (.bss empty)
53
        jmpi_ct .bss_clear
54
 
55
        ldli r7, 0                      ; load value 0 into r7
56
.bss_clear_loop:
57
        stw r7, r5                      ; store value in r7 at address in r5
58
        addi r5, 4                      ; increase address in r5 by the word size in bytes
59
        cmp_lt r5, r6                   ; check if address in r5 is less than address in r6
60
        jmpi_ct .bss_clear_loop
61
 
62
.bss_clear:
63
        ; clear hardware registers
64
        CLEAR_REG r0
65
        CLEAR_REG r1
66
        CLEAR_REG r2
67
        CLEAR_REG r3
68
        CLEAR_REG r4
69
        CLEAR_REG r5
70
        CLEAR_REG r6
71
        CLEAR_REG r7
72
        CLEAR_REG r8
73
        CLEAR_REG r9
74
        CLEAR_REG r10
75
        CLEAR_REG r11
76
        CLEAR_REG r12
77
        CLEAR_REG r13
78
        CLEAR_REG r14
79
        CLEAR_REG r15
80
 
81
        ; clear memory-mapped extension module registers
82
        CLEAR_MEM_REG -24 ; frame pointer W register
83
        CLEAR_MEM_REG -20 ; frame pointer X register
84
        CLEAR_MEM_REG -16 ; frame pointer Y register
85
        CLEAR_MEM_REG -12 ; frame pointer Z register
86
 
87
        ; initialize the FP and SP register to the beginning of the stack
88
        ; ('__stack' is provided through the linker script)
89
        LOAD_SYM_TO_REG r13 __stack     ; store symbol '__stack' in r13
90
        STORE_MEM_REG -16               ; frame pointer register Y (FP)
91
        STORE_MEM_REG -12               ; frame pointer register Z (SP)
92
 
93
        ; call main
94
        LOAD_SYM_TO_REG r13 main        ; store symbol 'main' in r13
95
        jsr r13
96
 
97
        ; call _exit ('_exit' is provided by the libc and loops indefinitely)
98
        mov r1, r0                      ; move return value of 'main' in r0 to argument register r1
99
        LOAD_SYM_TO_REG r13 _exit       ; store symbol ' exit' in r13
100
        jsr r13
101
        .size   _start, .-_start

powered by: WebSVN 2.1.0

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