diff options
-rw-r--r-- | makefile | 19 | ||||
-rw-r--r-- | src/kernel/files.c | 17 | ||||
-rw-r--r-- | src/kernel/files.h | 3 | ||||
-rw-r--r-- | src/kernel/keyb.asm | 32 | ||||
-rw-r--r-- | src/kernel/keyb.c | 39 | ||||
-rw-r--r-- | src/kernel/keyb.h | 30 | ||||
-rw-r--r-- | src/kernel/main.c | 39 | ||||
-rw-r--r-- | src/kernel/proc.c | 16 | ||||
-rw-r--r-- | src/kernel/proc.h | 6 | ||||
-rw-r--r-- | src/kernel/serial.asm | 26 | ||||
-rw-r--r-- | src/kernel/serial.h | 2 | ||||
-rw-r--r-- | src/skel/cfg/init/once.rc | 0 | ||||
-rw-r--r-- | src/skel/cfg/init/repeat.rc | 1 |
13 files changed, 198 insertions, 32 deletions
@@ -1,27 +1,32 @@ -cd: kernel fs +cd: files grub + grub2-mkrescue out/fs -o out/cd.iso --product-name=portland --product-version=0.0.9 + +grub: kernel mkdir -p out/fs/boot/grub mv out/kernel.elf out/fs/boot/ cp src/grub.cfg out/fs/boot/grub/ - grub2-mkrescue out/fs -o out/cd.iso --product-name=portland --product-version=0.0.9 + +files: out + mkdir -p out/fs + cp -r src/skel/* out/fs/ kernel: obj out + nasm src/kernel/keyb.asm -o obj/kkeyba.o -f elf32 nasm src/kernel/serial.asm -o obj/kserial.o -f elf32 nasm src/kernel/stub.asm -o obj/kstub.o -f elf32 gcc -c src/kernel/files.c -o obj/kfiles.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/keyb.c -o obj/kkeybc.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/main.c -o obj/kmain.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/mem.c -o obj/kmem.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding -nostdlib -m32 - ld obj/kstub.o obj/kfiles.o obj/kmain.o obj/kmem.o obj/kproc.o obj/kserial.o obj/kvga.o \ + ld obj/kkeyba.o obj/kstub.o obj/kfiles.o obj/kkeybc.o obj/kmain.o \ + obj/kmem.o obj/kproc.o obj/kserial.o obj/kvga.o \ -o out/kernel.elf -T src/kernel/link.ld -s --orphan-handling=discard -melf_i386 - clean: rm -r obj out -fs: out - mkdir -p out/fs - obj: mkdir -p obj diff --git a/src/kernel/files.c b/src/kernel/files.c index b42638a..78fe664 100644 --- a/src/kernel/files.c +++ b/src/kernel/files.c @@ -20,14 +20,14 @@ OF THIS SOFTWARE. #include "files.h" uint16_t open_file(uint8_t *name) { - //TODO + return 0;//TODO } void close_file(uint16_t handle) { file_table[handle].first_sector = 0; } -void read_file(uint16_t handle, uint32_t length, void *buffer) { +uint32_t read_file(uint16_t handle, uint32_t length, void *buffer) { //TODO } @@ -40,5 +40,16 @@ void seek_file(uint16_t handle, int32_t by) { } uint32_t get_size(uint16_t handle) { - //TODO + return 0;//TODO +} + +uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer) { + uint8_t *i = (uint8_t *)buffer; + while (i < (uint8_t *)buffer + max) { + if (!read_file(handle, 1, i) || (*i == (uint8_t)'\n')) { + *i = 0; + return i - (uint8_t *)buffer; + } + ++i; + } }
\ No newline at end of file diff --git a/src/kernel/files.h b/src/kernel/files.h index f7665dc..d9102ab 100644 --- a/src/kernel/files.h +++ b/src/kernel/files.h @@ -32,9 +32,10 @@ struct file_info { struct file_info file_table[65536]; uint16_t open_file(uint8_t *name); void close_file(uint16_t handle); -void read_file(uint16_t handle, uint32_t length, void *buffer); +uint32_t 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); +uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer); #endif
\ No newline at end of file diff --git a/src/kernel/keyb.asm b/src/kernel/keyb.asm new file mode 100644 index 0000000..e3078cc --- /dev/null +++ b/src/kernel/keyb.asm @@ -0,0 +1,32 @@ +;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. + +global get_key +global get_char +global get_line + +section .text +get_key:;uint16_t get_key(void) + push ebp + mov ebp, esp + + xor eax, eax + + ;return in ax + + leave + ret
\ No newline at end of file diff --git a/src/kernel/keyb.c b/src/kernel/keyb.c new file mode 100644 index 0000000..bae462a --- /dev/null +++ b/src/kernel/keyb.c @@ -0,0 +1,39 @@ +/* +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 "serial.h" +#include "vga.h" + +uint8_t get_char(bool echo) { + uint8_t ch = poll_port(COM2) ? read_byte(COM2) : 0;//TODO: from get_key + if (echo) + put_char(ch); + return ch; +} + +uint32_t get_line(uint32_t max, uint8_t *buffer, bool echo) { + uint8_t *i = (uint8_t *)buffer; + while (i < (uint8_t *)buffer + max) { + if ((*i = get_char(echo)) == (uint8_t)'\n') { + *i = 0; + return i - (uint8_t *)buffer; + } + ++i; + } +}
\ No newline at end of file diff --git a/src/kernel/keyb.h b/src/kernel/keyb.h new file mode 100644 index 0000000..d4deba7 --- /dev/null +++ b/src/kernel/keyb.h @@ -0,0 +1,30 @@ +/* +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> +#include <stdbool.h> + +#ifndef KEYB_H +#define KEYB_H + +uint16_t get_key(void); +uint8_t get_char(bool echo); +uint32_t get_line(uint32_t max, uint8_t *buffer, bool echo); + +#endif
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c index 97226bd..2c4a24f 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -80,23 +80,14 @@ enum error_codes { NO_BOOT_DEVICE = 0x00000000, NO_MMAP = 0x00000001, INSUFF_MEMORY = 0x00000002, - MMAP_TOO_SMALL = 0x00000003 + MMAP_TOO_SMALL = 0x00000003, + MISSING_RC = 0x00000004, + BAD_RC_LINE = 0x00000005 }; struct tag_start *tag_pointer; uint32_t main(void) { - clear(); - - /* - uint32_t *debug_ptr = (uint32_t *)tag_pointer - 2; - uint32_t debug_size = *debug_ptr / 4; - for (uint32_t i = 0; i < debug_size; ++i) { - put_32_hex(debug_ptr[i]); - put_char(' '); - } - */ - put_sz("Multiboot info:\n"); while (tag_pointer->type) { put_sz(" Tag type 0x"); @@ -231,12 +222,30 @@ uint32_t main(void) { put_32_hex(sizeof(struct file_info) * 65536); put_char('\n'); - put_sz("\nWelcome to Portland version 0.0.9!\n"); - while (1) - asm ("hlt"); + uint8_t rc_buffer[4096]; + + uint16_t rc_handle = open_file("/cfg/init/once.rc"); + if (!rc_handle) + return MISSING_RC; + while (read_line_file(rc_handle, 4095, (void *)rc_buffer)) + if ((*rc_buffer != (uint8_t)'#') && !new_proc(rc_buffer)) + return BAD_RC_LINE; + close_file(rc_handle); + + rc_handle = open_file("/cfg/init/repeat.rc"); + if (!rc_handle) + return MISSING_RC; + while (1) { + while (read_line_file(rc_handle, 4095, (void *)rc_buffer)) + if ((*rc_buffer != (uint8_t)'#') && !new_proc(rc_buffer)) + return BAD_RC_LINE; + seek_file(rc_handle, -0x80000000); + seek_file(rc_handle, -0x80000000); + } } void wrapped_main(void) { + clear(); uint32_t error = main(); set_color(0x47); clear(); diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 84075d7..0912f3c 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -25,10 +25,10 @@ uint16_t new_proc(uint8_t *file) { uint16_t handle = open_file(file); if (handle) for (uint16_t id = 3; id; ++id) - if (!proc_table[id].memory_start) { + if (!proc_table[id].text) { uint32_t size = get_size(id); void *mem; - proc_table[id].memory_end = size + (proc_table[id].memory_start = allocate_block(size, id)); + proc_table[id].text = size + (proc_table[id].text = allocate_block(size, id)); read_file(handle, size, mem); close_file(handle); //Process file header and make new process @@ -39,6 +39,14 @@ uint16_t new_proc(uint8_t *file) { } void end_proc(uint16_t id) { - deallocate_block(proc_table[id].memory_start); - proc_table[id].memory_start = 0; + if (id && proc_table[id].text) { + deallocate_block(proc_table[id].text); + if (proc_table[id].rodata) + deallocate_block(proc_table[id].rodata); + if (proc_table[id].data) + deallocate_block(proc_table[id].data); + if (proc_table[id].bss) + deallocate_block(proc_table[id].bss); + proc_table[id].text = 0; + } }
\ No newline at end of file diff --git a/src/kernel/proc.h b/src/kernel/proc.h index bbff903..94b0c53 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -23,8 +23,10 @@ OF THIS SOFTWARE. #define PROC_H struct proc_info { - void *memory_start; - void *memory_end; + void *text; + void *rodata; + void *data; + void *bss; }; struct proc_info proc_table[65536]; diff --git a/src/kernel/serial.asm b/src/kernel/serial.asm index 6318bc5..2213fd8 100644 --- a/src/kernel/serial.asm +++ b/src/kernel/serial.asm @@ -17,7 +17,9 @@ global send_byte global read_byte +global poll_port +section .text send_byte:;void send_byte(uint8_t value, uint8_t port) push ebp mov ebp, esp @@ -77,5 +79,29 @@ read_byte:;uint8_t read_byte(uint8_t port) leave ret +poll_port:;bool poll_port(uint8_t port) + push ebp + mov ebp, esp + + xor eax, eax + + xor ecx, ecx + mov cl, byte [ebp + 8];port + + test cl, 0xfc + jnz .leave + + shl cl, 1 + mov dx, word [ecx + com_ports] + + or dx, 5 + + in al, dx + and al, 0x01 + +.leave: + leave + ret + section .rodata com_ports dw 0x03f8, 0x02f8, 0x03e8, 0x02e8
\ No newline at end of file diff --git a/src/kernel/serial.h b/src/kernel/serial.h index 88d3712..2588bee 100644 --- a/src/kernel/serial.h +++ b/src/kernel/serial.h @@ -18,6 +18,7 @@ OF THIS SOFTWARE. */ #include <stdint.h> +#include <stdbool.h> #ifndef SERIAL_H #define SERIAL_H @@ -31,5 +32,6 @@ enum serials { void send_byte(uint8_t value, uint8_t port); uint8_t read_byte(uint8_t port); +bool poll_port(uint8_t port); #endif
\ No newline at end of file diff --git a/src/skel/cfg/init/once.rc b/src/skel/cfg/init/once.rc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/skel/cfg/init/once.rc diff --git a/src/skel/cfg/init/repeat.rc b/src/skel/cfg/init/repeat.rc new file mode 100644 index 0000000..b04613d --- /dev/null +++ b/src/skel/cfg/init/repeat.rc @@ -0,0 +1 @@ +/exec/pshell.elf
\ No newline at end of file |