Globals and start.asm #19

Merged
ShatteredMINT merged 10 commits from Gelthor/symphony_stdlib:graphics into main 2026-09-06 20:13:07 +02:00
Contributor

Added support for global variables.

This requires including start.asm as the first code. This includes a jmp to 0x100 for user code, and a magic number that modules can check to verify that the user has correctly reserved the space.

The magic number is 0xb301534c:

  • This has the high bit set so is not a valid instruction.
  • On builds that ignore the high bit this decodes to nor zr, zr, 0x534c a no-op.
  • The immediate is "SL" for Standard Library.

start.asm also initialises sp so it starts just below the 64KiB LUT memory allocation.

Added some error codes for the upcoming graphics module.

Added support for global variables. This requires including `start.asm` as the first code. This includes a `jmp` to 0x100 for user code, and a magic number that modules can check to verify that the user has correctly reserved the space. The magic number is 0xb301534c: * This has the high bit set so is not a valid instruction. * On builds that ignore the high bit this decodes to `nor zr, zr, 0x534c` a no-op. * The immediate is "SL" for Standard Library. `start.asm` also initialises `sp` so it starts just below the 64KiB LUT memory allocation. Added some error codes for the upcoming graphics module.
Gelthor added 5 commits 2026-09-06 12:15:43 +02:00
v
Added support for global variables.

This requires including `start.asm` as the first code. This includes
a `jmp` to 0x100 for user code, and a magic number that modules
can check to verify th the user has correctly reserved the space.

The magic number is 0xb301534c:

* This has the high bit set so is not a valid instruction

* On builds that ignore the high bit this decodes to `nor zr, zr,
  0x534c` a no-op.

* The immediate is "SL" for standardl ibrary.

Due to a bug start pads with U... 0, instead of @addr.

`start.asm` also initialises `sp` so it start just below the 64KiB LUT
memory alocation.

Added some error codes for the upcoming graphics module.
@@ -16,10 +16,21 @@ All functions in the standard library should follow the following outline:
; Arguments: <which register contains what argument>
; Result: <what is the result, and where is it stored>
; Clobbers: <list of registers that are clobbered>
; Globals: <list of globals are accessed. OPTIONAL>
Contributor

Which errors can occur (if any) should probably have its own section here, probably called "Errors"

Which errors can occur (if any) should probably have its own section here, probably called "Errors"
Gelthor marked this conversation as resolved
@@ -0,0 +28,4 @@
; - r5: If non-zero, clears the current framebuffer.
; - r6: If non-zero, enable double buffering
; Returns:
; - r1: Status
Contributor

The status is returned in flags, not r1. Errors should probably have their own dedicated section here

The status is returned in `flags`, not `r1`. Errors should probably have their own dedicated section here
Gelthor marked this conversation as resolved
@@ -0,0 +1,28 @@
; Addresses of global variables
Contributor

I'd personally rather see reserved addresses put in hex, but I don't have a good reasoning for that.

I'd personally rather see reserved addresses put in hex, but I don't have a good reasoning for that.
Gelthor marked this conversation as resolved
src/globals.asm Outdated
@@ -0,0 +22,4 @@
; * 2 => 32 bits per pixel
pub const FB_LOG_BPP = 43 ; U8 Specialisations should hardcode this
pub const MAGIC_ADDRESS_LONG = 12 ; U32 Location of the magic value
Contributor

If we do not declare these addresses in order, I fear we will accidentally introduce double use of an address at some point.

If we do not declare these addresses in order, I fear we will accidentally introduce double use of an address at some point.
Gelthor marked this conversation as resolved
@@ -0,0 +23,4 @@
; Arguments:
; - r1: Point to allocated framebuffer
; - r2: Size of FB allocation, in bytes
; - r3: Bits per pixel: One of `8` or `32`
Contributor

Since this function lives in graphics_32, I'd expect that to imply 32 bits per pixel. If the same function is intended to be used for both modes, it should live in a generic graphics file.

Since this function lives in `graphics_32`, I'd expect that to imply 32 bits per pixel. If the same function is intended to be used for both modes, it should live in a generic graphics file.
Gelthor marked this conversation as resolved
@@ -0,0 +25,4 @@
; - r2: Size of FB allocation, in bytes
; - r3: Bits per pixel: One of `8` or `32`
; - r4: Width - height is set to `width / 4 * 3`
; - r5: If non-zero, clears the current framebuffer.
Contributor

If you are worried about register pressure, rather than having 2 bool arguments like this you could have a single u32 argument holding a bitwise OR of flags.

If you are worried about register pressure, rather than having 2 bool arguments like this you could have a single u32 argument holding a bitwise OR of flags.
Author
Contributor

I'm not sure register pressure is important for a rarely called initialisation function.

I'm not sure register pressure is important for a rarely called initialisation function.
@@ -0,0 +67,4 @@
mov r8, 0
jmp mode_ok
invalid_mode:
Contributor

I'd recommend centralizing the function epilogue. Otherwise, if a future refactor changes which registers need to be saved and one of the return sites is missed that could lead to nasty errors.

I'd recommend centralizing the function epilogue. Otherwise, if a future refactor changes which registers need to be saved and one of the return sites is missed that could lead to nasty errors.
Gelthor marked this conversation as resolved
@@ -0,0 +81,4 @@
ja width_invalid
cmp r4, 4
jb width_invalid
; Is width a power of two?
Contributor

There is a bit trick for this: !(v & (v - 1)). Though that does not yield the log2.

There is a bit trick for this: `!(v & (v - 1))`. Though that does not yield the log2.
Author
Contributor

Fixed the comment to describe what the code actually does.

Fixed the comment to describe what the code actually does.
Gelthor marked this conversation as resolved
@@ -0,0 +178,4 @@
mov flags, 0 ; OK
jmp r13 ; return
pub set_text_mode:
Contributor

I think I'd rather see graphics mode and text mode code in separate files.

I think I'd rather see graphics mode and text mode code in separate files.
Gelthor marked this conversation as resolved
@@ -0,0 +415,4 @@
; Returns:
; - None
; Clobbers:
; - r1: Old display FB => new draw FB
Contributor

Should we document these as returns instead? If any caller is writing to the buffer directly, they could then rely on this return and skip the extra load.

Should we document these as returns instead? If any caller is writing to the buffer directly, they could then rely on this return and skip the extra load.
Gelthor marked this conversation as resolved
@@ -0,0 +438,4 @@
; Framebuffer pointer is stored in FB_PTR.
;
; Arguments:
; - r1 Color 24 bit RGB0 PRESERVED
Contributor

The function code does not match this argument list

The function code does not match this argument list
Gelthor marked this conversation as resolved
Gelthor added 5 commits 2026-09-06 19:03:34 +02:00
PleegWat approved these changes 2026-09-06 19:33:46 +02:00
ShatteredMINT merged commit e654d451a7 into main 2026-09-06 20:13:07 +02:00
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TCShenanigans/symphony_stdlib#19