From 7572ae8eea831865b7855d2387a1ca013557090f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Wed, 8 Sep 2021 16:48:18 +0200 Subject: [PATCH 01/61] feat(base): include lesson05 NOTE: does not work yet Current output: ``` 61 EnableRegister: ff84110c Kernel process started. EL 1 , ESR: 1fe00000, address, 1434 ``` --- chainloader/include/kernel/peripherals/mini_uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/include/kernel/peripherals/mini_uart.h b/chainloader/include/kernel/peripherals/mini_uart.h index 52839ad..51edebc 100644 --- a/chainloader/include/kernel/peripherals/mini_uart.h +++ b/chainloader/include/kernel/peripherals/mini_uart.h @@ -1,7 +1,7 @@ #ifndef _ROSE_K_P_MINI_UART_H #define _ROSE_K_P_MINI_UART_H -#include "base.h" +#include "kernel/peripherals/base.h" #define SYSTEM_CLOCK_FREQ 500000000 #define BAUD_RATE_REG(target_baudrate) ((SYSTEM_CLOCK_FREQ/target_baudrate/8)-1) From e28e7ad92b40209aeb2c93fe746f0aa0d6f107f6 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Wed, 8 Sep 2021 17:02:54 +0200 Subject: [PATCH 02/61] feat(io): modify printf to allow %p %P for 0x........ notation --- thorn/src/common/printf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/thorn/src/common/printf.c b/thorn/src/common/printf.c index 64f38c5..05fea32 100644 --- a/thorn/src/common/printf.c +++ b/thorn/src/common/printf.c @@ -205,6 +205,17 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { unsigned int),16, (ch == 'P'), bf); putchw (putp, putf, w, lz, bf); break; + case 'p': case 'P': + putf(putp, '0'); + putf(putp, 'x'); +#ifdef PRINTF_LONG_SUPPORT + if (lng) + uli2a(va_arg(va, unsigned long int),16,(ch=='P'),bf); + else +#endif + ui2a(va_arg(va, unsigned int),16,(ch=='P'),bf); + putchw(putp,putf,w,lz,bf); + break; case '%' : putf (putp, ch); default: From 256b9fe032639db343e139e215f3c9b343845f58 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Mon, 13 Sep 2021 12:36:19 +0200 Subject: [PATCH 03/61] feat(io): add uart as alternative to mini uart NOTE: the first uart to be included will be the implementation used throughout the program --- chainloader/include/kernel/peripherals/mini_uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/include/kernel/peripherals/mini_uart.h b/chainloader/include/kernel/peripherals/mini_uart.h index 51edebc..52839ad 100644 --- a/chainloader/include/kernel/peripherals/mini_uart.h +++ b/chainloader/include/kernel/peripherals/mini_uart.h @@ -1,7 +1,7 @@ #ifndef _ROSE_K_P_MINI_UART_H #define _ROSE_K_P_MINI_UART_H -#include "kernel/peripherals/base.h" +#include "base.h" #define SYSTEM_CLOCK_FREQ 500000000 #define BAUD_RATE_REG(target_baudrate) ((SYSTEM_CLOCK_FREQ/target_baudrate/8)-1) From 0ff6b7fff4eccaa2979cdd87e4c9e417005e78e2 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 10:34:09 +0200 Subject: [PATCH 04/61] style(io): rename hdmi to gpu --- thorn/include/common/gpu.h | 21 +++++++++++++++++++++ thorn/include/kernel/peripherals/gpu.h | 11 +++++++++++ thorn/src/common/gpu.c | 6 ++++++ thorn/src/kernel/kernel.c | 2 ++ 4 files changed, 40 insertions(+) create mode 100644 thorn/include/common/gpu.h create mode 100644 thorn/include/kernel/peripherals/gpu.h create mode 100644 thorn/src/common/gpu.c diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h new file mode 100644 index 0000000..5560f69 --- /dev/null +++ b/thorn/include/common/gpu.h @@ -0,0 +1,21 @@ +#ifndef _ROSE_C_GPU_H +#define _ROSE_C_GPU_H + +#include "kernel/mailbox.h" + +// Reference: +// https://jsandler18.github.io/extra/prop-channel.html + +#define GPU_SCREEN_WIDTH 1920 +#define GPU_SCREEN_HEIGHT 1280 + +#define GPU_VIRTUAL_WIDTH 1920 +#define GPU_VIRTUAL_HEIGHT 1280 + +#define GPU_COLOUR_DEPTH 24 + +void init_gpu (void); + +void * request_framebuffer (void); + +#endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/include/kernel/peripherals/gpu.h b/thorn/include/kernel/peripherals/gpu.h new file mode 100644 index 0000000..a2886f1 --- /dev/null +++ b/thorn/include/kernel/peripherals/gpu.h @@ -0,0 +1,11 @@ +#ifndef _ROSE_K_P_GPU_H +#define _ROSE_K_P_GPU_H + +#define GPU_REQUEST_FRAMEBUFFER 0x40001 +#define GPU_SET_SCREEN_SIZE 0x48003 +#define GPU_SET_VIRTUAL_SIZE 0x48004 +#define GPU_SET_COLOUR_DEPTH 0x48005 + +#endif //_ROSE_K_P_GPU_H + +/* Copyright (C) 2020 Aaron Alef */ \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c new file mode 100644 index 0000000..0bcd57f --- /dev/null +++ b/thorn/src/common/gpu.c @@ -0,0 +1,6 @@ +#include "common/gpu.h" + +void init_gpu () { + + +} diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index f03d806..dcac9fe 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -1,6 +1,7 @@ #include "kernel/mini_uart.h" #include "common/printf.h" #include "common/utils.h" +#include "common/gpu.h" #include "kernel/mm.h" #include "kernel/timer.h" #include "kernel/irq.h" @@ -62,6 +63,7 @@ void kernel_main (int processor_id) { if (processor_id == current_processor) { uart_init (); + init_gpu (); init_printf (0, putc); irq_vector_init (); timer_init (); From 8732d02a0b95c308b343c01fc94ad788799990dd Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 13:02:55 +0200 Subject: [PATCH 05/61] feat(io): add mailbox send and read functions [untested] --- chainloader/src/mailbox.c | 65 ++++++++++++++++++++++ thorn/include/kernel/mailbox.h | 54 ++++++++++++++++++ thorn/include/kernel/peripherals/gpu.h | 1 + thorn/include/kernel/peripherals/mailbox.h | 19 +++++++ 4 files changed, 139 insertions(+) create mode 100644 chainloader/src/mailbox.c create mode 100644 thorn/include/kernel/mailbox.h create mode 100644 thorn/include/kernel/peripherals/mailbox.h diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c new file mode 100644 index 0000000..cf12e56 --- /dev/null +++ b/chainloader/src/mailbox.c @@ -0,0 +1,65 @@ +#include "kernel/mailbox.h" + +void mailbox_send (unsigned int data, channel_t channel) { + mbox_message_t msg = {data, channel}; + + while ((MBOX1 + MBOX_STATUS) & MBOX_WRITE_FULL); + put32 (MBOX1 + MBOX_WRITE, * (unsigned int *) & msg); +} + +unsigned int mailbox_read (channel_t channel) { + unsigned int value; + + do { + // Wait until there's a message + while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); + + value = get32 (MBOX0 + MBOX_READ); + + // Wait until the channel matches (lest four significant bits) + } while ((value & 0xF) != channel); + + // Return most significant bits (actual address) + return value >> 4; +} + +unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { + mbox_property_t * msg = (mbox_property_t *) get_free_page (); + + // Add tags to message: + unsigned int struct_size = 2 * sizeof (unsigned int); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (msg + struct_size), tags); + + // Add end tag and 16 byte-aligned padding: + struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; + + // write struct size to message: + msg->struct_size = struct_size; + + mailbox_send ((unsigned int) msg, channel); + return msg; +} + +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { + unsigned int written = 0; + while (src->identity) { + dest += written; + + unsigned int buffer_size = src->buffer_size; + + dest->identity = src->identity; + dest->buffer_size = buffer_size; + dest->response = 0; + + + for (unsigned int i = 0; i < buffer_size; i ++) { + dest->buffer[written] = src->buffer[written]; + } + written += 3 * sizeof (unsigned int) + buffer_size; + put32 (dest + written, 0); + written += sizeof (unsigned int); + put32 (dest + written, 0); + written += (written % 16) ? 16 - (written % 16) : 0; + } + return written; +} diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h new file mode 100644 index 0000000..a75cf68 --- /dev/null +++ b/thorn/include/kernel/mailbox.h @@ -0,0 +1,54 @@ +#ifndef _ROSE_K_MAILBOX_H +#define _ROSE_K_MAILBOX_H + +#include "common/utils.h" +#include "kernel/peripherals/mailbox.h" +#include "kernel/mm.h" + +// Documentation: +// https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface + +typedef enum { + POWER = 0, + FRAMEBUFFER, + VIRTUAL_UART, + VCHIQ, + LEDS, + BUTTONS, + TOUCH_SCREEN, + RESERVED, + PROPERTY_ARM_VC, // Request from ARM for response by VC + PROPERTY_VC_ARM // Request from VC for response by ARM (Currently not in use) +} channel_t; + + +typedef struct { + unsigned int data: 28; // most significant bits contain shared memory address + channel_t channel: 4; // least four significant bits contain channel +} mbox_message_t; + +typedef struct { + unsigned int identity; + unsigned int buffer_size; + unsigned int response; + unsigned char * buffer; +} mbox_tag_t; + +typedef struct { + unsigned int struct_size; + unsigned int response; + mbox_tag_t * tags; +} mbox_property_t; + + +void mailbox_send (unsigned int data, channel_t channel); + +// Returns address of message +unsigned int mailbox_read (channel_t channel); + +unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags); + +// Returns total size written +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src); + +#endif //_ROSE_K_MAILBOX_H \ No newline at end of file diff --git a/thorn/include/kernel/peripherals/gpu.h b/thorn/include/kernel/peripherals/gpu.h index a2886f1..ec95fd1 100644 --- a/thorn/include/kernel/peripherals/gpu.h +++ b/thorn/include/kernel/peripherals/gpu.h @@ -2,6 +2,7 @@ #define _ROSE_K_P_GPU_H #define GPU_REQUEST_FRAMEBUFFER 0x40001 +#define GPU_BLANK_SCREEN 0x40002 #define GPU_SET_SCREEN_SIZE 0x48003 #define GPU_SET_VIRTUAL_SIZE 0x48004 #define GPU_SET_COLOUR_DEPTH 0x48005 diff --git a/thorn/include/kernel/peripherals/mailbox.h b/thorn/include/kernel/peripherals/mailbox.h new file mode 100644 index 0000000..6f8c889 --- /dev/null +++ b/thorn/include/kernel/peripherals/mailbox.h @@ -0,0 +1,19 @@ +#ifndef _ROSE_K_P_MAILBOX_H +#define _ROSE_K_P_MAILBOX_H + +#include "base.h" + +#define MBOX0 (PBASE + 0xB880) // Read from CPU +#define MBOX1 (PBASE + 0xB840) // Write to CPU + +#define MBOX_READ 0x00 +#define MBOX_STATUS 0x18 +#define MBOX_IRQ 0x1C +#define MBOX_WRITE 0x20 + +#define MBOX_READ_EMPTY (1 << 30) +#define MBOX_WRITE_FULL (1 << 31) + +#define MBOX_IRQ_ENABLE (1 << 0) + +#endif //_ROSE_K_P_MAILBOX_H \ No newline at end of file From fc3469f139c0b7c6b2af821a88ea8d24a06f33ff Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 14:03:05 +0200 Subject: [PATCH 06/61] feat(io): initialise framebuffer [not working] NOTE: Absolutely Not Working --- thorn/include/common/gpu.h | 11 ++++++-- thorn/include/common/stddef.h | 2 ++ thorn/include/kernel/mailbox.h | 3 ++- thorn/src/common/gpu.c | 46 +++++++++++++++++++++++++++++++--- thorn/src/kernel/kernel.c | 7 +++++- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 5560f69..d4042af 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -1,7 +1,11 @@ #ifndef _ROSE_C_GPU_H #define _ROSE_C_GPU_H +#include "common/stdbool.h" +#include "common/stddef.h" +#include "kernel/peripherals/gpu.h" #include "kernel/mailbox.h" +#include "kernel/mm.h" // Reference: // https://jsandler18.github.io/extra/prop-channel.html @@ -14,8 +18,11 @@ #define GPU_COLOUR_DEPTH 24 -void init_gpu (void); +// framebuffer +static ptr_t fb; -void * request_framebuffer (void); +bool init_gpu (void); + +ptr_t get_fb (void); #endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/include/common/stddef.h b/thorn/include/common/stddef.h index cf32c4e..2d12078 100644 --- a/thorn/include/common/stddef.h +++ b/thorn/include/common/stddef.h @@ -5,4 +5,6 @@ #define ptr_t unsigned long +#define byte_t unsigned char + #endif //_ROSE_C_STDDEF_H \ No newline at end of file diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h index a75cf68..80083c5 100644 --- a/thorn/include/kernel/mailbox.h +++ b/thorn/include/kernel/mailbox.h @@ -2,6 +2,7 @@ #define _ROSE_K_MAILBOX_H #include "common/utils.h" +#include "common/stddef.h" #include "kernel/peripherals/mailbox.h" #include "kernel/mm.h" @@ -31,7 +32,7 @@ typedef struct { unsigned int identity; unsigned int buffer_size; unsigned int response; - unsigned char * buffer; + byte_t * buffer; } mbox_tag_t; typedef struct { diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 0bcd57f..dab151f 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,6 +1,46 @@ #include "common/gpu.h" -void init_gpu () { - - +bool init_gpu () { + unsigned int * buffer = (unsigned int *) get_free_page (); + + mbox_tag_t * screen_size = (mbox_tag_t *) buffer; + unsigned int screen_buffer[] = {GPU_SCREEN_WIDTH, GPU_SCREEN_HEIGHT}; + screen_size->identity = GPU_SET_SCREEN_SIZE; + screen_size->buffer_size = 8; + screen_size->response = 0; + screen_size->buffer = (byte_t *) screen_buffer; + + mbox_tag_t * virtual_size = (mbox_tag_t * ) (buffer + sizeof (mbox_tag_t)); + unsigned int virtual_buffer[] = {GPU_VIRTUAL_WIDTH, GPU_VIRTUAL_HEIGHT}; + virtual_size->identity = GPU_SET_VIRTUAL_SIZE; + virtual_size->buffer_size = 8; + virtual_size->response = 0; + virtual_size->buffer = (byte_t *) virtual_buffer; + + mbox_tag_t * colour_depth = (mbox_tag_t * ) (buffer + 2 * sizeof (mbox_tag_t)); + unsigned int colour_depth_buffer = GPU_COLOUR_DEPTH; + colour_depth->identity = GPU_SET_COLOUR_DEPTH; + colour_depth->buffer_size = 4; + colour_depth->response = 0; + colour_depth->buffer = (byte_t * ) & colour_depth_buffer; + + mbox_property_t * msg1 = (mbox_property_t *) mailbox_send_tags (PROPERTY_ARM_VC, (mbox_tag_t *) buffer); + if (msg1->response != 0x80000000) return false; + + byte_t alignment[] = {16}; + mbox_tag_t request_fb = { + GPU_REQUEST_FRAMEBUFFER, + 8, + 0, + alignment, + }; + mbox_property_t * msg2 = (mbox_property_t *) mailbox_send_tags (PROPERTY_ARM_VC, & request_fb); + if (msg2->response != 0x80000000) return false; + + fb = (ptr_t) (msg2 + 5 * sizeof (unsigned int)); + return true; } + +ptr_t get_fb () { + return fb; +} \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index dcac9fe..0dcf41a 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -63,7 +63,6 @@ void kernel_main (int processor_id) { if (processor_id == current_processor) { uart_init (); - init_gpu (); init_printf (0, putc); irq_vector_init (); timer_init (); @@ -72,6 +71,12 @@ void kernel_main (int processor_id) { task_init (); LOG("Logging works"); + + if (! init_gpu ()) { + printf ("Error while initialising framebuffer\r\n"); + } else { + get_fb (); + } } while (processor_id != current_processor); From 2babdc2b81bf26cefaf6bca3eb1b066e149f1890 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 10:02:07 +0200 Subject: [PATCH 07/61] fix(mb): added missing left shift --- chainloader/src/mailbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index cf12e56..f0c8e93 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -20,7 +20,7 @@ unsigned int mailbox_read (channel_t channel) { } while ((value & 0xF) != channel); // Return most significant bits (actual address) - return value >> 4; + return ((value >> 4) << 4); } unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { From c46136f36f57947954c2b1fe8f9ead19251ddeb6 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 12:31:10 +0200 Subject: [PATCH 08/61] feat(io): clear UART screen --- thorn/src/kernel/mini_uart.c | 1 + thorn/src/kernel/uart.c | 1 + 2 files changed, 2 insertions(+) diff --git a/thorn/src/kernel/mini_uart.c b/thorn/src/kernel/mini_uart.c index e89e266..427f260 100644 --- a/thorn/src/kernel/mini_uart.c +++ b/thorn/src/kernel/mini_uart.c @@ -59,6 +59,7 @@ void mini_uart_init (void) { put32 (AUX_MU_CNTL_REG, 3); + mini_uart_send_string ("\033[2J\033[H"); mini_uart_send_string ("Initialised mini UART\r\n"); init_done = true; diff --git a/thorn/src/kernel/uart.c b/thorn/src/kernel/uart.c index 1384238..7ac37b2 100644 --- a/thorn/src/kernel/uart.c +++ b/thorn/src/kernel/uart.c @@ -56,6 +56,7 @@ void _uart_init (void) { // Enable Receive, Transmit, and UART_ itself put32 (UART_CR, (1 << 9) | (1 << 8) | (1 << 0)); + _uart_send_string ("\033[2J\033[H"); _uart_send_string ("Initialised standard UART\r\n"); init_done = true; From 93f39e4672969e5e3d9b11e3ef0138196d98fe86 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 11:55:39 +0200 Subject: [PATCH 09/61] refactor(io): rewrite mailbox and adapt gpu init to it NOTE: doesn't work yet - produces ``` Type SYNC_INVALID_EL1h, ESR: 0x96000040, address, 0x81044Type ``` --- chainloader/src/mailbox.c | 44 ++++++++++++---------- thorn/include/common/gpu.h | 4 ++ thorn/include/kernel/mailbox.h | 11 +++--- thorn/include/kernel/peripherals/mailbox.h | 2 + thorn/src/common/gpu.c | 21 +++++------ 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index f0c8e93..0ce766c 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -1,34 +1,38 @@ #include "kernel/mailbox.h" -void mailbox_send (unsigned int data, channel_t channel) { - mbox_message_t msg = {data, channel}; +bool mailbox_request (unsigned int data_ptr, channel_t channel) { + mbox_message_t msg; + unsigned int * msg_ptr = (unsigned int *) & msg; + unsigned int check; - while ((MBOX1 + MBOX_STATUS) & MBOX_WRITE_FULL); - put32 (MBOX1 + MBOX_WRITE, * (unsigned int *) & msg); -} - -unsigned int mailbox_read (channel_t channel) { - unsigned int value; + * msg_ptr = data_ptr; + msg.channel = channel; + + while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + put32 (MBOX0 + MBOX_WRITE, * msg_ptr); do { // Wait until there's a message while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); - value = get32 (MBOX0 + MBOX_READ); + check = get32 (MBOX0 + MBOX_READ); - // Wait until the channel matches (lest four significant bits) - } while ((value & 0xF) != channel); + // Check if it's the response to our message + } while (* msg_ptr == check); + + // Get the pointer to the property request message + mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~ 0xFF)); - // Return most significant bits (actual address) - return ((value >> 4) << 4); + // Return the message's response code + return property->response == MBOX_SUCCESS; } -unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { - mbox_property_t * msg = (mbox_property_t *) get_free_page (); +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { + mbox_property_t * msg = (mbox_property_t * ) & message; // Add tags to message: unsigned int struct_size = 2 * sizeof (unsigned int); - struct_size += mailbox_write_tags ((mbox_tag_t * ) (msg + struct_size), tags); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags); // Add end tag and 16 byte-aligned padding: struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; @@ -36,8 +40,8 @@ unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { // write struct size to message: msg->struct_size = struct_size; - mailbox_send ((unsigned int) msg, channel); - return msg; + // return number of bytes written, for reference + return struct_size; } unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { @@ -56,9 +60,9 @@ unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { dest->buffer[written] = src->buffer[written]; } written += 3 * sizeof (unsigned int) + buffer_size; - put32 (dest + written, 0); + put32 ((unsigned int) (dest + written), 0); written += sizeof (unsigned int); - put32 (dest + written, 0); + put32 ((unsigned int) (dest + written), 0); written += (written % 16) ? 16 - (written % 16) : 0; } return written; diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index d4042af..84061b8 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -18,6 +18,10 @@ #define GPU_COLOUR_DEPTH 24 +#define GPU_MAX_MSG_SIZE 64 + +static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); + // framebuffer static ptr_t fb; diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h index 80083c5..908d0f7 100644 --- a/thorn/include/kernel/mailbox.h +++ b/thorn/include/kernel/mailbox.h @@ -2,6 +2,7 @@ #define _ROSE_K_MAILBOX_H #include "common/utils.h" +#include "common/stdbool.h" #include "common/stddef.h" #include "kernel/peripherals/mailbox.h" #include "kernel/mm.h" @@ -41,13 +42,11 @@ typedef struct { mbox_tag_t * tags; } mbox_property_t; +// Send message and check responses +bool mailbox_request (unsigned int data_ptr, channel_t channel); -void mailbox_send (unsigned int data, channel_t channel); - -// Returns address of message -unsigned int mailbox_read (channel_t channel); - -unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags); +// Returns total size written +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags); // Returns total size written unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src); diff --git a/thorn/include/kernel/peripherals/mailbox.h b/thorn/include/kernel/peripherals/mailbox.h index 6f8c889..273779c 100644 --- a/thorn/include/kernel/peripherals/mailbox.h +++ b/thorn/include/kernel/peripherals/mailbox.h @@ -16,4 +16,6 @@ #define MBOX_IRQ_ENABLE (1 << 0) +#define MBOX_SUCCESS 0x80000000 + #endif //_ROSE_K_P_MAILBOX_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index dab151f..e5987f7 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,43 +1,42 @@ #include "common/gpu.h" bool init_gpu () { - unsigned int * buffer = (unsigned int *) get_free_page (); - - mbox_tag_t * screen_size = (mbox_tag_t *) buffer; + unsigned int tag_buffer[24]; + mbox_tag_t * screen_size = (mbox_tag_t *) tag_buffer; unsigned int screen_buffer[] = {GPU_SCREEN_WIDTH, GPU_SCREEN_HEIGHT}; screen_size->identity = GPU_SET_SCREEN_SIZE; screen_size->buffer_size = 8; screen_size->response = 0; screen_size->buffer = (byte_t *) screen_buffer; - mbox_tag_t * virtual_size = (mbox_tag_t * ) (buffer + sizeof (mbox_tag_t)); + mbox_tag_t * virtual_size = (mbox_tag_t * ) (tag_buffer + sizeof (mbox_tag_t)); unsigned int virtual_buffer[] = {GPU_VIRTUAL_WIDTH, GPU_VIRTUAL_HEIGHT}; virtual_size->identity = GPU_SET_VIRTUAL_SIZE; virtual_size->buffer_size = 8; virtual_size->response = 0; virtual_size->buffer = (byte_t *) virtual_buffer; - mbox_tag_t * colour_depth = (mbox_tag_t * ) (buffer + 2 * sizeof (mbox_tag_t)); + mbox_tag_t * colour_depth = (mbox_tag_t * ) (tag_buffer + 2 * sizeof (mbox_tag_t)); unsigned int colour_depth_buffer = GPU_COLOUR_DEPTH; colour_depth->identity = GPU_SET_COLOUR_DEPTH; colour_depth->buffer_size = 4; colour_depth->response = 0; colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - mbox_property_t * msg1 = (mbox_property_t *) mailbox_send_tags (PROPERTY_ARM_VC, (mbox_tag_t *) buffer); - if (msg1->response != 0x80000000) return false; + mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer); + if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; byte_t alignment[] = {16}; - mbox_tag_t request_fb = { + volatile mbox_tag_t request_fb = { GPU_REQUEST_FRAMEBUFFER, 8, 0, alignment, }; - mbox_property_t * msg2 = (mbox_property_t *) mailbox_send_tags (PROPERTY_ARM_VC, & request_fb); - if (msg2->response != 0x80000000) return false; + mailbox_write_msg ((unsigned int) buffer, & request_fb); + if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; - fb = (ptr_t) (msg2 + 5 * sizeof (unsigned int)); + fb = * ((ptr_t * ) (buffer + 5)); return true; } From b26321a1373ed76a3232774deb3262d244a32a11 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 13:08:04 +0200 Subject: [PATCH 10/61] WIP: add debug showing program gets stuck waiting for configuration --- chainloader/src/mailbox.c | 25 ++++++++-- thorn/include/common/debug.h | 16 +++++++ thorn/include/common/gpu.h | 2 + thorn/include/common/logging.h | 5 +- thorn/include/kernel/mailbox.h | 7 ++- thorn/src/common/debug.c | 25 ++++++++++ thorn/src/common/gpu.c | 9 +++- thorn/src/common/printf.c | 23 +++------- thorn/src/kernel/kernel.c | 51 ++++++++++++--------- thorn/src/kernel/mailbox.c | 84 ++++++++++++++++++++++++++++++++++ 10 files changed, 197 insertions(+), 50 deletions(-) create mode 100644 thorn/include/common/debug.h create mode 100644 thorn/src/common/debug.c create mode 100644 thorn/src/kernel/mailbox.c diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index 0ce766c..ee5b8b7 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -8,31 +8,42 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { * msg_ptr = data_ptr; msg.channel = channel; + LOG ("Waiting for empty write buffer GPU..."); while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + LOG ("Writing to GPU..."); put32 (MBOX0 + MBOX_WRITE, * msg_ptr); + LOG ("Reading response..."); do { // Wait until there's a message + LOG ("Waiting for any message..."); while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); + LOG ("Check message"); check = get32 (MBOX0 + MBOX_READ); + LOG ("Check channel"); // Check if it's the response to our message } while (* msg_ptr == check); + LOG ("Read pointer to property response"); // Get the pointer to the property request message mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~ 0xFF)); + char * buffer[100]; + sprinf (buffer, "Returning response code: operation %s", + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + LOG (buffer); // Return the message's response code return property->response == MBOX_SUCCESS; } -unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count) { mbox_property_t * msg = (mbox_property_t * ) & message; // Add tags to message: unsigned int struct_size = 2 * sizeof (unsigned int); - struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags, tags_count); // Add end tag and 16 byte-aligned padding: struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; @@ -40,13 +51,15 @@ unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { // write struct size to message: msg->struct_size = struct_size; + int_dump (struct_size, (unsigned int *) msg); + // return number of bytes written, for reference return struct_size; } -unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count) { unsigned int written = 0; - while (src->identity) { + for (int i = 0; i < tags_count; i ++) { dest += written; unsigned int buffer_size = src->buffer_size; @@ -55,15 +68,17 @@ unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { dest->buffer_size = buffer_size; dest->response = 0; - for (unsigned int i = 0; i < buffer_size; i ++) { dest->buffer[written] = src->buffer[written]; } written += 3 * sizeof (unsigned int) + buffer_size; put32 ((unsigned int) (dest + written), 0); + written += sizeof (unsigned int); put32 ((unsigned int) (dest + written), 0); + written += (written % 16) ? 16 - (written % 16) : 0; } + return written; } diff --git a/thorn/include/common/debug.h b/thorn/include/common/debug.h new file mode 100644 index 0000000..913987a --- /dev/null +++ b/thorn/include/common/debug.h @@ -0,0 +1,16 @@ +#ifndef _ROSE_C_DEBUG_H +#define _ROSE_DEBUG_H + +#include "common/stddef.h" +#include "common/printf.h" +#include "common/logging.h" + +#define CHECKPOINT LOG ("Checkpoint"); + +void print_hex (unsigned char dec); + +void byte_dump (unsigned int size, byte_t * array); + +void int_dump (unsigned int size, unsigned int * array); + +#endif //_ROSE_C_DEBUG_H \ No newline at end of file diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 84061b8..46b729c 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -1,6 +1,8 @@ #ifndef _ROSE_C_GPU_H #define _ROSE_C_GPU_H +#include "common/printf.h" + #include "common/stdbool.h" #include "common/stddef.h" #include "kernel/peripherals/gpu.h" diff --git a/thorn/include/common/logging.h b/thorn/include/common/logging.h index 00c8758..6db814a 100644 --- a/thorn/include/common/logging.h +++ b/thorn/include/common/logging.h @@ -3,8 +3,9 @@ #include "common/printf.h" -#define LOG(msg) do { \ - printf(__FILE__":%d: %s\r\n", __LINE__, msg); \ +#define LOG(msg) do { \ + static int __counter__ = 0; \ + printf(__FILE__":%d:[%d] %s\r\n", __LINE__, __counter__++, msg); \ } while (0) #define ASSERT(expr) do { \ diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h index 908d0f7..8ef3619 100644 --- a/thorn/include/kernel/mailbox.h +++ b/thorn/include/kernel/mailbox.h @@ -7,6 +7,9 @@ #include "kernel/peripherals/mailbox.h" #include "kernel/mm.h" +#include "common/debug.h" +#include "common/logging.h" + // Documentation: // https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface @@ -46,9 +49,9 @@ typedef struct { bool mailbox_request (unsigned int data_ptr, channel_t channel); // Returns total size written -unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags); +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count); // Returns total size written -unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src); +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count); #endif //_ROSE_K_MAILBOX_H \ No newline at end of file diff --git a/thorn/src/common/debug.c b/thorn/src/common/debug.c new file mode 100644 index 0000000..8a256c6 --- /dev/null +++ b/thorn/src/common/debug.c @@ -0,0 +1,25 @@ +#include "common/debug.h" + +void print_hex (unsigned char dec) { + char fst = dec / 16; + char snd = dec % 16; + fst = (fst > 9) ? 'A' + fst - 10 : '0' + fst; + snd = (snd > 9) ? 'A' + snd - 10 : '0' + snd; + printf ("%c%c ", fst, snd); +} + +void byte_dump (unsigned int size, byte_t * array) { + for (int i = 0; i < size; i ++) { + print_hex (array[i]); + if (! ((i + 1) % 4)) printf (" "); + if (! ((i + 1) % 80)) printf ("\r\n"); + } + printf ("\r\n"); +} + +void int_dump (unsigned int size, unsigned int * array) { + for (int i = 0; i < size / sizeof (int); i ++) { + printf ("%d\t", array[i]); + } + printf ("\r\n"); +} diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index e5987f7..b9281dd 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -23,7 +23,10 @@ bool init_gpu () { colour_depth->response = 0; colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer); + + printf ("Preparing screen configuration request...\r\n"); + mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); + printf ("Sending screen configuration request...\r\n"); if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; byte_t alignment[] = {16}; @@ -33,7 +36,9 @@ bool init_gpu () { 0, alignment, }; - mailbox_write_msg ((unsigned int) buffer, & request_fb); + printf ("Preparing framebuffer request...\r\n"); + mailbox_write_msg ((unsigned int) buffer, & request_fb, 1); + printf ("Requesting framebuffer...\r\n"); if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; fb = * ((ptr_t * ) (buffer + 5)); diff --git a/thorn/src/common/printf.c b/thorn/src/common/printf.c index 05fea32..4089b52 100644 --- a/thorn/src/common/printf.c +++ b/thorn/src/common/printf.c @@ -158,7 +158,7 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { else #endif ui2a (va_arg (va, - unsigned int),10, 0, bf); + unsigned int), 10, 0, bf); putchw (putp, putf, w, lz, bf); break; } @@ -169,7 +169,7 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { else #endif i2a (va_arg (va, - int),bf); + int), bf); putchw (putp, putf, w, lz, bf); break; } @@ -181,16 +181,16 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { else #endif ui2a (va_arg (va, - unsigned int),16, (ch == 'X'), bf); + unsigned int), 16, (ch == 'X'), bf); putchw (putp, putf, w, lz, bf); break; case 'c' : putf (putp, (char) (va_arg (va, - int))); + int))); break; case 's' : putchw (putp, putf, w, 0, va_arg (va, - char*)); + char*)); break; case 'p': case 'P': @@ -202,20 +202,9 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { else #endif ui2a (va_arg (va, - unsigned int),16, (ch == 'P'), bf); + unsigned int), 16, (ch == 'P'), bf); putchw (putp, putf, w, lz, bf); break; - case 'p': case 'P': - putf(putp, '0'); - putf(putp, 'x'); -#ifdef PRINTF_LONG_SUPPORT - if (lng) - uli2a(va_arg(va, unsigned long int),16,(ch=='P'),bf); - else -#endif - ui2a(va_arg(va, unsigned int),16,(ch=='P'),bf); - putchw(putp,putf,w,lz,bf); - break; case '%' : putf (putp, ch); default: diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 0dcf41a..9b9e170 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -61,21 +61,28 @@ void kernel_main (int processor_id) { static unsigned int current_processor = 0; - if (processor_id == current_processor) { + if (processor_id == 0) { uart_init (); init_printf (0, putc); - irq_vector_init (); - timer_init (); - enable_interrupt_controller (); - enable_irq (); - task_init (); +// irq_vector_init (); +// timer_init (); +// enable_interrupt_controller (); +// enable_irq (); +// task_init (); LOG("Logging works"); - if (! init_gpu ()) { - printf ("Error while initialising framebuffer\r\n"); + printf ("Initialising Framebuffer...\r\n"); + int gpu_status = init_gpu (); + if (! gpu_status) { + printf ("Error while initialising Framebuffer\r\n"); } else { - get_fb (); + unsigned long fb = get_fb (); + if (! fb) { + printf ("Error: Invalid Framebuffer received\r\n"); + } else { + printf ("Received framebuffer: %p\r\n", fb); + } } } @@ -84,17 +91,17 @@ void kernel_main (int processor_id) { printf ("Hello, from processor %d\n\r", processor_id); current_processor++; - - if (processor_id == 0) { - while (current_processor != 4); - int res = copy_process (PF_KTHREAD, (unsigned long) & kernel_process, 0, 0); - if (res < 0) { - printf ("error while starting kernel process"); - return; - } - - while (1) { - schedule (); - } - } + +// if (processor_id == 0) { +// while (current_processor != 4); +// int res = copy_process (PF_KTHREAD, (unsigned long) & kernel_process, 0, 0); +// if (res < 0) { +// printf ("error while starting kernel process"); +// return; +// } +// +// while (1) { +// schedule (); +// } +// } } diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c new file mode 100644 index 0000000..dca578e --- /dev/null +++ b/thorn/src/kernel/mailbox.c @@ -0,0 +1,84 @@ +#include "kernel/mailbox.h" + +bool mailbox_request (unsigned int data_ptr, channel_t channel) { + mbox_message_t msg; + unsigned int * msg_ptr = (unsigned int *) & msg; + unsigned int check; + + * msg_ptr = data_ptr; + msg.channel = channel; + + LOG ("Waiting for empty write buffer GPU..."); + while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + LOG ("Writing to GPU..."); + put32 (MBOX0 + MBOX_WRITE, * msg_ptr); + + LOG ("Reading response..."); + do { + // Wait until there's a message + LOG ("Waiting for any message..."); + while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); + + LOG ("Check message"); + check = get32 (MBOX0 + MBOX_READ); + + LOG ("Check channel"); + // Check if it's the response to our message + } while (* msg_ptr == check); + + LOG ("Read pointer to property response"); + // Get the pointer to the property request message + mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~0xFF)); + + char * buffer[100]; + sprinf (buffer, "Returning response code: operation %s", + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + LOG (buffer); + // Return the message's response code + return property->response == MBOX_SUCCESS; +} + +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count) { + mbox_property_t * msg = (mbox_property_t * ) & message; + + // Add tags to message: + unsigned int struct_size = 2 * sizeof (unsigned int); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags, tags_count); + + // Add end tag and 16 byte-aligned padding: + struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; + + // write struct size to message: + msg->struct_size = struct_size; + + int_dump (struct_size, (unsigned int *) msg); + + // return number of bytes written, for reference + return struct_size; +} + +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count) { + unsigned int written = 0; + for (int i = 0; i < tags_count; i++) { + dest += written; + + unsigned int buffer_size = src->buffer_size; + + dest->identity = src->identity; + dest->buffer_size = buffer_size; + dest->response = 0; + + for (unsigned int i = 0; i < buffer_size; i++) { + dest->buffer[written] = src->buffer[written]; + } + written += 3 * sizeof (unsigned int) + buffer_size; + put32 ((unsigned int) (dest + written), 0); + + written += sizeof (unsigned int); + put32 ((unsigned int) (dest + written), 0); + + written += (written % 16) ? 16 - (written % 16) : 0; + } + + return written; +} \ No newline at end of file From d8c4d60b1ba8e1f9cb13d55ca3f47fd3921e4b34 Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 7 Oct 2021 13:58:47 +0200 Subject: [PATCH 11/61] Work in progress --- thorn/src/common/debug.c | 4 ++-- thorn/src/common/gpu.c | 29 +++++++++++++++++++++++++++-- thorn/src/kernel/mailbox.c | 5 +++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/thorn/src/common/debug.c b/thorn/src/common/debug.c index 8a256c6..82dab7f 100644 --- a/thorn/src/common/debug.c +++ b/thorn/src/common/debug.c @@ -8,7 +8,7 @@ void print_hex (unsigned char dec) { printf ("%c%c ", fst, snd); } -void byte_dump (unsigned int size, byte_t * array) { +void hex_dump (unsigned int size, byte_t * array) { for (int i = 0; i < size; i ++) { print_hex (array[i]); if (! ((i + 1) % 4)) printf (" "); @@ -19,7 +19,7 @@ void byte_dump (unsigned int size, byte_t * array) { void int_dump (unsigned int size, unsigned int * array) { for (int i = 0; i < size / sizeof (int); i ++) { - printf ("%d\t", array[i]); + printf ("%d ", array[i]); } printf ("\r\n"); } diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index b9281dd..a0b8112 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -22,12 +22,37 @@ bool init_gpu () { colour_depth->buffer_size = 4; colour_depth->response = 0; colour_depth->buffer = (byte_t * ) & colour_depth_buffer; + + + int test_buffer[20] = {0}; + test_buffer[0] = 80; + test_buffer[1] = 0; + test_buffer[2] = 0x00048003; + test_buffer[3] = 8; + test_buffer[4] = 0; + test_buffer[5] = 640; + test_buffer[6] = 480; + test_buffer[7] = 0x00048004; + test_buffer[8] = 8; + test_buffer[9] = 0; + test_buffer[10] = 640; + test_buffer[11] = 480; + test_buffer[12] = 0x00048005; + test_buffer[13] = 4; + test_buffer[14] = 0; + test_buffer[15] = 24; + test_buffer[16] = 0; + + int_dump (sizeof(test_buffer), (unsigned int *) test_buffer); - + for (int i = 0; i < 20; i++) { + printf("%d ", tag_buffer[i]); + } + printf ("Preparing screen configuration request...\r\n"); mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); printf ("Sending screen configuration request...\r\n"); - if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; + if (! mailbox_request ((unsigned int) test_buffer, PROPERTY_ARM_VC)) return false; byte_t alignment[] = {16}; volatile mbox_tag_t request_fb = { diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index dca578e..f1b9ef6 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -10,6 +10,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { LOG ("Waiting for empty write buffer GPU..."); while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + LOG ("Writing to GPU..."); put32 (MBOX0 + MBOX_WRITE, * msg_ptr); @@ -31,8 +32,8 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~0xFF)); char * buffer[100]; - sprinf (buffer, "Returning response code: operation %s", - (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + sprintf (buffer, "Returning response code: operation %s", + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); LOG (buffer); // Return the message's response code return property->response == MBOX_SUCCESS; From 9fa3b720b8a3b771a5bb612d31de20919e71aa93 Mon Sep 17 00:00:00 2001 From: BMG93 Date: Fri, 8 Oct 2021 13:52:18 +0200 Subject: [PATCH 12/61] WIP --- thorn/include/common/gpu.h | 5 ++ thorn/include/kernel/peripherals/mailbox.h | 12 ++- thorn/src/common/gpu.c | 98 ++++++++++++++-------- thorn/src/kernel/mailbox.c | 2 +- 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 46b729c..bc8044b 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -22,6 +22,9 @@ #define GPU_MAX_MSG_SIZE 64 +static volatile unsigned int __attribute__((aligned(16))) mbox[36]; + + static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); // framebuffer @@ -31,4 +34,6 @@ bool init_gpu (void); ptr_t get_fb (void); + + #endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/include/kernel/peripherals/mailbox.h b/thorn/include/kernel/peripherals/mailbox.h index 273779c..6b97426 100644 --- a/thorn/include/kernel/peripherals/mailbox.h +++ b/thorn/include/kernel/peripherals/mailbox.h @@ -14,8 +14,16 @@ #define MBOX_READ_EMPTY (1 << 30) #define MBOX_WRITE_FULL (1 << 31) -#define MBOX_IRQ_ENABLE (1 << 0) - #define MBOX_SUCCESS 0x80000000 +enum { + VIDEOCORE_MBOX = (PBASE + 0x0000B880), + MBOX_POLL = (VIDEOCORE_MBOX + 0x10), + MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), + MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), + MBOX_RESPONSE = 0x80000000, + MBOX_FULL = 0x80000000, + MBOX_EMPTY = 0x40000000 +}; + #endif //_ROSE_K_P_MAILBOX_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index a0b8112..2f397ee 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -24,49 +24,73 @@ bool init_gpu () { colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - int test_buffer[20] = {0}; - test_buffer[0] = 80; - test_buffer[1] = 0; - test_buffer[2] = 0x00048003; - test_buffer[3] = 8; - test_buffer[4] = 0; - test_buffer[5] = 640; - test_buffer[6] = 480; - test_buffer[7] = 0x00048004; - test_buffer[8] = 8; - test_buffer[9] = 0; - test_buffer[10] = 640; - test_buffer[11] = 480; - test_buffer[12] = 0x00048005; - test_buffer[13] = 4; - test_buffer[14] = 0; - test_buffer[15] = 24; - test_buffer[16] = 0; + mbox[0] = 80; + mbox[1] = 0; + mbox[2] = 0x00048003; + mbox[3] = 8; + mbox[4] = 0; + mbox[5] = 640; + mbox[6] = 480; + mbox[7] = 0x00048004; + mbox[8] = 8; + mbox[9] = 0; + mbox[10] = 640; + mbox[11] = 480; + mbox[12] = 0x00048005; + mbox[13] = 4; + mbox[14] = 0; + mbox[15] = 24; + mbox[16] = 0; + mbox[17] = 0; + mbox[18] = 0; + mbox[19] = 0; + + + int_dump (sizeof(mbox), (unsigned int *) mbox); + + channel_t ch = PROPERTY_ARM_VC; + + // 28-bit address (MSB) and 4-bit value (LSB) + unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); - int_dump (sizeof(test_buffer), (unsigned int *) test_buffer); + // Wait until we can write + // while (get32(MBOX_STATUS) & MBOX_FULL); - for (int i = 0; i < 20; i++) { - printf("%d ", tag_buffer[i]); + // Write the address of our buffer to the mailbox with the channel appended + put32(MBOX_WRITE, r); + + while (1) { + // Is there a reply? + while (get32(MBOX_STATUS) & MBOX_EMPTY); + + // Is it a reply to our message? + if (r == get32(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? + } - printf ("Preparing screen configuration request...\r\n"); - mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); - printf ("Sending screen configuration request...\r\n"); - if (! mailbox_request ((unsigned int) test_buffer, PROPERTY_ARM_VC)) return false; + + // for (int i = 0; i < 20; i++) { + // printf("%d ", tag_buffer[i]); + // } + + // printf ("Preparing screen configuration request...\r\n"); + // mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); + // printf ("Sending screen configuration request...\r\n"); + // if (! mailbox_request ((unsigned int) mbox, PROPERTY_ARM_VC)) return false; - byte_t alignment[] = {16}; - volatile mbox_tag_t request_fb = { - GPU_REQUEST_FRAMEBUFFER, - 8, - 0, - alignment, - }; - printf ("Preparing framebuffer request...\r\n"); - mailbox_write_msg ((unsigned int) buffer, & request_fb, 1); - printf ("Requesting framebuffer...\r\n"); - if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; + // byte_t alignment[] = {16}; + // volatile mbox_tag_t request_fb = { + // GPU_REQUEST_FRAMEBUFFER, + // 8, + // 0, + // alignment, + // }; + // printf ("Preparing framebuffer request...\r\n"); + // mailbox_write_msg ((unsigned int) buffer, & request_fb, 1); + // printf ("Requesting framebuffer...\r\n"); + // if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; - fb = * ((ptr_t * ) (buffer + 5)); + // fb = * ((ptr_t * ) (buffer + 5)); return true; } diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index f1b9ef6..e26d3e1 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -33,7 +33,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { char * buffer[100]; sprintf (buffer, "Returning response code: operation %s", - (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); LOG (buffer); // Return the message's response code return property->response == MBOX_SUCCESS; From c8f19e5ddf7670233f535405249f0e63335888d0 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 8 Oct 2021 15:43:39 +0200 Subject: [PATCH 13/61] WIP --- thorn/include/common/gpu.h | 3 +- thorn/src/common/debug.c | 13 ++-- thorn/src/common/gpu.c | 133 +++++++++++++++++++++++++------------ 3 files changed, 101 insertions(+), 48 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index bc8044b..5ad2755 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -22,7 +22,7 @@ #define GPU_MAX_MSG_SIZE 64 -static volatile unsigned int __attribute__((aligned(16))) mbox[36]; +static volatile unsigned int __attribute__((aligned(16))) mbox[20]; static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); @@ -35,5 +35,4 @@ bool init_gpu (void); ptr_t get_fb (void); - #endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/src/common/debug.c b/thorn/src/common/debug.c index 82dab7f..563da15 100644 --- a/thorn/src/common/debug.c +++ b/thorn/src/common/debug.c @@ -9,16 +9,19 @@ void print_hex (unsigned char dec) { } void hex_dump (unsigned int size, byte_t * array) { - for (int i = 0; i < size; i ++) { - print_hex (array[i]); - if (! ((i + 1) % 4)) printf (" "); - if (! ((i + 1) % 80)) printf ("\r\n"); + for (int i = 0; i < size;) { + i += 4; + for (int j = 1; j <= 4; j++) { + print_hex (array[i - j]); + } + printf (" "); + if (!(i % 32)) printf ("\r\n"); } printf ("\r\n"); } void int_dump (unsigned int size, unsigned int * array) { - for (int i = 0; i < size / sizeof (int); i ++) { + for (int i = 0; i < size / sizeof (int); i++) { printf ("%d ", array[i]); } printf ("\r\n"); diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 2f397ee..2c4125c 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,29 +1,29 @@ #include "common/gpu.h" bool init_gpu () { - unsigned int tag_buffer[24]; - mbox_tag_t * screen_size = (mbox_tag_t *) tag_buffer; - unsigned int screen_buffer[] = {GPU_SCREEN_WIDTH, GPU_SCREEN_HEIGHT}; - screen_size->identity = GPU_SET_SCREEN_SIZE; - screen_size->buffer_size = 8; - screen_size->response = 0; - screen_size->buffer = (byte_t *) screen_buffer; - - mbox_tag_t * virtual_size = (mbox_tag_t * ) (tag_buffer + sizeof (mbox_tag_t)); - unsigned int virtual_buffer[] = {GPU_VIRTUAL_WIDTH, GPU_VIRTUAL_HEIGHT}; - virtual_size->identity = GPU_SET_VIRTUAL_SIZE; - virtual_size->buffer_size = 8; - virtual_size->response = 0; - virtual_size->buffer = (byte_t *) virtual_buffer; - - mbox_tag_t * colour_depth = (mbox_tag_t * ) (tag_buffer + 2 * sizeof (mbox_tag_t)); - unsigned int colour_depth_buffer = GPU_COLOUR_DEPTH; - colour_depth->identity = GPU_SET_COLOUR_DEPTH; - colour_depth->buffer_size = 4; - colour_depth->response = 0; - colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - - +// unsigned int tag_buffer[24]; +// mbox_tag_t * screen_size = (mbox_tag_t *) tag_buffer; +// unsigned int screen_buffer[] = {GPU_SCREEN_WIDTH, GPU_SCREEN_HEIGHT}; +// screen_size->identity = GPU_SET_SCREEN_SIZE; +// screen_size->buffer_size = 8; +// screen_size->response = 0; +// screen_size->buffer = (byte_t *) screen_buffer; +// +// mbox_tag_t * virtual_size = (mbox_tag_t * ) (tag_buffer + sizeof (mbox_tag_t)); +// unsigned int virtual_buffer[] = {GPU_VIRTUAL_WIDTH, GPU_VIRTUAL_HEIGHT}; +// virtual_size->identity = GPU_SET_VIRTUAL_SIZE; +// virtual_size->buffer_size = 8; +// virtual_size->response = 0; +// virtual_size->buffer = (byte_t *) virtual_buffer; +// +// mbox_tag_t * colour_depth = (mbox_tag_t * ) (tag_buffer + 2 * sizeof (mbox_tag_t)); +// unsigned int colour_depth_buffer = GPU_COLOUR_DEPTH; +// colour_depth->identity = GPU_SET_COLOUR_DEPTH; +// colour_depth->buffer_size = 4; +// colour_depth->response = 0; +// colour_depth->buffer = (byte_t * ) & colour_depth_buffer; + + /* mbox[0] = 80; mbox[1] = 0; mbox[2] = 0x00048003; @@ -45,34 +45,86 @@ bool init_gpu () { mbox[18] = 0; mbox[19] = 0; - - int_dump (sizeof(mbox), (unsigned int *) mbox); - channel_t ch = PROPERTY_ARM_VC; - + int_dump (sizeof (mbox), (unsigned int *) mbox); + hex_dump (sizeof (mbox), (unsigned int *) mbox); + // 28-bit address (MSB) and 4-bit value (LSB) - unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); - + unsigned int outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); + // Wait until we can write - // while (get32(MBOX_STATUS) & MBOX_FULL); + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); // Write the address of our buffer to the mailbox with the channel appended - put32(MBOX_WRITE, r); - + put32 (MBOX0 + MBOX_WRITE, outgoing); + + unsigned int incoming; while (1) { // Is there a reply? - while (get32(MBOX_STATUS) & MBOX_EMPTY); - + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); + + incoming = get32 (MBOX0 + MBOX_READ); + // Is it a reply to our message? - if (r == get32(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? - + if (outgoing == incoming) { + int_dump (sizeof (mbox), (unsigned int *) mbox); + hex_dump (sizeof (mbox), (unsigned int *) mbox); + + if (mbox[1] != MBOX_SUCCESS) { + return false; + } + break; + } } - - + */ + + mbox[0] = 32; + mbox[1] = 0; + mbox[2] = 0x00040001; + mbox[3] = 8; + mbox[4] = 0; + mbox[5] = 16; + mbox[6] = 0; + mbox[7] = 0; + + int_dump (sizeof (mbox), (unsigned int *) mbox); + hex_dump (sizeof (mbox), (unsigned int *) mbox); + + // 28-bit address (MSB) and 4-bit value (LSB) + unsigned int outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); + + // Wait until we can write + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); + + // Write the address of our buffer to the mailbox with the channel appended + put32 (MBOX0 + MBOX_WRITE, outgoing); + + while (1) { + // Is there a reply? + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); + + unsigned int incoming = get32 (MBOX0 + MBOX_READ); + + // Is it a reply to our message? + if (outgoing == incoming) { + int_dump (sizeof (mbox), (unsigned int *) mbox); + hex_dump (sizeof (mbox), (unsigned int *) mbox); + + if (mbox[1] != MBOX_SUCCESS) { + return false; + } + break; + } + } + + + fb = * (ptr_t * ) (mbox + 5 * 4); + return true; + // for (int i = 0; i < 20; i++) { // printf("%d ", tag_buffer[i]); // } - + // printf ("Preparing screen configuration request...\r\n"); // mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); // printf ("Sending screen configuration request...\r\n"); @@ -90,8 +142,7 @@ bool init_gpu () { // printf ("Requesting framebuffer...\r\n"); // if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; - // fb = * ((ptr_t * ) (buffer + 5)); - return true; + // fb = * ((ptr_t * ) (buffer + 20)); } ptr_t get_fb () { From 887b5edf7d9fdd2bb196c86844e4313d4c7c6dea Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Mon, 11 Oct 2021 09:16:14 +0200 Subject: [PATCH 14/61] chore(make): fix stty baud rate for mac (#22) --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f46d029..04d1e09 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ setup-serial-Linux: stty -F $(SERIAL_PORT) $(BAUD_RATE) raw cs8 -ixoff -cstopb -parenb setup-serial-Darwin: + cat -v $(SERIAL_PORT) & stty -f $(SERIAL_PORT) $(BAUD_RATE) raw cs8 -ixoff -cstopb -parenb resend: reboot send From d9d0e4881f207f6790ff895b64ef50ff2f6544f2 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 12:25:49 +0200 Subject: [PATCH 15/61] feat(gpu): hardcode printing of four pixels --- thorn/include/common/debug.h | 4 +- thorn/include/common/gpu.h | 17 +++++++- thorn/src/common/debug.c | 8 ++-- thorn/src/common/gpu.c | 85 ++++++++++++++++++++++++++++-------- thorn/src/kernel/kernel.c | 28 +++++++----- thorn/src/kernel/mailbox.c | 4 +- 6 files changed, 107 insertions(+), 39 deletions(-) diff --git a/thorn/include/common/debug.h b/thorn/include/common/debug.h index 913987a..552b19d 100644 --- a/thorn/include/common/debug.h +++ b/thorn/include/common/debug.h @@ -9,8 +9,8 @@ void print_hex (unsigned char dec); -void byte_dump (unsigned int size, byte_t * array); +void byte_dump (byte_t * array); -void int_dump (unsigned int size, unsigned int * array); +void int_dump (unsigned int * array); #endif //_ROSE_C_DEBUG_H \ No newline at end of file diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 5ad2755..ce78bd6 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -27,12 +27,25 @@ static volatile unsigned int __attribute__((aligned(16))) mbox[20]; static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); +typedef struct { + byte_t blue; + byte_t green; + byte_t red; + byte_t alpha; +} color; + +extern unsigned int const _vgapal[]; +extern color const * vgapal; + + // framebuffer -static ptr_t fb; +static color * fb; bool init_gpu (void); -ptr_t get_fb (void); +void draw (void); + +color * get_fb (void); #endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/src/common/debug.c b/thorn/src/common/debug.c index 563da15..ca910cb 100644 --- a/thorn/src/common/debug.c +++ b/thorn/src/common/debug.c @@ -8,8 +8,8 @@ void print_hex (unsigned char dec) { printf ("%c%c ", fst, snd); } -void hex_dump (unsigned int size, byte_t * array) { - for (int i = 0; i < size;) { +void hex_dump (byte_t * array) { + for (int i = 0; i < * (unsigned int *) array;) { i += 4; for (int j = 1; j <= 4; j++) { print_hex (array[i - j]); @@ -20,8 +20,8 @@ void hex_dump (unsigned int size, byte_t * array) { printf ("\r\n"); } -void int_dump (unsigned int size, unsigned int * array) { - for (int i = 0; i < size / sizeof (int); i++) { +void int_dump (unsigned int * array) { + for (int i = 0; i < * array; i++) { printf ("%d ", array[i]); } printf ("\r\n"); diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 2c4125c..21f0fd3 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,5 +1,26 @@ #include "common/gpu.h" +unsigned int const _vgapal[] = { + 0x000000, + 0x0000AA, + 0x00AA00, + 0x00AAAA, + 0xAA0000, + 0xAA00AA, + 0xAA5500, + 0xAAAAAA, + 0x555555, + 0x5555FF, + 0x55FF55, + 0x55FFFF, + 0xFF5555, + 0xFF55FF, + 0xFFFF55, + 0xFFFFFF +}; + +color const * vgapal = (color * ) & _vgapal; + bool init_gpu () { // unsigned int tag_buffer[24]; // mbox_tag_t * screen_size = (mbox_tag_t *) tag_buffer; @@ -23,14 +44,13 @@ bool init_gpu () { // colour_depth->response = 0; // colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - /* mbox[0] = 80; mbox[1] = 0; mbox[2] = 0x00048003; mbox[3] = 8; mbox[4] = 0; - mbox[5] = 640; - mbox[6] = 480; + mbox[5] = 1920; + mbox[6] = 1080; mbox[7] = 0x00048004; mbox[8] = 8; mbox[9] = 0; @@ -39,15 +59,15 @@ bool init_gpu () { mbox[12] = 0x00048005; mbox[13] = 4; mbox[14] = 0; - mbox[15] = 24; + mbox[15] = 32; mbox[16] = 0; mbox[17] = 0; mbox[18] = 0; mbox[19] = 0; - int_dump (sizeof (mbox), (unsigned int *) mbox); - hex_dump (sizeof (mbox), (unsigned int *) mbox); + int_dump ((unsigned int *) mbox); + hex_dump ((unsigned int *) mbox); // 28-bit address (MSB) and 4-bit value (LSB) unsigned int outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); @@ -67,8 +87,8 @@ bool init_gpu () { // Is it a reply to our message? if (outgoing == incoming) { - int_dump (sizeof (mbox), (unsigned int *) mbox); - hex_dump (sizeof (mbox), (unsigned int *) mbox); + int_dump ((unsigned int *) mbox); + hex_dump ((unsigned int *) mbox); if (mbox[1] != MBOX_SUCCESS) { return false; @@ -76,7 +96,6 @@ bool init_gpu () { break; } } - */ mbox[0] = 32; mbox[1] = 0; @@ -87,11 +106,11 @@ bool init_gpu () { mbox[6] = 0; mbox[7] = 0; - int_dump (sizeof (mbox), (unsigned int *) mbox); - hex_dump (sizeof (mbox), (unsigned int *) mbox); + int_dump ((unsigned int *) mbox); + hex_dump ((unsigned int *) mbox); // 28-bit address (MSB) and 4-bit value (LSB) - unsigned int outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); + outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); // Wait until we can write while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); @@ -103,12 +122,12 @@ bool init_gpu () { // Is there a reply? while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); - unsigned int incoming = get32 (MBOX0 + MBOX_READ); + incoming = get32 (MBOX0 + MBOX_READ); // Is it a reply to our message? if (outgoing == incoming) { - int_dump (sizeof (mbox), (unsigned int *) mbox); - hex_dump (sizeof (mbox), (unsigned int *) mbox); + int_dump ((unsigned int *) mbox); + hex_dump ((unsigned int *) mbox); if (mbox[1] != MBOX_SUCCESS) { return false; @@ -118,7 +137,8 @@ bool init_gpu () { } - fb = * (ptr_t * ) (mbox + 5 * 4); + fb = (color * ) ( + long) (mbox[5] & 0x3FFFFFFF); return true; // for (int i = 0; i < 20; i++) { @@ -145,6 +165,37 @@ bool init_gpu () { // fb = * ((ptr_t * ) (buffer + 20)); } -ptr_t get_fb () { +void draw () { + printf ("\n"); + color black = {0, 0, 0, 0xFF}; + color red = {0, 0, 0xFF, 0xFF}; + color blue = {0xff, 0, 0, 0xFF}; + color green = {0, 0xff, 0, 0xFF}; + color yellow = {0, 0xff, 0xFF, 0xFF}; + color cyan = {0xff, 0xff, 0, 0xff}; + + fb[0] = red; + fb[1] = yellow; + fb[16] = blue; + fb[17] = cyan; + +// for (int i = 0; i < 1024;) { +// fb[i] = black; +// fb[()] = red; +// delay (100000); +// printf ("\r%d ", i); +// printf ("\ri: %d; %p ", i, * (unsigned int *) & c); +// } + +// while (1) { +// for (int i = 0; i < 1024; i++) { +// ((unsigned int *) fb)[i] = c++; +// printf ("\r%p", c); +// delay (100); +// } +// } +} + +color * get_fb () { return fb; } \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 9b9e170..eecf8e9 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -59,26 +59,26 @@ void kernel_process () { void kernel_main (int processor_id) { - static unsigned int current_processor = 0; + static volatile unsigned int current_processor = 0; if (processor_id == 0) { uart_init (); init_printf (0, putc); -// irq_vector_init (); -// timer_init (); -// enable_interrupt_controller (); -// enable_irq (); + irq_vector_init (); + timer_init (); + enable_interrupt_controller (); + enable_irq (); // task_init (); - + LOG("Logging works"); printf ("Initialising Framebuffer...\r\n"); int gpu_status = init_gpu (); - if (! gpu_status) { + if (!gpu_status) { printf ("Error while initialising Framebuffer\r\n"); } else { unsigned long fb = get_fb (); - if (! fb) { + if (!fb) { printf ("Error: Invalid Framebuffer received\r\n"); } else { printf ("Received framebuffer: %p\r\n", fb); @@ -91,9 +91,12 @@ void kernel_main (int processor_id) { printf ("Hello, from processor %d\n\r", processor_id); current_processor++; + + if (processor_id == 0) { + while (current_processor != 3); + + draw (); -// if (processor_id == 0) { -// while (current_processor != 4); // int res = copy_process (PF_KTHREAD, (unsigned long) & kernel_process, 0, 0); // if (res < 0) { // printf ("error while starting kernel process"); @@ -103,5 +106,8 @@ void kernel_main (int processor_id) { // while (1) { // schedule (); // } -// } + } + + LOG("DONE PRINTING"); + while (1); } diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index e26d3e1..cf86e08 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -33,7 +33,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { char * buffer[100]; sprintf (buffer, "Returning response code: operation %s", - (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); LOG (buffer); // Return the message's response code return property->response == MBOX_SUCCESS; @@ -52,8 +52,6 @@ unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int t // write struct size to message: msg->struct_size = struct_size; - int_dump (struct_size, (unsigned int *) msg); - // return number of bytes written, for reference return struct_size; } From 515428164d095f342597f61ba413fe16d9cd24d6 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 15:06:34 +0200 Subject: [PATCH 16/61] WIP --- thorn/src/common/gpu.c | 43 +++++++++++++++++++++------------------ thorn/src/kernel/kernel.c | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 21f0fd3..2eadd1d 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -48,12 +48,12 @@ bool init_gpu () { mbox[1] = 0; mbox[2] = 0x00048003; mbox[3] = 8; - mbox[4] = 0; + mbox[4] = 8; mbox[5] = 1920; mbox[6] = 1080; mbox[7] = 0x00048004; mbox[8] = 8; - mbox[9] = 0; + mbox[9] = 8; mbox[10] = 640; mbox[11] = 480; mbox[12] = 0x00048005; @@ -174,26 +174,29 @@ void draw () { color yellow = {0, 0xff, 0xFF, 0xFF}; color cyan = {0xff, 0xff, 0, 0xff}; - fb[0] = red; - fb[1] = yellow; - fb[16] = blue; - fb[17] = cyan; - -// for (int i = 0; i < 1024;) { -// fb[i] = black; -// fb[()] = red; -// delay (100000); -// printf ("\r%d ", i); -// printf ("\ri: %d; %p ", i, * (unsigned int *) & c); -// } + char index[] = {0, 1, 16, 17}; + + byte_t c[] = {0xff, 0xff, 0xff, 0}; + color colour = * (color *) c; + unsigned int c_int = * (unsigned int *) c; + while (1) { + for (int i = 0; i < 4; i++) { + c_int = c_int ? 0 : 0xFFFFFF; + fb[index[i]] = colour; + } + delay (30000); -// while (1) { -// for (int i = 0; i < 1024; i++) { -// ((unsigned int *) fb)[i] = c++; -// printf ("\r%p", c); -// delay (100); +// for (int i = 0; i < 4; i++) { +// for (int ci = 0; ci < 3; ci++) { +// for (int ind = 0; ind < 256; ind++) { +// c[ci] = ind; +// c[(ci + 1) % 3] = 255 - ind; +// fb[index[i]] = * (color *) c; +// delay (100); +// } +// } // } -// } + } } color * get_fb () { diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index eecf8e9..9b77044 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -106,8 +106,8 @@ void kernel_main (int processor_id) { // while (1) { // schedule (); // } + LOG("DONE PRINTING"); } - LOG("DONE PRINTING"); while (1); } From 5fee6532b9540d7bc4c4b3a4274d1af9323af099 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 16:00:06 +0200 Subject: [PATCH 17/61] feat(gpu): fix screen size and print RAINBOW --- thorn/include/common/gpu.h | 10 ++-- thorn/src/common/gpu.c | 107 ++++++++++++------------------------- 2 files changed, 38 insertions(+), 79 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index ce78bd6..b867bcc 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -13,16 +13,16 @@ // https://jsandler18.github.io/extra/prop-channel.html #define GPU_SCREEN_WIDTH 1920 -#define GPU_SCREEN_HEIGHT 1280 +#define GPU_SCREEN_HEIGHT 1080 -#define GPU_VIRTUAL_WIDTH 1920 -#define GPU_VIRTUAL_HEIGHT 1280 +#define GPU_VIRTUAL_WIDTH GPU_SCREEN_WIDTH +#define GPU_VIRTUAL_HEIGHT GPU_SCREEN_HEIGHT -#define GPU_COLOUR_DEPTH 24 +#define GPU_COLOUR_DEPTH 32 #define GPU_MAX_MSG_SIZE 64 -static volatile unsigned int __attribute__((aligned(16))) mbox[20]; +static volatile unsigned int __attribute__((aligned(16))) mbox[24]; static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 2eadd1d..c98793e 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -44,26 +44,30 @@ bool init_gpu () { // colour_depth->response = 0; // colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - mbox[0] = 80; + mbox[0] = 96; mbox[1] = 0; mbox[2] = 0x00048003; mbox[3] = 8; mbox[4] = 8; - mbox[5] = 1920; - mbox[6] = 1080; + mbox[5] = GPU_SCREEN_WIDTH; + mbox[6] = GPU_SCREEN_HEIGHT; mbox[7] = 0x00048004; mbox[8] = 8; mbox[9] = 8; - mbox[10] = 640; - mbox[11] = 480; + mbox[10] = GPU_VIRTUAL_WIDTH; + mbox[11] = GPU_VIRTUAL_HEIGHT; mbox[12] = 0x00048005; mbox[13] = 4; mbox[14] = 0; - mbox[15] = 32; - mbox[16] = 0; - mbox[17] = 0; + mbox[15] = GPU_COLOUR_DEPTH; + mbox[16] = 0x00040001; + mbox[17] = 8; mbox[18] = 0; - mbox[19] = 0; + mbox[19] = 16; + mbox[20] = 0; + mbox[21] = 0; + mbox[22] = 0; + mbox[23] = 0; int_dump ((unsigned int *) mbox); @@ -97,48 +101,12 @@ bool init_gpu () { } } - mbox[0] = 32; - mbox[1] = 0; - mbox[2] = 0x00040001; - mbox[3] = 8; - mbox[4] = 0; - mbox[5] = 16; - mbox[6] = 0; - mbox[7] = 0; int_dump ((unsigned int *) mbox); hex_dump ((unsigned int *) mbox); - // 28-bit address (MSB) and 4-bit value (LSB) - outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); - - // Wait until we can write - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); - - // Write the address of our buffer to the mailbox with the channel appended - put32 (MBOX0 + MBOX_WRITE, outgoing); - - while (1) { - // Is there a reply? - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); - - incoming = get32 (MBOX0 + MBOX_READ); - - // Is it a reply to our message? - if (outgoing == incoming) { - int_dump ((unsigned int *) mbox); - hex_dump ((unsigned int *) mbox); - - if (mbox[1] != MBOX_SUCCESS) { - return false; - } - break; - } - } - - fb = (color * ) ( - long) (mbox[5] & 0x3FFFFFFF); + long) (mbox[19] & 0x3FFFFFFF); return true; // for (int i = 0; i < 20; i++) { @@ -167,35 +135,26 @@ bool init_gpu () { void draw () { printf ("\n"); - color black = {0, 0, 0, 0xFF}; - color red = {0, 0, 0xFF, 0xFF}; - color blue = {0xff, 0, 0, 0xFF}; - color green = {0, 0xff, 0, 0xFF}; - color yellow = {0, 0xff, 0xFF, 0xFF}; - color cyan = {0xff, 0xff, 0, 0xff}; - - char index[] = {0, 1, 16, 17}; - - byte_t c[] = {0xff, 0xff, 0xff, 0}; - color colour = * (color *) c; - unsigned int c_int = * (unsigned int *) c; - while (1) { - for (int i = 0; i < 4; i++) { - c_int = c_int ? 0 : 0xFFFFFF; - fb[index[i]] = colour; + + color rainbow[] = { + {0x80, 0x00, 0xff, 0}, + {0x00, 0x00, 0xff, 0}, + {0x00, 0x80, 0xff, 0}, + {0x00, 0xff, 0xff, 0}, + {0x00, 0xff, 0x80, 0}, + {0x00, 0xff, 0x00, 0}, + {0x80, 0xff, 0x00, 0}, + {0xff, 0xff, 0x00, 0}, + {0xff, 0x80, 0x00, 0}, + {0xff, 0x00, 0x00, 0}, + {0xff, 0x00, 0x80, 0} + }; + + color c = {0, 0, 0, 0}; + for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { + for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { + fb[y * GPU_SCREEN_WIDTH + x] = rainbow[x / (GPU_SCREEN_WIDTH / (sizeof (rainbow) / sizeof (color)))]; } - delay (30000); - -// for (int i = 0; i < 4; i++) { -// for (int ci = 0; ci < 3; ci++) { -// for (int ind = 0; ind < 256; ind++) { -// c[ci] = ind; -// c[(ci + 1) % 3] = 255 - ind; -// fb[index[i]] = * (color *) c; -// delay (100); -// } -// } -// } } } From 520a3da9cc35267924ec81ace9a57827e718a3bf Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 16:41:18 +0200 Subject: [PATCH 18/61] refactor(gpu): clean up unused code and add comments --- thorn/include/common/gpu.h | 12 +--- thorn/src/common/gpu.c | 139 ++++++++++++------------------------- 2 files changed, 45 insertions(+), 106 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index b867bcc..15a01ce 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -20,13 +20,6 @@ #define GPU_COLOUR_DEPTH 32 -#define GPU_MAX_MSG_SIZE 64 - -static volatile unsigned int __attribute__((aligned(16))) mbox[24]; - - -static volatile unsigned int buffer[GPU_MAX_MSG_SIZE] __attribute__((aligned(16))); - typedef struct { byte_t blue; byte_t green; @@ -34,13 +27,12 @@ typedef struct { byte_t alpha; } color; -extern unsigned int const _vgapal[]; -extern color const * vgapal; - +static volatile unsigned int __attribute__((aligned(16))) mbox[2048]; // framebuffer static color * fb; + bool init_gpu (void); void draw (void); diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index c98793e..75bea0f 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,73 +1,37 @@ #include "common/gpu.h" -unsigned int const _vgapal[] = { - 0x000000, - 0x0000AA, - 0x00AA00, - 0x00AAAA, - 0xAA0000, - 0xAA00AA, - 0xAA5500, - 0xAAAAAA, - 0x555555, - 0x5555FF, - 0x55FF55, - 0x55FFFF, - 0xFF5555, - 0xFF55FF, - 0xFFFF55, - 0xFFFFFF -}; - -color const * vgapal = (color * ) & _vgapal; - bool init_gpu () { -// unsigned int tag_buffer[24]; -// mbox_tag_t * screen_size = (mbox_tag_t *) tag_buffer; -// unsigned int screen_buffer[] = {GPU_SCREEN_WIDTH, GPU_SCREEN_HEIGHT}; -// screen_size->identity = GPU_SET_SCREEN_SIZE; -// screen_size->buffer_size = 8; -// screen_size->response = 0; -// screen_size->buffer = (byte_t *) screen_buffer; -// -// mbox_tag_t * virtual_size = (mbox_tag_t * ) (tag_buffer + sizeof (mbox_tag_t)); -// unsigned int virtual_buffer[] = {GPU_VIRTUAL_WIDTH, GPU_VIRTUAL_HEIGHT}; -// virtual_size->identity = GPU_SET_VIRTUAL_SIZE; -// virtual_size->buffer_size = 8; -// virtual_size->response = 0; -// virtual_size->buffer = (byte_t *) virtual_buffer; -// -// mbox_tag_t * colour_depth = (mbox_tag_t * ) (tag_buffer + 2 * sizeof (mbox_tag_t)); -// unsigned int colour_depth_buffer = GPU_COLOUR_DEPTH; -// colour_depth->identity = GPU_SET_COLOUR_DEPTH; -// colour_depth->buffer_size = 4; -// colour_depth->response = 0; -// colour_depth->buffer = (byte_t * ) & colour_depth_buffer; - - mbox[0] = 96; - mbox[1] = 0; - mbox[2] = 0x00048003; - mbox[3] = 8; - mbox[4] = 8; - mbox[5] = GPU_SCREEN_WIDTH; - mbox[6] = GPU_SCREEN_HEIGHT; - mbox[7] = 0x00048004; - mbox[8] = 8; - mbox[9] = 8; - mbox[10] = GPU_VIRTUAL_WIDTH; - mbox[11] = GPU_VIRTUAL_HEIGHT; - mbox[12] = 0x00048005; - mbox[13] = 4; - mbox[14] = 0; - mbox[15] = GPU_COLOUR_DEPTH; - mbox[16] = 0x00040001; - mbox[17] = 8; - mbox[18] = 0; - mbox[19] = 16; - mbox[20] = 0; - mbox[21] = 0; - mbox[22] = 0; - mbox[23] = 0; + int c = 0; + mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + mbox[++c] = 0x00048003; // Tag to set physical display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_SCREEN_WIDTH; // Set physical screen width | Overwritten by actual width + mbox[++c] = GPU_SCREEN_HEIGHT; // Set physical screen height | Overwritten by actual height + + mbox[++c] = 0x00048004; // Tag to set virtual display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + mbox[++c] = GPU_VIRTUAL_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height + + mbox[++c] = 0x00048005; // Tag to set pixel depth + mbox[++c] = 4; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_COLOUR_DEPTH; // Set colour depth | Overwritten by actual colour depth + + mbox[++c] = 0x00040001; // Tag to allocate framebuffer + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size will be written here + mbox[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer + mbox[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer + + mbox[++c] = 0; // End tag + mbox[++c] = 0; // Padding + mbox[++c] = 0; // Padding + + mbox[0] = 4 * c; // Write message size at the beginning of the buffer int_dump ((unsigned int *) mbox); @@ -101,36 +65,12 @@ bool init_gpu () { } } - int_dump ((unsigned int *) mbox); hex_dump ((unsigned int *) mbox); fb = (color * ) ( long) (mbox[19] & 0x3FFFFFFF); return true; - - // for (int i = 0; i < 20; i++) { - // printf("%d ", tag_buffer[i]); - // } - - // printf ("Preparing screen configuration request...\r\n"); - // mailbox_write_msg (buffer, (mbox_tag_t *) tag_buffer, 3); - // printf ("Sending screen configuration request...\r\n"); - // if (! mailbox_request ((unsigned int) mbox, PROPERTY_ARM_VC)) return false; - - // byte_t alignment[] = {16}; - // volatile mbox_tag_t request_fb = { - // GPU_REQUEST_FRAMEBUFFER, - // 8, - // 0, - // alignment, - // }; - // printf ("Preparing framebuffer request...\r\n"); - // mailbox_write_msg ((unsigned int) buffer, & request_fb, 1); - // printf ("Requesting framebuffer...\r\n"); - // if (! mailbox_request ((unsigned int) buffer, PROPERTY_ARM_VC)) return false; - - // fb = * ((ptr_t * ) (buffer + 20)); } void draw () { @@ -147,13 +87,20 @@ void draw () { {0xff, 0xff, 0x00, 0}, {0xff, 0x80, 0x00, 0}, {0xff, 0x00, 0x00, 0}, - {0xff, 0x00, 0x80, 0} + {0xff, 0x00, 0x80, 0}, + {0xff, 0x00, 0xff, 0} }; - color c = {0, 0, 0, 0}; - for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { - for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { - fb[y * GPU_SCREEN_WIDTH + x] = rainbow[x / (GPU_SCREEN_WIDTH / (sizeof (rainbow) / sizeof (color)))]; + int rb_size = sizeof (rainbow) / sizeof (color); + int divisor = GPU_SCREEN_WIDTH / rb_size; + + while (1) { + for (int offset = 0; offset < rb_size; offset++) { + for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % rb_size; x++) { + for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { + fb[y * GPU_SCREEN_WIDTH + x] = rainbow[(x / divisor + offset) % rb_size]; + } + } } } } From 8c67b8f2be0e84118decd80a77efc70c24553a9d Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 17:01:53 +0200 Subject: [PATCH 19/61] feat(gpu): use physical dimensions read as virtual size --- thorn/include/common/gpu.h | 12 ++++--- thorn/src/common/gpu.c | 74 +++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 15a01ce..f7a25ff 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -12,13 +12,15 @@ // Reference: // https://jsandler18.github.io/extra/prop-channel.html -#define GPU_SCREEN_WIDTH 1920 -#define GPU_SCREEN_HEIGHT 1080 +#define GPU_SCREEN_WIDTH 1920 +#define GPU_SCREEN_HEIGHT 1080 -#define GPU_VIRTUAL_WIDTH GPU_SCREEN_WIDTH -#define GPU_VIRTUAL_HEIGHT GPU_SCREEN_HEIGHT +#define GPU_VIRTUAL_WIDTH GPU_SCREEN_WIDTH +#define GPU_VIRTUAL_HEIGHT GPU_SCREEN_HEIGHT -#define GPU_COLOUR_DEPTH 32 +#define GPU_COLOUR_DEPTH 32 + +#define VC_SDRAM_OFFSET 0x3FFFFFFF typedef struct { byte_t blue; diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 75bea0f..dcdfd39 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,38 +1,48 @@ #include "common/gpu.h" bool init_gpu () { - int c = 0; - mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE - - mbox[++c] = 0x00048003; // Tag to set physical display width / height - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_SCREEN_WIDTH; // Set physical screen width | Overwritten by actual width - mbox[++c] = GPU_SCREEN_HEIGHT; // Set physical screen height | Overwritten by actual height - - mbox[++c] = 0x00048004; // Tag to set virtual display width / height - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width - mbox[++c] = GPU_VIRTUAL_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height - - mbox[++c] = 0x00048005; // Tag to set pixel depth - mbox[++c] = 4; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_COLOUR_DEPTH; // Set colour depth | Overwritten by actual colour depth - - mbox[++c] = 0x00040001; // Tag to allocate framebuffer - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size will be written here - mbox[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer - mbox[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer - - mbox[++c] = 0; // End tag - mbox[++c] = 0; // Padding - mbox[++c] = 0; // Padding - - mbox[0] = 4 * c; // Write message size at the beginning of the buffer + { // First message: read physical dimensions + int c = 0; // Message size; increment while we write + mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + mbox[++c] = 0x00040003; // Tag to get physical display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_SCREEN_WIDTH; // Get physical screen width | Overwritten by actual width + mbox[++c] = GPU_SCREEN_HEIGHT; // Get physical screen height | Overwritten by actual height + + mbox[0] = 4 * c; // Write message size at the beginning of the buffer + } + byte_t index_framebuffer; + { + int c = 0; // Message size; increment while we write + mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + mbox[++c] = 0x00048004; // Tag to set virtual display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c];//GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + mbox[++c];//GPU_SCREEN_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height + + mbox[++c] = 0x00048005; // Tag to set pixel depth + mbox[++c] = 4; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_COLOUR_DEPTH; // Set colour depth | Overwritten by actual colour depth + + mbox[++c] = 0x00040001; // Tag to allocate framebuffer + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size will be written here + mbox[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer + index_framebuffer = c; + mbox[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer + + mbox[++c] = 0; // End tag + mbox[++c] = 0; // Padding + mbox[++c] = 0; // Padding + + mbox[0] = 4 * c; // Write message size at the beginning of the buffer + } int_dump ((unsigned int *) mbox); hex_dump ((unsigned int *) mbox); @@ -69,7 +79,7 @@ bool init_gpu () { hex_dump ((unsigned int *) mbox); fb = (color * ) ( - long) (mbox[19] & 0x3FFFFFFF); + long) (mbox[index_framebuffer] & VC_SDRAM_OFFSET); return true; } From d1bbd1de1a8c2cb375c16650084d457d18efb110 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 17:20:10 +0200 Subject: [PATCH 20/61] feat(gpu): update screensaver --- thorn/src/common/gpu.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index dcdfd39..9c8fbc6 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -102,13 +102,24 @@ void draw () { }; int rb_size = sizeof (rainbow) / sizeof (color); - int divisor = GPU_SCREEN_WIDTH / rb_size; + int divisor; while (1) { for (int offset = 0; offset < rb_size; offset++) { - for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % rb_size; x++) { + divisor = GPU_SCREEN_WIDTH / rb_size; + for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % divisor; x++) { for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { - fb[y * GPU_SCREEN_WIDTH + x] = rainbow[(x / divisor + offset) % rb_size]; + fb[y * GPU_SCREEN_WIDTH + x].red ^= rainbow[(x / divisor + offset) % rb_size].red; + fb[y * GPU_SCREEN_WIDTH + x].green ^= rainbow[(x / divisor + offset) % rb_size].green; + fb[y * GPU_SCREEN_WIDTH + x].blue ^= rainbow[(x / divisor + offset) % rb_size].blue; + } + } + divisor = GPU_SCREEN_HEIGHT / rb_size; + for (int y = 0; y < GPU_SCREEN_HEIGHT - GPU_SCREEN_HEIGHT % divisor; y++) { + for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { + fb[y * GPU_SCREEN_WIDTH + x].red ^= rainbow[(y / divisor + offset) % rb_size].red; + fb[y * GPU_SCREEN_WIDTH + x].green ^= rainbow[(y / divisor + offset) % rb_size].green; + fb[y * GPU_SCREEN_WIDTH + x].blue ^= rainbow[(y / divisor + offset) % rb_size].blue; } } } From 32b473d97e15c3de49e5adf6774eb1f8c2923ba2 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 17:48:16 +0200 Subject: [PATCH 21/61] feat(gpu): read out physical dims to use for virtual dims --- thorn/include/common/debug.h | 2 +- thorn/include/kernel/mailbox.h | 23 +------- thorn/src/common/gpu.c | 53 ++++------------- thorn/src/kernel/mailbox.c | 104 +++++++++++---------------------- 4 files changed, 50 insertions(+), 132 deletions(-) diff --git a/thorn/include/common/debug.h b/thorn/include/common/debug.h index 552b19d..d5c9c9b 100644 --- a/thorn/include/common/debug.h +++ b/thorn/include/common/debug.h @@ -9,7 +9,7 @@ void print_hex (unsigned char dec); -void byte_dump (byte_t * array); +void hex_dump (byte_t * array); void int_dump (unsigned int * array); diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h index 8ef3619..16075ca 100644 --- a/thorn/include/kernel/mailbox.h +++ b/thorn/include/kernel/mailbox.h @@ -10,6 +10,8 @@ #include "common/debug.h" #include "common/logging.h" +#define DUMP_BUFFER true + // Documentation: // https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface @@ -28,30 +30,11 @@ typedef enum { typedef struct { - unsigned int data: 28; // most significant bits contain shared memory address + unsigned int data: 28; // most significant bits contain shared memory address channel_t channel: 4; // least four significant bits contain channel } mbox_message_t; -typedef struct { - unsigned int identity; - unsigned int buffer_size; - unsigned int response; - byte_t * buffer; -} mbox_tag_t; - -typedef struct { - unsigned int struct_size; - unsigned int response; - mbox_tag_t * tags; -} mbox_property_t; - // Send message and check responses bool mailbox_request (unsigned int data_ptr, channel_t channel); -// Returns total size written -unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count); - -// Returns total size written -unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count); - #endif //_ROSE_K_MAILBOX_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 9c8fbc6..5526113 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -6,15 +6,17 @@ bool init_gpu () { mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE mbox[++c] = 0x00040003; // Tag to get physical display width / height - mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Size of value buffer mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_SCREEN_WIDTH; // Get physical screen width | Overwritten by actual width - mbox[++c] = GPU_SCREEN_HEIGHT; // Get physical screen height | Overwritten by actual height + mbox[++c] = 0; // Get physical screen width | Overwritten by actual width + mbox[++c] = 0; // Get physical screen height | Overwritten by actual height - mbox[0] = 4 * c; // Write message size at the beginning of the buffer + mbox[0] = 4 * ++c; // Write message size at the beginning of the buffer + + // If reading physical screen dimension fails exit function + if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; } - byte_t index_framebuffer; { int c = 0; // Message size; increment while we write mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE @@ -34,7 +36,7 @@ bool init_gpu () { mbox[++c] = 8; // Size of value buffer mbox[++c] = 0; // Response & value buffer size will be written here mbox[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer - index_framebuffer = c; + byte_t index_framebuffer = c; mbox[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer mbox[++c] = 0; // End tag @@ -42,44 +44,13 @@ bool init_gpu () { mbox[++c] = 0; // Padding mbox[0] = 4 * c; // Write message size at the beginning of the buffer - } - - int_dump ((unsigned int *) mbox); - hex_dump ((unsigned int *) mbox); - - // 28-bit address (MSB) and 4-bit value (LSB) - unsigned int outgoing = ((unsigned int) ((long) mbox) & ~0xF) | (PROPERTY_ARM_VC & 0xF); - - // Wait until we can write - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); - - // Write the address of our buffer to the mailbox with the channel appended - put32 (MBOX0 + MBOX_WRITE, outgoing); - - unsigned int incoming; - while (1) { - // Is there a reply? - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); - incoming = get32 (MBOX0 + MBOX_READ); + // If message failed exit + if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; - // Is it a reply to our message? - if (outgoing == incoming) { - int_dump ((unsigned int *) mbox); - hex_dump ((unsigned int *) mbox); - - if (mbox[1] != MBOX_SUCCESS) { - return false; - } - break; - } + // Since message succeeded, update the frame buffer + fb = (color * ) (mbox[index_framebuffer] & VC_SDRAM_OFFSET); } - - int_dump ((unsigned int *) mbox); - hex_dump ((unsigned int *) mbox); - - fb = (color * ) ( - long) (mbox[index_framebuffer] & VC_SDRAM_OFFSET); return true; } diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index cf86e08..81e153d 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -1,83 +1,47 @@ #include "kernel/mailbox.h" bool mailbox_request (unsigned int data_ptr, channel_t channel) { - mbox_message_t msg; - unsigned int * msg_ptr = (unsigned int *) & msg; - unsigned int check; + unsigned int * buffer = (unsigned int *) (long) data_ptr; - * msg_ptr = data_ptr; - msg.channel = channel; - - LOG ("Waiting for empty write buffer GPU..."); - while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); - - LOG ("Writing to GPU..."); - put32 (MBOX0 + MBOX_WRITE, * msg_ptr); - - LOG ("Reading response..."); - do { - // Wait until there's a message - LOG ("Waiting for any message..."); - while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); - - LOG ("Check message"); - check = get32 (MBOX0 + MBOX_READ); - - LOG ("Check channel"); - // Check if it's the response to our message - } while (* msg_ptr == check); - - LOG ("Read pointer to property response"); - // Get the pointer to the property request message - mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~0xFF)); - - char * buffer[100]; - sprintf (buffer, "Returning response code: operation %s", - (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); - LOG (buffer); - // Return the message's response code - return property->response == MBOX_SUCCESS; -} - -unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count) { - mbox_property_t * msg = (mbox_property_t * ) & message; + if (DUMP_BUFFER) { + int_dump ((byte_t *) buffer); + hex_dump ((unsigned int *) (long) buffer); + } - // Add tags to message: - unsigned int struct_size = 2 * sizeof (unsigned int); - struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags, tags_count); + // 28-bit address (MSB) and 4-bit value (LSB) + unsigned int outgoing = ((unsigned int) ((long) data_ptr) & ~0xF) | (channel & 0xF); - // Add end tag and 16 byte-aligned padding: - struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; + // Wait until we can write + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL); - // write struct size to message: - msg->struct_size = struct_size; + // Write the address of our buffer to the mailbox with the channel appended + put32 (MBOX0 + MBOX_WRITE, outgoing); - // return number of bytes written, for reference - return struct_size; -} - -unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count) { - unsigned int written = 0; - for (int i = 0; i < tags_count; i++) { - dest += written; + unsigned int incoming; + while (1) { + // Is there a reply? + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY); - unsigned int buffer_size = src->buffer_size; + incoming = get32 (MBOX0 + MBOX_READ); - dest->identity = src->identity; - dest->buffer_size = buffer_size; - dest->response = 0; - - for (unsigned int i = 0; i < buffer_size; i++) { - dest->buffer[written] = src->buffer[written]; + // Is it a reply to our message? + if (outgoing == incoming) { + if (buffer[1] != MBOX_SUCCESS) { + if (DUMP_BUFFER) { + int_dump ((byte_t *) buffer); + hex_dump ((unsigned int *) buffer); + } + + return false; + } + break; } - written += 3 * sizeof (unsigned int) + buffer_size; - put32 ((unsigned int) (dest + written), 0); - - written += sizeof (unsigned int); - put32 ((unsigned int) (dest + written), 0); - - written += (written % 16) ? 16 - (written % 16) : 0; } - return written; -} \ No newline at end of file + if (DUMP_BUFFER) { + int_dump ((byte_t *) buffer); + hex_dump ((unsigned int *) buffer); + } + + return true; +} From 9712af459a8d3dcd4848d5034b8c6bb7544cf02a Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 17:53:52 +0200 Subject: [PATCH 22/61] refactor(gpu): allow overriding screen dims read from GPU --- thorn/include/common/gpu.h | 7 +++++-- thorn/src/common/gpu.c | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index f7a25ff..ce23aba 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -12,8 +12,11 @@ // Reference: // https://jsandler18.github.io/extra/prop-channel.html -#define GPU_SCREEN_WIDTH 1920 -#define GPU_SCREEN_HEIGHT 1080 +// Uncomment to override physical / virtual screen size with the values defined below +//#define GPU_OVERRIDE_PHYSICAL_SCREEN + +#define GPU_SCREEN_WIDTH 1920 // Width used if Override is enabled +#define GPU_SCREEN_HEIGHT 1080 // Height used if Override is enabled #define GPU_VIRTUAL_WIDTH GPU_SCREEN_WIDTH #define GPU_VIRTUAL_HEIGHT GPU_SCREEN_HEIGHT diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 5526113..929d81d 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -20,12 +20,26 @@ bool init_gpu () { { int c = 0; // Message size; increment while we write mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + +#ifdef GPU_OVERRIDE_PHYSICAL_SCREEN + mbox[++c] = 0x00048003; // Tag to set virtual display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + mbox[++c] = GPU_SCREEN_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height mbox[++c] = 0x00048004; // Tag to set virtual display width / height mbox[++c] = 8; // Size of value buffer mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c];//GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width - mbox[++c];//GPU_SCREEN_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height + mbox[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + mbox[++c] = GPU_VIRTUAL_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height +#else + mbox[++c] = 0x00048004; // Tag to set virtual display width / height + mbox[++c] = 8; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c];//GPU_SCREEN_WIDTH; // Keep virtual screen width | Overwritten by actual virtual width + mbox[++c];//GPU_SCREEN_HEIGHT; // Keep virtual screen height | Overwritten by actual virtual height +#endif mbox[++c] = 0x00048005; // Tag to set pixel depth mbox[++c] = 4; // Size of value buffer @@ -43,7 +57,7 @@ bool init_gpu () { mbox[++c] = 0; // Padding mbox[++c] = 0; // Padding - mbox[0] = 4 * c; // Write message size at the beginning of the buffer + mbox[0] = 4 * ++c; // Write message size at the beginning of the buffer // If message failed exit if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; @@ -58,6 +72,7 @@ void draw () { printf ("\n"); color rainbow[] = { + {0xff, 0x00, 0xff, 0}, {0x80, 0x00, 0xff, 0}, {0x00, 0x00, 0xff, 0}, {0x00, 0x80, 0xff, 0}, @@ -68,8 +83,7 @@ void draw () { {0xff, 0xff, 0x00, 0}, {0xff, 0x80, 0x00, 0}, {0xff, 0x00, 0x00, 0}, - {0xff, 0x00, 0x80, 0}, - {0xff, 0x00, 0xff, 0} + {0xff, 0x00, 0x80, 0} }; int rb_size = sizeof (rainbow) / sizeof (color); From 16b5d6debe1e2e98d886916c9458fe750a4ffb2f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 18:25:00 +0200 Subject: [PATCH 23/61] feat(gpu): request pitch NOTE: received pitch is always 0! --- thorn/include/common/gpu.h | 2 +- thorn/src/common/gpu.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index ce23aba..7046c7c 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -13,7 +13,7 @@ // https://jsandler18.github.io/extra/prop-channel.html // Uncomment to override physical / virtual screen size with the values defined below -//#define GPU_OVERRIDE_PHYSICAL_SCREEN +#define GPU_OVERRIDE_PHYSICAL_SCREEN #define GPU_SCREEN_WIDTH 1920 // Width used if Override is enabled #define GPU_SCREEN_HEIGHT 1080 // Height used if Override is enabled diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 929d81d..a77a73a 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -11,7 +11,9 @@ bool init_gpu () { mbox[++c] = 0; // Get physical screen width | Overwritten by actual width mbox[++c] = 0; // Get physical screen height | Overwritten by actual height - mbox[0] = 4 * ++c; // Write message size at the beginning of the buffer + mbox[++c] = 0; // End tag + + mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer // If reading physical screen dimension fails exit function if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; @@ -56,8 +58,9 @@ bool init_gpu () { mbox[++c] = 0; // End tag mbox[++c] = 0; // Padding mbox[++c] = 0; // Padding + mbox[++c] = 0; // Padding - mbox[0] = 4 * ++c; // Write message size at the beginning of the buffer + mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer // If message failed exit if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; @@ -65,6 +68,27 @@ bool init_gpu () { // Since message succeeded, update the frame buffer fb = (color * ) (mbox[index_framebuffer] & VC_SDRAM_OFFSET); } + { // Third message: read pitch (in bytes per line) + int c = 0; // Message size; increment while we write + mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + mbox[++c] = 0x00040008; // Tag to get pitch + mbox[++c] = 0; // Size of value buffer + mbox[++c] = 0; // Response & value buffer size written will be written here + mbox[++c] = 0; // Pitch will be written here + int index_pitch = c; + + mbox[++c] = 0; // End tag + mbox[++c] = 0; // Padding + + mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer + + // If message failed exit + if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; + if (mbox[index_pitch]) {printf ("\r\nGot pitch: %d\r\n", mbox[index_pitch]);} + else {printf ("\r\nPitch received as 0\r\n");} + } + return true; } From 8e0be78ce5f2183e525ddf6aa06ad22001065c14 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 18:27:54 +0200 Subject: [PATCH 24/61] fix(debug): fix int dump printing too many integers --- thorn/src/common/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thorn/src/common/debug.c b/thorn/src/common/debug.c index ca910cb..5d61ef7 100644 --- a/thorn/src/common/debug.c +++ b/thorn/src/common/debug.c @@ -21,7 +21,7 @@ void hex_dump (byte_t * array) { } void int_dump (unsigned int * array) { - for (int i = 0; i < * array; i++) { + for (int i = 0; i < * array / 4; i++) { printf ("%d ", array[i]); } printf ("\r\n"); From 2bdbc94d89c4911c67f4def998dba7ef422a1d15 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 18:30:12 +0200 Subject: [PATCH 25/61] refactor(debug): make output more understandable --- thorn/src/common/gpu.c | 2 +- thorn/src/kernel/mailbox.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index a77a73a..4e964a2 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -86,7 +86,7 @@ bool init_gpu () { // If message failed exit if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; if (mbox[index_pitch]) {printf ("\r\nGot pitch: %d\r\n", mbox[index_pitch]);} - else {printf ("\r\nPitch received as 0\r\n");} + else {printf ("\r\nPitch is 0?!\r\n");} } return true; diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index 81e153d..503711f 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -4,6 +4,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { unsigned int * buffer = (unsigned int *) (long) data_ptr; if (DUMP_BUFFER) { + LOG ("Dumping message buffer before sending:"); int_dump ((byte_t *) buffer); hex_dump ((unsigned int *) (long) buffer); } @@ -28,6 +29,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { if (outgoing == incoming) { if (buffer[1] != MBOX_SUCCESS) { if (DUMP_BUFFER) { + LOG ("Dumping failed message buffer:"); int_dump ((byte_t *) buffer); hex_dump ((unsigned int *) buffer); } @@ -39,6 +41,7 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { } if (DUMP_BUFFER) { + LOG ("Dumping successful message buffer:"); int_dump ((byte_t *) buffer); hex_dump ((unsigned int *) buffer); } From 6037e7cef2a30cd1e4fed2b37f9041cd5050167b Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 12:17:29 +0200 Subject: [PATCH 26/61] feat(gpu): double rainbow resolution --- thorn/src/common/gpu.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 4e964a2..7e7640d 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -97,17 +97,29 @@ void draw () { color rainbow[] = { {0xff, 0x00, 0xff, 0}, + {0xc0, 0x00, 0xff, 0}, {0x80, 0x00, 0xff, 0}, + {0x40, 0x00, 0xff, 0}, {0x00, 0x00, 0xff, 0}, + {0x00, 0x40, 0xff, 0}, {0x00, 0x80, 0xff, 0}, + {0x00, 0xc0, 0xff, 0}, {0x00, 0xff, 0xff, 0}, + {0x00, 0xff, 0xc0, 0}, {0x00, 0xff, 0x80, 0}, + {0x00, 0xff, 0x40, 0}, {0x00, 0xff, 0x00, 0}, + {0x40, 0xff, 0x00, 0}, {0x80, 0xff, 0x00, 0}, + {0xc0, 0xff, 0x00, 0}, {0xff, 0xff, 0x00, 0}, + {0xff, 0xc0, 0x00, 0}, {0xff, 0x80, 0x00, 0}, + {0xff, 0x40, 0x00, 0}, {0xff, 0x00, 0x00, 0}, - {0xff, 0x00, 0x80, 0} + {0xff, 0x00, 0x40, 0}, + {0xff, 0x00, 0x80, 0}, + {0xff, 0x00, 0xc0, 0} }; int rb_size = sizeof (rainbow) / sizeof (color); From 890343a8f266667c699a243053ebee580445fe15 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 14:23:49 +0200 Subject: [PATCH 27/61] feat(gpu): display a continuous rainbow pattern --- thorn/include/common/gpu.h | 2 - thorn/include/common/rainbow.h | 20 ++++++++++ thorn/include/kernel/mailbox.h | 2 +- thorn/include/kernel/mm.h | 2 +- thorn/src/common/gpu.c | 55 --------------------------- thorn/src/common/rainbow.c | 69 ++++++++++++++++++++++++++++++++++ thorn/src/kernel/kernel.c | 1 + 7 files changed, 92 insertions(+), 59 deletions(-) create mode 100644 thorn/include/common/rainbow.h create mode 100644 thorn/src/common/rainbow.c diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 7046c7c..9fca21a 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -40,8 +40,6 @@ static color * fb; bool init_gpu (void); -void draw (void); - color * get_fb (void); diff --git a/thorn/include/common/rainbow.h b/thorn/include/common/rainbow.h new file mode 100644 index 0000000..518009c --- /dev/null +++ b/thorn/include/common/rainbow.h @@ -0,0 +1,20 @@ +#ifndef _ROSE_RAINBOW_H +#define _ROSE_RAINBOW_H + +#include "common/gpu.h" + +#define SIZE_OF_RAINBOW 950 +#define OFFSET_STEPS 19 +#define OFFSET_FACTOR (SIZE_OF_RAINBOW / OFFSET_STEPS) + +static color rainbow[SIZE_OF_RAINBOW]; + +static unsigned int const RB_SIZE = SIZE_OF_RAINBOW; + +void draw (void); + +void populate_rainbow (void); + +int write_color_to_rainbow (unsigned char red, unsigned char green, unsigned char blue); + +#endif //_ROSE_RAINBOW_H \ No newline at end of file diff --git a/thorn/include/kernel/mailbox.h b/thorn/include/kernel/mailbox.h index 16075ca..bb8645a 100644 --- a/thorn/include/kernel/mailbox.h +++ b/thorn/include/kernel/mailbox.h @@ -10,7 +10,7 @@ #include "common/debug.h" #include "common/logging.h" -#define DUMP_BUFFER true +#define DUMP_BUFFER false // Documentation: // https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface diff --git a/thorn/include/kernel/mm.h b/thorn/include/kernel/mm.h index 0be2178..718f88a 100644 --- a/thorn/include/kernel/mm.h +++ b/thorn/include/kernel/mm.h @@ -12,7 +12,7 @@ #define SECTION_SIZE (1 << SECTION_SHIFT) #define LOW_MEMORY (2 * SECTION_SIZE) -#define HIGH_MEMORY 0x60000000 +#define HIGH_MEMORY 0x70000000 #define PAGING_MEMORY (HIGH_MEMORY - LOW_MEMORY) #define PAGING_PAGES (PAGING_MEMORY/PAGE_SIZE) diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 7e7640d..10fc41a 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -92,61 +92,6 @@ bool init_gpu () { return true; } -void draw () { - printf ("\n"); - - color rainbow[] = { - {0xff, 0x00, 0xff, 0}, - {0xc0, 0x00, 0xff, 0}, - {0x80, 0x00, 0xff, 0}, - {0x40, 0x00, 0xff, 0}, - {0x00, 0x00, 0xff, 0}, - {0x00, 0x40, 0xff, 0}, - {0x00, 0x80, 0xff, 0}, - {0x00, 0xc0, 0xff, 0}, - {0x00, 0xff, 0xff, 0}, - {0x00, 0xff, 0xc0, 0}, - {0x00, 0xff, 0x80, 0}, - {0x00, 0xff, 0x40, 0}, - {0x00, 0xff, 0x00, 0}, - {0x40, 0xff, 0x00, 0}, - {0x80, 0xff, 0x00, 0}, - {0xc0, 0xff, 0x00, 0}, - {0xff, 0xff, 0x00, 0}, - {0xff, 0xc0, 0x00, 0}, - {0xff, 0x80, 0x00, 0}, - {0xff, 0x40, 0x00, 0}, - {0xff, 0x00, 0x00, 0}, - {0xff, 0x00, 0x40, 0}, - {0xff, 0x00, 0x80, 0}, - {0xff, 0x00, 0xc0, 0} - }; - - int rb_size = sizeof (rainbow) / sizeof (color); - int divisor; - - while (1) { - for (int offset = 0; offset < rb_size; offset++) { - divisor = GPU_SCREEN_WIDTH / rb_size; - for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % divisor; x++) { - for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { - fb[y * GPU_SCREEN_WIDTH + x].red ^= rainbow[(x / divisor + offset) % rb_size].red; - fb[y * GPU_SCREEN_WIDTH + x].green ^= rainbow[(x / divisor + offset) % rb_size].green; - fb[y * GPU_SCREEN_WIDTH + x].blue ^= rainbow[(x / divisor + offset) % rb_size].blue; - } - } - divisor = GPU_SCREEN_HEIGHT / rb_size; - for (int y = 0; y < GPU_SCREEN_HEIGHT - GPU_SCREEN_HEIGHT % divisor; y++) { - for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { - fb[y * GPU_SCREEN_WIDTH + x].red ^= rainbow[(y / divisor + offset) % rb_size].red; - fb[y * GPU_SCREEN_WIDTH + x].green ^= rainbow[(y / divisor + offset) % rb_size].green; - fb[y * GPU_SCREEN_WIDTH + x].blue ^= rainbow[(y / divisor + offset) % rb_size].blue; - } - } - } - } -} - color * get_fb () { return fb; } \ No newline at end of file diff --git a/thorn/src/common/rainbow.c b/thorn/src/common/rainbow.c new file mode 100644 index 0000000..874f187 --- /dev/null +++ b/thorn/src/common/rainbow.c @@ -0,0 +1,69 @@ +#include "common/rainbow.h" + +void draw () { + populate_rainbow (); + + unsigned int const X_DIVISOR = GPU_SCREEN_WIDTH / RB_SIZE; + unsigned int const Y_DIVISOR = GPU_SCREEN_HEIGHT / RB_SIZE; + + unsigned int * rainbow_i = (unsigned int *) rainbow; + unsigned int * fb_i = (unsigned int *) get_fb (); + + color current = rainbow[0]; + unsigned int current_i = * (unsigned int *) & current; + + while (1) { + for (int offset = 0; offset < OFFSET_STEPS; offset++) { + for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % X_DIVISOR; x++) { + for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { + fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(x / X_DIVISOR + OFFSET_FACTOR * offset) % RB_SIZE]; + } + } + for (int y = 0; y < GPU_SCREEN_HEIGHT - GPU_SCREEN_HEIGHT % Y_DIVISOR; y++) { + for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { + fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(y / Y_DIVISOR + OFFSET_FACTOR * offset) % RB_SIZE]; + } + } + } + } +} + +void populate_rainbow () { + unsigned char red = 0xFF; + unsigned char green = 0x00; + unsigned char blue = 0xFF; + + do { // purple to red + write_color_to_rainbow (red, green, blue); + } while (blue -= 4 > 3); + + do { // red to yellow + write_color_to_rainbow (red, green += 4, blue); + } while (green < 252); + + do { // yellow to green + write_color_to_rainbow (red, green, blue); + } while (red -= 4 > 3); + + do { // green to cyan + write_color_to_rainbow (red, green, blue += 4); + } while (blue < 252); + + do { // cyan to blue + write_color_to_rainbow (red, green, blue); + } while (green -= 4 > 3); + + do { // blue to purple + write_color_to_rainbow (red += 4, green, blue); + } while (red < 252); + +} + +int write_color_to_rainbow (unsigned char red, unsigned char green, unsigned char blue) { + static int index = 0; + rainbow[index].red = red; + rainbow[index].green = green; + rainbow[index].blue = blue; + printf ("%d ", index); + return ++index; +} diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 9b77044..c0d4045 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -9,6 +9,7 @@ #include "kernel/fork.h" #include "kernel/sys.h" #include "common/logging.h" +#include "common/rainbow.h" void user_process1 (char * array) { char buf[2] = {0}; From bbf67055ed2d317b3e8069edd115485d74ab8f36 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 14:36:39 +0200 Subject: [PATCH 28/61] feat(colour): switch to discrete rainbow again --- thorn/include/common/rainbow.h | 36 ++++++++++++++++------- thorn/src/common/rainbow.c | 54 ++++------------------------------ 2 files changed, 31 insertions(+), 59 deletions(-) diff --git a/thorn/include/common/rainbow.h b/thorn/include/common/rainbow.h index 518009c..5abc049 100644 --- a/thorn/include/common/rainbow.h +++ b/thorn/include/common/rainbow.h @@ -3,18 +3,34 @@ #include "common/gpu.h" -#define SIZE_OF_RAINBOW 950 -#define OFFSET_STEPS 19 -#define OFFSET_FACTOR (SIZE_OF_RAINBOW / OFFSET_STEPS) +static color const RAINBOW[] = { + {0xff, 0x00, 0xff, 0}, + {0xc0, 0x00, 0xff, 0}, + {0x80, 0x00, 0xff, 0}, + {0x40, 0x00, 0xff, 0}, + {0x00, 0x00, 0xff, 0}, + {0x00, 0x40, 0xff, 0}, + {0x00, 0x80, 0xff, 0}, + {0x00, 0xc0, 0xff, 0}, + {0x00, 0xff, 0xff, 0}, + {0x00, 0xff, 0xc0, 0}, + {0x00, 0xff, 0x80, 0}, + {0x00, 0xff, 0x40, 0}, + {0x00, 0xff, 0x00, 0}, + {0x40, 0xff, 0x00, 0}, + {0x80, 0xff, 0x00, 0}, + {0xc0, 0xff, 0x00, 0}, + {0xff, 0xff, 0x00, 0}, + {0xff, 0xc0, 0x00, 0}, + {0xff, 0x80, 0x00, 0}, + {0xff, 0x40, 0x00, 0}, + {0xff, 0x00, 0x00, 0}, + {0xff, 0x00, 0x40, 0}, + {0xff, 0x00, 0x80, 0}, + {0xff, 0x00, 0xc0, 0} +}; -static color rainbow[SIZE_OF_RAINBOW]; - -static unsigned int const RB_SIZE = SIZE_OF_RAINBOW; void draw (void); -void populate_rainbow (void); - -int write_color_to_rainbow (unsigned char red, unsigned char green, unsigned char blue); - #endif //_ROSE_RAINBOW_H \ No newline at end of file diff --git a/thorn/src/common/rainbow.c b/thorn/src/common/rainbow.c index 874f187..5fbd75a 100644 --- a/thorn/src/common/rainbow.c +++ b/thorn/src/common/rainbow.c @@ -1,69 +1,25 @@ #include "common/rainbow.h" void draw () { - populate_rainbow (); - + unsigned int const RB_SIZE = sizeof (RAINBOW) / sizeof (color); unsigned int const X_DIVISOR = GPU_SCREEN_WIDTH / RB_SIZE; unsigned int const Y_DIVISOR = GPU_SCREEN_HEIGHT / RB_SIZE; - unsigned int * rainbow_i = (unsigned int *) rainbow; + unsigned int * rainbow_i = (unsigned int *) RAINBOW; unsigned int * fb_i = (unsigned int *) get_fb (); - color current = rainbow[0]; - unsigned int current_i = * (unsigned int *) & current; - while (1) { - for (int offset = 0; offset < OFFSET_STEPS; offset++) { + for (int offset = 0; offset < RB_SIZE; offset++) { for (int x = 0; x < GPU_SCREEN_WIDTH - GPU_SCREEN_WIDTH % X_DIVISOR; x++) { for (int y = 0; y < GPU_SCREEN_HEIGHT; y++) { - fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(x / X_DIVISOR + OFFSET_FACTOR * offset) % RB_SIZE]; + fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(x / X_DIVISOR + offset) % RB_SIZE]; } } for (int y = 0; y < GPU_SCREEN_HEIGHT - GPU_SCREEN_HEIGHT % Y_DIVISOR; y++) { for (int x = 0; x < GPU_SCREEN_WIDTH; x++) { - fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(y / Y_DIVISOR + OFFSET_FACTOR * offset) % RB_SIZE]; + fb_i[y * GPU_SCREEN_WIDTH + x] ^= rainbow_i[(y / Y_DIVISOR + offset) % RB_SIZE]; } } } } } - -void populate_rainbow () { - unsigned char red = 0xFF; - unsigned char green = 0x00; - unsigned char blue = 0xFF; - - do { // purple to red - write_color_to_rainbow (red, green, blue); - } while (blue -= 4 > 3); - - do { // red to yellow - write_color_to_rainbow (red, green += 4, blue); - } while (green < 252); - - do { // yellow to green - write_color_to_rainbow (red, green, blue); - } while (red -= 4 > 3); - - do { // green to cyan - write_color_to_rainbow (red, green, blue += 4); - } while (blue < 252); - - do { // cyan to blue - write_color_to_rainbow (red, green, blue); - } while (green -= 4 > 3); - - do { // blue to purple - write_color_to_rainbow (red += 4, green, blue); - } while (red < 252); - -} - -int write_color_to_rainbow (unsigned char red, unsigned char green, unsigned char blue) { - static int index = 0; - rainbow[index].red = red; - rainbow[index].green = green; - rainbow[index].blue = blue; - printf ("%d ", index); - return ++index; -} From 9faf4e35eeb5b7f624aae132b4b015c35288d6cb Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 15:02:46 +0200 Subject: [PATCH 29/61] feat(gpu): store fb related data in fb_info struct * Get framebuffer with `get_fb ()` * Get framebuffer info struct with `get_fb_info ()` NOTE: Pitch doesn't seem to work; it always gets set to 0 --- thorn/include/common/gpu.h | 14 +++- thorn/src/common/gpu.c | 147 ++++++++++++++++++++----------------- thorn/src/kernel/kernel.c | 2 +- 3 files changed, 93 insertions(+), 70 deletions(-) diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index 9fca21a..c6ee8a2 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -32,15 +32,23 @@ typedef struct { byte_t alpha; } color; -static volatile unsigned int __attribute__((aligned(16))) mbox[2048]; +typedef struct { + color * fb; + unsigned int fb_size; + short virtual_width; + short virtual_height; + short pitch; + short colour_depth; +} fb_info_t; -// framebuffer -static color * fb; +static volatile unsigned int __attribute__((aligned(16))) gpu_msg_buffer[128]; +static fb_info_t fb_info; bool init_gpu (void); color * get_fb (void); +fb_info_t const * get_fb_info (void); #endif //_ROSE_C_GPU_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 10fc41a..a2f8550 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -1,97 +1,112 @@ #include "common/gpu.h" bool init_gpu () { - { // First message: read physical dimensions - int c = 0; // Message size; increment while we write - mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + { // First message: read physical dimensions + int c = 0; // Message size; increment while we write + gpu_msg_buffer[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE - mbox[++c] = 0x00040003; // Tag to get physical display width / height - mbox[++c] = 0; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = 0; // Get physical screen width | Overwritten by actual width - mbox[++c] = 0; // Get physical screen height | Overwritten by actual height + gpu_msg_buffer[++c] = 0x00040003; // Tag to get physical display width / height + gpu_msg_buffer[++c] = 0; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = 0; // Get physical screen width | Overwritten by actual width + gpu_msg_buffer[++c] = 0; // Get physical screen height | Overwritten by actual height - mbox[++c] = 0; // End tag + gpu_msg_buffer[++c] = 0; // End tag - mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer + gpu_msg_buffer[0] = (4 * ++c); // Write message size at the beginning of the buffer // If reading physical screen dimension fails exit function - if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; + if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; } - - { - int c = 0; // Message size; increment while we write - mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + { // Second message: request frame buffer + int c = 0; // Message size; increment while we write + gpu_msg_buffer[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE -#ifdef GPU_OVERRIDE_PHYSICAL_SCREEN - mbox[++c] = 0x00048003; // Tag to set virtual display width / height - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width - mbox[++c] = GPU_SCREEN_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height - - mbox[++c] = 0x00048004; // Tag to set virtual display width / height - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width - mbox[++c] = GPU_VIRTUAL_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height +#ifdef GPU_OVERRIDE_PHYSICAL_SCREEN // If this is set, update physical /virtual dimensions based on constants + gpu_msg_buffer[++c] = 0x00048003; // Tag to set virtual display width / height + gpu_msg_buffer[++c] = 8; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + gpu_msg_buffer[++c] = GPU_SCREEN_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height + + gpu_msg_buffer[++c] = 0x00048004; // Tag to set virtual display width / height + gpu_msg_buffer[++c] = 8; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + int index_virt_width = c; + gpu_msg_buffer[++c] = GPU_VIRTUAL_HEIGHT; // Set virtual screen height | Overwritten by actual virtual height + int index_virt_height = c; #else - mbox[++c] = 0x00048004; // Tag to set virtual display width / height - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c];//GPU_SCREEN_WIDTH; // Keep virtual screen width | Overwritten by actual virtual width - mbox[++c];//GPU_SCREEN_HEIGHT; // Keep virtual screen height | Overwritten by actual virtual height + gpu_msg_buffer[++c] = 0x00048004; // Tag to set virtual display width / height + gpu_msg_buffer[++c] = 8; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c];//GPU_SCREEN_WIDTH; // Reuse previous width | Overwritten by actual virtual width + int index_virt_width = c; + gpu_msg_buffer[++c];//GPU_SCREEN_HEIGHT; // Reuse previous height | Overwritten by actual virtual height + int index_virt_height = c; #endif - mbox[++c] = 0x00048005; // Tag to set pixel depth - mbox[++c] = 4; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = GPU_COLOUR_DEPTH; // Set colour depth | Overwritten by actual colour depth + gpu_msg_buffer[++c] = 0x00048005; // Tag to set pixel depth + gpu_msg_buffer[++c] = 4; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = GPU_COLOUR_DEPTH; // Set colour depth | Overwritten by actual colour depth - mbox[++c] = 0x00040001; // Tag to allocate framebuffer - mbox[++c] = 8; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size will be written here - mbox[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer - byte_t index_framebuffer = c; - mbox[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer + gpu_msg_buffer[++c] = 0x00040001; // Tag to allocate framebuffer + gpu_msg_buffer[++c] = 8; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size will be written here + gpu_msg_buffer[++c] = 16; // Buffer alignment | Overwritten by pointer to framebuffer + int index_framebuffer = c; + gpu_msg_buffer[++c] = 0; // Unused - will be overwritten | Overwritten by size of framebuffer + int index_fb_size = c; - mbox[++c] = 0; // End tag - mbox[++c] = 0; // Padding - mbox[++c] = 0; // Padding - mbox[++c] = 0; // Padding + gpu_msg_buffer[++c] = 0; // End tag + gpu_msg_buffer[++c] = 0; // Padding + gpu_msg_buffer[++c] = 0; // Padding + gpu_msg_buffer[++c] = 0; // Padding - mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer + gpu_msg_buffer[0] = (4 * ++c); // Write message size at the beginning of the buffer // If message failed exit - if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; + if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; - // Since message succeeded, update the frame buffer - fb = (color * ) (mbox[index_framebuffer] & VC_SDRAM_OFFSET); + // Since message succeeded, update frame buffer and its size + fb_info.fb = (color * ) (gpu_msg_buffer[index_framebuffer] & VC_SDRAM_OFFSET); + fb_info.fb_size = gpu_msg_buffer[index_fb_size]; } - { // Third message: read pitch (in bytes per line) - int c = 0; // Message size; increment while we write - mbox[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE - - mbox[++c] = 0x00040008; // Tag to get pitch - mbox[++c] = 0; // Size of value buffer - mbox[++c] = 0; // Response & value buffer size written will be written here - mbox[++c] = 0; // Pitch will be written here + { // Third message: read pitch (in bytes per line) + int c = 0; // Message size; increment while we write + gpu_msg_buffer[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + gpu_msg_buffer[++c] = 0x00040008; // Tag to get pitch + gpu_msg_buffer[++c] = 0; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = 0; // Pitch will be written here int index_pitch = c; - mbox[++c] = 0; // End tag - mbox[++c] = 0; // Padding + gpu_msg_buffer[++c] = 0; // End tag + gpu_msg_buffer[++c] = 0; // Padding - mbox[0] = (4 * ++c); // Write message size at the beginning of the buffer + gpu_msg_buffer[0] = (4 * ++c); // Write message size at the beginning of the buffer // If message failed exit - if (!mailbox_request (mbox, PROPERTY_ARM_VC)) return false; - if (mbox[index_pitch]) {printf ("\r\nGot pitch: %d\r\n", mbox[index_pitch]);} - else {printf ("\r\nPitch is 0?!\r\n");} + if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; + + // Else write pitch appropriately + int pitch = gpu_msg_buffer; + if (pitch) { + printf ("\r\nGot pitch: %d\r\n", pitch); + } else { + printf ("\r\nPitch is 0?!\r\n"); + } + fb_info.pitch = pitch; } - return true; } color * get_fb () { - return fb; + return fb_info.fb; +} + +fb_info_t const * get_fb_info () { + return & fb_info; } \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index c0d4045..d631d68 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -78,7 +78,7 @@ void kernel_main (int processor_id) { if (!gpu_status) { printf ("Error while initialising Framebuffer\r\n"); } else { - unsigned long fb = get_fb (); + color * fb = get_fb (); if (!fb) { printf ("Error: Invalid Framebuffer received\r\n"); } else { From 41b9349393624ccceeae332c5f26251bb564c2da Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 12:13:13 +0200 Subject: [PATCH 30/61] feat(temperature): continously read temperature NOTE: always reads 0 as both max and current temperature --- thorn/include/common/temperature.h | 34 ++++++++++++++++ thorn/src/common/temperature.c | 62 ++++++++++++++++++++++++++++++ thorn/src/config.txt | 1 + thorn/src/kernel/kernel.c | 20 ++++++++-- 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 thorn/include/common/temperature.h create mode 100644 thorn/src/common/temperature.c diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h new file mode 100644 index 0000000..5e8d02b --- /dev/null +++ b/thorn/include/common/temperature.h @@ -0,0 +1,34 @@ +#ifndef _ROSE_C_TEMPERATURE_H +#define _ROSE_C_TEMPERATURE_H + +#include "common/stdbool.h" +#include "kernel/mailbox.h" + +// Pin 32 / GPIO 12 (PWM0) +#define GPIO_FAN 32 + +// Temperature the system tries to keep. Turns off cooling if it falls below. +// NOTE: The pi hits a 'soft' limit at 70 °C, reducing clock frequency. +// This value is defined in the config.txt and defaults to 60 °C if not set +#define TEMPERATURE_SHOULD (45 * 1000) +#define TEMPERATURE_MAX (80 * 1000) + +#define TEMPERATURE_CHECK_DELAY 20000000 + +static volatile unsigned int __attribute__((aligned(16))) temperature_request[8]; + +// Max temperature in degree milliCelsius. +// USB + Ethernet are designed up to 70 °C but unlikely to overheat. +// CPU is designed up to 85 °C so 80 is probably a reasonable upper limit. +// Consider reducing to 70 °C if the workload on the ports increases +static int max_temperature; + +bool init_temperature (void); + +void regulate_temperature (void); + +int get_max_temperature (void); + +int get_temperature (void); + +#endif //_ROSE_C_TEMPERATURE_H \ No newline at end of file diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c new file mode 100644 index 0000000..15516c9 --- /dev/null +++ b/thorn/src/common/temperature.c @@ -0,0 +1,62 @@ +#include "common/temperature.h" + +bool init_temperature () { + { // Read out maximum temperature + int c = 0; // Message size; increment while we write + temperature_request[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + temperature_request[++c] = 0x0003000a; // Tag to get maximum temperature + temperature_request[++c] = 4; // Size of value buffer + temperature_request[++c] = 0; // Response & value buffer size written will be written here + temperature_request[++c] = 0; // Temperature (device?) ID, should stay 0 + temperature_request[++c] = 0; // Will be overwritten by maximum temperature + int index_max_temperature = c; + + temperature_request[++c] = 0; // End tag + + temperature_request[0] = (4 * ++c); // Write message size at the beginning of the buffer + + // If reading maximum temperature fails, keep default + if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return false; + // Else update temperature + max_temperature = temperature_request[index_max_temperature] ? : TEMPERATURE_MAX; + + return true; // TODO: remove + } + + // Start regulate_temperature service here +} + +void regulate_temperature () { + static int previous_temperature = TEMPERATURE_SHOULD; + int current = get_temperature (); + printf ("\rCurrent temperature: %d °C", current / 1000); +} + +int get_max_temperature () { + return max_temperature; +} + +int get_temperature () { + { // Read out current temperature + int c = 0; // Message size; increment while we write + temperature_request[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE + + temperature_request[++c] = 0x00030006; // Tag to get current temperature + temperature_request[++c] = 0; // Size of value buffer + temperature_request[++c] = 4; // Response & value buffer size written will be written here + temperature_request[++c] = 0; // Temperature (device?) ID, should stay 0 + temperature_request[++c] = 0; // Will be overwritten by current temperature + int index_temperature = c; + + temperature_request[++c] = 0; // End tag + + temperature_request[0] = (4 * ++c); // Write message size at the beginning of the buffer + + // If reading maximum temperature fails, keep default + if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return -1; + // Else update temperature + max_temperature = temperature_request[index_temperature] ? : TEMPERATURE_MAX; + return temperature_request[index_temperature]; + } +} \ No newline at end of file diff --git a/thorn/src/config.txt b/thorn/src/config.txt index 1cb4eed..e187384 100644 --- a/thorn/src/config.txt +++ b/thorn/src/config.txt @@ -1,2 +1,3 @@ enable_uart=1 dtparam=watchdog=on +temp_soft_limit=70 \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index d631d68..9b5ee99 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -10,6 +10,7 @@ #include "kernel/sys.h" #include "common/logging.h" #include "common/rainbow.h" +#include "common/temperature.h" void user_process1 (char * array) { char buf[2] = {0}; @@ -58,7 +59,7 @@ void kernel_process () { } -void kernel_main (int processor_id) { +_Noreturn void kernel_main (int processor_id) { static volatile unsigned int current_processor = 0; @@ -69,10 +70,10 @@ void kernel_main (int processor_id) { timer_init (); enable_interrupt_controller (); enable_irq (); -// task_init (); - + task_init (); LOG("Logging works"); + // Display printf ("Initialising Framebuffer...\r\n"); int gpu_status = init_gpu (); if (!gpu_status) { @@ -85,6 +86,10 @@ void kernel_main (int processor_id) { printf ("Received framebuffer: %p\r\n", fb); } } + + // Temperature + printf ("Initialising temperature %s. Max temperature set to %d °C.\r\n", + init_temperature () ? "succeeded" : "failed", get_max_temperature () / 1000); } while (processor_id != current_processor); @@ -110,5 +115,14 @@ void kernel_main (int processor_id) { LOG("DONE PRINTING"); } + // Use processor 1 for checking temperature + if (processor_id == 1) { + while (current_processor != 3); + while (1) { + regulate_temperature (); + delay (TEMPERATURE_CHECK_DELAY); + } + } + while (1); } From 4ef1d2a0026e61976b356889f9e4a67b44522aab Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 15:38:10 +0200 Subject: [PATCH 31/61] fix(temperature): fix message using invalid buffer size --- thorn/src/common/temperature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 15516c9..edd618d 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -6,7 +6,7 @@ bool init_temperature () { temperature_request[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE temperature_request[++c] = 0x0003000a; // Tag to get maximum temperature - temperature_request[++c] = 4; // Size of value buffer + temperature_request[++c] = 8; // Size of value buffer temperature_request[++c] = 0; // Response & value buffer size written will be written here temperature_request[++c] = 0; // Temperature (device?) ID, should stay 0 temperature_request[++c] = 0; // Will be overwritten by maximum temperature @@ -43,7 +43,7 @@ int get_temperature () { temperature_request[++c] = 0; // Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE temperature_request[++c] = 0x00030006; // Tag to get current temperature - temperature_request[++c] = 0; // Size of value buffer + temperature_request[++c] = 8; // Size of value buffer temperature_request[++c] = 4; // Response & value buffer size written will be written here temperature_request[++c] = 0; // Temperature (device?) ID, should stay 0 temperature_request[++c] = 0; // Will be overwritten by current temperature From a1338733dc76de128f2a7772296a3c1e208afc71 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 15 Oct 2021 16:33:31 +0200 Subject: [PATCH 32/61] WIP: toggle GPIO pin for fan --- thorn/include/common/temperature.h | 8 ++++--- thorn/include/kernel/peripherals/gpio.h | 1 + thorn/src/common/temperature.c | 28 ++++++++++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 5e8d02b..f473957 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -3,14 +3,14 @@ #include "common/stdbool.h" #include "kernel/mailbox.h" +#include "kernel/peripherals/gpio.h" -// Pin 32 / GPIO 12 (PWM0) -#define GPIO_FAN 32 +#define GPIO_FAN 18 // Temperature the system tries to keep. Turns off cooling if it falls below. // NOTE: The pi hits a 'soft' limit at 70 °C, reducing clock frequency. // This value is defined in the config.txt and defaults to 60 °C if not set -#define TEMPERATURE_SHOULD (45 * 1000) +#define TEMPERATURE_SHOULD (50 * 1000) #define TEMPERATURE_MAX (80 * 1000) #define TEMPERATURE_CHECK_DELAY 20000000 @@ -31,4 +31,6 @@ int get_max_temperature (void); int get_temperature (void); +void set_fan (bool enable); + #endif //_ROSE_C_TEMPERATURE_H \ No newline at end of file diff --git a/thorn/include/kernel/peripherals/gpio.h b/thorn/include/kernel/peripherals/gpio.h index bd31882..8532dd1 100644 --- a/thorn/include/kernel/peripherals/gpio.h +++ b/thorn/include/kernel/peripherals/gpio.h @@ -3,6 +3,7 @@ #include "kernel/peripherals/base.h" +#define GPIO_BASE (PBASE+0x00200000) #define GPFSEL1 (PBASE+0x00200004) #define GPSET0 (PBASE+0x0020001C) #define GPCLR0 (PBASE+0x00200028) diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index edd618d..908cb64 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -20,17 +20,28 @@ bool init_temperature () { if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return false; // Else update temperature max_temperature = temperature_request[index_max_temperature] ? : TEMPERATURE_MAX; - - return true; // TODO: remove } // Start regulate_temperature service here + return true; } void regulate_temperature () { - static int previous_temperature = TEMPERATURE_SHOULD; + static int fan = 1; + static int previous = TEMPERATURE_SHOULD; int current = get_temperature (); - printf ("\rCurrent temperature: %d °C", current / 1000); + printf ("\rCurrent temperature: %d °C. Change since last iteration: %d °mC ", current / 1000, + (current - previous)); + + if (current < TEMPERATURE_SHOULD) { + fan = 0; + } else { + fan = 1; + } + + set_fan (fan); + + previous = current; } int get_max_temperature () { @@ -54,9 +65,12 @@ int get_temperature () { temperature_request[0] = (4 * ++c); // Write message size at the beginning of the buffer // If reading maximum temperature fails, keep default - if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return -1; - // Else update temperature - max_temperature = temperature_request[index_temperature] ? : TEMPERATURE_MAX; + if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return max_temperature; + // Else return temperature return temperature_request[index_temperature]; } +} + +void set_fan (bool enable) { + printf ("set fan %d \r", enable); } \ No newline at end of file From b2769b692c3519536f8f90b8764d02d493da53be Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Wed, 8 Sep 2021 16:48:18 +0200 Subject: [PATCH 33/61] feat(base): include lesson05 NOTE: does not work yet Current output: ``` 61 EnableRegister: ff84110c Kernel process started. EL 1 , ESR: 1fe00000, address, 1434 ``` --- chainloader/include/kernel/peripherals/mini_uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/include/kernel/peripherals/mini_uart.h b/chainloader/include/kernel/peripherals/mini_uart.h index b065deb..44a9554 100644 --- a/chainloader/include/kernel/peripherals/mini_uart.h +++ b/chainloader/include/kernel/peripherals/mini_uart.h @@ -1,7 +1,7 @@ #ifndef _ROSE_K_P_MINI_UART_H #define _ROSE_K_P_MINI_UART_H -#include "base.h" +#include "kernel/peripherals/base.h" #define SYSTEM_CLOCK_FREQ 500000000 #define BAUD_RATE_REG(target_baudrate) ((SYSTEM_CLOCK_FREQ / target_baudrate / 8) - 1) From f9bb2e24bb282527b8ee80f7db2ea9596d885d40 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Wed, 8 Sep 2021 17:02:54 +0200 Subject: [PATCH 34/61] feat(io): modify printf to allow %p %P for 0x........ notation --- thorn/src/common/printf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/thorn/src/common/printf.c b/thorn/src/common/printf.c index 85627be..4955175 100644 --- a/thorn/src/common/printf.c +++ b/thorn/src/common/printf.c @@ -200,6 +200,17 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { ui2a (va_arg (va, unsigned int), 16, (ch == 'P'), bf); putchw (putp, putf, w, lz, bf); break; + case 'p': case 'P': + putf(putp, '0'); + putf(putp, 'x'); +#ifdef PRINTF_LONG_SUPPORT + if (lng) + uli2a(va_arg(va, unsigned long int),16,(ch=='P'),bf); + else +#endif + ui2a(va_arg(va, unsigned int),16,(ch=='P'),bf); + putchw(putp,putf,w,lz,bf); + break; case '%': putf (putp, ch); default: From c63598b952d0c1e559abc8bd26ee85cef8822686 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Mon, 13 Sep 2021 12:36:19 +0200 Subject: [PATCH 35/61] feat(io): add uart as alternative to mini uart NOTE: the first uart to be included will be the implementation used throughout the program --- chainloader/include/kernel/peripherals/mini_uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/include/kernel/peripherals/mini_uart.h b/chainloader/include/kernel/peripherals/mini_uart.h index 44a9554..b065deb 100644 --- a/chainloader/include/kernel/peripherals/mini_uart.h +++ b/chainloader/include/kernel/peripherals/mini_uart.h @@ -1,7 +1,7 @@ #ifndef _ROSE_K_P_MINI_UART_H #define _ROSE_K_P_MINI_UART_H -#include "kernel/peripherals/base.h" +#include "base.h" #define SYSTEM_CLOCK_FREQ 500000000 #define BAUD_RATE_REG(target_baudrate) ((SYSTEM_CLOCK_FREQ / target_baudrate / 8) - 1) From 260af244c3f0ee07b6ec3d446ab943a8af065477 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 10:34:09 +0200 Subject: [PATCH 36/61] style(io): rename hdmi to gpu --- thorn/include/kernel/peripherals/gpu.h | 4 +--- thorn/src/kernel/kernel.c | 13 +++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/thorn/include/kernel/peripherals/gpu.h b/thorn/include/kernel/peripherals/gpu.h index 5677fad..2408fba 100644 --- a/thorn/include/kernel/peripherals/gpu.h +++ b/thorn/include/kernel/peripherals/gpu.h @@ -7,6 +7,4 @@ #define GPU_SET_VIRTUAL_SIZE 0x48004 #define GPU_SET_COLOUR_DEPTH 0x48005 -#endif//_ROSE_K_P_GPU_H - -/* Copyright (C) 2020 Aaron Alef */ \ No newline at end of file +#endif//_ROSE_K_P_GPU_H \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index c766c27..46a4431 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -59,12 +59,13 @@ void kernel_process () { void kernel_init (void) { uart_init (); - init_printf (0, putc); - irq_vector_init (); - timer_init (); - enable_interrupt_controller (); - enable_irq (); - task_init (); + init_gpu (); + init_printf (0, putc); + irq_vector_init (); + timer_init (); + enable_interrupt_controller (); + enable_irq (); + task_init (); printf ("Initialising Framebuffer...\r\n"); int gpu_status = init_gpu (); From d2a4e3e0c382a69568bab817a82cf14778d3a853 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 13:02:55 +0200 Subject: [PATCH 37/61] feat(io): add mailbox send and read functions [untested] --- chainloader/src/mailbox.c | 65 ++++++++++++++++++++++ thorn/include/kernel/peripherals/mailbox.h | 10 ---- thorn/src/kernel/mailbox.c | 4 +- 3 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 chainloader/src/mailbox.c diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c new file mode 100644 index 0000000..cf12e56 --- /dev/null +++ b/chainloader/src/mailbox.c @@ -0,0 +1,65 @@ +#include "kernel/mailbox.h" + +void mailbox_send (unsigned int data, channel_t channel) { + mbox_message_t msg = {data, channel}; + + while ((MBOX1 + MBOX_STATUS) & MBOX_WRITE_FULL); + put32 (MBOX1 + MBOX_WRITE, * (unsigned int *) & msg); +} + +unsigned int mailbox_read (channel_t channel) { + unsigned int value; + + do { + // Wait until there's a message + while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); + + value = get32 (MBOX0 + MBOX_READ); + + // Wait until the channel matches (lest four significant bits) + } while ((value & 0xF) != channel); + + // Return most significant bits (actual address) + return value >> 4; +} + +unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { + mbox_property_t * msg = (mbox_property_t *) get_free_page (); + + // Add tags to message: + unsigned int struct_size = 2 * sizeof (unsigned int); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (msg + struct_size), tags); + + // Add end tag and 16 byte-aligned padding: + struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; + + // write struct size to message: + msg->struct_size = struct_size; + + mailbox_send ((unsigned int) msg, channel); + return msg; +} + +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { + unsigned int written = 0; + while (src->identity) { + dest += written; + + unsigned int buffer_size = src->buffer_size; + + dest->identity = src->identity; + dest->buffer_size = buffer_size; + dest->response = 0; + + + for (unsigned int i = 0; i < buffer_size; i ++) { + dest->buffer[written] = src->buffer[written]; + } + written += 3 * sizeof (unsigned int) + buffer_size; + put32 (dest + written, 0); + written += sizeof (unsigned int); + put32 (dest + written, 0); + written += (written % 16) ? 16 - (written % 16) : 0; + } + return written; +} diff --git a/thorn/include/kernel/peripherals/mailbox.h b/thorn/include/kernel/peripherals/mailbox.h index bdef5b5..37f664c 100644 --- a/thorn/include/kernel/peripherals/mailbox.h +++ b/thorn/include/kernel/peripherals/mailbox.h @@ -16,14 +16,4 @@ #define MBOX_SUCCESS 0x80000000 -enum { - VIDEOCORE_MBOX = (PBASE + 0x0000B880), - MBOX_POLL = (VIDEOCORE_MBOX + 0x10), - MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), - MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), - MBOX_RESPONSE = 0x80000000, - MBOX_FULL = 0x80000000, - MBOX_EMPTY = 0x40000000 -}; - #endif//_ROSE_K_P_MAILBOX_H \ No newline at end of file diff --git a/thorn/src/kernel/mailbox.c b/thorn/src/kernel/mailbox.c index a5684b0..a744c50 100644 --- a/thorn/src/kernel/mailbox.c +++ b/thorn/src/kernel/mailbox.c @@ -13,7 +13,7 @@ bool mailbox_request (volatile unsigned int * data_ptr, channel_t channel) { unsigned int outgoing = ((unsigned int) ((long) data_ptr) & ~0xF) | (channel & 0xF); // Wait until we can write - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_FULL) + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL) ; // Write the address of our buffer to the mailbox with the channel appended @@ -22,7 +22,7 @@ bool mailbox_request (volatile unsigned int * data_ptr, channel_t channel) { unsigned int incoming; while (1) { // Is there a reply? - while (get32 (MBOX0 + MBOX_STATUS) & MBOX_EMPTY) + while (get32 (MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY) ; incoming = get32 (MBOX0 + MBOX_READ); From 0561c129f5f5f3945bda06aafa914e84646901aa Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Fri, 17 Sep 2021 14:03:05 +0200 Subject: [PATCH 38/61] feat(io): initialise framebuffer [not working] NOTE: Absolutely Not Working --- thorn/src/kernel/kernel.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 46a4431..7a1cb37 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -59,13 +59,12 @@ void kernel_process () { void kernel_init (void) { uart_init (); - init_gpu (); - init_printf (0, putc); - irq_vector_init (); - timer_init (); - enable_interrupt_controller (); - enable_irq (); - task_init (); + init_printf (0, putc); + irq_vector_init (); + timer_init (); + enable_interrupt_controller (); + enable_irq (); + task_init (); printf ("Initialising Framebuffer...\r\n"); int gpu_status = init_gpu (); @@ -90,6 +89,12 @@ void kernel_main (int processor_id) { if (processor_id == 0) { kernel_init (); + + if (! init_gpu ()) { + printf ("Error while initialising framebuffer\r\n"); + } else { + get_fb (); + } } while (processor_id != current_processor) From fb44629c19bccb8627461fdc965536c75013807d Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 10:02:07 +0200 Subject: [PATCH 39/61] fix(mb): added missing left shift --- chainloader/src/mailbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index cf12e56..f0c8e93 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -20,7 +20,7 @@ unsigned int mailbox_read (channel_t channel) { } while ((value & 0xF) != channel); // Return most significant bits (actual address) - return value >> 4; + return ((value >> 4) << 4); } unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { From 24d89f842a24f8c1e9f5a3c0f6f6482565ea134f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 11:55:39 +0200 Subject: [PATCH 40/61] refactor(io): rewrite mailbox and adapt gpu init to it NOTE: doesn't work yet - produces ``` Type SYNC_INVALID_EL1h, ESR: 0x96000040, address, 0x81044Type ``` --- chainloader/src/mailbox.c | 44 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index f0c8e93..0ce766c 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -1,34 +1,38 @@ #include "kernel/mailbox.h" -void mailbox_send (unsigned int data, channel_t channel) { - mbox_message_t msg = {data, channel}; +bool mailbox_request (unsigned int data_ptr, channel_t channel) { + mbox_message_t msg; + unsigned int * msg_ptr = (unsigned int *) & msg; + unsigned int check; - while ((MBOX1 + MBOX_STATUS) & MBOX_WRITE_FULL); - put32 (MBOX1 + MBOX_WRITE, * (unsigned int *) & msg); -} - -unsigned int mailbox_read (channel_t channel) { - unsigned int value; + * msg_ptr = data_ptr; + msg.channel = channel; + + while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + put32 (MBOX0 + MBOX_WRITE, * msg_ptr); do { // Wait until there's a message while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); - value = get32 (MBOX0 + MBOX_READ); + check = get32 (MBOX0 + MBOX_READ); - // Wait until the channel matches (lest four significant bits) - } while ((value & 0xF) != channel); + // Check if it's the response to our message + } while (* msg_ptr == check); + + // Get the pointer to the property request message + mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~ 0xFF)); - // Return most significant bits (actual address) - return ((value >> 4) << 4); + // Return the message's response code + return property->response == MBOX_SUCCESS; } -unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { - mbox_property_t * msg = (mbox_property_t *) get_free_page (); +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { + mbox_property_t * msg = (mbox_property_t * ) & message; // Add tags to message: unsigned int struct_size = 2 * sizeof (unsigned int); - struct_size += mailbox_write_tags ((mbox_tag_t * ) (msg + struct_size), tags); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags); // Add end tag and 16 byte-aligned padding: struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; @@ -36,8 +40,8 @@ unsigned int mailbox_send_tags (channel_t channel, mbox_tag_t * tags) { // write struct size to message: msg->struct_size = struct_size; - mailbox_send ((unsigned int) msg, channel); - return msg; + // return number of bytes written, for reference + return struct_size; } unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { @@ -56,9 +60,9 @@ unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { dest->buffer[written] = src->buffer[written]; } written += 3 * sizeof (unsigned int) + buffer_size; - put32 (dest + written, 0); + put32 ((unsigned int) (dest + written), 0); written += sizeof (unsigned int); - put32 (dest + written, 0); + put32 ((unsigned int) (dest + written), 0); written += (written % 16) ? 16 - (written % 16) : 0; } return written; From 57f1f23688cb6c87e5791703104f09f8320bda12 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 21 Sep 2021 13:08:04 +0200 Subject: [PATCH 41/61] WIP: add debug showing program gets stuck waiting for configuration --- chainloader/src/mailbox.c | 25 ++++++++++++++++++++----- thorn/include/common/logging.h | 9 ++++----- thorn/src/common/printf.c | 33 ++++++++++++++------------------- thorn/src/kernel/kernel.c | 13 ++++++++++--- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/chainloader/src/mailbox.c b/chainloader/src/mailbox.c index 0ce766c..ee5b8b7 100644 --- a/chainloader/src/mailbox.c +++ b/chainloader/src/mailbox.c @@ -8,31 +8,42 @@ bool mailbox_request (unsigned int data_ptr, channel_t channel) { * msg_ptr = data_ptr; msg.channel = channel; + LOG ("Waiting for empty write buffer GPU..."); while ((MBOX0 + MBOX_STATUS) & MBOX_WRITE_FULL); + LOG ("Writing to GPU..."); put32 (MBOX0 + MBOX_WRITE, * msg_ptr); + LOG ("Reading response..."); do { // Wait until there's a message + LOG ("Waiting for any message..."); while ((MBOX0 + MBOX_STATUS) & MBOX_READ_EMPTY); + LOG ("Check message"); check = get32 (MBOX0 + MBOX_READ); + LOG ("Check channel"); // Check if it's the response to our message } while (* msg_ptr == check); + LOG ("Read pointer to property response"); // Get the pointer to the property request message mbox_property_t * property = (mbox_property_t * ) ((unsigned long) (* msg_ptr & ~ 0xFF)); + char * buffer[100]; + sprinf (buffer, "Returning response code: operation %s", + (property->response == MBOX_SUCCESS) ? "succeeded" : "failed"); + LOG (buffer); // Return the message's response code return property->response == MBOX_SUCCESS; } -unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { +unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags, int tags_count) { mbox_property_t * msg = (mbox_property_t * ) & message; // Add tags to message: unsigned int struct_size = 2 * sizeof (unsigned int); - struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags); + struct_size += mailbox_write_tags ((mbox_tag_t * ) (message + struct_size), tags, tags_count); // Add end tag and 16 byte-aligned padding: struct_size += (struct_size % 16) ? 32 - (struct_size % 16) : 16; @@ -40,13 +51,15 @@ unsigned int mailbox_write_msg (unsigned int message[], mbox_tag_t * tags) { // write struct size to message: msg->struct_size = struct_size; + int_dump (struct_size, (unsigned int *) msg); + // return number of bytes written, for reference return struct_size; } -unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { +unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src, int tags_count) { unsigned int written = 0; - while (src->identity) { + for (int i = 0; i < tags_count; i ++) { dest += written; unsigned int buffer_size = src->buffer_size; @@ -55,15 +68,17 @@ unsigned int mailbox_write_tags (mbox_tag_t * dest, mbox_tag_t * src) { dest->buffer_size = buffer_size; dest->response = 0; - for (unsigned int i = 0; i < buffer_size; i ++) { dest->buffer[written] = src->buffer[written]; } written += 3 * sizeof (unsigned int) + buffer_size; put32 ((unsigned int) (dest + written), 0); + written += sizeof (unsigned int); put32 ((unsigned int) (dest + written), 0); + written += (written % 16) ? 16 - (written % 16) : 0; } + return written; } diff --git a/thorn/include/common/logging.h b/thorn/include/common/logging.h index fa4db93..710659d 100644 --- a/thorn/include/common/logging.h +++ b/thorn/include/common/logging.h @@ -3,11 +3,10 @@ #include "common/printf.h" -#define LOG(msg) \ - do { \ - static int __counter__ = 0; \ - printf (__FILE__ ":%d:[%d] %s\r\n", __LINE__, __counter__++, msg); \ - } while (0) +#define LOG(msg) \do { \ + static int __counter__ = 0; \ + printf(__FILE__":%d:[%d] %s\r\n", __LINE__, __counter__++, msg); \ +} while (0) #define ASSERT(expr) \ do { \ diff --git a/thorn/src/common/printf.c b/thorn/src/common/printf.c index 4955175..059ee24 100644 --- a/thorn/src/common/printf.c +++ b/thorn/src/common/printf.c @@ -158,7 +158,8 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { uli2a (va_arg (va, unsigned long int), 10, 0, bf); else #endif - ui2a (va_arg (va, unsigned int), 10, 0, bf); + ui2a (va_arg (va, + unsigned int), 10, 0, bf); putchw (putp, putf, w, lz, bf); break; } @@ -168,7 +169,8 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { li2a (va_arg (va, unsigned long int), bf); else #endif - i2a (va_arg (va, int), bf); + i2a (va_arg (va, + int), bf); putchw (putp, putf, w, lz, bf); break; } @@ -179,14 +181,17 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { uli2a (va_arg (va, unsigned long int), 16, (ch == 'X'), bf); else #endif - ui2a (va_arg (va, unsigned int), 16, (ch == 'X'), bf); + ui2a (va_arg (va, + unsigned int), 16, (ch == 'X'), bf); putchw (putp, putf, w, lz, bf); break; - case 'c': - putf (putp, (char) (va_arg (va, int))); + case 'c' : + putf (putp, (char) (va_arg (va, + int))); break; - case 's': - putchw (putp, putf, w, 0, va_arg (va, char *)); + case 's' : + putchw (putp, putf, w, 0, va_arg (va, + char*)); break; case 'p': case 'P': @@ -197,20 +202,10 @@ void tfp_format (void * putp, putcf putf, char * fmt, va_list va) { uli2a (va_arg (va, unsigned long int), 16, (ch == 'P'), bf); else #endif - ui2a (va_arg (va, unsigned int), 16, (ch == 'P'), bf); + ui2a (va_arg (va, + unsigned int), 16, (ch == 'P'), bf); putchw (putp, putf, w, lz, bf); break; - case 'p': case 'P': - putf(putp, '0'); - putf(putp, 'x'); -#ifdef PRINTF_LONG_SUPPORT - if (lng) - uli2a(va_arg(va, unsigned long int),16,(ch=='P'),bf); - else -#endif - ui2a(va_arg(va, unsigned int),16,(ch=='P'),bf); - putchw(putp,putf,w,lz,bf); - break; case '%': putf (putp, ch); default: diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 7a1cb37..5821a44 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -90,10 +90,17 @@ void kernel_main (int processor_id) { if (processor_id == 0) { kernel_init (); - if (! init_gpu ()) { - printf ("Error while initialising framebuffer\r\n"); + printf ("Initialising Framebuffer...\r\n"); + int gpu_status = init_gpu (); + if (! gpu_status) { + printf ("Error while initialising Framebuffer\r\n"); } else { - get_fb (); + unsigned long fb = get_fb (); + if (! fb) { + printf ("Error: Invalid Framebuffer received\r\n"); + } else { + printf ("Received framebuffer: %p\r\n", fb); + } } } From 47a56965f3fb89f94d978fdfd096577ab3998857 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 14 Oct 2021 12:25:49 +0200 Subject: [PATCH 42/61] feat(gpu): hardcode printing of four pixels --- thorn/src/kernel/kernel.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 5821a44..07811f7 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -86,22 +86,8 @@ void kernel_init (void) { void kernel_main (int processor_id) { static volatile unsigned int current_processor = 0; - if (processor_id == 0) { kernel_init (); - - printf ("Initialising Framebuffer...\r\n"); - int gpu_status = init_gpu (); - if (! gpu_status) { - printf ("Error while initialising Framebuffer\r\n"); - } else { - unsigned long fb = get_fb (); - if (! fb) { - printf ("Error: Invalid Framebuffer received\r\n"); - } else { - printf ("Received framebuffer: %p\r\n", fb); - } - } } while (processor_id != current_processor) From 94e05492c7d7a509a592f49b889b80bc1ff43aad Mon Sep 17 00:00:00 2001 From: BMG93 Date: Thu, 14 Oct 2021 19:57:54 +0200 Subject: [PATCH 43/61] Bitmap font : WIP currently not rendering any pixels on screen --- thorn/include/common/font.h | 139 +++++++++++++++++++++++++++++++++ thorn/include/common/gpu.h | 6 +- thorn/include/common/logging.h | 11 +-- thorn/include/common/rainbow.h | 2 +- thorn/include/common/screen.h | 21 ++--- thorn/src/common/gpu.c | 10 +-- thorn/src/common/rainbow.c | 2 +- thorn/src/common/screen.c | 55 +++---------- thorn/src/kernel/kernel.c | 2 +- 9 files changed, 170 insertions(+), 78 deletions(-) create mode 100644 thorn/include/common/font.h diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h new file mode 100644 index 0000000..1210bbb --- /dev/null +++ b/thorn/include/common/font.h @@ -0,0 +1,139 @@ +#ifndef _ROSE_C_FONT_H +#define _ROSE_C_FONT_H + +#define FONT_SIZE 8 +/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ +const unsigned long long int * font(int c) { + static const char f[128][FONT_SIZE] = { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space) + { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!) + { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (") + { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#) + { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($) + { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%) + { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&) + { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (') + { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (() + { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ()) + { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*) + { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,) + { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.) + { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/) + { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0) + { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1) + { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2) + { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3) + { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4) + { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5) + { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6) + { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7) + { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8) + { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9) + { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:) + { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (//) + { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<) + { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=) + { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>) + { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?) + { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@) + { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A) + { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B) + { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C) + { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D) + { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E) + { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F) + { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G) + { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H) + { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I) + { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J) + { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K) + { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L) + { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M) + { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N) + { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O) + { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P) + { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q) + { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R) + { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S) + { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T) + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U) + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V) + { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W) + { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X) + { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y) + { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z) + { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([) + { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\) + { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (]) + { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_) + { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`) + { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a) + { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b) + { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c) + { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d) + { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e) + { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f) + { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g) + { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h) + { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i) + { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j) + { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k) + { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l) + { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m) + { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n) + { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o) + { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p) + { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q) + { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r) + { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s) + { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v) + { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w) + { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x) + { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y) + { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z) + { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({) + { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|) + { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (}) + { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F + }; + return (unsigned long long int *)f[c]; +} +#endif diff --git a/thorn/include/common/gpu.h b/thorn/include/common/gpu.h index dadc67b..de01056 100644 --- a/thorn/include/common/gpu.h +++ b/thorn/include/common/gpu.h @@ -30,10 +30,10 @@ typedef struct { byte_t green; byte_t red; byte_t alpha; -} color; +} color_t; typedef struct { - color * fb; + color_t * fb; unsigned int fb_size; short virtual_width; short virtual_height; @@ -47,7 +47,7 @@ static fb_info_t fb_info; bool init_gpu (void); -color * get_fb (void); +color_t * get_fb (void); fb_info_t const * get_fb_info (void); diff --git a/thorn/include/common/logging.h b/thorn/include/common/logging.h index 710659d..a58da93 100644 --- a/thorn/include/common/logging.h +++ b/thorn/include/common/logging.h @@ -3,14 +3,15 @@ #include "common/printf.h" -#define LOG(msg) \do { \ - static int __counter__ = 0; \ - printf(__FILE__":%d:[%d] %s\r\n", __LINE__, __counter__++, msg); \ -} while (0) +#define LOG(msg) \ + do { \ + static int __counter__ = 0; \ + printf (__FILE__ ":%d:[%d] %s\r\n", __LINE__, __counter__++, msg); \ + } while (0) #define ASSERT(expr) \ do { \ - if (!(expr)) \ + if (! (expr)) \ LOG ("Assertion failed"); \ } while (0) diff --git a/thorn/include/common/rainbow.h b/thorn/include/common/rainbow.h index b8ae654..0389940 100644 --- a/thorn/include/common/rainbow.h +++ b/thorn/include/common/rainbow.h @@ -3,7 +3,7 @@ #include "common/gpu.h" -static color const RAINBOW[] = { +static color_t const RAINBOW[] = { {0xff, 0x00, 0xff, 0}, {0xc0, 0x00, 0xff, 0}, {0x80, 0x00, 0xff, 0}, diff --git a/thorn/include/common/screen.h b/thorn/include/common/screen.h index 8da1800..ab4b68a 100644 --- a/thorn/include/common/screen.h +++ b/thorn/include/common/screen.h @@ -1,21 +1,10 @@ #ifndef _ROSE_C_SCREEN_H #define _ROSE_C_SCREEN_H +#include "common/font.h" +#include "common/gpu.h" -#include "common/printf.h" +void printc(char c); -#define HEIGHT 79 -#define WIDTH 317 +void drawpx (unsigned int x, unsigned int y, color_t color); -static char screen[HEIGHT * WIDTH]; - -void clear_screen (); - -void draw_border (); - -void draw_screen (); - -char get_pixel (int x, int y); - -char set_pixel (int x, int y, char c); - -#endif//_ROSE_C_SCREEN_H \ No newline at end of file +#endif //_ROSE_C_SCREEN_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index 2b31913..b86af19 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -16,7 +16,7 @@ bool init_gpu () { gpu_msg_buffer[0] = (4 * ++c);// Write message size at the beginning of the buffer // If reading physical screen dimension fails exit function - if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) + if (! mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; } { // Second message: request frame buffer @@ -64,11 +64,11 @@ bool init_gpu () { gpu_msg_buffer[0] = (4 * ++c);// Write message size at the beginning of the buffer // If message failed exit - if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) + if (! mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; // Since message succeeded, update frame buffer and its size - fb_info.fb = (color *) (long) (gpu_msg_buffer[index_framebuffer] & VC_SDRAM_OFFSET); + fb_info.fb = (color_t *) (long) (gpu_msg_buffer[index_framebuffer] & VC_SDRAM_OFFSET); fb_info.fb_size = gpu_msg_buffer[index_fb_size]; } { // Third message: read pitch (in bytes per line) @@ -87,7 +87,7 @@ bool init_gpu () { gpu_msg_buffer[0] = (4 * ++c);// Write message size at the beginning of the buffer // If message failed exit - if (!mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) + if (! mailbox_request (gpu_msg_buffer, PROPERTY_ARM_VC)) return false; // Else write pitch appropriately @@ -96,7 +96,7 @@ bool init_gpu () { return true; } -color * get_fb () { +color_t * get_fb () { return fb_info.fb; } diff --git a/thorn/src/common/rainbow.c b/thorn/src/common/rainbow.c index 7efb05e..16e000f 100644 --- a/thorn/src/common/rainbow.c +++ b/thorn/src/common/rainbow.c @@ -1,7 +1,7 @@ #include "common/rainbow.h" void draw () { - unsigned int const RB_SIZE = sizeof (RAINBOW) / sizeof (color); + unsigned int const RB_SIZE = sizeof (RAINBOW) / sizeof (color_t); unsigned int const X_DIVISOR = GPU_SCREEN_WIDTH / RB_SIZE; unsigned int const Y_DIVISOR = GPU_SCREEN_HEIGHT / RB_SIZE; diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index 937b091..a01d33d 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -1,47 +1,10 @@ #include "common/screen.h" - -void clear_screen () { - for (int i = 0; i < HEIGHT; i++) { - printf ("\n"); - } -} - -void draw_border () { - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { - char c; - if (y == 0 || y == HEIGHT - 1) { - if (x == 0 || x == WIDTH - 1) { - c = '+'; - } else { - c = '-'; - } - } else { - if (x == 0 || x == WIDTH - 1) { - c = '|'; - } else { - c = ' '; - } - } - printf ("%c", c); - set_pixel (x, y, c); - } - } -} - -void draw_screen () { - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { - printf ("%c", get_pixel (x, y)); - } - printf ("\r\n"); - } -} - -char get_pixel (int x, int y) { - return screen[x + WIDTH * y]; -} - -char set_pixel (int x, int y, char c) { - return screen[x + WIDTH * y] = c; -} +#define FB_PITCH GPU_COLOUR_DEPTH * GPU_SCREEN_WIDTH +//static color_t * fb = get_fb(); +void printc(char c){ +}; + +void drawpx (unsigned int x, unsigned int y, color_t color){ + unsigned long int location = get_fb() + y * FB_PITCH + x * GPU_COLOUR_DEPTH; + get_fb()[location] = color; +}; \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 07811f7..6244a1e 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -71,7 +71,7 @@ void kernel_init (void) { if (! gpu_status) { printf ("Error while initialising Framebuffer\r\n"); } else { - color * fb = get_fb (); + color_t * fb = get_fb (); if (! fb) { printf ("Error: Invalid Framebuffer received\r\n"); } else { From dd73b5158f857caa815c776e3aef2d200307c6c9 Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 21 Oct 2021 10:51:48 +0200 Subject: [PATCH 44/61] fix(bitmap): remove get_fb() from pixel location --- thorn/src/common/screen.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index a01d33d..1566aa4 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -1,10 +1,9 @@ #include "common/screen.h" -#define FB_PITCH GPU_COLOUR_DEPTH * GPU_SCREEN_WIDTH -//static color_t * fb = get_fb(); -void printc(char c){ -}; +#define FB_PITCH GPU_COLOUR_DEPTH *GPU_SCREEN_WIDTH +// static color_t * fb = get_fb(); +void printc(char c){}; -void drawpx (unsigned int x, unsigned int y, color_t color){ - unsigned long int location = get_fb() + y * FB_PITCH + x * GPU_COLOUR_DEPTH; - get_fb()[location] = color; +void drawpx(unsigned int x, unsigned int y, color_t color) { + unsigned long int location = y * FB_PITCH + x * GPU_COLOUR_DEPTH; + get_fb()[location] = color; }; \ No newline at end of file From 4120e92100585c79d4bae7041ed403f52c6ba410 Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 21 Oct 2021 12:45:26 +0200 Subject: [PATCH 45/61] feat(bitmap): WIP --- thorn/include/common/font.h | 137 +---------------------------- thorn/include/common/screen.h | 4 + thorn/src/common/gpu.c | 34 +++++--- thorn/src/common/screen.c | 159 ++++++++++++++++++++++++++++++++-- thorn/src/kernel/kernel.c | 37 +++++--- 5 files changed, 207 insertions(+), 164 deletions(-) diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index 1210bbb..de1ef9e 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -2,138 +2,7 @@ #define _ROSE_C_FONT_H #define FONT_SIZE 8 -/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ -const unsigned long long int * font(int c) { - static const char f[128][FONT_SIZE] = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space) - { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!) - { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (") - { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#) - { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($) - { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%) - { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&) - { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (') - { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (() - { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ()) - { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*) - { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+) - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,) - { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-) - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.) - { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/) - { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0) - { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1) - { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2) - { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3) - { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4) - { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5) - { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6) - { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7) - { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8) - { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9) - { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:) - { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (//) - { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<) - { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=) - { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>) - { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?) - { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@) - { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A) - { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B) - { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C) - { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D) - { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E) - { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F) - { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G) - { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H) - { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I) - { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J) - { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K) - { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L) - { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M) - { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N) - { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O) - { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P) - { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q) - { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R) - { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S) - { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T) - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U) - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V) - { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W) - { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X) - { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y) - { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z) - { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([) - { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\) - { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (]) - { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^) - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_) - { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`) - { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a) - { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b) - { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c) - { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d) - { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e) - { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f) - { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g) - { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h) - { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i) - { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j) - { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k) - { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l) - { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m) - { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n) - { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o) - { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p) - { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q) - { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r) - { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s) - { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t) - { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u) - { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v) - { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w) - { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x) - { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y) - { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z) - { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({) - { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|) - { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (}) - { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~) - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F - }; - return (unsigned long long int *)f[c]; -} + +const unsigned long long int * font (int c); + #endif diff --git a/thorn/include/common/screen.h b/thorn/include/common/screen.h index ab4b68a..6beaf3b 100644 --- a/thorn/include/common/screen.h +++ b/thorn/include/common/screen.h @@ -7,4 +7,8 @@ void printc(char c); void drawpx (unsigned int x, unsigned int y, color_t color); +short get_max_width (); +short get_max_height (); + + #endif //_ROSE_C_SCREEN_H \ No newline at end of file diff --git a/thorn/src/common/gpu.c b/thorn/src/common/gpu.c index b86af19..17539a8 100644 --- a/thorn/src/common/gpu.c +++ b/thorn/src/common/gpu.c @@ -6,12 +6,11 @@ bool init_gpu () { gpu_msg_buffer[++c] = 0;// Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE gpu_msg_buffer[++c] = 0x00040003;// Tag to get physical display width / height - gpu_msg_buffer[++c] = 0; // Size of value buffer + gpu_msg_buffer[++c] = 8; // Size of value buffer gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here gpu_msg_buffer[++c] = 0; // Get physical screen width | Overwritten by actual width gpu_msg_buffer[++c] = 0; // Get physical screen height | Overwritten by actual height - - gpu_msg_buffer[++c] = 0;// End tag + gpu_msg_buffer[++c] = 0; // End tag gpu_msg_buffer[0] = (4 * ++c);// Write message size at the beginning of the buffer @@ -24,23 +23,29 @@ bool init_gpu () { gpu_msg_buffer[++c] = 0;// Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE #ifdef GPU_OVERRIDE_PHYSICAL_SCREEN // If this is set, update physical /virtual dimensions based on constants - gpu_msg_buffer[++c] = 0x00048003; // Tag to set virtual display width / height + gpu_msg_buffer[++c] = 0x00048003; // Tag to set virtual display width / height + gpu_msg_buffer[++c] = 8; // Size of value buffer + gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here + gpu_msg_buffer[++c] = GPU_SCREEN_WIDTH;// Set virtual screen width | Overwritten by actual virtual width + int index_gpu_width = c; + gpu_msg_buffer[++c] = GPU_SCREEN_HEIGHT;// Set virtual screen height | Overwritten by actual virtual height + int index_gpu_height = c; + + gpu_msg_buffer[++c] = 0x00048004; // Tag to set virtual display width / height gpu_msg_buffer[++c] = 8; // Size of value buffer gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here - gpu_msg_buffer[++c] = GPU_SCREEN_WIDTH; // Set virtual screen width | Overwritten by actual virtual width - gpu_msg_buffer[++c] = GPU_SCREEN_HEIGHT;// Set virtual screen height | Overwritten by actual virtual height - - gpu_msg_buffer[++c] = 0x00048004; // Tag to set virtual display width / height - gpu_msg_buffer[++c] = 8; // Size of value buffer - gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here - gpu_msg_buffer[++c] = GPU_VIRTUAL_WIDTH; // Set virtual screen width | Overwritten by actual virtual width + gpu_msg_buffer[++c] = GPU_VIRTUAL_WIDTH;// Set virtual screen width | Overwritten by actual virtual width + int index_width = c; gpu_msg_buffer[++c] = GPU_VIRTUAL_HEIGHT;// Set virtual screen height | Overwritten by actual virtual height + int index_height = c; #else gpu_msg_buffer[++c] = 0x00048004;// Tag to set virtual display width / height gpu_msg_buffer[++c] = 8; // Size of value buffer gpu_msg_buffer[++c] = 0; // Response & value buffer size written will be written here gpu_msg_buffer[++c]; //GPU_SCREEN_WIDTH; // Reuse previous width | Overwritten by actual virtual width - gpu_msg_buffer[++c]; //GPU_SCREEN_HEIGHT; // Reuse previous height | Overwritten by actual virtual height + int index_width = c; + gpu_msg_buffer[++c];//GPU_SCREEN_HEIGHT; // Reuse previous height | Overwritten by actual virtual height + int index_height = c; #endif gpu_msg_buffer[++c] = 0x00048005; // Tag to set pixel depth @@ -70,6 +75,11 @@ bool init_gpu () { // Since message succeeded, update frame buffer and its size fb_info.fb = (color_t *) (long) (gpu_msg_buffer[index_framebuffer] & VC_SDRAM_OFFSET); fb_info.fb_size = gpu_msg_buffer[index_fb_size]; + + // printf ("PHY_WIDTH: %d, PHY_HEIGHT: %d, VIRT_WIDTH: %d, VIRT_HEIGHT: %d\n\r", gpu_msg_buffer[index_gpu_width], gpu_msg_buffer[index_gpu_height], gpu_msg_buffer[index_width], gpu_msg_buffer[index_height]); + + fb_info.virtual_width = gpu_msg_buffer[index_width]; + fb_info.virtual_height = gpu_msg_buffer[index_height]; } { // Third message: read pitch (in bytes per line) int c = 0;// Message size; increment while we write diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index 1566aa4..9f7520a 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -1,9 +1,156 @@ #include "common/screen.h" -#define FB_PITCH GPU_COLOUR_DEPTH *GPU_SCREEN_WIDTH +#include "common/font.h" +#define FB_PITCH GPU_COLOUR_DEPTH * GPU_SCREEN_WIDTH // static color_t * fb = get_fb(); -void printc(char c){}; -void drawpx(unsigned int x, unsigned int y, color_t color) { - unsigned long int location = y * FB_PITCH + x * GPU_COLOUR_DEPTH; - get_fb()[location] = color; -}; \ No newline at end of file +/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ +const unsigned long long int * font (int c) { + static const char f[128][FONT_SIZE] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0000 (nul) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0001 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0002 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0003 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0004 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0005 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0006 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0007 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0008 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0009 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000A + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000B + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000C + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000D + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000E + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000F + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0010 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0011 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0012 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0013 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0014 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0015 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0016 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0017 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0018 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0019 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001A + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001B + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001C + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001D + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001E + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001F + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0020 (space) + {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00},// U+0021 (!) + {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0022 (") + {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00},// U+0023 (#) + {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00},// U+0024 ($) + {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00},// U+0025 (%) + {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00},// U+0026 (&) + {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0027 (') + {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00},// U+0028 (() + {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00},// U+0029 ()) + {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00},// U+002A (*) + {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00},// U+002B (+) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+002C (,) + {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00},// U+002D (-) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+002E (.) + {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00},// U+002F (/) + {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00},// U+0030 (0) + {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00},// U+0031 (1) + {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00},// U+0032 (2) + {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00},// U+0033 (3) + {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00},// U+0034 (4) + {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00},// U+0035 (5) + {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00},// U+0036 (6) + {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00},// U+0037 (7) + {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+0038 (8) + {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00},// U+0039 (9) + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+003A (:) + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+003B (//) + {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00},// U+003C (<) + {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00},// U+003D (=) + {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00},// U+003E (>) + {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00},// U+003F (?) + {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00},// U+0040 (@) + {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00},// U+0041 (A) + {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00},// U+0042 (B) + {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00},// U+0043 (C) + {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00},// U+0044 (D) + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00},// U+0045 (E) + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00},// U+0046 (F) + {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00},// U+0047 (G) + {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00},// U+0048 (H) + {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0049 (I) + {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00},// U+004A (J) + {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00},// U+004B (K) + {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00},// U+004C (L) + {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00},// U+004D (M) + {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00},// U+004E (N) + {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00},// U+004F (O) + {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00},// U+0050 (P) + {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00},// U+0051 (Q) + {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00},// U+0052 (R) + {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00},// U+0053 (S) + {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0054 (T) + {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00},// U+0055 (U) + {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0056 (V) + {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00},// U+0057 (W) + {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00},// U+0058 (X) + {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00},// U+0059 (Y) + {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00},// U+005A (Z) + {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00},// U+005B ([) + {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00},// U+005C (\) + {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00},// U+005D (]) + {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00},// U+005E (^) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},// U+005F (_) + {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0060 (`) + {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00},// U+0061 (a) + {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00},// U+0062 (b) + {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00},// U+0063 (c) + {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00},// U+0064 (d) + {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00},// U+0065 (e) + {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00},// U+0066 (f) + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0067 (g) + {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00},// U+0068 (h) + {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0069 (i) + {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E},// U+006A (j) + {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00},// U+006B (k) + {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+006C (l) + {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00},// U+006D (m) + {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00},// U+006E (n) + {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00},// U+006F (o) + {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F},// U+0070 (p) + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78},// U+0071 (q) + {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00},// U+0072 (r) + {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00},// U+0073 (s) + {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00},// U+0074 (t) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00},// U+0075 (u) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0076 (v) + {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00},// U+0077 (w) + {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00},// U+0078 (x) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0079 (y) + {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00},// U+007A (z) + {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00},// U+007B ({) + {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},// U+007C (|) + {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00},// U+007D (}) + {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+007E (~) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F + }; + return (unsigned long long int *) f[c]; +} + + +void printc (char c) {}; + +void drawpx (unsigned int x, unsigned int y, color_t color) { + unsigned long int location = y * get_fb_info ()->pitch + x; + printf ("X: %d, Y: %d, location: %d\r\n", x, y, location); + get_fb ()[location] = color; +}; + +short get_max_width () { + return get_fb_info ()->virtual_width - 1; +} + +short get_max_height () { + return get_fb_info ()->virtual_height - 1; +} \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 6244a1e..9d5189f 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -2,6 +2,7 @@ #include "common/logging.h" #include "common/printf.h" #include "common/rainbow.h" +#include "common/screen.h" #include "common/utils.h" #include "kernel/fork.h" #include "kernel/irq.h" @@ -50,7 +51,7 @@ void user_process () { } void kernel_process () { - printf ("Kernel process started. EL %d\r\n", get_el ()); + // printf ("Kernel process started. EL %d\r\n", get_el ()); int err = move_to_user_mode ((unsigned long) &user_process); if (err < 0) { printf ("Error while moving process to user mode\n\r"); @@ -80,6 +81,14 @@ void kernel_init (void) { } LOG ("Initialisation done"); + + printf ("MAX_WIDTH: %d\n\r", get_fb_info ()->virtual_width); + printf ("MAX_HEIGHT: %d\n\r", get_fb_info ()->virtual_height); + + printf ("GET_MAX_WIDTH: %d\n\r", get_max_width ()); + printf ("GET_MAX_HEIGHT: %d\n\r", get_max_height ()); + + printf ("PITCH: %d\n\r", get_fb_info ()->pitch); } @@ -93,32 +102,36 @@ void kernel_main (int processor_id) { while (processor_id != current_processor) ; - printf ("Hello, from processor %d\n\r", processor_id); + // printf ("Hello, from processor %d\n\r", processor_id); current_processor++; while (current_processor != 3) ; switch (processor_id) { case 0: { - int res = copy_process (PF_KTHREAD, (unsigned long) &kernel_process, 0, 0); - if (res < 0) { - printf ("error while starting kernel process"); - return; - } + // int res = copy_process (PF_KTHREAD, (unsigned long) &kernel_process, 0, 0); + // if (res < 0) { + // // printf ("error while starting kernel process"); + // return; + // } while (1) { - schedule (); + // schedule (); } } case 1: - if (get_fb ()) - draw (); + if (get_fb ()) { + color_t color = {0xff, 0xff, 0xff, 0xff}; + for (int i = 0; i < 50; i++) { + drawpx (i, i, color); + } + } break; case 2: case 3: default: - printf ("Undefined behaviour on processor %d\r\n", processor_id); + // printf ("Undefined behaviour on processor %d\r\n", processor_id); while (1) ; } - printf ("Processor %d going out of scope\r\n", processor_id); + // printf ("Processor %d going out of scope\r\n", processor_id); } From d2f9e290a873ebf92f3c871c06f3a03d2082dc87 Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 21 Oct 2021 12:55:42 +0200 Subject: [PATCH 46/61] fix(bitmap): drawpx --- thorn/src/common/screen.c | 2 +- thorn/src/kernel/kernel.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index 9f7520a..9b88ca5 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -142,7 +142,7 @@ const unsigned long long int * font (int c) { void printc (char c) {}; void drawpx (unsigned int x, unsigned int y, color_t color) { - unsigned long int location = y * get_fb_info ()->pitch + x; + unsigned long int location = y * (get_fb_info ()->pitch) / sizeof (color_t) + x; printf ("X: %d, Y: %d, location: %d\r\n", x, y, location); get_fb ()[location] = color; }; diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 9d5189f..7d06db2 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -121,9 +121,13 @@ void kernel_main (int processor_id) { case 1: if (get_fb ()) { color_t color = {0xff, 0xff, 0xff, 0xff}; - for (int i = 0; i < 50; i++) { + for (int i = 0; i < get_max_height (); i++) { drawpx (i, i, color); } + drawpx (0, 0, color); + drawpx (get_max_width (), 0, color); + drawpx (0, get_max_height (), color); + drawpx (get_max_width (), get_max_height (), color); } break; case 2: From 90608fcd040d34e774675682f907a84822201cd0 Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 21 Oct 2021 12:56:43 +0200 Subject: [PATCH 47/61] chore(bitmap): remove printf in drawpx --- thorn/src/common/screen.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index 9b88ca5..f16c382 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -143,8 +143,7 @@ void printc (char c) {}; void drawpx (unsigned int x, unsigned int y, color_t color) { unsigned long int location = y * (get_fb_info ()->pitch) / sizeof (color_t) + x; - printf ("X: %d, Y: %d, location: %d\r\n", x, y, location); - get_fb ()[location] = color; + get_fb ()[location] = color; }; short get_max_width () { From 356c0f78e4c11fc3f26538583080e06fac090aeb Mon Sep 17 00:00:00 2001 From: Max Streitberger Date: Thu, 21 Oct 2021 13:58:46 +0200 Subject: [PATCH 48/61] feat(bitmap): working on printing char --- thorn/include/common/font.h | 5 +- thorn/src/common/font.c | 163 ++++++++++++++++++++++++++++++++++++ thorn/src/common/screen.c | 141 ------------------------------- thorn/src/kernel/kernel.c | 9 +- 4 files changed, 169 insertions(+), 149 deletions(-) create mode 100644 thorn/src/common/font.c diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index de1ef9e..3a2e4e9 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -1,8 +1,11 @@ #ifndef _ROSE_C_FONT_H #define _ROSE_C_FONT_H -#define FONT_SIZE 8 +#define FONT_SIZE 8 * 5 + +#include "common/screen.h" const unsigned long long int * font (int c); +void printc_location(char c, unsigned int x, unsigned int y); #endif diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c new file mode 100644 index 0000000..9ed177a --- /dev/null +++ b/thorn/src/common/font.c @@ -0,0 +1,163 @@ +#include "common/font.h" + +/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ +const unsigned long long int * font (int c) { + static const char f[128][FONT_SIZE] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0000 (nul) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0001 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0002 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0003 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0004 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0005 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0006 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0007 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0008 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0009 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000A + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000B + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000C + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000D + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000E + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000F + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0010 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0011 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0012 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0013 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0014 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0015 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0016 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0017 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0018 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0019 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001A + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001B + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001C + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001D + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001E + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001F + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0020 (space) + {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00},// U+0021 (!) + {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0022 (") + {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00},// U+0023 (#) + {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00},// U+0024 ($) + {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00},// U+0025 (%) + {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00},// U+0026 (&) + {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0027 (') + {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00},// U+0028 (() + {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00},// U+0029 ()) + {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00},// U+002A (*) + {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00},// U+002B (+) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+002C (,) + {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00},// U+002D (-) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+002E (.) + {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00},// U+002F (/) + {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00},// U+0030 (0) + {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00},// U+0031 (1) + {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00},// U+0032 (2) + {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00},// U+0033 (3) + {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00},// U+0034 (4) + {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00},// U+0035 (5) + {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00},// U+0036 (6) + {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00},// U+0037 (7) + {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+0038 (8) + {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00},// U+0039 (9) + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+003A (:) + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+003B (//) + {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00},// U+003C (<) + {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00},// U+003D (=) + {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00},// U+003E (>) + {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00},// U+003F (?) + {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00},// U+0040 (@) + {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00},// U+0041 (A) + {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00},// U+0042 (B) + {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00},// U+0043 (C) + {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00},// U+0044 (D) + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00},// U+0045 (E) + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00},// U+0046 (F) + {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00},// U+0047 (G) + {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00},// U+0048 (H) + {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0049 (I) + {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00},// U+004A (J) + {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00},// U+004B (K) + {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00},// U+004C (L) + {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00},// U+004D (M) + {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00},// U+004E (N) + {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00},// U+004F (O) + {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00},// U+0050 (P) + {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00},// U+0051 (Q) + {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00},// U+0052 (R) + {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00},// U+0053 (S) + {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0054 (T) + {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00},// U+0055 (U) + {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0056 (V) + {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00},// U+0057 (W) + {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00},// U+0058 (X) + {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00},// U+0059 (Y) + {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00},// U+005A (Z) + {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00},// U+005B ([) + {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00},// U+005C (\) + {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00},// U+005D (]) + {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00},// U+005E (^) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},// U+005F (_) + {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0060 (`) + {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00},// U+0061 (a) + {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00},// U+0062 (b) + {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00},// U+0063 (c) + {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00},// U+0064 (d) + {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00},// U+0065 (e) + {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00},// U+0066 (f) + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0067 (g) + {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00},// U+0068 (h) + {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0069 (i) + {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E},// U+006A (j) + {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00},// U+006B (k) + {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+006C (l) + {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00},// U+006D (m) + {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00},// U+006E (n) + {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00},// U+006F (o) + {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F},// U+0070 (p) + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78},// U+0071 (q) + {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00},// U+0072 (r) + {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00},// U+0073 (s) + {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00},// U+0074 (t) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00},// U+0075 (u) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0076 (v) + {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00},// U+0077 (w) + {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00},// U+0078 (x) + {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0079 (y) + {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00},// U+007A (z) + {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00},// U+007B ({) + {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},// U+007C (|) + {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00},// U+007D (}) + {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+007E (~) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F + }; + return (unsigned long long int *) f[c]; +} + +void printc (char c) { + + // for (int i = 0; i < FONT_SIZE; i++) { + + // unsigned int y = ?; + // unsigned int x = ?; + // drawpx(); + // } +}; + +void printc_location(char c, unsigned int x, unsigned int y) { + color_t bg = {0x0, 0x0, 0x0, 0x0}; + color_t fg = {0xff, 0xff, 0xff, 0xff}; + unsigned long long int * bitmap = font(c); + for (int i = 0; i < FONT_SIZE; i++) { + for (int j = 0; j < FONT_SIZE; j++) { + bool is_on = bitmap[i] & (1 << FONT_SIZE - j - 1); + + for (int k = 0; k < 5; k++) { + for (int h = 0; h < 5; h++) { + drawpx(((x*k) + i), ((y*h) + j), is_on ? fg : bg); + } + } + } + } +} \ No newline at end of file diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index f16c382..f410612 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -1,145 +1,4 @@ #include "common/screen.h" -#include "common/font.h" -#define FB_PITCH GPU_COLOUR_DEPTH * GPU_SCREEN_WIDTH -// static color_t * fb = get_fb(); - -/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ -const unsigned long long int * font (int c) { - static const char f[128][FONT_SIZE] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0000 (nul) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0001 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0002 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0003 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0004 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0005 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0006 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0007 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0008 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0009 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000A - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000B - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000C - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000D - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000E - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+000F - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0010 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0011 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0012 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0013 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0014 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0015 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0016 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0017 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0018 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0019 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001A - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001B - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001C - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001D - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001E - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+001F - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0020 (space) - {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00},// U+0021 (!) - {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0022 (") - {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00},// U+0023 (#) - {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00},// U+0024 ($) - {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00},// U+0025 (%) - {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00},// U+0026 (&) - {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0027 (') - {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00},// U+0028 (() - {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00},// U+0029 ()) - {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00},// U+002A (*) - {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00},// U+002B (+) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+002C (,) - {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00},// U+002D (-) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+002E (.) - {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00},// U+002F (/) - {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00},// U+0030 (0) - {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00},// U+0031 (1) - {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00},// U+0032 (2) - {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00},// U+0033 (3) - {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00},// U+0034 (4) - {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00},// U+0035 (5) - {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00},// U+0036 (6) - {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00},// U+0037 (7) - {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+0038 (8) - {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00},// U+0039 (9) - {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+003A (:) - {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+003B (//) - {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00},// U+003C (<) - {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00},// U+003D (=) - {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00},// U+003E (>) - {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00},// U+003F (?) - {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00},// U+0040 (@) - {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00},// U+0041 (A) - {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00},// U+0042 (B) - {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00},// U+0043 (C) - {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00},// U+0044 (D) - {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00},// U+0045 (E) - {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00},// U+0046 (F) - {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00},// U+0047 (G) - {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00},// U+0048 (H) - {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0049 (I) - {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00},// U+004A (J) - {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00},// U+004B (K) - {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00},// U+004C (L) - {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00},// U+004D (M) - {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00},// U+004E (N) - {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00},// U+004F (O) - {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00},// U+0050 (P) - {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00},// U+0051 (Q) - {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00},// U+0052 (R) - {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00},// U+0053 (S) - {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0054 (T) - {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00},// U+0055 (U) - {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0056 (V) - {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00},// U+0057 (W) - {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00},// U+0058 (X) - {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00},// U+0059 (Y) - {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00},// U+005A (Z) - {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00},// U+005B ([) - {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00},// U+005C (\) - {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00},// U+005D (]) - {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00},// U+005E (^) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},// U+005F (_) - {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0060 (`) - {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00},// U+0061 (a) - {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00},// U+0062 (b) - {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00},// U+0063 (c) - {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00},// U+0064 (d) - {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00},// U+0065 (e) - {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00},// U+0066 (f) - {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0067 (g) - {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00},// U+0068 (h) - {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+0069 (i) - {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E},// U+006A (j) - {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00},// U+006B (k) - {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+006C (l) - {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00},// U+006D (m) - {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00},// U+006E (n) - {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00},// U+006F (o) - {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F},// U+0070 (p) - {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78},// U+0071 (q) - {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00},// U+0072 (r) - {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00},// U+0073 (s) - {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00},// U+0074 (t) - {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00},// U+0075 (u) - {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00},// U+0076 (v) - {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00},// U+0077 (w) - {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00},// U+0078 (x) - {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+0079 (y) - {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00},// U+007A (z) - {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00},// U+007B ({) - {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},// U+007C (|) - {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00},// U+007D (}) - {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+007E (~) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F - }; - return (unsigned long long int *) f[c]; -} - - -void printc (char c) {}; void drawpx (unsigned int x, unsigned int y, color_t color) { unsigned long int location = y * (get_fb_info ()->pitch) / sizeof (color_t) + x; diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 7d06db2..ce291df 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -120,14 +120,9 @@ void kernel_main (int processor_id) { } case 1: if (get_fb ()) { - color_t color = {0xff, 0xff, 0xff, 0xff}; - for (int i = 0; i < get_max_height (); i++) { - drawpx (i, i, color); + for (int i = 0; i < 128; i++) { + printc_location(i, i*8, 0); } - drawpx (0, 0, color); - drawpx (get_max_width (), 0, color); - drawpx (0, get_max_height (), color); - drawpx (get_max_width (), get_max_height (), color); } break; case 2: From f0e492eebda81a7e371a019d8191c052689878cc Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 21 Oct 2021 15:01:43 +0200 Subject: [PATCH 49/61] feat(font): configure printf to print to screen --- thorn/include/common/font.h | 14 ++++++++-- thorn/src/common/font.c | 55 +++++++++++++++++++++++-------------- thorn/src/kernel/kernel.c | 27 +++++++----------- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index 3a2e4e9..84c1989 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -1,11 +1,21 @@ #ifndef _ROSE_C_FONT_H #define _ROSE_C_FONT_H -#define FONT_SIZE 8 * 5 +#define FONT_SIZE 8 +#define FONT_FACTOR 2 + +// Spacing between lines in pixels +#define FONT_SPACING 4 #include "common/screen.h" +static int cursor_x = 0; +static int cursor_y = 0; + const unsigned long long int * font (int c); -void printc_location(char c, unsigned int x, unsigned int y); +void printc (char c); +void printc_location (char c, unsigned int x, unsigned int y); + +void putc_screen (void * p, char c); #endif diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c index 9ed177a..1e721b5 100644 --- a/thorn/src/common/font.c +++ b/thorn/src/common/font.c @@ -135,29 +135,44 @@ const unsigned long long int * font (int c) { return (unsigned long long int *) f[c]; } -void printc (char c) { - - // for (int i = 0; i < FONT_SIZE; i++) { - - // unsigned int y = ?; - // unsigned int x = ?; - // drawpx(); - // } -}; - -void printc_location(char c, unsigned int x, unsigned int y) { - color_t bg = {0x0, 0x0, 0x0, 0x0}; - color_t fg = {0xff, 0xff, 0xff, 0xff}; - unsigned long long int * bitmap = font(c); +void printc_location (char c, unsigned int x, unsigned int y) { + color_t bg = {0x0, 0x0, 0x0, 0xff}; + color_t fg = {0xff, 0xff, 0xff, 0xff}; + unsigned char const * bitmap = font (c); for (int i = 0; i < FONT_SIZE; i++) { for (int j = 0; j < FONT_SIZE; j++) { - bool is_on = bitmap[i] & (1 << FONT_SIZE - j - 1); - - for (int k = 0; k < 5; k++) { - for (int h = 0; h < 5; h++) { - drawpx(((x*k) + i), ((y*h) + j), is_on ? fg : bg); + bool is_on = bitmap[i] & (1 << j); + + int _x, _y; + for (int k = 0; k < FONT_FACTOR; k++) { + for (int h = 0; h < FONT_FACTOR; h++) { + _x = x + j * FONT_FACTOR + k; + _y = y + i * FONT_FACTOR + h; + drawpx (_x, _y, is_on ? fg : bg); } } } } -} \ No newline at end of file +} + +void printc (char c) { + printc_location (c, cursor_x, cursor_y); + cursor_x += FONT_SIZE * FONT_FACTOR; + if (c == '\r') { + cursor_x = 0; + } else if (c == '\n') { + cursor_y += FONT_SIZE * FONT_FACTOR + FONT_SPACING; + } else { + if (cursor_x >= get_max_width ()) { + cursor_x = 0; + cursor_y += FONT_SIZE * FONT_FACTOR + FONT_SPACING; + } + } + if (cursor_y >= get_max_height ()) { + cursor_y = 0; + } +} + +void putc_screen (void * p, char c) { + printc (c); +} diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index ce291df..18e88b6 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -77,18 +77,11 @@ void kernel_init (void) { printf ("Error: Invalid Framebuffer received\r\n"); } else { printf ("Received framebuffer: %p\r\n", fb); + init_printf (0, putc_screen); } } LOG ("Initialisation done"); - - printf ("MAX_WIDTH: %d\n\r", get_fb_info ()->virtual_width); - printf ("MAX_HEIGHT: %d\n\r", get_fb_info ()->virtual_height); - - printf ("GET_MAX_WIDTH: %d\n\r", get_max_width ()); - printf ("GET_MAX_HEIGHT: %d\n\r", get_max_height ()); - - printf ("PITCH: %d\n\r", get_fb_info ()->pitch); } @@ -102,27 +95,27 @@ void kernel_main (int processor_id) { while (processor_id != current_processor) ; - // printf ("Hello, from processor %d\n\r", processor_id); + printf ("Hello, from processor %d\n\r", processor_id); current_processor++; while (current_processor != 3) ; switch (processor_id) { case 0: { - // int res = copy_process (PF_KTHREAD, (unsigned long) &kernel_process, 0, 0); - // if (res < 0) { - // // printf ("error while starting kernel process"); - // return; - // } + int res = copy_process (PF_KTHREAD, (unsigned long) &kernel_process, 0, 0); + if (res < 0) { + // printf ("error while starting kernel process"); + return; + } while (1) { // schedule (); } } case 1: + printf ("Width resolution: %d\n\r", get_fb_info ()->virtual_width); + printf ("Height resolution: %d\n\r", get_fb_info ()->virtual_height); + printf ("Frame buffer: %p\n\r", get_fb ()); if (get_fb ()) { - for (int i = 0; i < 128; i++) { - printc_location(i, i*8, 0); - } } break; case 2: From 069e856dd88d69ab03d018eee3969189efa46a3f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 21 Oct 2021 15:13:19 +0200 Subject: [PATCH 50/61] refactor(font): make printing a bit nicer Also makes the font grey --- thorn/include/common/font.h | 9 +++++++-- thorn/src/common/font.c | 8 +++----- thorn/src/kernel/kernel.c | 12 +++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index 84c1989..dda8215 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -7,14 +7,19 @@ // Spacing between lines in pixels #define FONT_SPACING 4 +#include "common/gpu.h" #include "common/screen.h" static int cursor_x = 0; static int cursor_y = 0; +static color_t bg = {0x00, 0x00, 0x00, 0x00}; +static color_t fg = {0xC0, 0xC0, 0xC0, 0x00}; + const unsigned long long int * font (int c); -void printc (char c); -void printc_location (char c, unsigned int x, unsigned int y); + +void printc (char c); +void printc_location (char c, unsigned int x, unsigned int y); void putc_screen (void * p, char c); diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c index 1e721b5..30dc743 100644 --- a/thorn/src/common/font.c +++ b/thorn/src/common/font.c @@ -136,9 +136,7 @@ const unsigned long long int * font (int c) { } void printc_location (char c, unsigned int x, unsigned int y) { - color_t bg = {0x0, 0x0, 0x0, 0xff}; - color_t fg = {0xff, 0xff, 0xff, 0xff}; - unsigned char const * bitmap = font (c); + unsigned char const * bitmap = (unsigned char const *) font (c); for (int i = 0; i < FONT_SIZE; i++) { for (int j = 0; j < FONT_SIZE; j++) { bool is_on = bitmap[i] & (1 << j); @@ -163,12 +161,12 @@ void printc (char c) { } else if (c == '\n') { cursor_y += FONT_SIZE * FONT_FACTOR + FONT_SPACING; } else { - if (cursor_x >= get_max_width ()) { + if (cursor_x + FONT_SIZE + FONT_FACTOR >= get_max_width ()) { cursor_x = 0; cursor_y += FONT_SIZE * FONT_FACTOR + FONT_SPACING; } } - if (cursor_y >= get_max_height ()) { + if (cursor_y + FONT_SIZE + FONT_FACTOR >= get_max_height ()) { cursor_y = 0; } } diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 18e88b6..764402e 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -72,12 +72,13 @@ void kernel_init (void) { if (! gpu_status) { printf ("Error while initialising Framebuffer\r\n"); } else { - color_t * fb = get_fb (); - if (! fb) { + if (! get_fb ()) { printf ("Error: Invalid Framebuffer received\r\n"); } else { - printf ("Received framebuffer: %p\r\n", fb); init_printf (0, putc_screen); + printf ("Frame buffer: %p\r\n", get_fb ()); + printf ("Width resolution: %d\r\n", get_fb_info ()->virtual_width); + printf ("Height resolution: %d\r\n", get_fb_info ()->virtual_height); } } @@ -108,13 +109,10 @@ void kernel_main (int processor_id) { return; } while (1) { - // schedule (); + schedule (); } } case 1: - printf ("Width resolution: %d\n\r", get_fb_info ()->virtual_width); - printf ("Height resolution: %d\n\r", get_fb_info ()->virtual_height); - printf ("Frame buffer: %p\n\r", get_fb ()); if (get_fb ()) { } break; From 987ff7d6f0c26961e2b75b5ac6761c9d80aaedc1 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 10:29:16 +0100 Subject: [PATCH 51/61] =?UTF-8?q?feat(fan):=20run=20fan=20while=20temperat?= =?UTF-8?q?ure=20is=20above=2050=C2=B0C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thorn/include/common/temperature.h | 2 +- thorn/src/common/temperature.c | 33 +++++++++++++++++------------- thorn/src/kernel/kernel.c | 6 +----- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 883edbf..9f978b9 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -2,8 +2,8 @@ #define _ROSE_C_TEMPERATURE_H #include "common/stdbool.h" +#include "kernel/gpio.h" #include "kernel/mailbox.h" -#include "kernel/peripherals/gpio.h" #define GPIO_FAN 18 diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index d1abf73..5889e4c 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -1,6 +1,7 @@ #include "common/temperature.h" bool init_temperature () { + gpio_mode (GPIO_FAN, GPIO_OUTPUT); { // Read out maximum temperature int c = 0;// Message size; increment while we write temperature_request[++c] = 0;// Response - will be 0x80000000 for SUCCESS or 0x80000001 for FAILURE @@ -17,7 +18,7 @@ bool init_temperature () { temperature_request[0] = (4 * ++c);// Write message size at the beginning of the buffer // If reading maximum temperature fails, keep default - if (! mailbox_request (temperature_request, PROPERTY_ARM_VC)) + if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return false; // Else update temperature max_temperature = temperature_request[index_max_temperature] ?: TEMPERATURE_MAX; @@ -30,19 +31,23 @@ bool init_temperature () { void regulate_temperature () { static int fan = 1; static int previous = TEMPERATURE_SHOULD; - int current = get_temperature (); - printf ("\rCurrent temperature: %d °C. Change since last iteration: %d °mC ", current / 1000, - (current - previous)); - - if (current < TEMPERATURE_SHOULD) { - fan = 0; - } else { - fan = 1; - } + while (1) { + int current = get_temperature (); + printf ("\rCurrent temperature: %d °C. Change since last iteration: %d °mC ", current / 1000, + (current - previous)); + + if (current < TEMPERATURE_SHOULD) { + fan = 0; + } else { + fan = 1; + } - set_fan (fan); + set_fan (fan); - previous = current; + previous = current; + + delay (TEMPERATURE_CHECK_DELAY); + } } int get_max_temperature () { @@ -66,7 +71,7 @@ int get_temperature () { temperature_request[0] = (4 * ++c);// Write message size at the beginning of the buffer // If reading maximum temperature fails, keep default - if (! mailbox_request (temperature_request, PROPERTY_ARM_VC)) + if (!mailbox_request (temperature_request, PROPERTY_ARM_VC)) return max_temperature; // Else return temperature return temperature_request[index_temperature]; @@ -74,5 +79,5 @@ int get_temperature () { } void set_fan (bool enable) { - printf ("set fan %d \r", enable); + gpio_set (GPIO_FAN, !enable); } \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 70b963b..9d71569 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -125,16 +125,12 @@ void kernel_main (int processor_id) { break; } case 1: - while (1) { - regulate_temperature (); - delay (TEMPERATURE_CHECK_DELAY); - } + regulate_temperature (); break; case 2: while (get_fb ()) { // Do screen work here } - break; case 3: default: while (1) {} From d93a7ba40378c6902583b698fdf5f71932a62b44 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 10:48:03 +0100 Subject: [PATCH 52/61] feat(fan): regulate fan in kernel process --- thorn/include/common/temperature.h | 1 + thorn/src/common/temperature.c | 7 ++++--- thorn/src/kernel/kernel.c | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 9f978b9..d5b36e0 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -2,6 +2,7 @@ #define _ROSE_C_TEMPERATURE_H #include "common/stdbool.h" +#include "kernel/fork.h" #include "kernel/gpio.h" #include "kernel/mailbox.h" diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 5889e4c..ebb1b0c 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -25,6 +25,7 @@ bool init_temperature () { } // Start regulate_temperature service here + copy_process (PF_KTHREAD, (unsigned long) ®ulate_temperature, 0, 0); return true; } @@ -36,10 +37,10 @@ void regulate_temperature () { printf ("\rCurrent temperature: %d °C. Change since last iteration: %d °mC ", current / 1000, (current - previous)); - if (current < TEMPERATURE_SHOULD) { - fan = 0; - } else { + if (current >= TEMPERATURE_SHOULD) { fan = 1; + } else if (current < TEMPERATURE_SHOULD - 2000) { + fan = 0; } set_fan (fan); diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 9d71569..63b6cf1 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -120,17 +120,15 @@ void kernel_main (int processor_id) { // break; // } while (1) { - // schedule (); + schedule (); } break; } case 1: - regulate_temperature (); - break; - case 2: while (get_fb ()) { // Do screen work here } + case 2: case 3: default: while (1) {} From b7ce1c1a71c07bf90f326b88e6dbf696d223efd8 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 11:46:28 +0100 Subject: [PATCH 53/61] feat(font): replace font with extended ascii font --- thorn/include/common/font.h | 6 +- thorn/src/common/font.c | 116 +++++++++++++++++++++++++++++++++--- 2 files changed, 113 insertions(+), 9 deletions(-) diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index b732416..e28b335 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -2,7 +2,7 @@ #define _ROSE_C_FONT_H #define FONT_SIZE 8 -#define FONT_FACTOR 2 +#define FONT_FACTOR 4 #define FONT_REAL_WIDTH (FONT_SIZE * FONT_FACTOR) // Spacing between lines in pixels @@ -20,6 +20,7 @@ #include "common/gpu.h" #include "common/screen.h" +#include "kernel/mini_uart.h" #include "kernel/mm.h" static point_t cursor = {0, 0}; @@ -29,10 +30,11 @@ static volatile color_t font_normal_fg = {0xC0, 0xC0, 0xC0, 0x00}; static volatile color_t font_error_fg = {0x00, 0x00, 0xC0, 0x00}; static volatile color_t font_fg; -const unsigned long long int * font (int c); +unsigned char const * font (unsigned char c); void printc (char c); void printc_location (point_t point, char c); +void prints_location (point_t point, char const * s); void putc_screen (void * p, char c); diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c index 86addf5..532bec5 100644 --- a/thorn/src/common/font.c +++ b/thorn/src/common/font.c @@ -1,9 +1,9 @@ #include "common/font.h" /* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */ -const unsigned long long int * font (int c) { - static const char f[128][FONT_SIZE] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0000 (nul) +unsigned char const * font (unsigned char c) { + static unsigned char const f[256][FONT_SIZE] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0000 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0001 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0002 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+0003 @@ -62,7 +62,7 @@ const unsigned long long int * font (int c) { {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+0038 (8) {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00},// U+0039 (9) {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00},// U+003A (:) - {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+003B (//) + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06},// U+003B (;) {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00},// U+003C (<) {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00},// U+003D (=) {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00},// U+003E (>) @@ -130,13 +130,109 @@ const unsigned long long int * font (int c) { {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},// U+007C (|) {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00},// U+007D (}) {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+007E (~) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// U+007F + {0x1E, 0x33, 0x03, 0x33, 0x1E, 0x18, 0x30, 0x1E},// U+00C7 (C cedille) + {0x00, 0x33, 0x00, 0x33, 0x33, 0x33, 0x7E, 0x00},// U+00FC (u umlaut) + {0x38, 0x00, 0x1E, 0x33, 0x3F, 0x03, 0x1E, 0x00},// U+00E9 (e aigu) + {0x7E, 0xC3, 0x3C, 0x60, 0x7C, 0x66, 0xFC, 0x00},// U+00E2 (a circumflex) + {0x33, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x7E, 0x00},// U+00E4 (a umlaut) + {0x07, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x7E, 0x00},// U+00E0 (a grave) + {0x0C, 0x0C, 0x1E, 0x30, 0x3E, 0x33, 0x7E, 0x00},// U+00E5 (a ring) + {0x00, 0x00, 0x1E, 0x03, 0x03, 0x1E, 0x30, 0x1C},// U+00E7 (c cedille) + {0x7E, 0xC3, 0x3C, 0x66, 0x7E, 0x06, 0x3C, 0x00},// U+00EA (e circumflex) + {0x33, 0x00, 0x1E, 0x33, 0x3F, 0x03, 0x1E, 0x00},// U+00EB (e umlaut) + {0x07, 0x00, 0x1E, 0x33, 0x3F, 0x03, 0x1E, 0x00},// U+00E8 (e grave) + {0x33, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+00EF (i umlaut) + {0x3E, 0x63, 0x1C, 0x18, 0x18, 0x18, 0x3C, 0x00},// U+00EE (i circumflex) + {0x07, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+00EC (i grave) + {0x63, 0x1C, 0x36, 0x63, 0x7F, 0x63, 0x63, 0x00},// U+00C4 (A umlaut) + {0x0C, 0x0C, 0x00, 0x1E, 0x33, 0x3F, 0x33, 0x00},// U+00C5 (A ring) + {0x07, 0x00, 0x3F, 0x06, 0x1E, 0x06, 0x3F, 0x00},// U+00C8 (E grave) + {0x00, 0x00, 0xFE, 0x30, 0xFE, 0x33, 0xFE, 0x00},// U+00E6 (ae) + {0x7C, 0x36, 0x33, 0x7F, 0x33, 0x33, 0x73, 0x00},// U+00C6 (AE) + {0x1E, 0x33, 0x00, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+00F4 (o circumflex) + {0x00, 0x33, 0x00, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+00F6 (o umlaut) + {0x00, 0x07, 0x00, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+00F2 (o grave) + {0x1E, 0x33, 0x00, 0x33, 0x33, 0x33, 0x7E, 0x00},// U+00FB (u circumflex) + {0x00, 0x07, 0x00, 0x33, 0x33, 0x33, 0x7E, 0x00},// U+00F9 (u grave) + {0x00, 0x33, 0x00, 0x33, 0x33, 0x3E, 0x30, 0x1F},// U+00FF (y umlaut) + {0xC3, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x00},// U+00D6 (O umlaut) + {0x33, 0x00, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x00},// U+00DC (U umlaut) + {0x18, 0x18, 0x7E, 0x03, 0x03, 0x7E, 0x18, 0x18},// U+00A2 (dollarcents) + {0x1C, 0x36, 0x26, 0x0F, 0x06, 0x67, 0x3F, 0x00},// U+00A3 (pound sterling) + {0x33, 0x33, 0x1E, 0x3F, 0x0C, 0x3F, 0x0C, 0x0C},// U+00A5 (yen) + {0x7C, 0xC6, 0x1C, 0x36, 0x36, 0x1C, 0x33, 0x1E},// U+00A7 (paragraph) + {0x70, 0xD8, 0x18, 0x3C, 0x18, 0x18, 0x1B, 0x0E},// U+0192 (dutch florijn) + {0x38, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x7E, 0x00},// U+00E1 (a aigu) + {0x1C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00},// U+00ED (i augu) + {0x00, 0x38, 0x00, 0x1E, 0x33, 0x33, 0x1E, 0x00},// U+00F3 (o aigu) + {0x00, 0x38, 0x00, 0x33, 0x33, 0x33, 0x7E, 0x00},// U+00FA (u aigu) + {0x00, 0x1F, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x00},// U+00F1 (n ~) + {0x3F, 0x00, 0x33, 0x37, 0x3F, 0x3B, 0x33, 0x00},// U+00D1 (N ~) + {0x3C, 0x36, 0x36, 0x7C, 0x00, 0x00, 0x00, 0x00},// U+00AA (superscript a) + {0x1C, 0x36, 0x36, 0x1C, 0x00, 0x00, 0x00, 0x00},// U+00BA (superscript 0) + {0x0C, 0x00, 0x0C, 0x06, 0x03, 0x33, 0x1E, 0x00},// U+00BF (inverted ?) + {0x00, 0x00, 0x00, 0x3F, 0x03, 0x03, 0x00, 0x00},// U+2310 (gun pointing right) + {0x00, 0x00, 0x00, 0x3F, 0x30, 0x30, 0x00, 0x00},// U+00AC (gun pointing left) + {0xC3, 0x63, 0x33, 0x7B, 0xCC, 0x66, 0x33, 0xF0},// U+00BD (1/2) + {0xC3, 0x63, 0x33, 0xBD, 0xEC, 0xF6, 0xF3, 0x03},// U+00BC (1/4) + {0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00},// U+00A1 (inverted !) + {0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00},// U+00AB (<<) + {0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00},// U+00BB (>>) + {0x55, 0x00, 0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00},// U+2591 (25% solid) + {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA},// U+2592 (50% solid) + {0xFF, 0xAA, 0xFF, 0x55, 0xFF, 0xAA, 0xFF, 0x55},// U+2593 (75% solid) + {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},// U+2502 (thin vertical) + {0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08},// U+2524 (down L, left L, up L) + {0x08, 0x08, 0x08, 0x0F, 0x08, 0x0F, 0x08, 0x08},// U+2561 (up L, down L, left D) + {0x14, 0x14, 0x14, 0x14, 0x17, 0x14, 0x14, 0x14},// U+2562 (up D, down D, left L) + {0x00, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x14, 0x14},// U+2556 (down D, left L) + {0x00, 0x00, 0x00, 0x0F, 0x08, 0x0F, 0x08, 0x08},// U+2555 (down L, left D) + {0x14, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14},// U+2563 (up D, down D, left D) + {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14},// U+2551 (double vertical) + {0x00, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x14, 0x14},// U+2557 (down D, left D) + {0x14, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x00, 0x00},// U+255D (up D, left D) + {0x14, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x00, 0x00},// U+255C (up D, left L) + {0x08, 0x08, 0x08, 0x0F, 0x08, 0x0F, 0x00, 0x00},// U+255B (up L, left D) + {0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x08, 0x08},// U+2510 (down L, left L) + {0x08, 0x08, 0x08, 0x08, 0xf8, 0x00, 0x00, 0x00},// U+2514 (up L, right L) + {0x08, 0x08, 0x08, 0x08, 0xff, 0x00, 0x00, 0x00},// U+2534 (up L, right L, left L) + {0x00, 0x00, 0x00, 0x00, 0xff, 0x08, 0x08, 0x08},// U+252C (down L, right L, left L) + {0x08, 0x08, 0x08, 0x08, 0xf8, 0x08, 0x08, 0x08},// U+251C (down L, right L, up L) + {0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00},// U+2500 (thin horizontal) + {0x08, 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08},// U+253C (up L, right L, left L, down L) + {0x08, 0x08, 0x08, 0xF8, 0x08, 0xF8, 0x08, 0x08},// U+255E (up L, down L, right D) + {0x14, 0x14, 0x14, 0x14, 0xF4, 0x14, 0x14, 0x14},// U+255F (up D, down D, right L) + {0x14, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x00, 0x00},// U+255A (up D, right D) + {0x00, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14},// U+2554 (down D, right D) + {0x14, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00},// U+2569 (left D, right D, up D) + {0x00, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14},// U+2566 (left D, right D, down D) + {0x14, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x14, 0x14},// U+2560 (up D, down D, right D) + {0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00},// U+2550 (double horizontal) + {0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14},// U+256C (left D, right D, down D, up D) + {0x08, 0x08, 0x08, 0xFF, 0x00, 0xFF, 0x00, 0x00},// U+2567 (left D, right D, up L) + {0x14, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x00, 0x00},// U+2568 (left L, right L, up D) + {0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x08, 0x08},// U+2564 (left D, right D, down L) + {0x00, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x14, 0x14},// U+2565 (left L, right L, down D) + {0x14, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x00, 0x00},// U+2559 (up D, right L) + {0x08, 0x08, 0x08, 0xF8, 0x08, 0xF8, 0x00, 0x00},// U+2558 (up L, right D) + {0x00, 0x00, 0x00, 0xF8, 0x08, 0xF8, 0x08, 0x08},// U+2552 (down L, right D) + {0x00, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x14, 0x14},// U+2553 (down D, right L) + {0x14, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x14, 0x14},// U+256B (left L, right L, down D, up D) + {0x08, 0x08, 0x08, 0xFF, 0x08, 0xFF, 0x08, 0x08},// U+256A (left D, right D, down L, up L) + {0x08, 0x08, 0x08, 0x08, 0x0f, 0x00, 0x00, 0x00},// U+2518 (up L, left L) + {0x00, 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08},// U+250C (down L, right L) + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},// U+2588 (solid) + {0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF},// U+2584 (bottom half) + {0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F},// U+258C (left half) + {0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0},// U+2590 (right half) + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00},// U+2580 (top half) }; - return (unsigned long long int *) f[c]; + return f[c]; } void printc_location (point_t point, char c) { - unsigned char const * bitmap = (unsigned char const *) font (c); + unsigned char const * bitmap = font (c); for (int i = 0; i < FONT_SIZE; i++) { for (int j = 0; j < FONT_SIZE; j++) { bool is_on = bitmap[i] & (1 << j); @@ -152,6 +248,12 @@ void printc_location (point_t point, char c) { } } } +void prints_location (point_t point, char const * s) { + while (*s) { + printc_location (point, *s++); + point.x += FONT_REAL_WIDTH; + } +} void printc (char c) { // Handle special characters, print otherwise From 08b595db8357456f90df4dd9bd800f1a1159f364 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 12:30:30 +0100 Subject: [PATCH 54/61] =?UTF-8?q?feat(temperature):=20remove=20=C2=B0=20(n?= =?UTF-8?q?ot=20working)=20and=20print=20a=20graph=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thorn/include/common/font.h | 2 +- thorn/include/common/temperature.h | 4 ++++ thorn/src/common/font.c | 23 +++++++++++++++++++++- thorn/src/common/temperature.c | 31 +++++++++++++++++++++--------- thorn/src/kernel/kernel.c | 2 +- thorn/src/kernel/mini_uart.c | 4 ++-- 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/thorn/include/common/font.h b/thorn/include/common/font.h index e28b335..b11ad30 100644 --- a/thorn/include/common/font.h +++ b/thorn/include/common/font.h @@ -2,7 +2,7 @@ #define _ROSE_C_FONT_H #define FONT_SIZE 8 -#define FONT_FACTOR 4 +#define FONT_FACTOR 3 #define FONT_REAL_WIDTH (FONT_SIZE * FONT_FACTOR) // Spacing between lines in pixels diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index d5b36e0..2f5f17f 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -1,6 +1,8 @@ #ifndef _ROSE_C_TEMPERATURE_H #define _ROSE_C_TEMPERATURE_H +#include "common/font.h" +#include "common/screen.h" #include "common/stdbool.h" #include "kernel/fork.h" #include "kernel/gpio.h" @@ -34,4 +36,6 @@ int get_temperature (void); void set_fan (bool enable); +void draw_temp_graph (void); + #endif//_ROSE_C_TEMPERATURE_H \ No newline at end of file diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c index 532bec5..74f4ca7 100644 --- a/thorn/src/common/font.c +++ b/thorn/src/common/font.c @@ -227,7 +227,28 @@ unsigned char const * font (unsigned char c) { {0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F},// U+258C (left half) {0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0},// U+2590 (right half) {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00},// U+2580 (top half) - }; + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x1C, 0x36, 0x36, 0x1C, 0x00, 0x00, 0x00, 0x00},// U+00BA (degree) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; return f[c]; } diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index ebb1b0c..3a7de93 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -30,24 +30,21 @@ bool init_temperature () { } void regulate_temperature () { - static int fan = 1; static int previous = TEMPERATURE_SHOULD; while (1) { + delay (TEMPERATURE_CHECK_DELAY); int current = get_temperature (); - printf ("\rCurrent temperature: %d °C. Change since last iteration: %d °mC ", current / 1000, - (current - previous)); + printf ("\rCurrent temperature: %d C. Change since last iteration: %d mC ", current / 1000, + ((current - previous) + 50) / 500 * 500); if (current >= TEMPERATURE_SHOULD) { - fan = 1; + set_fan (1); } else if (current < TEMPERATURE_SHOULD - 2000) { - fan = 0; + set_fan (0); } - - set_fan (fan); - previous = current; - delay (TEMPERATURE_CHECK_DELAY); + draw_temp_graph (); } } @@ -81,4 +78,20 @@ int get_temperature () { void set_fan (bool enable) { gpio_set (GPIO_FAN, !enable); +} + +void draw_temp_graph () { + // Clear lower half of screen + memzero (get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2); + + // Corners of graph + point_t OO = {0, get_fb_info ()->virtual_height / 2}; + point_t OY = {0, get_fb_info ()->virtual_height - 1}; + point_t XO = {get_fb_info ()->virtual_width - 1, get_fb_info ()->virtual_height / 2}; + point_t XY = {get_fb_info ()->virtual_width - 1, get_fb_info ()->virtual_height - 1}; + + // Draw frame + legend + drawrec (OO, XY, (color_t) {0xFF, 0xFF, 0x00, 0}); + prints_location (OO, "55C"); + prints_location ((point_t) {OY.x, OY.y - FONT_REAL_WIDTH}, "45C"); } \ No newline at end of file diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index 63b6cf1..aa9d139 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -93,7 +93,7 @@ void kernel_init (void) { } } // Temperature - printf ("Initialising temperature %s. Max temperature set to %d °C.\r\n", + printf ("Initialising temperature %s. Max temperature set to %d C.\r\n", init_temperature () ? "succeeded" : "failed", get_max_temperature () / 1000); LOG ("Initialisation done"); ERROR ("I'm important!"); diff --git a/thorn/src/kernel/mini_uart.c b/thorn/src/kernel/mini_uart.c index 8f6c2bf..44c3174 100644 --- a/thorn/src/kernel/mini_uart.c +++ b/thorn/src/kernel/mini_uart.c @@ -29,7 +29,7 @@ void mini_uart_init (void) { static volatile bool init_done = false; if (init_progress) { - while (! init_done) + while (!init_done) ; return; } @@ -71,7 +71,7 @@ void handle_mini_uart_irq (void) { case 19: toggle_blank_screen (); default: - mini_uart_send (c_event); + printf ("%c", c_event); } } From e38145fcc3253cb919421b177ee1a0b3a0176010 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 14:51:47 +0100 Subject: [PATCH 55/61] feat(temperature): graph development of temperature --- thorn/include/common/screen.h | 1 + thorn/include/common/temperature.h | 7 ++++++- thorn/src/common/font.c | 6 +++--- thorn/src/common/screen.c | 8 ++++++++ thorn/src/common/temperature.c | 33 ++++++++++++++++++++++-------- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/thorn/include/common/screen.h b/thorn/include/common/screen.h index 8020bde..4e6a2c5 100644 --- a/thorn/include/common/screen.h +++ b/thorn/include/common/screen.h @@ -3,6 +3,7 @@ #include "common/geometry.h" #include "common/gpu.h" +#include "common/logging.h" #include "common/math.h" #include "common/printf.h" diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 2f5f17f..8547b77 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -16,10 +16,15 @@ #define TEMPERATURE_SHOULD (50 * 1000) #define TEMPERATURE_MAX (80 * 1000) -#define TEMPERATURE_CHECK_DELAY 20000000 +#define TEMPERATURE_CHECK_DELAY 10000000 + +#define TEMPERATURE_POINTS 100 static volatile unsigned int __attribute__ ((aligned (16))) temperature_request[8]; +static unsigned int temperatures[TEMPERATURE_POINTS] = {0}; +static unsigned int current_temperature_index = 0; + // Max temperature in degree milliCelsius. // USB + Ethernet are designed up to 70 °C but unlikely to overheat. // CPU is designed up to 85 °C so 80 is probably a reasonable upper limit. diff --git a/thorn/src/common/font.c b/thorn/src/common/font.c index 74f4ca7..fe134ea 100644 --- a/thorn/src/common/font.c +++ b/thorn/src/common/font.c @@ -300,11 +300,11 @@ void printc (char c) { cursor.y += FONT_REAL_HEIGHT; } // If next line would overflow screen height (ignoring line spacing) move to beginning of screen - if (cursor.y + FONT_REAL_WIDTH - FONT_SPACING >= get_max_height ()) { + if (cursor.y + FONT_REAL_WIDTH - FONT_SPACING > get_max_height () / 2) { #ifdef FONT_SCROLLBACK cursor.y -= FONT_SB_LINES * FONT_REAL_HEIGHT; - unsigned int remove_size = FONT_SB_LINES * FONT_REAL_HEIGHT * get_fb_info ()->pitch; - unsigned int scroll_size = get_fb_info ()->fb_size - remove_size; + unsigned int remove_size = FONT_SB_LINES * FONT_REAL_HEIGHT * get_fb_info ()->pitch - FONT_SPACING; + unsigned int scroll_size = get_fb_info ()->fb_size / 2 - remove_size; memcpy ((ptr_t) get_fb (), (ptr_t) get_fb () + remove_size, scroll_size); memzero ((ptr_t) get_fb () + scroll_size, remove_size); #else diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index 801e7c8..dd4670e 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -8,6 +8,14 @@ void drawpx (point_t p, color_t color) { // Bresenham's line algorithm void drawline (point_t p0, point_t p1, color_t color) { + if (p0.x > get_max_width () + || p0.y > get_max_height () + || p1.x > get_max_width () + || p1.y > get_max_height ()) { + ERROR ("Couldn't draw line"); + printf ("Offending points: {%u, %u} - {%u, %u}\r\n", p0.x, p0.y, p1.x, p1.y); + return; + } if (p1.y == p0.y) { if (p0.x < p1.x) diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 3a7de93..2af84ac 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -30,19 +30,19 @@ bool init_temperature () { } void regulate_temperature () { - static int previous = TEMPERATURE_SHOULD; while (1) { delay (TEMPERATURE_CHECK_DELAY); - int current = get_temperature (); + unsigned int previous = temperatures[(current_temperature_index++) % TEMPERATURE_POINTS]; + temperatures[current_temperature_index] = get_temperature (); + unsigned int current = temperatures[current_temperature_index]; printf ("\rCurrent temperature: %d C. Change since last iteration: %d mC ", current / 1000, - ((current - previous) + 50) / 500 * 500); + (current - previous + 5050) / 100 * 100 - 5000); if (current >= TEMPERATURE_SHOULD) { set_fan (1); } else if (current < TEMPERATURE_SHOULD - 2000) { set_fan (0); } - previous = current; draw_temp_graph (); } @@ -82,16 +82,31 @@ void set_fan (bool enable) { void draw_temp_graph () { // Clear lower half of screen - memzero (get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2); + memzero ((unsigned long) get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2); // Corners of graph - point_t OO = {0, get_fb_info ()->virtual_height / 2}; - point_t OY = {0, get_fb_info ()->virtual_height - 1}; - point_t XO = {get_fb_info ()->virtual_width - 1, get_fb_info ()->virtual_height / 2}; - point_t XY = {get_fb_info ()->virtual_width - 1, get_fb_info ()->virtual_height - 1}; + point_t OO = {0, get_max_height () / 2}; + point_t OY = {0, get_max_height ()}; + point_t XO = {get_max_width (), get_max_height () / 2}; + point_t XY = {get_max_width (), get_max_height ()}; // Draw frame + legend drawrec (OO, XY, (color_t) {0xFF, 0xFF, 0x00, 0}); + drawline_grid ((point_t) {0, get_max_height () / 8 * 6}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 255, 0}); + drawline_grid ((point_t) {0, get_max_height () / 8 * 7}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 0, 0}); prints_location (OO, "55C"); prints_location ((point_t) {OY.x, OY.y - FONT_REAL_WIDTH}, "45C"); + + // Draw lines between data points + int factor_x = get_fb_info ()->virtual_width / TEMPERATURE_POINTS; + int divisor_y = 10000 / (get_fb_info ()->virtual_height / 2); + for (int j = 0; j < TEMPERATURE_POINTS - 1; j++) { + unsigned int i0 = (current_temperature_index + j + 1) % TEMPERATURE_POINTS; + unsigned int i1 = (i0 + 1) % TEMPERATURE_POINTS; + if (!temperatures[i0] || !temperatures[i1]) + continue; + point_t a = {j * factor_x, OO.y + (temperatures[i0] - 45000) / divisor_y}; + point_t b = {(j + 1) * factor_x, OO.y + (temperatures[i1] - 45000) / divisor_y}; + drawline (a, b, (color_t) {0, 0, 255, 0}); + } } \ No newline at end of file From ec769b1a2d916dafb3691c93f05914d8b88683b1 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 14:53:22 +0100 Subject: [PATCH 56/61] fix(temperature): invert graph --- thorn/src/common/temperature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 2af84ac..5758b49 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -105,8 +105,8 @@ void draw_temp_graph () { unsigned int i1 = (i0 + 1) % TEMPERATURE_POINTS; if (!temperatures[i0] || !temperatures[i1]) continue; - point_t a = {j * factor_x, OO.y + (temperatures[i0] - 45000) / divisor_y}; - point_t b = {(j + 1) * factor_x, OO.y + (temperatures[i1] - 45000) / divisor_y}; + point_t a = {j * factor_x, OY.y - (temperatures[i0] - 45000) / divisor_y}; + point_t b = {(j + 1) * factor_x, OY.y - (temperatures[i1] - 45000) / divisor_y}; drawline (a, b, (color_t) {0, 0, 255, 0}); } } \ No newline at end of file From e7d826836c57898c099f3b1a61937b32c15c4ba0 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 14:57:05 +0100 Subject: [PATCH 57/61] feat(fan): turn-off-fan value adjusted to match graph --- thorn/include/common/temperature.h | 2 +- thorn/src/common/temperature.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 8547b77..5d8d137 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -16,7 +16,7 @@ #define TEMPERATURE_SHOULD (50 * 1000) #define TEMPERATURE_MAX (80 * 1000) -#define TEMPERATURE_CHECK_DELAY 10000000 +#define TEMPERATURE_CHECK_DELAY 5000000 #define TEMPERATURE_POINTS 100 diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 5758b49..26c8e58 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -40,7 +40,7 @@ void regulate_temperature () { if (current >= TEMPERATURE_SHOULD) { set_fan (1); - } else if (current < TEMPERATURE_SHOULD - 2000) { + } else if (current < TEMPERATURE_SHOULD - 2500) { set_fan (0); } From c50fba009cc76d8c6d6dfa1941ea63fc3e3b1a39 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 15:16:44 +0100 Subject: [PATCH 58/61] refactor(temperature): change graph clearing to not clear unused bottom --- thorn/src/common/temperature.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 26c8e58..4faf57d 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -35,8 +35,10 @@ void regulate_temperature () { unsigned int previous = temperatures[(current_temperature_index++) % TEMPERATURE_POINTS]; temperatures[current_temperature_index] = get_temperature (); unsigned int current = temperatures[current_temperature_index]; - printf ("\rCurrent temperature: %d C. Change since last iteration: %d mC ", current / 1000, - (current - previous + 5050) / 100 * 100 - 5000); + + previous = (previous + 50) / 100 * 100; + current = (previous + 50) / 100 * 100; + printf ("\rCurrent temperature: %d,%d C. Change since last iteration: %d mC ", current / 1000, current % 1000 / 100, current - previous); if (current >= TEMPERATURE_SHOULD) { set_fan (1); @@ -82,7 +84,7 @@ void set_fan (bool enable) { void draw_temp_graph () { // Clear lower half of screen - memzero ((unsigned long) get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2); + memzero ((unsigned long) get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2 - get_fb_info ()->pitch * 10); // Corners of graph point_t OO = {0, get_max_height () / 2}; From 41f302654492ef6d74606506f386edcefce50d6d Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 15:41:29 +0100 Subject: [PATCH 59/61] style(temperature): use colors to indicate the status of the fan Also, factor out some constants --- thorn/include/common/temperature.h | 8 +++++-- thorn/src/common/temperature.c | 38 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 5d8d137..524824e 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -13,13 +13,17 @@ // Temperature the system tries to keep. Turns off cooling if it falls below. // NOTE: The pi hits a 'soft' limit at 70 °C, reducing clock frequency. // This value is defined in the config.txt and defaults to 60 °C if not set -#define TEMPERATURE_SHOULD (50 * 1000) -#define TEMPERATURE_MAX (80 * 1000) +#define TEMPERATURE_FAN_OFF 47500 +#define TEMPERATURE_FAN_ON 50000 +#define TEMPERATURE_MAX 80000 #define TEMPERATURE_CHECK_DELAY 5000000 #define TEMPERATURE_POINTS 100 +#define TEMPERATURE_GRAPH_LOW 45000 +#define TEMPERATURE_GRAPH_HIGH 55000 + static volatile unsigned int __attribute__ ((aligned (16))) temperature_request[8]; static unsigned int temperatures[TEMPERATURE_POINTS] = {0}; diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 4faf57d..2780ca3 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -36,16 +36,16 @@ void regulate_temperature () { temperatures[current_temperature_index] = get_temperature (); unsigned int current = temperatures[current_temperature_index]; - previous = (previous + 50) / 100 * 100; - current = (previous + 50) / 100 * 100; - printf ("\rCurrent temperature: %d,%d C. Change since last iteration: %d mC ", current / 1000, current % 1000 / 100, current - previous); - - if (current >= TEMPERATURE_SHOULD) { + if (current >= TEMPERATURE_FAN_ON) { set_fan (1); - } else if (current < TEMPERATURE_SHOULD - 2500) { + } else if (current <= TEMPERATURE_FAN_OFF) { set_fan (0); } + previous = (previous + 50) / 100 * 100; + current = (current + 50) / 100 * 100; + printf ("\rCurrent temperature: %d,%d C. Change since last iteration: %d mC ", current / 1000, current % 1000 / 100, current - previous); + draw_temp_graph (); } } @@ -96,19 +96,29 @@ void draw_temp_graph () { drawrec (OO, XY, (color_t) {0xFF, 0xFF, 0x00, 0}); drawline_grid ((point_t) {0, get_max_height () / 8 * 6}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 255, 0}); drawline_grid ((point_t) {0, get_max_height () / 8 * 7}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 0, 0}); - prints_location (OO, "55C"); - prints_location ((point_t) {OY.x, OY.y - FONT_REAL_WIDTH}, "45C"); + char buf[5] = {0}; + sprintf (buf, "%d C", TEMPERATURE_GRAPH_HIGH / 1000); + prints_location (OO, buf); + sprintf (buf, "%d C", TEMPERATURE_GRAPH_LOW / 1000); + prints_location ((point_t) {OY.x, OY.y - FONT_REAL_WIDTH}, buf); // Draw lines between data points - int factor_x = get_fb_info ()->virtual_width / TEMPERATURE_POINTS; - int divisor_y = 10000 / (get_fb_info ()->virtual_height / 2); - for (int j = 0; j < TEMPERATURE_POINTS - 1; j++) { + color_t const red = {0, 0, 255, 0}; + color_t const blue = {196, 0, 0, 0}; + color_t current = red; + int factor_x = get_fb_info ()->virtual_width / TEMPERATURE_POINTS; + int divisor_y = (TEMPERATURE_GRAPH_HIGH - TEMPERATURE_GRAPH_LOW) / (get_fb_info ()->virtual_height / 2); + for (int j = 0; j < TEMPERATURE_POINTS; j++) { unsigned int i0 = (current_temperature_index + j + 1) % TEMPERATURE_POINTS; unsigned int i1 = (i0 + 1) % TEMPERATURE_POINTS; if (!temperatures[i0] || !temperatures[i1]) continue; - point_t a = {j * factor_x, OY.y - (temperatures[i0] - 45000) / divisor_y}; - point_t b = {(j + 1) * factor_x, OY.y - (temperatures[i1] - 45000) / divisor_y}; - drawline (a, b, (color_t) {0, 0, 255, 0}); + if (temperatures[i0] >= TEMPERATURE_FAN_ON) + current = red; + else if (temperatures[i0] <= TEMPERATURE_FAN_OFF) + current = blue; + point_t a = {j * factor_x, OY.y - (temperatures[i0] - TEMPERATURE_GRAPH_LOW) / divisor_y}; + point_t b = {(j + 1) * factor_x, OY.y - (temperatures[i1] - TEMPERATURE_GRAPH_LOW) / divisor_y}; + drawline (a, b, current); } } \ No newline at end of file From 32898859994737e9443c196d4f1b6a4cce2d9a97 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 11 Nov 2021 11:23:07 +0100 Subject: [PATCH 60/61] feat(screen): add fillrec, a function filling rectangles with color --- thorn/include/common/screen.h | 1 + thorn/src/common/screen.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/thorn/include/common/screen.h b/thorn/include/common/screen.h index 4e6a2c5..347e1e4 100644 --- a/thorn/include/common/screen.h +++ b/thorn/include/common/screen.h @@ -19,6 +19,7 @@ void drawline_grid (point_t p0, point_t p1, color_t color); void drawrec (point_t p0, point_t p1, color_t color); void drawcircle (point_t p, int radius, color_t color); void draw_all_octant_points (point_t p, point_t offset, color_t color); +void fillrec (point_t pp0, point_t p1, color_t color); void test_drawing (); diff --git a/thorn/src/common/screen.c b/thorn/src/common/screen.c index dd4670e..3e3d738 100644 --- a/thorn/src/common/screen.c +++ b/thorn/src/common/screen.c @@ -155,6 +155,16 @@ short get_max_height () { return get_fb_info ()->virtual_height - 1; } +void fillrec (point_t p0, point_t p1, color_t color) { + unsigned int startx = p0.x > p1.x ? p1.x : p0.x; + unsigned int starty = p0.y > p1.y ? p1.y : p0.y; + unsigned int endx = p0.x < p1.x ? p1.x : p0.x; + unsigned int endy = p0.y < p1.y ? p1.y : p0.y; + for (unsigned int i = starty; i <= endy; i++) { + drawline_grid ((point_t) {startx, i}, (point_t) {endx, i}, color); + } +} + void test_drawing () { color_t white_color = {0xff, 0xff, 0xff, 0xff}; color_t blue_color = {0xff, 0x00, 0x00, 0xff}; @@ -240,4 +250,12 @@ void test_drawing () { drawcircle (POINT (1128, 428), 50, red_color); + + fillrec (POINT (800, 800), + POINT (900, 900), + blue_color); + + fillrec (POINT (800, 800), + POINT (850, 850), + red_color); } From c7a8b98a2292eaeeab92dfc88db5841f987bec6f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 11 Nov 2021 12:53:39 +0100 Subject: [PATCH 61/61] refactor(temperature): make graph less stroboscopic --- thorn/include/common/temperature.h | 4 ++-- thorn/include/kernel/irq.h | 2 +- thorn/include/kernel/timer.h | 6 ++++++ thorn/src/common/temperature.c | 29 +++++++++++++++++++---------- thorn/src/kernel/entry.S | 1 + thorn/src/kernel/irq.c | 4 ++-- thorn/src/kernel/kernel.c | 2 ++ thorn/src/kernel/timer.c | 6 +----- 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/thorn/include/common/temperature.h b/thorn/include/common/temperature.h index 524824e..6528640 100644 --- a/thorn/include/common/temperature.h +++ b/thorn/include/common/temperature.h @@ -17,9 +17,9 @@ #define TEMPERATURE_FAN_ON 50000 #define TEMPERATURE_MAX 80000 -#define TEMPERATURE_CHECK_DELAY 5000000 +#define TEMPERATURE_CHECK_DELAY 2000 -#define TEMPERATURE_POINTS 100 +#define TEMPERATURE_POINTS 200 #define TEMPERATURE_GRAPH_LOW 45000 #define TEMPERATURE_GRAPH_HIGH 55000 diff --git a/thorn/include/kernel/irq.h b/thorn/include/kernel/irq.h index d95cc0b..7997206 100644 --- a/thorn/include/kernel/irq.h +++ b/thorn/include/kernel/irq.h @@ -13,7 +13,7 @@ void enable_interrupt_controller (void); -void show_invalid_entry_message (int type, ptr_t esr, ptr_t address); +void show_invalid_entry_message (int type, ptr_t esr, ptr_t address, ptr_t far); void irq_vector_init (void); diff --git a/thorn/include/kernel/timer.h b/thorn/include/kernel/timer.h index f5cd0b8..bfc59ce 100644 --- a/thorn/include/kernel/timer.h +++ b/thorn/include/kernel/timer.h @@ -1,6 +1,12 @@ #ifndef _ROSE_K_TIMER_H #define _ROSE_K_TIMER_H +#include "common/printf.h" +#include "common/status_led.h" +#include "common/utils.h" +#include "kernel/peripherals/timer.h" +#include "kernel/sched.h" + void timer_init (void); void handle_timer_irq (void); diff --git a/thorn/src/common/temperature.c b/thorn/src/common/temperature.c index 2780ca3..09f9343 100644 --- a/thorn/src/common/temperature.c +++ b/thorn/src/common/temperature.c @@ -32,7 +32,8 @@ bool init_temperature () { void regulate_temperature () { while (1) { delay (TEMPERATURE_CHECK_DELAY); - unsigned int previous = temperatures[(current_temperature_index++) % TEMPERATURE_POINTS]; + unsigned int previous = temperatures[current_temperature_index]; + current_temperature_index = (current_temperature_index + 1) % TEMPERATURE_POINTS; temperatures[current_temperature_index] = get_temperature (); unsigned int current = temperatures[current_temperature_index]; @@ -83,31 +84,39 @@ void set_fan (bool enable) { } void draw_temp_graph () { - // Clear lower half of screen - memzero ((unsigned long) get_fb () + get_fb_info ()->fb_size / 2, get_fb_info ()->fb_size / 2 - get_fb_info ()->pitch * 10); - // Corners of graph point_t OO = {0, get_max_height () / 2}; point_t OY = {0, get_max_height ()}; point_t XO = {get_max_width (), get_max_height () / 2}; point_t XY = {get_max_width (), get_max_height ()}; - // Draw frame + legend - drawrec (OO, XY, (color_t) {0xFF, 0xFF, 0x00, 0}); - drawline_grid ((point_t) {0, get_max_height () / 8 * 6}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 255, 0}); - drawline_grid ((point_t) {0, get_max_height () / 8 * 7}, (point_t) {get_max_width (), get_max_height () / 4 * 3}, (color_t) {0, 128, 0, 0}); + // Clear lower half of screen + unsigned int pitch = get_fb_info ()->pitch; + unsigned int size = get_fb_info ()->fb_size; + unsigned long fb = (unsigned long) get_fb (); + memzero (fb + size / 8 * 4 - 7 * pitch, size / 4 - 5 * pitch); + memzero (fb + size / 8 * 6 - 11 * pitch, size / 8 - 3 * pitch); + memzero (fb + size / 8 * 7 - 13 * pitch, size / 8 - 22 * pitch); + + // Draw frame, legend and orientation lines + drawline_grid ((point_t) {0, get_max_height () / 8 * 6}, (point_t) {get_max_width (), get_max_height () / 8 * 6}, (color_t) {0, 128, 255, 0}); + drawline_grid ((point_t) {0, get_max_height () / 8 * 7}, (point_t) {get_max_width (), get_max_height () / 8 * 7}, (color_t) {0, 128, 0, 0}); + + drawline_grid ((point_t) {0, get_max_height () / 8 * 4}, (point_t) {get_max_width (), get_max_height () / 8 * 4}, (color_t) {255, 128, 0, 0}); + drawline_grid ((point_t) {4 * FONT_REAL_WIDTH, get_max_height () / 8 * 8}, (point_t) {get_max_width (), get_max_height () / 8 * 8}, (color_t) {255, 128, 0, 0}); + char buf[5] = {0}; sprintf (buf, "%d C", TEMPERATURE_GRAPH_HIGH / 1000); - prints_location (OO, buf); + prints_location (POINT (OO.x, OO.y - FONT_REAL_WIDTH - 3), buf); sprintf (buf, "%d C", TEMPERATURE_GRAPH_LOW / 1000); prints_location ((point_t) {OY.x, OY.y - FONT_REAL_WIDTH}, buf); // Draw lines between data points color_t const red = {0, 0, 255, 0}; color_t const blue = {196, 0, 0, 0}; - color_t current = red; int factor_x = get_fb_info ()->virtual_width / TEMPERATURE_POINTS; int divisor_y = (TEMPERATURE_GRAPH_HIGH - TEMPERATURE_GRAPH_LOW) / (get_fb_info ()->virtual_height / 2); + color_t current = red; for (int j = 0; j < TEMPERATURE_POINTS; j++) { unsigned int i0 = (current_temperature_index + j + 1) % TEMPERATURE_POINTS; unsigned int i1 = (i0 + 1) % TEMPERATURE_POINTS; diff --git a/thorn/src/kernel/entry.S b/thorn/src/kernel/entry.S index 4f44a25..4fe363a 100644 --- a/thorn/src/kernel/entry.S +++ b/thorn/src/kernel/entry.S @@ -7,6 +7,7 @@ mov x0, #\type mrs x1, esr_el1 mrs x2, elr_el1 + mrs x3, far_el1 bl show_invalid_entry_message b err_hang .endm diff --git a/thorn/src/kernel/irq.c b/thorn/src/kernel/irq.c index b893bda..bab9f1f 100644 --- a/thorn/src/kernel/irq.c +++ b/thorn/src/kernel/irq.c @@ -19,8 +19,8 @@ void assign_target (unsigned int irq, unsigned int cpu) { put32 (targetRegister, get32 (targetRegister) | (1 << 8)); } -void show_invalid_entry_message (int type, ptr_t esr, ptr_t address) { - printf ("Type %s, ESR: %p, address, %p\r\n", entry_error_messages[type], (void *) esr, (void *) address); +void show_invalid_entry_message (int type, ptr_t esr, ptr_t address, ptr_t far) { + printf ("Type %s, ESR: %p, ELR: %p, FAR: %p\r\n", entry_error_messages[type], (void *) esr, (void *) address, (void *) far); } void enable_interrupt_controller () { diff --git a/thorn/src/kernel/kernel.c b/thorn/src/kernel/kernel.c index aa9d139..c5af6ec 100644 --- a/thorn/src/kernel/kernel.c +++ b/thorn/src/kernel/kernel.c @@ -127,6 +127,8 @@ void kernel_main (int processor_id) { case 1: while (get_fb ()) { // Do screen work here + // test_drawing (); + // break; } case 2: case 3: diff --git a/thorn/src/kernel/timer.c b/thorn/src/kernel/timer.c index 0fe4556..94950df 100644 --- a/thorn/src/kernel/timer.c +++ b/thorn/src/kernel/timer.c @@ -1,8 +1,4 @@ -#include "kernel/peripherals/timer.h" -#include "common/printf.h" -#include "common/status_led.h" -#include "common/utils.h" -#include "kernel/sched.h" +#include "kernel/timer.h" const unsigned int interval = 200000; unsigned int curVal = 0;