Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/boot2/Symbols.c

Source at commit 655 created 13 years 4 months ago.
By meklort, Modules update. removed hardcoding for dyld_stub_bunder in modules.c Added a subset of klibc for a more complete c library implimentation. Added a subset of uclibc++ for an initial c++ implimentation. Note: cout / cin / file io has been disabled. Also note that exceptions and rtti is disabled. Modified the helow world code foa small c++ test.
1/*
2 * Symbols.c
3 *
4 * Module loader support module. This module is the first module to ever be loaded.
5 * It contains a copy of each symbol inside ov the current version of chameleon as well
6 * as a strcmp function. Chameleon calls lookup_symbol to resolve internal symbols
7 * when they are requested by a module. This module does *not* depend on any intenrla
8 * symbols, as such it can be loaded without a symbol table initialized.
9 *
10 * Copyright (c) 2009 Evan Lojewski. All rights reserved.
11 */
12
13#include "Symbols.h"
14
15static int strcmp(const char * s1, const char * s2);
16
17void Symbols_start()
18{
19}
20
21unsigned int lookup_symbol(const char* symbol)
22{
23if(strcmp(symbol, "dyld_stub_binder") == 0) return lookup_symbol("_dyld_stub_binder");// ugly hack
24
25int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;
26int lowerLimit = 0;
27int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
28int result;
29
30while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)
31{
32if(result > 0)// We need to search a HIGHER index
33{
34if(compareIndex != lowerLimit)
35{
36lowerLimit = compareIndex;
37}
38else
39{
40return 0xFFFFFFFF;// Symbol not found
41}
42compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
43}
44else // We Need to search a LOWER index
45{
46if(compareIndex != upperLimit)
47{
48upperLimit = compareIndex;
49}
50else
51{
52return 0xFFFFFFFF;// Symbol not found
53}
54compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
55}
56}
57return symbolList[compareIndex].addr;
58}
59
60/*
61 * strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point
62 */
63static int strcmp(const char * s1, const char * s2)
64{
65while (*s1 && (*s1 == *s2)) {
66s1++;
67s2++;
68}
69return (*s1 - *s2);
70}
71
72
73
74

Archive Download this file

Revision: 655