Browse Source

init: Move all init into init.c from start_kernel.c

Aaron Lindsay 7 years ago
parent
commit
c90edb451d
5 changed files with 102 additions and 124 deletions
  1. 2 0
      include/console.h
  2. 0 3
      include/init.h
  3. 99 1
      kernel/init.c
  4. 1 2
      kernel/kernel.mk
  5. 0 118
      kernel/start_kernel.c

+ 2 - 0
include/console.h

@@ -18,6 +18,8 @@
18 18
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 19
  */
20 20
 
21
+#include <framebuffer.h>
22
+
21 23
 #ifndef CONSOLE_H
22 24
 #define CONSOLE_H
23 25
 

+ 0 - 3
include/init.h

@@ -18,9 +18,6 @@
18 18
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 19
  */
20 20
 
21
-void init_earlyinitcalls();
22
-void init_initcalls();
23
-
24 21
 struct initcall_func {
25 22
 	void (*fptr)();
26 23
 };

+ 99 - 1
kernel/init.c

@@ -18,8 +18,18 @@
18 18
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 19
  */
20 20
 
21
-#include <types.h>
21
+#include <atags.h>
22
+#include <console.h>
23
+#include <framebuffer.h>
24
+#include <kmalloc.h>
22 25
 #include <print.h>
26
+#include <mm.h>
27
+#include <mmu.h>
28
+#include <types.h>
29
+
30
+#include <drivers/fb.h>
31
+#include <drivers/serial.h>
32
+
23 33
 
24 34
 extern uint32 early_initcalls_start, early_initcalls_end;
25 35
 extern uint32 initcalls_start, initcalls_end;
@@ -35,3 +45,91 @@ void init_initcalls() {
35 45
 	for (initcall = (void (**)()) &initcalls_start; initcall < (void (**)())&initcalls_end; initcall++)
36 46
 		(*initcall)();
37 47
 }
48
+struct fb console_fb;
49
+
50
+void print_console_logo() {
51
+	print("      _            _      _\n");
52
+	print("     / \\   ___  __| |_ __(_)_  __\n");
53
+	print("    / _ \\ / _ \\/ _` | '__| \\ \\/ /\n");
54
+	print("   / ___ \\  __/ (_| | |  | |>  <\n");
55
+	print("  /_/   \\_\\___|\\__,_|_|  |_/_/\\_\\\n\n");
56
+	print("  Copyright (C) 2012 - Aaron Lindsay\n\n\n");
57
+}
58
+
59
+void video_console_init(void) {
60
+	struct fb_dev *fbdev = fb_first_device();
61
+	int ret;
62
+
63
+	if (!fbdev) {
64
+		print("Error: No framebuffer-capable device registered.");
65
+		return;
66
+	}
67
+
68
+	ret = fbdev->init(&console_fb, 16);
69
+	if (ret) {
70
+		print("Error: Failed to initialize framebuffer device.");
71
+		return;
72
+	}
73
+
74
+	if ((console_init(&console_fb)))
75
+		return;
76
+
77
+	print_register_func(&console_putc);
78
+	print_console_logo();
79
+
80
+	print("Initialized video console on %s.\n", fbdev->name);
81
+}
82
+
83
+void serial_console_init() {
84
+	struct serial_dev *sdev = serial_first_device();
85
+
86
+	if (!sdev)
87
+		return;
88
+
89
+	print_register_func_early(sdev->putc);
90
+	print("Initialized serial console on %s\n", sdev->name);
91
+}
92
+
93
+//Forward declarations of non-initcall initializations that are only needed
94
+//once, and only here
95
+void serial_init();
96
+void kmalloc_init();
97
+
98
+int main(void) {
99
+	char *lower, *upper;
100
+	struct atag *atags;
101
+
102
+	//setup MMU
103
+	mmu_reinit();
104
+
105
+	/* Initialize the serial subsystem before
106
+	 * init_earlyinitcalls(), because console drivers get
107
+	 * initialized here so as to have an output console as
108
+	 * early as possible, and we don't want those
109
+	 * initializations to fail. */
110
+	serial_init();
111
+	init_earlyinitcalls();
112
+	serial_console_init();
113
+
114
+	//setup memory subsystems
115
+	mm_init();
116
+	kmalloc_init();
117
+
118
+	if (atags_first_mem_region(&atags)) {
119
+		print("Error: atags must contain at least one memory region\n");
120
+		return -1;
121
+	}
122
+
123
+	do {
124
+		lower = (char *)atags->data.mem.start;
125
+		upper = lower + atags->data.mem.size - 1;
126
+		print("atags: physical memory at %x-%x\n", lower, upper);
127
+		declare_memory_region(lower, upper);
128
+	} while (!atags_next_mem_region(&atags));
129
+
130
+	init_initcalls();
131
+
132
+	video_console_init();
133
+
134
+	return 0;
135
+}

