diff --git a/LINES b/LINES index d3be1178840f9bc613d6570c24cd847c0645dce5..13b49a6f2fda8f2dc8ca1dbe50f8672a39b22a09 100644 --- a/LINES +++ b/LINES @@ -22,3 +22,5 @@ 2021-2-25 0.566: 566 lines, 6 files, rain +2021-2-25 0.790: 790 lines, 10 files, rain + diff --git a/Makefile b/Makefile index 4137959ea866d3486f951e97a167606ec6a7ca69..d011cb27613ff34896a8aa51666fa2c7acdedfa2 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,11 @@ all: make cunix.img clear: - rm *.bin boot/x86/*.bin kernel/*.o kernel/*.bin kernel/init/*.o cunix.img -rf + rm *.bin boot/x86/*.bin kernel/*.o kernel/*.bin kernel/init/*.o kernel/hal/*.o cunix.img -rf lines: - wc boot/x86/boot.asm boot/x86/loader.asm kernel/init/*.c include/arch/x86/* -l + wc boot/x86/boot.asm boot/x86/loader.asm kernel/init/*.c kernel/hal/*.c include/arch/x86/* include/kernel/* -l cunix.img: boot/x86/bootloader.bin kernel/kernel.bin diff --git a/README.md b/README.md index 9973d82f25e178369a6a44255762349d84d10b9d..bdd26167f31c34d23731a1dba6b28932ca049bd2 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,6 @@ Cunix kernel `0.566s-kernel`:     write in C.
+ +`0.790s-kernel`: +    make some structs
diff --git a/include/kernel/errno.h b/include/kernel/errno.h new file mode 100644 index 0000000000000000000000000000000000000000..9d00f3b507c6d1ad3cf0f9fca32431f3f29cb9fb --- /dev/null +++ b/include/kernel/errno.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2021 Rain */ + +/* This file is part of Cunix. */ + +/* + Cunix is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) and later version. +*/ + +/* + Cunix is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +/* + You should have received a copy of the GNU General Public License + along with Cunix. If not, see . +*/ + + + + +typedef __uint32_t errno_t; + + +/* error in kernel */ +#define E_KERROR 0x20000000 + +/* error io port */ +#define E_IOERROR 0x00000001 + +/* no enough memory for this call */ +#define E_NOMEM 0x00000002 + +/* call interrupted by signal */ +#define E_SIGNAL 0x00000003 + + +/* no permision */ +#define E_DENIED 0x40000000 + +/* need root to call this */ +#define E_NDROOT 0x00000001 + +/* no io passport */ +#define E_IODND 0x00000002 + +/* need hardware super 0 */ +#define E_HARDSP 0x00000003 + +/* user error (caller) */ +#define E_UERROR 0x80000000 + +/* syntax error for this call (invalid argument) */ +#define E_SYNERR 0x00000001 + +/* error because address is invalid */ +#define E_ADDRE 0x00000002 + +/* call out of range */ +#define E_OUTRAG 0x000000003 + diff --git a/include/kernel/init.h b/include/kernel/init.h new file mode 100644 index 0000000000000000000000000000000000000000..1073c38be08741b4006c5b8249ff51a03b3f56a0 --- /dev/null +++ b/include/kernel/init.h @@ -0,0 +1,85 @@ +/* Copyright (C) 2021 Rain */ + +/* This file is part of Cunix. */ + +/* + Cunix is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) and later version. +*/ + +/* + Cunix is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +/* + You should have received a copy of the GNU General Public License + along with Cunix. If not, see . +*/ + + + + +#include +#include + + + +#define MAKE_MODULE(name) struct file_operations name##_fop = { \ + .open = name##_open; \ + .creat = name##_create; \ + .read = name##_read; \ + .write = name##_write; \ + .lseek = name##_lseek; \ + .close = name##_close; \ +}; + + +struct inode_desc { + /* this struct is a general descriptor, so we must know + * how big is it. */ + + __uint32_t size; + + /* file descriptor */ + __uint32_t fd; + + /* this is optional */ + __uint32_t off; + + /* this is optional too */ + char *name; +}; + + +struct file_oprerations { + /* open a file */ + struct inode_desc * (* open) (char *name, __uint32_t type, __uint32_t mode, __uint32_t *errno); + struct inode_desc * (* open) (__uint32_t type, __uint32_t mode, __uint32_t *errno); + + /* or create one */ + + /* `creat` doesn't return file-descriptor, it returns errno */ + errno_t (* creat) (char *name, __uint32_t type, __uint32_t mode); + errno_t (* creat) (__uint32_t type, __uint32_t mode); + + /* read from file-descriptor */ + errno_t (* read) (struct inode_desc *i, char *buffer, __uint64_t l); + + /* write to file-descriptor */ + errno_t (* write) (struct inode_desc *i, char *buffer, __uint64_t l); + + /* change position */ + + /* 'seg' = whence */ + __uint32_t (* lseek) (struct inode_desc *i, __uint32_t off, __uint32_t seg); + + /* close a file-descriptor */ + void (* close) (struct inode_desc *i); +}; + + diff --git a/include/kernel/types.h b/include/kernel/types.h new file mode 100644 index 0000000000000000000000000000000000000000..a489f2e4b0fd3dc995220cdaba780950a0e545fc --- /dev/null +++ b/include/kernel/types.h @@ -0,0 +1,47 @@ +/* Copyright (C) 2021 Rain */ + +/* This file is part of Cunix. */ + +/* + Cunix is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) and later version. +*/ + +/* + Cunix is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +/* + You should have received a copy of the GNU General Public License + along with Cunix. If not, see . +*/ + + + + +#define NULL (void *) 0 + + +typedef char __schar_t; +typedef unsigned char __uchar_t; + +typedef short __sshort_t; +typedef unsigned short __ushort_t; + +typedef int __sint_t; +typedef unsigned int __uint_t; + +typedef long __slong_t; +typedef unsigned long __ulong_t; + +typedef __uchar_t __uint8_t; +typedef __ushort_t __uint16_t; +typedef __uint_t __uint32_t; +typedef __ulong_t __uint64_t; + + diff --git a/kernel/Makefile b/kernel/Makefile index 4a67c053166d6a2ab6eacc1bc9da2af3bbc39457..dd57bd44fad27c57f2e879cddd4f86244784e3c2 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,11 +1,10 @@ default: - make kernel.bin - -init/main.o: init/main.c make -C init/ + make -C hal/ + make kernel.bin -kernel.o: init/main.o - ld -b elf64-x86-64 -o kernel.o init/main.o -T kernel.lds +kernel.o: init/main.o hal/terminal.o + ld -b elf64-x86-64 -o kernel.o init/main.o hal/terminal.o -T kernel.lds kernel.bin: kernel.o objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary kernel.o kernel.bin diff --git a/kernel/hal/Makefile b/kernel/hal/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5e6f7414b0742be65b7e3d7dc7ec53e23fc028ed --- /dev/null +++ b/kernel/hal/Makefile @@ -0,0 +1,8 @@ +C_FLAGS = -mcmodel=large -fno-builtin -m64 + +all: terminal.c + +%.o: %.c + gcc -c $*.c $(C_FLAGS) + + diff --git a/kernel/hal/terminal.c b/kernel/hal/terminal.c new file mode 100644 index 0000000000000000000000000000000000000000..b16692e427695362e97c63b529e0f1ef8ede48b2 --- /dev/null +++ b/kernel/hal/terminal.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2021 Rain */ + +/* This file is part of Cunix. */ + +/* + Cunix is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) and later version. +*/ + +/* + Cunix is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +/* + You should have received a copy of the GNU General Public License + along with Cunix. If not, see . +*/ + + + +