Rev 40 | Go to most recent revision | Details | Compare with Previous | 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 | |||
40 | pj | 66 | DWORD _stkbase; |
2 | pj | 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 | |||
40 | pj | 75 | #ifndef MAIN |
76 | #define MAIN main |
||
77 | #endif |
||
78 | |||
79 | extern void MAIN(int argc,char *argv[]); |
||
2 | pj | 80 | extern void bios_save(void); |
81 | extern void bios_restore(void); |
||
82 | |||
83 | /* This is used in GNU-C to implement C++ constructors/destructors */ |
||
84 | /* See the lib sources for more details */ |
||
85 | void __main(int argc, char **argv) |
||
86 | { |
||
87 | } |
||
88 | |||
89 | |||
40 | pj | 90 | struct multiboot_info * mbi_address(void) |
2 | pj | 91 | { |
40 | pj | 92 | /* This is declared in [wc32/gnu]\x0.[asm/s] */ |
93 | extern struct multiboot_info *mbi; |
||
2 | pj | 94 | |
40 | pj | 95 | return (mbi); |
2 | pj | 96 | } |
97 | |||
98 | void _startup(void) |
||
99 | { |
||
40 | pj | 100 | register int i = 0; |
101 | struct multiboot_info *mbi = mbi_address(); |
||
102 | char *cmdline = (char *)(mbi->cmdline); |
||
2 | pj | 103 | |
40 | pj | 104 | if (!(mbi->flags & MB_INFO_MEMORY)) { |
105 | cputs("X/Runtime library error!!! Unable to find memory information!\n"); |
||
106 | l1_exit(-1); |
||
107 | } |
||
108 | |||
109 | if (mbi->flags & MB_INFO_CMDLINE) { |
||
110 | /* Build parameter list, up to 100 parms... */ |
||
111 | while (cmdline[i] != 0) { |
||
112 | _argv[_argc] = &(cmdline[i]); |
||
113 | while (cmdline[i] != ' ' && cmdline[i] != 0) i++; |
||
114 | if (cmdline[i] == ' ') { |
||
115 | cmdline[i] = 0; i++; _argc++; |
||
116 | } |
||
2 | pj | 117 | } |
40 | pj | 118 | _argc++; |
119 | } |
||
120 | |||
121 | bios_save(); |
||
122 | /* Call main procedure using standard C convention */ |
||
123 | /* Remember you cannot call any console I/O function */ |
||
124 | /* if you do not call bios_save() */ |
||
125 | |||
2 | pj | 126 | #ifdef __DUMP_MEM__ |
40 | pj | 127 | message("X/MEM : %u\n",mbi->mem_upper); |
128 | message("DOS/MEM : %u\n",mbi->mem_lower); |
||
129 | message("x_bios Size : %u\n",sizeof(X_BIOSCALL)); |
||
130 | message("mbi Size : %u\n",sizeof(struct multiboot_info)); |
||
131 | message("Cmdline : %s\n",mbi->cmdline); |
||
132 | message("Argc : %u",_argc); |
||
133 | message("Argv[0] : %s / %s\n",_argv[0]); |
||
134 | message("Argv[1] : %s\n",_argv[1]); |
||
135 | message("Argv[2] : %s\n",_argv[2]); |
||
136 | message("Argv[3] : %s\n",_argv[3]); |
||
2 | pj | 137 | #endif |
40 | pj | 138 | MAIN(_argc,_argv); |
139 | bios_restore(); |
||
2 | pj | 140 | } |