keyboard skeleton, skeleton, rcs, etc
This commit is contained in:
parent
dc6b746faa
commit
c055a2f6a9
13 changed files with 198 additions and 32 deletions
19
makefile
19
makefile
|
@ -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
|
mkdir -p out/fs/boot/grub
|
||||||
mv out/kernel.elf out/fs/boot/
|
mv out/kernel.elf out/fs/boot/
|
||||||
cp src/grub.cfg out/fs/boot/grub/
|
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
|
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/serial.asm -o obj/kserial.o -f elf32
|
||||||
nasm src/kernel/stub.asm -o obj/kstub.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/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/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/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/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32
|
||||||
gcc -c src/kernel/vga.c -o obj/kvga.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
|
-o out/kernel.elf -T src/kernel/link.ld -s --orphan-handling=discard -melf_i386
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r obj out
|
rm -r obj out
|
||||||
|
|
||||||
fs: out
|
|
||||||
mkdir -p out/fs
|
|
||||||
|
|
||||||
obj:
|
obj:
|
||||||
mkdir -p obj
|
mkdir -p obj
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,14 @@ OF THIS SOFTWARE.
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
|
|
||||||
uint16_t open_file(uint8_t *name) {
|
uint16_t open_file(uint8_t *name) {
|
||||||
//TODO
|
return 0;//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_file(uint16_t handle) {
|
void close_file(uint16_t handle) {
|
||||||
file_table[handle].first_sector = 0;
|
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
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,5 +40,16 @@ void seek_file(uint16_t handle, int32_t by) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_size(uint16_t handle) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -32,9 +32,10 @@ struct file_info {
|
||||||
struct file_info file_table[65536];
|
struct file_info file_table[65536];
|
||||||
uint16_t open_file(uint8_t *name);
|
uint16_t open_file(uint8_t *name);
|
||||||
void close_file(uint16_t handle);
|
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 write_file(uint16_t handle, uint32_t length, void *buffer);
|
||||||
void seek_file(uint16_t handle, int32_t by);
|
void seek_file(uint16_t handle, int32_t by);
|
||||||
uint32_t get_size(uint16_t handle);
|
uint32_t get_size(uint16_t handle);
|
||||||
|
uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
32
src/kernel/keyb.asm
Normal file
32
src/kernel/keyb.asm
Normal file
|
@ -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
|
39
src/kernel/keyb.c
Normal file
39
src/kernel/keyb.c
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
30
src/kernel/keyb.h
Normal file
30
src/kernel/keyb.h
Normal file
|
@ -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
|
|
@ -80,23 +80,14 @@ enum error_codes {
|
||||||
NO_BOOT_DEVICE = 0x00000000,
|
NO_BOOT_DEVICE = 0x00000000,
|
||||||
NO_MMAP = 0x00000001,
|
NO_MMAP = 0x00000001,
|
||||||
INSUFF_MEMORY = 0x00000002,
|
INSUFF_MEMORY = 0x00000002,
|
||||||
MMAP_TOO_SMALL = 0x00000003
|
MMAP_TOO_SMALL = 0x00000003,
|
||||||
|
MISSING_RC = 0x00000004,
|
||||||
|
BAD_RC_LINE = 0x00000005
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tag_start *tag_pointer;
|
struct tag_start *tag_pointer;
|
||||||
|
|
||||||
uint32_t main(void) {
|
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");
|
put_sz("Multiboot info:\n");
|
||||||
while (tag_pointer->type) {
|
while (tag_pointer->type) {
|
||||||
put_sz(" Tag type 0x");
|
put_sz(" Tag type 0x");
|
||||||
|
@ -231,12 +222,30 @@ uint32_t main(void) {
|
||||||
put_32_hex(sizeof(struct file_info) * 65536);
|
put_32_hex(sizeof(struct file_info) * 65536);
|
||||||
put_char('\n');
|
put_char('\n');
|
||||||
|
|
||||||
put_sz("\nWelcome to Portland version 0.0.9!\n");
|
uint8_t rc_buffer[4096];
|
||||||
while (1)
|
|
||||||
asm ("hlt");
|
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) {
|
void wrapped_main(void) {
|
||||||
|
clear();
|
||||||
uint32_t error = main();
|
uint32_t error = main();
|
||||||
set_color(0x47);
|
set_color(0x47);
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -25,10 +25,10 @@ uint16_t new_proc(uint8_t *file) {
|
||||||
uint16_t handle = open_file(file);
|
uint16_t handle = open_file(file);
|
||||||
if (handle)
|
if (handle)
|
||||||
for (uint16_t id = 3; id; ++id)
|
for (uint16_t id = 3; id; ++id)
|
||||||
if (!proc_table[id].memory_start) {
|
if (!proc_table[id].text) {
|
||||||
uint32_t size = get_size(id);
|
uint32_t size = get_size(id);
|
||||||
void *mem;
|
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);
|
read_file(handle, size, mem);
|
||||||
close_file(handle);
|
close_file(handle);
|
||||||
//Process file header and make new process
|
//Process file header and make new process
|
||||||
|
@ -39,6 +39,14 @@ uint16_t new_proc(uint8_t *file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_proc(uint16_t id) {
|
void end_proc(uint16_t id) {
|
||||||
deallocate_block(proc_table[id].memory_start);
|
if (id && proc_table[id].text) {
|
||||||
proc_table[id].memory_start = 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -23,8 +23,10 @@ OF THIS SOFTWARE.
|
||||||
#define PROC_H
|
#define PROC_H
|
||||||
|
|
||||||
struct proc_info {
|
struct proc_info {
|
||||||
void *memory_start;
|
void *text;
|
||||||
void *memory_end;
|
void *rodata;
|
||||||
|
void *data;
|
||||||
|
void *bss;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct proc_info proc_table[65536];
|
struct proc_info proc_table[65536];
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
global send_byte
|
global send_byte
|
||||||
global read_byte
|
global read_byte
|
||||||
|
global poll_port
|
||||||
|
|
||||||
|
section .text
|
||||||
send_byte:;void send_byte(uint8_t value, uint8_t port)
|
send_byte:;void send_byte(uint8_t value, uint8_t port)
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
|
@ -77,5 +79,29 @@ read_byte:;uint8_t read_byte(uint8_t port)
|
||||||
leave
|
leave
|
||||||
ret
|
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
|
section .rodata
|
||||||
com_ports dw 0x03f8, 0x02f8, 0x03e8, 0x02e8
|
com_ports dw 0x03f8, 0x02f8, 0x03e8, 0x02e8
|
|
@ -18,6 +18,7 @@ OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifndef SERIAL_H
|
#ifndef SERIAL_H
|
||||||
#define SERIAL_H
|
#define SERIAL_H
|
||||||
|
@ -31,5 +32,6 @@ enum serials {
|
||||||
|
|
||||||
void send_byte(uint8_t value, uint8_t port);
|
void send_byte(uint8_t value, uint8_t port);
|
||||||
uint8_t read_byte(uint8_t port);
|
uint8_t read_byte(uint8_t port);
|
||||||
|
bool poll_port(uint8_t port);
|
||||||
|
|
||||||
#endif
|
#endif
|
0
src/skel/cfg/init/once.rc
Normal file
0
src/skel/cfg/init/once.rc
Normal file
1
src/skel/cfg/init/repeat.rc
Normal file
1
src/skel/cfg/init/repeat.rc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/exec/pshell.elf
|
Reference in a new issue