7 #include <aros/system.h>
9 #define __typedef_LONG /* LONG, ULONG, WORD, BYTE and BOOL are declared in Windows headers. Looks like everything */
10 #define __typedef_WORD /* is the same except BOOL. It's defined to short on AROS and to int on Windows. This means */
11 #define __typedef_BYTE /* that you can't use it in OS-native part of the code and can't use any AROS structure */
12 #define __typedef_BOOL /* definition that contains BOOL. */
13 typedef unsigned AROS_16BIT_TYPE UWORD
;
14 typedef unsigned char UBYTE
;
16 #include <aros/kernel.h>
17 #include <utility/tagitem.h>
20 #include "elfloader32.h"
23 #include "../kernel/hostinterface.h"
27 static unsigned char __bss_track
[32768];
28 struct TagItem km
[64];
29 char bootstrapdir
[MAX_PATH
];
30 char SystemVersion
[256];
34 typedef int (*kernel_entry_fun_t
)(struct TagItem
*);
37 * Some helpful functions that link us to the underlying host OS.
38 * Without them we would not be able to estabilish any interaction with it.
40 struct HostInterface HostIFace
= {
43 Host_HostLib_GetPointer
,
44 Host_HostLib_FreeErrorStr
,
45 Host_HostLib_GetInterface
,
53 int main(int argc
, char ** argv
)
56 unsigned long BadSyms
;
61 unsigned int memSize
= 64;
62 char *kernel
= "boot\\aros-mingw32";
63 char *KernelArgs
= NULL
;
66 GetCurrentDirectory(MAX_PATH
, bootstrapdir
);
67 bootstrapname
= argv
[0];
68 cmdline
= GetCommandLine();
72 if (!strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h"))
77 "usage: %s [options] [kernel arguments]\n"
78 "Availible options:\n"
79 " -h show this page\n"
80 " -m <size> allocate <size> Megabytes of memory for AROS\n"
82 " -k <file> use <file> as a kernel\n"
83 " (default is boot\\aros-mingw32)\n"
84 " --help same as '-h'\n"
85 " --memsize <size> same as '-m <size>'\n"
86 " --kernel <file> same as '-k'\n"
88 "Please report bugs to the AROS development team. http://www.aros.org/\n",
93 else if (!strcmp(argv
[i
], "--memsize") || !strcmp(argv
[i
], "-m"))
98 while ((argv
[i
])[x
] >= '0' && (argv
[i
])[x
] <= '9')
100 memSize
= memSize
* 10 + (argv
[i
])[x
] - '0';
105 else if (!strcmp(argv
[i
], "--kernel") || !strcmp(argv
[i
], "-k"))
114 D(printf("[Bootstrap] %ld arguments processed\n", i
));
115 D(printf("[Bootstrap] Raw command line: %s\n", cmdline
));
117 KernelArgs
= cmdline
;
118 while(isspace(*KernelArgs
++));
119 for (x
= 0; x
< i
; x
++) {
120 while (!isspace(*KernelArgs
++));
121 while (isspace(*KernelArgs
))
125 D(printf("[Bootstrap] Kernel arguments: %s\n", KernelArgs
));
126 winver
.dwOSVersionInfoSize
= sizeof(winver
);
127 GetVersionEx(&winver
);
128 sprintf(SystemVersion
, "Windows %lu.%lu build %lu %s", winver
.dwMajorVersion
, winver
.dwMinorVersion
, winver
.dwBuildNumber
, winver
.szCSDVersion
);
129 D(printf("[Bootstrap] OS version: %s\n", SystemVersion
));
131 if (!stat("..\\AROS.boot", &st
)) {
135 //load elf-kernel and fill in the bootinfo
136 void * file
= fopen(kernel
, "rb");
140 printf("[Bootstrap] unable to open kernel \"%s\"\n", kernel
);
143 set_base_address(__bss_track
, &SysBase
);
144 i
= load_elf_file(file
,0);
147 printf("[Bootstrap] Failed to load kernel \"%s\"\n", kernel
);
150 D(printf("[Bootstrap] allocating working mem: %iMb\n",memSize
));
152 size_t memlen
= memSize
<< 20;
153 void * memory
= malloc(memlen
);
156 printf("[Bootstrap] Failed to allocate RAM!\n");
159 D(printf("[Bootstrap] RAM memory allocated: %p-%p (%lu bytes)\n", memory
, memory
+ memlen
, memlen
));
161 kernel_entry_fun_t kernel_entry_fun
= kernel_lowest();
163 //fill in kernel message
164 struct TagItem
*tag
= km
;
166 tag
->ti_Tag
= KRN_MEMLower
;
167 tag
->ti_Data
= (unsigned long)memory
;
170 tag
->ti_Tag
= KRN_MEMUpper
;
171 tag
->ti_Data
= memory
+ memlen
- 1;
174 tag
->ti_Tag
= KRN_KernelLowest
;
175 tag
->ti_Data
= kernel_entry_fun
;
178 tag
->ti_Tag
= KRN_KernelHighest
;
179 tag
->ti_Data
= kernel_highest();
182 tag
->ti_Tag
= KRN_KernelBss
;
183 tag
->ti_Data
= (unsigned long)__bss_track
;
186 tag
->ti_Tag
= KRN_BootLoader
;
187 tag
->ti_Data
= SystemVersion
;
190 tag
->ti_Tag
= KRN_CmdLine
;
191 tag
->ti_Data
= KernelArgs
;
194 tag
->ti_Tag
= KRN_HostInterface
;
195 tag
->ti_Data
= &HostIFace
;
198 tag
->ti_Tag
= TAG_DONE
;
200 printf("[Bootstrap] entering kernel@%p...\n",kernel_entry_fun
);
201 int retval
= kernel_entry_fun(km
);
203 printf("kernel returned %i\n",retval
);