Chameleon

Chameleon Svn Source Tree

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

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 internal
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// load_dependency("Symbols", 300);
20//verbose("Symbols_start\n");
21}
22
23unsigned int lookup_symbol(const char* symbol)
24{
25if(strcmp(symbol, "dyld_stub_binder") == 0) return lookup_symbol("_dyld_stub_binder");// ugly hack
26
27int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;
28int lowerLimit = 0;
29int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
30int result;
31
32while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)
33{
34if(result > 0)// We need to search a HIGHER index
35{
36if(compareIndex != lowerLimit)
37{
38lowerLimit = compareIndex;
39}
40else
41{
42return 0xFFFFFFFF;// Symbol not found
43}
44compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
45}
46else // We Need to search a LOWER index
47{
48if(compareIndex != upperLimit)
49{
50upperLimit = compareIndex;
51}
52else
53{
54return 0xFFFFFFFF;// Symbol not found
55}
56compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
57}
58}
59return symbolList[compareIndex].addr;
60}
61
62/*
63 * strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point
64 */
65static int strcmp(const char * s1, const char * s2)
66{
67while (*s1 && (*s1 == *s2)) {
68s1++;
69s2++;
70}
71return (*s1 - *s2);
72}
73
74
75
76

Archive Download this file

Revision: 676