Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | /* File: X1.C */ |
||
23 | /* Startup code: */ |
||
24 | /* Build parameters list & make info accessible */ |
||
25 | |||
26 | #include <ll/i386/hw-func.h> |
||
27 | #include <ll/stdlib.h> |
||
28 | #include <ll/i386/cons.h> |
||
29 | #include <ll/i386/mb-info.h> |
||
30 | |||
31 | #include <ll/i386/mem.h> |
||
32 | |||
33 | FILE(X1); |
||
34 | |||
35 | /* #define __DUMP_MEM__ */ |
||
36 | |||
37 | /* We need to copy from X address space to the application space */ |
||
38 | /* the info structure to allow pointer access using flat model */ |
||
39 | /* Remember that flat model is similar to small model also if we */ |
||
40 | /* can see the whole memory, because it has no explicit far */ |
||
41 | /* pointers; then if we pass into _args[] the address of the */ |
||
42 | /* string of the n-th argument it could not be correctly accessed */ |
||
43 | /* because it lies in a memory zone unseen from PM application. */ |
||
44 | /* This is due to the ELF format which has no relocation info */ |
||
45 | /* since the file is already relocated starting from address 0! */ |
||
46 | /* Then the PM application cannot see a real flat memory (segment */ |
||
47 | /* with 0 base) but CS,DS & SS MUST have the base correctly set. */ |
||
48 | /* Refer to this figure: */ |
||
49 | /* */ |
||
50 | /* DOS Memory <- X is there */ |
||
51 | /* */ |
||
52 | /* EXTENDED Memory -----[ */ |
||
53 | /* [ */ |
||
54 | /* Address xxxx [ <- Application code is here! */ |
||
55 | /* [ */ |
||
56 | /* Address yyyy [ <- Application Data & Stack! */ |
||
57 | /* */ |
||
58 | /* Then CS has xxxx base while DS & SS have yyyy base! */ |
||
59 | |||
60 | /* Stack base address; use this to check stack overflow! */ |
||
61 | /* With Flat model I do not think we can use 386 protection */ |
||
62 | /* to detect a stack overflow; anyway Watcom C use a standard */ |
||
63 | /* function __CHK to detect it! The compiler place it whenever */ |
||
64 | /* it calls a function to detect overflow */ |
||
65 | |||
66 | DWORD _stkbase; |
||
67 | DWORD _stktop; |
||
68 | |||
69 | /* This is some extra stuff we need to compile with argument */ |
||
70 | /* passing and math extensions */ |
||
71 | DWORD _argc = 0; |
||
72 | typedef char *charp; |
||
73 | charp _argv[100]; |
||
74 | |||
75 | extern void main(int argc, char *argv[]); |
||
76 | extern void bios_save(void); |
||
77 | extern void bios_restore(void); |
||
78 | |||
79 | /* This is used in GNU-C to implement C++ constructors/destructors */ |
||
80 | /* See the lib sources for more details */ |
||
81 | void __main(int argc, char **argv) |
||
82 | { |
||
83 | } |
||
84 | |||
85 | |||
86 | struct multiboot_info *mbi_address(void) |
||
87 | { |
||
88 | /* This is declared in [wc32/gnu]\x0.[asm/s] */ |
||
89 | extern struct multiboot_info *mbi; |
||
90 | |||
91 | return (mbi); |
||
92 | } |
||
93 | |||
94 | #ifndef __NOH4__ |
||
95 | |||
96 | void __kernel_init__(struct multiboot_info *m); |
||
97 | |||
98 | void _startup(void) |
||
99 | { |
||
100 | struct multiboot_info *mbi = mbi_address(); |
||
101 | |||
102 | bios_save(); |
||
103 | |||
104 | /* Call init procedure using standard C convention */ |
||
105 | /* Remember you cannot call any console I/O function */ |
||
106 | /* if you do not call bios_save() */ |
||
107 | |||
108 | #ifdef __DUMP_MEM__ |
||
109 | message("X/MEM : %u\n", mbi->mem_upper); |
||
110 | message("DOS/MEM : %u\n", mbi->mem_lower); |
||
111 | message("x_bios Size : %u\n", sizeof(X_BIOSCALL)); |
||
112 | message("mbi Size : %u\n", sizeof(struct multiboot_info)); |
||
113 | message("Cmdline : %s\n", mbi->cmdline); |
||
114 | /* message("Argc : %u",_argc); |
||
115 | message("Argv[0] : %s / %s\n",_argv[0]); |
||
116 | message("Argv[1] : %s\n",_argv[1]); |
||
117 | message("Argv[2] : %s\n",_argv[2]); |
||
118 | message("Argv[3] : %s\n",_argv[3]); */ |
||
119 | #endif |
||
120 | |||
121 | __kernel_init__(mbi); |
||
122 | |||
123 | bios_restore(); |
||
124 | } |
||
125 | |||
126 | #else |
||
127 | void _startup(void) |
||
128 | { |
||
129 | register int i = 0; |
||
130 | struct multiboot_info *mbi = mbi_address(); |
||
131 | char *cmdline = (char *) (mbi->cmdline); |
||
132 | |||
133 | if (!(mbi->flags & MB_INFO_MEMORY)) { |
||
134 | cputs |
||
135 | ("X/Runtime library error!!! Unable to find memory information!\n"); |
||
136 | l1_exit(-1); |
||
137 | } |
||
138 | |||
139 | if (mbi->flags & MB_INFO_CMDLINE) { |
||
140 | /* Build parameter list, up to 100 parms... */ |
||
141 | while (cmdline[i] != 0) { |
||
142 | _argv[_argc] = &(cmdline[i]); |
||
143 | while (cmdline[i] != ' ' && cmdline[i] != 0) |
||
144 | i++; |
||
145 | if (cmdline[i] == ' ') { |
||
146 | cmdline[i] = 0; |
||
147 | i++; |
||
148 | _argc++; |
||
149 | } |
||
150 | } |
||
151 | _argc++; |
||
152 | } |
||
153 | |||
154 | bios_save(); |
||
155 | /* Call main procedure using standard C convention */ |
||
156 | /* Remember you cannot call any console I/O function */ |
||
157 | /* if you do not call bios_save() */ |
||
158 | |||
159 | #ifdef __DUMP_MEM__ |
||
160 | message("X/MEM : %u\n", mbi->mem_upper); |
||
161 | message("DOS/MEM : %u\n", mbi->mem_lower); |
||
162 | message("x_bios Size : %u\n", sizeof(X_BIOSCALL)); |
||
163 | message("mbi Size : %u\n", sizeof(struct multiboot_info)); |
||
164 | message("Cmdline : %s\n", mbi->cmdline); |
||
165 | message("Argc : %u", _argc); |
||
166 | message("Argv[0] : %s / %s\n", _argv[0]); |
||
167 | message("Argv[1] : %s\n", _argv[1]); |
||
168 | message("Argv[2] : %s\n", _argv[2]); |
||
169 | message("Argv[3] : %s\n", _argv[3]); |
||
170 | #endif |
||
171 | main(_argc, _argv); |
||
172 | bios_restore(); |
||
173 | } |
||
174 | |||
175 | #endif |