repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
NightfallDM/xbook2
src/include/xbook/spinlock.h
#ifndef _XBOOK_SPINLOCK_H #define _XBOOK_SPINLOCK_H /* 自旋锁: 在多核处理器系统中,系统不允许在不同的CPU上运行的内核控制路径同时访问某些内核数据结构, 在这种情况下如果修改数据结构所需的时间比较短,那么信号量(参考信号量)是低效的。 这是系统会使用自旋锁,当一个进程发现锁被另一个进程锁着时,他就不停”旋转”,执行一个紧凑的循环指令直到锁被打开。 但是这种自旋锁在单核处理器下是无效的。当内核控制路径试图访问一个上锁的数据结构,他就开始无休止的循环。因此, 内核控制路径可能因为正在修改受保护的数据结构而没有机会继续执行,也没有机会释放这个...
NightfallDM/xbook2
src/include/xbook/kernel.h
#ifndef _XBOOK_KERNEL_H #define _XBOOK_KERNEL_H #include <arch/page.h> #define KERN_EMERG "<0>" /* system is unuseable */ #define KERN_ALTER "<1>" /* action must be taken immediatgely */ #define KERN_CRIT "<2>" /* critical condition */ #define KERN_ERR "<3>" /* error...
NightfallDM/xbook2
library/xlibc/include/arch/const.h
<reponame>NightfallDM/xbook2 #ifndef _LIB_ARCH_CONST_H #define _LIB_ARCH_CONST_H #include <arch/config.h> #define KB 1024 #define MB (KB * 1024) #define GB (MB * 1024) #define TB (GB * 1024) #define WORDSZ _WORDSZ #endif /* _LIB_ARCH_CONST_H */
NightfallDM/xbook2
library/xlibc/syslib/spinlock.c
<gh_stars>0 #include <arch/xchg.h> #include <sys/proc.h> #include <sys/spinlock.h> #include <stdio.h> #include <errno.h> /* 自选一定次数后,才进行yeild */ #define __SPIN_COUNT 10 int spin_lock_init(spinlock_t *lock) { if (!lock) return EINVAL; lock->lock = 0; return 0; } int spin_lock(spinlock_t *lock) {...
NightfallDM/xbook2
src/kernel/syscall.c
#include <xbook/syscall.h> #include <xbook/process.h> #include <xbook/vmspace.h> #include <xbook/resource.h> #include <xbook/trigger.h> #include <xbook/alarm.h> #include <xbook/ktime.h> #include <xbook/clock.h> #include <xbook/waitque.h> #include <xbook/srvcall.h> #include <xbook/fs.h> #include <xbook/driver...
NightfallDM/xbook2
src/kernel/interrupt.c
<filename>src/kernel/interrupt.c #include <arch/interrupt.h> #include <xbook/kmalloc.h> #include <stddef.h> #include <types.h> /* var: hardware_intr_contorller must be support in arch */ extern struct hardware_intr_controller hardware_intr_contorller; /* irq描述表,更深层次地表现中断 */ irq_description_t irq_description_...
NightfallDM/xbook2
library/xlibc/stdio/remove.c
/* * libc/stdio/remove.c */ #include <stdio.h> #include <unistd.h> int remove(const char * path) { return unlink(path); }
NightfallDM/xbook2
library/xlibc/include/wchar.h
#ifndef _XLIBC_WCHAR_H #define _XLIBC_WCHAR_H #ifndef _WCHAR_T_DEFINED typedef unsigned short wchar_t; #define _WCHAR_T_DEFINED #endif #endif /* _XLIBC_WCHAR_H */
NightfallDM/xbook2
src/include/const.h
<filename>src/include/const.h #ifndef _XBOOK_CONST_H #define _XBOOK_CONST_H /* 系统信息 */ #define OS_NAME "xbook2 kernel " #define OS_VERSION "0.1.0" #define KB 1024 #define MB (1024*KB) #define GB (1024*MB) #define SECTOR_SIZE 512 #define BLOCK_SIZE 1024 #endif /* _XBOOK_CONST_H */
NightfallDM/xbook2
library/xlibc/include/sys/vmm.h
#ifndef _SYS_VMM_H #define _SYS_VMM_H #include <stddef.h> /* 物理内存信息 */ typedef struct { unsigned long ms_total; /* 物理内存总大小 */ unsigned long ms_free; /* 物理内存空闲大小 */ unsigned long ms_used; /* 物理内存已使用大小 */ } mstate_t; int mstate(mstate_t *ms); /* vmm */ void *heap(void *heap); int munmap(void *a...
NightfallDM/xbook2
src/include/list.h
#ifndef _xBOOK_LIST_H #define _xBOOK_LIST_H #include <stddef.h> /* * 链表数据结构,在看了Linux的链表结构之后,觉得他那个比较通用, * 而且也比较清晰,所以我打算移植一个过来。本文件里面的都是内联函数, * 使用的时候会编译在调用的地方。并且还有很多宏定义。 */ /* * 链表结构体 */ typedef struct list { struct list *prev; struct list *next; } list_t; /* 为链表结构赋值 */ #define LIST_HEAD_INIT(name) { &(na...
NightfallDM/xbook2
src/lib/fifoio.c
#include <xbook/fifoio.h> #include <assert.h> #include <math.h> #include <string.h> /** * fifo_io_init - io队列的初始化 * @fifo: io队列 */ int fifo_io_init(fifo_io_t *fifo, unsigned char *buffer, unsigned int size) { /* 大小必须是2的n次幂 */ if (!is_power_of_2(size)) return -1; fifo->buff...
NightfallDM/xbook2
src/arch/x86/include/arch/memory.h
#ifndef _X86_MEMORY_H #define _X86_MEMORY_H #define flush_tlb_one(addr) \ __asm__ __volatile__ ("invlpg (%0) \n\t"::"r"(addr):"memory") /* */ #define flush_tlb() \ do \ { \ unsigned long tmpreg; \ __asm__ __volatile__ ( \ "movl %%cr3, %0 \n\t" \ "movl %0, %%cr3 \n\t" \ :"=r...
NightfallDM/xbook2
src/lib/fifobuf.c
#include <xbook/fifobuf.h> #include <xbook/kmalloc.h> #include <math.h> #include <assert.h> #include <string.h> void fifo_buf_init(fifo_buf_t *fifo, unsigned char *buffer, unsigned int size) { /* 大小必须是2的n次幂 */ if (!is_power_of_2(size)) return; fifo->buffer = buffer; f...
NightfallDM/xbook2
src/arch/x86/include/arch/config.h
<reponame>NightfallDM/xbook2 #ifndef _X86_CONFIG_H #define _X86_CONFIG_H /* debug methods: 1 -> in text mode, in os. 2 -> serial send to host machine console */ #define CONFIG_DEBUG_METHOD 2 /* 把控制台的信息同时输出到串口,用于调试 */ #define CONFIG_CONS_TO_SERIAL 1 #endif /* _X86_CONFIG_H */
NightfallDM/xbook2
library/xlibc/stdlib/stream.c
#include <stdlib.h> int fflush(void *file) { return 0; }
NightfallDM/xbook2
src/include/gui/keyboard.h
#ifndef __GUISRV_DRIVER_KEYBOARD_H__ #define __GUISRV_DRIVER_KEYBOARD_H__ #define GUI_KMOD_SHIFT_L 0x01 #define GUI_KMOD_SHIFT_R 0x02 #define GUI_KMOD_SHIFT (GUI_KMOD_SHIFT_L | GUI_KMOD_SHIFT_R) #define GUI_KMOD_CTRL_L 0x04 #define GUI_KMOD_CTRL_R 0x08 #define GUI_KMOD_CTRL (GUI_KMOD_CTRL_L | ...
NightfallDM/xbook2
src/kernel/rawblock.c
#include <xbook/rawblock.h> #include <string.h> #include <math.h> #include <xbook/debug.h> #include <xbook/driver.h> #include <xbook/kmalloc.h> #define DEBUG_LOCAL 0 LIST_HEAD(raw_block_list); raw_block_t *raw_block_alloc(handle_t handle, char *name) { raw_block_t *block = kmalloc(sizeof(raw_block_t...
NightfallDM/xbook2
library/xlibc/include/srv/guisrv.h
<filename>library/xlibc/include/srv/guisrv.h #ifndef _SRV_GUI_SRV_H #define _SRV_GUI_SRV_H /* gui server call */ #if 0 enum guisrv_call_num { GUISRV_OPEN_DISPLAY = 0, GUISRV_CLOSE_DISPLAY, GUISRV_CREATE_WIN, GUISRV_DESTROY_WIN, GUISRV_MAP_WIN, GUISRV_UNMAP_WIN, GUISRV_SET_WMNAME, GUISRV...
NightfallDM/xbook2
library/xlibc/unistd/dir.c
<reponame>NightfallDM/xbook2<filename>library/xlibc/unistd/dir.c #include <unistd.h> #include <types.h> #include <stddef.h> #include <string.h> #include <math.h> #include <dirent.h> #include <stdio.h> #include <math.h> #include <assert.h> #include <sys/srvcall.h> #include <srv/filesrv.h> #include <sys/dir.h> #include ...
NightfallDM/xbook2
src/include/xbook/vmarea.h
#ifndef _XBOOK_VMAREA_H #define _XBOOK_VMAREA_H #include <stddef.h> #include <list.h> #include <types.h> #include <arch/page.h> #include <arch/pmem.h> #define VMAREA_BASE __VMAREA_BASE #define VMAREA_END __VMAREA_END /* 虚拟区域结构体 */ typedef struct vmarea { unsigned long addr; unsigned long si...
NightfallDM/xbook2
src/arch/x86/mach-i386/ioremap.c
#include <xbook/debug.h> #include <arch/page.h> #include <arch/ioremap.h> int __ioremap(unsigned long paddr, unsigned long vaddr, size_t size) { unsigned long end = vaddr + size; while (vaddr < end) { /* 添加页面 */ __page_link(vaddr, paddr, PG_RW_W | PG_US_S); vaddr += PAGE_SIZE; p...
NightfallDM/xbook2
src/task/pthread.c
#include <xbook/task.h> #include <xbook/schedule.h> #include <xbook/process.h> #include <xbook/pthread.h> #include <arch/interrupt.h> #include <arch/task.h> #define DEBUG_LOCAL 0 /* 用户线程 */ void pthread_desc_init(pthread_desc_t *pthread) { if (pthread != NULL) { /* 最开始只有一个主线程(当前进程) */ ...
NightfallDM/xbook2
src/include/xbook/mutexlock.h
/* 互斥锁: 互斥锁(Mutex)是在原子操作API的基础上实现的信号量行为。互斥锁不能进行递归锁定或解锁, 能用于交互上下文但是不能用于中断上下文,同一时间只能有一个任务持有互斥锁,而且只有这个任务可以对互斥锁进行解锁。 当无法获取锁时,线程进入睡眠等待状态。 互斥锁是信号量的特例。信号量的初始值表示有多少个任务可以同时访问共享资源,如果初始值为1,表示只有1个任务可以访问, 信号量变成互斥锁(Mutex)。但是互斥锁和信号量又有所区别,互斥锁的加锁和解锁必须在同一线程里对应使用,所以互斥锁只能用于线程的互斥; 信号量可以由一个线程释放,另一个线程得到,所以信号量可以用于线程的同步。 1...
NightfallDM/xbook2
library/xlibc/include/srv/filesrv.h
<filename>library/xlibc/include/srv/filesrv.h #ifndef _SRV_FILE_SRV_H #define _SRV_FILE_SRV_H /* file server call */ enum filesrv_call_num { FILESRV_OPEN = 0, FILESRV_CLOSE, FILESRV_READ, FILESRV_WRITE, FILESRV_LSEEK, FILESRV_ASSERT, FILESRV_OPENDIR, FILESRV_CLOSEDIR, FILESRV_READDI...
NightfallDM/xbook2
library/xlibc/math/floor.c
<reponame>NightfallDM/xbook2 /* File: floor.c Contains: For round down Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT floor(M_FLOAT x) { int intX = x; if (x < 0 && x < intX) return intX - 1.0; retu...
NightfallDM/xbook2
src/ipc/pipe.c
<gh_stars>0 #include <xbook/pipe.h> #include <xbook/trigger.h> #include <xbook/debug.h> #include <fsal/fsal.h> #include <types.h> #include <fcntl.h> #include <unistd.h> LIST_HEAD(pipe_list_head); static kobjid_t pipe_next_id = 0; pipe_t *create_pipe() { pipe_t *pipe = kmalloc(sizeof(pipe_t)); if (pipe == NU...
NightfallDM/xbook2
src/kernel/debug.c
<reponame>NightfallDM/xbook2<filename>src/kernel/debug.c #include <xbook/debug.h> #include <stdarg.h> #include <string.h> #include <xbook/spinlock.h> #include <arch/interrupt.h> #include <arch/cpu.h> #include <arch/debug.h> #include <stdio.h> char *printk_msg[] = { "emege: ", "alter: ", "crit: ", "err...
NightfallDM/xbook2
library/xlibc/stdlib/malloc.c
<reponame>NightfallDM/xbook2 /** * 这种内存分配方式,只会扩展堆,而不会对堆进行缩小。 * 1.使用显示双向链表,按地址顺序维护内存块。 * 2.使用循环首次适应算法进行空闲块的选择。 */ #include <stddef.h> #include <types.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #define __HAS_NOT_USED 0 #define __HAS_USED 1 #define ALIGN8(size) ((size + 8) & (~7)) #define ALIGN...
NightfallDM/xbook2
src/vmm/vmm.c
<reponame>NightfallDM/xbook2 #include <arch/pmem.h> #include <xbook/vmm.h> #include <xbook/debug.h> #include <xbook/vmspace.h> void vmm_init(vmm_t *vmm) { vmm->page_storage = copy_kernel_page_storge(); if (vmm->page_storage == NULL) { panic(KERN_EMERG "task_init_vmm: kmalloc for page_storege f...
NightfallDM/xbook2
src/gui/console/console.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <math.h> #include <sys/input.h> #include <sys/trigger.h> /// 程序本地头文件 #include <gui/console/cursor.h> #include <gui/console/console.h> #include <gui/console/clipboard.h> #include <gui/screen.h> #include <gui/keyboard.h> #include <gu...
NightfallDM/xbook2
src/arch/x86/include/arch/hwinfo.h
#ifndef _X86_HWINFO_H #define _X86_HWINFO_H #include <arch/config.h> #include <arch/cmos.h> /* hardware info */ #endif /* _X86_HWINFO_H */
NightfallDM/xbook2
library/xlibc/stdio/setvbuf.c
<reponame>NightfallDM/xbook2 /* * libc/stdio/setvbuf.c */ #include <stdio.h> int setvbuf(FILE * f, char * buf, int mode, size_t size) { f->rwflush(f); f->mode = mode; return 0; }
NightfallDM/xbook2
src/arch/x86/mach-i386/vmm.c
#include <arch/page.h> #include <arch/vmm.h> #include <xbook/kmalloc.h> #include <xbook/debug.h> #include <xbook/vmspace.h> #include <xbook/vmm.h> #include <string.h> #define DEBUG_LOCAL 0 static int do_copy_share_page(addr_t vaddr, vmm_t *child, vmm_t *parent) { /* 保存物理地址 */ addr_t paddr = addr_v2p(vaddr); ...
NightfallDM/xbook2
src/arch/x86/include/arch/vmm.h
#ifndef _X86_VMM_H #define _X86_VMM_H #include <xbook/task.h> int __copy_vm_mapping(task_t *child, task_t *parent); #define copy_vm_mapping __copy_vm_mapping #endif /*_X86_VMM_H */
NightfallDM/xbook2
src/include/xbook/fs.h
#ifndef _XBOOK_FS_H #define _XBOOK_FS_H #define LOCAL_FILE_OPEN_NR 128 #include <stddef.h> #include <stdint.h> #include <types.h> #define FILE_FD_ALLOC 0X01 /* alloced */ #define FILE_FD_NORMAL 0X02 /* is normal file */ #define FILE_FD_DEVICE 0X04 /* is a device */ #define FILE_FD_SOCKET 0X08 /* i...
NightfallDM/xbook2
src/vmm/vmspace.c
<gh_stars>0 #include <xbook/vmspace.h> #include <xbook/task.h> #include <xbook/debug.h> #define DEBUG_LOCAL 0 void dump_vmspace(vmm_t *vmm) { if (vmm == NULL) return; vmspace_t *space = vmm->vmspace_head; while (space != NULL) { printk(KERN_INFO "space: start=%x end=%x pr...
NightfallDM/xbook2
src/ipc/sem.c
<reponame>NightfallDM/xbook2 #include <xbook/memcache.h> #include <xbook/debug.h> #include <string.h> #include <string.h> #include <xbook/sem.h> #include <sys/ipc.h> /* debug sem : 1 enable, 0 disable */ #define DEBUG_SEM 0 sem_t *sem_table; /* 保护信号量的分配与释放 */ DEFINE_SEMAPHORE(sem_mutex, 1); /** * s...
NightfallDM/xbook2
src/kernel/ktime.c
#include <xbook/ktime.h> #include <xbook/clock.h> #include <xbook/task.h> #include <xbook/debug.h> ktime_t ktime; /* 每月对应的天数,2月的会在闰年是加1 */ const char month_day[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; void loop_delay(int t) { long i, j; for (i = 0; i < 100 * t; i++) for (j = 0; j < 10...
NightfallDM/xbook2
src/include/gui/color.h
#ifndef __GRAPH_COLOR_H__ #define __GRAPH_COLOR_H__ #include <stdint.h> #define SCREEN_COLOR uint32_t #define GUI_COLOR uint32_t #define COLOR_NO_ALPHA 255 #define __ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #define COLOR_ARGB(a, r, g, b) __ARGB((a) & 0xff, (r) & 0xff, (g) & 0xff, (b) & ...
NightfallDM/xbook2
src/task/mutexlock.c
#include <xbook/mutexlock.h> #include <xbook/schedule.h> /** * mutex_lock - 互斥锁加锁 * @mutex: 锁对象 */ void mutex_lock(mutexlock_t *mutex) { do { /* 保证整个函数是原子的 */ disable_intr(); /* 循环+等待,做更深的判断 */ if (!atomic_xchg(&mutex->count, 1)) { /* 如果获取到锁,直接返回 */ ...
NightfallDM/xbook2
src/include/xbook/net.h
<gh_stars>0 #ifndef _XBOOK_NET_H #define _XBOOK_NET_H #include <lwip/sockets.h> void init_net(void); /* 套接字参数传递 */ struct _sockarg { void *buf; /* 缓冲区 */ int len; /* 缓冲区长度 */ unsigned int flags; /* 标志 */ struct sockaddr *to_from; /* 传输目的地或者传输源 */ so...
NightfallDM/xbook2
library/xlibc/math/frexp.c
/* File: frexp.c Contains: Split a float into mantissa and exponent Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT frexp(double x, int *exptr) { union { double* _x; double_t* x; } ux; ux._...
NightfallDM/xbook2
library/xlibc/stdlib/abs.c
#include<stdlib.h> int abs(int const i) { return i>0?i:-i; }
NightfallDM/xbook2
src/include/gui/text.h
#ifndef __GRAPH_TEXT_H__ #define __GRAPH_TEXT_H__ #include "color.h" #include "font.h" void gui_draw_word_ex( int x, int y, char word, GUI_COLOR color, gui_font_t *font ); void gui_draw_text_ex( int x, int y, char *text, GUI_COLOR color, gui_font_t *font ); void gui_draw_word...
NightfallDM/xbook2
src/lib/trigger.c
<reponame>NightfallDM/xbook2<gh_stars>0 #include <xbook/trigger.h> /** * trigaddset - 触发器集添加一个触发器 * @set: 触发器集 * @trig: 触发器 */ int trigaddset(trigset_t *set,int trig) { if (IS_BAD_TRIGGER(trig)) return -1; *set |= (1 << trig); return 0; } /** * trigdelset - 触发器集删除一个触发器 * @se...
NightfallDM/xbook2
library/xlibc/math/pow.c
<reponame>NightfallDM/xbook2 /* File: pow.c Contains: For x^y Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT pow(double x, double y) { union { double d; int x[2]; } u = { x }; u.x[1] = (int...
NightfallDM/xbook2
tools/fatfs/main.c
<filename>tools/fatfs/main.c #include <stdio.h> #include <string.h> #include "driver.h" #include <stdlib.h> #ifdef WIN32 #include <io.h> #else #include <sys/dir.h> #include <dirent.h> #include <unistd.h> #endif #include "ff.h" #define DEBUG_LOCAL 0 /* 磁盘驱动,把镜像文件模拟成一个磁盘设备 */ /* 镜像目录 */ //#define IMAGE_FILE "D:/Dev...
NightfallDM/xbook2
library/xlibc/console/xcons.c
#include <sys/syscall.h> #include <xcons.h> int xcons_clear() { syscall0(int, SYS_XCONCLEAR); return 0; } int xcons_getkey(int *buf, int flags) { return syscall2(int, SYS_XCONGET, buf, flags); } int xcons_putstr(void *buf, int len) { return syscall2(int, SYS_XCONPUT, buf, len); }
NightfallDM/xbook2
src/include/xbook/rawblock.h
<reponame>NightfallDM/xbook2 #ifndef _XBOOK_RAW_BLOCK_H #define _XBOOK_RAW_BLOCK_H #include "driver.h" #include <list.h> #include <xbook/config.h> #define RAW_BLOCK_NAME_LEN 24 #define RB_SEEK_SET 0 #define RB_SEEK_CUR 1 #define RB_SEEK_END 2 #define RB_BLOCK_NR 256 #define RB_DEVICE "vfloppy" ...
NightfallDM/xbook2
src/include/gui/rect.h
<filename>src/include/gui/rect.h #ifndef __GRAPH_RECT_H__ #define __GRAPH_RECT_H__ #include "color.h" void gui_draw_rect_fill(int x, int y, int width, int height, GUI_COLOR color); void gui_draw_rect(int x, int y, int width, int height, GUI_COLOR color); #endif /* __GRAPH_RECT_H__ */
NightfallDM/xbook2
src/gui/gui.c
#include <gui/screen.h> #include <gui/keyboard.h> #include <gui/mouse.h> #include <gui/event.h> #include <gui/font.h> #include <gui/text.h> #include <gui/rect.h> #include <gui/console/console.h> #include <xbook/debug.h> #include <xbook/gui.h> #include <xbook/task.h> /* 主要是处理输入事件 */ void kgui_thread(void *arg) { c...
NightfallDM/xbook2
src/arch/x86/include/arch/bootmem.h
<filename>src/arch/x86/include/arch/bootmem.h #ifndef _X86_BOOTMEM_H #define _X86_BOOTMEM_H #include <stddef.h> /* bootmem是用于初始化内核内存空间以及其数据结构的一个简单 分配器。在这里,我们尽量做得简单。 */ typedef struct boot_mem { unsigned int start_addr; // 记录从哪个地方开始进行分配 unsigned int cur_addr; // 当前分配到的位置的地址 unsigned int top_addr; ...
NightfallDM/xbook2
src/include/fsal/dir.h
#ifndef __FILESRV_FSAL_DIR_H__ #define __FILESRV_FSAL_DIR_H__ #include "fsal.h" #include "../../fs/fatfs/ff.h" #include <stdint.h> #include <types.h> /* 允许打开的目录数量 */ #define FSAL_DIR_OPEN_NR 128 #define FSAL_DIR_USED 0X01 /* 目录结构 */ typedef int dir_t; typedef struct { char flags; /* 文件标...
NightfallDM/xbook2
src/task/waitqueue.c
<filename>src/task/waitqueue.c<gh_stars>0 #include <xbook/waitqueue.h> #include <xbook/task.h> /** * wait_queue_add - 把进程添加到等待队列中 * @wait_queue: 等待队列 * @task: 要添加的任务 */ void wait_queue_add(wait_queue_t *wait_queue, void *_task) { task_t *task = (task_t *) _task; /* 添加到队列时,需要关闭中断 */ unsigned lo...
NightfallDM/xbook2
library/xlibc/stdio/printf.c
/* * libc/stdio/printf.c */ #include <stdarg.h> #include <sizes.h> #include <stdio.h> int printf(const char * fmt, ...) { va_list ap; char buf[SZ_1K] = {0}; int rv; va_start(ap, fmt); rv = vsnprintf(buf, SZ_4K, fmt, ap); va_end(ap); rv = (fputs(buf, stdout) < 0) ? 0 : rv; fflush(stdout); return rv; }
NightfallDM/xbook2
library/xlibc/include/sys/mount.h
<reponame>NightfallDM/xbook2 #ifndef _SYS_MOUNT_H #define _SYS_MOUNT_H int mount( const char *source, const char *target, const char *fstype, unsigned long flags ); int unmount(const char *source, unsigned long flags); int mkfs( const char *source, const char *fstype, unsigned long flags ...
NightfallDM/xbook2
library/xlibc/math/exp.c
<gh_stars>0 /* File: exp.c Contains: For e^x Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT exp(M_FLOAT x) { /* It's not important */ if (fabs(x) < EPSILON) return (1.0); x = 1.0 + x / 16384; /* set...
NightfallDM/xbook2
user/tests/xlibc_test.c
<reponame>NightfallDM/xbook2<gh_stars>0 #include"test.h" int xlibc_test(int argc,char *argv[]) { puts("-----------xlibc_test------------"); puts("time"); printf("%lu\n",time(NULL)); puts("stdlib"); srand(time(NULL)); for(int count=0;count<10;count++) { printf("%d ",rand()); } putchar('\n'); for(int coun...
NightfallDM/xbook2
src/arch/x86/include/arch/atomic.h
<reponame>NightfallDM/xbook2 #ifndef _ARCH_ATOMIC_H #define _ARCH_ATOMIC_H #include <arch/instruction.h> /* 原子变量结构体 */ typedef struct { int value; // 变量的值 } atomic_t; #define atomic_get(atomic) ((atomic)->value) #define atomic_set(atomic,val) (((atomic)->value) = (val)) #define ATOMIC_INIT(val) {val} void __...
NightfallDM/xbook2
src/include/gui/event.h
<reponame>NightfallDM/xbook2 #ifndef __GUISRV_EVENT_H__ #define __GUISRV_EVENT_H__ /* 图形事件状态 */ typedef enum _gui_event_state { GUI_NOSTATE = 0, /* 无状态 */ GUI_PRESSED, /* 按下状态 */ GUI_RELEASED, /* 释放状态 */ GUI_ENTER, /* 进入状态 */ GUI_LEAVE, /* 离开状态...
NightfallDM/xbook2
src/arch/x86/mach-i386/pic.c
<gh_stars>0 #include <arch/pic.h> #include <arch/io.h> #include <arch/interrupt.h> #include <arch/interrupt.h> /** * InitPic - 初始化pic */ void init_pic(void) { /* mask all intr */ __out8(PIC_MASTER_CTLMASK, 0xff ); __out8(PIC_SLAVE_CTLMASK, 0xff ); /* set master pic */ __out8(PIC_MASTER_CTL, 0x1...
NightfallDM/xbook2
library/xlibc/math/log10.c
<gh_stars>0 /* File: log10.c Contains: For log(10)(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT log10(M_FLOAT x) { return (LOG_MULTIPLE / MATH_LN10 * log2(x)); }
NightfallDM/xbook2
library/xlibc/syslib/trigger.c
#include <sys/trigger.h> #include <sys/syscall.h> /** * trigaddset - 触发器集添加一个触发器 * @set: 触发器集 * @trig: 触发器 */ int trigaddset(trigset_t *set,int trig) { if (IS_BAD_TRIGGER(trig)) return -1; *set |= (1 << trig); return 0; } /** * trigdelset - 触发器集删除一个触发器 * @set: 触发器集 * @trig: 触发器 */ int trig...
NightfallDM/xbook2
src/include/fcntl.h
#ifndef _XLIBC_FCNTL_H #define _XLIBC_FCNTL_H #include <stdint.h> enum { F_SETFL = 1, F_GETFL, }; #endif /* _XLIBC_FCNTL_H */
NightfallDM/xbook2
user/tests/test_jpg.c
<filename>user/tests/test_jpg.c #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <errno.h> #include <jpeglib.h> #include <jmorecfg.h> #include <jconfig.h> #include "test.h" int jpg_display(char * path)// **指定图片的路径就可以调用这个jpg的解析。** { //LCD_init(); /* 1. 分配并初始化一个jpeg解压...
NightfallDM/xbook2
src/gui/event.c
<filename>src/gui/event.c #include <xbook/kmalloc.h> #include <stddef.h> #include <gui/event.h> #include <gui/keyboard.h> #include <gui/mouse.h> gui_event_pool *event_pool; /* 添加一个事件 */ int gui_event_add(gui_event *ev) { /* 检查事件池满 */ int next = (event_pool->head + 1) % GUI_EVENT_NR; if (next == event_poo...
NightfallDM/xbook2
src/arch/x86/mach-i386/segment.c
#include <arch/registers.h> #include <arch/segment.h> #include <arch/tss.h> /* * Global descriptor table */ struct segment_descriptor *gdt; static void set_segment_descriptor(struct segment_descriptor *descriptor, unsigned int limit, \ unsigned int base, unsigned int attributes) { descriptor->limit_low = lim...
NightfallDM/xbook2
src/include/fsal/fatfs.h
<filename>src/include/fsal/fatfs.h #ifndef __FILESRV_FSAL_FATFS_H__ #define __FILESRV_FSAL_FATFS_H__ #include "fsal.h" extern fsal_t fatfs_fsal; #endif /* __FILESRV_FSAL_FATFS_H__ */
NightfallDM/xbook2
library/xlibc/include/sys/time.h
<gh_stars>0 #ifndef _SYS_TIME_H #define _SYS_TIME_H #include "ktime.h" #include <types.h> //#include <time.h> #define CLOCK_REALTIME 1 /*系统统当前时间,从1970年1.1日算起*/ #define CLOCK_MONOTONIC 2 /*系统的启动时间,不能被设置*/ #define CLOCK_PROCESS_CPUTIME_ID 3 /* 本进程运行时间*/ #define CLOCK_THREAD_CPUTIME_ID 4 /*本线程运行时...
NightfallDM/xbook2
src/task/schedule.c
#include <xbook/schedule.h> #include <xbook/task.h> #include <assert.h> #include <xbook/debug.h> #include <arch/interrupt.h> #include <arch/task.h> #define DEBUG_LOCAL 0 extern task_t *task_idle; /* 优先级队列 */ priority_queue_t priority_queue[MAX_PRIORITY_NR]; /* 最高等级的队列 */ priority_queue_t *highest_pri...
NightfallDM/xbook2
src/arch/x86/mach-i386/ards.c
#include <xbook/debug.h> #define ARDS_ADDR 0x80001000 //ARDS结构从哪儿开始储存 #define MAX_ARDS_NR 12 //最大有12个ards结构 /* ards结构体 */ struct ards_struct { unsigned int baseLow; //基址低32位 unsigned int base_high; unsigned int lengthLow; //长度低32位 unsigned int length_high; unsigned int type; //该结构的类型(1可以被系统使用) }; unsig...
NightfallDM/xbook2
src/arch/x86/include/arch/interrupt.h
#ifndef _ARCH_INTERRUPT_H #define _ARCH_INTERRUPT_H #include "atomic.h" #include "registers.h" void __disable_intr(void); void __enable_intr(void); /* save intr status and disable intr */ #define __save_intr(flags) \ do { \ flags = (unsigned int)load_e...
NightfallDM/xbook2
library/xlibc/syslib/srvcall.c
<gh_stars>0 #include <sys/syscall.h> #include <sys/srvcall.h> int srvcall_bind(int port) { return syscall1(int, SYS_SRVCALL_BIND, port); } int srvcall_unbind(int port) { return syscall1(int, SYS_SRVCALL_UNBIND, port); } int srvcall_listen(int port, srvarg_t *arg) { return syscall2(int, SYS_SRVCALL_LISTEN,...
NightfallDM/xbook2
library/xlibc/include/sys/filedes.h
<reponame>NightfallDM/xbook2<filename>library/xlibc/include/sys/filedes.h<gh_stars>0 #ifndef _SYS_FILEDES_H #define _SYS_FILEDES_H #endif /* _SYS_FILEDES_H */
NightfallDM/xbook2
src/fs/fsal/dir.c
<reponame>NightfallDM/xbook2 #include <fsal/dir.h> #include <string.h> #include <assert.h> #include <xbook/kmalloc.h> /* 目录表指针 */ fsal_dir_t *fsal_dir_table; /** * init_fsal_dir_table - 初始化目录表 * * 分配目录表内存,并清空 */ int init_fsal_dir_table() { fsal_dir_table = kmalloc(FSAL_DIR_OPEN_NR * sizeof(fsal_dir_t)); ...
NightfallDM/xbook2
library/xlibc/math/asin.c
<filename>library/xlibc/math/asin.c /* File: asin.c Contains: For arcsin(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT asin(M_FLOAT x) { return atan2(x, sqrt(1.0 - x * x)); }
NightfallDM/xbook2
src/fs/diskman.c
<gh_stars>0 #include <list.h> #include <xbook/diskman.h> #include <xbook/resource.h> #include <xbook/kmalloc.h> #include <string.h> #include <stdio.h> LIST_HEAD(disk_list_head); static int next_disk_solt = 0; static int disk_solt_cache[DISK_SOLT_NR]; #define IS_BAD_SOLT(solt) \ (solt < 0 || solt >= DISK_SOL...
NightfallDM/xbook2
src/include/xbook/waitque.h
<filename>src/include/xbook/waitque.h #ifndef _XBOOK_WAIT_QUE_H #define _XBOOK_WAIT_QUE_H /* 用户态使用的等待队列 */ #include "waitqueue.h" #define WAITQUE_USING (1 << 0) /* 用户态等待队列 */ typedef struct __waitque { wait_queue_t wait_queue; /* 等待队列 */ unsigned int flags; /* 标志 */ } waitque...
NightfallDM/xbook2
library/xlibc/math/atan2.c
<gh_stars>0 /* File: atan2.c Contains: For arctan2(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> #define DBL_EPSILON 2.2204460492503131e-016 #ifdef __LIB_32B__ #define PI M_PI #else #define PI M_PIl #endif static const ...
NightfallDM/xbook2
library/xlibc/include/math.h
#ifndef _XLIBC_MATH_H #define _XLIBC_MATH_H #include <arch/config.h> #include <stddef.h> /* max() & min() */ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) /* 除后上入 */ #define DIV_ROUND_UP(X, STEP) ((X + STEP - 1) / (STEP)) /* 除后下舍 */ #define DIV_ROUND_DOWN(X, STEP) ((X) / (STEP))...
NightfallDM/xbook2
library/xlibc/math/math.c
/* File: math.c Contains: For all math const data Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> #ifdef __LIB_32B__ const M_FLOAT MATH_PI = M_PI; const M_FLOAT MATH_PI_D = M_PI_D; const M_FLOAT MATH_PI_2 = M_PI_2; const M_FLO...
NightfallDM/xbook2
user/tests/socket_test.c
<filename>user/tests/socket_test.c<gh_stars>0 #include "test.h" #include <arpa/inet.h> #define MAXLINE 4096 int socket_test(int argc, char *argv[]) { int sockfd; char sendline[4096]; struct sockaddr_in servaddr; if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("create ...
NightfallDM/xbook2
library/xlibc/include/sys/input.h
#ifndef _SYS_INPUT_H #define _SYS_INPUT_H #include <stdint.h> typedef struct input_event { uint16_t type; uint16_t code; uint32_t value; } input_event_t; #define EV_SYN 0x00 #define EV_KEY 0x01 #define EV_REL 0x02 #define EV_ABS 0x03 //绝对坐标 #define EV_M...
NightfallDM/xbook2
library/xlibc/stdlib/abort.c
#include <stdlib.h> #include <sys/trigger.h> #include <sys/proc.h> void abort(void) { triggeron(TRIGHSOFT, getpid()); }
NightfallDM/xbook2
src/arch/x86/include/arch/registers.h
#ifndef _X86_REGISTERS_H #define _X86_REGISTERS_H void load_tr(unsigned int tr); void load_gdtr(unsigned int limit, unsigned int addr); void load_idtr(unsigned int limit, unsigned int addr); unsigned int load_eflags(void); void store_gdtr(unsigned int gdtr); void store_idtr(unsigned int idtr); void store_eflags(unsig...
NightfallDM/xbook2
src/include/xbook/vmspace.h
<reponame>NightfallDM/xbook2 #ifndef _XBOOK_VMSPACE_H #define _XBOOK_VMSPACE_H #include "vmm.h" #include "memcache.h" #include <stddef.h> #include <stdint.h> #include <types.h> #include <arch/page.h> /* map flags */ #define VMS_MAP_FIXED 0x10 /* 映射固定位置 */ #define VMS_MAP_STACK 0x20 ...
NightfallDM/xbook2
src/include/sys/kfile.h
<reponame>NightfallDM/xbook2 #ifndef _SYS_KFILE_H #define _SYS_KFILE_H typedef struct { unsigned char *file; unsigned long size; } kfile_t; #endif /* _SYS_KFILE_H */
NightfallDM/xbook2
user/bosh/shell.c
<reponame>NightfallDM/xbook2 #include <stdio.h> #include <xcons.h> #include <string.h> #include <sys/input.h> #include <sys/trigger.h> #include "cmd.h" #include "shell.h" int shell_event_poll(char *buf, int pid) { int keybuf[2]; *buf = 0; /* 获取事件 */ if (xcons_getkey(keybuf, 1) < 0) return -...
NightfallDM/xbook2
user/socket_server/main.c
<reponame>NightfallDM/xbook2<filename>user/socket_server/main.c #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<stdio.h> #include<stdlib.h> #include<netinet/in.h> #include<arpa/inet.h> #include<sys/ioctl.h> #include<string.h> int main() { //创建一个socket int listenSocket=socket(AF_INET,S...
NightfallDM/xbook2
src/include/xbook/process.h
#ifndef _XBOOK_PROCESS_H #define _XBOOK_PROCESS_H #include "task.h" #include "elf32.h" #include <sys/kfile.h> task_t *start_process(char *name, char **argv); int proc_destroy(task_t *task, int thread); int proc_vmm_init(task_t *task); int proc_vmm_exit(task_t *task); int proc_build_arg(unsigned long arg_to...
NightfallDM/xbook2
library/xlibc/include/utime.h
<filename>library/xlibc/include/utime.h #ifndef _XLIBC_UTIME_H #define _XLIBC_UTIME_H #include <types.h> #include <stddef.h> struct utimbuf { time_t actime; /* access time */ time_t modtime; /* modification time */ }; int utime(const char *pathname, const struct utimbuf *times); #endif /* _XLIBC_U...
NightfallDM/xbook2
src/include/xbook/byteorder.h
<filename>src/include/xbook/byteorder.h<gh_stars>0 /* 字序转换,大端字序和小端字序 */ #ifndef _XBOOK_BYTEORDER_H #define _XBOOK_BYTEORDER_H #include <stdint.h> /** * swap16 - 16位的字节交换 * @data: 需要交换的数据 * * 返回交换后的数据 */ static inline uint16_t swap16(uint16_t data) { return (uint16_t)((data & 0xFF) << 8) | ((...
NightfallDM/xbook2
src/vmm/vmarea.c
<gh_stars>0 #include <arch/interrupt.h> #include <arch/ioremap.h> #include <xbook/vmarea.h> #include <xbook/debug.h> #include <xbook/bitmap.h> #include <xbook/memcache.h> #include <string.h> /* vir addr management bitmap */ static bitmap_t vaddr_bitmap; /* vaddr start base */ static unsigned long vaddr_ba...
NightfallDM/xbook2
user/tests/libvideo.c
#include "test.h" static video_info_t video_info; /* R5G6B5 color helper */ static uint32_t GUI_TO_R5G6B5(uint32_t gui_color) { uint32_t r, g, b; b = gui_color&0xF8; g = gui_color&0xFC00; r = gui_color&0xF80000; return (b>>3)|(g>>5)|(r>>8); } static unsigned int video_ram_size = 0;...
NightfallDM/xbook2
src/arch/x86/mach-i386/page.c
<reponame>NightfallDM/xbook2<filename>src/arch/x86/mach-i386/page.c #include <arch/page.h> #include <arch/pmem.h> #include <arch/instruction.h> #include <arch/registers.h> #include <arch/tss.h> #include <xbook/debug.h> #include <math.h> #include <string.h> #include <assert.h> #include <xbook/task.h> #include <xbook/vms...
NightfallDM/xbook2
src/gui/lowlevel/screen.c
<filename>src/gui/lowlevel/screen.c<gh_stars>0 #include <string.h> #include <stdio.h> #include <xbook/driver.h> #include <sys/ioctl.h> #include <xbook/kmalloc.h> #include <xbook/vmarea.h> /// 程序本地头文件 #include <gui/screen.h> #define DEBUG_LOCAL 0 #ifndef GUI_SCREEN_DEVICE_NAME #define GUI_SCREEN_DEVICE_NAME ...
NightfallDM/xbook2
src/gui/graph/text.c
<gh_stars>0 #include <gui/screen.h> #include <gui/text.h> static void gui_draw_word_bit( int x, int y, GUI_COLOR color, uint8_t *data ) { unsigned int i; uint8_t d /* data */; for (i = 0; i < 16; i++) { d = data[i]; if ((d & 0x80) != 0) gui_screen.output_pixel(x + 0, y + i, color); ...
NightfallDM/xbook2
src/arch/x86/mach-i386/bootmem.c
#include <xbook/debug.h> #include <math.h> #include <arch/bootmem.h> static boot_mem_t boot_mem_alloctor; /* * init_boot_mem - 初始化引导内存分配器 * * 初始化后就可以进行简单粗暴的内存分配了。 */ void init_boot_mem(unsigned int start, unsigned int end) { boot_mem_alloctor.start_addr = start; boot_mem_alloctor.cur_addr = boot_mem_all...
NightfallDM/xbook2
src/include/xbook/config.h
#ifndef _XBOOK_CONFIG_H #define _XBOOK_CONFIG_H /* config architecture */ #define CONFIG_ARCH_X86 /* #define CONFIG_ARCH_X64 */ /* #define CONFIG_ARCH_ARM32 */ /* #define CONFIG_ARCH_ARM64 */ /* config address width */ #define CONFIG_32BIT /* #define CONFIG_64BIT */ /* config large alloc size in memcach...