Subversion Repositories shark

Rev

Rev 1683 | 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
 
1621 fabio 26
#include <arch/stdlib.h>
2 pj 27
#include <ll/i386/hw-func.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
 
1688 fabio 75
extern void __kernel_init__(int argc, char *argv[]);
2 pj 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
 
40 pj 86
struct multiboot_info * mbi_address(void)
2 pj 87
{
40 pj 88
  /* This is declared in [wc32/gnu]\x0.[asm/s] */
89
  extern struct multiboot_info *mbi;
2 pj 90
 
40 pj 91
  return (mbi);
2 pj 92
}
93
 
94
void _startup(void)
95
{
40 pj 96
  register int i = 0;
94 giacomo 97
  char temp[1000];
40 pj 98
  struct multiboot_info *mbi = mbi_address();
99
  char *cmdline = (char *)(mbi->cmdline);
2 pj 100
 
40 pj 101
  if (!(mbi->flags & MB_INFO_MEMORY)) {
102
    cputs("X/Runtime library error!!! Unable to find memory information!\n");
103
    l1_exit(-1);
104
  }
94 giacomo 105
 
40 pj 106
  if (mbi->flags & MB_INFO_CMDLINE) {
107
    /* Build parameter list, up to 100 parms... */
94 giacomo 108
    while (cmdline[i] != 0 && i < 1000) {
109
      temp[i] = cmdline[i];
110
      _argv[_argc] = &(temp[i]);
111
      while (cmdline[i] != ' ' && cmdline[i] != 0 && i < 1000) {
112
        temp[i] = cmdline[i];
113
        i++;
114
      }
40 pj 115
      if (cmdline[i] == ' ') {
94 giacomo 116
        temp[i] = 0; i++; _argc++;
40 pj 117
      }
2 pj 118
    }
94 giacomo 119
    temp[i] = 0;
40 pj 120
    _argc++;
121
  }
122
 
123
  bios_save();
124
  /* Call main procedure using standard C convention   */
125
  /* Remember you cannot call any console I/O function */
126
  /* if you do not call bios_save()            */
94 giacomo 127
 
128
 
2 pj 129
#ifdef __DUMP_MEM__
40 pj 130
  message("X/MEM   : %u\n",mbi->mem_upper);
131
  message("DOS/MEM : %u\n",mbi->mem_lower);
132
  message("x_bios Size : %u\n",sizeof(X_BIOSCALL));
133
  message("mbi Size : %u\n",sizeof(struct multiboot_info));
134
  message("Cmdline : %s\n",mbi->cmdline);
94 giacomo 135
  message("Argc : %u\n",_argc);
136
  message("Argv[0] : %s\n",_argv[0]);
40 pj 137
  message("Argv[1] : %s\n",_argv[1]);
138
  message("Argv[2] : %s\n",_argv[2]);
139
  message("Argv[3] : %s\n",_argv[3]);
2 pj 140
#endif
1688 fabio 141
  __kernel_init__(_argc,_argv);
40 pj 142
  bios_restore();
2 pj 143
}