/
main.c
115 lines (90 loc) · 2.98 KB
/
main.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
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <compiler.h>
#include <debug.h>
#include <string.h>
#include <app.h>
#include <arch.h>
#include <platform.h>
#include <target.h>
#include <lib/heap.h>
#include <kernel/thread.h>
#include <kernel/timer.h>
#include <kernel/dpc.h>
#include <platform/mt_gpt.h>
#if _MAKE_HTC_LK
#include <htc_bootloader_log.h>
#endif
#ifdef MTK_LK_IRRX_SUPPORT
#include <platform/mtk_ir_lk_core.h>
#endif
extern void *__ctor_list;
extern void *__ctor_end;
extern int __bss_start;
extern int _end;
/* boot_time is calculated form kmain to kernel jump */
volatile unsigned int boot_time = 0;
static int bootstrap2(void *arg);
/* called from crt0.S */
void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
void kmain(void)
{
boot_time = get_timer(0);
zzytest_printf("kmain begin, boot_time=%d\n", boot_time);
// get us into some sort of thread context
thread_init_early();
// early arch stuff
arch_early_init();
// do bootloader log init
bldr_log_init(BOOT_DEBUG_LOG_BASE_PA, BOOT_DEBUG_LOG_SIZE);
// do any super early platform initialization
platform_early_init();
zzytest_printf("zzytest, printf log end\n");
dprintf(CRITICAL, "zzytest, after platform_early_init\n");
// bring up the kernel heap
heap_init();
// initialize the threading system
thread_init();
// initialize the dpc system
dpc_init();
// initialize kernel timers
timer_init();
// create a thread to complete system initialization
thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
// enable interrupts
exit_critical_section();
// become the idle thread
dprintf(CRITICAL, "zzytest, thread_become_idle\n");
thread_become_idle();
}
int main(void);
static int bootstrap2(void *arg)
{
dprintf(CRITICAL, "zzytest, bootstrap2\n");
// initialize the rest of the platform
platform_init();
apps_init();
return 0;
}