From 80ab489828b8d06d6bb777f73357654442689bff Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 26 Jul 2020 15:38:29 -0500 Subject: [PATCH] Add libc documentaion + libc cleanup --- .github/workflows/main.yml | 7 +- .gitignore | 1 + Makefile | 2 + docindex.html | 1 + libc/ActionDoxyfile | 14 ++ libc/Doxyfile | 17 +++ libc/ctype.h | 9 ++ libc/dbg.h | 9 ++ libc/devbuf.c | 38 ----- libc/devbuf.h | 16 --- libc/elf.h | 1 + libc/errno.h | 17 ++- libc/grub/multiboot.h | 274 ------------------------------------- libc/grub/multiboot2.h | 3 + libc/initrd.h | 15 +- libc/ipc/devfs.h | 21 --- libc/ipc/vfs.h | 31 ----- libc/klog.h | 6 - libc/math.h | 15 ++ libc/memory.h | 45 +++++- libc/pthread.h | 16 ++- libc/stdlib.c | 43 ++++-- libc/stdlib.h | 30 +++- libc/string.h | 67 ++++++++- libc/tasking.h | 42 +++++- libc/unistd.h | 16 ++- libc/vfs.h | 7 - 27 files changed, 344 insertions(+), 419 deletions(-) create mode 100644 libc/ActionDoxyfile create mode 100644 libc/Doxyfile delete mode 100644 libc/devbuf.c delete mode 100644 libc/devbuf.h delete mode 100644 libc/grub/multiboot.h delete mode 100644 libc/ipc/devfs.h delete mode 100644 libc/ipc/vfs.h delete mode 100644 libc/klog.h delete mode 100644 libc/vfs.h diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a22bf2e..e9f1648 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,9 +27,12 @@ jobs: uses: mattnotmitt/doxygen-action@v1.1.0 with: doxyfile-path: "./kernel/ActionDoxyfile" + - name: Generate libc docs + uses: mattnotmitt/doxygen-action@v1.1.0 + with: + doxyfile-path: "./libc/ActionDoxyfile" - name: Put files in the right place - run: sudo mv kernel/docs/html docsite/kernel; sudo cp docindex.html docsite/index.html - + run: sudo mv kernel/docs/html docsite/kernel; sudo mv libc/docs/html docsite/libc; sudo cp docindex.html docsite/index.html - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.gitignore b/.gitignore index ac5ee6a..10c025b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ vga_drv/vga_drv .vscode kernel/docs sysroot/usr/share/man +libc/docs diff --git a/Makefile b/Makefile index bd8432b..615a3bc 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ sysroot/usr/lib/libc.a: $(LIBC_OBJ) sysroot/usr/share/man: doc @ cp -r kernel/docs/man/man9 sysroot/usr/share/man + @ cp -r libc/docs/man/man3 sysroot/usr/share/man sysroot/usr/include: $(LIBC_SOURCES) $(LIBC_HEADERS) @ cd libc;rsync -R *.h */*.h ../sysroot/usr/include/ @@ -96,3 +97,4 @@ clean: doc: $(C_SOURCES) $(C_HEADERS) @doxygen kernel/Doxyfile > /dev/null + @doxygen libc/Doxyfile > /dev/null diff --git a/docindex.html b/docindex.html index a78a4e6..1585e59 100644 --- a/docindex.html +++ b/docindex.html @@ -10,5 +10,6 @@

Kernel Documentation

+

Libc Documentation

diff --git a/libc/ActionDoxyfile b/libc/ActionDoxyfile new file mode 100644 index 0000000..4d94428 --- /dev/null +++ b/libc/ActionDoxyfile @@ -0,0 +1,14 @@ +PROJECT_NAME = "MyOS Kernel" +OUTPUT_DIRECTORY = ./libc/docs +OPTIMIZE_OUTPUT_FOR_C = YES +TYPEDEF_HIDES_STRUCT = YES +EXTRACT_STATIC = YES +WARN_NO_PARAMDOC = YES +INPUT = ./libc +RECURSIVE = YES +EXCLUDE = elf.h grub/multiboot2.h +HTML_DYNAMIC_SECTIONS = YES +GENERATE_TREEVIEW = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +PREDEFINED = __attribute__(x)= DOXYGEN_SHOULD_SKIP_THIS= diff --git a/libc/Doxyfile b/libc/Doxyfile new file mode 100644 index 0000000..326bb83 --- /dev/null +++ b/libc/Doxyfile @@ -0,0 +1,17 @@ +PROJECT_NAME = "MyOS Libc" +OUTPUT_DIRECTORY = ./libc/docs +OPTIMIZE_OUTPUT_FOR_C = YES +TYPEDEF_HIDES_STRUCT = YES +EXTRACT_STATIC = YES +WARN_NO_PARAMDOC = YES +INPUT = /Users/peterterpstra/Desktop/projects/os/libc +RECURSIVE = YES +EXCLUDE = libc/elf.h libc/grub/multiboot2.h +HTML_DYNAMIC_SECTIONS = YES +GENERATE_TREEVIEW = YES +GENERATE_MAN = YES +MAN_EXTENSION = .3 +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +PREDEFINED = __attribute__(x)= DOXYGEN_SHOULD_SKIP_THIS= +HAVE_DOT = YES diff --git a/libc/ctype.h b/libc/ctype.h index 18aa9e9..98b00df 100644 --- a/libc/ctype.h +++ b/libc/ctype.h @@ -1,6 +1,15 @@ +/** + * \file +*/ + #ifndef CTYPE_H #define CTYPE_H +/** + * Checks whether a character is an ascii digit + * \param c The character to check + * \return 0 if the character is a digit +*/ int isdigit(int c); #endif diff --git a/libc/dbg.h b/libc/dbg.h index 5b564b1..edec373 100644 --- a/libc/dbg.h +++ b/libc/dbg.h @@ -1,6 +1,15 @@ +/** + * \file +*/ + + #ifndef DBG_H #define DBG_H +/** + * Prints a string to the kernel serial console + * \param str The string to print +*/ void serial_print(char* str); #endif diff --git a/libc/devbuf.c b/libc/devbuf.c deleted file mode 100644 index 5e100fe..0000000 --- a/libc/devbuf.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include - -devbuf* devbuf_init() { - devbuf* buf=malloc(sizeof(devbuf)); - buf->rd=0; - buf->wr=0; - for (int i=0;i<256;i++) { - buf->buf[i]=EOF; - } - return buf; -} - -void devbuf_add(char byte,devbuf* buf) { - buf->buf[buf->wr]=byte; - buf->wr++; - if (buf->wr==buf->rd) { - buf->wr--; - } -} - -int devbuf_get(devbuf* buf) { - if (buf->buf[buf->rd]==-1) { - buf->rd++; - if (buf->buf[buf->rd]==-1) { - buf->rd--; - while (buf->buf[buf->rd]==-1); - } - } - int data=buf->buf[buf->rd]; - buf->buf[buf->rd]=-1; - buf->rd++; - if (buf->rd>buf->wr) { - buf->rd=buf->wr-1; - } - return data; -} diff --git a/libc/devbuf.h b/libc/devbuf.h deleted file mode 100644 index 785e978..0000000 --- a/libc/devbuf.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DEVBUF_H -#define DEVBUF_H - -#include - -typedef struct { - int buf[256]; - uint8_t rd; - uint8_t wr; -} devbuf; - -devbuf* devbuf_init(); -void devbuf_add(char byte,devbuf* buf); -int devbuf_get(devbuf* buf); - -#endif diff --git a/libc/elf.h b/libc/elf.h index 639a2d8..4486a80 100644 --- a/libc/elf.h +++ b/libc/elf.h @@ -4,6 +4,7 @@ #include + typedef struct { uint32_t magic; char type; diff --git a/libc/errno.h b/libc/errno.h index 07b32a3..88ba47a 100644 --- a/libc/errno.h +++ b/libc/errno.h @@ -1,8 +1,19 @@ +/** + * \file +*/ + #ifndef ERRNO_H #define ERRNO_H -#define errno (*(__get_errno_address())) -int* __get_errno_address(); +#define errno (*(__get_errno_address())) //!< wrapper around __get_errno_address to provide the errno variable +/** + * Gets the address of errno for the current thread. + * \note This is an internal function. DO NOT CALL THIS DIRECTLY + * \return the address of errno for the current thread +*/ +int* __get_errno_address(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS #define E2BIG 1 #define EACCES 2 @@ -87,3 +98,5 @@ int* __get_errno_address(); #define EXDEV 81 #endif + +#endif diff --git a/libc/grub/multiboot.h b/libc/grub/multiboot.h deleted file mode 100644 index 9d7fc53..0000000 --- a/libc/grub/multiboot.h +++ /dev/null @@ -1,274 +0,0 @@ -/* multiboot.h - Multiboot header file. */ -/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to -* deal in the Software without restriction, including without limitation the -* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -* sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY -* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - - #ifndef MULTIBOOT_HEADER - #define MULTIBOOT_HEADER 1 - - /* How many bytes from the start of the file we search for the header. */ - #define MULTIBOOT_SEARCH 8192 - #define MULTIBOOT_HEADER_ALIGN 4 - - /* The magic field should contain this. */ - #define MULTIBOOT_HEADER_MAGIC 0x1BADB002 - - /* This should be in %eax. */ - #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 - - /* Alignment of multiboot modules. */ - #define MULTIBOOT_MOD_ALIGN 0x00001000 - - /* Alignment of the multiboot info structure. */ - #define MULTIBOOT_INFO_ALIGN 0x00000004 - - /* Flags set in the 'flags' member of the multiboot header. */ - - /* Align all boot modules on i386 page (4KB) boundaries. */ - #define MULTIBOOT_PAGE_ALIGN 0x00000001 - - /* Must pass memory information to OS. */ - #define MULTIBOOT_MEMORY_INFO 0x00000002 - - /* Must pass video information to OS. */ - #define MULTIBOOT_VIDEO_MODE 0x00000004 - - /* This flag indicates the use of the address fields in the header. */ - #define MULTIBOOT_AOUT_KLUDGE 0x00010000 - - /* Flags to be set in the 'flags' member of the multiboot info structure. */ - - /* is there basic lower/upper memory information? */ - #define MULTIBOOT_INFO_MEMORY 0x00000001 - /* is there a boot device set? */ - #define MULTIBOOT_INFO_BOOTDEV 0x00000002 - /* is the command-line defined? */ - #define MULTIBOOT_INFO_CMDLINE 0x00000004 - /* are there modules to do something with? */ - #define MULTIBOOT_INFO_MODS 0x00000008 - - /* These next two are mutually exclusive */ - - /* is there a symbol table loaded? */ - #define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 - /* is there an ELF section header table? */ - #define MULTIBOOT_INFO_ELF_SHDR 0X00000020 - - /* is there a full memory map? */ - #define MULTIBOOT_INFO_MEM_MAP 0x00000040 - - /* Is there drive info? */ - #define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 - - /* Is there a config table? */ - #define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 - - /* Is there a boot loader name? */ - #define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 - - /* Is there a APM table? */ - #define MULTIBOOT_INFO_APM_TABLE 0x00000400 - - /* Is there video information? */ - #define MULTIBOOT_INFO_VBE_INFO 0x00000800 - #define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 - - #ifndef ASM_FILE - - typedef unsigned char multiboot_uint8_t; - typedef unsigned short multiboot_uint16_t; - typedef unsigned int multiboot_uint32_t; - typedef unsigned long long multiboot_uint64_t; - - struct multiboot_header - { - /* Must be MULTIBOOT_MAGIC - see above. */ - multiboot_uint32_t magic; - - /* Feature flags. */ - multiboot_uint32_t flags; - - /* The above fields plus this one must equal 0 mod 2^32. */ - multiboot_uint32_t checksum; - - /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ - multiboot_uint32_t header_addr; - multiboot_uint32_t load_addr; - multiboot_uint32_t load_end_addr; - multiboot_uint32_t bss_end_addr; - multiboot_uint32_t entry_addr; - - /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ - multiboot_uint32_t mode_type; - multiboot_uint32_t width; - multiboot_uint32_t height; - multiboot_uint32_t depth; - }; - - /* The symbol table for a.out. */ - struct multiboot_aout_symbol_table - { - multiboot_uint32_t tabsize; - multiboot_uint32_t strsize; - multiboot_uint32_t addr; - multiboot_uint32_t reserved; - }; - typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; - - /* The section header table for ELF. */ - struct multiboot_elf_section_header_table - { - multiboot_uint32_t num; - multiboot_uint32_t size; - multiboot_uint32_t addr; - multiboot_uint32_t shndx; - }; - typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; - - struct multiboot_info - { - /* Multiboot info version number */ - multiboot_uint32_t flags; - - /* Available memory from BIOS */ - multiboot_uint32_t mem_lower; - multiboot_uint32_t mem_upper; - - /* "root" partition */ - multiboot_uint32_t boot_device; - - /* Kernel command line */ - multiboot_uint32_t cmdline; - - /* Boot-Module list */ - multiboot_uint32_t mods_count; - multiboot_uint32_t mods_addr; - - union - { - multiboot_aout_symbol_table_t aout_sym; - multiboot_elf_section_header_table_t elf_sec; - } u; - - /* Memory Mapping buffer */ - multiboot_uint32_t mmap_length; - multiboot_uint32_t mmap_addr; - - /* Drive Info buffer */ - multiboot_uint32_t drives_length; - multiboot_uint32_t drives_addr; - - /* ROM configuration table */ - multiboot_uint32_t config_table; - - /* Boot Loader Name */ - multiboot_uint32_t boot_loader_name; - - /* APM table */ - multiboot_uint32_t apm_table; - - /* Video */ - multiboot_uint32_t vbe_control_info; - multiboot_uint32_t vbe_mode_info; - multiboot_uint16_t vbe_mode; - multiboot_uint16_t vbe_interface_seg; - multiboot_uint16_t vbe_interface_off; - multiboot_uint16_t vbe_interface_len; - - multiboot_uint64_t framebuffer_addr; - multiboot_uint32_t framebuffer_pitch; - multiboot_uint32_t framebuffer_width; - multiboot_uint32_t framebuffer_height; - multiboot_uint8_t framebuffer_bpp; - #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 - #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 - #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 - multiboot_uint8_t framebuffer_type; - union - { - struct - { - multiboot_uint32_t framebuffer_palette_addr; - multiboot_uint16_t framebuffer_palette_num_colors; - }; - struct - { - multiboot_uint8_t framebuffer_red_field_position; - multiboot_uint8_t framebuffer_red_mask_size; - multiboot_uint8_t framebuffer_green_field_position; - multiboot_uint8_t framebuffer_green_mask_size; - multiboot_uint8_t framebuffer_blue_field_position; - multiboot_uint8_t framebuffer_blue_mask_size; - }; - }; - }; - typedef struct multiboot_info multiboot_info_t; - - struct multiboot_color - { - multiboot_uint8_t red; - multiboot_uint8_t green; - multiboot_uint8_t blue; - }; - - struct multiboot_mmap_entry - { - multiboot_uint32_t size; - multiboot_uint64_t addr; - multiboot_uint64_t len; - #define MULTIBOOT_MEMORY_AVAILABLE 1 - #define MULTIBOOT_MEMORY_RESERVED 2 - #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 - #define MULTIBOOT_MEMORY_NVS 4 - #define MULTIBOOT_MEMORY_BADRAM 5 - multiboot_uint32_t type; - } __attribute__((packed)); - typedef struct multiboot_mmap_entry multiboot_memory_map_t; - - struct multiboot_mod_list - { - /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ - multiboot_uint32_t mod_start; - multiboot_uint32_t mod_end; - - /* Module command line */ - multiboot_uint32_t cmdline; - - /* padding to take it to 16 bytes (must be zero) */ - multiboot_uint32_t pad; - }; - typedef struct multiboot_mod_list multiboot_module_t; - - /* APM BIOS info. */ - struct multiboot_apm_info - { - multiboot_uint16_t version; - multiboot_uint16_t cseg; - multiboot_uint32_t offset; - multiboot_uint16_t cseg_16; - multiboot_uint16_t dseg; - multiboot_uint16_t flags; - multiboot_uint16_t cseg_len; - multiboot_uint16_t cseg_16_len; - multiboot_uint16_t dseg_len; - }; - - #endif /* ! ASM_FILE */ - - #endif /* ! MULTIBOOT_HEADER */ diff --git a/libc/grub/multiboot2.h b/libc/grub/multiboot2.h index 2318334..2b8ea0f 100644 --- a/libc/grub/multiboot2.h +++ b/libc/grub/multiboot2.h @@ -1,3 +1,4 @@ +#ifndef DOXYGEN_SHOULD_SKIP_THIS /* multiboot2.h - Multiboot 2 header file. */ /* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. * @@ -422,3 +423,5 @@ struct multiboot_tag_load_base_addr #endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ + +#endif /* ! DOXYGEN_SHOULD_SKIP_THIS */ diff --git a/libc/initrd.h b/libc/initrd.h index f497047..e547ad2 100644 --- a/libc/initrd.h +++ b/libc/initrd.h @@ -1,7 +1,20 @@ +/** + * \file +*/ + #ifndef INITRD_H #define INITRD_H -long initrd_sz(); + +/** + * Gets the size of the initrd + * \return the size of the initrd +*/ +long initrd_sz(); +/** + * Copies the initrd to a specified area in memory + * \param initrd the address to copy the initrd to +*/ void initrd_get(char* initrd); #endif diff --git a/libc/ipc/devfs.h b/libc/ipc/devfs.h deleted file mode 100644 index 67cfcfc..0000000 --- a/libc/ipc/devfs.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef DEVFS_H -#define DEVFS_H - -typedef enum { - DEVFS_REGISTER -} devfs_msg_type; - -typedef enum { - DEV_GLOBAL, - DEV_INDIVIDUAL -} devfs_dev_type; - - -typedef struct { - int msg_type; - int dev_type; - uint32_t mbox; - char name[128]; -} devfs_message; - -#endif diff --git a/libc/ipc/vfs.h b/libc/ipc/vfs.h deleted file mode 100644 index bbdd6b0..0000000 --- a/libc/ipc/vfs.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef IPC_VFS_H -#define IPC_VFS_H - -#include - -typedef enum { - VFS_OPEN, - VFS_PUTS, - VFS_GETS, - VFS_CLOSE, - VFS_REGISTER_FS, - VFS_MOUNT, - VFS_UMOUNT, - VFS_SEEK -} vfs_message_type; - -typedef struct { - char flags; - vfs_message_type type; - uint8_t id; - char mode[10]; - uint32_t fd; - uint32_t pos; - int data; - char in_progress; - uint32_t orig_mbox; - void* fs_data; - char path[4096]; -} __attribute__((packed)) vfs_message; - -#endif diff --git a/libc/klog.h b/libc/klog.h deleted file mode 100644 index 910dd9a..0000000 --- a/libc/klog.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef KLOG_H -#define KLOG_H - -void klog(char* level,char* s,...); - -#endif diff --git a/libc/math.h b/libc/math.h index a002811..9ff2bc4 100644 --- a/libc/math.h +++ b/libc/math.h @@ -1,7 +1,22 @@ +/** + * \file +*/ + #ifndef MATH_H #define MATH_H +/** + * Round a float to the next biggist integer if it is non-integral + * \param num the number to round + * \returns the rounded number +*/ float ceilf(float num); + +/** + * Round a double to the next biggist integer if it is non-integral + * \param num the number to round + * \returns the rounded number +*/ double ceil(double num); #endif diff --git a/libc/memory.h b/libc/memory.h index c1fa232..a7ce241 100644 --- a/libc/memory.h +++ b/libc/memory.h @@ -1,15 +1,58 @@ +/** + * \file +*/ + #ifndef MEMORY_H #define MEMORY_H #include -#define BLK_SZ 4096 +#define BLK_SZ 4096 //!< Page size of the architecture +/** + * Allocates pages of memory + * \param num_pages The number of pages to allocate + * \return the start address of the pages +*/ void* alloc_memory(int num_pages); + +/** + * Allocates pages of memory at a specified start address + * \param num_pages The number of pages to allocate + * \param addr The start address of the pages +*/ void alloc_memory_virt(int num_pages,void* addr); + +/** + * Creates a new address space with kernel mappings + * \return a pointer to the new address space in physical memory +*/ void* new_address_space(); + +/** + * Copy data into an address space at a specified virtual address + * \param cr3 The adress space to copy data to. + * \param data The data to copy + * \param size The size of the data + * \param virt_addr The address to copy the data to in the address space +*/ void copy_data(void* cr3, void* data,size_t size,void* virt_addr); + +/** + * Put data into an address space at an unknown virtual address + * \param cr3 The adress space to copy data to. + * \param data The data to copy + * \param size The size of the data + * \return The address that the data was copied to. +*/ void* put_data(void* cr3, void* data,size_t size); + +/** + * Map physical pages into virtual memory + * \param phys_addr the start of the physical memory block to map + * \param num_pages the number of pages to map + * \return the start address of the mapping in virtual memory +*/ void* map_phys(void* phys_addr,size_t num_pages); #endif diff --git a/libc/pthread.h b/libc/pthread.h index 56ce60e..f9cf289 100644 --- a/libc/pthread.h +++ b/libc/pthread.h @@ -1,11 +1,23 @@ +/** + * \file +*/ + #ifndef PTHREAD_H #define PTHREAD_H #include -typedef pid_t pthread_t; -typedef int pthread_attr_t; //Created as dummy +typedef pid_t pthread_t; //!< Represents a thread +typedef int pthread_attr_t; //!< Created as dummy +/** + * Create a thread in the current process + * \param thread A pointer to a pthread_t where the created thread will be placed + * \param attr Either a pointer to a thread attribute structure, or NULL, in which case the default attributes will be used + * \param start_routine The start function of the thread + * \param arg An arhument to the start function + * \return 0 if creation was sucsessful, 1 otherwise +*/ int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void*), void *restrict arg); diff --git a/libc/stdlib.c b/libc/stdlib.c index 8f37e3c..d940661 100644 --- a/libc/stdlib.c +++ b/libc/stdlib.c @@ -1,22 +1,35 @@ +/** + * \file +*/ + #include #include #include #include -#define MAX_BLOCKS 512 +#define MAX_BLOCKS 512 //!< Maximum number of blocks that can be used +/** + * Represents a contiguos block in the heap +*/ typedef struct { - char* bitmap; - size_t bitmap_byt_size; - size_t bitmap_bit_size; - size_t avail_data_size; - void* data_block; + char* bitmap; //!< Bitmap of avilable four byte groups + size_t bitmap_byt_size; //!< Size of the bitmap in bytes + size_t bitmap_bit_size; //!< Size of the bitmap in bits + size_t avail_data_size; //!< Size of the data block + void* data_block; //!< Data block } heap_block; -static heap_block entries[MAX_BLOCKS]; -static size_t num_used_entries=0; +static heap_block entries[MAX_BLOCKS]; //!< List of blocks in the heap +static size_t num_used_entries=0; //!< Number of blocks in the heap +/** + * Get a bit in a bitmap + * \param bmap The bitmap + * \param index The index in the bitmap + * \return the bit +*/ static char get_bmap_bit(char* bmap,size_t index) { size_t byte=index/8; size_t bit=index%8; @@ -24,18 +37,32 @@ static char get_bmap_bit(char* bmap,size_t index) { return (entry&(1<0; } +/** + * Set a bit in a bitmap + * \param bmap The bitmap + * \param index The index in the bitmap +*/ static void set_bmap_bit(char* bmap,size_t index) { size_t byte=index/8; size_t bit=index%8; bmap[byte]=bmap[byte]|(1< -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 //!< Success exit code +#define EXIT_FAILURE 1 //!< Failure exit code +/** + * Allocates a block of memory on the heap + * \param size The size of the block to allocate + * \return The address of the allocated block, or NUL if the allocation failed +*/ void* malloc(size_t size); +/** + * Changes a block of memory on the heap to a new size, or if mem is NULL, act like malloc + * \param mem The block of memory to change size + * \param new_sz The size of the block to allocate + * \return The new address of the allocated block, or NUL if the allocation failed +*/ void* realloc(void *mem, size_t new_sz); + +/** + * Frees a block of memory on the heap + * \param mem The block of memory to free +*/ void free(void* mem); +#ifndef DOXYGEN_SHOULD_SKIP_THIS void abort(void); // GCC required int atexit(void (*func)(void)); // GCC required int atoi(const char *str); // GCC required char *getenv(const char *name); // GCC required +#endif +/** + * Exit the process + * \param code The exit code of the process +*/ __attribute__((noreturn)) void exit(int code); #endif diff --git a/libc/string.h b/libc/string.h index 0e5ff5b..b77a61c 100644 --- a/libc/string.h +++ b/libc/string.h @@ -1,17 +1,82 @@ +/** + * \file +*/ + #ifndef STRING_H #define STRING_H #include +/** + * Copies a block of memory from one address to another + * \param dest The destination address + * \param src The source address + * \param len The length of the block + * \return the destination address +*/ void* memcpy(void* dest,const void* src,size_t len); +/** + * Sets a block of memory to a byte + * \param dest The block to set + * \param val The byte to set it to + * \param len The length of the block + * \return the destination address +*/ void* memset(void* dest,int val,size_t len); +/** + * Compares two strings + * \param s1 String 1 to compare + * \param s2 String 2 to compare + * \return 0 if the strings are the same, otherwise the difference between the values of the first non-identical character +*/ int strcmp(const char* s1,const char* s2); +/** + * Gets the length of a string + * \param str The string to get the length of + * \return the length of the string +*/ size_t strlen(const char* str); +/** + * Copies a string from one address to another + * \param dest The destination string + * \param src The source string + * \return the destination string +*/ char* strcpy(char* dest,const char* src); +/** + * Reads characters from a string until it hits a delimeter character + * \param str The string to read from (or NULL if you are continuing tokenization) + * \param delim A stribg containing possible delimeter characters. + * \return the read characters, not including the delmimeter. This string will be overwritten by sucessive calls to strtok. +*/ char* strtok(const char* str, const char* delim); - +/** + * Reverses a string in place + * \param str The string to reverse + * \return the string +*/ char* strrev(char *str); +/** + * Converts a number to a base 10 string + * \param n The number to convert + * \param str A buffer to hold the converted number +*/ void int_to_ascii(int n,char* str); +/** + * Converts a number to a base 16 string + * \param n The number to convert + * \param str A buffer to hold the converted number +*/ void hex_to_ascii(unsigned int n, char* str); +/** + * Appends a character to a string + * \param s The string + * \param n The character to append +*/ void append(char* s, char n); +/** + * Deletes the last character of a string + * \param s The string +*/ void backspace(char* s); + #endif diff --git a/libc/tasking.h b/libc/tasking.h index 8eb290a..c14de9d 100644 --- a/libc/tasking.h +++ b/libc/tasking.h @@ -1,3 +1,7 @@ +/** + * \file +*/ + #ifndef TASKING_H #define TASKING_H @@ -5,21 +9,47 @@ #include #ifndef KERN_TASKING_H +/** + * Represents the state of a thread +*/ typedef enum thread_state { - THREAD_RUNNING, - THREAD_READY, - THREAD_EXITED, - THREAD_BLOCKED + THREAD_RUNNING, //!< The state of a running thread + THREAD_READY, //!< The state of a ready to run thread + THREAD_EXITED, //!< The state of an exited thread + THREAD_BLOCKED //!< The state of a generically blocked thread } thread_state; #endif +/** + * Yield the CPU to another process +*/ void yield(); -void yieldToPID(pid_t pid); + +/** + * Create a process + * \param start The start function of the process + * \param cr3 The address space of the process +*/ void createProcCr3(void* start,void* cr3); +/** + * Create a process with 2 arguments + * \param start The start function of the process + * \param cr3 The address space of the process + * \param param1 The first parameter of the process + * \param param2 The second parameter of the process +*/ void createProcCr3Param(void* start,void* cr3,void* param1,void* param2); -char isPrivleged(pid_t pid); +/** + * Block the current thread + * \param state The state to block it with +*/ void blockThread(thread_state state); +/** + * Unblock a thread in a process + * \param pid The PID of the thread's process + * \param tid The TID of the thread +*/ void unblockThread(pid_t pid,pid_t tid); diff --git a/libc/unistd.h b/libc/unistd.h index 1b47b67..ea52cc6 100644 --- a/libc/unistd.h +++ b/libc/unistd.h @@ -1,12 +1,26 @@ +/** + * \file +*/ + #ifndef UNISTD_H #define UNISTD_H #include +#ifndef DOXYGEN_SHOULD_SKIP_THIS + pid_t fork(void); // GCC required int execv(const char* path, char* const argv[]); // GCC required int execve(const char* path, char* const argv[], char* const envp[]); // GCC required int execvp(const char* file, char* const argv[]); // GCC required -pid_t getpid(); + +#endif + +/** + * Gets the current process's PID + * \return the current process's PID +*/ +pid_t getpid(); + #endif diff --git a/libc/vfs.h b/libc/vfs.h deleted file mode 100644 index e7c45d7..0000000 --- a/libc/vfs.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef VFS_H -#define VFS_H - -void register_fs(const char* name,uint32_t mbox); -void mount(char* file,char* type,char* path); - -#endif