diff options
author | Benji Dial <benji3.141@gmail.com> | 2019-12-17 00:43:52 -0500 |
---|---|---|
committer | Benji Dial <benji3.141@gmail.com> | 2019-12-17 00:43:52 -0500 |
commit | 4c2f2fb867cfe64f217a246010a2e2722514dd90 (patch) | |
tree | e36b4baa5e48b7e7d3f3bafba6d0ef7bb236f024 /src/kernel | |
parent | cdc7b2ae532fd3a93e13784812f7501f2fd5c07a (diff) | |
download | portland-os-4c2f2fb867cfe64f217a246010a2e2722514dd90.tar.gz |
a good deal of process
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/files.c | 44 | ||||
-rw-r--r-- | src/kernel/files.h | 40 | ||||
-rw-r--r-- | src/kernel/main.c | 11 | ||||
-rw-r--r-- | src/kernel/mem.c | 41 | ||||
-rw-r--r-- | src/kernel/mem.h | 29 | ||||
-rw-r--r-- | src/kernel/proc.c | 43 | ||||
-rw-r--r-- | src/kernel/proc.h | 34 |
7 files changed, 242 insertions, 0 deletions
diff --git a/src/kernel/files.c b/src/kernel/files.c new file mode 100644 index 0000000..c17edd4 --- /dev/null +++ b/src/kernel/files.c @@ -0,0 +1,44 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include "files.h" + +uint16_t open_file(uint8_t *name) { + //TODO +} + +void close_file(uint16_t handle) { + FILE_HANDLES[handle].first_sector = 0; +} + +void read_file(uint16_t handle, uint32_t length, void *buffer) { + //TODO +} + +void write_file(uint16_t handle, uint32_t length, void *buffer) { + //TODO +} + +void seek_file(uint16_t handle, int32_t by) { + //TODO +} + +uint32_t get_size(uint16_t handle) { + //TODO +}
\ No newline at end of file diff --git a/src/kernel/files.h b/src/kernel/files.h new file mode 100644 index 0000000..31ad21f --- /dev/null +++ b/src/kernel/files.h @@ -0,0 +1,40 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include <stdint.h> + +#ifndef FILES_H +#define FILES_H + +struct file_handle_info { + uint16_t first_sector; + uint16_t current_sector; + uint8_t *io_buffer; + uint32_t position; +}; + +#define FILE_HANDLES ((struct file_handle_info *)*(uint32_t *)0x0000050c) +uint16_t open_file(uint8_t *name); +void close_file(uint16_t handle); +void read_file(uint16_t handle, uint32_t length, void *buffer); +void write_file(uint16_t handle, uint32_t length, void *buffer); +void seek_file(uint16_t handle, int32_t by); +uint32_t get_size(uint16_t handle); + +#endif
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c index 079779c..d5f463c 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -18,8 +18,19 @@ OF THIS SOFTWARE. */ #include "vga.h" +#include "files.h" +#include "mem.h" +#include "proc.h" void main(void) { + *(uint32_t *)0x0000050c = (uint32_t)allocate_pages(16 * sizeof(struct file_handle_info), 2); + for (struct file_handle_info *i = FILE_HANDLES, *l = FILE_HANDLES + 65536; i < l; ++i) + i->first_sector = 0; + + *(uint32_t *)0x00000510 = (uint32_t)allocate_pages(16 * sizeof(struct proc_info), 2); + for (struct proc_info *i = FILE_HANDLES, *l = FILE_HANDLES + 65536; i < l; ++i) + i->memory_start = 0; + put_sz("Welcome to Portland version 0.0.8!\n"); while (1) put_sz("|\b/\b-\b\\\b"); diff --git a/src/kernel/mem.c b/src/kernel/mem.c new file mode 100644 index 0000000..f12fbf7 --- /dev/null +++ b/src/kernel/mem.c @@ -0,0 +1,41 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include "mem.h" + +void *allocate_pages(uint16_t n_pages, uint16_t proc_n) { + for (uint16_t *i = MMAP, *l = MMAP + 0x1000 - proc_n; ++i; i <= l) + outer_for: + if (!*i) { + for (uint16_t j = 1; j < n_pages; ++j) + if (i[j]) { + i += j + 1; + goto outer_for; + } + for (uint16_t j = 0; j < n_pages; ++j) + i[j] = proc_n; + return (void *)((i - MMAP) * 0x1000); + } + return (void *)0; +} + +void deallocate_pages(void *from, uint16_t n_pages) { + for (uint16_t *mb = MMAP + ((uint32_t)from / 0x1000), *l = mb + n_pages; mb < l; ++mb) + *mb = 0; +}
\ No newline at end of file diff --git a/src/kernel/mem.h b/src/kernel/mem.h new file mode 100644 index 0000000..2bfb3bf --- /dev/null +++ b/src/kernel/mem.h @@ -0,0 +1,29 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include <stdint.h> + +#ifndef MEM_H +#define MEM_H + +#define MMAP ((uint16_t *)0x00002000) +void *allocate_pages(uint16_t n_pages, uint16_t proc_n); +void deallocate_pages(void *from, uint16_t n_pages); + +#endif
\ No newline at end of file diff --git a/src/kernel/proc.c b/src/kernel/proc.c new file mode 100644 index 0000000..dba6b92 --- /dev/null +++ b/src/kernel/proc.c @@ -0,0 +1,43 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include "proc.h" +#include "mem.h" +#include "files.h" + +uint16_t new_proc(uint8_t *file) { + uint16_t handle = open_file(file); + if (handle) + for (uint16_t id = 3; id; ++id) + if (!(PROCS[id].memory_start)) { + uint32_t size = get_size(id); + void *mem = PROCS[id].memory_start = allocate_pages(PROCS[id].n_pages = (size - 1) / 4096 + 1, id); + read_file(handle, size, mem); + close_file(handle); + //Process file header and make new process + return id; + } + close_file(handle); + return 0; +} + +void end_proc(uint16_t id) { + deallocate_pages(PROCS[id].memory_start, PROCS[id].n_pages); + PROCS[id].memory_start = 0; +}
\ No newline at end of file diff --git a/src/kernel/proc.h b/src/kernel/proc.h new file mode 100644 index 0000000..893b84e --- /dev/null +++ b/src/kernel/proc.h @@ -0,0 +1,34 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include <stdint.h> + +#ifndef PROC_H +#define PROC_H + +struct proc_info { + void *memory_start; + uint16_t n_pages; +}; + +#define PROCS ((struct proc_info *)*(uint32_t *)0x00000510) +uint16_t new_proc(uint8_t *file); +void end_proc(uint16_t id); + +#endif
\ No newline at end of file |