+ 1 - 2
kernel/kernel.mk

@@ -13,8 +13,7 @@ OBJS_$(d) := $(d)/atags.o \
13 13
 	$(d)/math.o \
14 14
 	$(d)/mm.o \
15 15
 	$(d)/mmu.o \
16
-	$(d)/print.o \
17
-	$(d)/start_kernel.o
16
+	$(d)/print.o
18 17
 
19 18
 KOBJS += $(OBJS_$(d))
20 19
 

+ 0 - 118
kernel/start_kernel.c

@@ -1,118 +0,0 @@
1
-/*
2
-    Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
3
-
4
-    This file is part of Aedrix.
5
-
6
-    This program is free software; you can redistribute it and/or modify
7
-    it under the terms of the GNU General Public License as published by
8
-    the Free Software Foundation; either version 2 of the License, or
9
-    (at your option) any later version.
10
-
11
-    This program is distributed in the hope that it will be useful,
12
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
-    GNU General Public License for more details.
15
-
16
-    You should have received a copy of the GNU General Public License along
17
-    with this program; if not, write to the Free Software Foundation, Inc.,
18
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
- */
20
-
21
-#include <atags.h>
22
-#include <init.h>
23
-#include <kmalloc.h>
24
-#include <mmu.h>
25
-#include <mm.h>
26
-#include <print.h>
27
-#include <framebuffer.h>
28
-#include <console.h>
29
-
30
-#include <drivers/serial.h>
31
-#include <drivers/fb.h>
32
-
33
-struct fb console_fb;
34
-
35
-void print_console_logo() {
36
-	print_func(&console_putc, "                            _            _      _\n");
37
-	print_func(&console_putc, "                           / \\   ___  __| |_ __(_)_  __\n");
38
-	print_func(&console_putc, "                          / _ \\ / _ \\/ _` | '__| \\ \\/ /\n");
39
-	print_func(&console_putc, "                         / ___ \\  __/ (_| | |  | |>  <\n");
40
-	print_func(&console_putc, "                        /_/   \\_\\___|\\__,_|_|  |_/_/\\_\\\n\n");
41
-	print_func(&console_putc, "                        Copyright (C) 2012 - Aaron Lindsay\n\n\n");
42
-}
43
-
44
-void video_console_init(void) {
45
-	struct fb_dev *fbdev = fb_first_device();
46
-	int ret;
47
-
48
-	if (!fbdev) {
49
-		print("Error: No framebuffer-capable device registered.");
50
-		return;
51
-	}
52
-
53
-	ret = fbdev->init(&console_fb, 16);
54
-	if (ret) {
55
-		print("Error: Failed to initialize framebuffer device.");
56
-		return;
57
-	}
58
-
59
-	if ((console_init(&console_fb)))
60
-		return;
61
-
62
-	print_register_func(&console_putc);
63
-	print_console_logo();
64
-
65
-	print_func(&console_putc, "Successfully initialized video console on %s.\n", fbdev->name);
66
-}
67
-
68
-void serial_console_init() {
69
-	struct serial_dev *sdev = serial_first_device();
70
-
71
-	if (!sdev)
72
-		return;
73
-
74
-	print_register_func_early(sdev->putc);
75
-	print("Successfully initialized serial console on %s\n", sdev->name);
76
-}
77
-
78
-void serial_init();
79
-void kmalloc_init();
80
-
81
-int main(void) {
82
-	char *lower, *upper;
83
-	struct atag *atags;
84
-
85
-	//setup MMU
86
-	mmu_reinit();
87
-
88
-	/* Initialize the serial subsystem before
89
-	 * init_earlyinitcalls(), because console drivers get
90
-	 * initialized here so as to have an output console as
91
-	 * early as possible, and we don't want those
92
-	 * initializations to fail. */
93
-	serial_init();
94
-	init_earlyinitcalls();
95
-	serial_console_init();
96
-
97
-	//setup memory
98
-	mm_init();
99
-	kmalloc_init();
100
-
101
-	if (atags_first_mem_region(&atags)) {
102
-		print("Error: atags must contain at least one memory region\n");
103
-		return -1;
104
-	}
105
-
106
-	do {
107
-		lower = (char *)atags->data.mem.start;
108
-		upper = lower + atags->data.mem.size - 1;
109
-		print("atags: physical memory at %x-%x\n", lower, upper);
110
-		declare_memory_region(lower, upper);
111
-	} while (!atags_next_mem_region(&atags));
112
-
113
-	init_initcalls();
114
-
115
-	video_console_init();
116
-
117
-	return 0;
118
-}