Sign in Join
Wiki copytemporary

WinCE port/ru: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: WinCE port/ru

OldNewLine
1+Портирование на WinCE вполне выполнимо. Начат и закреплён сей процесс был Юрием Сидоровым. Oliver (Oro06) портировал заголовочные файлы WinCE API.
2+
3+## Статус
4+
5+- FPC 2.2.0 или позже поддерживает целевую платформу WinCE.
6+- Процессоры: платформы WinCE:
7+ - [[ARM]] поддерживается.
8+ - [[i386]] Поддержка недостаточно протестирована и содержит ошибки. Исправления приветствуются.
9+- Поддерживаются следующие версии WinCE:
10+ - Устройства на WinCE 3.0 или позднее
11+ - Pocket PC 2002 – версия WinCE: 3.0
12+ - Pocket PC 2003 – версия WinCE: 4.20
13+ - Pocket PC 2003 Second Edition – версия WinCE: 4.21
14+ - Windows Mobile 5 – версия WinCE : 5.0
15+ - Windows Mobile 6 – версия WinCE : 5.2
16+ - Windows Mobile 6.5 - версия WinCE : 5.2.1
17+- юниты [RTL](http://community.freepascal.org:10000/docs-html/rtl) и [FCL](http://community.freepascal.org:10000/docs-html/fcl) работают.
18+
19+## Скачать кроссплатформенный компилятор
20+
21+Наиболее лёгкий способ начать разрабатывать для WinCE - загрузить свежую версию FPC под Win32 и arm-wince cross compiler for Win32.
22+
23+Скачать можно тут: <http://www.freepascal.org/download.var>
24+
25+Сначала установите FPC for Win32, затем установите arm-wince cross compiler как add-on пакет.
26+
27+Если же нужен ещё и лазарус, то качайте вот отсюда оба: <http://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/Lazarus%200.9.28.2/>
28+
29+Установите оба в одну папку, сначала win32 потом cross-compiler.
30+
31+## Сборка WinCE cross compiler из исходников
32+
33+During the tutorial some paths will be suposed to demonstrate the build process. Just substitute those paths with the ones on your system.
34+
35+This tutorial demonstrates how to build **arm-wince** crosscompiler. **i386-wince** crosscompiler can be build similar way. Just substitute **arm** to **i386**. Also binutils are not needed for i386-wince target.
36+
37+**Step 1** - Cross binutils
38+
39+These are the basic tools necessary to create executables, such as: Linker (ld), Assembler (as), Archiver (ar) (Creates smartlinking .a files), strip and some others.
40+
41+You need cross binutils for arm-wince, get them from <ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip> for Win32.
42+
43+Extract them to some dir in the path on your machine. We will supose that you extracted the cross binutils to: `C:\Programas\arm`
44+
45+**Step 2** - Cross compiler
46+
47+Now you need to build fpc cross compiler for ARM processor. To do that you need fpc 2.2.0 or later sources and working installation of fpc 2.2.0 for Win32.
48+
49+You can get the latest fpc source repository from Subversion: <http://www.freepascal.org/develop.html#svn>
50+
51+We will supose that your Win32 fpc compiler is located here: `C:\Programas\fpc\bin\i386-win32`
52+
53+And your Free Pascal source code is located here: `C:\Programas\fpc`
54+
55+**Step 3** - The Build process
56+
57+In order to build the cross compiler it is necessary to have a correct `PATH` environment variable. On Windows it is very easy to get a `PATH` crowded with information put by installers. To ensure that your path is correct, create a batch file with the following code:
58+
59+ PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\arm
60+ make cycle CPU_TARGET=arm OS_TARGET=wince
61+
62+Put this file on `C:\Programas\fpc\compiler`, open the Windows command line, go to this folder and execute the batch file.
63+
64+On the end of the compile you should not see any errors.
65+
66+You should have a `ppccrossarm.exe` in `C:\Programas\fpc\compiler` and some `.o` and `.ppu` files in `C:\Programas\fpc\rtl\units\arm-wince`
67+
68+Now copy those files to your Free Pascal installation. The cross compiler `ppccrossarm.exe` should go to `C:\Programas\fpc\bin\arm-wince` and the units to `C:\Programas\fpc\units\arm-wince`
69+
70+**Step 4** - Configuration file
71+
72+Now you need to create `fpc.cfg` configuration file in `C:\Programas\fpc\bin\arm-wince` folder in order to use `ppccrossarm.exe` easy.
73+
74+Create empty `fpc.cfg` file in `C:\Programas\fpc\bin\arm-wince` folder and add the following lines to it:
75+
76+ -Twince
77+ -FuC:\Programas\fpc\units\arm-wince
78+ -XParm-wince-
79+ -FDC:\Programas\arm
80+
81+Finally add `C:\Programas\fpc\bin\arm-wince` and `C:\Programas\fpc\bin\i386-win32` to your `PATH` environment variable.
82+
83+**Remember to substitute the paths with the ones on your system.**
84+
85+**Alternative Step 4** - Configuration file for hybrid compilation
86+
87+If you want to compile your projects with the same "fpc" for both win32 and winCE platforms, you can do the following:
88+
89+- copy ppcrossarm.exe into your fpc/bin/i386-win32 directory
90+- edit your fpc.cfg in that directory and add:
91+
92+ -FuC:\path_to_fpc\units\arm-wince
93+ -XParm-wince-
94+ -FDC:\path_to_arm_binutils
95+
96+**Remember to substitute the paths with the ones on your system.**
97+
98+Now when you want to compile for WinCE you just have to specify the OS and Arch targets to fpc.
99+
100+NOTE: if you use Lazarus this will work flawlessly, but make sure to point lazarus to "fpc.exe" not "ppc386.exe".
101+
102+## Компиляция тестового проекта
103+
104+У меня есть компилятор! Что я могу делать теперь? Дальше следует инструкция по созданию программы hello world.
105+
106+**Шаг 1** - Установкаи настройка эмулятора
107+
108+Вам понадобится Windows CE Emulator сконфигурированный с ActiveSync. The ActiveSync is necessary to install PocketCMD, a command line tool to run our hello world software.
109+
110+Download the free Pocket PC device emulator from Microsoft. It emulates ARM CPU. <http://msdn.microsoft.com/mobility/downloads/Emulator/default.aspx>
111+
112+There is a tutorial on how to set up the Emulator for ActiveSync [here](http://www.pocketpcfaq.com/faqs/5.0/emulator.htm).
113+
114+**Step 2** - Installing the command line
115+
116+Download and install **PocketCMD** by SymbolicTools. Get it [here](http://www.symbolictools.de/public/pocketconsole/applications/PocketCMD) (this site seems to be gone) but try here [1](http://www.mobile2day.de/platform_wince/device/CASIO/Cassiopeia+E-115/download.html?file=c112516.exe&prod=14571)
117+
118+To enable the console on newer devices (I needed it in my 6.1CE pro), you may to set the following registry value [link](http://forum.xda-developers.com/showthread.php?t=275019&highlight=console)
119+
120+`HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo -> 0`
121+
122+Check the WinCE port notes section bellow for more details on command lines on Pocket PC.
123+
124+**Step 3** - Compiling
125+
126+A example file to compile:
127+
128+ program test;
129+
130+ {$apptype console}
131+
132+ var
133+ Str: string;
134+ begin
135+ WriteLn('Software Developed with:');
136+ WriteLn('The Free Pascal Compiler');
137+ WriteLn('');
138+ WriteLn('Please, enter your name:');
139+ ReadLn(Str);
140+ WriteLn('Your name is: ' + Str);
141+ end.
142+
143+Sample command line to compile `test.pas`:
144+
145+`ppcrossarm test.pas`
146+
147+You will get `test.exe` executable file. Copy it to your Windows CE device and run.
148+
149+[Here](http://wiki.lazarus.freepascal.org/index.php/Windows_CE_Interface#Screenshots) is a screenshot of a software created this way.
150+
151+## Debugging WinCE applications
152+
153+GDB can be used to debug your WinCE applications remotely via ActiveSync. Download GDB 6.4 for Win32 host and arm-wince target here: <ftp://ftp.freepascal.org/pub/fpc/contrib/cross/gdb-6.4-win32-arm-wince.zip>
154+
155+**Some hints:**
156+
157+- Pass `--tui` parameter to GDB to enable TUI interface which makes debugging more comfortable.
158+- Use unix line endings (LF only) in your pascal source files. Otherwise GDB will show sources incorrctly.
159+
160+**How to use:**
161+
162+First, make ActiveSync connection to your Pocket PC device.
163+
164+Then launch gdb:
165+
166+`gdb --tui <your_executable_at_local_pc>`
167+
168+On gdb prompt type:
169+
170+`run` or just `r`
171+
172+GDB will copy your executable to the device in `\gdb` folder and run it.
173+
174+Here is a short list of most needed GDB commands:
175+
176+- `r args` - run program with args arguments.
177+- `s` - step into.
178+- `n` - step over.
179+- `ni` - step over instrument.step over assembly instruction.
180+- `c` - continue execution.
181+- `br <function_name>` - set a breakpoint at `function_name`. Use `PASCALMAIN` to set a breakpoint at program start.
182+- `br <source_file>:<line_number>` - set a breakpoint at specified source line.
183+- `disas` - show disassembly of current location.
184+- `x/fmt address` - dump memory at address with special format.use "help x" for more informations.
185+- `bt` - back trace.print back trace of the call stack.
186+- `where` - Display the current line and function and the stack of calls that got you there.
187+- `q` - Quit gdb.
188+
189+To learn more how to use GDB read its documentation here: <http://www.gnu.org/software/gdb/documentation>
190+
191+## Building FPC libraries
192+
193+If you want to build libraries available with FPC just go to library folder and execute:
194+
195+ PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\fpc\compiler;C:\Programas\arm
196+ make OS_TARGET=wince CPU_TARGET=arm PP=ppcrossarm.exe
197+
198+For example you want to build FCL. Go to `fpc\fcl` folder and execute the command above. You will get FCL compiled units in `fpc\fcl\units\arm-wince`.
199+
200+## Documentation
201+
202+### some WinCE notes
203+
204+- If you are getting "Uknown error! Error code : 0xc1" and using dlls then the error might be becouse of using some export entries not found in dll file.Check the dll file export section and name of them and how you used them.
205+
206+### WinCE port notes
207+
208+- **`chdir`** procedure always produces an error (WinCE does not support setting of current directory).
209+- All file/dir paths must be absolute (started with \\).
210+- WinCE is unicode OS. All string parameters to API calls must be PWideChar.
211+- WinCE does not have support for environment strings.
212+- WinCE does not have support for console applications by default. But you can install console support by yourself. Please note that FPC creates GUI applications for WinCE target by default. To create console application you should use `-WC` compiler switch or put `{$APPTYPE CONSOLE}` directive to source code.\
213+ To enable console in WinCE install one of the following programs:
214+ - **PocketCMD** by SymbolicTools. It is recommended solution. Get it [here](http://www.symbolictools.de/public/pocketconsole/applications/PocketCMD)
215+ - **PPC Command Shell** from Microsoft Windows Mobile Developer Power Toys. Get it [here](http://www.microsoft.com/downloads/details.aspx?FamilyID=74473fd6-1dcc-47aa-ab28-6a2b006edfe9&displaylang=en)\
216+ PPC Command Shell have less features than PocketCMD. Also it have some issues. One of them - a new console window is opened even if an application is started from a console command prompt.
217+ - To enable console output in Windows Mobile 5 and 6 set "HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo" to 0.
218+
219+## See Also
220+
221+- [[Tested Unstable Revisions]]
222+- [Windows CE interface for Lazarus](http://wiki.lazarus.freepascal.org/Windows_CE_Interface)
223+- [Windows CE Development Notes](http://wiki.lazarus.freepascal.org/Windows_CE_Development_Notes)
224+- [Приложения WinCE с исползованием KOL](http://wiki.lazarus.freepascal.org/KOL-CE/ru)
225+
226+## Links
227+
228+- Useful WinCE info <http://www.rainer-keuchel.de/documents.html>
229+- Standalone Pocket PC device emulator from Microsoft. It emulates ARM CPU. Get it [here](http://www.microsoft.com/downloads/details.aspx?FamilyId=C62D54A5-183A-4A1E-A7E2-CC500ED1F19A&displaylang=en)
230+- Mamaich Pocket PC port of GCC <http://mamaich.uni.cc>
231+- [Buildfaq](http://www.stack.nl/~marcov/buildfaq.pdf) is a general FAQ about how to build and configure FPC.
232+
233+Here are some links related to ARM CPU Architecture
234+
235+- [ARM Core Developers Forum](http://www.armcorepro.com/) Not that much active though.
236+- [GCC ARM Improvement Project](http://www.inf.u-szeged.hu/gcc-arm/)
237+- [ARM ASSEMBLER](http://www.heyrick.co.uk/assembler/index.html) Good information and codes related to arm assembly language.
238+- [GNU ARM toolchain for Cygwin, Linux and MacOS](http://www.gnuarm.com/)
239+- [Microsoft Windows CE .NET 4.2 ARM Guide](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcechp40/html/ccrefarmguide.asp)
240+- [ARM Instruction Sets & Programs](http://soc.csie.ndhu.edu.tw/source/intro_embedded/ch2-arm-2.ppt) Very good and consice information about arm architecture
241+- [The ARM Instruction Set](http://web.njit.edu/~baltrush/arm_stuff/ARMInst.ppt) Another fine power point file about arm
242+
243+## Contacts
244+
245+Write any questions regarding WinCE port to [Yury Sidorov](mailto:yury_sidorov@mail.ru)
246+
247+---
248+*From the Free Pascal wiki, page "WinCE port/ru", as it stood on 2015-05-14 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
249+Category: Russian
250+Category: WinCE/ru

Back to history