Author: wmb Date: 2009-05-24 13:01:02 +0200 (Sun, 24 May 2009) New Revision: 1199
Added: cpu/arm/beagle/ cpu/arm/beagle/beagle.bth cpu/arm/beagle/build/ cpu/arm/beagle/build/Makefile cpu/arm/beagle/traps.fth cpu/arm/openmoko/ cpu/arm/openmoko/build/ cpu/arm/openmoko/build/Makefile cpu/arm/openmoko/openmoko.bth dev/omap/ dev/omap/diaguart.fth Modified: cpu/arm/traps.fth Log: ARM - added Beagle Board / Gumstix Overo support, and the start of OpenMoko
Added: cpu/arm/beagle/beagle.bth =================================================================== --- cpu/arm/beagle/beagle.bth (rev 0) +++ cpu/arm/beagle/beagle.bth 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,90 @@ +purpose: Load file for OFW on ARM beagleboard +\ See license at end of file + +dictionary: ${BP}/cpu/arm/build/basefw.dic +command: &armforth &dictionary &this +build-now + +" beagle.tag" r/w create-file drop tag-file ! + +\ ' $report-name is include-hook + +use-movable-vector-base \ CortexA8 CPU core has a movable vector base + +h# 8.0000 constant initial-heap-size + +: (initial-heap) ( -- adr len ) limit initial-heap-size ; +' (initial-heap) to initial-heap + + +fload ${BP}/dev/omap/diaguart.fth \ OMAP UART +h# 49020000 to uart-base \ UART# base address on beagleboard + +fload ${BP}/forth/lib/sysuart.fth \ Set console I/O vectors to UART + + +\ Install the simple UART driver from the standalone I/O init chain +: stand-init-io ( -- ) + stand-init-io + inituarts install-uart-io +; + +0 [if] \ This turns off an LED; it's useful for startup debugging +code usr1-off + begin + set r1,0x49056090 + set r2,0x00400000 + str r2,[r1] + again +c; +[then] + +\ This is some glue code to convert the machine setup that QEMU gives us +\ to the setup that start-forth (see arm/boot.fth) wants. +\ We get here via a call instruction at origin+8, which is inserted below + +code stand-cold-code ( r0: 0 r1: board-id r2: &kernel-args lr: &aif_header+8c ) + here origin 8 + put-call \ Insert call instruction + + \ Put the arguments in safe registers + sub r6,lr,#0x8c \ r6 points to header (lr set by code at origin) + mov r7,#0 \ r7: functions + add r8,r6,0x200000 \ r8: memtop - 2MiB above load address + \ r9 is up + mov r10,#0 \ r10: argc + mov r11,r2 \ r11: argv (kernel args) + mov r12,`initial-heap-size` \ r12: initial-heap-size + + b 'code start-forth \ Branch to the generic startup code +end-code + + +tag-file @ fclose tag-file off + +fload ${BP}/cpu/arm/saverom.fth \ Save the dictionary for standalone startup + +.( --- Saving beagle.rom --- ) cr " beagle.rom" $save-rom + +\ LICENSE_BEGIN +\ Copyright (c) 2009 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Property changes on: cpu/arm/beagle/beagle.bth ___________________________________________________________________ Added: svn:executable + *
Added: cpu/arm/beagle/build/Makefile =================================================================== --- cpu/arm/beagle/build/Makefile (rev 0) +++ cpu/arm/beagle/build/Makefile 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,59 @@ +OS := $(shell uname) + +BASEDIR= `(cd ../../../..; pwd;)` +TAGFILES= ../../build/*.tag *.tag +CLIENTDIR=../../../../clients +CLIENTPROGS= + +all: beagle.rom tags + +beagle.tag: beagle.rom + +tags: beagle.tag + @${BASEDIR}/forth/lib/toctags ${BASEDIR} ${TAGFILES} + +beagle.rom: FORCE build ${CLIENTPROGS} + ./build $@ + +../../${OS}/forth: + @make -C ../../${OS} forth + +../../build/inflate.bin: + @make -C ../../build inflate.bin + +build: ../../${OS}/forth + @ln -sf ../../${OS}/forth build + +clean: + rm -f *.dic *.log headers *~ *.elf *.di *.img builton.fth build *.rom *.version + +clean-all: clean + @make -C ../../build clean + @make -C ../../${OS} clean + +.PHONY: FORCE clean all clean-all + +# LICENSE_BEGIN +# Copyright (c) 2009 FirmWorks +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# LICENSE_END +
Property changes on: cpu/arm/beagle/build/Makefile ___________________________________________________________________ Added: svn:executable + *
Added: cpu/arm/beagle/traps.fth =================================================================== --- cpu/arm/beagle/traps.fth (rev 0) +++ cpu/arm/beagle/traps.fth 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,114 @@ +purpose: Save the processor state after an exception - hardware version +\ See license at end of file + +only forth also hidden also forth definitions + +\ The common subroutines on which this depends are defined in +\ cpu/arm/register.fth + +headerless + +\ This is the first part of the exception handling sequence and the last +\ half of the exception restart sequence. It is executed in exception state. + +label hw-save-state + \ On entry: r13: scratch r14: PC from old mode + + \ Check for second half of (restart, if so restore all the registers + \ from the save area and return from the exception. + + 'code (restart drop restart-offset + ( offset ) + adr r13,* \ Address of trap in (restart + + dec r14,1cell \ Point to the trapped instruction + cmp r13,r14 + + adr r13,'body main-task \ Get user pointer address + ldr r13,[r13] \ Get user pointer + ldr r13,[r13,`'user# cpu-state`] \ State save address + + beq 'body restart-common + + stmia r13,{r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12} + + mov r0,r13 \ Move cpu-state pointer into r0 + mov r4,#0 \ Set r4 to 0 to indicate no user abort + b 'body save-common +end-code + +defer init-vector-base +' noop to init-vector-base + +defer vector-base +0 value fixed-vector-base +' fixed-vector-base to vector-base + +: hw-install-handler ( handler exception# -- ) + vector-base swap la+ ( handler vector-adr ) + + \ Put "ldr pc,[pc,40-8]" in exception vector at vector-base + (exception# * 4 ) + h# e59ff038 over instruction! ( handler vector-adr ) + + \ Put handler address in address table at vector-base + 40 + (exception# * 4) + h# 40 + l! +; +: hw-catch-exception ( exception# -- ) hw-save-state swap install-handler ; + +\ Some ARM CPUs, such as CortexA8, let you move the vector base anywhere +code vector-base@ ( -- adr ) + psh tos,sp + mrc p15,0,tos,cr12,cr0,0 +c; + +code vector-base! ( adr --- ) + mcr p15,0,tos,cr12,cr0,0 + pop tos,sp +c; + +h# 80 buffer: ram-vector-base-buf +: move-vector-base ( -- ) ram-vector-base-buf h# 20 round-up vector-base! ; + +\ Execute this at compile time for processors that need it. +\ Ideally we would detect the vector base register at run time +\ but I don't know how yet. +: use-movable-vector-base ( -- ) + ['] vector-base@ to vector-base + ['] move-vector-base to init-vector-base +; + +: stand-init-io ( -- ) + stand-init-io + ['] (restart is restart + ['] hw-install-handler is install-handler + ['] hw-catch-exception is catch-exception + init-vector-base + catch-exceptions + 2 catch-exception \ Software interrupt (we don't catch this under DEMON) +; + +headers +only forth also definitions + +\ LICENSE_BEGIN +\ Copyright (c) 2009 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Property changes on: cpu/arm/beagle/traps.fth ___________________________________________________________________ Added: svn:executable + *
Added: cpu/arm/openmoko/build/Makefile =================================================================== --- cpu/arm/openmoko/build/Makefile (rev 0) +++ cpu/arm/openmoko/build/Makefile 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,58 @@ +OS := $(shell uname) + +BASEDIR= `(cd ../../../..; pwd;)` +TAGFILES= ../../build/*.tag *.tag +CLIENTDIR=../../../../clients +CLIENTPROGS= + +all: openmoko.rom tags + +openmoko.tag: openmoko.rom + +tags: openmoko.tag + @${BASEDIR}/forth/lib/toctags ${BASEDIR} ${TAGFILES} + +openmoko.rom: FORCE build ${CLIENTPROGS} + ./build $@ + +../../${OS}/forth: + @make -C ../../${OS} forth + +../../build/inflate.bin: + @make -C ../../build inflate.bin + +build: ../../${OS}/forth + @ln -sf ../../${OS}/forth build + +clean: + rm -f *.dic *.log headers *~ *.elf *.di *.img builton.fth build *.rom *.version + +clean-all: clean + @make -C ../../build clean + @make -C ../../${OS} clean + +.PHONY: FORCE clean all clean-all + +# LICENSE_BEGIN +# Copyright (c) 2009 FirmWorks +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# LICENSE_END
Added: cpu/arm/openmoko/openmoko.bth =================================================================== --- cpu/arm/openmoko/openmoko.bth (rev 0) +++ cpu/arm/openmoko/openmoko.bth 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,100 @@ +purpose: Load file for OFW on ARM beagleboard +\ See license at end of file + +dictionary: ${BP}/cpu/arm/build/basefw.dic +command: &armforth &dictionary &this +build-now + +" beagle.tag" r/w create-file drop tag-file ! + +\ ' $report-name is include-hook + +h# 8.0000 constant initial-heap-size + +: (initial-heap) ( -- adr len ) limit initial-heap-size ; +' (initial-heap) to initial-heap + + +\ fload ${BP}/dev/diaguartbb.fth \ beagleboard UART3 +fload ${BP}/cpu/arm/beagle/diaguartbb.fth \ beagleboard UART3 +\ h# 50000000 to uart-base \ UART# base address on beagleboard +h# 50004000 to uart-base \ UART# base address on beagleboard +\ h# 50008000 to uart-base \ UART# base address on beagleboard + +fload ${BP}/forth/lib/sysuart.fth \ Set console I/O vectors to UART + +patch noop catch-exceptions stand-init-io +patch drop hw-catch-exception stand-init-io + +h# 5000.8000 value uart-base +: fifo-stat@ ( -- n ) uart-base h# 18 + l@ ; +: rxtx-stat@ ( -- n ) uart-base h# 10 + l@ ; + +\ Install the simple UART driver from the standalone I/O init chain +: stand-init-io ( -- ) + ( [char] A h# 5000.0023 c! ) [char] a h# 5000.0020 c! + ( [char] B h# 5000.4023 c! ) [char] b h# 5000.4020 c! + ( [char] C h# 5000.8023 c! ) [char] c h# 5000.8020 c! + begin again + stand-init-io +\ inituarts install-uart-io +; + +\ This is some glue code to convert the machine setup that QEMU gives us +\ to the setup that start-forth (see arm/boot.fth) wants. +\ We get here via a call instruction at origin+8, which is inserted below + +code stand-cold-code ( r0: 0 r1: board-id r2: &kernel-args lr: &aif_header+8c ) + here origin 8 + put-call \ Insert call instruction + + \ Put the arguments in safe registers + sub r6,lr,#0x8c \ r6 points to header (lr set by code at origin) + mov r7,#0 \ r7: functions + add r8,r6,0x200000 \ r8: memtop - 2MiB above load address + \ r9 is up + mov r10,#0 \ r10: argc + mov r11,r2 \ r11: argv (kernel args) + mov r12,`initial-heap-size` \ r12: initial-heap-size + +\ XXX FB hack +\ set r1,0x08800000 \ memtop of 2MB above load address +\ set r0,0x10000 +\ set r2,0xaa +\ begin +\ decs r0,1 +\ strgeb r2,[r1],#1 +\ < until + + b 'code start-forth \ Branch to the generic startup code +end-code + + +tag-file @ fclose tag-file off + +fload ${BP}/cpu/arm/saverom.fth \ Save the dictionary for standalone startup + +.( --- Saving openmoko.rom --- ) cr " openmoko.rom" $save-rom + +\ LICENSE_BEGIN +\ Copyright (c) 2009 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Modified: cpu/arm/traps.fth =================================================================== --- cpu/arm/traps.fth 2009-05-14 08:55:20 UTC (rev 1198) +++ cpu/arm/traps.fth 2009-05-24 11:01:02 UTC (rev 1199) @@ -36,20 +36,52 @@ b 'body save-common end-code
-: hw-install-handler ( handler exception# -- ) - \ Put "ldr pc,[pc,40-8]" in exception vector at 0 + (exception# * 4) - h# e59ff038 over /l* instruction! ( exception# ) +defer init-vector-base +' noop to init-vector-base
- \ Put handler address in address table at 40 + (exception# * 4) - h# 40 swap la+ l! +defer vector-base +0 value fixed-vector-base +' fixed-vector-base to vector-base + +: hw-install-handler ( handler exception# -- ) + vector-base swap la+ ( handler vector-adr ) + + \ Put "ldr pc,[pc,40-8]" in exception vector at vector-base + (exception# * 4 ) + h# e59ff038 over instruction! ( handler vector-adr ) + + \ Put handler address in address table at vector-base + 40 + (exception# * 4) + h# 40 + l! ; : hw-catch-exception ( exception# -- ) hw-save-state swap install-handler ;
+\ Some ARM CPUs, such as CortexA8, let you move the vector base anywhere +code vector-base@ ( -- adr ) + psh tos,sp + mrc p15,0,tos,cr12,cr0,0 +c; + +code vector-base! ( adr --- ) + mcr p15,0,tos,cr12,cr0,0 + pop tos,sp +c; + +h# 80 buffer: ram-vector-base-buf +: move-vector-base ( -- ) ram-vector-base-buf h# 20 round-up vector-base! ; + +\ Execute this at compile time for processors that need it. +\ Ideally we would detect the vector base register at run time +\ but I don't know how yet. +: use-movable-vector-base ( -- ) + ['] vector-base@ to vector-base + ['] move-vector-base to init-vector-base +; + : stand-init-io ( -- ) stand-init-io ['] (restart is restart ['] hw-install-handler is install-handler ['] hw-catch-exception is catch-exception + init-vector-base catch-exceptions 2 catch-exception \ Software interrupt (we don't catch this under DEMON) ; @@ -58,7 +90,7 @@ only forth also definitions
\ LICENSE_BEGIN -\ Copyright (c) 1997 FirmWorks +\ Copyright (c) 2009 FirmWorks \ \ Permission is hereby granted, free of charge, to any person obtaining \ a copy of this software and associated documentation files (the
Added: dev/omap/diaguart.fth =================================================================== --- dev/omap/diaguart.fth (rev 0) +++ dev/omap/diaguart.fth 2009-05-24 11:01:02 UTC (rev 1199) @@ -0,0 +1,64 @@ +purpose: Diagnostic (before console installation) access to serial port +\ See license at end of file + +\ For the OMAP's UART + +d# 48000000 constant uart-clock-frequency + +[ifndef] uart@ + +h# 49020000 value uart-base \ Virtual address of UART; set later +: uart@ ( reg# -- byte ) /l* uart-base + l@ ; \ Read from a UART register +: uart! ( byte reg# -- ) /l* uart-base + l! ; \ Write from a UART register + +[then] + +: baud ( baud-rate -- ) + uart-clock-frequency d# 16 / swap rounded-/ ( baud-rate-divisor ) + + begin 5 uart@ h# 40 and until \ Wait until transmit done + + 3 uart@ dup >r h# 80 or 3 uart! \ divisor latch access bit on + dup h# ff and 0 uart! 8 >> 1 uart! \ Write lsb and msb + r> 3 uart! \ Restore old state +; + +: inituarts ( -- ) +\ 3 3 uart! \ 8 bits, no parity +\ 7 2 uart! \ Clear and enable FIFOs +\ d# 38400 baud +\ d# 9600 baud +\ d# 115200 baud +; + +: ukey? ( -- flag ) 5 uart@ 1 and 0<> ; \ Test for rcv character +: uemit? ( -- flag ) 5 uart@ h# 20 and 0<> ; \ Test for xmit ready +: ubreak? ( -- flag ) 5 uart@ h# 10 and 0<> ; \ Test for received break +: clear-break ( -- ) 5 uart@ drop ; \ Clear break indication + +: ukey ( -- char ) begin ukey? until 0 uart@ ; \ Receive a character +: uemit ( char -- ) begin uemit? until 0 uart! ; \ Transmit a character + +\ LICENSE_BEGIN +\ Copyright (c) 2009 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Property changes on: dev/omap/diaguart.fth ___________________________________________________________________ Added: svn:executable + *
openfirmware@openfirmware.info