Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / all-mingw32 / bootstrap / bootstrap.c
blob205b4d39a7589664ca166ee54caebac597f524b9
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <strings.h>
4 #include <signal.h>
5 #include <windows.h>
6 #include <sys/stat.h>
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>
19 #include "debug.h"
20 #include "elfloader32.h"
21 #include "hostlib.h"
22 #include "shutdown.h"
23 #include "../kernel/hostinterface.h"
25 #define D(x)
27 static unsigned char __bss_track[32768];
28 struct TagItem km[64];
29 char bootstrapdir[MAX_PATH];
30 char SystemVersion[256];
31 char *bootstrapname;
32 char *cmdline;
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 = {
41 Host_HostLib_Open,
42 Host_HostLib_Close,
43 Host_HostLib_GetPointer,
44 Host_HostLib_FreeErrorStr,
45 Host_HostLib_GetInterface,
46 Host_VKPrintF,
47 Host_PutChar,
48 Host_Shutdown
51 void *SysBase;
53 int main(int argc, char ** argv)
55 char *error;
56 unsigned long BadSyms;
57 struct TagItem *t;
58 int x;
59 struct stat st;
60 int i = 1;
61 unsigned int memSize = 64;
62 char *kernel = "boot\\aros-mingw32";
63 char *KernelArgs = NULL;
64 OSVERSIONINFO winver;
66 GetCurrentDirectory(MAX_PATH, bootstrapdir);
67 bootstrapname = argv[0];
68 cmdline = GetCommandLine();
70 while (i < argc)
72 if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
74 printf
76 "AROS for Windows\n"
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"
81 " (default is 64M)\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"
87 "\n"
88 "Please report bugs to the AROS development team. http://www.aros.org/\n",
89 argv[0]
91 return 0;
93 else if (!strcmp(argv[i], "--memsize") || !strcmp(argv[i], "-m"))
95 i++;
96 x = 0;
97 memSize = 0;
98 while ((argv[i])[x] >= '0' && (argv[i])[x] <= '9')
100 memSize = memSize * 10 + (argv[i])[x] - '0';
101 x++;
103 i++;
105 else if (!strcmp(argv[i], "--kernel") || !strcmp(argv[i], "-k"))
107 kernel = argv[++i];
108 i++;
110 else
111 break;
114 D(printf("[Bootstrap] %ld arguments processed\n", i));
115 D(printf("[Bootstrap] Raw command line: %s\n", cmdline));
116 if (i < argc) {
117 KernelArgs = cmdline;
118 while(isspace(*KernelArgs++));
119 for (x = 0; x < i; x++) {
120 while (!isspace(*KernelArgs++));
121 while (isspace(*KernelArgs))
122 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)) {
132 chdir("..");
135 //load elf-kernel and fill in the bootinfo
136 void * file = fopen(kernel, "rb");
138 if (!file)
140 printf("[Bootstrap] unable to open kernel \"%s\"\n", kernel);
141 return -1;
143 set_base_address(__bss_track, &SysBase);
144 i = load_elf_file(file,0);
145 fclose(file);
146 if (!i) {
147 printf("[Bootstrap] Failed to load kernel \"%s\"\n", kernel);
148 return -1;
150 D(printf("[Bootstrap] allocating working mem: %iMb\n",memSize));
152 size_t memlen = memSize << 20;
153 void * memory = malloc(memlen);
155 if (!memory) {
156 printf("[Bootstrap] Failed to allocate RAM!\n");
157 return -1;
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;
168 tag++;
170 tag->ti_Tag = KRN_MEMUpper;
171 tag->ti_Data = memory + memlen - 1;
172 tag++;
174 tag->ti_Tag = KRN_KernelLowest;
175 tag->ti_Data = kernel_entry_fun;
176 tag++;
178 tag->ti_Tag = KRN_KernelHighest;
179 tag->ti_Data = kernel_highest();
180 tag++;
182 tag->ti_Tag = KRN_KernelBss;
183 tag->ti_Data = (unsigned long)__bss_track;
184 tag++;
186 tag->ti_Tag = KRN_BootLoader;
187 tag->ti_Data = SystemVersion;
188 tag++;
190 tag->ti_Tag = KRN_CmdLine;
191 tag->ti_Data = KernelArgs;
192 tag++;
194 tag->ti_Tag = KRN_HostInterface;
195 tag->ti_Data = &HostIFace;
196 tag++;
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);