regspy 发表于 2006-10-30 22:20:23

ELF信息

Эльфы are written in language Си and provide the maximal speed.
For their start at you 3 PATCHES should be established(installed): library of functions, elfloader and swi-hook it is concrete for YOUR MODEL of an insertion and мобилы (number of an insertion we look on * *06 *-> Other functions, line SW-Version). References(links) to patches we look below.
At the moment the loader эльфов is written for all models x65 (the some people need to be altered in др. Model that is designated->): CX65-> CX70, M65 (-> CX70), C65-> SL65, S65
And for x75 models: S75, CX75, etc. The instruction on creation эльфов from cbn 0.3:All examples () Rst7.
What is эльфы see here.
Ready эльфы and patches we search on kibab

The maintenance(contents):
1. Installation Си of compiler IAR
2. Installation of the loader эльфов on мобилу
3. Start of examples in IAR
4. We create the эльф
5. An example 1. Work with memory and files
6. An example 2. A conclusion to the screen and processing of keys
7. The example is easier. We start background process, we draw on the timer
8. An example 4. The resident program
9. FAQ

1. Installation Си of compiler IAR
- From a site www.iar.com скачиваем evaluation version ARM IAR of the compiler (> 100 Mb),
At registration specifying real e-mail - on it(him) will send a key.
- We start крек iarunicrk to bypass 30-day's restriction (to read through the instruction).

2. Installation of the loader эльфов on мобилу (the cord - without it(him) in any way is required):
- We go on сименс-club, we read all about эльфы in FAQ and at forums in the same place.
- We do(make) as there it is written...:)

3. Start of examples in IAR
- We unpack examples from Rst7 (or any др.) in folder E: \ARM\
- We start IAR, we open Open existing Workspace one of examples
- We click in the left window above on the name of the project and we choose menu Project-> Options-> Arm
- We compile Project-> Rebuild All
If have received a mistake(an error) " _thumb... in range 0-0xFF " have not made the previous item(point)!
In adjustments(options) should stand Release (Project-> Edit Configurations-> Release) since compiled with Debug эльфы will not be loaded!
- Received эльф lays in folder E:\ARM\Имя of the project \Release \Exe\
PS. If it is necessary эльф for x65 before compilation it is made comments // in file E: \ARM \swilib.h a line
*define NEWSGOLD, if for s75 we clean(remove) the comment.
As we see all very simply:)

4. We create the эльф
Now creation эльфов became absolutely simple business:)
Most easier to correct a ready example: see the previous section.
We add to the project " Project-> Add Files " files Siemens.c and main.c
We correct(adjust) in main.c functions:
onkey - processing of keys (return 1 for an output(exit) from эльфа)
onredraw - copying of the screen (a file screen )
onstart, oncreate - functions are caused at start
onclose, onexit - functions are caused at an output(exit)
REDRAW () it is caused for copying the screen (start onredraw)
And ALL! At you the ready appendix. Specificity of Siemens the nobility not it is necessary in general!
Also see examples below.

5. An example 1. Work with memory and files
We change in any example main.c on:
*include "E: \ARM \swilib.h"

void ElfKiller (void) { // It is used for an output(exit) from эльфа
extern void *ELF_BEGIN;
// here usually still release(exempt) memory on mfree (), freeWS ()
((void (*) (void *)) (mfree_adr ())) (*ELF_BEGIN); // Nothing is clear: (
}

