duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 5d674083b30bf2bd80268ff855714e33615f3d5c
parent 1808e6d3fdb49c9aad9179d544dd5e71736c052d
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 12 Jun 2023 14:27:26 -0400

rpi: move drivers and glue code at more appropriate places

Now, the only difference between bootlo.fs and rpiboot.fs are the few pushret,
and popret, I needed to add to make it work.

Diffstat:
Afs/drv/rpi/uart.fs | 38++++++++++++++++++++++++++++++++++++++
Mfs/xcomp/arm/rpi/build.fs | 2++
Afs/xcomp/arm/rpi/glue.fs | 23+++++++++++++++++++++++
Mfs/xcomp/rpiboot.fs | 59+----------------------------------------------------------
4 files changed, 64 insertions(+), 58 deletions(-)

diff --git a/fs/drv/rpi/uart.fs b/fs/drv/rpi/uart.fs @@ -0,0 +1,38 @@ +\ Raspberry Pi model 1 UART + +$20000000 const MMIO_BASE +MMIO_BASE $200000 + const GPIO_BASE +GPIO_BASE $94 + const GPPUD +GPIO_BASE $98 + const GPPUDCLK0 +GPIO_BASE $1000 + const UART0_BASE +UART0_BASE const UART0_DR +UART0_BASE $18 + const UART0_FR +UART0_BASE $24 + const UART0_IBRD +UART0_BASE $28 + const UART0_FBRD +UART0_BASE $2c + const UART0_LCRH +UART0_BASE $30 + const UART0_CR +UART0_BASE $38 + const UART0_IMSC +UART0_BASE $44 + const UART0_ICR + +: delay ( n -- ) begin 1- ?dup not until ; +: uart$ + 0 UART0_CR ! \ Disable UART0 + 0 GPPUD ! 100 delay \ Disable pull up/down for all GPIO pins + $c000 GPPUDCLK0 ! 100 delay \ Disable pull up/down for pins 14,15 + \ Write 0 to GPPUD and GPPUDCLK0 to make it take effect. + 0 GPPUD ! 0 GPPUDCLK0 ! + $7ff UART0_ICR ! \ Clear pending interrupts. + \ Set integer & fractional part of baud rate. + \ UART_CLOCK on rpi1 is 48Mhz + \ Divider = UART_CLOCK/(16 * Baud) + \ Fraction part register = 64th of the unit + \ Baud = 115200. + \ Divider = 48000000 / (16 * 115200) = 26.042 + 26 UART0_IBRD ! + 3 UART0_FBRD ! + $70 UART0_LCRH ! \ Enable FIFO & 8N1 + $7f2 UART0_IMSC ! \ Mask all interrupts + $301 UART0_CR ! ; \ Enable UART0, receive & transfer part of UART. + +: uart! begin UART0_FR @ $20 and not until UART0_DR ! ; +: uart@ begin UART0_FR @ $10 and not until UART0_DR c@ ; diff --git a/fs/xcomp/arm/rpi/build.fs b/fs/xcomp/arm/rpi/build.fs @@ -14,4 +14,6 @@ org value kernel ." Putting kernel in place\n" kernel kernellen V1 IO :write S" /xcomp/rpiboot.fs" V1 spitfile + S" /drv/rpi/uart.fs" V1 spitfile + S" /xcomp/arm/rpi/glue.fs" V1 spitfile r> IO :flush ; diff --git a/fs/xcomp/arm/rpi/glue.fs b/fs/xcomp/arm/rpi/glue.fs @@ -0,0 +1,23 @@ +struct[ Foo + sfield bar + sfield baz +]struct + +extends Foo struct[ Bar + sfield zzz +]struct + +: foo ." foo!" ; +: bar ." bar!" ; +: prompt ." Hello World!" ; + +create data 'A' , 'X' , 'Z' , + +data structbind Bar mybar +: hey mybar zzz emit ; + +uart$ +' uart! ' emit realias +prompt +' uart@ ' in< realias + diff --git a/fs/xcomp/rpiboot.fs b/fs/xcomp/rpiboot.fs @@ -248,47 +248,9 @@ code [c]? ( c a u -- i ) drop, then 8 ps+, -1 LIT>W, exit, -\ For RPI model 1 -$20000000 const MMIO_BASE -MMIO_BASE $200000 + const GPIO_BASE -GPIO_BASE $94 + const GPPUD -GPIO_BASE $98 + const GPPUDCLK0 -GPIO_BASE $1000 + const UART0_BASE -UART0_BASE const UART0_DR -UART0_BASE $18 + const UART0_FR -UART0_BASE $24 + const UART0_IBRD -UART0_BASE $28 + const UART0_FBRD -UART0_BASE $2c + const UART0_LCRH -UART0_BASE $30 + const UART0_CR -UART0_BASE $38 + const UART0_IMSC -UART0_BASE $44 + const UART0_ICR - -: delay ( n -- ) begin 1- ?dup not until ; -: uartinit - 0 UART0_CR ! \ Disable UART0 - 0 GPPUD ! 100 delay \ Disable pull up/down for all GPIO pins - $c000 GPPUDCLK0 ! 100 delay \ Disable pull up/down for pins 14,15 - \ Write 0 to GPPUD and GPPUDCLK0 to make it take effect. - 0 GPPUD ! 0 GPPUDCLK0 ! - $7ff UART0_ICR ! \ Clear pending interrupts. - \ Set integer & fractional part of baud rate. - \ UART_CLOCK on rpi1 is 48Mhz - \ Divider = UART_CLOCK/(16 * Baud) - \ Fraction part register = 64th of the unit - \ Baud = 115200. - \ Divider = 48000000 / (16 * 115200) = 26.042 - 26 UART0_IBRD ! - 3 UART0_FBRD ! - $70 UART0_LCRH ! \ Enable FIFO & 8N1 - $7f2 UART0_IMSC ! \ Mask all interrupts - $301 UART0_CR ! ; \ Enable UART0, receive & transfer part of UART. - -: emit begin UART0_FR @ $20 and not until UART0_DR ! ; -: key begin UART0_FR @ $10 and not until UART0_DR c@ ; - \ Emitting $20 const SPC $0d const CR $0a const LF $08 const BS $1b const ESC -\ alias drop emit +alias drop emit : nl> LF emit ; : spc> SPC emit ; :realias rtype ( a u ) for c@+ emit next drop ; : stype ( str -- ) c@+ rtype ; @@ -512,22 +474,3 @@ extends IO struct[ File : \s console readio IO :close ; : fload ( fs id -- ) dup floaded, swap Filesystem :open IO :interpret File :close ; -struct[ Foo - sfield bar - sfield baz -]struct - -extends Foo struct[ Bar - sfield zzz -]struct - -: foo ." foo!" ; -: bar ." bar!" ; -: prompt ." Hello World!" ; - -create data 'A' , 'X' , 'Z' , - -data structbind Bar mybar -: hey mybar zzz emit ; - -uartinit prompt ' key ' in< realias