···11#include <stdint.h>
22#ifndef CHAR_BMPS_H
33#define CHAR_BMPS_H
44-/* From https://github.com/dhepper/font8x8/blob/master/font8x8_block.h */
44+55+/**
66+ * @file chars_pixels.h
77+ * @brief Contains the font bitmap for the 8x8 font
88+ */
99+1010+/**
1111+ * @brief Get the font bitmap for a character
1212+ *
1313+ * @param c The character to get the bitmap for
1414+ * @return The bitmap for the character (as const uint8_t*).
1515+ *
1616+ * The following description is directly taken from where the front is:
1717+ * https://github.com/dhepper/font8x8/blob/master/font8x8_block.h
1818+ *
1919+ * Every character in the font is encoded row-wise in 8 bytes.
2020+ *
2121+ * The least significant bit of each byte corresponds to the first pixel in a
2222+ * row.
2323+ *
2424+ * The character 'A' (0x41 / 65) is encoded as
2525+ * <code>{ 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}</code>
2626+ *
2727+ * <code>
2828+ 0x0C => 0000 1100 => ..XX.... <br>
2929+ 0X1E => 0001 1110 => .XXXX... <br>
3030+ 0x33 => 0011 0011 => XX..XX.. <br>
3131+ 0x33 => 0011 0011 => XX..XX.. <br>
3232+ 0x3F => 0011 1111 => xxxxxx.. <br>
3333+ 0x33 => 0011 0011 => XX..XX.. <br>
3434+ 0x33 => 0011 0011 => XX..XX.. <br>
3535+ 0x00 => 0000 0000 => ........ <br>
3636+ </code>
3737+ *
3838+ * To access the nth pixel in a row, right-shift by n.
3939+ * \verbatim
4040+ . . X X . . . .
4141+ | | | | | | | |
4242+ (0x0C >> 0) & 1 == 0-+ | | | | | | |
4343+ (0x0C >> 1) & 1 == 0---+ | | | | | |
4444+ (0x0C >> 2) & 1 == 1-----+ | | | | |
4545+ (0x0C >> 3) & 1 == 1-------+ | | | |
4646+ (0x0C >> 4) & 1 == 0---------+ | | |
4747+ (0x0C >> 5) & 1 == 0-----------+ | |
4848+ (0x0C >> 6) & 1 == 0-------------+ |
4949+ (0x0C >> 7) & 1 == 0---------------+
5050+ \endverbatim
5151+ */
5252+553const uint8_t *font(int c)
654{
755 static const char f[128][8] = {
+97-15
os/include/kernel/mailbox.h
···33#ifndef MAILBOX_H
44#define MAILBOX_H
5566+/**
77+ * @file mailbox.h
88+ * @brief Mailbox interface
99+ *
1010+ * The mailbox is a way to communicate with the GPU. It is a FIFO queue of
1111+ * messages. The GPU can send messages to the CPU, and the CPU can send
1212+ * messages to the GPU. The CPU can also send messages to itself.
1313+ *
1414+ */
1515+616#define MAILBOX_OFFSET 0xB880
717818#define MAILBOX_BASE MMIO_BASE + MAILBOX_OFFSET
919#define MAIL0_READ (((mail_message_t *)(0x00 + MAILBOX_BASE)))
1020#define MAIL0_STATUS (((mail_status_t *)(0x18 + MAILBOX_BASE)))
1121#define MAIL0_WRITE (((mail_message_t *)(0x20 + MAILBOX_BASE)))
2222+1223#define PROPERTY_CHANNEL 8
1324#define FRAMEBUFFER_CHANNEL 1
14252626+/**
2727+ * @brief A message that can be sent to the mailbox
2828+ *
2929+ * The mailbox has 16 channels, and each channel has a 32 bit buffer
3030+ * associated with it. The buffer is used to store the data for the message
3131+ * that is being sent.
3232+ *
3333+ * A message is 32 bits, with the first 4 bits being the channel, and the
3434+ * remaining 28 bits being the data to be sent. The channel is used to route
3535+ * the message to the correct buffer, and the data is the actual data that is
3636+ * being sent. The data is not interpreted by the mailbox or the GPU, it is
3737+ * just passed through. The data is interpreted by the driver that is recieving
3838+ * the message. The driver will know what to do with the data, and will know
3939+ * how to interpret it.
4040+ */
1541typedef struct
1642{
1743 uint8_t channel : 4;
1844 uint32_t data : 28;
1945} mail_message_t;
20464747+/**
4848+ * @brief The status of the mailbox
4949+ *
5050+ * The mailbox has a status register that can be used to check if there is
5151+ * mail to read, or if there is space to write mail to. The status register
5252+ * is 32 bits, with the first 30 bits being reserved, and the last 2 bits
5353+ * being the full and empty flags.
5454+ *
5555+ * The full and empty flags are mutually exclusive, so if the full flag is
5656+ * set, then the empty flag will not be set, and vice versa.
5757+ *
5858+ * The reserved bits are reserved for future use, and should be set to 0. If
5959+ * they are not set to 0, then the behavior is undefined.
6060+ *
6161+ * What goes into the reserved bits is not specified, so it is not possible
6262+ * to check if the mailbox is empty or full by checking if the reserved bits
6363+ * are 0 or not. The empty and full flags must be used instead.
6464+ */
2165typedef struct
2266{
2367 uint32_t reserved : 30;
···2973void mailbox_send(mail_message_t msg, int channel);
30743175/**
7676+ * @brief A tag that can be sent to the mailbox
7777+ *
3278 * A property message can either be a request, or a response, and a response
3333- * can be successfull or an error
7979+ * can be successfull or an error.
3480 */
3581typedef enum
3682{
···3985 RESPONSE_ERROR = 0x80000001
4086} buffer_req_res_code_t;
41874242-/*
4343- * A buffer that holds many property messages.
8888+/**
8989+ * @brief A buffer that holds many property messages
9090+ *
4491 * The last tag must be a 4 byte zero, and then padding to make the whole thing
4545- * 4 byte aligned
9292+ * 4 byte aligned. The size field is the size of the whole buffer, including
9393+ * the size field itself.
4694 */
4795typedef struct
4896{
4949- uint32_t size; // Size includes the size itself
9797+ uint32_t size; /**< Size includes the size itself */
5098 buffer_req_res_code_t req_res_code;
5151- uint32_t tags[1]; // A concatenated sequence of tags. will use overrun to
5252- // make large enough
9999+ uint32_t tags[1]; /**< The tags start here. Will use overrun to make large
100100+ enough */
53101} property_message_buffer_t;
5410255103/**
5656- * A message is identified by a tag. These are some of the possible tags
104104+ * @brief A tag that can be sent to the mailbox
105105+ *
106106+ * A message is identified by a tag. These are some of the possible tags. The
107107+ * full list can be found in the BCM2835 ARM Peripherals manual, section 6.1
108108+ * (page 102)
109109+ * https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
110110+ *
111111+ * For general information about the mailbox, see the following link:
112112+ * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
57113 */
58114typedef enum
59115{
···74130 * buffer, and the response value buffer
75131 */
76132133133+/**
134134+ * @brief Request value buffer for FB_ALLOCATE_BUFFER
135135+ *
136136+ * The request value buffer for FB_ALLOCATE_BUFFER is just the alignment
137137+ * that the framebuffer should be aligned to. The alignment must be
138138+ * a power of 2 and at least 16 bytes.
139139+ */
77140typedef struct
78141{
79142 void *fb_addr;
80143 uint32_t fb_size;
81144} fb_allocate_res_t;
82145146146+/**
147147+ * @brief Response value buffer for FB_ALLOCATE_BUFFER
148148+ *
149149+ * The response value buffer for FB_ALLOCATE_BUFFER is the address and size
150150+ * of the framebuffer.
151151+ */
83152typedef struct
84153{
85154 uint32_t width;
86155 uint32_t height;
87156} fb_screen_size_t;
881578989-/*
9090- * The value buffer can be any one of these types
158158+/**
159159+ * @brief Union of all possible value buffers
160160+ *
161161+ * Different types of data that can be sent with the tags, depending on the
162162+ * specific tag being used.
91163 */
92164typedef union
93165{
···98170 uint32_t fb_bytes_per_row;
99171} value_buffer_t;
100172101101-/*
102102- * A message_buffer can contain any number of these
173173+/**
174174+ * @brief A message that can be sent to the mailbox.
175175+ *
176176+ * A tag is a property tag, and a value buffer. The value buffer is the data
177177+ * that is sent with the tag.
103178 */
104179typedef struct
105180{
···108183} property_message_tag_t;
109184110185/**
111111- * given an array of tags, will send all of the tags given, and will populate
112112- * that array with the responses. the given array should end with a "null tag"
113113- * with the proptag field set to 0. returns 0 on success
186186+ * @brief Send a message to the mailbox
187187+ *
188188+ * @param tags The tags to send.
189189+ * @return 0 on success, -1 on failure
190190+ *
191191+ *
192192+ * Given an array of tags, will send all of the tags given, and will populate
193193+ * that array with the responses. The last tag must be a 4 byte zero, and then
194194+ * padding to make the whole thing 4 byte aligned. The size field is the size
195195+ * of the whole buffer, including the size field itself.
114196 */
115197int send_messages(property_message_tag_t *tags);
116198
-3
os/src/kernel/mailbox.c
···3838 *MAIL0_WRITE = msg;
3939}
40404141-/**
4242- * returns the max of the size of the request and result buffer for each tag
4343- */
4441static uint32_t get_value_buffer_len(property_message_tag_t *tag)
4542{
4643 switch(tag->proptag)