~vdupras/duskos

ad622d2761e987fc2cb3e213190be5439dd5f2b5 — Virgil Dupras 2 years ago 3577972 nasm
Transition to x86 asm complete
5 files changed, 24 insertions(+), 78 deletions(-)

M Makefile
M README.md
M boot.fs
D boot2.fs
M dusk.asm
M Makefile => Makefile +1 -1
@@ 6,7 6,7 @@ xcomp.asm: dusk.asm xcomp.txt f2asm.py aliases.txt
	cat dusk.asm >> $@ 
	./f2asm.py xcomp.txt >> $@

dusk: xcomp.asm boot2.fs
dusk: xcomp.asm boot.fs
	nasm -f elf32 xcomp.asm -o dusk.o
	ld -m elf_i386 dusk.o -o $@
	

M README.md => README.md +14 -14
@@ 78,22 78,20 @@ fun...

The roadmap so far is, of course, very fuzzy, but here's what I have in mind:

1. Have a 32-bit Forth written in C run on top of POSIX.
2. Tweak the VM to allow arbitrary native binary to be embedded into into words
   (something that isn't possible in Collapse OS' CVM right now).
3. Add a "CC" word to compile C code into words using the system C compiler.
4. Integrate a C compiler into the system to replace the system C compiler.
1. Have a 32-bit Forth written in x86 run on top of of a Linux system.
2. Add a "CC" word to compile C code into words using the system C compiler.
3. Integrate a C compiler into the system to replace the system C compiler.
   qbe? ack? a Forth one? to be determined.
5. Self-host.
6. Run as PID 1 on top of a Linux or BSD kernel.
7. Target a machine and have it run bare metal on it.
8. Steal drivers from Linux and/or BSD kernels to widen hardware support.
9. Port exiting POSIX applications so that Dusk OS fulfills its stated goals.
4. Self-host.
5. Run as PID 1 on top of a Linux or BSD kernel.
6. Target a machine and have it run bare metal on it.
7. Steal drivers from Linux and/or BSD kernels to widen hardware support.
8. Port exiting POSIX applications so that Dusk OS fulfills its stated goals.

## Status

Not much so far. Step 1 of the roadmap above is well underway. Development
happens on [sourcehut][3].
We have a function Forth prompt and currently working on step 2 of the roadmap
above. Development happens on [sourcehut][3].

Unlike Collapse OS which is a personal effort and doesn't lend itself well to
collaboration, Dusk OS' wider scope makes it fitting for a collaborative effort.


@@ 104,11 102,13 @@ Let's discuss this on its [public mailing list][4].
To build Dusk OS, you need:

* GNU Make
* A C99 compiler
* GNU binutils
* nasm
* Python 3
* A x86-compatible Linux kernel to run this on

Run `make` and then run `./dusk`. You'll get a prompt. Look at `xcomp.txt` and
`boot.fs` to have an idea of the vocabyulary available. Type `bye` to quit.
`boot.fs` to have an idea of the vocabulary available. Type `bye` to quit.

[1]: http://collapseos.org
[2]: http://collapseos.org/why.html

M boot.fs => boot.fs +8 -7
@@ 1,18 1,17 @@
: immediate current 1- dup c@ $80 or swap c! ;
: ['] ' litn ; immediate
: compile ' litn ['] call, call, ; immediate
: [compile] ' call, ; immediate
: if [compile] (?br) here 4 allot ; immediate
: if compile (?br) here 4 allot ; immediate
: then here swap ! ; immediate
: else [compile] (br) here 4 allot here rot ! ; immediate
: else compile (br) here 4 allot here rot ! ; immediate
: begin here ; immediate
: again [compile] (br) , ; immediate
: until [compile] (?br) , ; immediate
: next [compile] (next) , ; immediate
: again compile (br) , ; immediate
: until compile (?br) , ; immediate
: next compile (next) , ; immediate
: \ begin in< LF = until ; immediate
\ hello, this is a comment!
: ," begin in< dup '"' = if drop exit then c, again ;
: S" [compile] (br) here 4 allot here ," tuck here -^ swap
: S" compile (br) here 4 allot here ," tuck here -^ swap
  here swap ! swap litn litn ; immediate
: S= \ sa1 sl1 sa2 sl2 -- f
  rot over = if \ same len, s2 s1 l )


@@ 33,6 32,8 @@
: .S ( -- )
  S" SP " stype scnt .x spc> S" RS " stype rcnt .x spc>
  S" -- " stype stack? psdump ;
: create entry compile (cell) ;
: value entry compile (val) , ;
64 value LNSZ 
create in( LNSZ allot
: in) in( 64 + ;

D boot2.fs => boot2.fs +0 -55
@@ 1,55 0,0 @@
: immediate current 1- dup c@ $80 or swap c! ;
: ['] ' litn ; immediate
: compile ' litn ['] call, call, ; immediate
: if compile (?br) here 4 allot ; immediate
: then here swap ! ; immediate
: else compile (br) here 4 allot here rot ! ; immediate
: begin here ; immediate
: again compile (br) , ; immediate
: until compile (?br) , ; immediate
: next compile (next) , ; immediate
: \ begin in< LF = until ; immediate
\ hello, this is a comment!
: ," begin in< dup '"' = if drop exit then c, again ;
: S" compile (br) here 4 allot here ," tuck here -^ swap
  here swap ! swap litn litn ; immediate
: S= \ sa1 sl1 sa2 sl2 -- f
  rot over = if \ same len, s2 s1 l )
  []= else drop 2drop 0 then ;
: waitw \ sa sl --
  begin 2dup word S= until 2drop ;
: ( S" )" waitw ; immediate
( hello, another comment! )
: <> ( n n -- l h ) 2dup > if swap then ;
: min <> drop ; : max <> nip ;
: fill ( a u b -- *A* ) rot> >r >A begin dup Ac!+ next drop ;
: .h $f and tbl-0-f + c@ emit ;
: .x dup >> >> >> >> .h .h ;
: nl> CR emit LF emit ; : spc> SPC emit ;
: psdump scnt not if exit then
  scnt >A begin dup .x spc> >r scnt not until
  begin r> scnt A> = until ;
: .S ( -- )
  S" SP " stype scnt .x spc> S" RS " stype rcnt .x spc>
  S" -- " stype stack? psdump ;
: create entry compile (cell) ;
: value entry compile (val) , ;
64 value LNSZ 
create in( LNSZ allot
: in) in( 64 + ;
: bs? BS over = swap $7f = or ;
: lntype ( ptr c -- ptr+1 f )
  dup bs? if ( ptr c )
    drop dup in( > if 1- BS emit then spc> BS emit 0
  else ( ptr c ) \ non-BS
    dup SPC < if drop dup in) over - 0 fill 1 else
      tuck emit c!+ dup in) = then then ;
: rdln S"  ok" stype nl> in( begin key lntype until drop nl> ;
: rdln<? ( -- c-or-0 )
  in> in) < if in> c@+ swap to in> else 0 then ;
: rdln< ( -- c ) rdln<? ?dup not if
    rdln in( to in> SPC then ;
: rdln$ ['] rdln< to in< ['] rdln<? to in<?
  in) to in> 'curword 6 0 fill ;
: init S" Dusk OS" stype rdln$ ;
init

M dusk.asm => dusk.asm +1 -1
@@ 110,7 110,7 @@ ps_top:
herestart: resb MEMSIZE

SECTION .data
bootsrc: incbin "boot2.fs"
bootsrc: incbin "boot.fs"
SECTION .text

GLOBAL _start