From ba44ae06c6aa311d233b6d056a18895b7bf7ab76 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 13:56:35 -0400 Subject: fmt --- kernel/fs/ramfs.c | 16 +-- kernel/fs/tar.c | 385 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 205 insertions(+), 196 deletions(-) diff --git a/kernel/fs/ramfs.c b/kernel/fs/ramfs.c index e9d5bc2..0c92c96 100644 --- a/kernel/fs/ramfs.c +++ b/kernel/fs/ramfs.c @@ -1,5 +1,5 @@ -/*#include -#include +#include +/*#include //#include //#include #include @@ -36,7 +36,7 @@ int ramfs_delete(const char *name) { kfree(allTheFiles[i].data); for(int j = i; j < numberOfFiles; j++) { allTheFiles[j] = allTheFiles[j+1]; - numberOfFiles -= 1; + numberOfFiles -= 1; } return NOERROR; @@ -62,7 +62,7 @@ int ramfs_write(const char *name, char *buffer) { } // here we return the index of the file as well. -/*int ramfs_find_file(root *r, const char *fullpath, const char *name, file *out, directory *outDirectory) { +*int ramfs_find_file(root *r, const char *fullpath, const char *name, file *out, directory *outDirectory) { directory *location = r->root; if(ramfs_find_directory(r, fullpath, name, location) == NOERROR) { for(int i = 0; i < location->file_count; i++) { @@ -89,14 +89,14 @@ int ramfs_find_directory(root *r, const char *fullpath, const char *name, direct location = location->directories[i]; wasItFound = true; break; - + } } if(!wasItFound) { return ERROR; } tempPath = strtok(NULL, "/"); - + } out = location; return NOERROR; @@ -142,7 +142,7 @@ int ramfs_delete_file(root *r, const char *fullpath, const char *name) { return NOERROR; } return ERROR; - + } return ERROR; } @@ -155,7 +155,7 @@ int ramfs_delete_directory() { } int ramfs_write() { - + } diff --git a/kernel/fs/tar.c b/kernel/fs/tar.c index 569a876..5f02c34 100644 --- a/kernel/fs/tar.c +++ b/kernel/fs/tar.c @@ -4,163 +4,173 @@ // the placements of these values mimics their placement in standard UStar struct tar_header { - char name[100]; // 0-99 - char mode[8]; // 100-107 - char ownerUID[8]; // 108-115 - char groupUID[8]; // 116-123 - char fileSize[12]; // 124-135 - char lastMod[12]; // 136-147 - char checksum[8]; // 148-155 - char type_flag; // 156 - char linked_name[100]; // 157-256 - char magic[6]; // 257-262 - char version[2]; // 263-264 - char username[32]; // 265-296 - char groupname[32]; // 297-328 - char majorNum[8]; // 329-336 - char minorNum[8]; // 337-344 - char prefix[155]; // 345-499 - char notUsed[12]; // 500-511 + char name[100]; // 0-99 + char mode[8]; // 100-107 + char ownerUID[8]; // 108-115 + char groupUID[8]; // 116-123 + char fileSize[12]; // 124-135 + char lastMod[12]; // 136-147 + char checksum[8]; // 148-155 + char type_flag; // 156 + char linked_name[100]; // 157-256 + char magic[6]; // 257-262 + char version[2]; // 263-264 + char username[32]; // 265-296 + char groupname[32]; // 297-328 + char majorNum[8]; // 329-336 + char minorNum[8]; // 337-344 + char prefix[155]; // 345-499 + char notUsed[12]; // 500-511 }; -#define TAR_SIZE 512 -#define TMAGIC "ustar" /* ustar and a null */ -#define TMAGLEN 6 -#define TVERSION "00" /* 00 and no null */ +#define TAR_SIZE 512 +#define TMAGIC "ustar" /* ustar and a null */ +#define TMAGLEN 6 +#define TVERSION "00" /* 00 and no null */ #define TVERSLEN 2 #define ERROR_TAR 1 #define NOERROR_TAR 0 -#define REGTYPE '0' /* regular file */ -#define DIRTYPE '5' /* directory */ - +#define REGTYPE '0' /* regular file */ +#define DIRTYPE '5' /* directory */ struct tar_file { - struct file file; - struct file_system *fs; - size_t len; - size_t offset; - size_t sect; + struct file file; + struct file_system *fs; + size_t len; + size_t offset; + size_t sect; }; // read_tar_header reads what is in tar -int read_tar_header(struct disk *disk, uint32_t sect, struct tar_header *hdr) { - - if(disk_read(disk, sect * TAR_SIZE, TAR_SIZE, hdr) < TAR_SIZE) { - return ERROR_TAR; - } - if(memcmp(hdr->magic, TMAGIC, TMAGLEN) != 0 || memcmp(hdr->version, TVERSION, TVERSLEN) != 0) { - return ERROR_TAR; - } - return NOERROR_TAR; - +int read_tar_header(struct disk *disk, uint32_t sect, struct tar_header *hdr) +{ + if (disk_read(disk, sect * TAR_SIZE, TAR_SIZE, hdr) < TAR_SIZE) { + return ERROR_TAR; + } + if (memcmp(hdr->magic, TMAGIC, TMAGLEN) != 0 || + memcmp(hdr->version, TVERSION, TVERSLEN) != 0) { + return ERROR_TAR; + } + return NOERROR_TAR; } -/// @brief +/// @brief /// @param f the file to be read /// @param buffer the buffer that the content of the file is read into -/// @param len -/// @return -int tar_read(struct file *f, void *buffer, size_t len) { - struct tar_file *tf = (struct tar_file*) f; - long size = MIN((tf->len - tf->offset), len); - if(tf->file.f_type != F_REG || size < 1) { - return ERROR_TAR; - } - size = disk_read(tf->fs->fs_disk, (tf->sect+1) * TAR_SIZE + tf->offset, size, buffer); - tf->offset += size; - return size; +/// @param len +/// @return +int tar_read(struct file *f, void *buffer, size_t len) +{ + struct tar_file *tf = (struct tar_file *)f; + long size = MIN((tf->len - tf->offset), len); + if (tf->file.f_type != F_REG || size < 1) { + return ERROR_TAR; + } + size = disk_read(tf->fs->fs_disk, (tf->sect + 1) * TAR_SIZE + tf->offset, + size, buffer); + tf->offset += size; + return size; } //static int read_tar() // we are assuming that things are formatted correctly. -int find_file(struct file_system *fs, const char *filepath, size_t *sect, size_t *sect_return, struct tar_header *outHeader) { - //char *tempFilePath = filepath; - struct tar_header hdr; - size_t curr_sect; - if(sect == NULL) { - curr_sect = 0; - } else { - curr_sect = *sect; - } - while (1 == 1) { - if(read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { - return ERROR_TAR; - } - if(memcmp(hdr.name, filepath, strlen(filepath) + 1) != 0) { - // didn't find it. - - curr_sect += ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - continue; - } else { - *outHeader = hdr; - *sect_return = curr_sect; - if(sect != NULL) { - sect += curr_sect; - } - return NOERROR_TAR; - } +int find_file(struct file_system *fs, const char *filepath, size_t *sect, + size_t *sect_return, struct tar_header *outHeader) +{ + //char *tempFilePath = filepath; + struct tar_header hdr; + size_t curr_sect; + if (sect == NULL) { + curr_sect = 0; + } else { + curr_sect = *sect; + } + while (1 == 1) { + if (read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { + return ERROR_TAR; + } + if (memcmp(hdr.name, filepath, strlen(filepath) + 1) != 0) { + // didn't find it. - } - return ERROR_TAR; + curr_sect += + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / TAR_SIZE) + + 1; + continue; + } else { + *outHeader = hdr; + *sect_return = curr_sect; + if (sect != NULL) { + sect += curr_sect; + } + return NOERROR_TAR; + } + } + return ERROR_TAR; } -int find_file_redux(struct file_system *fs, const char *filepath, size_t *sect, size_t *sect_return, struct tar_header *outHeader) { - struct tar_header hdr; - size_t curr_sect; - if(sect == NULL) { - curr_sect = 0; - } else { - curr_sect = *sect; - } - while (1 == 1) { - if(read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { - return ERROR_TAR; - } - if(memcmp(hdr.name, filepath, MIN(strlen(filepath), strlen(hdr.name))) != 0) { - // didn't find it. - - curr_sect += ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - continue; - } else { - *outHeader = hdr; - *sect_return = curr_sect; - if(sect != NULL) { - sect += curr_sect + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - } - return NOERROR_TAR; - - } - - } - return ERROR_TAR; // it should never actually reach here. +int find_file_redux(struct file_system *fs, const char *filepath, size_t *sect, + size_t *sect_return, struct tar_header *outHeader) +{ + struct tar_header hdr; + size_t curr_sect; + if (sect == NULL) { + curr_sect = 0; + } else { + curr_sect = *sect; + } + while (1 == 1) { + if (read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { + return ERROR_TAR; + } + if (memcmp(hdr.name, filepath, + MIN(strlen(filepath), strlen(hdr.name))) != 0) { + // didn't find it. + curr_sect += + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / TAR_SIZE) + + 1; + continue; + } else { + *outHeader = hdr; + *sect_return = curr_sect; + if (sect != NULL) { + sect += curr_sect + + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / + TAR_SIZE) + + 1; + } + return NOERROR_TAR; + } + } + return ERROR_TAR; // it should never actually reach here. } - -void tar_close(struct file *f) { - kfree(f); +void tar_close(struct file *f) +{ + kfree(f); } -int tar_seek(struct file *f, long int offsetAdd, int theSeek) { - struct tar_file *tf = (struct tar_file*) f; - if(theSeek == SEEK_SET) { - tf->offset = offsetAdd; - return tf->offset; - } else if(theSeek == SEEK_CUR) { - tf->offset = tf->offset + offsetAdd; - return tf->offset; - } else if(theSeek ==SEEK_END) { - tf->offset = tf->len + offsetAdd; - return tf->offset; - } else { - return -1; - } - +int tar_seek(struct file *f, long int offsetAdd, int theSeek) +{ + struct tar_file *tf = (struct tar_file *)f; + if (theSeek == SEEK_SET) { + tf->offset = offsetAdd; + return tf->offset; + } else if (theSeek == SEEK_CUR) { + tf->offset = tf->offset + offsetAdd; + return tf->offset; + } else if (theSeek == SEEK_END) { + tf->offset = tf->len + offsetAdd; + return tf->offset; + } else { + return -1; + } } -int tar_write(struct file *f, const void *buffer, size_t len) { - // tar doesn't do write lol. This is just here so there is something to send to write - (void)f; - (void)buffer; - (void)len; - return ERROR_TAR; +int tar_write(struct file *f, const void *buffer, size_t len) +{ + // tar doesn't do write lol. This is just here so there is something to send to write + (void)f; + (void)buffer; + (void)len; + return ERROR_TAR; } /*int tar_ents(struct file *f, struct dirent *d, size_t dIndex) { @@ -193,9 +203,8 @@ int tar_write(struct file *f, const void *buffer, size_t len) { } - -}*/ +}*/ int tar_ents(struct file *f, struct dirent *ent, size_t entry) { @@ -212,8 +221,8 @@ int tar_ents(struct file *f, struct dirent *ent, size_t entry) return -1; if (read_tar_header(tf->fs->fs_disk, sect, &dir)) { - return ERROR_TAR; - } + return ERROR_TAR; + } while (1) { if (find_file_redux(tf->fs, dir.name, §_off, §, &hdr)) @@ -234,64 +243,64 @@ int tar_ents(struct file *f, struct dirent *ent, size_t entry) } // opens up the tar file at fullpath, and puts it in out. -int tar_open(struct file_system *fs, const char *fullpath, int flags, struct file **out) { - struct tar_header hdr; - struct tar_file *newFile; - size_t sect_result; - find_file(fs, fullpath, NULL, §_result, &hdr); - if(flags != O_RDONLY) { - return ERROR_TAR; - } - newFile = kalloc(sizeof(struct tar_file)); - - newFile->file.f_type = F_REG; - newFile->fs = fs; - newFile->file.read = tar_read; - newFile->file.close = tar_close; - newFile->file.write = tar_write; // doesn't actually work; - newFile->file.ents = tar_ents; - newFile->file.seek = tar_seek; - newFile->offset = 0; - newFile->len = strtoull(hdr.fileSize, NULL, 8); - newFile->sect = sect_result; - - *out = (struct file *)newFile; - return NOERROR_TAR; - - - - +int tar_open(struct file_system *fs, const char *fullpath, int flags, + struct file **out) +{ + struct tar_header hdr; + struct tar_file *newFile; + size_t sect_result; + find_file(fs, fullpath, NULL, §_result, &hdr); + if (flags != O_RDONLY) { + return ERROR_TAR; + } + newFile = kalloc(sizeof(struct tar_file)); + + newFile->file.f_type = F_REG; + newFile->fs = fs; + newFile->file.read = tar_read; + newFile->file.close = tar_close; + newFile->file.write = tar_write; // doesn't actually work; + newFile->file.ents = tar_ents; + newFile->file.seek = tar_seek; + newFile->offset = 0; + newFile->len = strtoull(hdr.fileSize, NULL, 8); + newFile->sect = sect_result; + + *out = (struct file *)newFile; + return NOERROR_TAR; } // gets stats at the file at fullpath, putting them in out. -int tar_stat(struct file_system *fs, const char *fullpath, struct stat *out) { - struct tar_header hdr; - size_t sect_result; - find_file(fs, fullpath, NULL, §_result, &hdr); - out->s_length = strtoull(hdr.fileSize, NULL, 8); - if(hdr.type_flag == REGTYPE) { - out->s_type = F_REG; - } else if(hdr.type_flag == DIRTYPE) { - out->s_type = F_DIR; - } else { - // wth - return ERROR_TAR; - } - return NOERROR_TAR; +int tar_stat(struct file_system *fs, const char *fullpath, struct stat *out) +{ + struct tar_header hdr; + size_t sect_result; + find_file(fs, fullpath, NULL, §_result, &hdr); + out->s_length = strtoull(hdr.fileSize, NULL, 8); + if (hdr.type_flag == REGTYPE) { + out->s_type = F_REG; + } else if (hdr.type_flag == DIRTYPE) { + out->s_type = F_DIR; + } else { + // wth + return ERROR_TAR; + } + return NOERROR_TAR; } // use tar for the filesystem. -int tar_mount(struct file_system *fs) { - struct tar_header hdr; - // reads into hdr - if(read_tar_header(fs->fs_disk, 0, &hdr) == 0) { - fs->fs_name = "tar"; - fs->open = tar_open; - fs->stat = tar_stat; - fs->fs_present = true; - return NOERROR_TAR; - } - return ERROR_TAR; +int tar_mount(struct file_system *fs) +{ + struct tar_header hdr; + // reads into hdr + if (read_tar_header(fs->fs_disk, 0, &hdr) == 0) { + fs->fs_name = "tar"; + fs->open = tar_open; + fs->stat = tar_stat; + fs->fs_present = true; + return NOERROR_TAR; + } + return ERROR_TAR; } // no need to unmount, since mount just overrides whatever it was using previously. \ No newline at end of file -- cgit v1.2.3-freya From 633d89e0cbfea56cb5dc9c2d7fb19857cbe6f49d Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 14:06:27 -0400 Subject: increase identity map --- kernel/include/comus/limits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/include/comus/limits.h b/kernel/include/comus/limits.h index 1ef13b4..a036fcb 100644 --- a/kernel/include/comus/limits.h +++ b/kernel/include/comus/limits.h @@ -7,7 +7,7 @@ */ /// number of pts to identity map the kernel (1pt = 2MB) -#define N_IDENT_PTS 4 // max 512 (1G) +#define N_IDENT_PTS 64 // max 512 (1G) /// max number of processes #define N_PROCS 256 -- cgit v1.2.3-freya From 6cfcabf38e6f4982bfb116ac9cedf2333e29d275 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 14:20:05 -0400 Subject: smooth scrolling for term --- kernel/term.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/term.c b/kernel/term.c index 917f645..88fa072 100644 --- a/kernel/term.c +++ b/kernel/term.c @@ -7,8 +7,10 @@ // terminal data static char buffer[TERM_MAX_WIDTH * TERM_MAX_HEIGHT]; static uint16_t buffer_line = UINT16_MAX; -static uint16_t width = 80; // baseline vga text mode until resized -static uint16_t height = 25; +static uint16_t last_width = 80, + width = 80; // baseline vga text mode until resized +static uint16_t last_height = 25, height = 25; +static uint16_t scrolling = 0; static uint16_t x = 0; static uint16_t y = 0; @@ -140,10 +142,26 @@ void term_redraw(void) for (uint16_t j = 0; j < height; j++) { for (uint16_t i = 0; i < width; i++) { - char c = buffer[BUFIDX(i, j)]; + char c; + + c = buffer[BUFIDX(i, j)]; + + // if screen hasnet changed size + // dont redraw what we dont need to redraw + if (last_width == height && last_width == width) { + char prev; + prev = buffer[BUFIDX(i, (j - scrolling))]; + if (c == prev) + continue; + } + gpu_draw_char(c, i, j); } } + + last_width = width; + last_height = height; + scrolling = 0; } void term_scroll(uint16_t lines) @@ -151,6 +169,8 @@ void term_scroll(uint16_t lines) if (!lines) return; buffer_line += lines; + term_clear_line(y); + scrolling = lines; term_redraw(); } -- cgit v1.2.3-freya From 0fd92cbb351a7ae652ceb047516ad4f00a85ddb6 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 14:21:26 -0400 Subject: set max res for gop framebuffer --- kernel/efi/gop.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/efi/gop.c b/kernel/efi/gop.c index 899bbee..5495980 100644 --- a/kernel/efi/gop.c +++ b/kernel/efi/gop.c @@ -4,6 +4,8 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL; +#define MAX_H_RES 1920 + EFI_STATUS efi_load_gop(EFI_SYSTEM_TABLE *ST) { EFI_STATUS status = EFI_SUCCESS; @@ -33,6 +35,8 @@ EFI_STATUS efi_load_gop(EFI_SYSTEM_TABLE *ST) if (info->PixelFormat != PixelBlueGreenRedReserved8BitPerColor && info->PixelFormat != PixelRedGreenBlueReserved8BitPerColor) continue; + if (info->HorizontalResolution > MAX_H_RES) + continue; if (info->HorizontalResolution > width) { width = info->HorizontalResolution; best = i; -- cgit v1.2.3-freya From 128aeb51424414e59dc61c5a6df0c72f87012a52 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 15:03:23 -0400 Subject: start docs --- docs/DRIVERS.md | 47 ++++++++++++++++++++++++ docs/FS.md | 0 docs/HEADERS.md | 0 docs/MEMORY.md | 0 docs/MODULES.md | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/PCB.md | 53 +++++++++++++++++++++++++++ kernel/procs.c | 1 - 7 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 docs/DRIVERS.md create mode 100644 docs/FS.md create mode 100644 docs/HEADERS.md create mode 100644 docs/MEMORY.md create mode 100644 docs/MODULES.md create mode 100644 docs/PCB.md diff --git a/docs/DRIVERS.md b/docs/DRIVERS.md new file mode 100644 index 0000000..e17e15e --- /dev/null +++ b/docs/DRIVERS.md @@ -0,0 +1,47 @@ +# Drivers + +All drivers and their uses + +## acpi.c + +ACPI (Advanced Configuration and Power Interface) +- allows powering off the system + +## ata.c + +ATA (Advanced Technology Attachment) / IDE (Integrated Drive Electronics) +- ide/ata disk device driver + +## clock.c + +COMS real time clock driver + +## gpu/ + +Contains drivers for each type of gpu +- Bochs (QEMU default gpu device) +- GOP (Graphics Output Protocol), UEFI framebuffer + +## gpu.c + +Functions for abstracting over current loaded gpu + +## pci.c + +PCI (Peripheral Component Interconnect) +- driver to load pci devices (not pcie) + +## pit.c + +PIT (Programmable Interval Timer) +- sends timer interrupts to the pic +- set pc speaker tones + +## ps2.c + +PS2 Controller / Keyboard / Mouse driver +- allows keyboard / mouse input + +## uart.c + +Serial (UART) driver diff --git a/docs/FS.md b/docs/FS.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/HEADERS.md b/docs/HEADERS.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/MEMORY.md b/docs/MEMORY.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/MODULES.md b/docs/MODULES.md new file mode 100644 index 0000000..cf452ff --- /dev/null +++ b/docs/MODULES.md @@ -0,0 +1,109 @@ +# modules + +list of all kernel modules and their functions + +## cpu/ + +Initalizes all cpu components and low level tabels. +- FPU / SSE / AVX +- IDT (Interrupt Descriptor Table) +- PIC (Programmable Interrupt Controller) +- TSS (Task State Segment) + - used for allowing kernel to switch into ring 3 + - used for setting kernel stack on interrupt + +## drivers/ + +Folder `drivers/` contains drivers for the system. See DRIVERS.md. + +File `drivers.c` loads each of the drivers in `drivers/`. + +## efi/ + +Load UEFI components +- UEFI memory map +- GOP (Graphics Output Protocol), UEFI framebuffer + +## entry.S + +Entry point into the kernel along with: +- GDT (Global Descriptor Table) +- Multiboot header see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html +- Inital kernel stack + - not used once interrupts since interrupt stack will be used +- Inital page tables + - see MEMORY.md + +Symbols: +- `_start` + - generic legacy bios entrypoint in IA-32 mode + +- `_start_efi` + - uefi entrypoint in IA-32e mode + +## font/ + +Loads psf2 font files into kernel .rodata segment + +## fs/ + +See FS.md + +## include/ + +All kernel headers. + +- SEE HEADERS.md + +## input.c + +Abstracts all input from all sources over a single keycode / mouseevent buffer. +- uses ps2 and uart + +## lib/ + +Kernel c library + +Notable files: + +- `backtrace.c` - does stack backtraces and logs them to output + - used during exceptions +- `kspin.c` + - spinlock in kernel space +- `panic.c` + - implements panic functions, along with halt called during exceptions or panic + +## main.c + +Kernel main entrypoint. +- Loads all components of the kernel in order. +- Loads init process +- Dispatches init + +## mboot/ + +Laod information provided by multiboot standard +- `efi.c` - gets `EFI_SYSTEM_TABLE` & `EFI_HANDLE` + - read UEFI standard for more information +- `mmap.c` - load memory map when in legacy boot + - memory map is loaded from `efi/` module when booting from UEFI +- `module.c` + - loads initrd (ramdisk) +- `rsdp.c` + - load root ACPI table, provided for the ACPI driver + +## memory/ + +See MEMORY.md + +## procs.c + +Stores loaded process information and scheduler +- multiple queues for scheduling + - ready - pcb is ready to be executed + - zombie - pcb is a zombie, and waiting to be cleaned up + - syscall - replaced blocked/waiting in baseline + - each syscall has its own queue + - acessed though syscall_queue[SYS_num] + +See PCB.md for pcb information. diff --git a/docs/PCB.md b/docs/PCB.md new file mode 100644 index 0000000..9eaa2a2 --- /dev/null +++ b/docs/PCB.md @@ -0,0 +1,53 @@ +# PCB + +PCB information + +## context + +Contains context infromation for the curernt process. +- memory context (pcb->memctx) + - stores page directory and vitural address allocateor (see MEMORY.md) +- context save area (pcb->regs) + +## medatada + +- `pid` - process idenfitication number +- `parent` ` - parent of the current process + - can be NULL if the init process +- `state` - the current runing state of the process + - `UNUSED` - proces in ptable is not used + - `NEW` - process in ptable has been allocated but has not been initalized + - `READY` - process is ready to be dispatched (and in ready queue) + - `RUNNING` - process is the current running process (and in no queues) + - `BLOCKED` - process is in a syscall queue waiting on their syscall to return + - `ZOMBIE` - process is a zombie and waiting to be cleaned up (in zombie queue) +- `priority` - running process priority + - any number form 0 to SIZET_MAX + - higher priority means longer wait to be scheduled +- `ticks` - number of ticks the process has been running for + - set to zero when process is not running + +## heap + +- `heap_start` is the start of the progams heap +- `heap_len` is the length of the programs heap + +## open files + +- `open_files` is a list of currently opened files indexed by file descriptor + +## elf metadata + +- `elf_header` - the programs elf header (Elf64_Ehdr) +- `elf_segments` - the programs loadable elf segments (Elf64_Phdr[]) +- `n_elf_segments` - the number of elf segmsnts the program has + +## queue linkage + +- `next` - the next pcb in the current queue this pcb is in + +## processs state information + +- `syscall` - the current syscall this process is blocked on +- `wakeup` - the number of ticks until the process can be waked up (used during SYS_sleep) +- `exit_status` - the exit status of the process when a zombie diff --git a/kernel/procs.c b/kernel/procs.c index d471416..6017e3a 100644 --- a/kernel/procs.c +++ b/kernel/procs.c @@ -1,4 +1,3 @@ -#include "lib/kio.h" #include #include #include -- cgit v1.2.3-freya