diff options
author | 3gg <3gg@shellblade.net> | 2025-10-13 20:44:06 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-10-13 20:44:06 -0700 |
commit | 338bd46fb6dbcb8271102ddb6b896a335eb909dc (patch) | |
tree | dafa50f732804df571521751c619de57d12299aa | |
parent | 079cd940e727c1705e9f1b30706b9531d5aedda6 (diff) |
-rw-r--r-- | src/framebuffer.c | 35 | ||||
-rw-r--r-- | src/kernel.c | 5 | ||||
-rw-r--r-- | src/mailbox.c | 9 | ||||
-rw-r--r-- | src/mailbox.h | 1 |
4 files changed, 30 insertions, 20 deletions
diff --git a/src/framebuffer.c b/src/framebuffer.c index a90bcaa..e3303b6 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c | |||
@@ -4,27 +4,38 @@ | |||
4 | 4 | ||
5 | #include <stdint.h> | 5 | #include <stdint.h> |
6 | 6 | ||
7 | #define WIDTH 640 | 7 | #define WIDTH 640 |
8 | #define HEIGHT 480 | 8 | #define HEIGHT 480 |
9 | #define DEPTH 32 | 9 | #define DEPTH 32 |
10 | #define ALIGNMENT 16 // Framebuffer byte alignment. | ||
10 | 11 | ||
11 | bool framebuffer_init(uint32_t* error) { | 12 | bool framebuffer_init(uint32_t* error) { |
12 | volatile const Mail* mail; | 13 | volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t ConfigureScreen[20] = { |
13 | 14 | 80, // Size in bytes, aligned to MAIL_ALIGN. | |
14 | volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t InitFramebuffer[] = { | ||
15 | 80, // Size in bytes aligned to MAIL_ALIGN(16). | ||
16 | MAILBOX_REQUEST, | 15 | MAILBOX_REQUEST, |
17 | TAG_FRAMEBUFFER_SET_PHYSICAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, | 16 | TAG_FRAMEBUFFER_SET_PHYSICAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, |
18 | TAG_FRAMEBUFFER_SET_VIRTUAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, | 17 | TAG_FRAMEBUFFER_SET_VIRTUAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, |
19 | TAG_FRAMEBUFFER_SET_DEPTH, 4, MAILBOX_REQUEST, DEPTH, | 18 | TAG_FRAMEBUFFER_SET_DEPTH, 4, MAILBOX_REQUEST, DEPTH, |
20 | TAG_END, | 19 | TAG_END, |
21 | 0, 0, 0 // Pad. | 20 | 0, 0, 0 // Padding. |
21 | }; | ||
22 | mbox_write(PROPERTY_CHANNEL, ConfigureScreen); | ||
23 | const Mail* response = mbox_read(PROPERTY_CHANNEL); | ||
24 | if (response->code != MAILBOX_SUCCESS) { | ||
25 | goto end; | ||
26 | } | ||
27 | |||
28 | volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t InitFramebuffer[8] = { | ||
29 | 32, // Size in bytes, aligned to MAIL_ALIGN. | ||
30 | MAILBOX_REQUEST, | ||
31 | TAG_FRAMEBUFFER_ALLOCATE, 8, MAILBOX_REQUEST, ALIGNMENT, 0, | ||
32 | TAG_END | ||
22 | }; | 33 | }; |
23 | |||
24 | mbox_write(PROPERTY_CHANNEL, InitFramebuffer); | 34 | mbox_write(PROPERTY_CHANNEL, InitFramebuffer); |
25 | while ((mail = mbox_read(PROPERTY_CHANNEL)) != (volatile Mail*)(InitFramebuffer)); | 35 | response = mbox_read(PROPERTY_CHANNEL); |
26 | 36 | ||
27 | *error = mail->code; | 37 | end: |
28 | return mail->code == MAILBOX_SUCCESS; | 38 | *error = response->code; |
39 | return response->code == MAILBOX_SUCCESS; | ||
29 | } | 40 | } |
30 | 41 | ||
diff --git a/src/kernel.c b/src/kernel.c index ac803cc..151028d 100644 --- a/src/kernel.c +++ b/src/kernel.c | |||
@@ -19,11 +19,14 @@ void main() { | |||
19 | 19 | ||
20 | mbox_init(); | 20 | mbox_init(); |
21 | uart_init(raspi); | 21 | uart_init(raspi); |
22 | uart_print("Initializing framebuffer\n"); | ||
22 | success = framebuffer_init(&error); | 23 | success = framebuffer_init(&error); |
23 | if (!success) { | 24 | if (!success) { |
24 | uart_print("Failed to initialize framebuffer\n"); | 25 | uart_print("Failed to initialize framebuffer:\n"); |
25 | if (error == MAILBOX_DELIVERY_ERROR) { | 26 | if (error == MAILBOX_DELIVERY_ERROR) { |
26 | uart_print("MAILBOX_DELIVERY_ERROR\n"); | 27 | uart_print("MAILBOX_DELIVERY_ERROR\n"); |
28 | } else if (error == MAILBOX_ERROR) { | ||
29 | uart_print("MAILBOX_ERROR\n"); | ||
27 | } | 30 | } |
28 | goto end; | 31 | goto end; |
29 | } | 32 | } |
diff --git a/src/mailbox.c b/src/mailbox.c index aacb747..310b2b1 100644 --- a/src/mailbox.c +++ b/src/mailbox.c | |||
@@ -16,13 +16,8 @@ static inline uint8_t msg_channel(Message msg) { | |||
16 | return msg & 0xf; | 16 | return msg & 0xf; |
17 | } | 17 | } |
18 | 18 | ||
19 | static inline const void* msg_data(Message msg) { | ||
20 | // The data field is actually a pointer to the data. | ||
21 | return (const void*)((uintptr_t)(msg >> 4)); | ||
22 | } | ||
23 | |||
24 | static inline Message msg_make(uint8_t channel, volatile const void* data) { | 19 | static inline Message msg_make(uint8_t channel, volatile const void* data) { |
25 | return ((uintptr_t)(data) << 4) | (channel & 0xf); | 20 | return ((uintptr_t)(data) & ~0xf) | (channel & 0xf); |
26 | } | 21 | } |
27 | 22 | ||
28 | typedef struct Mailbox { | 23 | typedef struct Mailbox { |
@@ -61,7 +56,7 @@ const Mail* mbox_read(uint8_t channel) { | |||
61 | // Read the mail. | 56 | // Read the mail. |
62 | msg = pMailbox->inbox; | 57 | msg = pMailbox->inbox; |
63 | } while (msg_channel(msg) != channel); | 58 | } while (msg_channel(msg) != channel); |
64 | return (const Mail*)(msg_data(msg)); | 59 | return (const Mail*)((uintptr_t)msg & ~0xf); |
65 | } | 60 | } |
66 | 61 | ||
67 | void mbox_write(uint8_t channel, volatile const void* mail) { | 62 | void mbox_write(uint8_t channel, volatile const void* mail) { |
diff --git a/src/mailbox.h b/src/mailbox.h index 3cca366..b35c7a6 100644 --- a/src/mailbox.h +++ b/src/mailbox.h | |||
@@ -55,6 +55,7 @@ typedef struct __attribute__((aligned(MAIL_ALIGN))) Mail { | |||
55 | Tag tags[]; // Variable quantity. | 55 | Tag tags[]; // Variable quantity. |
56 | } Mail; | 56 | } Mail; |
57 | 57 | ||
58 | // TODO: Remove? Unused. | ||
58 | #define MAIL_SIZE(TYPE) (sizeof(TYPE) + (2 * sizeof(uint32_t))) | 59 | #define MAIL_SIZE(TYPE) (sizeof(TYPE) + (2 * sizeof(uint32_t))) |
59 | 60 | ||
60 | void mbox_init(); | 61 | void mbox_init(); |