Subversion Repositories shark

Rev

Rev 40 | 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;
94 giacomo 101
  char temp[1000];
40 pj 102
  struct multiboot_info *mbi = mbi_address();
103
  char *cmdline = (char *)(mbi->cmdline);
2 pj 104
 
40 pj 105
  if (!(mbi->flags & MB_INFO_MEMORY)) {
106
    cputs("X/Runtime library error!!! Unable to find memory information!\n");
107
    l1_exit(-1);
108
  }
94 giacomo 109
 
40 pj 110
  if (mbi->flags & MB_INFO_CMDLINE) {
111
    /* Build parameter list, up to 100 parms... */
94 giacomo 112
    while (cmdline[i] != 0 && i < 1000) {
113
      temp[i] = cmdline[i];
114
      _argv[_argc] = &(temp[i]);
115
      while (cmdline[i] != ' ' && cmdline[i] != 0 && i < 1000) {
116
        temp[i] = cmdline[i];
117
        i++;
118
      }
40 pj 119
      if (cmdline[i] == ' ') {
94 giacomo 120
        temp[i] = 0; i++; _argc++;
40 pj 121
      }
2 pj 122
    }
94 giacomo 123
    temp[i] = 0;
40 pj 124
    _argc++;
125
  }
126
 
127
  bios_save();
128
  /* Call main procedure using standard C convention   */
129
  /* Remember you cannot call any console I/O function */
130
  /* if you do not call bios_save()            */
94 giacomo 131
 
132
 
2 pj 133
#ifdef __DUMP_MEM__
40 pj 134
  message("X/MEM   : %u\n",mbi->mem_upper);
135
  message("DOS/MEM : %u\n",mbi->mem_lower);
136
  message("x_bios Size : %u\n",sizeof(X_BIOSCALL));
137
  message("mbi Size : %u\n",sizeof(struct multiboot_info));
138
  message("Cmdline : %s\n",mbi->cmdline);
94 giacomo 139
  message("Argc : %u\n",_argc);
140
  message("Argv[0] : %s\n",_argv[0]);
40 pj 141
  message("Argv[1] : %s\n",_argv[1]);
142
  message("Argv[2] : %s\n",_argv[2]);
143
  message("Argv[3] : %s\n",_argv[3]);
2 pj 144
#endif
40 pj 145
  MAIN(_argc,_argv);
146
  bios_restore();
2 pj 147
}