xref: /haiku/src/system/boot/platform/atari_m68k/start.cpp (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
1 /*
2  * Copyright 2008-2010, François Revol, revol@free.fr. All rights reserved.
3  * Copyright 2003-2010, Axel Dörfler, axeld@pinc-software.de.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include <KernelExport.h>
9 #include <boot/platform.h>
10 #include <boot/heap.h>
11 #include <boot/stage2.h>
12 #include <arch/cpu.h>
13 
14 #include <string.h>
15 
16 #include "console.h"
17 #include "cpu.h"
18 #include "mmu.h"
19 #include "keyboard.h"
20 #include "toscalls.h"
21 
22 
23 #define HEAP_SIZE 65536
24 
25 // GCC defined globals
26 extern void (*__ctor_list)(void);
27 extern void (*__ctor_end)(void);
28 extern uint8 __bss_start;
29 extern uint8 _end;
30 
31 extern "C" int main(stage2_args *args);
32 extern "C" void _start(void);
33 
34 
35 static uint32 sBootOptions;
36 
37 
38 static void
39 clear_bss(void)
40 {
41 	memset(&__bss_start, 0, &_end - &__bss_start);
42 }
43 
44 
45 static void
46 call_ctors(void)
47 {
48 	void (**f)(void);
49 
50 	for (f = &__ctor_list; f < &__ctor_end; f++) {
51 		(**f)();
52 	}
53 }
54 
55 
56 extern "C" uint32
57 platform_boot_options(void)
58 {
59 #if 0
60 	if (!gKernelArgs.fb.enabled)
61 		sBootOptions |= check_for_boot_keys();
62 #endif
63 	return sBootOptions;
64 }
65 
66 
67 extern "C" void
68 platform_start_kernel(void)
69 {
70 	static struct kernel_args *args = &gKernelArgs;
71 		// something goes wrong when we pass &gKernelArgs directly
72 		// to the assembler inline below - might be a bug in GCC
73 		// or I don't see something important...
74 	addr_t stackTop
75 		= gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size;
76 
77 	//smp_init_other_cpus();
78 	//serial_cleanup();
79 	mmu_init_for_kernel();
80 	//smp_boot_other_cpus();
81 
82 #warning M68K: stop ints
83 
84 	dprintf("kernel entry at %lx\n",
85 		gKernelArgs.kernel_image.elf_header.e_entry);
86 
87 	asm volatile (
88 		"move.l	%0,%%sp;	"			// move stack out of way
89 		: : "m" (stackTop));
90 
91 	asm volatile (
92 		"or	#0x0700,%%sr; " : : );		// disable interrupts
93 
94 	asm volatile (
95 		"move.l  #0x0,-(%%sp); "		// we're the BSP cpu (0)
96 		"move.l 	%0,-(%%sp);	"		// kernel args
97 		"move.l 	#0x0,-(%%sp);"		// dummy retval for call to main
98 		"move.l 	%1,-(%%sp);	"		// this is the start address
99 		"rts;		"					// jump.
100 		: : "g" (args), "g" (gKernelArgs.kernel_image.elf_header.e_entry));
101 
102 	// Huston, we have a problem!
103 
104 	asm volatile (
105 		"and	#0xf8ff,%%sr; " : : );		// reenable interrupts
106 
107 	panic("kernel returned!\n");
108 
109 }
110 
111 
112 extern "C" void
113 platform_exit(void)
114 {
115 	// Terminate if running under ARAnyM
116 	int32 nfShutdownId = nat_feat_getid("NF_SHUTDOWN");
117 	if (nfShutdownId)
118 		nat_feat_call(nfShutdownId, 0);
119 
120 	// This crashes...
121 	// TODO: Puntaes() instead ?
122 	Pterm0();
123 }
124 
125 
126 extern "C" void
127 _start(void)
128 {
129 	stage2_args args;
130 	Bconout(DEV_CON, 'H');
131 
132 	//asm("cld");			// Ain't nothing but a GCC thang.
133 	//asm("fninit");		// initialize floating point unit
134 
135 	clear_bss();
136 	Bconout(DEV_CON, 'A');
137 	call_ctors();
138 		// call C++ constructors before doing anything else
139 	Bconout(DEV_CON, 'I');
140 
141 	args.heap_size = HEAP_SIZE;
142 	args.arguments = NULL;
143 
144 	// so we can dprintf
145 	init_nat_features();
146 
147 	//serial_init();
148 	Bconout(DEV_CON, 'K');
149 	console_init();
150 	Bconout(DEV_CON, 'U');
151 	Bconout(DEV_CON, '\n');
152 	dprintf("membot   = %p\n", (void*)*TOSVAR_membot);
153 	dprintf("memtop   = %p\n", (void*)*TOSVAR_memtop);
154 	dprintf("v_bas_ad = %p\n", *TOSVAR_v_bas_ad);
155 	dprintf("phystop  = %p\n", (void*)*TOSVARphystop);
156 	dprintf("ramtop   = %p\n", (void*)*TOSVARramtop);
157 	cpu_init();
158 	mmu_init();
159 
160 	// wait a bit to give the user the opportunity to press a key
161 	spin(750000);
162 
163 	// reading the keyboard doesn't seem to work in graphics mode (maybe a bochs problem)
164 	sBootOptions = check_for_boot_keys();
165 	//if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT)
166 		//serial_enable();
167 
168 	//apm_init();
169 	//smp_init();
170 	main(&args);
171 }
172