~vdupras/tumbleforth

047b75f5c6867d207e0777f399507ca89afe24aa — Virgil Dupras 10 months ago f969573
Replace targz bundles with link to git repo
M 01-duskcc/01-buckleup.md => 01-duskcc/01-buckleup.md +3 -2
@@ 31,7 31,8 @@ compiled and then ran?
        return foo(42, 12);
    }

*Code in this article is also available in [this tarball][srctgz].*
*Code in this article is also available in
[Tumble Forth's git repository][src].*

So, you know that you can save this to `buckleup.c`, then run `cc -o buckleup
buckleup.c` and then run the resulting `./buckleup` executable, which will exit


@@ 211,7 212,7 @@ we'll talk later.

[collapseos]: http://collapseos.org
[duskos]: http://duskos.org
[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/01-buckleup.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[elf]: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
[ccall]: https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI
[nasm]: https://www.nasm.us/

M 01-duskcc/02-baremetal.md => 01-duskcc/02-baremetal.md +3 -2
@@ 69,7 69,8 @@ Enough babbling, let’s flex our fingers and get going.

## Hello World

*Code in this article is also available in [a tarball][srctgz].*
*Code in this article is also available in
[Tumble Forth's git repository][src].*

We’re going to print “Hello World!” on a bare metal PC using BIOS functions
through a boot sector we’ll assemble using NASM. The listing is so simple that


@@ 246,7 247,7 @@ world of Forth, which OSdev doesn’t cover.

[^16]: Although I’d be happy if it did!

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/02-baremetal.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 01-buckleup.html
[nextup]: 03-onesector.html
[qemu]: https://www.qemu.org/

M 01-duskcc/03-onesector.md => 01-duskcc/03-onesector.md +4 -4
@@ 59,11 59,11 @@ have to worry about CHS addressing for now as we will always read from cylinder

*We’re about to start talking about code. Up until now, all code was inlined in
the articles, but it’s becoming too voluminous for this. The code associated
with this article is available in [a tarball][srctgz] which you should use in
order to follow along.*
with this article is available in [Tumble Forth's git repository][src] which
you should use in order to follow along.*

We have a source? We have a destination? Then we know what to do, let’s write
it. Oh wait, [I wrote it for you already][srctgz]. If you run this (with `make
it. Oh wait, [I wrote it for you already][src]. If you run this (with `make
run`), you’ll have a result similar to the previous “Hello World!”, but this
time, the code that’s executed comes from the second sector of the disk.



@@ 147,7 147,7 @@ number would need to be 0xaa55 to have the intended effect.
[^6]: You think that’s complicated? Just wait until you try to get in protected
mode!

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/03-onesector.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 02-baremetal.html
[nextup]: 04-wordsshell.html
[sectorforth]: https://github.com/cesarblum/sectorforth

M 01-duskcc/04-wordsshell.md => 01-duskcc/04-wordsshell.md +2 -2
@@ 56,7 56,7 @@ interactive.

Our input stream will, for now, feed itself directly from the horse’s mouth:
the keyboard. As you can see from the [implementation I’ve written for
you][srctgz], the BIOS makes it quite straightforward.
you][src], the BIOS makes it quite straightforward.

If we begin reading the code at the `loop` label in `kernel.asm`, we see that
`readword` is repeatedly called, and if we look at that routine, we see that


@@ 161,7 161,7 @@ prefer that order. More on this later.
[^6]: With the contents having been loaded from the bootloader.
[^7]: "jb” means “jump if dest operand is below source operand”.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/04-wordsshell.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 03-onesector.html
[nextup]: 05-dolookup.html
[basic]: https://en.wikipedia.org/wiki/BASIC_interpreter

M 01-duskcc/05-dolookup.md => 01-duskcc/05-dolookup.md +2 -2
@@ 47,7 47,7 @@ so you might as well get used to it.

All Forths start with a system dictionary which is often assembled in their
predefined structure directly in the code. If you look at the [implementation
I’ve written for you][srctgz], you’ll see that this is what I’ve done too,
I’ve written for you][src], you’ll see that this is what I’ve done too,
starting at the `“; Dictionary”` comment. Let’s look at the first entry
(`hellomsg` isn’t part of the dictionary entry):



@@ 190,7 190,7 @@ centered around colors!
word “user” really doesn’t convey how intensely the creativity of the person at
the keyboard is being solicited. You’re like Tank in the Matrix!

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/05-dolookup.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 04-wordsshell.html
[nextup]: 06-taletwostacks.html
[ll]: https://en.wikipedia.org/wiki/Linked_list

M 01-duskcc/06-taletwostacks.md => 01-duskcc/06-taletwostacks.md +2 -2
@@ 95,7 95,7 @@ documentation for a word will often reference those names. For example, for

## Registers are getting tight

If you look at the [Parameter stack I’ve implemented for you][srctgz], you’ll
If you look at the [Parameter stack I’ve implemented for you][src], you’ll
see that I assigned `PS` to the `BP` register, initializing it to 0xf800[^6].
This means that across the whole code, this register’s value must be preserved
at all times. So far, we had enough registers to go around merrily, without


@@ 280,7 280,7 @@ personal convention.
used.
[^11]: In Forth speak, the “!” symbol means “store”.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/06-taletwostacks.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 05-dolookup.html
[nextup]: 07-babywalk.html
[ccall]: https://en.wikipedia.org/wiki/X86_calling_conventions

M 01-duskcc/07-babywalk.md => 01-duskcc/07-babywalk.md +2 -2
@@ 34,7 34,7 @@ this data properly so that it can be reused where it must.
In Forth speak, adding something to that heap is called “write” and the
associated symbol for its action is “,” (the comma).

If you look at [the implementation I’ve written for you][srctgz], you’ll see
If you look at [the implementation I’ve written for you][src], you’ll see
that I’ve added a new `here` variable which is initialized with the value of
the `herestart` label, which is simply placed at the very end of the code[^3].



@@ 183,7 183,7 @@ unfinished, and thus broken. With no `ret` to stop the call chain, calling the
broken word will result in executing uninitialized memory, which means
“fireworks!”. Our baby Forth isn’t mistake-friendly!

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/07-babywalk.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 06-taletwostacks.html
[nextup]: 08-immediate.html
[brad]: https://www.bradrodriguez.com/papers/moving1.htm

M 01-duskcc/08-immediate.md => 01-duskcc/08-immediate.md +2 -2
@@ 59,7 59,7 @@ dictionary entry with a name inside parentheses, such as `(br)`, `(?br)`,
more compiled parameter next to them. But providing that we follow their
argument structure, they can be written in a word definition.

If you look at [the implementation I’ve written for you][srctgz], you’ll see
If you look at [the implementation I’ve written for you][src], you’ll see
that I’ve added a new `litn` routine. Although it’s not wrapped in a word[^3],
it’s what we could call a “parens word". Its goal is to read the parameter that
has been written next to its call and push it to `PS`. How do we access this


@@ 215,7 215,7 @@ to your will!
[^9]: and I’f be very happy if you were! Let me know if you’re stuck at some
point.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/08-immediate.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 07-babywalk.html
[nextup]: 09-dusktillc.html
[starting]: https://www.forth.com/starting-forth/

M 01-duskcc/09-dusktillc.md => 01-duskcc/09-dusktillc.md +2 -2
@@ 290,7 290,7 @@ You can now see, with `.S`, that we don’t leak to `PS` anymore! This completes
our extremely minimal i386 assembler. We’ll be able to use it in our C
compiler, when comes the time of generating the code.

*The source code for our toy assembler can be [downloaded here][srctgz]*
*The source code for our toy assembler can be [downloaded here][src]*

## Going further



@@ 327,7 327,7 @@ operands. For example, `“add [esi], [eax]”` is impossible. Therefore, one of
the operands is always “direct”. `reg` is the one.
[^6]: Let’s ignore the imm8 optimization for now.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/09-dusktillc.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 08-immediate.html
[nextup]: 10-beast.html
[dusk]: http://duskos.org/

M 01-duskcc/10-beast.md => 01-duskcc/10-beast.md +0 -1
@@ 311,7 311,6 @@ foo.c. Because our tokenizer is minimal, we can afford to stay simple.
[^6]: it only works for a single character.
[^7]: a structbind to the `Scratchpad` struct.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/10-beast.tar.gz
[prev]: 09-dusktillc.html
[upnext]: 11-eye.html
[usage]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/doc/usage.txt

M 01-duskcc/11-eye.md => 01-duskcc/11-eye.md +2 -2
@@ 20,7 20,7 @@ hardcode for the `int` type. Therefore, all we need to do is to consume the
token and assert that it's `int`.

This task is of course trivial, but what is less trivial is to design the API
for our C compiler. [My proposition][srctgz] is this, which you can put in a
for our C compiler. [My proposition][src] is this, which you can put in a
new unit called `mycc.fs`:

    ?f<< myasm.fs


@@ 229,6 229,6 @@ generation, using an Abstract Syntax Tree representation of the code in between.
We don't (DuskCC doesn't either). We generate code directly as we parse. It
comes with a few drawbacks, but results in a much simpler code.

[srctgz]: https://tumbleforth.hardcoded.net/01-duskcc/11-eye.tar.gz
[src]: https://git.sr.ht/~vdupras/tumbleforth
[prev]: 10-beast.html
[str]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/doc/lib/str.txt

M Makefile => Makefile +3 -9
@@ 1,5 1,5 @@
STORY_ARCS = 01-duskcc
ARTICLES_WITH_TGZ = \
ARTICLES = \
	01-duskcc/01-buckleup \
	01-duskcc/02-baremetal \
	01-duskcc/03-onesector \


@@ 11,21 11,15 @@ ARTICLES_WITH_TGZ = \
	01-duskcc/09-dusktillc \
	01-duskcc/10-beast \
	01-duskcc/11-eye
ARTICLES = \
	$(ARTICLES_WITH_TGZ)

OUTHTML = $(addsuffix .html, $(ARTICLES))
OUTTGZ = $(addsuffix .tar.gz, $(ARTICLES_WITH_TGZ))

.PHONY: all
all: $(OUTHTML) $(OUTTGZ)
all: $(OUTHTML)

$(OUTHTML): %.html: %.md
	markdown_py -x footnotes $< | cat header.html - footer.html > $@

$(OUTTGZ): %.tar.gz: %
	tar czf $@ $<

.PHONY: clean
clean:
	rm -f $(OUTHTML) $(OUTTGZ)
	rm -f $(OUTHTML)