Bluish Coder

Programming Languages, Martials Arts and Computers. The Weblog of Chris Double.


2007-02-17

Factor on Windows Mobile 5

Slava has been working on porting Factor to the ARM CPU for running on a gumstix.

Windows Mobile 5 devices also use a chipset that uses the ARM architecture. Doug Coleman, another Factor contributor, has a Windows Mobile 5 device and was keen to get Factor running on it.

Between us we'd been trying out the various options to compile code on the device. The cegcc project has a gcc port that runs on Linux and Windows (using cygwin) and cross compiles to Windows CE, which Windows Mobile 5 is a version of.

They have two versions of the compiler. One is like 'mingw' in that it has very few special libraries and is expected to use the Windows CE API. The other 'cegcc' is comparable to cygwin in that it has libraries that implement many common Unix functions to make porting software easier.

I was able to get Factor to compile using the 'cegcc' compiler and I've committed the changes to my repository. This is very much a work in progress and does not have everything working. For example, stack guards aren't implemented so if you cause a stack underflow the program segfaults. Apart from this it can bootstrap an image in 'no-compile' mode and run basic factor words in the interpreter.

To build Factor using the patches in my repository you'll need 'cegcc'. I built cegcc from their SVN repository using cygwin but the downloads they make available should work too.

I created a 'windows-arm' build option in Factor. In Linux or Cygwin, with '/opt/cegcc/bin' on the path, use:

make windows-arm CC=arm-wince-cegcc-gcc

This will build the binary for the mobile device. You'll also need some DLL's to exist on the device. I've included these in the .zip file mentioned below.

On the device you'll need a console program. I used the console programs used for the old 'pocket-gcc' project. They can be obtained from various places. I got mine from mamaich's site in file pocketcon.rar. Install both CAB files on the device. As these are for an older WinCE version you also need to make a registry change. Change HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo to be '0' (ie. the number zero). Running CMD will now give you a console.

Copy the entire Factor directory to the mobile device. Due to memory constraints it's best to have it on a storage card. Make sure the Factor directory has the 'f.exe' file that you built. Now you need a boot image. The 'arm' image can be generated from any Factor instance on any architecture. I generated it on a Windows machine with:

USE: image "arm" make-image

This generates boot.image.arm. Or you can download the one in the factor_wm5.zip file I've provided. That file also contains a pre-built 'f.exe' and the DLL's needed to run it.

With the contents of factor_wm5.zip in the Factor directory (which has 'core', 'libs', etc as subdirectories) (or your own generated boot and executable files) run a CMD console and change to the Factor directory. Run the following command:

f -i=boot.image.arm -no-native-io -no-compile -young=2 -aging=4 -codeheap=4

This will proceed to bootstrap an interpreter only Factor image.

The emulator has a limited amount of memory (and so too does the device I suspect) so to get things running I force very low amounts of memory using 'young', 'aging' and 'codeheap' options. You might need to play with these (the values are Megabytes) if you run out of memory.

Factor on Emulator

The bootstrap may take a while. It takes about 10 minutes on my laptop using the emulator. This will give you a factor.image. You can run it with:

f -young=2 -aging=4 -codeheap=4

You'll now be at a Factor prompt and can enter any Factor expression.

This is Factor running in 'interpreted' mode. Nothing is compiled. As a result it's quite slow and you can't call any FFI routines. When Slava finishes his ARM port then it'll become more useful. A screenshot of the emulator running Factor is here.

I don't actually have a Windows Mobile device so I've tested all this under Microsoft's emulator. The emulator runs under Windows and emulates the ARM CPU instructions so hopefully it's fairly accurate. Donations towards a device gratefully accepted :-)

For the emulator you'll need to get and install these files:

The emulator can map a directory on the hard drive of the host machine to act as the storage card. This is available in the options and is how I made the Factor directory available to it.

My repository with the patches to Factor is available with darcs:

darcs get http://www.bluishcoder.co.nz/repos/factor

Tags


This site is accessable over tor as hidden service 6vp5u25g4izec5c37wv52skvecikld6kysvsivnl6sdg6q7wy25lixad.onion, or Freenet using key:
USK@1ORdIvjL2H1bZblJcP8hu2LjjKtVB-rVzp8mLty~5N4,8hL85otZBbq0geDsSKkBK4sKESL2SrNVecFZz9NxGVQ,AQACAAE/bluishcoder/-61/


Tags

Archives
Links