File: kernel.c

package info (click to toggle)
plex86 0.0.20011018-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,868 kB
  • ctags: 8,721
  • sloc: ansic: 46,915; cpp: 17,817; xml: 1,283; makefile: 1,130; sh: 451; asm: 360; csh: 18
file content (156 lines) | stat: -rw-r--r-- 4,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 *  plex86: run multiple x86 operating systems concurrently
 *  Copyright (C) 1999-2000  The plex86 developers team
 *
 *  elf.c: load an ELF kernel image into VM memory
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#include "bios.h"
#include "multiboot.h"


plugin_t *bios_plugin;


  int
plugin_init(plugin_t *plugin, int argc, char *argv[])
{
  char *address_p, *filename_p, *stack_p, *hack_p, *rd_p;
  Bit32u address, stack;
  Bit32u rd_address, rd_size;

  unsigned i;
unsigned hack_linux;

#define FILE_PARAM    "file="
#define ADDRESS_PARAM "address="
#define STACK_PARAM   "stack="
#define HACK_PARAM    "hack="
#define RD_PARAM      "rd="

  bios_plugin = plugin;

  /* Get the file= parameter */
  i = 0;
  if ( !argv[i] || strncmp(argv[i], FILE_PARAM, strlen(FILE_PARAM)) )
    goto usage;
  filename_p = &argv[i][strlen(FILE_PARAM)];
  i++;

  /********************************/
  /* Get the [address=] parameter */
  /********************************/
  if ( !argv[i] || strncmp(argv[i], ADDRESS_PARAM, strlen(ADDRESS_PARAM)) ) {
    address = -1; /* not given, assign max val as flag */
    }
  else {
    address_p  = &argv[i][strlen(ADDRESS_PARAM)];
    address = strtoul(address_p, NULL, 0);
    i++;
    }

  /******************************/
  /* Get the [stack=] parameter */
  /******************************/
  if ( !argv[i] || strncmp(argv[i], STACK_PARAM, strlen(STACK_PARAM)) )
    goto usage;
  stack_p  = &argv[i][strlen(STACK_PARAM)];
  stack   = strtoul(stack_p, NULL, 0);
  i++;

  /***************************************/
  /* Get the [rd=address:path] parameter */
  /***************************************/
  if ( (i>=argc) || !argv[i] || strncmp(argv[i], RD_PARAM, strlen(RD_PARAM)) )
    {
    rd_address = 0xffffffff;
    rd_size = 0;
    }
  else {
    char *endptr;

    rd_p  = &argv[i][strlen(RD_PARAM)];
    rd_address = strtoul(rd_p, &endptr, 0);
    if (*endptr==':') {
      endptr++;
      rd_size = image_load(endptr, rd_address);
      if (rd_size==0) {
        fprintf(stderr, "loading of rd image '%s' failed.\n", endptr);
        return 1;
        }
      }
    else {
      fprintf(stderr, "format of rd= parameter incorrect\n");
      return 1;
      }
    i++;
    }

  /*******************************/
  /* Get the [hack=os] parameter */
  /*******************************/
hack_linux = 0;
  if ( (i>=argc) || !argv[i] || strncmp(argv[i], HACK_PARAM, strlen(HACK_PARAM)) )
    {
    }
  else {
    hack_p  = &argv[i][strlen(HACK_PARAM)];
    if ( !strcmp(hack_p, "linux") ) {
      load_linux_setup_params(rd_address, rd_size);
      if (linux_hack()) {
        fprintf(stderr, "linux_hack returns error.\n");
        return 1;
        }
hack_linux = 1;
      }
    else {
      fprintf(stderr, "'hack=' parameter, unrecognized OS.\n");
      return 1;
      }
    i++;
    }

  vm_conf.stack_address = stack;

  if (bin_load(filename_p, address)) {
    fprintf(stderr, "loading of kernel '%s' failed.\n", filename_p);
    return 1;
    }

  bin_context(hack_linux);

  return 0;

usage:
  fprintf(stderr, "usage: plugin-elf file=path [address=num] stack=num\n");
  return 1;
}


void
plugin_fini(void)
{
    return;
}