aboutsummaryrefslogtreecommitdiff
path: root/libgloss/hp74x/crt0.s
blob: b5986e6a2f7c89a131e1e3f2318dea0c9a64fe15 (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
/*
 * crt0.S -- startup file for hppa.
 * 		rob@cygnus.com (Rob Savoye)
 */
	.VERSION "0.2"
	.COPYRIGHT "crt0.S for hppa"

;sp      .equ    %r30     		; stack pointer
;dp      .equ    %r27     		; global data pointer
;arg0    .equ    %r26     		; argument
;arg1    .equ    %r25     		; argument or high part of double argument
;arg2    .equ    %r24     		; argument
;arg3    .equ    %r23     		; argument or high part of double argument

#define         IMM(a,b)        ldil L%a,b  ! ldo  R%a(b),b
#define         imm(i,t)        ldil LS%i,t ! addi RS%i,t,t

	.DATA

/****
 * FIXME: these are just a gross hack so this will assemble
 ****/
_bss_start	.WORD
_bss_end	.WORD
_foobar	
		.STRINGZ "Foo Bar...\r\n"

;;_SYSTEM_ID	.WORD
;;		.EXPORT _SYSTEM_ID	; FIXME this is only so it'll
					; link
	
/* 
 * Set up the standard spaces (sections) These definitions come
 * from /lib/pcc_prefix.s.
 */
	.space  $TEXT$,0
	
        .SUBSPA $BOOT$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=4
        .IMPORT _start

/*
 * stuff we need that's defined elsewhere.
 */
	.IMPORT main, CODE
	.IMPORT _bss_start, DATA
	.IMPORT _bss_end, DATA
	.IMPORT environ, DATA

/*
 * start -- set things up so the application will run.
 *
 */
        .PROC
        .CALLINFO SAVE_SP, FRAME=48
        .EXPORT $START$,ENTRY
$START$

	/* FIXME: this writes to page zero */
	;; setup the %30 (stack pointer) with some memory
	ldil 	L%_stack+48,%r30
        ldo 	R%_stack+48(%r30),%r30		; should be %r30 (sp) but then
						; we'd kill our test program :-)
	;; we need to set %r27 (global data pointer) here too 
	ldil 	L%$global$,%r27
        ldo 	R%$global$(%r27),%r27		; same problem as above

/*
 * zerobss -- zero out the bss section
 */
	; load the start of bss
	ldil 	L%_bss_start,%r4
        ldo 	R%_bss_start(%r4),%r4

	;  load the end of bss
	ldil 	L%_bss_end,%r5
        ldo 	R%_bss_end(%r5),%r5


bssloop
	addi	-1,%r5,%r5			; decrement _bss_end
	stb	%r0,0(0,%r5)			; we do this by bytes for now even
						; though it's slower, it's safer
	combf,=	%r4,%r5, bssloop	
	nop
	
	ldi	1,%ret0

/*
 * Call the main routine from the application to get it going.
 * main (argc, argv, environ)
 * We pass argv as a pointer to NULL.
 */

	bl	main,%r2
	nop

        .PROCEND
/*
 * _exit -- Exit from the application. Normally we cause a user trap
 * 	    to return to the ROM monitor for another run, but with
 *	    this monitor we can't. Still, "C" wants this symbol, it
 *	    should be here. Jumping to 0xF0000004 jumps back into the
 *	    firmware, while writing a 5 to 0xFFFE0030 causes a reset.
 */
	.EXPORT _exit, ENTRY
_exit
	.PROC
	.CALLINFO
	.ENTRY
;;	ldil	L%0xf0000004,%r1
;;	bl	%r1, %r2
	
	ldil 	L'4026531844,%r19
        ldo 	R'4026531844(%r19),%r19
	blr	%r19, %r2
	nop
	
	;; This just causes a breakpoint exception
;;	break	0x0e,0xa5a
;;      bv,n    (%rp)
	nop
	.EXIT
	.PROCEND

        .subspa $UNWIND_START$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=56
        .export $UNWIND_START
$UNWIND_START
        .subspa $UNWIND$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=64
        .subspa $UNWIND_END$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=72
        .export $UNWIND_END
$UNWIND_END
        .subspa $RECOVER_START$,QUAD=0,ALIGN=4,ACCESS=0x2c,SORT=73
        .export $RECOVER_START
$RECOVER_START
        .subspa $RECOVER$,QUAD=0,ALIGN=4,ACCESS=0x2c,SORT=80
        .subspa $RECOVER_END$,QUAD=0,ALIGN=4,ACCESS=0x2c,SORT=88
        .export $RECOVER_END
$RECOVER_END

; The following declarations are, by default in the data space ($PRIVATE$)

;;        .space  $PRIVATE$,1

/*
 * Here we set up the standard date sub spaces.
 * _dp is for the WinBond board.
 *
 * Set up some room for a stack. We just grab a chunk of memory.
 * We also setup some space for the global variable space, which
 * must be done using the reserved name "$global$" so "C" code
 * can find it. The stack grows towards the higher addresses.
 */

        .subspa $DATA$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=16
        .subspa $SHORTDATA$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=24
        .subspa $GLOBAL$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=40
        .export $global$
        .export _dp
$global$
_dp
        .subspa $SHORTBSS$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=80,ZERO
        .subspa $BSS$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=82,ZERO

       .subspa $STACK$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=88,ZERO
        .export _stack
_stack
        .BLOCK          0x2000

/*
 * The heap follows the stack. To use dynamic memory routines in an
 * application, some space MUST be assigned to the stack.
 */

        .subspa $HEAP$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=96,ZERO
        .export _heap
_heap
        .end