int main (char *exename, char *fname) { // the Basic function
// in exename the way started эльфа a kind 4: \Zbin \xyz.elf is transferred(transmitted)
// in fname the name of a file which is chosen in CardExplorere, kind 0: \Misc \data.txt is transferred(transmitted)
// or 0 if elf it is started
char *mem;
int i, err;
int handle;
if (fname) {
// Work with files is standard:
handle=fopen (fname, A_ReadWrite+A_BIN+A_Append+A_Create, P_READ+P_WRITE, *err);
// To open for reading and record in двоичн. A mode with дозаписью (append) to create if is not present
// or handle=fopen (fname, A_ReadOnly+A_BIN, 0, *err); // only for reading - constants see swilib.h
if (handle! =-1) {//-1 = error
mem=malloc (10000); // To allocate memory: AllocWS () for lines (on 2б)
if (mem! =0) {// 0 = error
i=fread (handle, mem, 10000, *err); // Returns number of the read through bytes and a mistake(an error) in err
// we Do(Make) something makesomebody (mem, i);
fwrite (handle, mem, i, *err);
mfree (mem); // To release(exempt) memory: FreeWS () for lines
}
fclose (handle); // To close a file
}
}
SUBPROC ((void *) ElfKiller); // се the riddle great is:) But without it(her) низя!
return (0);
}
// PS. Since in x65 file reading and record are spent by blocks up to 32767 bytes,
// instead of fread () and fwrite () it is used their analogues fread32 () and fwrite32 (similarly)

int fread32 (int fh, char *buf, int len, unsigned int *err) // () Rst7
{
int clen;
int rlen;
int total=0;
while (len)
{
if (len> 16384) clen=16384; else clen=len;
total + = (rlen=fread (fh, buf, clen, err));
if (rlen! =clen) break;
buf + = rlen;
len-= clen;
}
return (total);
}

It is not forgotten to include in each project fileFunc.asm:
PUBLIC ELF_BEGIN
RSEG ELFBEGIN:DATA
ELF_BEGIN
defadr MACRO a, b
PUBLIC a
a EQU b
ENDM
END

6. An example 2. A conclusion to the screen and processing of keys
Displays the small figure moved by means of джойстика,
Also leaves on long pressing the red button. It is made on an example TED (c) Rst7
To look from below-upwards:)
We change in an example main.c on:
*include "E: \ARM \swilib.h"

typedef struct
{
GUI gui;
// WSHDR *ws1;
// WSHDR *ws2;
// int i1;
} MAIN_GUI;

typedef struct
{
CSM_RAM csm;
int gui_id;
} MAIN_CSM;

const int minus11 =-11;
const unsigned int INK=0;
const unsigned int PAPER=1;
volatile int xx=0, yy=0; // Coordinates of display of figure

const char bmp = {0xFC, 0x86,0xB3,0xA9,0xB1,0xA9,0x81,0xFF, 0,0,0,0};
const IMGHDR img = {8,12,0x1,0, (char *) bmp};

// ================================
// the Conclusion to the screen
// ================================

void DrwImg (IMGHDR *img, int x, int y, int *pen, int *brush)
{
RECT rc;
DRWOBJ drwobj;
StoreXYWHtoRECT (*rc, x, y, img-> w, img-> h);
SetPropTo_Obj5 (*drwobj, *rc, 0, img);
SetColor (*drwobj, pen, brush);
DrawObject (*drwobj);
}

void DrawScreen (void)
{
int *ink=GetPaletteAdrByColorIndex (INK);
int *paper=GetPaletteAdrByColorIndex (PAPER);
int x=xx;
DrwImg ((IMGHDR *) *img, x, yy, ink, paper);
}

// Copying of the basic dialogue
void method0 (MAIN_GUI *data) {
DrawScreen ();
}

void method1 (MAIN_GUI *data, void * (*malloc_adr) (int)) {}
void method2 (MAIN_GUI *data, void (*mfree_adr) (void *)) {}
void method3 (MAIN_GUI *data, void * (*malloc_adr) (int), void (*mfree_adr) (void *)) {}
void method4 (MAIN_GUI *data, void (*mfree_adr) (void *)) {}
void method7 (MAIN_GUI *data, void (*mfree_adr) (void *)) {}
int method8 (void) {return (0);} // Empty õ-th
int method9 (void) {return (0);} // Empty õ-th

