···66#include <stddef.h> // defines NULL and size_t
77#include <stdint.h>
88#ifndef STDLIB_H
99-#define STDLIB_H
99+#define STDLIB_H /**< STDLIB_H */
10101111-#define MIN(x, y) ((x < y ? x : y))
1212-#define MAX(x, y) ((x < y ? y : x))
1111+#define MIN(x, y) ((x < y ? x : y)) /**< Find minimum of x and y */
1212+#define MAX(x, y) ((x < y ? y : x)) /**< Find maximum of x and y */
13131414+/**
1515+ * @brief Result of divmod function
1616+ *
1717+ * The Raspberry Pi 1 does not have the instruction to perform a division. This
1818+ * struct is used to return the result of a division and the remainder.
1919+ */
1420typedef struct divmod_result
1521{
1616- uint32_t div;
1717- uint32_t mod;
1818-} divmod_t;
2222+ uint32_t div; /**< Result of the division */
2323+ uint32_t mod; /**< Remainder of the division */
2424+} divmod_t; /**< Typedef for divmod_result */
19252626+/**
2727+ * @brief Performs a division and returns the result and the remainder
2828+ *
2929+ * @param dividend The dividend
3030+ * @param divisor The divisor
3131+ * @return divmod_t The result of the division and the remainder
3232+ */
2033divmod_t divmod(uint32_t dividend, uint32_t divisor);
3434+3535+/**
3636+ * @brief Performs a division and returns the result
3737+ *
3838+ * @param dividend The dividend
3939+ * @param divisor The divisor
4040+ * @return uint32_t The result of the division.
4141+ */
2142uint32_t div(uint32_t dividend, uint32_t divisor);
22432344/**
···4061 * Converts an int (Only base 10 supported for now)
4162 * to a null-terminated string using the specified base.
4263 * @param value Value to be converted to a string.
6464+ * @param base Numerical base used to represent the value as a string,
6565+ * between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal,
6666+ * and 2 binary.
4367 * @return A pointer to the resulting null-terminated string.
4468 */
4569char *itoa(int value, int base);
···4872 * @brief str -> int
4973 *
5074 * Converts a string to an int
5151- * @param str This is the string representation of an integral number.
7575+ * @param num This is the string representation of an integral number.
5276 * @return The converted integral number as an int value.
5377 * If no valid conversion could be performed, it returns zero.
5478 */
+52-37
os/include/kernel/atag.h
···88#include <stdint.h>
991010#ifndef ATAG_H
1111-#define ATAG_H
1111+#define ATAG_H /**< ATAG_H */
12121313/**
1414 * @brief Prints the ATAGs
1515+ *
1616+ * @param address Address of the ATAGs
1517 */
1618void print_atags(uint32_t address);
17191818-#define ATAG_NONE 0
1919-#define ATAG_CORE 0x54410001
2020-#define ATAG_MEM 0x54410002
2121-#define ATAG_VIDEOTEXT 0x54410003
2222-#define ATAG_RAMDISK 0x54410004
2323-#define ATAG_INITRD2 0x54420005
2424-#define ATAG_SERIAL 0x54410006
2525-#define ATAG_REVISION 0x54410007
2626-#define ATAG_VIDEOLFB 0x54410008
2727-#define ATAG_CMDLINE 0x54410009
2020+/**
2121+ * @brief Enumearation of ATAG types
2222+ */
2323+enum ATAG_TYPE
2424+{
2525+ ATAG_NONE = 0, /**< Empty tag used to end the list */
2626+ ATAG_CORE = 0x54410001, /**< First tag used to start the list */
2727+ ATAG_MEM = 0x54410002, /**< Describes a physical area of memory */
2828+ ATAG_VIDEOTEXT = 0x54410003, /**< VGA text screen information */
2929+ ATAG_RAMDISK = 0x54410004, /**< Describes how the ramdisk will be used */
3030+ ATAG_INITRD2 = 0x54420005, /**< Describes where the compressed ramdisk
3131+ image is placed in memory */
3232+ ATAG_SERIAL = 0x54410006, /**< Board serial number */
3333+ ATAG_REVISION = 0x54410007, /**< Board revision */
3434+ ATAG_VIDEOLFB = 0x54410008, /**< Framebuffer information */
3535+ ATAG_CMDLINE = 0x54410009 /**< Command line */
3636+};
28372938/**
3039 * @brief ATAG header structure
···95104 uint32_t size; /**< Size of compressed(?) image */
96105} atag_initrd2;
971069898-/* ATAG_SERIAL has the 64-bit serial number */
107107+/**
108108+ * @brief ATAG_SERIAL structure
109109+ *
110110+ * This ATAG describes the serial number of the board.
111111+ */
99112typedef struct atag_serial
100113{
101101- uint32_t low;
102102- uint32_t high;
114114+ uint32_t low; /**< Low 32 bits of serial number */
115115+ uint32_t high; /**< High 32 bits of serial number */
103116} atag_serial;
104117105118/**
···109122 */
110123typedef struct atag_revision
111124{
112112- uint32_t revision;
125125+ uint32_t revision; /**< Board revision */
113126} atag_revision;
114127115128/**
···119132 */
120133typedef struct atag_videolfb
121134{
122122- uint16_t width; /**< Width of buffer */
123123- uint16_t height; /**< Height */
124124- uint16_t depth; /**< Bits/pixel */
125125- uint16_t linelength; // ?
126126- uint32_t address; /**< Base address of buffer */
127127- uint32_t size; /**< Size of buffer */
128128- unsigned char redsize; /**< Number of red bits in each pixel */
129129- unsigned char redpos; /**< Position of red bits in pixel */
130130- unsigned char greensize;
131131- unsigned char greenpos;
132132- unsigned char bluesize;
133133- unsigned char bluepos;
135135+ uint16_t width; /**< Width of buffer */
136136+ uint16_t height; /**< Height */
137137+ uint16_t depth; /**< Bits/pixel */
138138+ uint16_t linelength; /**< Length of a line in bytes */
139139+ uint32_t address; /**< Base address of buffer */
140140+ uint32_t size; /**< Size of buffer */
141141+ unsigned char redsize; /**< Number of red bits in each pixel */
142142+ unsigned char redpos; /**< Position of red bits in pixel */
143143+ unsigned char greensize; /**< Number of green bits in each pixel */
144144+ unsigned char greenpos; /**< Position of green bits in pixel */
145145+ unsigned char bluesize; /**< Number of blue bits in each pixel */
146146+ unsigned char bluepos; /**< Position of blue bits in pixel */
134147 unsigned char reservedsize; /**< Number of reserved bits/pixel */
135148 unsigned char reservedpos; /**< Position of reserved bits */
136149} atag_videolfb;
···152165 */
153166typedef struct atag_t
154167{
155155- atag_header header;
168168+ atag_header header; /**< Standard header */
156169 union
157170 {
158158- atag_core core;
159159- atag_mem mem;
160160- atag_ramdisk ramdisk;
161161- atag_initrd2 initrd2;
162162- atag_serial serial;
163163- atag_revision revision;
164164- atag_videolfb videolfb;
165165- atag_cmdline cmdline;
171171+ atag_core core; /**< Core tag */
172172+ atag_mem mem; /**< Memory tag */
173173+ atag_ramdisk ramdisk; /**< Ramdisk tag */
174174+ atag_initrd2 initrd2; /**< Initrd2 tag */
175175+ atag_serial serial; /**< Serial tag */
176176+ atag_revision revision; /**< Revision tag */
177177+ atag_videolfb videolfb; /**< Videolfb tag */
178178+ atag_cmdline cmdline; /**< Cmdline tag */
166179 };
167167-} atag_t;
180180+} atag_t; /**< ATAG structure */
168181169182#define tag_next(t) \
170183 ((atag_t *)((uint32_t *)(t) + (t)->header.size)) /**< Get next tag */
···173186174187/**
175188 * @brief Get the memory size from the ATAGs
189189+ *
190190+ * @param atags Pointer to the ATAGs
176191 */
177192uint32_t get_mem_size(atag_t *atags);
178193
+31-14
os/include/kernel/framebuffer.h
···22#ifndef FRAMEBUFFER_H
33#define FRAMEBUFFER_H
4455-#define COLORDEPTH 24
66-#define BYTES_PER_PIXEL COLORDEPTH / 8
55+/**
66+ * @file framebuffer.h
77+ * @brief Provides functions to initialize the framebuffer and draw pixels.
88+ */
791010+#define COLORDEPTH 24 /**< Number of bits per pixel */
1111+#define BYTES_PER_PIXEL COLORDEPTH / 8 /**< Number of bytes per pixel */
1212+1313+/**
1414+ * @brief Struct to store information about the framebuffer.
1515+ *
1616+ * The framebuffer is a memory region that stores the pixels of the screen. The
1717+ * GPU writes the pixels to the framebuffer and the pixels are then displayed
1818+ * on the screen.
1919+ *
2020+ * The framebuffer is a contiguous memory region. The pixels are stored in
2121+ * raster order, with the first pixel being the top left pixel, and the last
2222+ * pixel being the bottom right pixel.
2323+ */
824typedef struct framebuffer_info
925{
1010- uint32_t width;
1111- uint32_t height;
1212- uint32_t pitch;
1313- void *buf;
1414- uint32_t buf_size;
1515- uint32_t chars_width;
1616- uint32_t chars_height;
1717- uint32_t chars_x;
1818- uint32_t chars_y;
1919-} framebuffer_info_t;
2626+ uint32_t width; /**< Width of the framebuffer in pixels */
2727+ uint32_t height; /**< Height of the framebuffer in pixels */
2828+ uint32_t pitch; /**< Number of bytes per row */
2929+ void *buf; /**< Pointer to the framebuffer */
3030+ uint32_t buf_size; /**< Size of the framebuffer in bytes */
3131+ uint32_t chars_width; /**< Width of the framebuffer in characters */
3232+ uint32_t chars_height; /**< Height of the framebuffer in characters */
3333+ uint32_t chars_x; /**< X position of the cursor in characters */
3434+ uint32_t chars_y; /**< Y position of the cursor in characters */
3535+} framebuffer_info_t; /**< Typedef for framebuffer_info */
20362121-extern framebuffer_info_t fbinfo;
3737+extern framebuffer_info_t
3838+ fbinfo; /**< Global variable to store framebuffer information */
22392323-int framebuffer_init(void);
4040+int framebuffer_init(); /**< Initializes the framebuffer */
24412542#endif // FRAMEBUFFER_H
+42-7
os/include/kernel/gpu.h
···22#ifndef GPU_H
33#define GPU_H
4455-#define CHAR_WIDTH 8
66-#define CHAR_HEIGHT 8
55+/**
66+ * @file gpu.h
77+ * @brief Definition of GPU functions.
88+ */
99+1010+#define CHAR_WIDTH 8 /**< Character width */
1111+#define CHAR_HEIGHT 8 /**< Character height */
7121313+/**
1414+ * @brief Struct to store information about the GPU.
1515+ *
1616+ * The GPU is responsible for drawing pixels on the screen.
1717+ */
818typedef struct pixel
919{
1010- uint8_t red;
1111- uint8_t green;
1212- uint8_t blue;
1313-} pixel_t;
2020+ uint8_t red; /**< Red component of the pixel */
2121+ uint8_t green; /**< Green component of the pixel */
2222+ uint8_t blue; /**< Blue component of the pixel */
2323+} pixel_t; /**< Typedef for pixel */
14241515-void gpu_init(void);
2525+/**
2626+ * @brief Initializes the GPU.
2727+ *
2828+ * - Calls the framebuffer_init() function in a loop until it returns a
2929+ * non-zero value. Sometimes this does not work on the first time so we loop
3030+ * until it works...
3131+ * - framebuffer_init() is a separate function that initializes
3232+ * the framebuffer, which is a portion of memory used to store the pixels that
3333+ * are displayed on the screen.
3434+ * - Once the framebuffer is initialized, we clear the screen by looping
3535+ * through all the pixels in the framebuffer and setting their color to black.
3636+ * This is done by calling the write_pixel() function.
3737+ */
3838+void gpu_init();
16394040+/**
4141+ * @brief Writes a pixel to the screen.
4242+ *
4343+ * @param x X coordinate of the pixel
4444+ * @param y Y coordinate of the pixel
4545+ * @param pixel Pointer to the pixel to write
4646+ */
1747void write_pixel(uint32_t x, uint32_t y, const pixel_t *pixel);
18484949+/**
5050+ * @brief Writes a character to the screen.
5151+ *
5252+ * @param c Character to write
5353+ */
1954void gpu_putc(char c);
20552156#endif
+52-3
os/include/kernel/kerio.h
···11#ifndef STDIO_H
22#define STDIO_H
3344-char getc(void);
44+/**
55+ * @file kerio.h
66+ * @brief This file contains the definitions for the standard input/output.
77+ *
88+ * This file contains the definitions for the standard input/output. It is
99+ * based on the C standard library.
1010+ */
1111+1212+/**
1313+ * @brief Reads a character from the standard input.
1414+ *
1515+ * Note that what exactly standerd input is depends on the implementation.
1616+ */
1717+char getc();
1818+1919+/**
2020+ * @brief Writes a character to the standard output.
2121+ *
2222+ * Note that what exactly standerd output is depends on the implementation. In
2323+ * particular, during developemnt it has proved usefull to redirect the output
2424+ * to UART0.
2525+ *
2626+ * @param c The character to write.
2727+ */
528void putc(char c);
6293030+/**
3131+ * @brief Writes a string to the standard output.
3232+ *
3333+ * This function calls internally @a putc to write the string, so please
3434+ * consider the documentation of that function.
3535+ *
3636+ * @param s The string to write.
3737+ */
738void puts(const char *s);
83999-// This version of gets copies until newline, replacing newline with null char,
1010-// or until buflen. whichever comes first
4040+/**
4141+ * @brief Reads a string from the standard input.
4242+ *
4343+ * This function reads a string from the standard input. The string is stored
4444+ * in the buffer @a buf. The buffer is guaranteed to be null-terminated. The
4545+ * maximum number of characters read is @a buflen - 1. The newline character
4646+ * is not stored in the buffer.
4747+ *
4848+ * @param buf The buffer to store the string in.
4949+ * @param buflen The maximum number of characters to read.
5050+ */
1151void gets(char *buf, int buflen);
12525353+/**
5454+ * @brief Writes a formatted string to the standard output.
5555+ *
5656+ * This function writes a formatted string to the standard output. The
5757+ * formatting is done in the same way as in the C standard library.
5858+ *
5959+ * @param fmt The format string.
6060+ * @param ... The arguments to the format string.
6161+ */
1362void printf(const char *fmt, ...);
14631564#endif
+79-44
os/include/kernel/mailbox.h
···1313 *
1414 */
15151616-#define MAILBOX_OFFSET 0xB880
1616+#define MAILBOX_OFFSET 0xB880 /**< The offset of the mailbox registers */
17171818-#define MAILBOX_BASE MMIO_BASE + MAILBOX_OFFSET
1919-#define MAIL0_READ (((mail_message_t *)(0x00 + MAILBOX_BASE)))
2020-#define MAIL0_STATUS (((mail_status_t *)(0x18 + MAILBOX_BASE)))
2121-#define MAIL0_WRITE (((mail_message_t *)(0x20 + MAILBOX_BASE)))
1818+#define MAILBOX_BASE \
1919+ MMIO_BASE \
2020+ +MAILBOX_OFFSET /**< The base address of the mailbox registers */
2121+#define MAIL0_READ \
2222+ (((mail_message_t *)(0x00 + MAILBOX_BASE))) /**< Read from \
2323+ mailbox 0 */
2424+#define MAIL0_STATUS \
2525+ (((mail_status_t *)(0x18 + MAILBOX_BASE))) /**< Status of \
2626+ mailbox 0 */
2727+#define MAIL0_WRITE \
2828+ (((mail_message_t *)(0x20 + MAILBOX_BASE))) /**< Write to \
2929+ mailbox 0 */
22302323-#define PROPERTY_CHANNEL 8
2424-#define FRAMEBUFFER_CHANNEL 1
3131+#define PROPERTY_CHANNEL 8 /**< Channel 8 is the property channel */
3232+#define FRAMEBUFFER_CHANNEL 1 /**< Channel 1 is the framebuffer channel */
25332634/**
2735 * @brief A message that can be sent to the mailbox
···4048 */
4149typedef struct
4250{
4343- uint8_t channel : 4;
4444- uint32_t data : 28;
5151+ uint8_t channel : 4; /**< The channel to send the message to */
5252+ uint32_t data : 28; /**< The data to send */
4553} mail_message_t;
46544755/**
···6472 */
6573typedef struct
6674{
6767- uint32_t reserved : 30;
6868- uint8_t empty : 1;
6969- uint8_t full : 1;
7070-} mail_status_t;
7575+ uint32_t reserved : 30; /**< Reserved for future use */
7676+ uint8_t empty : 1; /**< The empty flag */
7777+ uint8_t full : 1; /**< The full flag */
7878+} mail_status_t; /**< The status of the mailbox */
71798080+/**
8181+ * @brief Read from the mailbox
8282+ *
8383+ * This function will block until there is mail to read from the mailbox.
8484+ *
8585+ * @param channel The channel to read from
8686+ * @return The message that was read from the mailbox
8787+ */
7288mail_message_t mailbox_read(int channel);
8989+9090+/**
9191+ * @brief Write to the mailbox
9292+ *
9393+ * This function will block until there is space to write to the mailbox.
9494+ *
9595+ * @param msg The message to write to the mailbox
9696+ * @param channel The channel to write to
9797+ */
7398void mailbox_send(mail_message_t msg, int channel);
749975100/**
···80105 */
81106typedef enum
82107{
8383- REQUEST = 0x00000000,
8484- RESPONSE_SUCCESS = 0x80000000,
8585- RESPONSE_ERROR = 0x80000001
108108+ REQUEST = 0x00000000, /**< Request code */
109109+ RESPONSE_SUCCESS = 0x80000000, /**< Response success code */
110110+ RESPONSE_ERROR = 0x80000001 /**< Response error code */
86111} buffer_req_res_code_t;
8711288113/**
···94119 */
95120typedef struct
96121{
9797- uint32_t size; /**< Size includes the size itself */
9898- buffer_req_res_code_t req_res_code;
122122+ uint32_t size; /**< Size includes the size itself */
123123+ buffer_req_res_code_t req_res_code; /**< Request or response code */
99124 uint32_t tags[1]; /**< The tags start here. Will use overrun to make large
100125 enough */
101126} property_message_buffer_t;
···113138 */
114139typedef enum
115140{
116116- NULL_TAG = 0,
117117- FB_ALLOCATE_BUFFER = 0x00040001,
118118- FB_RELESE_BUFFER = 0x00048001,
119119- FB_GET_PHYSICAL_DIMENSIONS = 0x00040003,
120120- FB_SET_PHYSICAL_DIMENSIONS = 0x00048003,
121121- FB_GET_VIRTUAL_DIMENSIONS = 0x00040004,
122122- FB_SET_VIRTUAL_DIMENSIONS = 0x00048004,
123123- FB_GET_BITS_PER_PIXEL = 0x00040005,
124124- FB_SET_BITS_PER_PIXEL = 0x00048005,
125125- FB_GET_BYTES_PER_ROW = 0x00040008
126126-} property_tag_t;
141141+ NULL_TAG = 0, /**< The end of the tag list */
142142+ FB_ALLOCATE_BUFFER = 0x00040001, /**< Allocate a framebuffer */
143143+ FB_RELESE_BUFFER = 0x00048001, /**< Release a framebuffer */
144144+ FB_GET_PHYSICAL_DIMENSIONS = 0x00040003, /**< Get the physical dimensions
145145+ of the framebuffer */
146146+ FB_SET_PHYSICAL_DIMENSIONS = 0x00048003, /**< Set the physical dimensions
147147+ of the framebuffer */
148148+ FB_GET_VIRTUAL_DIMENSIONS = 0x00040004, /**< Get the virtual dimensions of
149149+ the framebuffer */
150150+ FB_SET_VIRTUAL_DIMENSIONS = 0x00048004, /**< Set the virtual dimensions of
151151+ the framebuffer */
152152+ FB_GET_BITS_PER_PIXEL = 0x00040005, /**< Get the number of bits per pixel
153153+ of the framebuffer */
154154+ FB_SET_BITS_PER_PIXEL = 0x00048005, /**< Set the number of bits per pixel
155155+ of the framebuffer */
156156+ FB_GET_BYTES_PER_ROW = 0x00040008 /**< Get the number of bytes per row of
157157+ the framebuffer */
158158+} property_tag_t; /**< The tag */
127159128160/**
129161 * For each possible tag, we create a struct corresponding to the request value
···139171 */
140172typedef struct
141173{
142142- void *fb_addr;
143143- uint32_t fb_size;
144144-} fb_allocate_res_t;
174174+ void *fb_addr; /**< The address of the framebuffer */
175175+ uint32_t fb_size; /**< The size of the framebuffer */
176176+} fb_allocate_res_t; /**< The response value buffer for FB_ALLOCATE_BUFFER */
145177146178/**
147179 * @brief Response value buffer for FB_ALLOCATE_BUFFER
···151183 */
152184typedef struct
153185{
154154- uint32_t width;
155155- uint32_t height;
156156-} fb_screen_size_t;
186186+ uint32_t width; /**< The width of the screen */
187187+ uint32_t height; /**< The height of the screen */
188188+} fb_screen_size_t; /**< The response value buffer for
189189+ FB_GET_PHYSICAL_DIMENSIONS */
157190158191/**
159192 * @brief Union of all possible value buffers
···163196 */
164197typedef union
165198{
166166- uint32_t fb_allocate_align;
167167- fb_allocate_res_t fb_allocate_res;
168168- fb_screen_size_t fb_screen_size;
169169- uint32_t fb_bits_per_pixel;
170170- uint32_t fb_bytes_per_row;
171171-} value_buffer_t;
199199+ uint32_t fb_allocate_align; /**< The alignment of the framebuffer */
200200+ fb_allocate_res_t fb_allocate_res; /**< The response value buffer for
201201+ FB_ALLOCATE_BUFFER */
202202+ fb_screen_size_t fb_screen_size; /**< The response value buffer for
203203+ FB_GET_PHYSICAL_DIMENSIONS */
204204+ uint32_t fb_bits_per_pixel; /**< The number of bits per pixel */
205205+ uint32_t fb_bytes_per_row; /**< The number of bytes per row */
206206+} value_buffer_t; /**< The value buffer */
172207173208/**
174209 * @brief A message that can be sent to the mailbox.
···178213 */
179214typedef struct
180215{
181181- property_tag_t proptag;
182182- value_buffer_t value_buffer;
183183-} property_message_tag_t;
216216+ property_tag_t property_tag; /**< The property tag */
217217+ value_buffer_t value_buffer; /**< The value buffer */
218218+} property_message_tag_t; /**< The property message tag */
184219185220/**
186221 * @brief Send a message to the mailbox
+79-14
os/include/kernel/memory.h
···22#include "atag.h"
33#include "list.h"
44#ifndef MEMORY_H
55-#define MEMORY_H
55+#define MEMORY_H /**< MEMORY_H */
6677-#define PAGE_SIZE 4096
88-#define KERNEL_HEAP_SIZE (1024 * 1024)
99-#define KERNEL_STACK_SIZE PAGE_SIZE
77+/**
88+ * @file memory.h
99+ * @brief Memory management
1010+ */
10111212+#define PAGE_SIZE 4096 /**< Page size */
1313+#define KERNEL_HEAP_SIZE (1024 * 1024) /**< Kernel heap size */
1414+#define KERNEL_STACK_SIZE PAGE_SIZE /**< Kernel stack size */
1515+1616+/**
1717+ * @brief Page flags
1818+ *
1919+ * This is a bit field that describes the state of a page. It is stored in the
2020+ * page_t structure. The flags are: allocated, kernel_page, kernel_heap_page.
2121+ * The remaining bits are reserved.
2222+ */
1123typedef struct
1224{
1313- uint8_t allocated : 1; // This page is allocated to something
1414- uint8_t kernel_page : 1; // This page is a part of the kernel
1515- uint8_t kernel_heap_page : 1; // This page is a part of the kernel
1616- uint32_t reserved : 29;
1717-} page_flags_t;
2525+ uint8_t allocated : 1; /**< This page is allocated to something */
2626+ uint8_t kernel_page : 1; /**< This page is a part of the kernel */
2727+ uint8_t kernel_heap_page : 1; /**< This page is a part of the kernel */
2828+ uint32_t reserved : 29; /**< Reserved */
2929+} page_flags_t; /**< Page flags */
18301919-DEFINE_LIST(page);
3131+DEFINE_LIST(page); /**< List of pages */
20323333+/**
3434+ * @brief Page
3535+ *
3636+ * This structure describes a page. It is used to keep track of the state of
3737+ * each page in the system. It is stored in the page itself, so it is not
3838+ * possible to allocate a page for the page structure itself.
3939+ */
2140typedef struct page
2241{
2323- uint32_t vaddr_mapped; // The virtual address that maps to this page
2424- page_flags_t flags;
2525- DEFINE_LINK(page);
2626-} page_t;
4242+ uint32_t vaddr_mapped; /**< Virtual address mapped to this page */
4343+ page_flags_t flags; /**< Page flags */
4444+ DEFINE_LINK(page); /**< Link to the next page */
4545+} page_t; /**< Page */
27464747+/**
4848+ * @brief Kernel heap
4949+ *
5050+ * This is a linked list of pages that are allocated to the kernel heap.
5151+ */
2852void mem_init(atag_t *atags);
29535454+/**
5555+ * @brief Allocate a page
5656+ *
5757+ * Allocates a page of physical memory. It gets a free page from a list of free
5858+ * pages, updates its metadata to mark it as allocated, and zeros out the
5959+ * page's contents.
6060+ *
6161+ * @return Pointer to the allocated page
6262+ */
3063void *alloc_page(void);
6464+6565+/**
6666+ * @brief Free a page
6767+ *
6868+ * This function frees a page that was previously allocated with alloc_page().
6969+ * If the page was not allocated with alloc_page(), the behavior is undefined.
7070+ *
7171+ * @param ptr Pointer to the page to free
7272+ */
3173void free_page(void *ptr);
32747575+/**
7676+ * @brief Allocate a page for the kernel heap
7777+ *
7878+ * This function allocates a block of memory from the kernel heap. It
7979+ * takes the number of bytes to allocate as a parameter, finds the best fit
8080+ * free segment in the heap, allocates the segment, and returns a pointer to
8181+ * the memory block that has been allocated. The returned pointer points to the
8282+ * memory block that starts immediately after the segment header, which
8383+ * contains information about the size of the segment and whether it has been
8484+ * allocated or not.
8585+ *
8686+ * @return Pointer to the allocated page
8787+ */
3388void *kmalloc(uint32_t bytes);
8989+9090+/**
9191+ * @brief Free a block of memory from the kernel heap
9292+ *
9393+ * This function frees a block of memory that was previously allocated with
9494+ * kmalloc(). If the block was not allocated with kmalloc(), the behavior is
9595+ * undefined.
9696+ *
9797+ * @param ptr Pointer to the block of memory to free
9898+ */
3499void kfree(void *ptr);
3510036101#endif // MEMORY_H
···6464 }
6565}
66666767-void gpu_init(void)
6767+void gpu_init()
6868{
6969 static const pixel_t BLACK = {0x00, 0x00, 0x00};
7070 // Aparantly, this sometimes does not work, so try in a loop
···40404141static uint32_t get_value_buffer_len(property_message_tag_t *tag)
4242{
4343- switch(tag->proptag)
4343+ switch(tag->property_tag)
4444 {
4545 case FB_ALLOCATE_BUFFER:
4646 case FB_GET_PHYSICAL_DIMENSIONS:
···6262 uint32_t bufsize = 0, i, len, bufpos;
63636464 // Calculate the sizes of each tag
6565- for(i = 0; tags[i].proptag != NULL_TAG; i++)
6565+ for(i = 0; tags[i].property_tag != NULL_TAG; i++)
6666 {
6767 bufsize += get_value_buffer_len(&tags[i]) + 3 * sizeof(uint32_t);
6868 }
···8181 msg->req_res_code = REQUEST;
82828383 // Copy the messages into the buffer
8484- for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++)
8484+ for(i = 0, bufpos = 0; tags[i].property_tag != NULL_TAG; i++)
8585 {
8686 len = get_value_buffer_len(&tags[i]);
8787- msg->tags[bufpos++] = tags[i].proptag;
8787+ msg->tags[bufpos++] = tags[i].property_tag;
8888 msg->tags[bufpos++] = len;
8989 msg->tags[bufpos++] = 0;
9090 memcpy(msg->tags + bufpos, &tags[i].value_buffer, len);
···112112 }
113113114114 // Copy the tags back into the array
115115- for(i = 0, bufpos = 0; tags[i].proptag != NULL_TAG; i++)
115115+ for(i = 0, bufpos = 0; tags[i].property_tag != NULL_TAG; i++)
116116 {
117117 len = get_value_buffer_len(&tags[i]);
118118 bufpos += 3; // skip over the tag bookkepping info
+16-14
os/src/kernel/memory.c
···66#include <stddef.h>
7788/**
99- * Heap Stuff
99+ * @brief Initalize the heap
1010+ *
1111+ * @param heap_start The start of the heap
1012 */
1113static void heap_init(uint32_t heap_start);
1214/**
···1618 */
1719typedef struct heap_segment
1820{
1919- struct heap_segment *next;
2020- struct heap_segment *prev;
2121- uint32_t is_allocated;
2222- uint32_t segment_size; // Includes this header
2323-} heap_segment_t;
2121+ struct heap_segment
2222+ *next; /**< pointer to the next segment in the linked list */
2323+ struct heap_segment
2424+ *prev; /**< pointer to the previous segment in the linked list */
2525+ uint32_t is_allocated; /**< 1 if the segment is allocated, 0 if it's free */
2626+ uint32_t segment_size; /**< size of the segment, including the header */
2727+} heap_segment_t; /**< Heap segment */
24282525-static heap_segment_t *heap_segment_list_head;
2626-/**
2727- * End Heap Stuff
2828- */
2929+static heap_segment_t
3030+ *heap_segment_list_head; /**< Head of the heap segment list */
29313030-extern uint8_t __end;
3131-static uint32_t num_pages;
3232+extern uint8_t __end; /**< Defined by the linker */
3333+static uint32_t num_pages; /**< Number of pages in the system */
32343335IMPLEMENT_LIST(page);
34363535-static page_t *all_pages_array;
3636-page_list_t free_pages;
3737+static page_t *all_pages_array; /**< Array of all pages in the system */
3838+page_list_t free_pages; /**< List of all free pages in the system */
37393840void mem_init(atag_t *atags)
3941{