Add libc documentaion + libc cleanup

This commit is contained in:
pjht 2020-07-26 15:38:29 -05:00
parent f7a6d95cc9
commit 80ab489828
27 changed files with 344 additions and 419 deletions

View File

@ -27,9 +27,12 @@ jobs:
uses: mattnotmitt/doxygen-action@v1.1.0 uses: mattnotmitt/doxygen-action@v1.1.0
with: with:
doxyfile-path: "./kernel/ActionDoxyfile" 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 - 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 - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ vga_drv/vga_drv
.vscode .vscode
kernel/docs kernel/docs
sysroot/usr/share/man sysroot/usr/share/man
libc/docs

View File

@ -73,6 +73,7 @@ sysroot/usr/lib/libc.a: $(LIBC_OBJ)
sysroot/usr/share/man: doc sysroot/usr/share/man: doc
@ cp -r kernel/docs/man/man9 sysroot/usr/share/man @ 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) sysroot/usr/include: $(LIBC_SOURCES) $(LIBC_HEADERS)
@ cd libc;rsync -R *.h */*.h ../sysroot/usr/include/ @ cd libc;rsync -R *.h */*.h ../sysroot/usr/include/
@ -96,3 +97,4 @@ clean:
doc: $(C_SOURCES) $(C_HEADERS) doc: $(C_SOURCES) $(C_HEADERS)
@doxygen kernel/Doxyfile > /dev/null @doxygen kernel/Doxyfile > /dev/null
@doxygen libc/Doxyfile > /dev/null

View File

@ -10,5 +10,6 @@
</head> </head>
<body> <body>
<h1><a href="kernel/index.html">Kernel Documentation</a></h1> <h1><a href="kernel/index.html">Kernel Documentation</a></h1>
<h1><a href="libc/index.html">Libc Documentation</a></h1>
</body> </body>
</html> </html>

14
libc/ActionDoxyfile Normal file
View File

@ -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=

17
libc/Doxyfile Normal file
View File

@ -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

View File

@ -1,6 +1,15 @@
/**
* \file
*/
#ifndef CTYPE_H #ifndef CTYPE_H
#define 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); int isdigit(int c);
#endif #endif

View File

@ -1,6 +1,15 @@
/**
* \file
*/
#ifndef DBG_H #ifndef DBG_H
#define DBG_H #define DBG_H
/**
* Prints a string to the kernel serial console
* \param str The string to print
*/
void serial_print(char* str); void serial_print(char* str);
#endif #endif

View File

@ -1,38 +0,0 @@
#include <devbuf.h>
#include <stdio.h>
#include <stdlib.h>
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;
}

View File

@ -1,16 +0,0 @@
#ifndef DEVBUF_H
#define DEVBUF_H
#include <stdint.h>
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

