diff options
author | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
---|---|---|
committer | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
commit | ae2cdd83ba4a0cae161db0b29031d5591005fa34 (patch) | |
tree | 82fbdfcbb1fe4e3b5e232db195c8c331d69489fd /kernel/include | |
parent | Started writing fat.c (diff) | |
parent | fs header changes (diff) | |
download | comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.gz comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.bz2 comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.zip |
Merge branch 'main' of https://github.com/kenshineto/kern into fat32
Merging main into here
Diffstat (limited to 'kernel/include')
-rw-r--r-- | kernel/include/comus/asm.h | 6 | ||||
-rw-r--r-- | kernel/include/comus/cpu.h | 12 | ||||
-rw-r--r-- | kernel/include/comus/drivers/ata.h | 4 | ||||
-rw-r--r-- | kernel/include/comus/drivers/gpu.h | 4 | ||||
-rw-r--r-- | kernel/include/comus/drivers/gpu/bochs.h | 2 | ||||
-rw-r--r-- | kernel/include/comus/drivers/gpu/gop.h | 2 | ||||
-rw-r--r-- | kernel/include/comus/drivers/ps2.h | 27 | ||||
-rw-r--r-- | kernel/include/comus/fs.h | 151 | ||||
-rw-r--r-- | kernel/include/comus/input.h | 36 | ||||
-rw-r--r-- | kernel/include/comus/keycodes.h | 138 | ||||
-rw-r--r-- | kernel/include/comus/limits.h | 8 | ||||
-rw-r--r-- | kernel/include/comus/memory.h | 38 | ||||
-rw-r--r-- | kernel/include/comus/procs.h | 35 | ||||
-rw-r--r-- | kernel/include/comus/syscalls.h | 5 | ||||
-rw-r--r-- | kernel/include/comus/user.h | 30 | ||||
-rw-r--r-- | kernel/include/lib.h | 1 | ||||
-rw-r--r-- | kernel/include/lib/kmath.h | 20 |
17 files changed, 381 insertions, 138 deletions
diff --git a/kernel/include/comus/asm.h b/kernel/include/comus/asm.h index c7597e7..4f376b1 100644 --- a/kernel/include/comus/asm.h +++ b/kernel/include/comus/asm.h @@ -36,8 +36,10 @@ static inline uint16_t inw(uint16_t port) static inline void rep_inw(uint16_t port, uint16_t *buffer, size_t count) { - while (count--) - *(buffer++) = inw(port); + __asm__ volatile("rep insw" + : "+D"(buffer), "+c"(count) + : "d"(port) + : "memory"); } static inline void outw(uint16_t port, uint16_t val) diff --git a/kernel/include/comus/cpu.h b/kernel/include/comus/cpu.h index ffc1782..df8f44e 100644 --- a/kernel/include/comus/cpu.h +++ b/kernel/include/comus/cpu.h @@ -31,6 +31,13 @@ struct cpu_feat { }; struct cpu_regs { + // pgdir + uint64_t cr3; + // segments + uint16_t gs; + uint16_t fs; + uint16_t es; + uint16_t ds; // registers uint64_t r15; uint64_t r14; @@ -89,4 +96,9 @@ void cpu_feats(struct cpu_feat *feats); */ void cpu_print_regs(struct cpu_regs *regs); +/** + * Return from a syscall handler back into userspace + */ +__attribute__((noreturn)) void syscall_return(void); + #endif /* cpu.h */ diff --git a/kernel/include/comus/drivers/ata.h b/kernel/include/comus/drivers/ata.h index 2f35e03..c404d84 100644 --- a/kernel/include/comus/drivers/ata.h +++ b/kernel/include/comus/drivers/ata.h @@ -44,7 +44,7 @@ enum ide_error ata_init(void); * * @returns IDE_ERROR_OK (0) on success or an error code on failure */ -enum ide_error ide_device_read_sectors(ide_device_t, uint8_t numsects, +enum ide_error ide_device_read_sectors(ide_device_t, uint16_t numsects, uint32_t lba, uint16_t buf[numsects * 256]); @@ -53,7 +53,7 @@ enum ide_error ide_device_read_sectors(ide_device_t, uint8_t numsects, * * @returns 0 on success or an error code on failure */ -enum ide_error ide_device_write_sectors(ide_device_t, uint8_t numsects, +enum ide_error ide_device_write_sectors(ide_device_t, uint16_t numsects, uint32_t lba, uint16_t buf[numsects * 256]); diff --git a/kernel/include/comus/drivers/gpu.h b/kernel/include/comus/drivers/gpu.h index 39c633f..0a8f4fa 100644 --- a/kernel/include/comus/drivers/gpu.h +++ b/kernel/include/comus/drivers/gpu.h @@ -11,7 +11,7 @@ #include <stdint.h> -struct gpu { +struct gpu_dev { const char *name; uint16_t width; uint16_t height; @@ -31,7 +31,7 @@ struct psf2_font { uint8_t data[]; }; -extern struct gpu *gpu_dev; +extern struct gpu_dev *gpu_dev; extern struct psf2_font en_font; /** diff --git a/kernel/include/comus/drivers/gpu/bochs.h b/kernel/include/comus/drivers/gpu/bochs.h index 7d26b60..ec70060 100644 --- a/kernel/include/comus/drivers/gpu/bochs.h +++ b/kernel/include/comus/drivers/gpu/bochs.h @@ -15,6 +15,6 @@ * Loads the bochs graphics driver * @returns 0 on success, NULL on error */ -int bochs_init(struct gpu **gpu_dev); +int bochs_init(struct gpu_dev **gpu_dev); #endif /* bochs.h */ diff --git a/kernel/include/comus/drivers/gpu/gop.h b/kernel/include/comus/drivers/gpu/gop.h index 6475f05..d3af921 100644 --- a/kernel/include/comus/drivers/gpu/gop.h +++ b/kernel/include/comus/drivers/gpu/gop.h @@ -15,6 +15,6 @@ * Loads the uefi gop graphics driver * @returns 0 on success, NULL on error */ -int gop_init(struct gpu **gpu_dev); +int gop_init(struct gpu_dev **gpu_dev); #endif /* gop.h */ diff --git a/kernel/include/comus/drivers/ps2.h b/kernel/include/comus/drivers/ps2.h new file mode 100644 index 0000000..7634e5f --- /dev/null +++ b/kernel/include/comus/drivers/ps2.h @@ -0,0 +1,27 @@ +/** + * @file ps2.h + * + * @author Freya Murphy <freya@freyacat.org> + * + * PS/2 Mouse & Keyboard + */ + +#ifndef PS2_H_ +#define PS2_H_ + +/** + * Initalize the ps2 controller + */ +int ps2_init(void); + +/** + * Recieve input from ps2 keyboard during interrupt + */ +void ps2kb_recv(void); + +/** + * Recieve input from ps2 mouse during interrupt + */ +void ps2mouse_recv(void); + +#endif /* ps2.h */ diff --git a/kernel/include/comus/fs.h b/kernel/include/comus/fs.h index e67b6fe..c48e3e1 100644 --- a/kernel/include/comus/fs.h +++ b/kernel/include/comus/fs.h @@ -9,7 +9,6 @@ #ifndef FS_H_ #define FS_H_ -#include <stdint.h> #include <stddef.h> #include <comus/limits.h> #include <comus/drivers/ata.h> @@ -45,7 +44,7 @@ struct disk { * @param offset - the offset into the disk to read * @param len - the length of the data to read into `buffer` * @param buffer - the buffer to save data into - * @returns bytes read on success, negative fs error code in failure + * @returns number of bytes read on success, negative fs error code in failure */ int disk_read(struct disk *disk, size_t offset, size_t len, void *buffer); @@ -56,7 +55,7 @@ int disk_read(struct disk *disk, size_t offset, size_t len, void *buffer); * @param offset - the offset into the disk to write * @param len - the length of the data to write into `buffer` * @param buffer - the buffer to read from - * @returns bytes written on success, negative fs error code in failure + * @returns number of bytes written on success, negative fs error code in failure */ int disk_write(struct disk *disk, size_t offset, size_t len, void *buffer); @@ -65,104 +64,55 @@ enum file_type { F_REG = 0, // directory F_DIR = 1, - // symbolic link - F_SYM = 2, }; -/// TODO: file name queue or storage area??? -/// hash map?!? (performance !!! :) ) +struct dirent { + int d_id; + unsigned long d_offset; + unsigned short d_namelen; + char d_name[N_FILE_NAME]; +}; + +struct stat { + /// file id + int s_id; + /// file type + enum file_type s_type; + /// file length + unsigned long s_length; +}; struct file { - /// name of the file - char name[N_FILE_NAME]; - /// parent directory of the file - struct file_s *parent; - /// type of the file - enum file_type type; - /// the filesystem of this file - struct file_system *fsys; + /// file id + int f_id; + /// read from the file + int (*read)(struct file *, char *, size_t); + /// write into the file + int (*write)(struct file *, char *, size_t); + /// seeks the file + int (*seek)(struct file *, long); + /// get directory entry at index + int (*ents)(struct file *, struct dirent *, size_t); }; -/// vtable for filesystem functions -/// NOTE: feel free to change this as needed -/// its just stuff that i thought may be good struct file_system { /// set to 1 in fs array to state that fs is defined /// system use only - int present; + int fs_present; /// index into the loaded filesystems array /// system use only - int id; + int fs_id; + /// mount point of this filesystem + /// system use only + char fs_mount[N_FILE_NAME]; /// the disk this filesystem is hooked up to struct disk disk; - /// get root file in file file_system - /// @param fs - the file system - /// @returns the root file or NULL on failure - struct file *(*fs_get_root_file)(struct file_system *fs); - /// rename a file - /// @param fs - the file system - /// @param file - the file to rename - /// @param name - the new file name - /// @returns 0 on success, or an negative fs error code on failure - int (*fs_rename_file)(struct file_system *fs, struct file *file, - char *name); - /// get length of file - /// @param fs - the file system - /// @param file - the file to get the length of - /// @param length - the pointer to save the length to - /// @return 0 on success, or an negative fs error code on failure - int (*fs_get_file_length)(struct file_system *fs, struct file *file, - uint64_t *length); - /// get created date of file - /// @param fs - the file system - /// @param file - the file to get the date created - /// @param created - the pointer to save the created date to - /// @param modified - the pointer to save the modified date to - /// @param accessed - the pointer to save the accessed date to - /// @return 0 on success, or an negative fs error code on failure - int (*fs_get_file_dates)(struct file_system *fs, struct file *file, - uint64_t *created, uint64_t *modified, - uint64_t *accessed); - /// delete a file in the file system - /// @param fs - the file system - /// @param file - the file to delete - /// @returns 0 on success, or an negative fs error code on failure - int (*fs_delete_file)(struct file_system *fs, struct file *file); - /// create a file with a given name and type - /// @param fs - the file system - /// @param res - the new file structure to save the new file into - /// @param parent - the parent (directory) of the file to create - /// @param type - the type of file to create - /// @returns 0 on success, or an negative fs error code on failure - int (*fs_new_file)(struct file_system *fs, struct file *res, - struct file *parent, enum file_type type); - /// get files in a directory - /// @param fs - the file system - /// @param dir - the directory to search into - /// @param start - the directory entry to start at - /// @param len - the max number of entrys to save starting at `start` - /// @param res - the list of structures to save into - /// @returns number of entries read, or an negative fs error code on failure - int (*fs_get_dir_ents)(struct file_system *fs, struct file *dir, - size_t start, size_t len, struct file res[]); - /// read from a file - /// @param fs - the file system - /// @param file - the file to read from - /// @param offset - the offset of the file to read into - /// @param length - the length of the file to read starting at `offset` - /// @param buffer - the buffer to save the data into - /// @returns number of bytes read, or an negative fs error code on failure - int (*fs_read_file)(struct file_system *fs, struct file *file, - size_t offset, size_t length, uint8_t *buffer); - /// write into a file - /// @param fs - the file system - /// @param file - the file to write to - /// @param offset - the offset of the file to write into - /// @param length - the length of the data to write - /// @param buffer - the buffer the data to write is stored in - /// @returns number of bytes written, or an negative fs error code on failure - int (*fs_write_file)(struct file_system *fs, struct file *file, - size_t offset, size_t length, uint8_t *buffer); + /// opens a file + int (*open)(const char *, struct file **); + /// closes a file + void (*close)(struct file *); + /// stats a file + int (*stat)(const char *, struct stat *); }; // list of all disks on the system @@ -190,29 +140,4 @@ struct disk *fs_get_root_disk(void); */ struct file_system *fs_get_root_file_system(void); -/** - * Find a file in the given file system, traversing the path - * Always use this function to find files globally - * - * @param fs - the file system to search - * @param name - the absolute path of the file to look for - * @param res - where to store the file structure - * @returns 0 on success, or an negative fs error code on failure - */ -int fs_find_file_abs(struct file_system *fs, char *abs_path, struct file *res); - -/** - * Find a file in the given file system, traversing the path, relative to - * another file. - * Always use this function to find files globally - * - * @param rel - the relative file to search from - * @param name - the absolute path of the file to look for - * @param res - where to store the file structure - * @returns 0 on success, or an negative fs error code on failure - */ -int fs_find_file_rel(struct file *rel, char *rel_path, struct file *res); - -// NOTE: fell free to add more functions if needed :) - #endif /* fs.h */ diff --git a/kernel/include/comus/input.h b/kernel/include/comus/input.h new file mode 100644 index 0000000..b2b3053 --- /dev/null +++ b/kernel/include/comus/input.h @@ -0,0 +1,36 @@ +/** + * @file input.h + */ + +#ifndef INPUT_H_ +#define INPUT_H_ + +#include <comus/keycodes.h> +#include <comus/limits.h> +#include <stdbool.h> +#include <stddef.h> + +struct keycode { + char key; + char flags; +}; + +struct mouse_event { + bool updated; + bool lmb; + bool rmb; + bool mmb; + int relx; + int rely; +}; + +void keycode_push(struct keycode *ev); +int keycode_pop(struct keycode *ev); +size_t keycode_len(void); +char keycode_to_char(struct keycode *ev); + +void mouse_event_push(struct mouse_event *ev); +int mouse_event_pop(struct mouse_event *ev); +size_t mouse_event_len(void); + +#endif /* input.h */ diff --git a/kernel/include/comus/keycodes.h b/kernel/include/comus/keycodes.h new file mode 100644 index 0000000..ebf296a --- /dev/null +++ b/kernel/include/comus/keycodes.h @@ -0,0 +1,138 @@ +/** + * @file keycodes.h + * + * @author Tristan Miller <trimill@trimill.xyz> + * + * Kernel keycodes + */ + +#ifndef KEYCODES_H_ +#define KEYCODES_H_ + +#define KC_FLAG_KEY_DOWN 0x01 +#define KC_FLAG_KEY_UP 0x02 +#define KC_FLAG_ERROR 0x04 + +#define KEY_NONE 0x00 +#define KEY_UNKNOWN 0x01 + +#define KEY_ESCAPE 0x10 +#define KEY_1 0x11 +#define KEY_2 0x12 +#define KEY_3 0x13 +#define KEY_4 0x14 +#define KEY_5 0x15 +#define KEY_6 0x16 +#define KEY_7 0x17 +#define KEY_8 0x18 +#define KEY_9 0x19 +#define KEY_0 0x1A +#define KEY_MINUS 0x1B +#define KEY_EQUAL 0x1C +#define KEY_BACKSPACE 0x1D +#define KEY_L_SHIFT 0x1E +#define KEY_R_SHIFT 0x1F + +#define KEY_TAB 0x20 +#define KEY_Q 0x21 +#define KEY_W 0x22 +#define KEY_E 0x23 +#define KEY_R 0x24 +#define KEY_T 0x25 +#define KEY_Y 0x26 +#define KEY_U 0x27 +#define KEY_I 0x28 +#define KEY_O 0x29 +#define KEY_P 0x2A +#define KEY_L_BRACE 0x2B +#define KEY_R_BRACE 0x2C +#define KEY_BACKSLASH 0x2D +#define KEY_L_CTRL 0x2E +#define KEY_R_CTRL 0x2F + +#define KEY_CAPS_LOCK 0x30 +#define KEY_A 0x31 +#define KEY_S 0x32 +#define KEY_D 0x33 +#define KEY_F 0x34 +#define KEY_G 0x35 +#define KEY_H 0x36 +#define KEY_J 0x37 +#define KEY_K 0x38 +#define KEY_L 0x39 +#define KEY_SEMICOLON 0x3A +#define KEY_QUOTE 0x3B +#define KEY_ENTER 0x3C +#define KEY_MENU 0x3D +#define KEY_L_ALT 0x3E +#define KEY_R_ALT 0x3F + +#define KEY_SPACE 0x40 +#define KEY_Z 0x41 +#define KEY_X 0x42 +#define KEY_C 0x43 +#define KEY_V 0x44 +#define KEY_B 0x45 +#define KEY_N 0x46 +#define KEY_M 0x47 +#define KEY_COMMA 0x48 +#define KEY_PERIOD 0x49 +#define KEY_SLASH 0x4A +#define KEY_BACKTICK 0x4B +#define KEY_NUM_LOCK 0x4C +#define KEY_SCROLL_LOCK 0x4D +#define KEY_L_META 0x4E +#define KEY_R_META 0x4F + +#define KEY_NP_SLASH 0x50 +#define KEY_NP_7 0x51 +#define KEY_NP_8 0x52 +#define KEY_NP_9 0x53 +#define KEY_NP_ASTERISK 0x54 +#define KEY_NP_4 0x55 +#define KEY_NP_5 0x56 +#define KEY_NP_6 0x57 +#define KEY_NP_MINUS 0x58 +#define KEY_NP_1 0x59 +#define KEY_NP_2 0x5A +#define KEY_NP_3 0x5B +#define KEY_NP_PLUS 0x5C +#define KEY_NP_0 0x5D +#define KEY_NP_PERIOD 0x5E +#define KEY_NP_ENTER 0x5F + +#define KEY_PRINT_SCREEN 0x60 +#define KEY_PAUSE 0x61 +#define KEY_INSERT 0x62 +#define KEY_HOME 0x63 +#define KEY_PAGE_UP 0x64 +#define KEY_DELETE 0x65 +#define KEY_END 0x66 +#define KEY_PAGE_DOWN 0x67 +#define KEY_UP 0x68 +#define KEY_DOWN 0x69 +#define KEY_LEFT 0x6A +#define KEY_RIGHT 0x6B +// #define _ 0x6C +// #define _ 0x6D +// #define _ 0x6E +// #define _ 0x6F + +#define KEY_F1 0x70 +#define KEY_F2 0x71 +#define KEY_F3 0x72 +#define KEY_F4 0x73 +#define KEY_F5 0x74 +#define KEY_F6 0x75 +#define KEY_F7 0x76 +#define KEY_F8 0x77 +#define KEY_F9 0x78 +#define KEY_F10 0x79 +#define KEY_F11 0x7A +#define KEY_F12 0x7B +// #define _ 0x7C +// #define _ 0x7D +// #define _ 0x7E +// #define _ 0x7F + +#endif /* keycodes */ diff --git a/kernel/include/comus/limits.h b/kernel/include/comus/limits.h index 675df47..4cb348d 100644 --- a/kernel/include/comus/limits.h +++ b/kernel/include/comus/limits.h @@ -20,8 +20,16 @@ /// max fs limits #define N_FILE_NAME 256 +#define N_DIR_ENTS 256 #define N_DISKS 8 +/// elf limits +#define N_ELF_SEGMENTS 16 + +/// input buffer +#define N_KEYCODE 64 +#define N_MOUSEEV 64 + /// length of terminal buffer #define TERM_MAX_WIDTH 1920 #define TERM_MAX_HEIGHT 1080 diff --git a/kernel/include/comus/memory.h b/kernel/include/comus/memory.h index 942e7a8..47ea103 100644 --- a/kernel/include/comus/memory.h +++ b/kernel/include/comus/memory.h @@ -87,7 +87,7 @@ mem_ctx_t mem_ctx_alloc(void); * * @returns pointer context or NULL on failure */ -mem_ctx_t mem_ctx_clone(mem_ctx_t ctx, bool cow); +mem_ctx_t mem_ctx_clone(const mem_ctx_t ctx, bool cow); /** * Free a memory context into a new one @@ -104,6 +104,11 @@ void mem_ctx_free(mem_ctx_t ctx); void mem_ctx_switch(mem_ctx_t ctx); /** + * @returns the pgdir pointer in the memory ctx + */ +volatile void *mem_ctx_pgdir(mem_ctx_t ctx); + +/** * Allocates at least len bytes of memory starting at * physical address addr. Returned address can be * any virtural address. @@ -121,7 +126,14 @@ void *mem_mapaddr(mem_ctx_t ctx, void *phys, void *virt, size_t len, * Unmaps mapped address from the kmapaddr function * @param virt - the vitural address returned from kmapaddr */ -void mem_unmapaddr(mem_ctx_t ctx, void *virt); +void mem_unmapaddr(mem_ctx_t ctx, const void *virt); + +/** + * Gets the physical address for a given vitural address + * @param ctx - the memory context + * @param virt - the vitural address + */ +void *mem_get_phys(mem_ctx_t ctx, const void *virt); /** * Allocate a single page of memory with the given paging structure @@ -169,7 +181,7 @@ void *mem_alloc_pages_at(mem_ctx_t ctx, size_t count, void *virt, * * @param ptr - the pointer provided by alloc_page or alloc_pages */ -void mem_free_pages(mem_ctx_t ctx, void *ptr); +void mem_free_pages(mem_ctx_t ctx, const void *ptr); /** * Allocates at least len bytes of memory starting at @@ -185,10 +197,26 @@ void mem_free_pages(mem_ctx_t ctx, void *ptr); void *kmapaddr(void *phys, void *virt, size_t len, unsigned int flags); /** + * Map a vitural address in a userspace context to kernel space + * + * @param ctx - the userspace memory context to map from + * @param virt - the vitural address given by userspace + * @param len - the length of the buffer to map + * @returns vitural address mapped in kernel context + */ +void *kmapuseraddr(mem_ctx_t ctx, const void *virt, size_t len); + +/** + * Gets the physical address for a given vitural address + * @param virt - the vitural address + */ +void *kget_phys(const void *virt); + +/** * Unmaps mapped address from the kmapaddr function * @param virt - the vitural address returned from kmapaddr */ -void kunmapaddr(void *virt); +void kunmapaddr(const void *virt); /** * Allocate a single page of memory @@ -210,6 +238,6 @@ void *kalloc_pages(size_t count); * * @param ptr - the pointer provided by alloc_page or alloc_pages */ -void kfree_pages(void *ptr); +void kfree_pages(const void *ptr); #endif /* memory.h */ diff --git a/kernel/include/comus/procs.h b/kernel/include/comus/procs.h index d92bc5d..7b1a70a 100644 --- a/kernel/include/comus/procs.h +++ b/kernel/include/comus/procs.h @@ -12,10 +12,12 @@ #include <comus/cpu.h> #include <comus/limits.h> #include <comus/memory.h> +#include <comus/syscalls.h> #include <lib.h> +#include <elf.h> -#define PCB_REG(pcb, x) ((pcb)->regs->x) -#define PCB_RET(pcb) ((pcb)->regs->rax) +#define PCB_REG(pcb, x) ((pcb)->regs.x) +#define PCB_RET(pcb) ((pcb)->regs.rax) #define PCB_ARG1(pcb) PCB_REG((pcb), rdi) #define PCB_ARG2(pcb) PCB_REG((pcb), rsi) #define PCB_ARG3(pcb) PCB_REG((pcb), rdx) @@ -33,11 +35,8 @@ enum proc_state { PROC_STATE_READY, PROC_STATE_RUNNING, // runnable, but waiting for some event - PROC_STATE_SLEEPING, PROC_STATE_BLOCKED, - PROC_STATE_WAITING, // no longer runnalbe - PROC_STATE_KILLED, PROC_STATE_ZOMBIE, // sentinel N_PROC_STATES, @@ -46,8 +45,8 @@ enum proc_state { /// process control block struct pcb { // context - struct cpu_regs *regs; mem_ctx_t memctx; + struct cpu_regs regs; // metadata pid_t pid; @@ -56,10 +55,20 @@ struct pcb { size_t priority; size_t ticks; + // heap + char *heap_start; + size_t heap_len; + + // elf metadata + Elf64_Ehdr elf_header; + Elf64_Phdr elf_segments[N_ELF_SEGMENTS]; + Elf64_Half n_elf_segments; + // queue linkage struct pcb *next; // next PDB in queue // process state information + uint64_t syscall; uint64_t wakeup; uint8_t exit_status; }; @@ -79,10 +88,9 @@ typedef struct pcb_queue_s *pcb_queue_t; /// public facing pcb queues extern pcb_queue_t pcb_freelist; -extern pcb_queue_t ready; -extern pcb_queue_t waiting; -extern pcb_queue_t sleeping; -extern pcb_queue_t zombie; +extern pcb_queue_t ready_queue; +extern pcb_queue_t zombie_queue; +extern pcb_queue_t syscall_queue[N_SYSCALLS]; /// pointer to the currently-running process extern struct pcb *current_pcb; @@ -216,6 +224,11 @@ void schedule(struct pcb *pcb); /** * Select the next process to receive the CPU */ -void dispatch(void); +__attribute__((noreturn)) void dispatch(void); + +/** + * Scheduler function called on every system tick + */ +void pcb_on_tick(void); #endif /* procs.h */ diff --git a/kernel/include/comus/syscalls.h b/kernel/include/comus/syscalls.h index 3dc128d..f714184 100644 --- a/kernel/include/comus/syscalls.h +++ b/kernel/include/comus/syscalls.h @@ -27,9 +27,12 @@ #define SYS_sleep 14 #define SYS_brk 15 #define SYS_sbrk 16 +#define SYS_poweroff 17 +#define SYS_drm 18 +#define SYS_ticks 19 // UPDATE THIS DEFINITION IF MORE SYSCALLS ARE ADDED! -#define N_SYSCALLS 13 +#define N_SYSCALLS 20 // interrupt vector entry for system calls #define VEC_SYSCALL 0x80 diff --git a/kernel/include/comus/user.h b/kernel/include/comus/user.h new file mode 100644 index 0000000..f51ada5 --- /dev/null +++ b/kernel/include/comus/user.h @@ -0,0 +1,30 @@ +/** + * @file user.h + * + * @author Freya Murphy <freya@freyacat.org> + * + * Userland functions + */ + +#ifndef USER_H_ +#define USER_H_ + +#include <comus/procs.h> +#include <comus/fs.h> + +/** + * Load a user elf program from a file into a pcb + */ +int user_load(struct pcb *pcb, struct disk *disk); + +/** + * Clone a user process. Used for fork(). + */ +struct pcb *user_clone(struct pcb *pcb); + +/** + * Clean up all loaded userland data from a pcb + */ +void user_cleanup(struct pcb *pcb); + +#endif /* user.h */ diff --git a/kernel/include/lib.h b/kernel/include/lib.h index be4e739..edfbeb4 100644 --- a/kernel/include/lib.h +++ b/kernel/include/lib.h @@ -15,6 +15,7 @@ #include <lib/kctype.h> #include <lib/kio.h> #include <lib/klib.h> +#include <lib/kmath.h> #include <lib/kstring.h> #endif /* lib.h */ diff --git a/kernel/include/lib/kmath.h b/kernel/include/lib/kmath.h new file mode 100644 index 0000000..3be953d --- /dev/null +++ b/kernel/include/lib/kmath.h @@ -0,0 +1,20 @@ +/** + * @file kmath.h + * + * @author Ian McFarlane <i.mcfarlane2002@gmail.com> + * + * Kernel math functions + */ + +#ifndef _KMATH_H +#define _KMATH_H + +#include <stddef.h> + +// min and max both prefer a over b +#define MAX(a, b) ((a) >= (b) ? (a) : (b)) +#define MIN(a, b) ((a) <= (b) ? (a) : (b)) + +#define CLAMP(val, min, max) (MAX((min), MIN((val), (max)))) + +#endif |