//------------------------------------------------------------------------------
// Осн. Dialogue - processing of buttons
//------------------------------------------------------------------------------
int method5 (MAIN_GUI *data, GUI_MSG *msg)
{
// if (msg-> gbsmsg-> msg == KEY_UP) // the Key is released(let off)
if ((msg-> gbsmsg-> msg == KEY_DOWN) || (msg-> gbsmsg-> msg == LONG_PRESS)) // Кл. It is pressed or is kept
switch (msg-> gbsmsg-> submess)
{
case RED_BUTTON:
return (1); // there Is call GeneralFunc for flew. GUI-> closing GUI
case UP_BUTTON:
if (yy> 0) - yy; break;
case LEFT_BUTTON:
if (xx> 0) - xx; break;
case DOWN_BUTTON:
if (yy<130) ++yy; break;
case RIGHT_BUTTON:
if (xx<120) ++xx; break;

// case GREEN_BUTTON:
// case RIGHT_SOFT:
// case ENTER_BUTTON:
// case LEFT_SOFT:
// case VOL_UP_BUTTON:
// case VOL_DOWN_BUTTON:
// case ' 0 ':
// case ' 9 ':
// case ' * ':
// SUBPROC ((void *) DoDiskAccess, 1);
// Др. Process with a low priority to not brake copying a window
}
DrawScreen ();
return (0);
}

const void * const gui_methods = {
(void *) method0, // Redraw
(void *) method1, // Create
(void *) method2, // Close
(void *) method3, // Focus
(void *) method4, // Unfocus
(void *) method5, // OnKey
0,
(void *) method7, // Destroy
(void *) method8,
(void *) method9,
0
};

const RECT Canvas = {0,0,131,175};

void maincsm_oncreate (CSM_RAM *data)
{
MAIN_GUI *main_gui=malloc (sizeof (MAIN_GUI));
MAIN_CSM*csm = (MAIN_CSM *) data;
zeromem (main_gui, sizeof (MAIN_GUI));

// ustk=malloc (STKSZ); // we Allocate memory under what is necessary to us
// info_ws=AllocWS (512);

main_gui-> gui.canvas = (void *) (*Canvas);
main_gui-> gui.flag30=2;
main_gui-> gui.methods = (void *) gui_methods; // the Basic methods (see above)
main_gui-> gui.item_ll.data_mfree = (void (*) (void *)) mfree_adr (); // Below ниче I do not know: (
csm-> csm.state=0;
csm-> csm.unk1=0;
csm-> gui_id=CreateGUI (main_gui); // Actually creation GUI
}