View File

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
typedef struct { typedef struct {
uint32_t magic; uint32_t magic;
char type; char type;

View File

@ -1,9 +1,20 @@
/**
* \file
*/
#ifndef ERRNO_H #ifndef ERRNO_H
#define ERRNO_H #define ERRNO_H
#define errno (*(__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(); int* __get_errno_address();
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define E2BIG 1 #define E2BIG 1
#define EACCES 2 #define EACCES 2
#define EADDRINUSE 3 #define EADDRINUSE 3
@ -87,3 +98,5 @@ int* __get_errno_address();
#define EXDEV 81 #define EXDEV 81
#endif #endif
#endif

View File

@ -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 */

View File

@ -1,3 +1,4 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* multiboot2.h - Multiboot 2 header file. */ /* multiboot2.h - Multiboot 2 header file. */
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. /* 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 /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */ #endif /* ! MULTIBOOT_HEADER */
#endif /* ! DOXYGEN_SHOULD_SKIP_THIS */

View File

@ -1,7 +1,20 @@
/**
* \file
*/
#ifndef INITRD_H #ifndef INITRD_H
#define INITRD_H #define INITRD_H
/**
* Gets the size of the initrd
* \return the size of the initrd
*/
long initrd_sz(); 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); void initrd_get(char* initrd);
#endif #endif

View File

@ -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

View File

@ -1,31 +0,0 @@
#ifndef IPC_VFS_H
#define IPC_VFS_H
#include <stdint.h>
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

View File

@ -1,6 +0,0 @@
#ifndef KLOG_H
#define KLOG_H
void klog(char* level,char* s,...);
#endif

View File

@ -1,7 +1,22 @@
/**
* \file
*/
#ifndef MATH_H #ifndef MATH_H
#define 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); 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); double ceil(double num);
#endif #endif

View File

@ -1,15 +1,58 @@
/**
* \file
*/
#ifndef MEMORY_H #ifndef MEMORY_H
#define MEMORY_H #define MEMORY_H
#include <stddef.h> #include <stddef.h>
#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); 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); 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(); 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); 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); 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); void* map_phys(void* phys_addr,size_t num_pages);
#endif #endif

View File

@ -1,11 +1,23 @@
/**
* \file
*/
#ifndef PTHREAD_H #ifndef PTHREAD_H
#define PTHREAD_H #define PTHREAD_H
#include <sys/types.h> #include <sys/types.h>
typedef pid_t pthread_t; typedef pid_t pthread_t; //!< Represents a thread
typedef int pthread_attr_t; //Created as dummy 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, int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr, const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg); void *(*start_routine)(void*), void *restrict arg);

View File

@ -1,22 +1,35 @@
/**
* \file
*/
#include <math.h> #include <math.h>
#include <memory.h> #include <memory.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#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 { typedef struct {
char* bitmap; char* bitmap; //!< Bitmap of avilable four byte groups
size_t bitmap_byt_size; size_t bitmap_byt_size; //!< Size of the bitmap in bytes
size_t bitmap_bit_size; size_t bitmap_bit_size; //!< Size of the bitmap in bits
size_t avail_data_size; size_t avail_data_size; //!< Size of the data block
void* data_block; void* data_block; //!< Data block
} heap_block; } heap_block;
static heap_block entries[MAX_BLOCKS]; static heap_block entries[MAX_BLOCKS]; //!< List of blocks in the heap
static size_t num_used_entries=0; 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) { static char get_bmap_bit(char* bmap,size_t index) {
size_t byte=index/8; size_t byte=index/8;
size_t bit=index%8; size_t bit=index%8;
@ -24,18 +37,32 @@ static char get_bmap_bit(char* bmap,size_t index) {
return (entry&(1<<bit))>0; return (entry&(1<<bit))>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) { static void set_bmap_bit(char* bmap,size_t index) {
size_t byte=index/8; size_t byte=index/8;
size_t bit=index%8; size_t bit=index%8;
bmap[byte]=bmap[byte]|(1<<bit); bmap[byte]=bmap[byte]|(1<<bit);
} }
/**
* Clear a bit in a bitmap
* \param bmap The bitmap
* \param index The index in the bitmap
*/
static void clear_bmap_bit(char* bmap,size_t index) { static void clear_bmap_bit(char* bmap,size_t index) {
size_t byte=index/8; size_t byte=index/8;
size_t bit=index%8; size_t bit=index%8;
bmap[byte]=bmap[byte]&(~(1<<bit)); bmap[byte]=bmap[byte]&(~(1<<bit));
} }
/**
* Add a block to the heap
* \param mem_blks The number of pages that this block will use
*/
static void reserve_block(size_t mem_blks) { static void reserve_block(size_t mem_blks) {
size_t bmap_byts=((mem_blks*BLK_SZ)/4)/8; size_t bmap_byts=((mem_blks*BLK_SZ)/4)/8;
entries[num_used_entries].bitmap=alloc_memory((size_t)ceilf((double)bmap_byts/BLK_SZ)); entries[num_used_entries].bitmap=alloc_memory((size_t)ceilf((double)bmap_byts/BLK_SZ));

View File

@ -1,18 +1,44 @@
/**
* \file
*/
#ifndef STDLIB_H #ifndef STDLIB_H
#define STDLIB_H #define STDLIB_H
#include <stddef.h> #include <stddef.h>
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0 //!< Success exit code
#define EXIT_FAILURE 1 #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); 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); 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); void free(void* mem);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
void abort(void); // GCC required void abort(void); // GCC required
int atexit(void (*func)(void)); // GCC required int atexit(void (*func)(void)); // GCC required
int atoi(const char *str); // GCC required int atoi(const char *str); // GCC required
char *getenv(const char *name); // 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); __attribute__((noreturn)) void exit(int code);
#endif #endif

View File

@ -1,17 +1,82 @@
/**
* \file
*/
#ifndef STRING_H #ifndef STRING_H
#define STRING_H #define STRING_H
#include <stddef.h> #include <stddef.h>
/**
* 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); void append(char* s, char n);
/**
* Deletes the last character of a string
* \param s The string
*/
void backspace(char* s); void backspace(char* s);
#endif #endif

View File

@ -1,3 +1,7 @@
/**
* \file
*/
#ifndef TASKING_H #ifndef TASKING_H
#define TASKING_H #define TASKING_H
@ -5,21 +9,47 @@
#include <sys/types.h> #include <sys/types.h>
#ifndef KERN_TASKING_H #ifndef KERN_TASKING_H
/**
* Represents the state of a thread
*/
typedef enum thread_state { typedef enum thread_state {
THREAD_RUNNING, THREAD_RUNNING, //!< The state of a running thread
THREAD_READY, THREAD_READY, //!< The state of a ready to run thread
THREAD_EXITED, THREAD_EXITED, //!< The state of an exited thread
THREAD_BLOCKED THREAD_BLOCKED //!< The state of a generically blocked thread
} thread_state; } thread_state;
#endif #endif
/**
* Yield the CPU to another process
*/
void yield(); 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); 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); 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); 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); void unblockThread(pid_t pid,pid_t tid);

View File

@ -1,12 +1,26 @@
/**
* \file
*/
#ifndef UNISTD_H #ifndef UNISTD_H
#define UNISTD_H #define UNISTD_H
#include <sys/types.h> #include <sys/types.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
pid_t fork(void); // GCC required pid_t fork(void); // GCC required
int execv(const char* path, char* const argv[]); // 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 execve(const char* path, char* const argv[], char* const envp[]); // GCC required
int execvp(const char* file, char* const argv[]); // 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 #endif

View File

@ -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