**Dies ist eine alte Version des Dokuments!**
Inhaltsverzeichnis
Gforth als Prozess 1 unter Linux
USB-Stick oder SD-Karte mit GForth almost native
Die Installation von GForth 'almost native' für x86-32Bit wurde für i686 Rechner (Pentium-Pro und neuer) kompiliert. Getestet wurde auf einem Thinkpad X60 und einen NoName Laptop mit VIA C7 CPU.
Bei Fragen und Verbesserungsvorschlägen bitte eine E-Mail an gforth-an@strotmann.de.
Anleitung Dateien
Anleitung zum erstellen einen USB-Stick oder SD-Karte unter Linux
- USB Stick oder SD-Karte einstecken, Gerätename per „dmesg“ herausfinden (im folgenden /dev/sdb1 bitte gegen den eigenen Gerätenamen austauschen. ACHTUNG, bei falschem Gerätenamen droht Datenverlust!)
 - die Software „syslinux“ als Paket installieren (per yum, apt-get, emerge etc)
 - eine primäre Partition auf dem Stick anlegen (wenn nicht schon vorhanden)
 - Partition mit dem EXT2 Dateisystem formatieren
% mkfs.ext2 /dev/sdb1 - Partition anhängen
'% mount /dev/sdb1 /mnt - Dateien auf die Partition spielen
cd /mnt; tar cvfz gforth-almost-native-20140815.tgz; sync; cd; - extlinux installieren
% extlinux -i /mnt - Bootsektor installieren
% cat /usr/share/syslinux/mbr.bin > /dev/sdb - Partition aushängen
% umount /mnt - USB-Stick ausprobieren
 
Anleitung Dateisystem-Abbild
- USB-Stick oder SD-Karte einstecken (mind. 512 MB), Gerätename per „dmesg“ herausfinden (im folgenden /dev/sdb1 bitte gegen den eigenen Gerätenamen austauschen. ACHTUNG, bei falschem Gerätenamen droht Datenverlust!)
 - Image auf das Gerät spielen
gzcat gforth-almost-native-20140815.img.gz | dd bs=1M > /dev/sdb - USB-Stick oder SD-Karte ausprobieren
 
GForth 'almost native' USB-Stick Image (512MB) vom 20140815 (37 MB)
Blocks und Datei-IO unter gforth-an
Wenn GNU/Forth (gforth) unter Linux als PID-1 gestartet wird, so ist ein Dateizugriff auf das Dateisystem des USB-Sticks oder der Festplatte möglich.
GNU/Forth Blocks sind im gforth-Handbuch Dokumentiert: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Blocks.html.
Wird keine explizite Datei für die Blocks angegeben, wir werden die Blocks in die Datei „blocks.fb“ auf dem Datenträger geschrieben, von dem gforth-an gestartet wurde (z.B. dem USB-Stick).
Die Datei-IO Worte des gforth orientieren sich am ANSI-Forth Standard und sind im Handbuch unter https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Files.html dokumentiert.
Es können so viele Blocks erstellt werden, wie Speicherplatz auf dem Datenträger frei ist.
Editor
Bis es einen besseren Editor für gforth-na gibt (Freiwillige vor), kann der Retro-Forth Editor (http://retroforth.org/pages/?PortsOfRetroEditor) benutzt werden. Der Retro-Forth Editor ist klein genug, um Ihn einzutippen und dann mittels des Editors (nochmal) in einen Block zu schreiben, um den Editor danach direkt aus dem Block laden zu können.
.( Retro Forth block editor for gForth ) cr 16 constant l/b : (block) scr @ block ; : (line) c/l * (block) + ; : row dup c/l type c/l + cr ; : .rows l/b 0 do i . row loop ; : .block ." Block: " scr @ dup . updated? 43 + emit space ; : +--- ." +---" ; : :--- ." :---" ; : x--- +--- :--- +--- :--- ; : --- space space x--- x--- x--- x--- cr ; : vb --- scr @ block .rows drop --- ; : .stack ." Stack: " .s ; : status .block .stack ; : v cr vb status ; : v* update v ; : s dup scr ! block drop v ; : ia (line) + >r 10 parse r> swap move v* ; : i 0 swap ia v* ; : d (line) c/l bl fill v* ; : x (block) l/b c/l * bl fill v* ; : p -1 scr +! v ; : n 1 scr +! v ; : e scr @ load ; cr .( editor loaded ) cr
Linux Syscalls aus GForth für ia86-32bit Linux
abi-code sys-getpid ( -- pid ) \ get process ID for gforth
   20  #   ax mov  \ get-pid syscall
   $80 #      int  \ execute syscall
   ax      cx mov  \ save result
   4 sp d) ax mov  \ get stackpointer
   4 #     ax sub  \ make space for result on stack
   cx    ax ) mov  \ move result to stack
              ret  \ return from code
end-code
abi-code sys-reboot ( -- ) \ shutdown and reboot machine
       88 # ax mov  \ reboot syscall
$fee1dead # bx mov  \ magic 1
 85072278 # cx mov  \ magic 2
$01234567 # dx mov  \ command (restart)
      $80 #    int  \ execute syscall
               ret  \ we don't expect to come back
end-code
abi-code sys-poweroff ( -- ) \ shutdown and poweroff machine
       88 # ax mov  \ reboot syscall
$fee1dead # bx mov  \ magic 1
 85072278 # cx mov  \ magic 2
$4321fedc # dx mov  \ command (poweroff)
      $80 #    int  \ execute syscall
               ret  \ we don't expect to come back
end-code
abi-code sys-sync ( -- ) \ commit buffer cache to disk
  36 #      ax mov  \ sync syscall
 $80 #         int  \ execute syscall
  4 sp d)   ax mov  \ return stackpointer
               ret  \ return
end-code
\ redefine "bye"
: bye sys-sync sys-poweroff ;
Links
- GNU/Forth Dokumentation: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html
 - GNU/Forth Quellcode auf github: https://github.com/forthy42/gforth
 - Anton Ertl: Almost native Forth: http://www.complang.tuwien.ac.at/forth/gforth/almost-native/
 - Linux 64Bit Syscall Tabelle: http://blog.rchapman.org/post/36801038863/linux-system-call-table-for-x86-64
 - Linux 32Bit Syscall Tabelle: http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html
 - GNU Forth (gforth): http://www.gnu.org/s/gforth/
 - Introduction to Computer Organization von Robert G. Plantz, PDF eBook bei Lulu: http://www.lulu.com/shop/robert-g-plantz/introduction-to-computer-organization-ebook/ebook/product-21369110.html
 - PC Assembly Language von Paul Carter, Kostenloses PDF eBook bei Lulu: http://www.lulu.com/shop/paul-carter/pc-assembly-language/ebook/product-17380062.html
 - Art of Assembly Language, 2nd Edition von Randall Hyde: http://www.nostarch.com/assembly2.htm
 - Wikibooks X86 Assembly: http://en.wikibooks.org/wiki/X86_Assembly
 - A. Ertl u. D. Kühling – ABI-CODE: Increasing the portability of assembly language words: http://www.complang.tuwien.ac.at/anton/euroforth/ef10/papers/ertl.pdf
 - fefe: diet libc - a libc optimized for small size: http://www.fefe.de/dietlibc/
 - Linux Kernel Repository: http://kernel.org
 - Knoppix-Live-Linux System: http://www.knopper.net/knoppix/index.html