update docs about library jump table

This commit is contained in:
Irmen de Jong
2025-04-18 23:16:08 +02:00
parent bd1894580e
commit 5a7bc04816
4 changed files with 27 additions and 23 deletions
+3 -3
View File
@@ -33,9 +33,9 @@ main {
; NOTE: the compiler has inserted a single JMP instruction at the start of the 'main' block, that jumps to the start() routine.
; This is convenient because the rest of the jump table simply follows it,
; making the first jump neatly be the required initialization routine for the library (initializing variables and BSS region).
; btw, ${'$'}4c = opcode for JMP.
${'$'}4c00, &library.func1,
${'$'}4c00, &library.func2,
; btw, $4c = opcode for JMP.
$4c00, &library.func1,
$4c00, &library.func2,
]
sub start() {
+9 -10
View File
@@ -187,16 +187,15 @@ Here is the small example library that was used in the example at the beginning
main {
; Create a jump table as first thing in the library.
uword[] @shared @nosplit jumptable = [
; NOTE: the compiler has inserted a single JMP instruction at the start
; of the 'main' block, that jumps to the start() routine.
; This is convenient because the rest of the jump table simply follows it,
; making the first jump neatly be the required initialization routine
; for the library (initializing variables and BSS region).
; Btw, $4c = opcode for JMP.
$4c00, &library.func1,
$4c00, &library.func2,
]
; NOTE: the compiler has inserted a single JMP instruction at the start
; of the 'main' block, that jumps to the start() routine.
; This is convenient because the rest of the jump table simply follows it,
; making the first jump neatly be the required initialization routine
; for the library (initializing variables and BSS region).
%jmptable (
library.func1,
library.func2,
)
sub start() {
; has to be here for initialization
+14 -10
View File
@@ -369,19 +369,23 @@ Directives
This builds a compact "jump table" meant to be used in libraries.
You can put the elements of the table on different lines if you wish.
It outputs a sequence of JMP machine code instructions jumping to each
of the given subroutines in the jmptable list::
jmp lib.routine1
jmp lib.routine2
...
of the given subroutines in the jmptable list in order. This way the routines in the library
can be accessed using a neat fixed list of offsets at the beginning of the library code,
and the actual implementation of those routines can be changed in later versions of the library
without existing callers noticing anything.
This is usually put at the top of the main block so that it ends up at the beginning
of the library file. *Note:* the compiler may still insert the required bootstrapping
code in front of it, which in the case of a library, is the JMP to the start routine
of the library file. *Note:* the compiler will still insert the required bootstrapping
code in front of it, which in the case of a library, is the single JMP to the start routine
which also does some variable initialization and BSS area clearing. So the first JMP
in the jumptable will then end up at offset 3 in the resulting binary. You could consider
the JMP start that prog8 inserts as the implicit first entry of the jump table.
Check the generated assembly code to see exactly what's up.
in the jumptable list will actually end up at offset 3 in the resulting binary program.
The ``jmp start`` instruction that prog8 inserts ends up as the implicit first entry of the
actual jump table instructions list that is put into the resulting library program::
jmp start ; first program instruction always generated by prog8
jmp lib.routine1 ; jump table first entry
jmp lib.routine2 ; jump table second entry
...
.. data:: %launcher <type>
+1
View File
@@ -23,6 +23,7 @@ Future Things and Ideas
- make a form of "manual generics" possible like: varsub routine(T arg)->T where T is expanded to a specific type
(this is already done hardcoded for several of the builtin functions)
- [much work:] more support for (64tass) SEGMENTS in the prog8 syntax itself?
- ability to use a sub instead of only a var for @bank ? what for though? dynamic bank/overlay loading?
- Zig-like try-based error handling where the V flag could indicate error condition? and/or BRK to jump into monitor on failure? (has to set BRK vector for that) But the V flag is also set on certain normal instructions