romboot.S revision 1.7 1 1.7 shin /* $NetBSD: romboot.S,v 1.7 2003/10/25 10:00:12 shin Exp $ */
2 1.1 shin
3 1.1 shin /*-
4 1.7 shin * Copyright (c) 2001, 2002, 2003 Takao Shinohara.
5 1.1 shin *
6 1.1 shin * Redistribution and use in source and binary forms, with or without
7 1.1 shin * modification, are permitted provided that the following conditions
8 1.1 shin * are met:
9 1.1 shin * 1. Redistributions of source code must retain the above copyright
10 1.1 shin * notice, this list of conditions and the following disclaimer.
11 1.1 shin * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 shin * notice, this list of conditions and the following disclaimer in the
13 1.1 shin * documentation and/or other materials provided with the distribution.
14 1.1 shin *
15 1.7 shin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.7 shin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.7 shin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.7 shin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.7 shin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.7 shin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.7 shin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.7 shin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.7 shin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.7 shin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 shin */
26 1.1 shin
27 1.1 shin /*
28 1.1 shin * simple boot loader for ROM
29 1.1 shin *
30 1.1 shin * supported platform: LASER5 L-Router(L-Board)
31 1.1 shin */
32 1.1 shin
33 1.1 shin #define zero $0
34 1.1 shin #define AT $at
35 1.1 shin #define v0 $2
36 1.1 shin #define v1 $3
37 1.1 shin #define a0 $4
38 1.1 shin #define a1 $5
39 1.1 shin #define a2 $6
40 1.1 shin #define a3 $7
41 1.1 shin #define t0 $8
42 1.1 shin #define t1 $9
43 1.1 shin #define t2 $10
44 1.1 shin #define t3 $11
45 1.1 shin #define t4 $12
46 1.1 shin #define t5 $13
47 1.1 shin #define t6 $14
48 1.1 shin #define t7 $15
49 1.1 shin #define s0 $16
50 1.1 shin #define s1 $17
51 1.1 shin #define s2 $18
52 1.1 shin #define s3 $19
53 1.1 shin #define s4 $20
54 1.1 shin #define s5 $21
55 1.1 shin #define s6 $22
56 1.1 shin #define s7 $23
57 1.1 shin #define t8 $24
58 1.1 shin #define t9 $25
59 1.1 shin #define k0 $26
60 1.1 shin #define k1 $27
61 1.1 shin #define gp $28
62 1.1 shin #define sp $29
63 1.1 shin #define s8 $30
64 1.1 shin #define ra $31
65 1.1 shin
66 1.6 shin #define MIPS_KSEG0_START 0x80000000
67 1.1 shin #define MIPS_KSEG1_START 0xa0000000
68 1.6 shin #define KSEG1_KSEG0_DIFF (MIPS_KSEG1_START - MIPS_KSEG0_START)
69 1.4 uch #define KERNEL_LOADADDR 0x80001000
70 1.6 shin #define MAX_KERNEL_SIZE (1024*1024*6) # 6MB
71 1.6 shin #define MAX_DCACHE_SIZE (1024*32) # 32KB
72 1.1 shin
73 1.1 shin .text
74 1.1 shin .set noreorder
75 1.1 shin .globl _start
76 1.1 shin _start:
77 1.1 shin bal 1f # ra = ROM address + 8
78 1.1 shin nop
79 1.6 shin 1: subu a0, ra, 8 # a0 = ROM address(kseg1)
80 1.6 shin subu a0, KSEG1_KSEG0_DIFF # convert to kseg0 address
81 1.1 shin move s0, a0 # keep it in s0
82 1.1 shin la t0, _etext
83 1.1 shin la t1, _ftext
84 1.1 shin subu t0, t1 # t0 = size of boot loader
85 1.1 shin addu a0, t0 # a0 = kernel address in ROM
86 1.1 shin li a1, KERNEL_LOADADDR
87 1.6 shin li t2, MAX_KERNEL_SIZE # max kernel size = 6MB - boot
88 1.1 shin subu t2, t0
89 1.1 shin addu t2, a1 # kernel end address
90 1.6 shin la t9, 2f
91 1.6 shin addu t9, s0
92 1.6 shin jr t9 # jump to cached address
93 1.6 shin nop
94 1.1 shin 2:
95 1.1 shin lw v0, 0(a0)
96 1.1 shin sw v0, 0(a1)
97 1.1 shin addu a0, 4
98 1.1 shin bltu a1, t2, 2b
99 1.1 shin addu a1, 4 # BDSLOT
100 1.6 shin
101 1.6 shin /* purge data cache */
102 1.6 shin li v0, MAX_DCACHE_SIZE
103 1.6 shin 3: lw zero, 0(a1)
104 1.6 shin addu a1, 4
105 1.6 shin bnez v0, 3b
106 1.6 shin subu v0, 4 # BDSLOT
107 1.1 shin
108 1.5 shin li sp, KERNEL_LOADADDR # initialize stack pointer
109 1.1 shin li a0, 1 # argc = 1
110 1.1 shin addu a1, sp, -16 # argv
111 1.1 shin la t0, argv0
112 1.1 shin addu t0, s0
113 1.1 shin sw t0, 0(a1) # argv[0] = "netbsd"
114 1.1 shin sw zero, 4(a1) # argv[1] = NULL
115 1.1 shin la a2, bootinfo
116 1.1 shin addu a2, s0
117 1.1 shin move a3, zero
118 1.1 shin li t9, KERNEL_LOADADDR
119 1.1 shin jr t9
120 1.1 shin nop
121 1.1 shin
122 1.1 shin argv0: .asciiz "netbsd"
123 1.1 shin
124 1.1 shin bootinfo:
125 1.1 shin .word 34 # len
126 1.1 shin .word 0x13536135 # magic
127 1.1 shin .word 0 # fb_addr
128 1.1 shin .word 0, 0 # fb_line_bytes, fb_width, fb_height, fb_type
129 1.1 shin .word 2 # BI_CNUSE_SERIAL
130 1.1 shin .word 0x04104500 # VR4122
131 1.1 shin .word 0x03810200 # LASER5 L-BOARD
132 1.1 shin /*
133 1.1 shin * kernel binary image begins here.
134 1.1 shin */
135