void Killer (void) // the Output(Exit)
{
extern void *ELF_BEGIN;
// mfree (ustk); // we Release(Exempt) memory
// FreeWS (info_ws);
((void (*) (void *)) (mfree_adr()) (*ELF_BEGIN);
}

void maincsm_onclose (CSM_RAM *csm)
{
// GBS_StopTimer (*light_tmr);
SUBPROC ((void *) Killer);
}

int maincsm_onmessage (CSM_RAM *data, GBS_MSG *msg) {
return (1);
}

unsigned short maincsm_name_body ;

const struct
{
CSM_DESC maincsm;
WSHDR maincsm_name;
} MAINCSM =
{
{
maincsm_onmessage, // Обработчик messages
maincsm_oncreate, // It is caused at creation
// 0, // For S75 to clean(remove) comments in 4х lines
// 0, // and раскомментировать in swilib.h a line *define NEWSGOLD
// 0,
// 0,
maincsm_onclose, // It is caused at closing
sizeof (MAIN_CSM),
1,
*minus11
},
{
maincsm_name_body,
NAMECSM_MAGIC1,
NAMECSM_MAGIC2,
0x0,
139
}
};

int main (char *exename, char *fname)
{
char dummy ;
// strcpy (filename, fname); // It is kept somewhere fname
CreateCSM (*MAINCSM.maincsm, dummy, 0);
return 0;
}

7. The example is easier. We start background process, we draw on the timer
We add to the project " Project-> Add Files " file Siemens.c:
// Siemens.c 0.1
// the Interface мобилы for IAR
// Here nothing is touched! (if are not assured)
// External functions are caused at:
extern int onstart (char *exename, char *fname); // Start of the appendix. Returns 0 or 1 for an output(exit).
extern void oncreate (); // Creation of a window
extern void onclose (); // Closing of a window
extern void onexit (); // the Output(Exit)
extern void onredraw (void); // to Copying of the screen
extern int onkey (unsigned char keycode, int pressed); // Pressing of a key. Returns 0 or 1 for an output(exit).

// In swilib.h it is made comments // a line *define NEWSGOLD if not S75
*include "E: \ARM \swilib.h"
// the Next line sets 16 bit mode (RGB 565 on 2 байта on a point of the screen screen)
// закомментировав we shall receive 8 bit mode (RGB 232 on 1 байту on a point)
*define HIGHCOLOR
*ifdef HIGHCOLOR
short screen ;
const int screensize=132*176*sizeof (short);
const IMGHDR img = {(unsigned) 132, (unsigned) 176,8,0, (char *) screen};
*else
char screen ;
const int screensize=132*176*sizeof (char);
const IMGHDR img = {(unsigned) 132, (unsigned) 176,5,0, (char *) screen};
*endif

// Below to read it is not necessary any more!:)
typedef struct
{
GUI gui;
WSHDR *ws1;
WSHDR *ws2;
int i1;
} MAIN_GUI;

typedef struct
{
CSM_RAM csm;
int gui_id;
} MAIN_CSM;

void DrawScreen () {
RECT rc; DRWOBJ drwobj;
StoreXYWHtoRECT (*rc, 0,0, img.w, img.h);
SetPropTo_Obj5 (*drwobj, *rc, 0, (IMGHDR *) and img);
SetColor (*drwobj, GetPaletteAdrByColorIndex (0), GetPaletteAdrByColorIndex (1));
DrawObject (*drwobj);
}
void method0 (MAIN_GUI *data) { onredraw (); DrawScreen ();}
void method1 (MAIN_GUI *data, void * (*malloc_adr) (int)) { oncreate (); data-> gui.state=1;}
void method2 (MAIN_GUI *data, void (*mfree_adr) (void *)) { data-> gui.state=0;}
void method3 (MAIN_GUI *data, void * (*malloc_adr) (int), void (*mfree_adr) (void *)) { data-> gui.state=2;}
void method4 (MAIN_GUI *data, void (*mfree_adr) (void *)) {if (data-> gui.state! =2) return; data-> gui.state=1;}
int method5 (MAIN_GUI *data, GUI_MSG *msg) {
return onkey (msg-> gbsmsg-> submess, msg-> gbsmsg-> msg);}
void method7 (MAIN_GUI *data, void (*mfree_adr) (void *)) {} // mfree_adr (data);
int method8 (void) {return (0);} // Empty &otilde;-th
int method9 (void) {return (0);} // Empty &otilde;-th

const void * const gui_methods = {
(void *) method0, // Redraw
(void *) method1, // Create
(void *) method2, // Close
(void *) method3, // Focus
(void *) method4, // Unfocus
(void *) method5, // OnKey
0,
(void *) method7, // Destroy
(void *) method8,
(void *) method9,
0
};

const RECT Canvas = {0,0,131,175};

void maincsm_oncreate (CSM_RAM *data)
{
MAIN_GUI *main_gui=malloc (sizeof (MAIN_GUI));
MAIN_CSM*csm = (MAIN_CSM *) data;
zeromem (main_gui, sizeof (MAIN_GUI));
// ustk=malloc (STKSZ); // we Allocate memory
// info_ws=AllocWS (512);
main_gui-> gui.canvas = (void *) (*Canvas);
main_gui-> gui.flag30=2;
main_gui-> gui.methods = (void *) gui_methods;
main_gui-> gui.item_ll.data_mfree = (void (*) (void *)) mfree_adr ();
csm-> csm.state=0;
csm-> csm.unk1=0;
csm-> gui_id=CreateGUI (main_gui);
}

void Killer (void) {
extern void *ELF_BEGIN;
extern void kill_data (void *p, void (*func_p) (void *));
onexit ();
kill_data (*ELF_BEGIN, (void (*) (void *)) mfree_adr ());
// ((void (*) (void *)) (mfree_adr()) (*ELF_BEGIN);
}

void maincsm_onclose (CSM_RAM *csm)
{
onclose ();
SUBPROC ((void *) Killer);
}

int maincsm_onmessage (CSM_RAM *data, GBS_MSG *msg) {
MAIN_CSM *csm = (MAIN_CSM *) data;
if ((msg-> msg == MSG_GUI_DESTROYED) ** ((int) msg-> data0 == csm-> gui_id))
csm-> csm.state =-3;
return (1);
}

const int minus11 =-11;
unsigned short maincsm_name_body ;

const struct
{
CSM_DESC maincsm;
WSHDR maincsm_name;
} MAINCSM =
{
{
maincsm_onmessage,
maincsm_oncreate,
*ifdef NEWSGOLD
0,
0,
0,
0,
*endif
maincsm_onclose,
sizeof (MAIN_CSM),
1,
*minus11
},
{
maincsm_name_body,
NAMECSM_MAGIC1,
NAMECSM_MAGIC2,
0x0,
139
}
};

int main (char *exename, char *fname) {
char dummy ;
if (onstart (exename, fname)) SUBPROC ((void *) Killer);
else CreateCSM (*MAINCSM.maincsm, dummy, 0);
return 0;
}

Now we correct(adjust) (if it is necessary) a file main.c:
// Main.c 0.1
// Demo 3: the Example is easier: we Start background process, we draw on the timer

*include "E: \ARM \swilib.h"
extern short screen ; // the Screen 132*176*2
extern void DrawScreen (); // Function of copying of the screen
void onredraw (void);

// *define RGB8 (R, G, B) (B + (G<<2)+(R<<5))
*define RGB16 (R, G, B) ((B> 31? 31:B) + ((G> 63? 63:G) <<5)+((R>31? 31:R)<<11))

char *buf=0; // Any buffer (for an example of allocation of memory)
int bufsize=10000; // Its(His) size
volatile int started=0; // Process checks a flag and leaves if =0
int color=0;

GBSTMR timer;
void timer_proc (void) {// Function is carried out on the timer of 10 times in a second
if (started) {
REDRAW (); // To draw again the screen
}
GBS_StartTimerProc (*timer, 262/10, timer_proc); // we Shall start the timer with frequency of 10 times in a second
// It(He) is carried out unitary therefore it(him) it is necessary to start constantly
}

void execute () {// Background process
started=1;
while (started) {// While there is no command(team) on останов
onredraw (); // ONLY for an example, in practice we do(make) something(something else)
}
}

int onstart (char *exename, char *fname) {// Start of the appendix. Returns 0 or 1 for an output(exit).
// if (! fname) return 1; // If the name of a file is not set leave
buf = (char *) malloc (bufsize); // we Allocate memory, etc.
if (! buf) return 1; // it has not turned out - we leave
// Here we do(make) something
return 0;
}

void oncreate () {// Creation of a window
SUBPROC ((void *) execute); // background process Is started
GBS_StartTimerProc (*timer, 262/10, timer_proc); // we Shall start the timer with frequency of 10 times in a second
}

void onclose () {// Closing of a window
started=0; // the Signal on a stop of background process
GBS_StopTimer (*timer); // we Stop the timer
// we Keep a configuration if it is necessary
}

void onexit () {// the Output(Exit)
if (buf) mfree (buf); // we Release(Exempt) memory
}

void onredraw (void) {// Copying of the screen screen
int i, j;
for (i=0, j=color ++; i<132*176;i++){
screen =j ++;
}
}

// keycode - a code of a key, pressed - it is pressed/is released/is kept(is pressed/is let)
int onkey (unsigned char keycode, int pressed) {// Обработчик keys. To return 0 or 1 for an output(exit)
switch (pressed) {
case KEY_UP: break; // the Key is released(let off)
case LONG_PRESS: // the Key is kept long (repetition)
case KEY_DOWN: // the Key is pressed
switch (keycode) {// the Code of a key
case RED_BUTTON: return 1; // the Output(Exit)
case LEFT_SOFT: case RIGHT_BUTTON: case UP_BUTTON: case ENTER_BUTTON: // we Do(Make) something
case ' 0 ': case ' 9 ': case ' * ': case ' * ': break;
default: return 0;
}
onredraw (); DrawScreen (); // To draw again the screen
}
return 0;
}
// *define MSG_GUI_DESTROYED 152 // for not s75 if at you is not present in swilib.h


8. An example 4. The resident program
[...]

9. FAQ
It is collected on the basis of answers Rst7 (thanks it(him):)

- Why in iar cu a design char c ; int a = * (int *) (c+5) switches off a pipe?
Because you try to read int to not round address - percents send it нах - generates exception... If you should such do(make), read побайтно and collect in separate инт.

- Necessarily at an output(exit) to release(exempt) all memory on mfree ()?
All with which has borrowed(occupied) - necessarily

- How to debug эльфы except for how to copy them on phone and to write a broad gully?
Дебаггером Хаосовским... You Search BLX R4 in the loader эльфов, you finish there останова and forward...

- What do(make) SUBPROC? REDRAW?
SUBPROC - a call of function in a context of other stream with a small priority to not brake GUI if it is necessary to something to do(make) long (for example in TED \'е to load the text, in MegaDial \'е to search for names in a notebook)
REDRAW - to cause a method onRedraw displayed GUI (it is possible from a context of process-assistant)

binghelingxi 发表于 2006-10-31 09:40:19

晕了。看不懂。。。。

binghelingxi 发表于 2006-10-31 09:44:47

幻。。。
这个是什么,S65 V58的,好像国内补丁没有这个。。。

;FREAD32,FWRITE32
#pragma enable old_equal_ff
;FREAD32
0x00FD9400: FBB51500002403E00199AD1B08180190
0x00FD9410: 002D0FD00948854201DB461E00E02E00
0x00FD9420: 0098074F029B01993F683200B8472418
0x00FD9430: B042E9D0200003B0F0BDC04601400000
0x00FD9440: F094FDA0
;FWRITE32
0x00FD9450: FBB51500002403E00199AD1B08180190
0x00FD9460: 002D0FD00948854201DB461E00E02E00
0x00FD9470: 0098074F029B01993F683200B8472418
0x00FD9480: B042E9D0200003B0F0BDC04601400000
0x00FD9490: F494FDA0
;RET_ADRS
;0x00FD94F0: 0xA122ECF0,0xA122EDD8 ; fread fwrite
0x00FD94F0: F0EC22A1D8ED22A1
#pragma disable old_equal_ff

regspy 发表于 2006-10-31 11:20:54

回复 #3 binghelingxi 的帖子

这个是TED 用的 读写函数。

jpg001 发表于 2006-11-1 21:17:45

昨天帮一个机友移植bennie的输入法补丁的时候,发现keil编译bennie的源码得到的文件里也有一个ELF文件,不知与这个elf有什么关系

regspy 发表于 2006-11-2 13:12:20

ARM ELF File Format文件格式.pdf

regspy 发表于 2006-11-2 13:14:30

回复 #5 jpg001 的帖子

我刚才看了一下。。。。。很像。。。。

你放进去试试。

jpg001 发表于 2006-11-2 19:13:33

回复 #7 regspy 的帖子

机器刷暴了好像,这两天开始暴费电了
又得重新来一遍了
早就弄过了,没什么反应,就算是,估计也没这么简单

regspy 发表于 2006-11-2 19:59:14

回复 #8 jpg001 的帖子

我也试了一次。。把 KEIL 编译补丁生成 的ELF放进去了。 但没有效果。

再大概看了一下 一楼的文章 。。。偶看不懂。

看他的意思,是要加载swilib.h
看来,就是 要调用软中断 来操作吧。
所有函数都 是取的LIB里的。

他还对 屏 分辨率进行了。设置,应该 75和65的 ELF不通用就是 SWILIB的起始地址不同吧。。

regspy 发表于 2006-11-2 20:05:49

我叫LE帮忙分析了文件头的连接信息。

用KEIL编译出来的 是静态连接

而他这个 是动态连接
页: [1]
查看完整版本: ELF信息