Chameleon

Chameleon Svn Source Tree

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

Source at commit 429 created 13 years 9 months ago.
By meklort, Updated module system. Hooks can now be used within modules when cetaion functions are called in chameleon. Note that onle two hooks currently exist, more need to be added. I also updated the HelloWorld module to use a hook instead of print out right away.
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// load_dependency("Symbols", 300);
20}
21
22unsigned int lookup_symbol(const char* symbol)
23{
24int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;
25int lowerLimit = 0;
26int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
27int result;
28
29while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)
30{
31if(result > 0)// We need to search a HIGHER index
32{
33if(compareIndex != lowerLimit)
34{
35lowerLimit = compareIndex;
36}
37else
38{
39return 0xFFFFFFFF;// Symbol not found
40}
41compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
42}
43else // We Need to search a LOWER index
44{
45if(compareIndex != upperLimit)
46{
47upperLimit = compareIndex;
48}
49else
50{
51return 0xFFFFFFFF;// Symbol not found
52}
53compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
54}
55}
56return symbolList[compareIndex].addr;
57}
58
59/*
60 * strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point
61 */
62static int strcmp(const char * s1, const char * s2)
63{
64while (*s1 && (*s1 == *s2)) {
65s1++;
66s2++;
67}
68return (*s1 - *s2);
69}
70
71
72
73

Archive Download this file

Revision: 429