1 #include <aros/kernel.h>
2 #include <aros/multiboot.h>
3 #include <aros/symbolsets.h>
4 #include <exec/execbase.h>
5 #include <exec/resident.h>
6 #include <utility/tagitem.h>
7 #include <proto/arossupport.h>
8 #include <proto/exec.h>
14 #include "hostinterface.h"
15 #include "kernel_base.h"
16 #include "kernel_debug.h"
17 #include "kernel_romtags.h"
18 #include "kernel_mingw32.h"
22 /* Some globals we can't live without */
23 struct HostInterface
*HostIFace
;
24 struct KernelInterface KernelIFace
;
25 static const char *kernel_functions
[];
28 int __startup
startup(struct TagItem
*msg
, ULONG magic
)
30 void *_stack
= AROS_GET_SP
;
35 struct TagItem
*tag
, *tstate
= msg
;
36 struct HostInterface
*hif
= NULL
;
37 struct mb_mmap
*mmap
= NULL
;
38 ULONG memflags
= MEMF_CHIP
|MEMF_PUBLIC
|MEMF_LOCAL
|MEMF_KICK
;
39 UWORD
*ranges
[] = {NULL
, NULL
, (UWORD
*)-1};
41 /* Fail if we are ocassionally started from within AROS command line */
42 if (magic
!= AROS_BOOT_MAGIC
)
45 while ((tag
= LibNextTagItem(&tstate
)))
49 case KRN_KernelLowest
:
50 ranges
[0] = (UWORD
*)tag
->ti_Data
;
53 case KRN_KernelHighest
:
54 ranges
[1] = (UWORD
*)tag
->ti_Data
;
58 mmap
= (struct mb_mmap
*)tag
->ti_Data
;
62 __clear_bss((struct KernelBSS
*)tag
->ti_Data
);
65 case KRN_HostInterface
:
66 hif
= (struct HostInterface
*)tag
->ti_Data
;
71 /* If there's no HostIFace, we can't even say anything */
75 /* Set globals only AFTER __clear_bss() */
79 /* Validate our HostInterface version */
80 if (strcmp(HostIFace
->System
, "Windows"))
82 if (HostIFace
->Version
!= HOSTINTERFACE_VERSION
)
85 /* Now we have debug output, we can bug() */
86 hostlib
= HostIFace
->hostlib_Open("Libs\\Host\\kernel.dll", &errstr
);
89 bug("[Kernel] Failed to load host-side module: %s\n", errstr
);
90 HostIFace
->hostlib_FreeErrorStr(errstr
);
94 for (i
= 0; kernel_functions
[i
]; i
++)
96 void *func
= HostIFace
->hostlib_GetPointer(hostlib
, kernel_functions
[i
], &errstr
);
100 bug("[Kernel] Failed to find symbol %s in host-side module: %s\n", kernel_functions
[i
], errstr
);
101 HostIFace
->hostlib_FreeErrorStr(errstr
);
102 HostIFace
->hostlib_Close(hostlib
, NULL
);
106 ((void **)&KernelIFace
)[i
] = func
;
109 /* Now we have core_alert(), krnDisplayAlert() works */
110 if ((!ranges
[0]) || (!ranges
[1]) || (!mmap
))
112 krnPanic(KernelBase
, "Not enough information from the bootstrap\n"
113 "Kickstart start 0x%p, end 0x%p\n"
114 "Memory map address: 0x%p",
115 ranges
[0], ranges
[1], mmap
);
121 * On x86-64 VirtualAlloc() still seems to return memory within 32-bit region.
122 * The documentation doesn't specify it explicitly, so we make a check, just in case.
123 * Looks like the lowest possible region is returned.
125 if (mmap
->addr
+ mmap
->len
<= 0x80000000)
126 memflags
|= MEMF_31BIT
;
130 * Prepare the first mem header and hand it to PrepareExecBase to take SysBase live
131 * We know that memory map has only one RAM element.
133 D(bug("[Kernel] preparing first mem header\n"));
134 mh
= (struct MemHeader
*)mmap
->addr
;
135 krnCreateMemHeader("Normal RAM", -5, mh
, mmap
->len
, memflags
);
138 * TODO: this needs to be replaced by SysBase address validation.
139 * This will make KickTags and capture vectors working.
143 D(bug("[Kernel] calling krnPrepareExecBase(), mh_First = 0x%p, msg = 0x%p\n", mh
->mh_First
, msg
));
144 if (!krnPrepareExecBase(ranges
, mh
, msg
))
147 D(bug("[Kernel] SysBase=0x%p, mh_First=0x%p\n", SysBase
, mh
->mh_First
);)
150 * ROM memory header. This special memory header covers all ROM code and data sections
151 * so that TypeOfMem() will not return 0 for addresses pointing into the kickstart.
153 krnCreateROMHeader("Kickstart ROM", ranges
[0], ranges
[1]);
156 * Stack memory header. This special memory header covers a little part of the programs
157 * stack so that TypeOfMem() will not return 0 for addresses pointing into the stack
158 * during initialization.
160 krnCreateROMHeader("Boot stack", _stack
- AROS_STACKSIZE
, _stack
);
162 D(bug("[Kernel] calling InitCode(RTF_SINGLETASK,0)\n"));
163 InitCode(RTF_SINGLETASK
, 0);
164 InitCode(RTF_COLDSTART
, 0);
166 krnPanic(KernelBase
, "Failed to start up the system");
167 HostIFace
->hostlib_Close(hostlib
, NULL
);
171 /* Functions we want from Libs/Host/kernel.dll */
172 static const char *kernel_functions
[] =
189 static int Platform_Init(struct KernelBase
*KernelBase
)
193 /* Our VBlank is software-driven, we can ask the user what frequency to use. Default is 50 Hz. */
194 SysBase
->VBlankFrequency
= 50;
196 args
= (char *)LibGetTagData(KRN_CmdLine
, 0, BootMsg
);
199 char *s
= strstr(args
, "vblank=");
202 SysBase
->VBlankFrequency
= atoi(&s
[7]);
205 D(bug("[Kernel] initializing host-side kernel module, timer frequency is %u\n", SysBase
->VBlankFrequency
));
207 *KernelIFace
.TrapVector
= core_TrapHandler
;
208 *KernelIFace
.IRQVector
= core_IRQHandler
;
210 return KernelIFace
.core_init(SysBase
->VBlankFrequency
);
213 ADD2INITLIB(Platform_Init
, 10);