summaryrefslogtreecommitdiff
path: root/util/mkelfImage/linux-ia64/head.S
blob: 4a12fb55663dbaee6e477eb3aab0ddd9ed009e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#define ASSEMBLY 1
	
	.text

#include "convert.h"

	.globl _start
	.proc _start
_start:
	alloc	loc0=ar.pfs,1,2,3,0 /* in, local, out, rotating */
	mov	loc1=rp
	mov	r14=ip	/* Get the address of _start, I'm in the first bundle */
	movl	r15=@gprel(_start)
	;;
	sub	gp=r14,r15	/* gp = _start - @gprel(_start), current value of gp */
	;; 
	mov	out0=in0
	mov	out1=r28
	add	out2=@gprel(params),gp
	br.call.sptk.few rp=convert_params

	
	mov	r28=r8
	add	r15=@gprel(entry), gp
	;;
	ld8	r16=[r15]
	;;
	mov	b1=r16
	mov	ar.pfs=loc0
	mov	rp=loc1
	;;
	br.cond.sptk.few b1

	.size _start, . - _start
	.endp _start


#if 0

/* Base Address */
#define UART_BASE	0x00000000f8030000
#define UART_BAUD	9600

/* Data */
#define UART_RBR	0x00
#define UART_TBR	0x00
/* Control */
#define UART_IER	0x01
#define UART_IIR	0x02
#define UART_FCR	0x02
#define UART_LCR	0x03
#define UART_MCR	0x04
	
#define UART_DLL	0x00
#define UART_DLM	0x01
/* Status */
#define UART_LSR	0x05
#define UART_MSR	0x06
#define UART_SCR	0x07

#define UART_PHYS_BASE	(0x8000000000000000|UART_BASE)
#define UART_DIV	(115200/UART_BAUD)
#define UART_DIV_LO	(UART_DIV&0xFF)
#define UART_DIV_HI	((UART_DIV >> 8)&0xFF)

#if ((115200%UART_BAUD) != 0)
#error Bad uart baud rate
#endif

/* NOTE: As these are debugging functions, they do not consume any
 * space on the register stack, and instead rely entirely on
 * scratch registers for the registers they use.
 */
uart_init:
	/* set the UART_BASE */
	movl	r31=UART_PHYS_BASE
	;;
	
	/* disable interrupts */
	add	r30=UART_IER,r31
	mov	r29=0x00
	;; 
	st1	[r30]=r29

	/* enable fifos */
	add	r30=UART_FCR,r31
	mov	r29=0x01
	;; 
	st1	[r30]=r29

	/* Set Baud Rate Divisor to UART_BAUD */
	add	r30=UART_LCR,r31
	mov	r29=0x83
	;; 
	st1	[r30]=r29

	add	r30=UART_DLL,r31
	mov	r29=UART_DIV_LO
	;; 
	st1	[r30]=r29
	
	add	r30=UART_DLM,r31
	mov	r29=UART_DIV_HI
	;; 
	st1	[r30]=r29

	add	r30=UART_LCR,r31
	mov	r29=0x03
	;; 
	st1	[r30]=r29

	br.ret.sptk.few rp

	.proc	uart_tx_byte
	.globl  uart_tx_byte
uart_tx_byte:
	/* set the UART_PHYS_BASE */
	movl	r31=UART_PHYS_BASE
	;;
__uart_tx_byte:
	/* Wait until the UART can hold another byte */
	add	r30=UART_LSR,r31
	;;
9:	ld1.acq.nta	r29=[r30]
	;;
	and	r29=0x20,r29
	;;
	cmp.eq	p63,p0=0,r29
(p63)	br.cond.sptk.few	9b

	/* Transmit the byte */
	add	r30=UART_TBR,r31
	;;
	st1.rel.nta	[r30]=r32
	;;
	
	/* Wait until the UART is empty to be certain the byte is flushed */
	add	r30=UART_LSR,r31
	;;
9:	ld1.acq.nta	r29=[r30]
	;;
	and	r29=0x40,r29
	;;
	cmp.eq	p63,p0=0,r29
(p63)	br.cond.sptk.few	9b
	;;
	br.ret.sptk.few	rp
	.endp uart_tx_byte

__uart_tx_hex_char:
	cmp.ltu	p62,p63=9,r32
	;;
(p63)	add	r32=48,r32	/* digits*/
(p62)	add	r32=55,r32	/* letters */
	br.cond.sptk.few __uart_tx_byte
	
uart_tx_hex64:
	/* set the UART_bASE */
	movl	r31=UART_PHYS_BASE
	/* skip r28 */
	mov	r27=rp
	mov	r26=ar.pfs
	mov	r25=r32
	;;
	extr.u	r32=r25,60,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,56,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,52,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,48,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,44,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,40,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,36,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,32,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,28,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,24,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,20,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,16,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,12,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,8,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,4,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	extr.u	r32=r25,0,4
	br.call.sptk.few rp=__uart_tx_hex_char
	;;
	mov	ar.pfs = r26
	mov	rp = r27
	;; 
	br.ret.sptk.few	rp
#endif

	.section ".trailer", "a"
	/* Constants set at build time, these are at the very end of my image */
	.balign 16
	.global params
params:
convert_magic:
	.quad	CONVERT_MAGIC
entry:
	.quad	0
initrd_start:
	.quad	0
initrd_size:
	.quad	0
cmdline:
	.asciz "BOOT_IMAGE=head.S console=ttyS0 ip=dhcp root=/dev/nfs"
	.org cmdline + 1024, 0
cmdline_end: