提交 855dd27b 编写于 作者: R rain

make error-no, file-operations and inode struct

上级 e02e1483
......@@ -22,3 +22,5 @@
2021-2-25 0.566: 566 lines, 6 files, rain
2021-2-25 0.790: 790 lines, 10 files, rain
......@@ -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
......
......@@ -51,3 +51,6 @@ Cunix kernel
`0.566s-kernel`:
&nbsp;&nbsp;&nbsp;&nbsp;write in C. <br/>
`0.790s-kernel`:
&nbsp;&nbsp;&nbsp;&nbsp;make some structs <br/>
/* 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 <https://www.gnu.org/licenses/>.
*/
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
/* 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 <https://www.gnu.org/licenses/>.
*/
#include <kernel/types.h>
#include <kernel/errno.h>
#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);
};
/* 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 <https://www.gnu.org/licenses/>.
*/
#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;
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
......
C_FLAGS = -mcmodel=large -fno-builtin -m64
all: terminal.c
%.o: %.c
gcc -c $*.c $(C_FLAGS)
/* 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 <https://www.gnu.org/licenses/>.
*/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册