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
];
33 typedef int (*kernel_entry_fun_t
)(struct TagItem
*);
35 #define BASE_ALIGNMENT 16
38 * Some helpful functions that link us to the underlying host OS.
39 * Without them we would not be able to estabilish any interaction with it.
41 struct HostInterface HostIFace
= {
44 Host_HostLib_GetPointer
,
45 Host_HostLib_FreeErrorStr
,
46 Host_HostLib_GetInterface
,
54 int main(int argc
, char ** argv
)
57 unsigned long BadSyms
;
61 char _use_hostmem
= 0;
63 unsigned int memSize
= 64;
64 char *kernel
= "boot\\aros-mingw32";
65 char *KernelArgs
= NULL
;
67 GetCurrentDirectory(MAX_PATH
, bootstrapdir
);
68 bootstrapname
= argv
[0];
69 cmdline
= GetCommandLine();
73 if (!strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h"))
78 "usage: %s [options] [kernel arguments]\n"
79 "Availible options:\n"
80 " -h show this page\n"
81 " -m <size> allocate <size> Megabytes of memory for AROS\n"
83 " -k <file> use <file> as a kernel\n"
84 " (default is boot\\aros-mingw32)\n"
85 " --help same as '-h'\n"
86 " --memsize <size> same as '-m <size>'\n"
87 " --kernel <file> same as '-k'\n"
88 " --hostmem Let AROS use the host operating system's facilities to\n"
91 "Please report bugs to the AROS development team. http://www.aros.org/\n",
96 else if (!strcmp(argv
[i
], "--memsize") || !strcmp(argv
[i
], "-m"))
101 while ((argv
[i
])[x
] >= '0' && (argv
[i
])[x
] <= '9')
103 memSize
= memSize
* 10 + (argv
[i
])[x
] - '0';
108 else if (!strcmp(argv
[i
], "--kernel") || !strcmp(argv
[i
], "-k"))
113 else if (!strcmp(argv
[i
], "--hostmem"))
122 D(printf("[Bootstrap] %ld arguments processed\n", i
));
123 D(printf("[Bootstrap] Raw command line: %s\n", cmdline
));
125 KernelArgs
= cmdline
;
126 while(isspace(*KernelArgs
++));
127 for (x
= 0; x
< i
; x
++) {
128 while (!isspace(*KernelArgs
++));
129 while (isspace(*KernelArgs
))
133 D(printf("[Bootstrap] Kernel arguments: %s\n", KernelArgs
));
135 if (!stat("..\\AROS.boot", &st
)) {
139 D(printf("[Bootstrap] allocating working mem: %iMb\n",memSize
));
141 void * memory
= malloc((memSize
<< 20));
143 //fill in kernel message related to allocated ram regions
144 struct TagItem
*tag
= km
;
146 tag
->ti_Tag
= KRN_KernelBss
;
147 tag
->ti_Data
= (unsigned long)__bss_track
;
150 /* FIXME: These tags should point to a memory map in PC BIOS format, not to memory itself.
151 This is a temporary solution because hosted kernel should translate all AllocMem() requests
152 to host's allocation requests. In future a full-featured memory map will be implemented in order
153 to support loadable modules. */
154 tag
->ti_Tag
= KRN_MMAPAddress
;
155 tag
->ti_Data
= (unsigned long)memory
;
158 tag
->ti_Tag
= KRN_MMAPLength
;
159 tag
->ti_Data
= (unsigned long)(memSize
<< 20);
162 //load elf-kernel and fill in the bootinfo
163 void * file
= fopen(kernel
, "rb");
167 fseek(file
,0,SEEK_END
);
169 ksize
+= BASE_ALIGNMENT
- ksize
% BASE_ALIGNMENT
;
170 printf("[Bootstrap] opened \"%s\"(%p) size:%p\n", kernel
, file
, ksize
);
171 fseek(file
,0,SEEK_SET
);
173 printf("[Bootstrap] unable to open kernel \"%s\"\n", kernel
);
176 unsigned int bufsize
= 10*ksize
;
177 void * buf
= malloc(bufsize
);
178 void * base
= buf
+ ksize
;
179 printf("[Bootstrap] memory allocated: %p-%p kernelBase: %p\n",buf
,buf
+bufsize
,base
);
180 set_base_address(base
, __bss_track
, &SysBase
);
181 load_elf_file(file
,0);
182 kernel_entry_fun_t kernel_entry_fun
= (kernel_entry_fun_t
)base
;
184 tag
->ti_Tag
= KRN_KernelLowest
;
185 tag
->ti_Data
= (unsigned long)kernel_lowest();
188 tag
->ti_Tag
= KRN_KernelHighest
;
189 tag
->ti_Data
= (unsigned long)kernel_highest();
192 tag
->ti_Tag
= KRN_CmdLine
;
193 tag
->ti_Data
= KernelArgs
;
196 tag
->ti_Tag
= KRN_HostInterface
;
197 tag
->ti_Data
= &HostIFace
;
200 tag
->ti_Tag
= TAG_DONE
;
202 printf("[Bootstrap] entering kernel@%p...\n",kernel_entry_fun
);
203 int retval
= kernel_entry_fun(km
);
205 printf("kernel returned %i\n",retval
);