summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/framebuffer.c35
-rw-r--r--src/kernel.c5
-rw-r--r--src/mailbox.c9
-rw-r--r--src/mailbox.h1
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
11bool framebuffer_init(uint32_t* error) { 12bool 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; 37end:
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
19static 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
24static inline Message msg_make(uint8_t channel, volatile const void* data) { 19static 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
28typedef struct Mailbox { 23typedef 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
67void mbox_write(uint8_t channel, volatile const void* mail) { 62void 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
60void mbox_init(); 61void mbox_init();