-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstartup.c
140 lines (106 loc) · 2.52 KB
/
startup.c
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
#include "audio.h"
#include "ccu.h"
#include "display.h"
#include "dma.h"
#include "fixed_addr.h"
#include "fs.h"
#include "interrupts.h"
#include "mmu.h"
#include "network.h"
#include "ports.h"
#include "smp.h"
#include "system.h"
#include "tve.h"
#include "uart.h"
#include "usb.h"
#include <stdio.h>
#include <stdlib.h>
#include <h3_i2c.h>
#include <h3_spi.h>
#ifdef GDBSTUB
#include "gdb/gdbstub.h"
#endif
volatile uint32_t tick_counter;
void libc_set_heap(void *start, void *end);
void __libc_init_array(void);
void _init(void) {}
void _reset(void);
void init_sp_irq(uint32_t addr);
void main(int argc, char **argv);
void h3_timer_init(void);
void h3_hs_timer_init(void);
void startup()
{
#ifdef JAILHOUSE
// SP_irq set up by loader
#else
init_sp_irq(0x2000);
#endif
// detect memory size
#ifdef JAILHOUSE
// MMU is already on, so memory detection needs to do cache management to
// work, so it needs to know the cache line size, so we need to call
// mmu_init() beforehand.
mmu_init();
#endif
libc_set_heap((void *)AWBM_BASE_ADDR + 0x02000000, mmu_detect_dram_end());
install_ivt();
#ifndef JAILHOUSE
uart_init(0);
#endif
#ifdef GDBSTUB
gdbstub_init();
#endif
#ifndef JAILHOUSE
// Set up MMU and paging configuration
mmu_init();
#endif
#ifndef JAILHOUSE
// Enble all GPIO
gpio_init();
#endif
// Configure the UART for debugging
uart_print("Booting!\r\n");
#ifdef AWBM_PLATFORM_h3
// Illuminate the power LED
set_pin_mode(PORTL, 10, 1); // PORT L10 output
set_pin_data(PORTL, 10, 1); // PORT L10 high
// reset button
set_pin_mode(PORTL, 3, GPIO_MODE_EINT);
gpio_irq_set_trigger(PORTL, 3, GPIO_EINT_NEGEDGE);
gpio_irq_enable(PORTL, 3, 1);
irq_enable(77); // PORT L interrupt (R_PL_EINT)
#ifndef JAILHOUSE // XXX??
dma_init();
#endif
h3_timer_init();
h3_hs_timer_init();
#endif // AWBM_PLATFORM_h3
__libc_init_array();
// Configure display; try HDMI/DVI first, fall back to analog if it fails to initialize
// XXX: We have to init the display because the system timer
// initialization uses it for calibration.
if (display_init(NULL) != 0)
tve_init(TVE_NORM_NTSC);
else
audio_hdmi_init();
irq_enable(127); // DE (for writeback)
sys_init_timer();
#ifndef JAILHOUSE
// USB
usb_init();
network_init();
#endif
#ifdef AWBM_PLATFORM_h3
h3_i2c_begin();
h3_spi_begin();
#endif
uart_print("Ready!\r\n");
#ifndef JAILHOUSE
set_pin_mode(PORTF, 6, 0); // SD CD pin
#endif
// __libc_init_array();
main(0, NULL);
_reset();
}
unsigned long __dso_handle;