This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

add more documentation

Ivan Ilak (May 7, 2023, 6:22 PM +0200) 7a438319 0c60b588

+397 -289
+31 -7
os/include/common/stdlib.h
··· 6 6 #include <stddef.h> // defines NULL and size_t 7 7 #include <stdint.h> 8 8 #ifndef STDLIB_H 9 - #define STDLIB_H 9 + #define STDLIB_H /**< STDLIB_H */ 10 10 11 - #define MIN(x, y) ((x < y ? x : y)) 12 - #define MAX(x, y) ((x < y ? y : x)) 11 + #define MIN(x, y) ((x < y ? x : y)) /**< Find minimum of x and y */ 12 + #define MAX(x, y) ((x < y ? y : x)) /**< Find maximum of x and y */ 13 13 14 + /** 15 + * @brief Result of divmod function 16 + * 17 + * The Raspberry Pi 1 does not have the instruction to perform a division. This 18 + * struct is used to return the result of a division and the remainder. 19 + */ 14 20 typedef struct divmod_result 15 21 { 16 - uint32_t div; 17 - uint32_t mod; 18 - } divmod_t; 22 + uint32_t div; /**< Result of the division */ 23 + uint32_t mod; /**< Remainder of the division */ 24 + } divmod_t; /**< Typedef for divmod_result */ 19 25 26 + /** 27 + * @brief Performs a division and returns the result and the remainder 28 + * 29 + * @param dividend The dividend 30 + * @param divisor The divisor 31 + * @return divmod_t The result of the division and the remainder 32 + */ 20 33 divmod_t divmod(uint32_t dividend, uint32_t divisor); 34 + 35 + /** 36 + * @brief Performs a division and returns the result 37 + * 38 + * @param dividend The dividend 39 + * @param divisor The divisor 40 + * @return uint32_t The result of the division. 41 + */ 21 42 uint32_t div(uint32_t dividend, uint32_t divisor); 22 43 23 44 /** ··· 40 61 * Converts an int (Only base 10 supported for now) 41 62 * to a null-terminated string using the specified base. 42 63 * @param value Value to be converted to a string. 64 + * @param base Numerical base used to represent the value as a string, 65 + * between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, 66 + * and 2 binary. 43 67 * @return A pointer to the resulting null-terminated string. 44 68 */ 45 69 char *itoa(int value, int base); ··· 48 72 * @brief str -> int 49 73 * 50 74 * Converts a string to an int 51 - * @param str This is the string representation of an integral number. 75 + * @param num This is the string representation of an integral number. 52 76 * @return The converted integral number as an int value. 53 77 * If no valid conversion could be performed, it returns zero. 54 78 */
+52 -37
os/include/kernel/atag.h
··· 8 8 #include <stdint.h> 9 9 10 10 #ifndef ATAG_H 11 - #define ATAG_H 11 + #define ATAG_H /**< ATAG_H */ 12 12 13 13 /** 14 14 * @brief Prints the ATAGs 15 + * 16 + * @param address Address of the ATAGs 15 17 */ 16 18 void print_atags(uint32_t address); 17 19 18 - #define ATAG_NONE 0 19 - #define ATAG_CORE 0x54410001 20 - #define ATAG_MEM 0x54410002 21 - #define ATAG_VIDEOTEXT 0x54410003 22 - #define ATAG_RAMDISK 0x54410004 23 - #define ATAG_INITRD2 0x54420005 24 - #define ATAG_SERIAL 0x54410006 25 - #define ATAG_REVISION 0x54410007 26 - #define ATAG_VIDEOLFB 0x54410008 27 - #define ATAG_CMDLINE 0x54410009 20 + /** 21 + * @brief Enumearation of ATAG types 22 + */ 23 + enum ATAG_TYPE 24 + { 25 + ATAG_NONE = 0, /**< Empty tag used to end the list */ 26 + ATAG_CORE = 0x54410001, /**< First tag used to start the list */ 27 + ATAG_MEM = 0x54410002, /**< Describes a physical area of memory */ 28 + ATAG_VIDEOTEXT = 0x54410003, /**< VGA text screen information */ 29 + ATAG_RAMDISK = 0x54410004, /**< Describes how the ramdisk will be used */ 30 + ATAG_INITRD2 = 0x54420005, /**< Describes where the compressed ramdisk 31 + image is placed in memory */ 32 + ATAG_SERIAL = 0x54410006, /**< Board serial number */ 33 + ATAG_REVISION = 0x54410007, /**< Board revision */ 34 + ATAG_VIDEOLFB = 0x54410008, /**< Framebuffer information */ 35 + ATAG_CMDLINE = 0x54410009 /**< Command line */ 36 + }; 28 37 29 38 /** 30 39 * @brief ATAG header structure ··· 95 104 uint32_t size; /**< Size of compressed(?) image */ 96 105 } atag_initrd2; 97 106 98 - /* ATAG_SERIAL has the 64-bit serial number */ 107 + /** 108 + * @brief ATAG_SERIAL structure 109 + * 110 + * This ATAG describes the serial number of the board. 111 + */ 99 112 typedef struct atag_serial 100 113 { 101 - uint32_t low; 102 - uint32_t high; 114 + uint32_t low; /**< Low 32 bits of serial number */ 115 + uint32_t high; /**< High 32 bits of serial number */ 103 116 } atag_serial; 104 117 105 118 /** ··· 109 122 */ 110 123 typedef struct atag_revision 111 124 { 112 - uint32_t revision; 125 + uint32_t revision; /**< Board revision */ 113 126 } atag_revision; 114 127 115 128 /** ··· 119 132 */ 120 133 typedef struct atag_videolfb 121 134 { 122 - uint16_t width; /**< Width of buffer */ 123 - uint16_t height; /**< Height */ 124 - uint16_t depth; /**< Bits/pixel */ 125 - uint16_t linelength; // ? 126 - uint32_t address; /**< Base address of buffer */ 127 - uint32_t size; /**< Size of buffer */ 128 - unsigned char redsize; /**< Number of red bits in each pixel */ 129 - unsigned char redpos; /**< Position of red bits in pixel */ 130 - unsigned char greensize; 131 - unsigned char greenpos; 132 - unsigned char bluesize; 133 - unsigned char bluepos; 135 + uint16_t width; /**< Width of buffer */ 136 + uint16_t height; /**< Height */ 137 + uint16_t depth; /**< Bits/pixel */ 138 + uint16_t linelength; /**< Length of a line in bytes */ 139 + uint32_t address; /**< Base address of buffer */ 140 + uint32_t size; /**< Size of buffer */ 141 + unsigned char redsize; /**< Number of red bits in each pixel */ 142 + unsigned char redpos; /**< Position of red bits in pixel */ 143 + unsigned char greensize; /**< Number of green bits in each pixel */ 144 + unsigned char greenpos; /**< Position of green bits in pixel */ 145 + unsigned char bluesize; /**< Number of blue bits in each pixel */ 146 + unsigned char bluepos; /**< Position of blue bits in pixel */ 134 147 unsigned char reservedsize; /**< Number of reserved bits/pixel */ 135 148 unsigned char reservedpos; /**< Position of reserved bits */ 136 149 } atag_videolfb; ··· 152 165 */ 153 166 typedef struct atag_t 154 167 { 155 - atag_header header; 168 + atag_header header; /**< Standard header */ 156 169 union 157 170 { 158 - atag_core core; 159 - atag_mem mem; 160 - atag_ramdisk ramdisk; 161 - atag_initrd2 initrd2; 162 - atag_serial serial; 163 - atag_revision revision; 164 - atag_videolfb videolfb; 165 - atag_cmdline cmdline; 171 + atag_core core; /**< Core tag */ 172 + atag_mem mem; /**< Memory tag */ 173 + atag_ramdisk ramdisk; /**< Ramdisk tag */ 174 + atag_initrd2 initrd2; /**< Initrd2 tag */ 175 + atag_serial serial; /**< Serial tag */ 176 + atag_revision revision; /**< Revision tag */ 177 + atag_videolfb videolfb; /**< Videolfb tag */ 178 + atag_cmdline cmdline; /**< Cmdline tag */ 166 179 }; 167 - } atag_t; 180 + } atag_t; /**< ATAG structure */ 168 181 169 182 #define tag_next(t) \ 170 183 ((atag_t *)((uint32_t *)(t) + (t)->header.size)) /**< Get next tag */ ··· 173 186 174 187 /** 175 188 * @brief Get the memory size from the ATAGs 189 + * 190 + * @param atags Pointer to the ATAGs 176 191 */ 177 192 uint32_t get_mem_size(atag_t *atags); 178 193
+31 -14
os/include/kernel/framebuffer.h
··· 2 2 #ifndef FRAMEBUFFER_H 3 3 #define FRAMEBUFFER_H 4 4 5 - #define COLORDEPTH 24 6 - #define BYTES_PER_PIXEL COLORDEPTH / 8 5 + /** 6 + * @file framebuffer.h 7 + * @brief Provides functions to initialize the framebuffer and draw pixels. 8 + */ 7 9 10 + #define COLORDEPTH 24 /**< Number of bits per pixel */ 11 + #define BYTES_PER_PIXEL COLORDEPTH / 8 /**< Number of bytes per pixel */ 12 + 13 + /** 14 + * @brief Struct to store information about the framebuffer. 15 + * 16 + * The framebuffer is a memory region that stores the pixels of the screen. The 17 + * GPU writes the pixels to the framebuffer and the pixels are then displayed 18 + * on the screen. 19 + * 20 + * The framebuffer is a contiguous memory region. The pixels are stored in 21 + * raster order, with the first pixel being the top left pixel, and the last 22 + * pixel being the bottom right pixel. 23 + */ 8 24 typedef struct framebuffer_info 9 25 { 10 - uint32_t width; 11 - uint32_t height; 12 - uint32_t pitch; 13 - void *buf; 14 - uint32_t buf_size; 15 - uint32_t chars_width; 16 - uint32_t chars_height; 17 - uint32_t chars_x; 18 - uint32_t chars_y; 19 - } framebuffer_info_t; 26 + uint32_t width; /**< Width of the framebuffer in pixels */ 27 + uint32_t height; /**< Height of the framebuffer in pixels */ 28 + uint32_t pitch; /**< Number of bytes per row */ 29 + void *buf; /**< Pointer to the framebuffer */ 30 + uint32_t buf_size; /**< Size of the framebuffer in bytes */ 31 + uint32_t chars_width; /**< Width of the framebuffer in characters */ 32 + uint32_t chars_height; /**< Height of the framebuffer in characters */ 33 + uint32_t chars_x; /**< X position of the cursor in characters */ 34 + uint32_t chars_y; /**< Y position of the cursor in characters */ 35 + } framebuffer_info_t; /**< Typedef for framebuffer_info */ 20 36 21 - extern framebuffer_info_t fbinfo; 37 + extern framebuffer_info_t 38 + fbinfo; /**< Global variable to store framebuffer information */ 22 39 23 - int framebuffer_init(void); 40 + int framebuffer_init(); /**< Initializes the framebuffer */ 24 41 25 42 #endif // FRAMEBUFFER_H
+42 -7
os/include/kernel/gpu.h
··· 2 2 #ifndef GPU_H 3 3 #define GPU_H 4 4 5 - #define CHAR_WIDTH 8 6 - #define CHAR_HEIGHT 8 5 + /** 6 + * @file gpu.h 7 + * @brief Definition of GPU functions. 8 + */ 9 + 10 + #define CHAR_WIDTH 8 /**< Character width */ 11 + #define CHAR_HEIGHT 8 /**< Character height */ 7 12 13 + /** 14 + * @brief Struct to store information about the GPU. 15 + * 16 + * The GPU is responsible for drawing pixels on the screen. 17 + */ 8 18 typedef struct pixel 9 19 { 10 - uint8_t red; 11 - uint8_t green; 12 - uint8_t blue; 13 - } pixel_t; 20 + uint8_t red; /**< Red component of the pixel */ 21 + uint8_t green; /**< Green component of the pixel */ 22 + uint8_t blue; /**< Blue component of the pixel */ 23 + } pixel_t; /**< Typedef for pixel */ 14 24 15 - void gpu_init(void); 25 + /** 26 + * @brief Initializes the GPU. 27 + * 28 + * - Calls the framebuffer_init() function in a loop until it returns a 29 + * non-zero value. Sometimes this does not work on the first time so we loop 30 + * until it works... 31 + * - framebuffer_init() is a separate function that initializes 32 + * the framebuffer, which is a portion of memory used to store the pixels that 33 + * are displayed on the screen. 34 + * - Once the framebuffer is initialized, we clear the screen by looping 35 + * through all the pixels in the framebuffer and setting their color to black. 36 + * This is done by calling the write_pixel() function. 37 + */ 38 + void gpu_init(); 16 39 40 + /** 41 + * @brief Writes a pixel to the screen. 42 + * 43 + * @param x X coordinate of the pixel 44 + * @param y Y coordinate of the pixel 45 + * @param pixel Pointer to the pixel to write 46 + */ 17 47 void write_pixel(uint32_t x, uint32_t y, const pixel_t *pixel); 18 48 49 + /** 50 + * @brief Writes a character to the screen. 51 + * 52 + * @param c Character to write 53 + */ 19 54 void gpu_putc(char c); 20 55 21 56 #endif
+52 -3
os/include/kernel/kerio.h
··· 1 1 #ifndef STDIO_H 2 2 #define STDIO_H 3 3 4 - char getc(void); 4 + /** 5 + * @file kerio.h 6 + * @brief This file contains the definitions for the standard input/output. 7 + * 8 + * This file contains the definitions for the standard input/output. It is 9 + * based on the C standard library. 10 + */ 11 + 12 + /** 13 + * @brief Reads a character from the standard input. 14 + * 15 + * Note that what exactly standerd input is depends on the implementation. 16 + */ 17 + char getc(); 18 + 19 + /** 20 + * @brief Writes a character to the standard output. 21 + * 22 + * Note that what exactly standerd output is depends on the implementation. In 23 + * particular, during developemnt it has proved usefull to redirect the output 24 + * to UART0. 25 + * 26 + * @param c The character to write. 27 + */ 5 28 void putc(char c); 6 29 30 + /** 31 + * @brief Writes a string to the standard output. 32 + * 33 + * This function calls internally @a putc to write the string, so please 34 + * consider the documentation of that function. 35 + * 36 + * @param s The string to write. 37 + */ 7 38 void puts(const char *s); 8 39 9 - // This version of gets copies until newline, replacing newline with null char, 10 - // or until buflen. whichever comes first 40 + /** 41 + * @brief Reads a string from the standard input. 42 + * 43 + * This function reads a string from the standard input. The string is stored 44 + * in the buffer @a buf. The buffer is guaranteed to be null-terminated. The 45 + * maximum number of characters read is @a buflen - 1. The newline character 46 + * is not stored in the buffer. 47 + * 48 + * @param buf The buffer to store the string in. 49 + * @param buflen The maximum number of characters to read. 50 + */ 11 51 void gets(char *buf, int buflen); 12 52 53 + /** 54 + * @brief Writes a formatted string to the standard output. 55 + * 56 + * This function writes a formatted string to the standard output. The 57 + * formatting is done in the same way as in the C standard library. 58 + * 59 + * @param fmt The format string. 60 + * @param ... The arguments to the format string. 61 + */ 13 62 void printf(const char *fmt, ...); 14 63 15 64 #endif
+79 -44
os/include/kernel/mailbox.h
··· 13 13 * 14 14 */ 15 15 16 - #define MAILBOX_OFFSET 0xB880 16 + #define MAILBOX_OFFSET 0xB880 /**< The offset of the mailbox registers */ 17 17 18 - #define MAILBOX_BASE MMIO_BASE + MAILBOX_OFFSET 19 - #define MAIL0_READ (((mail_message_t *)(0x00 + MAILBOX_BASE))) 20 - #define MAIL0_STATUS (((mail_status_t *)(0x18 + MAILBOX_BASE))) 21 - #define MAIL0_WRITE (((mail_message_t *)(0x20 + MAILBOX_BASE))) 18 + #define MAILBOX_BASE \ 19 + MMIO_BASE \ 20 + +MAILBOX_OFFSET /**< The base address of the mailbox registers */ 21 + #define MAIL0_READ \ 22 + (((mail_message_t *)(0x00 + MAILBOX_BASE))) /**< Read from \ 23 + mailbox 0 */ 24 + #define MAIL0_STATUS \ 25 + (((mail_status_t *)(0x18 + MAILBOX_BASE))) /**< Status of \ 26 + mailbox 0 */ 27 + #define MAIL0_WRITE \ 28 + (((mail_message_t *)(0x20 + MAILBOX_BASE))) /**< Write to \ 29 + mailbox 0 */ 22 30 23 - #define PROPERTY_CHANNEL 8 24 - #define FRAMEBUFFER_CHANNEL 1 31 + #define PROPERTY_CHANNEL 8 /**< Channel 8 is the property channel */ 32 + #define FRAMEBUFFER_CHANNEL 1 /**< Channel 1 is the framebuffer channel */ 25 33 26 34 /** 27 35 * @brief A message that can be sent to the mailbox ··· 40 48 */ 41 49 typedef struct 42 50 { 43 - uint8_t channel : 4; 44 - uint32_t data : 28; 51 + uint8_t channel : 4; /**< The channel to send the message to */ 52 + uint32_t data : 28; /**< The data to send */ 45 53 } mail_message_t; 46 54 47 55 /** ··· 64 72 */ 65 73 typedef struct 66 74 { 67 - uint32_t reserved : 30; 68 - uint8_t empty : 1; 69 - uint8_t full : 1; 70 - } mail_status_t; 75 + uint32_t reserved : 30; /**< Reserved for future use */ 76 + uint8_t empty : 1; /**< The empty flag */ 77 + uint8_t full : 1; /**< The full flag */ 78 + } mail_status_t; /**< The status of the mailbox */ 71 79 80 + /** 81 + * @brief Read from the mailbox 82 + * 83 + * This function will block until there is mail to read from the mailbox. 84 + * 85 + * @param channel The channel to read from 86 + * @return The message that was read from the mailbox 87 + */ 72 88 mail_message_t mailbox_read(int channel); 89 + 90 + /** 91 + * @brief Write to the mailbox 92 + * 93 + * This function will block until there is space to write to the mailbox. 94 + * 95 + * @param msg The message to write to the mailbox 96 + * @param channel The channel to write to 97 + */ 73 98 void mailbox_send(mail_message_t msg, int channel); 74 99 75 100 /** ··· 80 105 */ 81 106 typedef enum 82 107 { 83 - REQUEST = 0x00000000, 84 - RESPONSE_SUCCESS = 0x80000000, 85 - RESPONSE_ERROR = 0x80000001 108 + REQUEST = 0x00000000, /**< Request code */ 109 + RESPONSE_SUCCESS = 0x80000000, /**< Response success code */ 110 + RESPONSE_ERROR = 0x80000001 /**< Response error code */ 86 111 } buffer_req_res_code_t; 87 112 88 113 /** ··· 94 119 */ 95 120 typedef struct 96 121 { 97 - uint32_t size; /**< Size includes the size itself */ 98 - buffer_req_res_code_t req_res_code; 122 + uint32_t size; /**< Size includes the size itself */ 123 + buffer_req_res_code_t req_res_code; /**< Request or response code */ 99 124 uint32_t tags[1]; /**< The tags start here. Will use overrun to make large 100 125 enough */ 101 126 } property_message_buffer_t; ··· 113 138 */ 114 139 typedef enum 115 140 { 116 - NULL_TAG = 0, 117 - FB_ALLOCATE_BUFFER = 0x00040001, 118 - FB_RELESE_BUFFER = 0x00048001, 119 - FB_GET_PHYSICAL_DIMENSIONS = 0x00040003, 120 - FB_SET_PHYSICAL_DIMENSIONS = 0x00048003, 121 - FB_GET_VIRTUAL_DIMENSIONS = 0x00040004, 122 - FB_SET_VIRTUAL_DIMENSIONS = 0x00048004, 123 - FB_GET_BITS_PER_PIXEL = 0x00040005, 124 - FB_SET_BITS_PER_PIXEL = 0x00048005, 125 - FB_GET_BYTES_PER_ROW = 0x00040008 126 - } property_tag_t; 141 + NULL_TAG = 0, /**< The end of the tag list */ 142 + FB_ALLOCATE_BUFFER = 0x00040001, /**< Allocate a framebuffer */ 143 + FB_RELESE_BUFFER = 0x00048001, /**< Release a framebuffer */ 144 + FB_GET_PHYSICAL_DIMENSIONS = 0x00040003, /**< Get the physical dimensions 145 + of the framebuffer */ 146 + FB_SET_PHYSICAL_DIMENSIONS = 0x00048003, /**< Set the physical dimensions 147 + of the framebuffer */ 148 + FB_GET_VIRTUAL_DIMENSIONS = 0x00040004, /**< Get the virtual dimensions of 149 + the framebuffer */ 150 + FB_SET_VIRTUAL_DIMENSIONS = 0x00048004, /**< Set the virtual dimensions of 151 + the framebuffer */ 152 + FB_GET_BITS_PER_PIXEL = 0x00040005, /**< Get the number of bits per pixel 153 + of the framebuffer */ 154 + FB_SET_BITS_PER_PIXEL = 0x00048005, /**< Set the number of bits per pixel 155 + of the framebuffer */ 156 + FB_GET_BYTES_PER_ROW = 0x00040008 /**< Get the number of bytes per row of 157 + the framebuffer */ 158 + } property_tag_t; /**< The tag */ 127 159 128 160 /** 129 161 * For each possible tag, we create a struct corresponding to the request value ··· 139 171 */ 140 172 typedef struct 141 173 { 142 - void *fb_addr; 143 - uint32_t fb_size; 144 - } fb_allocate_res_t; 174 + void *fb_addr; /**< The address of the framebuffer */ 175 + uint32_t fb_size; /**< The size of the framebuffer */ 176 + } fb_allocate_res_t; /**< The response value buffer for FB_ALLOCATE_BUFFER */ 145 177 146 178 /** 147 179 * @brief Response value buffer for FB_ALLOCATE_BUFFER ··· 151 183 */ 152 184 typedef struct 153 185 { 154 - uint32_t width; 155 - uint32_t height; 156 - } fb_screen_size_t; 186 + uint32_t width; /**< The width of the screen */ 187 + uint32_t height; /**< The height of the screen */ 188 + } fb_screen_size_t; /**< The response value buffer for 189 + FB_GET_PHYSICAL_DIMENSIONS */ 157 190 158 191 /** 159 192 * @brief Union of all possible value buffers ··· 163 196 */ 164 197 typedef union 165 198 { 166 - uint32_t fb_allocate_align; 167 - fb_allocate_res_t fb_allocate_res; 168 - fb_screen_size_t fb_screen_size; 169 - uint32_t fb_bits_per_pixel; 170 - uint32_t fb_bytes_per_row; 171 - } value_buffer_t; 199 + uint32_t fb_allocate_align; /**< The alignment of the framebuffer */ 200 + fb_allocate_res_t fb_allocate_res; /**< The response value buffer for 201 + FB_ALLOCATE_BUFFER */ 202 + fb_screen_size_t fb_screen_size; /**< The response value buffer for 203 + FB_GET_PHYSICAL_DIMENSIONS */ 204 + uint32_t fb_bits_per_pixel; /**< The number of bits per pixel */ 205 + uint32_t fb_bytes_per_row; /**< The number of bytes per row */ 206 + } value_buffer_t; /**< The value buffer */ 172 207 173 208 /** 174 209 * @brief A message that can be sent to the mailbox. ··· 178 213 */ 179 214 typedef struct 180 215 { 181 - property_tag_t proptag; 182 - value_buffer_t value_buffer; 183 - } property_message_tag_t; 216 + property_tag_t property_tag; /**< The property tag */ 217 + value_buffer_t value_buffer; /**< The value buffer */ 218 + } property_message_tag_t; /**< The property message tag */ 184 219 185 220 /** 186 221 * @brief Send a message to the mailbox
+79 -14
os/include/kernel/memory.h
··· 2 2 #include "atag.h" 3 3 #include "list.h" 4 4 #ifndef MEMORY_H 5 - #define MEMORY_H 5 + #define MEMORY_H /**< MEMORY_H */ 6 6 7 - #define PAGE_SIZE 4096 8 - #define KERNEL_HEAP_SIZE (1024 * 1024) 9 - #define KERNEL_STACK_SIZE PAGE_SIZE 7 + /** 8 + * @file memory.h 9 + * @brief Memory management 10 + */ 10 11 12 + #define PAGE_SIZE 4096 /**< Page size */ 13 + #define KERNEL_HEAP_SIZE (1024 * 1024) /**< Kernel heap size */ 14 + #define KERNEL_STACK_SIZE PAGE_SIZE /**< Kernel stack size */ 15 + 16 + /** 17 + * @brief Page flags 18 + * 19 + * This is a bit field that describes the state of a page. It is stored in the 20 + * page_t structure. The flags are: allocated, kernel_page, kernel_heap_page. 21 + * The remaining bits are reserved. 22 + */ 11 23 typedef struct 12 24 { 13 - uint8_t allocated : 1; // This page is allocated to something 14 - uint8_t kernel_page : 1; // This page is a part of the kernel 15 - uint8_t kernel_heap_page : 1; // This page is a part of the kernel 16 - uint32_t reserved : 29; 17 - } page_flags_t; 25 + uint8_t allocated : 1; /**< This page is allocated to something */ 26 + uint8_t kernel_page : 1; /**< This page is a part of the kernel */ 27 + uint8_t kernel_heap_page : 1; /**< This page is a part of the kernel */ 28 + uint32_t reserved : 29; /**< Reserved */ 29 + } page_flags_t; /**< Page flags */ 18 30 19 - DEFINE_LIST(page); 31 + DEFINE_LIST(page); /**< List of pages */ 20 32 33 + /** 34 + * @brief Page 35 + * 36 + * This structure describes a page. It is used to keep track of the state of 37 + * each page in the system. It is stored in the page itself, so it is not 38 + * possible to allocate a page for the page structure itself. 39 + */ 21 40 typedef struct page 22 41 { 23 - uint32_t vaddr_mapped; // The virtual address that maps to this page 24 - page_flags_t flags; 25 - DEFINE_LINK(page); 26 - } page_t; 42 + uint32_t vaddr_mapped; /**< Virtual address mapped to this page */ 43 + page_flags_t flags; /**< Page flags */ 44 + DEFINE_LINK(page); /**< Link to the next page */ 45 + } page_t; /**< Page */ 27 46 47 + /** 48 + * @brief Kernel heap 49 + * 50 + * This is a linked list of pages that are allocated to the kernel heap. 51 + */ 28 52 void mem_init(atag_t *atags); 29 53 54 + /** 55 + * @brief Allocate a page 56 + * 57 + * Allocates a page of physical memory. It gets a free page from a list of free 58 + * pages, updates its metadata to mark it as allocated, and zeros out the 59 + * page's contents. 60 + * 61 + * @return Pointer to the allocated page 62 + */ 30 63 void *alloc_page(void); 64 + 65 + /** 66 + * @brief Free a page 67 + * 68 + * This function frees a page that was previously allocated with alloc_page(). 69 + * If the page was not allocated with alloc_page(), the behavior is undefined. 70 + * 71 + * @param ptr Pointer to the page to free 72 + */ 31 73 void free_page(void *ptr); 32 74 75 + /** 76 + * @brief Allocate a page for the kernel heap 77 + * 78 + * This function allocates a block of memory from the kernel heap. It 79 + * takes the number of bytes to allocate as a parameter, finds the best fit 80 + * free segment in the heap, allocates the segment, and returns a pointer to 81 + * the memory block that has been allocated. The returned pointer points to the 82 + * memory block that starts immediately after the segment header, which 83 + * contains information about the size of the segment and whether it has been 84 + * allocated or not. 85 + * 86 + * @return Pointer to the allocated page 87 + */ 33 88 void *kmalloc(uint32_t bytes); 89 + 90 + /** 91 + * @brief Free a block of memory from the kernel heap 92 + * 93 + * This function frees a block of memory that was previously allocated with 94 + * kmalloc(). If the block was not allocated with kmalloc(), the behavior is 95 + * undefined. 96 + * 97 + * @param ptr Pointer to the block of memory to free 98 + */ 34 99 void kfree(void *ptr); 35 100 36 101 #endif // MEMORY_H
+8 -142
os/src/kernel/framebuffer.c
··· 23 23 24 24 fb_init_t fbinit __attribute__((aligned(16))); 25 25 26 - int framebuffer_init(void) 26 + int framebuffer_init() 27 27 { 28 28 mail_message_t msg; 29 29 ··· 56 56 57 57 #elif MODEL_2 || MODEL_3 || MODEL_4 58 58 59 - typedef enum 60 - { 61 - NULL_TAG = 0, 62 - FB_ALLOCATE_BUFFER = 0x00040001, 63 - FB_RELESE_BUFFER = 0x00048001, 64 - FB_GET_PHYSICAL_DIMENSIONS = 0x00040003, 65 - FB_SET_PHYSICAL_DIMENSIONS = 0x00048003, 66 - FB_GET_VIRTUAL_DIMENSIONS = 0x00040004, 67 - FB_SET_VIRTUAL_DIMENSIONS = 0x00048004, 68 - FB_GET_BITS_PER_PIXEL = 0x00040005, 69 - FB_SET_BITS_PER_PIXEL = 0x00048005, 70 - FB_GET_BYTES_PER_ROW = 0x00040008 71 - } property_tag_t; 72 - 73 - typedef struct 74 - { 75 - void *fb_addr; 76 - uint32_t fb_size; 77 - } fb_allocate_res_t; 78 - 79 - typedef struct 80 - { 81 - uint32_t width; 82 - uint32_t height; 83 - } fb_screen_size_t; 84 - 85 - /* 86 - * The value buffer can be any one of these types 87 - */ 88 - typedef union 89 - { 90 - uint32_t fb_allocate_align; 91 - fb_allocate_res_t fb_allocate_res; 92 - fb_screen_size_t fb_screen_size; 93 - uint32_t fb_bits_per_pixel; 94 - uint32_t fb_bytes_per_row; 95 - } value_buffer_t; 96 - 97 - /* 98 - * A message_buffer can contain any number of these 99 - */ 100 - typedef struct 101 - { 102 - property_tag_t proptag; 103 - value_buffer_t value_buffer; 104 - } property_message_tag_t; 105 - 106 - static uint32_t get_value_buffer_len(property_message_tag_t *tag) 107 - { 108 - switch(tag->proptag) 109 - { 110 - case FB_ALLOCATE_BUFFER: 111 - case FB_GET_PHYSICAL_DIMENSIONS: 112 - case FB_SET_PHYSICAL_DIMENSIONS: 113 - case FB_GET_VIRTUAL_DIMENSIONS: 114 - case FB_SET_VIRTUAL_DIMENSIONS: return 8; 115 - case FB_GET_BITS_PER_PIXEL: 116 - case FB_SET_BITS_PER_PIXEL: 117 - case FB_GET_BYTES_PER_ROW: return 4; 118 - case FB_RELESE_BUFFER: 119 - default: return 0; 120 - } 121 - } 122 - 123 - int send_messages(property_message_tag_t *tags) 124 - { 125 - property_message_buffer_t *msg; 126 - mail_message_t mail; 127 - uint32_t bufsize = 0, i, len, bufpos; 128 - 129 - // Calculate the sizes of each tag 130 - for(i = 0; tags[i].proptag != NULL_TAG; i++) 131 - { 132 - bufsize += get_value_buffer_len(&tags[i]) + 3 * sizeof(uint32_t); 133 - } 134 - 135 - // Add the buffer size, buffer request/response code and buffer end tag sizes 136 - bufsize += 3 * sizeof(uint32_t); 137 - 138 - // buffer size must be 16 byte aligned 139 - bufsize += (bufsize % 16) ? 16 - (bufsize % 16) : 0; 140 - 141 - // kmalloc returns a 16 byte aligned address 142 - msg = kmalloc(bufsize); 143 - if(!msg) 144 - return -1; 145 - 146 - msg->size = bufsize; 147 - msg->req_res_code = REQUEST; 148 - 149 - // Copy the messages into the buffer 150 - for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++) 151 - { 152 - len = get_value_buffer_len(&tags[i]); 153 - msg->tags[bufpos++] = tags[i].proptag; 154 - msg->tags[bufpos++] = len; 155 - msg->tags[bufpos++] = 0; 156 - memcpy(msg->tags + bufpos, &tags[i].value_buffer, len); 157 - bufpos += len / 4; 158 - } 159 - 160 - msg->tags[bufpos] = 0; 161 - 162 - // Send the message 163 - mail.data = ((uint32_t)msg) >> 4; 164 - 165 - mailbox_send(mail, PROPERTY_CHANNEL); 166 - mail = mailbox_read(PROPERTY_CHANNEL); 167 - 168 - if(msg->req_res_code == REQUEST) 169 - { 170 - kfree(msg); 171 - return 1; 172 - } 173 - // Check the response code 174 - if(msg->req_res_code == RESPONSE_ERROR) 175 - { 176 - kfree(msg); 177 - return 2; 178 - } 179 - 180 - // Copy the tags back into the array 181 - for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++) 182 - { 183 - len = get_value_buffer_len(&tags[i]); 184 - bufpos += 3; // skip over the tag bookkepping info 185 - memcpy(&tags[i].value_buffer, msg->tags + bufpos, len); 186 - bufpos += len / 4; 187 - } 188 - 189 - kfree(msg); 190 - return 0; 191 - } 192 - 193 - int framebuffer_init(void) 59 + int framebuffer_init() 194 60 { 195 61 property_message_tag_t tags[5]; 196 62 197 - tags[0].proptag = FB_SET_PHYSICAL_DIMENSIONS; 63 + tags[0].property_tag = FB_SET_PHYSICAL_DIMENSIONS; 198 64 tags[0].value_buffer.fb_screen_size.width = 640; 199 65 tags[0].value_buffer.fb_screen_size.height = 480; 200 - tags[1].proptag = FB_SET_VIRTUAL_DIMENSIONS; 66 + tags[1].property_tag = FB_SET_VIRTUAL_DIMENSIONS; 201 67 tags[1].value_buffer.fb_screen_size.width = 640; 202 68 tags[1].value_buffer.fb_screen_size.height = 480; 203 - tags[2].proptag = FB_SET_BITS_PER_PIXEL; 69 + tags[2].property_tag = FB_SET_BITS_PER_PIXEL; 204 70 tags[2].value_buffer.fb_bits_per_pixel = COLORDEPTH; 205 - tags[3].proptag = NULL_TAG; 71 + tags[3].property_tag = NULL_TAG; 206 72 207 73 // Send over the initialization 208 74 if(send_messages(tags) != 0) ··· 219 85 fbinfo.pitch = fbinfo.width * BYTES_PER_PIXEL; 220 86 221 87 // request a framebuffer 222 - tags[0].proptag = FB_ALLOCATE_BUFFER; 88 + tags[0].property_tag = FB_ALLOCATE_BUFFER; 223 89 tags[0].value_buffer.fb_screen_size.width = 0; 224 90 tags[0].value_buffer.fb_screen_size.height = 0; 225 91 tags[0].value_buffer.fb_allocate_align = 16; 226 - tags[1].proptag = NULL_TAG; 92 + tags[1].property_tag = NULL_TAG; 227 93 228 94 if(send_messages(tags) != 0) 229 95 {
+1 -1
os/src/kernel/gpu.c
··· 64 64 } 65 65 } 66 66 67 - void gpu_init(void) 67 + void gpu_init() 68 68 { 69 69 static const pixel_t BLACK = {0x00, 0x00, 0x00}; 70 70 // Aparantly, this sometimes does not work, so try in a loop
+1 -1
os/src/kernel/kerio.c
··· 5 5 #include "common/stdlib.h" 6 6 #include <stdarg.h> 7 7 8 - char getc(void) { return uart_getc(); } 8 + char getc() { return uart_getc(); } 9 9 10 10 void putc(char c) 11 11 {
+5 -5
os/src/kernel/mailbox.c
··· 40 40 41 41 static uint32_t get_value_buffer_len(property_message_tag_t *tag) 42 42 { 43 - switch(tag->proptag) 43 + switch(tag->property_tag) 44 44 { 45 45 case FB_ALLOCATE_BUFFER: 46 46 case FB_GET_PHYSICAL_DIMENSIONS: ··· 62 62 uint32_t bufsize = 0, i, len, bufpos; 63 63 64 64 // Calculate the sizes of each tag 65 - for(i = 0; tags[i].proptag != NULL_TAG; i++) 65 + for(i = 0; tags[i].property_tag != NULL_TAG; i++) 66 66 { 67 67 bufsize += get_value_buffer_len(&tags[i]) + 3 * sizeof(uint32_t); 68 68 } ··· 81 81 msg->req_res_code = REQUEST; 82 82 83 83 // Copy the messages into the buffer 84 - for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++) 84 + for(i = 0, bufpos = 0; tags[i].property_tag != NULL_TAG; i++) 85 85 { 86 86 len = get_value_buffer_len(&tags[i]); 87 - msg->tags[bufpos++] = tags[i].proptag; 87 + msg->tags[bufpos++] = tags[i].property_tag; 88 88 msg->tags[bufpos++] = len; 89 89 msg->tags[bufpos++] = 0; 90 90 memcpy(msg->tags + bufpos, &tags[i].value_buffer, len); ··· 112 112 } 113 113 114 114 // Copy the tags back into the array 115 - for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++) 115 + for(i = 0, bufpos = 0; tags[i].property_tag != NULL_TAG; i++) 116 116 { 117 117 len = get_value_buffer_len(&tags[i]); 118 118 bufpos += 3; // skip over the tag bookkepping info
+16 -14
os/src/kernel/memory.c
··· 6 6 #include <stddef.h> 7 7 8 8 /** 9 - * Heap Stuff 9 + * @brief Initalize the heap 10 + * 11 + * @param heap_start The start of the heap 10 12 */ 11 13 static void heap_init(uint32_t heap_start); 12 14 /** ··· 16 18 */ 17 19 typedef struct heap_segment 18 20 { 19 - struct heap_segment *next; 20 - struct heap_segment *prev; 21 - uint32_t is_allocated; 22 - uint32_t segment_size; // Includes this header 23 - } heap_segment_t; 21 + struct heap_segment 22 + *next; /**< pointer to the next segment in the linked list */ 23 + struct heap_segment 24 + *prev; /**< pointer to the previous segment in the linked list */ 25 + uint32_t is_allocated; /**< 1 if the segment is allocated, 0 if it's free */ 26 + uint32_t segment_size; /**< size of the segment, including the header */ 27 + } heap_segment_t; /**< Heap segment */ 24 28 25 - static heap_segment_t *heap_segment_list_head; 26 - /** 27 - * End Heap Stuff 28 - */ 29 + static heap_segment_t 30 + *heap_segment_list_head; /**< Head of the heap segment list */ 29 31 30 - extern uint8_t __end; 31 - static uint32_t num_pages; 32 + extern uint8_t __end; /**< Defined by the linker */ 33 + static uint32_t num_pages; /**< Number of pages in the system */ 32 34 33 35 IMPLEMENT_LIST(page); 34 36 35 - static page_t *all_pages_array; 36 - page_list_t free_pages; 37 + static page_t *all_pages_array; /**< Array of all pages in the system */ 38 + page_list_t free_pages; /**< List of all free pages in the system */ 37 39 38 40 void mem_init(atag_t *atags) 39 41 {