2019-01-04 23:37:16 +00:00
|
|
|
# Helper to allocate a stream on the heap.
|
|
|
|
|
|
|
|
== code
|
|
|
|
# instruction effective address register displacement immediate
|
|
|
|
# . op subop mod rm32 base index scale r32
|
|
|
|
# . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes
|
|
|
|
|
2020-04-03 07:19:31 +00:00
|
|
|
new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int, out: (addr handle stream _)
|
2019-10-16 02:35:19 +00:00
|
|
|
# . prologue
|
2019-08-26 18:55:26 +00:00
|
|
|
55/push-ebp
|
|
|
|
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
|
2019-01-04 23:37:16 +00:00
|
|
|
# . save registers
|
2020-03-22 19:11:49 +00:00
|
|
|
50/push-eax
|
2019-08-26 18:55:26 +00:00
|
|
|
52/push-edx
|
2020-04-03 07:19:31 +00:00
|
|
|
# var size/edx: int = elemsize*length (clobbering eax)
|
2019-08-26 18:55:26 +00:00
|
|
|
# . eax = elemsize
|
|
|
|
8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x10/disp8 . # copy *(ebp+16) to eax
|
|
|
|
# . eax *= length
|
|
|
|
31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . . # clear edx
|
2020-08-22 21:35:44 +00:00
|
|
|
f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 0xc/disp8 . # multiply *(ebp+12) into edx:eax
|
2019-01-04 23:37:16 +00:00
|
|
|
# . if overflow abort
|
2019-08-26 18:55:26 +00:00
|
|
|
81 7/subop/compare 3/mod/direct 2/rm32/edx . . . . . 0/imm32 # compare edx
|
2020-01-17 02:31:12 +00:00
|
|
|
75/jump-if-!= $new-stream:abort/disp8
|
2019-08-26 18:55:26 +00:00
|
|
|
# . edx = elemsize*length
|
|
|
|
89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . . # copy eax to edx
|
2020-04-03 07:19:31 +00:00
|
|
|
# var n/eax: int = size + 12 (for read, write and size)
|
2019-08-26 18:55:26 +00:00
|
|
|
05/add-to-eax 0xc/imm32
|
2020-03-22 19:11:49 +00:00
|
|
|
# allocate(ad, n, out)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . push args
|
2020-03-22 19:11:49 +00:00
|
|
|
ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20)
|
2019-08-26 18:55:26 +00:00
|
|
|
50/push-eax
|
|
|
|
ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . call
|
|
|
|
e8/call allocate/disp32
|
|
|
|
# . . discard args
|
2020-03-22 19:11:49 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
|
|
|
|
# eax = out->payload
|
|
|
|
8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x14/disp8 . # copy *(ebp+20) to eax
|
|
|
|
8b/copy 1/mod/*+disp8 0/rm32/eax . . . 0/r32/eax 4/disp8 . # copy *(eax+4) to eax
|
|
|
|
# skip payload->allocid
|
|
|
|
05/add-to-eax 4/imm32
|
2020-04-03 07:19:31 +00:00
|
|
|
# eax->size = size
|
2019-08-26 18:55:26 +00:00
|
|
|
89/copy 1/mod/*+disp8 0/rm32/eax . . . 2/r32/edx 8/disp8 . # copy edx to *(eax+8)
|
|
|
|
# clear-stream(eax)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . push args
|
2019-08-26 18:55:26 +00:00
|
|
|
50/push-eax
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . call
|
|
|
|
e8/call clear-stream/disp32
|
|
|
|
# . . discard args
|
2019-08-26 18:55:26 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
|
2019-01-04 23:37:16 +00:00
|
|
|
$new-stream:end:
|
|
|
|
# . restore registers
|
2019-08-26 18:55:26 +00:00
|
|
|
5a/pop-to-edx
|
2020-03-22 19:11:49 +00:00
|
|
|
58/pop-to-eax
|
2019-10-16 02:35:19 +00:00
|
|
|
# . epilogue
|
2019-08-26 18:55:26 +00:00
|
|
|
89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp
|
|
|
|
5d/pop-to-ebp
|
2019-01-04 23:37:16 +00:00
|
|
|
c3/return
|
|
|
|
|
|
|
|
$new-stream:abort:
|
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.
So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.
A couple of things have gotten dropped in this process:
- I had old ways to run on just a Linux kernel, or with a Soso kernel.
No more.
- I had some old tooling for running a single test at the cursor. I haven't
used that lately. Maybe I'll bring it back one day.
The reorg isn't done yet. Still to do:
- redo documentation everywhere. All the README files, all other markdown,
particularly vocabulary.md.
- clean up how-to-run comments at the start of programs everywhere
- rethink what to do with the html/ directory. Do we even want to keep
supporting it?
In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-04 06:09:50 +00:00
|
|
|
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "new-stream: size too large" 3 0) # 3=cyan
|
|
|
|
{
|
|
|
|
eb/jump loop/disp8
|
|
|
|
}
|
2019-01-04 23:37:16 +00:00
|
|
|
# never gets here
|
|
|
|
|
|
|
|
test-new-stream:
|
2019-10-16 02:35:19 +00:00
|
|
|
# . prologue
|
2019-08-26 18:55:26 +00:00
|
|
|
55/push-ebp
|
|
|
|
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
|
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.
So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.
A couple of things have gotten dropped in this process:
- I had old ways to run on just a Linux kernel, or with a Soso kernel.
No more.
- I had some old tooling for running a single test at the cursor. I haven't
used that lately. Maybe I'll bring it back one day.
The reorg isn't done yet. Still to do:
- redo documentation everywhere. All the README files, all other markdown,
particularly vocabulary.md.
- clean up how-to-run comments at the start of programs everywhere
- rethink what to do with the html/ directory. Do we even want to keep
supporting it?
In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-04 06:09:50 +00:00
|
|
|
# var ad/ecx: allocation-descriptor containing 16 bytes
|
|
|
|
# . var end/ecx: (addr byte)
|
|
|
|
89/<- %ecx 4/r32/esp
|
|
|
|
# . var start/edx: (addr byte) = end - 32
|
|
|
|
81 5/subop/subtract %esp 0x20/imm32
|
|
|
|
89/<- %edx 4/r32/esp
|
|
|
|
# . ad = {start, end}
|
2019-08-26 18:55:26 +00:00
|
|
|
51/push-ecx
|
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.
So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.
A couple of things have gotten dropped in this process:
- I had old ways to run on just a Linux kernel, or with a Soso kernel.
No more.
- I had some old tooling for running a single test at the cursor. I haven't
used that lately. Maybe I'll bring it back one day.
The reorg isn't done yet. Still to do:
- redo documentation everywhere. All the README files, all other markdown,
particularly vocabulary.md.
- clean up how-to-run comments at the start of programs everywhere
- rethink what to do with the html/ directory. Do we even want to keep
supporting it?
In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-04 06:09:50 +00:00
|
|
|
52/push-edx
|
|
|
|
89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx
|
2019-08-26 18:55:26 +00:00
|
|
|
# var start/edx = ad->curr
|
|
|
|
8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . . # copy *ecx to edx
|
2020-03-22 19:11:49 +00:00
|
|
|
# var h/ebx: (handle stream byte)
|
|
|
|
68/push 0/imm32
|
|
|
|
68/push 0/imm32
|
|
|
|
89/copy 3/mod/direct 3/rm32/ebx . . . 4/r32/esp . . # copy esp to ebx
|
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.
So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.
A couple of things have gotten dropped in this process:
- I had old ways to run on just a Linux kernel, or with a Soso kernel.
No more.
- I had some old tooling for running a single test at the cursor. I haven't
used that lately. Maybe I'll bring it back one day.
The reorg isn't done yet. Still to do:
- redo documentation everywhere. All the README files, all other markdown,
particularly vocabulary.md.
- clean up how-to-run comments at the start of programs everywhere
- rethink what to do with the html/ directory. Do we even want to keep
supporting it?
In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-04 06:09:50 +00:00
|
|
|
# new-stream(ad, 3, 2, h)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . push args
|
2020-03-22 19:11:49 +00:00
|
|
|
53/push-ebx
|
2019-01-04 23:37:16 +00:00
|
|
|
68/push 2/imm32
|
|
|
|
68/push 3/imm32
|
2019-08-26 18:55:26 +00:00
|
|
|
51/push-ecx
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . call
|
|
|
|
e8/call new-stream/disp32
|
|
|
|
# . . discard args
|
2020-03-22 19:11:49 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp
|
|
|
|
# eax = out->payload
|
|
|
|
8b/copy 1/mod/*+disp8 3/rm32/ebx . . . 0/r32/eax 4/disp8 . # copy *(ebx+4) to eax
|
2019-08-26 18:55:26 +00:00
|
|
|
# check-ints-equal(eax, edx, msg)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . push args
|
|
|
|
68/push "F - test-new-stream: returns current pointer of allocation descriptor"/imm32
|
2019-08-26 18:55:26 +00:00
|
|
|
52/push-edx
|
|
|
|
50/push-eax
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . call
|
|
|
|
e8/call check-ints-equal/disp32
|
|
|
|
# . . discard args
|
2019-08-26 18:55:26 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
|
2020-03-22 19:11:49 +00:00
|
|
|
# skip payload->allocid
|
|
|
|
05/add-to-eax 4/imm32
|
2020-04-03 19:35:53 +00:00
|
|
|
# check-ints-equal(eax->size, 6, msg)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . push args
|
2020-04-03 19:35:53 +00:00
|
|
|
68/push "F - test-new-stream: sets size correctly"/imm32
|
2019-01-04 23:37:16 +00:00
|
|
|
68/push 6/imm32
|
2019-08-26 18:55:26 +00:00
|
|
|
ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . . 8/disp8 # push *(eax+8)
|
2019-01-04 23:37:16 +00:00
|
|
|
# . . call
|
|
|
|
e8/call check-ints-equal/disp32
|
|
|
|
# . . discard args
|
2019-08-26 18:55:26 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
|
2019-01-04 23:37:16 +00:00
|
|
|
# the rest is delegated to clear-stream() so we won't bother checking it
|
2020-03-22 19:11:49 +00:00
|
|
|
# . reclaim locals
|
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.
So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.
A couple of things have gotten dropped in this process:
- I had old ways to run on just a Linux kernel, or with a Soso kernel.
No more.
- I had some old tooling for running a single test at the cursor. I haven't
used that lately. Maybe I'll bring it back one day.
The reorg isn't done yet. Still to do:
- redo documentation everywhere. All the README files, all other markdown,
particularly vocabulary.md.
- clean up how-to-run comments at the start of programs everywhere
- rethink what to do with the html/ directory. Do we even want to keep
supporting it?
In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
2021-03-04 06:09:50 +00:00
|
|
|
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x30/imm32 # add to esp
|
2019-10-16 02:35:19 +00:00
|
|
|
# . epilogue
|
2019-08-26 18:55:26 +00:00
|
|
|
89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp
|
|
|
|
5d/pop-to-ebp
|
2019-01-04 23:37:16 +00:00
|
|
|
c3/return
|
|
|
|
|
|
|
|
# . . vim:nowrap:textwidth=0
|