Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 789