├── .gdbinit ├── CONTRIBUTING.md ├── DESIGN.md ├── INTERNALS.md ├── LICENSE.md ├── Makefile ├── README.md ├── TESTING.md ├── arch ├── i386 │ ├── apic.c │ ├── boot │ │ ├── cpu.asm │ │ ├── gdt.c │ │ ├── idt.c │ │ ├── int.asm │ │ ├── irq.c │ │ ├── main.c │ │ ├── mmu.c │ │ └── start.asm │ ├── cpuid.c │ ├── include │ │ ├── bits │ │ │ └── atomic.h │ │ └── kernel │ │ │ └── arch.h │ ├── kernel.ld │ ├── make.mk │ ├── mboot.c │ ├── pci.c │ ├── pic.c │ ├── rtc.c │ ├── serial.c │ └── tss.c └── x86_64 │ ├── include │ ├── bits │ │ └── atomic.h │ └── kernel │ │ └── arch.h │ └── make.mk ├── config.yml ├── configure ├── cov.sh ├── doc ├── Home.md ├── MemoryManagment.md ├── Structures.md ├── Utils.md ├── VirtualFileSystem.md └── timezones.txt ├── drivers ├── fs │ ├── README.md │ ├── ext2 │ │ ├── Makefile │ │ ├── blocks.c │ │ ├── dir.c │ │ ├── ext2.c │ │ ├── ext2.h │ │ ├── file.c │ │ ├── format.c │ │ ├── inodes.c │ │ └── super.c │ ├── isofs │ │ ├── Makefile │ │ ├── isofs.c │ │ └── isofs.h │ └── vfat │ │ ├── Makefile │ │ ├── data.c │ │ ├── dentry.c │ │ ├── diterator.c │ │ ├── format.c │ │ ├── module.c │ │ ├── table.c │ │ ├── utils │ │ └── format.c │ │ ├── vfat.c │ │ └── vfat.h ├── misc │ └── vbox │ │ ├── Makefile │ │ └── vbox.c ├── net │ └── ip4 │ │ ├── Makefile │ │ ├── arp.c │ │ ├── dhcp.c │ │ ├── dns.c │ │ ├── icmp.c │ │ ├── ip4.c │ │ ├── ip4.h │ │ ├── ip4_mod.c │ │ ├── ip4_sock.c │ │ ├── route.c │ │ ├── tcp.c │ │ └── udp.c └── pc │ ├── README.md │ ├── ac97 │ ├── Makefile │ └── ac97.c │ ├── ata │ ├── Makefile │ ├── ata.c │ ├── ata.h │ ├── pata.c │ └── patapi.c │ ├── e1000 │ ├── Makefile │ ├── e1000.c │ └── e1000_hw.h │ ├── ps2 │ ├── Makefile │ ├── ps2.c │ ├── ps2.h │ ├── ps2_kdb.c │ └── ps2_mouse.c │ ├── sb16 │ ├── Makefile │ └── sb16.c │ └── vga │ ├── Makefile │ ├── vga.c │ └── vga_qemu.c ├── include ├── _assert.h ├── _errno.h ├── bits │ ├── cdefs.h │ ├── cdefs │ │ ├── aarch64-gcc.h │ │ ├── arm-gcc.h │ │ ├── gcc.h │ │ ├── i386-gcc.h │ │ ├── i386-mcvs.h │ │ ├── mcvs.h │ │ ├── x86_64-gcc.h │ │ └── x86_64-mcvs.h │ └── io.h ├── c_header.sh ├── cbuild │ ├── ctype.h │ ├── iostm.h │ └── string.h ├── cc │ ├── stdarg.h │ ├── stdatomic.h │ ├── stdbool.h │ ├── stddef.h │ └── stdint.h ├── ctype.h ├── kernel │ ├── blkmap.h │ ├── bus │ │ └── pci.h │ ├── core.h │ ├── dlib.h │ ├── input.h │ ├── irq.h │ ├── memory.h │ ├── mods.h │ ├── net.h │ ├── net │ │ ├── eth.h │ │ ├── ip4.h │ │ └── lo.h │ ├── stdc.h │ ├── syscalls.h │ ├── tasks.h │ └── vfs.h ├── kora │ ├── bbtree.h │ ├── hmap.h │ ├── keys.h │ ├── llist.h │ ├── mcrs.h │ ├── rwlock.h │ ├── splock.h │ └── time.h ├── mbstring.h ├── string.h └── sys │ ├── errno.h │ ├── sem.h │ └── signum.h ├── make ├── build.mk ├── check.mk ├── drivers.mk ├── global.mk ├── host.sh └── targets.mk ├── scripts ├── bridge.sh ├── build.sh ├── cfg │ ├── grub.cfg │ ├── license.h │ ├── license.txt │ ├── menu.lst │ └── stage2_eltorito ├── coverage.sh ├── cross_gcc.sh ├── drivers.sh ├── kora.sh ├── license.sh ├── pre-commit.sh └── toolchain.sh ├── src ├── core │ ├── common.c │ ├── irq.c │ ├── launch.c │ ├── modules.c │ ├── scall_fs.c │ ├── scall_io.c │ ├── scall_mem.c │ ├── scall_sys.c │ ├── scall_task.c │ └── syscalls.c ├── mem │ ├── dlib.c │ ├── elf32.c │ ├── elf32.h │ ├── mcheck.c │ ├── memory.c │ ├── mspace.c │ ├── pages.c │ ├── vma.c │ ├── vma_anon.c │ ├── vma_dlib.c │ ├── vma_file.c │ ├── vma_misc.c │ └── vmsp.c ├── net │ ├── eth.c │ ├── lo.c │ ├── net.c │ ├── skb.c │ └── sock.c ├── stdc │ ├── allocator.h │ ├── arena.c │ ├── bbtree.c │ ├── bits.c │ ├── blkmap.c │ ├── cnd.c │ ├── debug.c │ ├── error.c │ ├── format_integer.c │ ├── format_print.c │ ├── format_scanf.c │ ├── format_vfprintf.c │ ├── format_vfscanf.c │ ├── heap.c │ ├── hmap.c │ ├── lock.c │ ├── mbstr.c │ ├── mtx.c │ ├── random.c │ ├── sem.c │ ├── string.c │ └── time.c ├── tasks │ ├── clock.c │ ├── dlib.c │ ├── elf.c │ ├── scheduler.c │ ├── streams.c │ └── threads.c └── vfs │ ├── bio.c │ ├── block.c │ ├── data.c │ ├── devfs.c │ ├── device.c │ ├── directory.c │ ├── fnode.c │ ├── framebuffer.c │ ├── fswalk.c │ ├── inode.c │ ├── parts.c │ ├── pipe.c │ ├── sock.c │ └── tarfs.c └── tests ├── cli.c ├── cli.h ├── fs_chmod.sh ├── fs_ext2.sh ├── fs_fat12.sh ├── fs_isofs.sh ├── fs_link.sh ├── fs_main.sh ├── fs_mkdir.sh ├── fs_open.sh ├── fs_paths.sh ├── fs_persist_rd.sh ├── fs_persist_rd2.sh ├── fs_persist_wr.sh ├── fs_readwrite.sh ├── fs_rename.sh ├── fs_rmdir.sh ├── fs_symlink.sh ├── fs_tarfs.sh ├── fs_truncate.sh ├── fs_unlink.sh ├── fs_utimes.sh ├── mem └── mem_main.c ├── mm_anon.sh ├── mm_dlib.sh ├── mm_elf.sh ├── mm_file.sh ├── mm_filecpy.sh ├── mm_heap.sh ├── mm_misc.sh ├── mm_start.sh ├── mm_test.sh ├── net ├── net_main.c └── subnet.c ├── net_ip0.sh ├── net_ping0.sh ├── net_udp0.sh ├── snd └── main.c ├── stub ├── stub_common.c ├── stub_irq.c ├── stub_kmap.c ├── stub_localfiles.c └── stub_task.c ├── tasks └── task_main.c ├── threads.c ├── tsk_main.sh ├── utils.h └── vfs ├── actions.c ├── cli-vfs.h ├── imgdk.c └── vfs_main.c /.gdbinit: -------------------------------------------------------------------------------- 1 | target remote localhost:1234 2 | b kpanic 3 | b __assert_fail 4 | b irq_fault 5 | b kernel_start 6 | c 7 | 8 | # add-symbol-file ../build/lib/libc.so 0x12cb0340 9 | # add-symbol-file ../build/lib/libgfx.so 0x1232da90 10 | # add-symbol-file ../build/bin/krish 0x8048ec0 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Wanna contribute to Kora ? 2 | 3 | 4 | 5 | > In the hope to recruit new developer or simply enthousiast users. Please sub scribe to KoraOS Slacks channels to get the lastest news about Kora progress. 6 | 7 | 8 | ## Do you want to raise an issue ? 9 | 10 | ## Do you wanna help with current development ? 11 | 12 | ## Do you request a new feature ? 13 | 14 | 15 | ## More about Development 16 | 17 | ### Coding conventions 18 | 19 | ### Propose a contrubution 20 | -------------------------------------------------------------------------------- /DESIGN.md: -------------------------------------------------------------------------------- 1 | 2 | ## Kernel startup 3 | 4 | At start up an architecture dependant code is run to setup the environment. At first this code save important information but give the hand to main function `kernel_start` as soon as possible. 5 | 6 | The kernel will then call back the architecture dependant code to configure in order. The memory, the cpu(s) and the clock. Those call are done by the kernel core code because we need to initialize some data structures first. 7 | 8 | After basic hardware is initialize. We initialize all module of the kernel. like file system and network. We need this prior to register any new module and devices. 9 | 10 | With the kernel ready a call is made to `platform_start()` which can declare some modules extensions and prepare some extra devices. It's also important to declare the pre-loaded modules used to complete the kernel. 11 | 12 | Finally N tasks are started as kernel threads. They will have for role to load modules, and configure the kernel by changing root, starting first usermode tasks and set users. Once all initial work have been completed those threads will terminate to keep only an idle one. 13 | 14 | ## Kernel core 15 | 16 | ## Virtual file system 17 | 18 | ## Network 19 | 20 | ## Scheduler 21 | 22 | ## Users & Security 23 | 24 | ## Modules 25 | 26 | 27 | ### Devices 28 | 29 | ### File systems 30 | 31 | ### Network protocols 32 | 33 | 34 | 35 | ---- 36 | 37 | ## x86 38 | 39 | Memory mapping 40 | 41 | - 0 GDT 42 | - 800 IDT 43 | - 1000 TSS (128 per entry - 32/4k) 44 | - 2000 MMU global directory page for CR3 45 | - 3000 MMU first directory page (for identity mapping) 46 | - 4000 Stack for BSP (2 pages) 47 | - 6000 48 | - 49 | - 20000 Kernel Code (37pages (0x25)) 50 | - 9FC00 Start Hardware ! 51 | - B8000 VBA Console 52 | - 100000 End !! 53 | - 200000 Old Code () 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /arch/i386/boot/gdt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | 24 | typedef struct x86_gdesc x86_gdesc_t; 25 | PACK(struct x86_gdesc { 26 | uint16_t lim0_15; 27 | uint16_t base0_15; 28 | uint8_t base16_23; 29 | uint8_t access; 30 | uint8_t lim16_19 : 4; 31 | uint8_t other : 4; 32 | uint8_t base24_31; 33 | }); 34 | 35 | void x86_write_gdesc(int no, uint32_t base, uint32_t limit, unsigned access, unsigned other) 36 | { 37 | x86_gdesc_t *gdesc = (void*)(no * sizeof(x86_gdesc_t)); 38 | 39 | gdesc->lim0_15 = (limit & 0xffff); 40 | gdesc->base0_15 = (base & 0xffff); 41 | gdesc->base16_23 = (base & 0xff0000) >> 16; 42 | gdesc->access = access; 43 | gdesc->lim16_19 = (limit & 0xf0000) >> 16; 44 | gdesc->other = (other & 0xf); 45 | gdesc->base24_31 = (base & 0xff000000) >> 24; 46 | } 47 | 48 | void x86_gdt() 49 | { 50 | x86_write_gdesc(1, 0, 0xfffff, 0x9B, 0x0D); // Kernel code 51 | x86_write_gdesc(2, 0, 0xfffff, 0x93, 0x0D); // Kernel data 52 | x86_write_gdesc(3, 0, 0x00000, 0x97, 0x0D); // Kernel stack 53 | x86_write_gdesc(4, 0, 0xfffff, 0xff, 0x0D); // User code 54 | x86_write_gdesc(5, 0, 0xfffff, 0xf3, 0x0D); // User data 55 | x86_write_gdesc(6, 0, 0x00000, 0xf7, 0x0D); // User stack 56 | } 57 | 58 | -------------------------------------------------------------------------------- /arch/i386/kernel.ld: -------------------------------------------------------------------------------- 1 | 2 | ENTRY(_start) 3 | OUTPUT_FORMAT(elf32-i386) 4 | SECTIONS 5 | { 6 | . = 128K; 7 | .text ALIGN(4K) : 8 | { 9 | code = .; 10 | *(.text.boot); 11 | *(.text); 12 | } 13 | .data ALIGN(4K) : 14 | { 15 | *(.data); 16 | *(.rodata); 17 | PROVIDE(ksymbols_start = .); 18 | *(.ksymbols); 19 | PROVIDE(ksymbols_end = .); 20 | } 21 | .bss : 22 | { 23 | bss = .; 24 | *(.bss); 25 | } 26 | end = .; 27 | 28 | /DISCARD/ : 29 | { 30 | *(.comment) 31 | *(.eh_frame) 32 | *(.note.gnu.build-id) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /arch/i386/make.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | $(outdir)/%.o: $(topdir)/%.asm 19 | $(S) mkdir -p $(dir $@) 20 | $(Q) echo " ASM "$^ 21 | $(V) nasm -f elf32 -o $@ $^ 22 | -------------------------------------------------------------------------------- /arch/i386/mboot.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | extern PACK(struct mboot_info { 7 | uint32_t flags; 8 | uint32_t mem_lower; 9 | uint32_t mem_upper; 10 | uint8_t rsvd3a; 11 | uint8_t rsvd3b; 12 | uint8_t rsvd3c; 13 | uint8_t boot_dev; 14 | char *cmdline; 15 | uint32_t mods_count; 16 | uint32_t mods_addr; 17 | uint32_t syms[4]; 18 | uint32_t mmap_length; 19 | uint32_t *mmap_addr; 20 | uint32_t drives_length; 21 | uint32_t drives_addr; 22 | uint32_t rsvd15; 23 | char *boot_loader; 24 | uint32_t apm_table; // Flags 10 25 | uint32_t vbe_control_info; 26 | uint32_t vbe_mode_info; 27 | uint16_t vbe_mode; 28 | uint16_t vbe_interface_seg; 29 | uint16_t vbe_interface_off; 30 | uint16_t vbe_interface_len; 31 | uint64_t framebuffer_addr; 32 | uint32_t framebuffer_pitch; 33 | uint32_t framebuffer_width; 34 | uint32_t framebuffer_height; 35 | uint8_t framebuffer_bpp; 36 | uint8_t framebuffer_type; 37 | }) *mboot_table; 38 | 39 | struct mboot_module { 40 | void *start; 41 | void *end; 42 | char *string; 43 | }; 44 | 45 | #define GRUB_MEM_BOUND (1 << 0) 46 | #define GRUB_BOOT_DEVICE (1 << 1) 47 | #define GRUB_CMDLINE (1 << 2) 48 | #define GRUB_MODULES (1 << 3) 49 | #define GRUB_MEMORY (1 << 6) 50 | #define GRUB_BOOT_LOADER (1 << 9) 51 | #define GRUB_VGA (1 << 11) 52 | 53 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 54 | 55 | /* Load every chunk of available memory from the multiboot table */ 56 | void mboot_memory() 57 | { 58 | uint32_t *ram = mboot_table->mmap_addr; 59 | for (; *ram == 0x14; ram += 6) { 60 | int64_t base = (int64_t)ram[1] | ((int64_t)ram[2] << 32); 61 | int64_t length = (int64_t)ram[3] | ((int64_t)ram[4] << 32); 62 | if (base < 4 * _Mib_) { // First 4 Mb are reserved for kernel code 63 | length -= 4 * _Mib_ - base; 64 | base = 4 * _Mib_; 65 | } 66 | 67 | if (length > 0 && ram[5] == 1) 68 | page_range(base, length); 69 | } 70 | } 71 | 72 | 73 | void mboot_modules() 74 | { 75 | if (mboot_table->flags & GRUB_MODULES) { 76 | struct mboot_module *mods = (struct mboot_module *)mboot_table->mods_addr; 77 | for (int i = 0; i < (int)mboot_table->mods_count; ++i) { 78 | char tmp [12]; 79 | size_t len = (size_t)(((char *)mods->end) - ((char *)mods->start)); 80 | kprintf(-1, "Module preloaded [%s] '%s'\n", sztoa(len), mods->string); 81 | inode_t *ino = tar_mount(mods->start, len, mods->string); 82 | snprintf(tmp, 12, "boot%d", i); 83 | int ret = vfs_early_mount(ino, tmp); 84 | if (ret < 0) 85 | kprintf(-1, "Error on loading module '%s'\n", mods->string); 86 | vfs_close_inode(ino); 87 | } 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /arch/i386/pic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | 22 | #define PIC1_CMD 0x20 23 | #define PIC1_DATA 0x21 24 | #define PIC2_CMD 0xA0 25 | #define PIC2_DATA 0xA1 26 | 27 | #define PIC_EOI 0x20 28 | 29 | 30 | void pic_setup() 31 | { 32 | /* PIC - ICW1 Initialization */ 33 | outb(PIC1_CMD, 0x11); 34 | outb(PIC2_CMD, 0x11); 35 | 36 | /* PIC - ICW2 Initialization */ 37 | outb(PIC1_DATA, 0x20); /* vector IRQ master */ 38 | outb(PIC2_DATA, 0x28); /* vector IRQ slave */ 39 | 40 | /* PIC - ICW3 Initialization */ 41 | outb(PIC1_DATA, 0x04); 42 | outb(PIC2_DATA, 0x02); 43 | 44 | /* PIC - ICW4 Initialization */ 45 | outb(PIC1_DATA, 0x01); 46 | outb(PIC2_DATA, 0x01); 47 | 48 | /* PIC - Set interrupts mask */ 49 | outb(PIC1_DATA, 0x0); 50 | outb(PIC2_DATA, 0x0); 51 | } 52 | 53 | 54 | void pic_mask_off() 55 | { 56 | inb(PIC1_DATA); 57 | outb(PIC1_DATA, 0xFF); 58 | inb(PIC2_DATA); 59 | outb(PIC2_DATA, 0xFF); 60 | } 61 | 62 | void pic_ack(int no) 63 | { 64 | if (no >= 8) 65 | outb(PIC2_CMD, PIC_EOI); 66 | outb(PIC1_CMD, PIC_EOI); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /arch/i386/tss.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int cpu_no(); 5 | 6 | typedef struct x86_tss x86_tss_t; 7 | struct x86_tss { 8 | uint16_t previous_task, __previous_task_unused; 9 | uint32_t esp0; 10 | uint16_t ss0, __ss0_unused; 11 | uint32_t esp1; 12 | uint16_t ss1, __ss1_unused; 13 | uint32_t esp2; 14 | uint16_t ss2, __ss2_unused; 15 | uint32_t cr3; 16 | uint32_t eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi; 17 | uint16_t es, __es_unused; 18 | uint16_t cs, __cs_unused; 19 | uint16_t ss, __ss_unused; 20 | uint16_t ds, __ds_unused; 21 | uint16_t fs, __fs_unused; 22 | uint16_t gs, __gs_unused; 23 | uint16_t ldt_selector, __ldt_sel_unused; 24 | uint16_t debug_flag, io_map; 25 | uint16_t padding[12]; 26 | }; 27 | 28 | void x86_write_gdesc(int no, uint32_t base, uint32_t limit, unsigned access, unsigned other); 29 | void x86_set_tss(int); 30 | 31 | void tss_setup(sys_info_t *sysinfo) 32 | { 33 | int no = cpu_no(); 34 | cpu_info_t *cpu = &sysinfo->cpu_table[no]; 35 | x86_tss_t *tss = (void *)0x1000; 36 | 37 | tss[no].debug_flag = 0; 38 | tss[no].io_map = 0x68; 39 | tss[no].esp0 = (size_t)cpu->stack + 0xFFC; 40 | tss[no].ss0 = 0x18; 41 | 42 | x86_write_gdesc(no + 7, (uint32_t)&tss[no], 0x68, 0x89, 4); 43 | x86_set_tss(no + 7); 44 | kprintf(-1, "CPU.%d TSS using stack %x\n", no, cpu->stack); 45 | } 46 | -------------------------------------------------------------------------------- /arch/x86_64/make.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | $(outdir)/%.o: $(topdir)/%.asm 19 | $(S) mkdir -p $(dir $@) 20 | $(Q) echo " ASM "$^ 21 | $(V) nasm -f elf64 -o $@ $^ 22 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ########################################### 4 | # Drivers 5 | # ########################################### 6 | drivers: 7 | disk: 8 | ata: y 9 | fs: 10 | isofs: y 11 | fat: y 12 | ext2: n 13 | input: 14 | ps2: y 15 | media: 16 | vga: y 17 | net: 18 | e1000: y 19 | 20 | -------------------------------------------------------------------------------- /cov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | make clean 6 | export NODEPS=y 7 | make cli-mem 8 | make cli-net 9 | make cli-snd 10 | make cli-tsk 11 | make cli-vfs 12 | 13 | cd tests 14 | ../bin/cli-mem mm_start.sh 15 | ../bin/cli-net net_ping0.sh 16 | ../bin/cli-net net_ip0.sh 17 | # ../bin/cli-net net_udp0.sh 18 | ../bin/cli-snd <(echo '# empty') 19 | ../bin/cli-tsk tsk_main.sh 20 | ../bin/cli-vfs fs_ext2.sh 21 | ../bin/cli-vfs fs_isofs.sh 22 | ../bin/cli-vfs fs_tarfs.sh 23 | ../bin/cli-vfs fs_main.sh 24 | 25 | cd ../ 26 | make do_coverage 27 | -------------------------------------------------------------------------------- /doc/Home.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/doc/Home.md -------------------------------------------------------------------------------- /drivers/fs/README.md: -------------------------------------------------------------------------------- 1 | # Kora file systems drivers 2 | 3 | This repository purpose is to regroup basic file systems drivers for KoraOs. 4 | 5 | - vfat 6 | - ext2 7 | - isofs (read-only) 8 | 9 | -------------------------------------------------------------------------------- /drivers/fs/ext2/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | ext2_LFLAGS += $(LFLAGS) 19 | ext2_SRCS := $(wildcard $(topdir)/drivers/fs/ext2/*.c) 20 | $(eval $(call link_driver,ext2)) 21 | 22 | SRCS_dr += $(ext2_SRCS) 23 | -------------------------------------------------------------------------------- /drivers/fs/ext2/inodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "ext2.h" 21 | 22 | int ext2_chmod(inode_t *ino, int mode) 23 | { 24 | struct bkmap bk_new; 25 | ext2_volume_t *vol = (ext2_volume_t *)ino->drv_data; 26 | ext2_ino_t *ino_new = ext2_entry(&bk_new, vol, ino->no, VM_WR); 27 | 28 | ino_new->mode = (ino_new->mode & EXT2_S_IFMT) | (mode & 0x1FF); // TODO -- extra mode bits 29 | ino->mode = mode & 0x1FF; 30 | 31 | bkunmap(&bk_new); 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /drivers/fs/ext2/super.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "ext2.h" 21 | 22 | -------------------------------------------------------------------------------- /drivers/fs/isofs/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | isofs_LFLAGS += $(LFLAGS) 19 | isofs_SRCS := $(wildcard $(topdir)/drivers/fs/isofs/*.c) 20 | $(eval $(call link_driver,isofs)) 21 | 22 | SRCS_dr += $(isofs_SRCS) 23 | -------------------------------------------------------------------------------- /drivers/fs/vfat/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | vfat_LFLAGS += $(LFLAGS) 19 | vfat_SRCS := $(wildcard $(topdir)/drivers/fs/vfat/*.c) 20 | $(eval $(call link_driver,vfat)) 21 | 22 | mkvfat_SRCS := $(topdir)/drivers/fs/vfat/utils/format.c 23 | $(eval $(call link_sbin,mkvfat)) 24 | 25 | SRCS_dr += $(vfat_SRCS) $(mkvfat_SRCS) 26 | -------------------------------------------------------------------------------- /drivers/fs/vfat/data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "vfat.h" 21 | #include 22 | 23 | int fat_read(inode_t *ino, void *buffer, size_t length, xoff_t offset, int flags) 24 | { 25 | FAT_volume_t *volume = ino->drv_data; 26 | size_t clusterSize = volume->SecPerClus * volume->BytsPerSec; 27 | assert(POW2(clusterSize) && (offset & (clusterSize - 1)) == 0); 28 | 29 | unsigned clustNo = ino->lba; 30 | xoff_t foff = 0; 31 | 32 | while (length > 0) { 33 | while (clustNo != 0 && offset - foff >= (xoff_t)clusterSize) { 34 | clustNo = fat_cluster_next_16(ino->dev->underlying, volume, clustNo); 35 | foff += clusterSize; 36 | } 37 | 38 | size_t cap = clusterSize; 39 | if (clustNo) { 40 | int lba = FAT_CLUSTER_TO_LBA(volume, clustNo); 41 | struct bkmap bm; 42 | char *data = bkmap(&bm, lba, 512, clusterSize, ino->dev->underlying, VM_RD); 43 | cap = MIN(cap, length); 44 | memcpy(buffer, data, cap); 45 | bkunmap(&bm); 46 | } else { 47 | cap = MIN(cap, length); 48 | memset(buffer, 0, cap); 49 | } 50 | 51 | length -= cap; 52 | offset += cap; 53 | buffer = ((char *)buffer) + cap; 54 | } 55 | return 0; 56 | } 57 | 58 | int fat_write(inode_t *ino, const void *buffer, size_t length, xoff_t offset, int flags) 59 | { 60 | assert(false); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /drivers/fs/vfat/module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "vfat.h" 21 | 22 | ino_ops_t fatfs_reg_ops = { 23 | // .close = fatfs_close, 24 | .read = (void *)fat_read, 25 | .write = (void *)fat_write, 26 | .truncate = fatfs_truncate, 27 | }; 28 | 29 | ino_ops_t fatfs_dir_ops = { 30 | // .open = fat_open, 31 | .lookup = fat_lookup, 32 | // .close = fatfs_close, 33 | .unlink = fat_unlink, 34 | .opendir = fat_opendir, 35 | .readdir = fat_readdir, 36 | .closedir = (void *)fat_closedir, 37 | }; 38 | 39 | inode_t *fat_mount(inode_t *dev, const char *options) 40 | { 41 | if (dev == NULL) { 42 | errno = ENODEV; 43 | return NULL; 44 | } 45 | 46 | uint8_t *ptr = (uint8_t *)kmap(PAGE_SIZE, dev, 0, VM_RD); 47 | FAT_volume_t *info = fatfs_init(ptr); 48 | kunmap(ptr, PAGE_SIZE); 49 | if (info == NULL) { 50 | errno = EBADF; 51 | return NULL; 52 | } 53 | 54 | const char *fsName = info->FATType == FAT32 ? "fat32" : (info->FATType == FAT16 ? "fat16" : "fat12"); 55 | inode_t *ino = vfs_inode(1, FL_DIR, NULL, &fatfs_dir_ops); 56 | ino->length = 0; 57 | ino->lba = info->RootEntry; 58 | ino->drv_data = info; 59 | ino->dev->devclass = strdup(fsName); 60 | ino->dev->devname = strdup(info->name); 61 | ino->dev->underlying = vfs_open_inode(dev); 62 | 63 | // int origin_sector = info->FirstDataSector - 2 * info->SecPerClus; 64 | // info->io_data_rw = bio_create(dev, VMA_FILE_RW, info->BytsPerSec * info->SecPerClus, origin_sector * info->BytsPerSec); 65 | // info->io_data_ro = bio_create(dev, VMA_FILE_RO, info->BytsPerSec * info->SecPerClus, origin_sector * info->BytsPerSec); 66 | errno = 0; 67 | return ino; 68 | } 69 | 70 | // int fatfs_umount(inode_t *ino) 71 | // { 72 | // FAT_volume_t *info = (FAT_volume_t *)ino->info; 73 | // kfree(info); 74 | // return 0; 75 | // } 76 | 77 | int fatfs_format(inode_t *dev, const char *options); 78 | 79 | void fat_setup() 80 | { 81 | vfs_addfs("fat", fat_mount, fatfs_format); 82 | vfs_addfs("vfat", fat_mount, fatfs_format); 83 | vfs_addfs("fat12", fat_mount, fatfs_format); 84 | vfs_addfs("fat16", fat_mount, fatfs_format); 85 | vfs_addfs("fat32", fat_mount, fatfs_format); 86 | } 87 | 88 | void fat_teardown() 89 | { 90 | vfs_rmfs("fat"); 91 | vfs_rmfs("vfat"); 92 | vfs_rmfs("fat12"); 93 | vfs_rmfs("fat16"); 94 | vfs_rmfs("fat32"); 95 | } 96 | 97 | EXPORT_MODULE(vfat, fat_setup, fat_teardown); 98 | -------------------------------------------------------------------------------- /drivers/fs/vfat/table.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/drivers/fs/vfat/table.c -------------------------------------------------------------------------------- /drivers/fs/vfat/utils/format.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | 21 | int main(int argc, char const *argv[]) 22 | { 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /drivers/fs/vfat/vfat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "vfat.h" 21 | #include 22 | 23 | int fatfs_truncate(inode_t *ino, xoff_t length) 24 | { 25 | FAT_volume_t *info = (FAT_volume_t *)ino->drv_data; 26 | const int entry_per_cluster = info->BytsPerSec / sizeof(struct FAT_ShortEntry); 27 | // int lba = ino->no / entry_per_cluster; 28 | struct FAT_ShortEntry *entry = NULL; // bio_access(info->io_data_rw, lba); 29 | entry += ino->no % entry_per_cluster; 30 | assert((entry->DIR_Attr & ATTR_ARCHIVE) != 0); 31 | 32 | unsigned cluster_sz = info->SecPerClus * 512; 33 | unsigned n, i = 0; 34 | unsigned lg = ALIGN_UP(entry->DIR_FileSize, cluster_sz) / cluster_sz; 35 | unsigned mx = ALIGN_UP(length, cluster_sz) / cluster_sz; 36 | 37 | if (mx > info->CountofClusters) { 38 | // TODO - Count used space 39 | // bio_clean(info->io_data_rw, lba); 40 | errno = ENOSPC; 41 | return -1; 42 | } else if (lg == mx) { 43 | entry->DIR_FileSize = length; 44 | fatfs_settime(&entry->DIR_WrtDate, &entry->DIR_WrtTime, xtime_read(XTIME_CLOCK)); 45 | // fatfs_settime(&entry->DIR_CrtDate, &entry->DIR_CrtTime, kclock()); -- on unix but not windows 46 | // bio_clean(info->io_data_rw, lba); 47 | return 0; 48 | } 49 | 50 | int cluster = entry->DIR_FstClusLo; 51 | if (cluster == 0) { 52 | assert(lg == 0); 53 | cluster = fatfs_alloc_cluster_16(ino->dev->underlying, info, -1); 54 | entry->DIR_FstClusLo = cluster; 55 | i = 1; 56 | } 57 | 58 | // int prev = -1; 59 | for (n = MIN(lg, mx); i < n; ++i) { 60 | // prev = cluster; 61 | // cluster = fatfs_next_cluster_16(info, cluster); 62 | } 63 | for (; i < mx; ++i) 64 | cluster = fatfs_alloc_cluster_16(ino->dev->underlying, info, cluster); 65 | for (; i < lg; ++i) { 66 | // cluster = fatfs_release_cluster_16(info, cluster); 67 | } 68 | 69 | entry->DIR_FileSize = length; 70 | fatfs_settime(&entry->DIR_WrtDate, &entry->DIR_WrtTime, xtime_read(XTIME_CLOCK)); 71 | // fatfs_settime(&entry->DIR_CrtDate, &entry->DIR_CrtTime, kclock()); -- on unix but not windows 72 | // bio_clean(info->io_data_rw, lba); 73 | // bio_sync(info->io_data_rw); 74 | ino->length = length; 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /drivers/fs/vfat/vfat.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/drivers/fs/vfat/vfat.h -------------------------------------------------------------------------------- /drivers/misc/vbox/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | vbox_SRCS := $(wildcard $(topdir)/drivers/misc/vbox/*.c) 19 | $(eval $(call link_driver,vbox)) 20 | 21 | SRCS_dr += $(vbox_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/net/ip4/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | ip4_SRCS := $(wildcard $(topdir)/drivers/net/ip4/*.c) 19 | $(eval $(call link_driver,ip4)) 20 | 21 | SRCS_dr += $(ip4_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/net/ip4/dns.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "ip4.h" 21 | 22 | #define IP4_PORT_DNS_SRV 53 23 | 24 | typedef struct dns_header dns_header_t; 25 | struct dns_header { 26 | uint16_t transaction; 27 | uint16_t flags; 28 | uint16_t qdcount; 29 | uint16_t ancount; 30 | uint16_t nscount; 31 | uint16_t arcount; 32 | }; 33 | 34 | #define DNS_OPT_STANDARD_QRY 0x0100 35 | 36 | #define DNS_TYPE_A 0x0001 // Host address IPv4 37 | #define DNS_TYPE_NS 0x0002 // Server name 38 | #define DNS_TYPE_MD 0x0003 // (Deprecated MX) 39 | #define DNS_TYPE_MF 0x0004 // (Deprecated MX) 40 | #define DNS_TYPE_CNAME 0x0005 // Canonical name 41 | #define DNS_TYPE_SOA 0x0006 // Autority zone 42 | #define DNS_TYPE_WKS 0x000B // Internet service 43 | #define DNS_TYPE_HINFO 0x000D // Machine information 44 | #define DNS_TYPE_MX 0x000F // Mail exchange 45 | #define DNS_TYPE_TXT 0x0010 // Text 46 | 47 | #define DNS_CLASS_IN 0x0001 // Internet 48 | 49 | /* Prepare a DNS packet */ 50 | static skb_t *dns_packet(ifnet_t* net, ip4_route_t* route, int length, uint16_t lport, dns_header_t** phead) 51 | { 52 | length += sizeof(dns_header_t); 53 | skb_t* skb = net_packet(net); 54 | if (udp_header(skb, route, length, IP4_PORT_DNS_SRV, lport, 0, 0) != 0) { 55 | net_skb_trash(skb); 56 | return NULL; 57 | } 58 | 59 | net_log(skb, ",dns"); 60 | dns_header_t *head = net_skb_reserve(skb, sizeof(dns_header_t)); 61 | memset(head, 0, sizeof(dns_header_t)); 62 | *phead = head; 63 | return skb; 64 | } 65 | 66 | /* Send a basic DNS request */ 67 | int dns_query_ip4(ifnet_t *net, const char *domain, uint16_t lport, uint16_t transac) 68 | { 69 | int len = strlen(domain); 70 | len += 2; // Count of '.' + 1 71 | int length = len + 4; 72 | dns_header_t* head; 73 | skb_t* skb = dns_packet(net, NULL, length, lport, &head); 74 | if (skb == NULL) 75 | return -1; 76 | 77 | head->transaction = transac; 78 | head->flags = DNS_OPT_STANDARD_QRY; 79 | head->qdcount = 1; 80 | 81 | uint8_t l; 82 | l = (uint8_t)strlen(domain); 83 | net_skb_write(skb, &l, 1); 84 | net_skb_write(skb, domain, l); 85 | 86 | l = (uint8_t)strlen(domain); 87 | net_skb_write(skb, &l, 1); 88 | net_skb_write(skb, domain, l); 89 | 90 | uint16_t tmp; 91 | tmp = htons(DNS_TYPE_A); 92 | net_skb_write(skb, &tmp, 2); 93 | tmp = htons(DNS_CLASS_IN); 94 | net_skb_write(skb, &tmp, 2); 95 | return net_skb_send(skb); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /drivers/pc/README.md: -------------------------------------------------------------------------------- 1 | # Kora drivers for PC platforms 2 | 3 | -------------------------------------------------------------------------------- /drivers/pc/ac97/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | ac97_SRCS := $(wildcard $(topdir)/drivers/pc/ac97/*.c) 19 | $(eval $(call link_driver,ac97)) 20 | 21 | SRCS_dr += $(ac97_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/ac97/ac97.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | 24 | #define AC97_VENDOR_ID 0x8086 25 | #define AC97_DEVICE_ID 0x2415 26 | #define AC97_NAME "ICH AC97" 27 | 28 | 29 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 30 | 31 | 32 | void ac97_startup(struct PCI_device *pci) 33 | { 34 | // IO region #0: d100..d200 35 | // IO region #1: d200..d240 36 | 37 | } 38 | 39 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 40 | 41 | int ac97_match_pci_device(uint16_t vendor, uint32_t class, uint16_t device) 42 | { 43 | if (vendor != AC97_VENDOR_ID || device != AC97_DEVICE_ID) 44 | return -1; 45 | return 0; 46 | } 47 | 48 | 49 | void ac97_setup() 50 | { 51 | struct PCI_device *pci = NULL; 52 | 53 | for (;;) { 54 | pci = pci_search(ac97_match_pci_device, NULL); 55 | if (pci == NULL) 56 | break; 57 | // kprintf(0, "Found %s (PCI.%02d.%02d)\n", AC97_NAME, pci->bus, pci->slot); 58 | ac97_startup(pci); 59 | } 60 | } 61 | 62 | void ac97_teardown() 63 | { 64 | } 65 | 66 | 67 | EXPORT_MODULE(ac97, ac97_setup, ac97_teardown); 68 | -------------------------------------------------------------------------------- /drivers/pc/ata/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | ata_SRCS := $(wildcard $(topdir)/drivers/pc/ata/*.c) 19 | $(eval $(call link_driver,ata)) 20 | 21 | SRCS_dr += $(ata_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/e1000/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | e1000_SRCS := $(wildcard $(topdir)/drivers/pc/e1000/*.c) 19 | $(eval $(call link_driver,e1000)) 20 | 21 | SRCS_dr += $(e1000_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/ps2/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | ps2_SRCS := $(wildcard $(topdir)/drivers/pc/ps2/*.c) 19 | $(eval $(call link_driver,ps2)) 20 | 21 | SRCS_dr += $(ps2_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/ps2/ps2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "ps2.h" 21 | #include 22 | #include 23 | #include 24 | 25 | inode_t *mouse_ino; 26 | inode_t *kdb_ino; 27 | 28 | 29 | // PS/2 Reset 30 | void PS2_reset() 31 | { 32 | uint8_t tmp = inb(0x61); 33 | outb(0x61, tmp | 0x80); 34 | outb(0x61, tmp & 0x7F); 35 | inb(0x60); 36 | } 37 | 38 | 39 | // int ps2_read(inode_t *ino, char *buf, size_t len, int flags) 40 | // { 41 | // return pipe_read((pipe_t *)ino->info, buf, len, flags); 42 | // } 43 | 44 | ino_ops_t ps2_ino_ops = { 45 | .read = NULL, 46 | // .read = ps2_read, 47 | }; 48 | 49 | void PS2_setup() 50 | { 51 | PS2_mouse_setup(); 52 | PS2_kbd_setup(); 53 | 54 | kdb_ino = vfs_inode(1, FL_CHR, NULL, &ps2_ino_ops); 55 | kdb_ino->dev->block = sizeof(evmsg_t); 56 | kdb_ino->dev->flags = FD_RDONLY; 57 | kdb_ino->dev->devclass = strdup("PS/2 Keyboard"); 58 | vfs_mkdev(kdb_ino, "kbd"); 59 | vfs_close_inode(kdb_ino); 60 | 61 | // TODO - Remove this hack! 62 | itimer_create(kdb_ino, MSEC_TO_USEC(100), MSEC_TO_USEC(40)); 63 | 64 | mouse_ino = vfs_inode(2, FL_CHR, NULL, &ps2_ino_ops); 65 | mouse_ino->dev->block = sizeof(evmsg_t); 66 | mouse_ino->dev->flags = FD_RDONLY; 67 | mouse_ino->dev->devclass = strdup("PS/2 Mouse"); 68 | vfs_mkdev(mouse_ino, "mouse"); 69 | vfs_close_inode(mouse_ino); 70 | 71 | irq_register(1, (irq_handler_t)PS2_kbd_handler, NULL); 72 | irq_register(12, (irq_handler_t)PS2_mouse_handler, NULL); 73 | } 74 | 75 | void PS2_teardown() 76 | { 77 | /* 78 | vfs_rmdev("kbd"); 79 | vfs_rmdev("mouse"); 80 | */ 81 | } 82 | 83 | 84 | EXPORT_MODULE(ps2, PS2_setup, PS2_teardown); 85 | -------------------------------------------------------------------------------- /drivers/pc/ps2/ps2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _SRC_DRV_PS2_H 21 | #define _SRC_DRV_PS2_H 1 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | extern inode_t *mouse_ino; 30 | extern inode_t *kdb_ino; 31 | 32 | void PS2_event(inode_t *ino, uint8_t type, int32_t param1, int32_t param2); 33 | 34 | void PS2_kbd_handler(); 35 | void PS2_kbd_setup(); 36 | 37 | void PS2_mouse_handler(); 38 | void PS2_mouse_setup(); 39 | 40 | 41 | 42 | #endif /* _SRC_DRV_PS2_H */ 43 | -------------------------------------------------------------------------------- /drivers/pc/sb16/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | sb16_SRCS := $(wildcard $(topdir)/drivers/pc/sb16/*.c) 19 | $(eval $(call link_driver,sb16)) 20 | 21 | SRCS_dr += $(sb16_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/vga/Makefile: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | vga_SRCS := $(wildcard $(topdir)/drivers/pc/vga/*.c) 19 | $(eval $(call link_driver,vga)) 20 | 21 | SRCS_dr += $(vga_SRCS) 22 | -------------------------------------------------------------------------------- /drivers/pc/vga/vga.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | struct device_id { 26 | uint16_t vendor; 27 | uint16_t id; 28 | const char *name; 29 | void (*start)(struct PCI_device *pci, struct device_id *info); 30 | }; 31 | 32 | void vga_start_qemu(struct PCI_device *pci, struct device_id *info); 33 | 34 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 35 | 36 | 37 | struct device_id __vga_ids[] = { 38 | { .vendor = 0x1234, .id = 0x1111, .name = "QEMU VGA", .start = vga_start_qemu }, 39 | { .vendor = 0x80EE, .id = 0xBEEF, .name = "VirtualBox VGA", .start = vga_start_qemu }, 40 | // { .vendor = 0x15ad, .id = 0x0405, .name = "VMWare VGA", .start = NULL }, 41 | }; 42 | 43 | 44 | // struct device_id *vga_pci_info(struct PCI_device *pci) 45 | // { 46 | // unsigned i; 47 | // for (i = 0; i < sizeof(__vga_ids) / sizeof(struct device_id); ++i) { 48 | // if (__vga_ids[i].id == pci->device_id && __vga_ids[i].vendor == pci->vendor_id) 49 | // return &__vga_ids[i]; 50 | // } 51 | 52 | // return NULL; 53 | // } 54 | 55 | int vga_match_pci_device(uint16_t vendor, uint32_t class, uint16_t device) 56 | { 57 | unsigned i; 58 | // if (class != 0x030000) // VGA_DEVICE 59 | // return -1; 60 | for (i = 0; i < sizeof(__vga_ids) / sizeof(struct device_id); ++i) { 61 | if (__vga_ids[i].id == device && __vga_ids[i].vendor == vendor) 62 | return i; 63 | } 64 | 65 | return -1; 66 | } 67 | 68 | void vga_setup() 69 | { 70 | struct PCI_device *pci = NULL; 71 | char name[48]; 72 | 73 | int i; 74 | for (;;) { 75 | pci = pci_search(vga_match_pci_device, &i); 76 | if (pci == NULL) 77 | break; 78 | 79 | struct device_id *info = &__vga_ids[i]; 80 | strcpy(name, info->name); 81 | info->start(pci, info); 82 | 83 | } 84 | } 85 | 86 | void vga_teardown() 87 | { 88 | 89 | } 90 | 91 | 92 | EXPORT_MODULE(vga, vga_setup, vga_teardown); 93 | -------------------------------------------------------------------------------- /include/_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _ASSERT_H 21 | #define _ASSERT_H 1 22 | 23 | #include 24 | 25 | #if 0 26 | #define assert(n) ((void)(n)) 27 | #else 28 | _Noreturn void __assert_fail(const char *expr, const char *file, int line); 29 | #define assert(n) do { if (!(n)) __assert_fail(#n,__FILE__,__LINE__); } while(0) 30 | #endif 31 | 32 | #endif /* _ASSERT_H */ 33 | -------------------------------------------------------------------------------- /include/_errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _ERRNO_H 21 | #define _ERRNO_H 1 22 | 23 | #include 24 | 25 | int *__errno_location(); 26 | #undef errno 27 | #define errno (*__errno_location()) 28 | 29 | #endif /* _ERRNO_H */ 30 | -------------------------------------------------------------------------------- /include/bits/cdefs/aarch64-gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | 21 | #define _Noreturn __attribute__((noreturn)) 22 | #define PACK(decl) decl __attribute__((packed)) 23 | #define unlikely(c) c 24 | #define likely(c) c 25 | 26 | #define PAGE_SIZE 4096 27 | #define WORDSIZE 64 28 | #define __ARCH "aarch64" 29 | #define __LP64 30 | #define __LPx 31 | -------------------------------------------------------------------------------- /include/bits/cdefs/arm-gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | 21 | #define _Noreturn __attribute__((noreturn)) 22 | #define PACK(decl) decl __attribute__((packed)) 23 | #define unlikely(c) c 24 | #define likely(c) c 25 | 26 | #define PAGE_SIZE 4096 27 | #define WORDSIZE 32 28 | #define __ARCH "arm" 29 | #define __ILP32 30 | #define __ILPx 31 | -------------------------------------------------------------------------------- /include/bits/cdefs/gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #define _Noreturn __attribute__((noreturn)) 21 | #define PACK(decl) decl __attribute__((packed)) 22 | #ifndef thread_local 23 | # define thread_local __thread 24 | #endif 25 | #define unlikely(c) c 26 | #define likely(c) c 27 | 28 | #if WORDSIZE == 32 29 | # define __ILP32 30 | # define __ILPx 31 | #else 32 | # define __LP64 33 | # define __LPx 34 | #endif 35 | 36 | #define __asm_irq_on_ asm("sti") 37 | #define __asm_irq_off_ asm("cli") 38 | #define __asm_pause_ asm("pause") 39 | 40 | // Memory barriers 41 | #define __asm_rmb asm("") 42 | #define __asm_wmb asm("") 43 | #define __asm_mb asm("") 44 | -------------------------------------------------------------------------------- /include/bits/cdefs/i386-gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __BITS_CDEFS_H 21 | #define __BITS_CDEFS_H 1 22 | 23 | #define _Noreturn __attribute__((noreturn)) 24 | #define PACK(decl) decl __attribute__((__packed__)) 25 | #define thread_local __thread 26 | #define unlikely(c) c 27 | #define likely(c) c 28 | 29 | #define PAGE_SIZE 4096 30 | #define WORDSIZE 32 31 | #define __ARCH "i386" 32 | #define __ILP32 33 | #define __ILPx 34 | 35 | #define RELAX asm volatile("pause") 36 | #define BARRIER asm volatile("") 37 | #if defined KORA_KRN 38 | # define THROW_ON irq_enable() 39 | # define THROW_OFF irq_disable() 40 | #else 41 | # define THROW_ON ((void)0) 42 | # define THROW_OFF ((void)0) 43 | #endif 44 | 45 | 46 | #endif /* __BITS_CDEFS_H */ 47 | -------------------------------------------------------------------------------- /include/bits/cdefs/i386-mcvs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __BITS_CDEFS_H 21 | #define __BITS_CDEFS_H 1 22 | 23 | #define _Noreturn __declspec(noreturn) 24 | #define PACK(decl) __pragma(pack(push,1)) decl __pragma(pack(pop)) 25 | #define thread_local __declspec(thread) 26 | #define unlikely(c) c 27 | #define likely(c) c 28 | 29 | #define PAGE_SIZE 4096 30 | #define WORDSIZE 32 31 | #define __ARCH "i386" 32 | #define __ILP32 33 | #define __ILPx 34 | 35 | #define RELAX asm volatile("pause") 36 | #define BARRIER asm volatile("") 37 | #if defined KORA_KRN 38 | # define THROW_ON irq_enable() 39 | # define THROW_OFF irq_disable() 40 | #else 41 | # define THROW_ON ((void)0) 42 | # define THROW_OFF ((void)0) 43 | #endif 44 | 45 | 46 | #endif /* __BITS_CDEFS_H */ 47 | -------------------------------------------------------------------------------- /include/bits/cdefs/mcvs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #define _Noreturn __declspec(noreturn) 21 | #define PACK(decl) __pragma(pack(push,1)) decl __pragma(pack(pop)) 22 | #define thread_local __declspec(thread) 23 | #define unlikely(c) c 24 | #define likely(c) c 25 | 26 | #if WORDSIZE == 32 27 | # define __ILP32 28 | # define __ILPx 29 | #else 30 | # define __LLP64 31 | # define __LLPx 32 | #endif 33 | 34 | #define __asm_mb 35 | -------------------------------------------------------------------------------- /include/bits/cdefs/x86_64-gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __BITS_CDEFS_H 21 | #define __BITS_CDEFS_H 1 22 | 23 | #define _Noreturn __attribute__((noreturn)) 24 | #define PACK(decl) decl __attribute__((__packed__)) 25 | #define thread_local __thread 26 | #define unlikely(c) c 27 | #define likely(c) c 28 | 29 | #define PAGE_SIZE 4096 30 | #define WORDSIZE 64 31 | #define __ARCH "x86_64" 32 | #define __LP64 33 | #define __LPx 34 | 35 | #define RELAX asm volatile("pause") 36 | #define BARRIER asm volatile("") 37 | #if defined KORA_KRN 38 | # define THROW_ON irq_enable() 39 | # define THROW_OFF irq_disable() 40 | #else 41 | # define THROW_ON ((void)0) 42 | # define THROW_OFF ((void)0) 43 | #endif 44 | 45 | 46 | #endif /* __BITS_CDEFS_H */ 47 | -------------------------------------------------------------------------------- /include/bits/cdefs/x86_64-mcvs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __BITS_CDEFS_H 21 | #define __BITS_CDEFS_H 1 22 | 23 | #define _Noreturn __declspec(noreturn) 24 | #define PACK(decl) __pragma(pack(push,1)) decl __pragma(pack(pop)) 25 | #define thread_local __declspec(thread) 26 | #define unlikely(c) c 27 | #define likely(c) c 28 | 29 | #define PAGE_SIZE 4096 30 | #define WORDSIZE 64 31 | #define __ARCH "x86_64" 32 | #define __LLP64 33 | #define __LPx 34 | 35 | #define RELAX asm volatile("pause") 36 | #define BARRIER asm volatile("") 37 | #if defined KORA_KRN 38 | # define THROW_ON irq_enable() 39 | # define THROW_OFF irq_disable() 40 | #else 41 | # define THROW_ON ((void)0) 42 | # define THROW_OFF ((void)0) 43 | #endif 44 | 45 | 46 | #endif /* __BITS_CDEFS_H */ 47 | -------------------------------------------------------------------------------- /include/bits/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __BITS_IO_H 21 | #define __BITS_IO_H 1 22 | 23 | 24 | #define O_SEARCH O_PATH 25 | #define O_EXEC O_PATH 26 | #define O_TTY_INIT 0 27 | 28 | #define O_ACCMODE (03|O_SEARCH) 29 | #define O_RDONLY 00 30 | #define O_WRONLY 01 31 | #define O_RDWR 02 32 | 33 | #define O_CREAT 0100 34 | #define O_EXCL 0200 35 | #define O_NOCTTY 0400 36 | #define O_TRUNC 01000 37 | #define O_APPEND 02000 38 | #define O_NONBLOCK 04000 39 | #define O_DSYNC 010000 40 | #define O_SYNC 04010000 41 | #define O_RSYNC 04010000 42 | #define O_DIRECTORY 0200000 43 | #define O_NOFOLLOW 0400000 44 | #define O_CLOEXEC 02000000 45 | 46 | #define O_ASYNC 020000 47 | #define O_DIRECT 040000 48 | #define O_LARGEFILE 0 49 | #define O_NOATIME 01000000 50 | #define O_PATH 010000000 51 | #define O_TMPFILE 020200000 52 | #define O_NDELAY O_NONBLOCK 53 | 54 | 55 | #define SEEK_SET 0 56 | #define SEEK_CUR 1 57 | #define SEEK_END 2 58 | 59 | #endif /* __BITS_IO_H */ 60 | -------------------------------------------------------------------------------- /include/c_header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | 19 | TOPDIR=`pwd` 20 | 21 | function header { 22 | 23 | DEF=`echo "${1^^}" | sed -e 's%/%_%g' -e 's%\.%_%g'` 24 | 25 | cat > "${TOPDIR}/${1}" << EOF 26 | #ifndef __$DEF 27 | #define __$DEF 1 28 | 29 | #include 30 | 31 | 32 | #endif /* __$DEF */ 33 | EOF 34 | 35 | } 36 | 37 | 38 | while [[ $# > 0 ]]; do 39 | header "${1}" 40 | shift 41 | done 42 | -------------------------------------------------------------------------------- /include/cbuild/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _CTYPE_NO_CMB 21 | _CTYPE(alnum) 22 | #endif 23 | _CTYPE(alpha) 24 | _CTYPE(cntrl) 25 | _CTYPE(digit) 26 | _CTYPE(graph) 27 | _CTYPE(lower) 28 | _CTYPE(print) 29 | _CTYPE(punct) 30 | _CTYPE(space) 31 | _CTYPE(upper) 32 | _CTYPE(xdigit) 33 | -------------------------------------------------------------------------------- /include/cbuild/iostm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _XIO 21 | # define _XIOs(n) n 22 | # define _XIOi(s,p) s ## p 23 | #else 24 | # define _XIOs(n) n ## _XIO 25 | # define _XIOi(s,p) s ## _XIO p 26 | #endif 27 | 28 | /* Write formated string on standard output */ 29 | int _XIOs(printf)(const _XCHAR *format, ...); 30 | /* Write formated string on an opened file */ 31 | int _XIOi(f, printf)(FILE *fp, const _XCHAR *format, ...); 32 | /* Write formated string from a string */ 33 | int _XIOi(s, printf)(_XCHAR *str, const _XCHAR *format, ...); 34 | /* Write formated string on standard output */ 35 | int _XIOi(v, printf)(const _XCHAR *format, va_list ap); 36 | /* Write formated string on an opened file */ 37 | int _XIOi(vf, printf)(FILE *fp, const _XCHAR *str, va_list ap); 38 | /* Write formated string from a string */ 39 | int _XIOi(vs, printf)(_XCHAR *str, const _XCHAR *format, va_list ap); 40 | 41 | 42 | /* Read and parse standard input */ 43 | int _XIOs(scanf)(const _XCHAR *format, ...); 44 | /* Read and parse an open file */ 45 | int _XIOi(f, scanf)(FILE *f, const _XCHAR *format, ...); 46 | /* Read and parse a string */ 47 | int _XIOi(s, scanf)(const _XCHAR *str, const _XCHAR *format, ...); 48 | 49 | 50 | /* Read a character from STREAM. */ 51 | int _XIOi(get, c)(FILE *stream); 52 | /* Read a character from STREAM. */ 53 | int _XIOi(fget, c)(FILE *stream); 54 | /* Get a newline-terminated string of finite length from STREAM. */ 55 | _XCHAR *_XIOi(fget, s)(_XCHAR *s, int n, FILE *stream); 56 | /* Write a character to STREAM. */ 57 | int _XIOi(put, c)(int c, FILE *stream); 58 | /* Write a character to STREAM. */ 59 | int _XIOi(fput, c)(int c, FILE *stream); 60 | /* Write a string to STREAM. */ 61 | int _XIOi(fput, s)(const _XCHAR *s, FILE *stream); 62 | 63 | 64 | /* Read a character from stdin. */ 65 | int _XIOi(get, char)(void); 66 | /* Write a character to stdout. */ 67 | int _XIOi(put, char)(int c); 68 | /* Push a character back onto the input buffer of STREAM. */ 69 | int _XIOi(unget, c)(int c, FILE *stream); 70 | -------------------------------------------------------------------------------- /include/cc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __STDARG_H 21 | #define __STDARG_H 1 22 | 23 | 24 | #if 0 25 | 26 | typedef __builtin_va_list va_list; 27 | 28 | # define va_start(v,l) __builtin_va_start(v,l) 29 | # define va_end(v) __builtin_va_end(v) 30 | # define va_arg(v,l) __builtin_va_arg(v,l) 31 | # define va_copy(d,s) __builtin_va_copy(d,s) 32 | 33 | #else 34 | 35 | typedef char *va_list; 36 | 37 | # define va_start(v,l) (v = (((char*)&(l)) + sizeof(l))) 38 | # define va_end(v) ((void)v) 39 | # define va_arg(v,l) (*((l*)((v += sizeof(l)) - sizeof(l)))) 40 | # define va_copy(d,s) (d = (s)) 41 | 42 | #endif 43 | 44 | #endif /* __STDARG_H */ 45 | -------------------------------------------------------------------------------- /include/cc/stdbool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _STDBOOL_H 21 | #define _STDBOOL_H 22 | 23 | #ifndef __cplusplus 24 | 25 | #define bool _Bool 26 | #define true 1 27 | #define false 0 28 | 29 | #else /* __cplusplus */ 30 | 31 | /* Supporting _Bool in C++ is a GCC extension. */ 32 | #define _Bool bool 33 | 34 | #if __cplusplus < 201103L 35 | /* Defining these macros in C++98 is a GCC extension. */ 36 | #define bool bool 37 | #define false false 38 | #define true true 39 | #endif 40 | 41 | #endif /* __cplusplus */ 42 | 43 | /* Signal that all the definitions are present. */ 44 | #define __bool_true_false_are_defined 1 45 | 46 | #endif /* _STDBOOL_H */ 47 | -------------------------------------------------------------------------------- /include/cc/stddef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __STDDEF_H 21 | #define __STDDEF_H 1 22 | 23 | 24 | #ifndef __PTRDIFF_TYPE__ 25 | #define __PTRDIFF_TYPE__ long 26 | #endif 27 | #define _PTRDIFF_T 28 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 29 | 30 | #ifndef __SIZE_TYPE__ 31 | #define __SIZE_TYPE__ unsigned long 32 | #endif 33 | #define _SIZE_T 34 | typedef __SIZE_TYPE__ size_t; 35 | 36 | #ifndef __WCHAR_TYPE__ 37 | #define __WCHAR_TYPE__ int 38 | #endif 39 | #define _WCHAR_T 40 | typedef __WCHAR_TYPE__ wchar_t; 41 | 42 | 43 | #undef NULL 44 | #ifndef __cplusplus 45 | #define NULL ((void *)0) 46 | #else 47 | #define NULL 0 48 | typedef decltype(nullptr) nullptr_t; 49 | #endif 50 | 51 | #if 0 52 | #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 53 | #else 54 | #define offsetof(TYPE, MEMBER) ((int)(&((TYPE*)0)->MEMBER)) 55 | #endif 56 | 57 | #endif /* __STDDEF_H */ 58 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _CTYPE_H 21 | #define _CTYPE_H 1 22 | 23 | 24 | static inline int isalpha(int a) 25 | { 26 | return (((unsigned)a | 32) - 'a') < 26; 27 | } 28 | 29 | static inline int isdigit(int a) 30 | { 31 | return ((unsigned)a - '0') < 10; 32 | } 33 | 34 | static inline int islower(int a) 35 | { 36 | return ((unsigned)a - 'a') < 26; 37 | } 38 | 39 | static inline int isupper(int a) 40 | { 41 | return ((unsigned)a - 'A') < 26; 42 | } 43 | 44 | static inline int isprint(int a) 45 | { 46 | return ((unsigned)a - 0x20) < 0x5f; 47 | } 48 | 49 | static inline int isgraph(int a) 50 | { 51 | return ((unsigned)a - 0x21) < 0x5e; 52 | } 53 | 54 | static inline int isspace(int a) 55 | { 56 | return (a) == ' ' || (unsigned)a - '\t' < 5; 57 | } 58 | 59 | // - - - - - - - - - - - - - - - 60 | 61 | static inline int isalnum(int a) 62 | { 63 | return (((unsigned)a | 32) - 'a') < 26 || ((unsigned)a - '0') < 10; 64 | } 65 | 66 | // - - - - - - - - - - - - - - - 67 | 68 | static inline int tolower(int a) 69 | { 70 | return ((unsigned)a - 'A') < 26 ? (a | 0x20) : a; 71 | } 72 | 73 | static inline int toupper(int a) 74 | { 75 | return ((unsigned)a - 'a') < 26 ? (a & ~0x20) : a; 76 | } 77 | 78 | // - - - - - - - - - - - - - - - 79 | 80 | int isblank(int); 81 | 82 | 83 | #endif /* _CTYPE_H */ 84 | -------------------------------------------------------------------------------- /include/kernel/blkmap.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERNEL_BLKMAP_H 2 | #define __KERNEL_BLKMAP_H 1 3 | 4 | #include 5 | 6 | typedef struct blkmap blkmap_t; 7 | struct blkmap 8 | { 9 | inode_t *ino; 10 | size_t block; 11 | size_t msize; 12 | xoff_t off; 13 | int rights; 14 | void *ptr; 15 | void *(*map)(blkmap_t *bkm, size_t no, int rights); 16 | blkmap_t *(*clone)(blkmap_t *bkm); 17 | void (*close)(blkmap_t *bkm); 18 | }; 19 | 20 | blkmap_t *blk_open(inode_t *ino, size_t blocksize); 21 | 22 | #define blk_map(b,n,r) (b)->map((b),(n),(r)) 23 | #define blk_close(b) (b)->close(b) 24 | #define blk_clone(b) (b)->clone(b) 25 | 26 | 27 | #endif /* __KERNEL_BLKMAP_H */ 28 | -------------------------------------------------------------------------------- /include/kernel/core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KERNEL_CORE_H 21 | #define _KERNEL_CORE_H 1 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | typedef struct cpu_info cpu_info_t; 29 | typedef struct sys_info sys_info_t; 30 | 31 | 32 | struct cpu_info { 33 | int id; 34 | int irq_semaphore; 35 | int mode; 36 | void *stack; 37 | acpu_info_t *arch; 38 | uint64_t ticks_system; 39 | uint64_t ticks_user; 40 | uint64_t ticks_irq; 41 | uint64_t ticks_idle; 42 | }; 43 | 44 | struct sys_info { 45 | int cpu_count; 46 | int is_ready; 47 | xtime_t uptime; 48 | cpu_info_t *cpu_table; 49 | asys_info_t *arch; 50 | }; 51 | 52 | 53 | #define KMODE_SYSTEM 0 54 | #define KMODE_IRQ 1 55 | #define KMODE_USER 2 56 | #define KMODE_IDLE 3 57 | 58 | 59 | sys_info_t *ksys(); 60 | cpu_info_t *kcpu(); 61 | 62 | 63 | // /* - */ 64 | // void cpu_setup(xtime_t *now); 65 | // /* - */ 66 | // void cpu_setjmp(cpu_state_t *buf, void *stack, void *func, void *arg); 67 | // /* - */ 68 | // int cpu_save(cpu_state_t *buf); 69 | // /* - */ 70 | // _Noreturn void cpu_restore(cpu_state_t *buf); 71 | // /* - */ 72 | // _Noreturn void cpu_halt(); 73 | // /* - */ 74 | // int cpu_no(); 75 | 76 | // per_cpu_t *cpu_store(); 77 | 78 | // /* - */ 79 | // void mmu_enable(); 80 | // /* - */ 81 | // void mmu_leave(); 82 | // /* - */ 83 | // void mmu_context(mspace_t *mspace); 84 | // /* - */ 85 | // int mmu_resolve(size_t vaddr, page_t phys, int flags); 86 | // /* - */ 87 | // page_t mmu_read(size_t vaddr); 88 | // /* - */ 89 | // page_t mmu_drop(size_t vaddr); 90 | // /* - */ 91 | // page_t mmu_protect(size_t vaddr, int flags); 92 | // /* - */ 93 | // void mmu_create_uspace(mspace_t *mspace); 94 | // /* - */ 95 | // void mmu_destroy_uspace(mspace_t *mspace); 96 | 97 | 98 | /* - */ 99 | void arch_start(); 100 | /* - */ 101 | void module_loader(); 102 | /* - */ 103 | size_t task_start(const char *name, void *func, void *arg); 104 | 105 | #endif /* _KERNEL_CORE_H */ 106 | -------------------------------------------------------------------------------- /include/kernel/irq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KERNEL_IRQ_H 21 | #define _KERNEL_IRQ_H 1 22 | 23 | #include 24 | 25 | 26 | typedef void (*irq_handler_t)(void *); 27 | 28 | void irq_reset(bool enable); 29 | bool irq_enable(); 30 | void irq_disable(); 31 | 32 | void irq_register(int no, irq_handler_t func, void *data); 33 | void irq_unregister(int no, irq_handler_t func, void *data); 34 | void irq_ack(int no); 35 | 36 | void irq_enter(int no); 37 | void irq_fault(const char *name, unsigned signum); 38 | long irq_syscall(unsigned no, long a1, long a2, long a3, long a4, long a5); 39 | 40 | 41 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 42 | 43 | #define SCALL_ENTRY(n,a1,a2,a3,a4,a5,rt,s) \ 44 | { .scall = (void*)sys_##n, .name = #n, .args = {a1, a2, a3, a4, a5, rt},\ 45 | .split = s } 46 | 47 | enum { 48 | ARG_NONE, 49 | ARG_STR, 50 | ARG_INT, 51 | ARG_FLG, 52 | ARG_LEN, 53 | ARG_FD, 54 | ARG_PTR, 55 | }; 56 | 57 | 58 | 59 | typedef struct syscall_info syscall_info_t; 60 | 61 | struct syscall_info { 62 | long(*scall)(long a1, long a2, long a3, long a4, long a5); 63 | const char *name; 64 | char args[6]; 65 | int split; 66 | }; 67 | 68 | #endif /* _KERNEL_IRQ_H */ 69 | -------------------------------------------------------------------------------- /include/kernel/mods.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KERNEL_MODS_H 21 | #define _KERNEL_MODS_H 1 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | typedef struct kmodule kmodule_t; 29 | typedef struct kapi kapi_t; 30 | 31 | struct kmodule { 32 | const char *name; 33 | void (*setup)(); 34 | void (*teardown)(); 35 | uint32_t version; 36 | llnode_t node; 37 | }; 38 | 39 | struct kapi { 40 | const char *name; 41 | void *sym; 42 | int flags; 43 | }; 44 | 45 | #define EXPORT_MODULE(n,s,t) \ 46 | kmodule_t kmodule_##n = { \ 47 | .name = #n, \ 48 | .setup = s, \ 49 | .teardown = t, \ 50 | .version = VERS32(0,1,0), } 51 | 52 | #define REQUIRE_MODULE(n) \ 53 | const char *kdepsmodule_##n __attribute__(section(".kmod"), used) = #n 54 | 55 | 56 | #ifdef KORA_KRN 57 | # define EXPORT_SYMBOL(n,s) \ 58 | kapi_t _ksym_##n = \ 59 | { .name = #n, .sym = n, .flags = (s) }; \ 60 | const kapi_t __attribute__((section(".ksymbols"))) \ 61 | * _kpsym_##n = &_ksym_##n 62 | #else 63 | # define EXPORT_SYMBOL(n,s) \ 64 | kapi_t _ksym_##n = \ 65 | { .name = #n, .sym = n, .flags = (s) } 66 | #endif 67 | 68 | 69 | #define kernel_export_symbol(x) module_symbol(#x,(void*)(x)); 70 | 71 | void module_symbol(const char *name, void *ptr); 72 | 73 | 74 | #endif /* _KERNEL_MODS_H */ 75 | -------------------------------------------------------------------------------- /include/kernel/net/eth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __KERNEL_NET_ETH_H 21 | #define __KERNEL_NET_ETH_H 1 22 | 23 | #include 24 | 25 | #define ETH_ALEN 6 26 | 27 | typedef struct eth_header eth_header_t; 28 | 29 | struct eth_header { 30 | uint8_t target[ETH_ALEN]; 31 | uint8_t sender[ETH_ALEN]; 32 | uint16_t type; 33 | }; 34 | 35 | int eth_receive(skb_t *skb); 36 | skb_t *eth_packet(ifnet_t *ifnet, const uint8_t *addr, uint16_t type); 37 | 38 | #endif /* __KERNEL_NET_ETH_H */ 39 | -------------------------------------------------------------------------------- /include/kernel/net/ip4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __KERNEL_NET_IP4_H 21 | #define __KERNEL_NET_IP4_H 1 22 | 23 | #include 24 | 25 | #define IP4_ALEN 4 26 | 27 | typedef struct ip4_route ip4_route_t; 28 | typedef struct ip4_frame ip4_frame_t; 29 | 30 | 31 | void ip4_setup(); 32 | 33 | int ip4_receive(skb_t *skb); 34 | skb_t *ip4_packet(ifnet_t *ifnet, ip4_route_t *route, ip4_frame_t *frame); 35 | skb_t *ip4_sock_packet(socket_t *sock); 36 | int ip4_connect(socket_t *socket, uint8_t *ip); 37 | void ip4_config(ifnet_t *ifnet, uint8_t *addr, uint8_t *mask, uint8_t *gateway); 38 | 39 | 40 | 41 | 42 | #endif /* __KERNEL_NET_IP4_H */ 43 | -------------------------------------------------------------------------------- /include/kernel/net/lo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __KERNEL_NET_LO_H 21 | #define __KERNEL_NET_LO_H 1 22 | 23 | #include 24 | 25 | 26 | int lo_receive(skb_t *skb); 27 | skb_t *lo_packet(ifnet_t *ifnet, uint16_t type); 28 | 29 | #endif /* __KERNEL_NET_LO_H */ 30 | -------------------------------------------------------------------------------- /include/kora/bbtree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KORA_BBTREE_H 21 | #define _KORA_BBTREE_H 1 22 | 23 | #include 24 | 25 | typedef struct bbtree bbtree_t; 26 | typedef struct bbnode bbnode_t; 27 | typedef struct bbslot bbslot_t; 28 | 29 | #ifndef itemof 30 | # undef offsetof 31 | # define offsetof(t,m) ((size_t)&(((t*)0)->m)) 32 | # define itemof(p,t,m) ((t*)itemof_((p), offsetof(t,m))) 33 | static inline void *itemof_(void *ptr, int off) 34 | { 35 | return ptr ? (char *)ptr - off : 0; 36 | } 37 | #endif 38 | 39 | 40 | /* BBTree (self-balancing binary tree) head */ 41 | struct bbtree 42 | { 43 | bbnode_t *root_; 44 | int count_; 45 | }; 46 | 47 | /* BBTree (self-balancing binary tree) node */ 48 | struct bbnode 49 | { 50 | bbnode_t *parent_; 51 | bbnode_t *left_; 52 | bbnode_t *right_; 53 | size_t value_; 54 | int level_; 55 | }; 56 | 57 | struct bbslot 58 | { 59 | bbnode_t node; 60 | void *data; 61 | }; 62 | 63 | void bbtree_init(bbtree_t *tree); 64 | int bbtree_check(bbnode_t *node); 65 | int bbtree_insert(bbtree_t *tree, bbnode_t *node); 66 | int bbtree_remove(bbtree_t *tree, size_t value); 67 | 68 | bbnode_t *bbtree_left_(bbnode_t *node); 69 | bbnode_t *bbtree_right_(bbnode_t *node); 70 | bbnode_t *bbtree_next_(bbnode_t *node); 71 | bbnode_t *bbtree_previous_(bbnode_t *node); 72 | 73 | bbnode_t *bbtree_search_(bbnode_t *node, size_t value, int accept); 74 | 75 | #define bbtree_first(t,s,m) (s*)itemof(bbtree_left_((t)->root_),s,m) 76 | #define bbtree_last(t,s,m) (s*)itemof(bbtree_right_((t)->root_),s,m) 77 | 78 | #define bbtree_next(n,s,m) (s*)itemof(bbtree_next_(n),s,m) 79 | #define bbtree_previous(n,s,m) (s*)itemof(bbtree_previous_(n),s,m) 80 | #define bbtree_left(n,s,m) (s*)itemof(bbtree_left_(n),s,m) 81 | #define bbtree_right(n,s,m) (s*)itemof(bbtree_right_(n),s,m) 82 | 83 | #define bbtree_each(t,n,s,m) ((n)=bbtree_first(t,s,m);(n);(n)=bbtree_next(&(n)->m,s,m)) 84 | 85 | #define bbtree_search_eq(t,v,s,m) (s*)itemof(bbtree_search_((t)->root_,v,0),s,m) 86 | #define bbtree_search_le(t,v,s,m) (s*)itemof(bbtree_search_((t)->root_,v,-1),s,m) 87 | #define bbtree_search_ge(t,v,s,m) (s*)itemof(bbtree_search_((t)->root_,v,1),s,m) 88 | 89 | #endif /* _KORA_BBTREE_H */ 90 | -------------------------------------------------------------------------------- /include/kora/hmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KORA_HMAP_H 21 | #define _KORA_HMAP_H 1 22 | 23 | #include 24 | #include 25 | 26 | typedef struct hmap hmap_t; 27 | typedef struct hnode hnode_t; 28 | 29 | struct hmap { 30 | hnode_t **hashes; 31 | uint32_t mask; 32 | uint32_t seed; 33 | uint32_t count; 34 | }; 35 | 36 | int murmur3_32(const void *key, int bytes, uint32_t seed); 37 | 38 | void hmp_init(hmap_t *map, int lg); 39 | void hmp_destroy(hmap_t *map); 40 | 41 | void hmp_put(hmap_t *map, const char *key, int lg, void *value); 42 | void *hmp_get(hmap_t *map, const char *key, int lg); 43 | void hmp_remove(hmap_t *map, const char *key, int lg); 44 | 45 | #endif /* _KORA_HMAP_H */ 46 | -------------------------------------------------------------------------------- /include/kora/mcrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KORA_MCRS_H 21 | #define _KORA_MCRS_H 1 22 | 23 | #define _Kib_ (1024L) 24 | #define _Mib_ (1024L*_Kib_) 25 | #define _Gib_ (1024LL*_Mib_) 26 | #define _Tib_ (1024LL*_Gib_) 27 | #define _Pib_ (1024LL*_Tib_) 28 | #define _Eib_ (1024LL*_Pib_) 29 | 30 | #define _PwMilli_ (1000L) 31 | #define _PwMicro_ (1000L * _PwMilli_) 32 | #define _PwNano_ (1000LL * _PwMicro_) 33 | #define _PwFemto_ (1000LL * _PwNano_) 34 | 35 | #define ALIGN_UP(v,a) (((v)+((a)-1))&(~((a)-1))) 36 | #define ALIGN_DW(v,a) ((v)&(~((a)-1))) 37 | #define IS_ALIGNED(v,a) (((v)&((a)-1))==0) 38 | 39 | #define ADDR_OFF(a,o) ((void*)(((char*)a)+(o))) 40 | #define ADDR_PUSH(a,s) ((void*)((a)=(void*)(((char*)(a))-(s)))) 41 | 42 | #define MIN(a,b) ((a)<=(b)?(a):(b)) 43 | #define MAX(a,b) ((a)>=(b)?(a):(b)) 44 | #define MIN3(a,b,c) MIN(a,MIN(b,c)) 45 | #define MAX3(a,b,c) MAX(a,MAX(b,c)) 46 | #define POW2(v) ((v) != 0 && ((v) & ((v)-1)) == 0) 47 | #define BIT(s) (1<<(s)) 48 | 49 | #define MIN_TO_USEC(s) ((s)*60000000LL) 50 | #define SEC_TO_USEC(s) ((s)*1000000LL) 51 | #define MSEC_TO_USEC(s) ((s)*1000LL) 52 | #define TMSPEC_TO_USEC(t) ((t).tv_sec*1000000LL+(t).tv_nsec/1000L) 53 | #define USEC_TO_SEC(s) ((s)/1000000LL) 54 | #define NSEC_OF_USEC(s) (((s) % 1000000LL) * 1000) 55 | 56 | #define STRINGIFY(x) #x 57 | #define TOSTRING(x) STRINGIFY(x) 58 | #define __AT__ __FILE__ ":" TOSTRING(__LINE__) 59 | 60 | static inline int POW2_UP(int val) 61 | { 62 | if (val == 0 || POW2(val)) 63 | return val; 64 | --val; 65 | val |= val >> 1; 66 | val |= val >> 2; 67 | val |= val >> 4; 68 | val |= val >> 8; 69 | val |= val >> 16; 70 | return val + 1; 71 | } 72 | 73 | #define VERS32(mj,mn,pt) ( (((mj) & 0x3FF) << 20) | (((mn) & 0x3FF) << 8) | ((pt) & 0xFF) ) 74 | #define VERS32_MJ(v) (((v) >> 20) & 0x3FF) 75 | #define VERS32_MN(v) (((v) >> 8) & 0x3FF) 76 | #define VERS32_PT(v) ((v) & 0xFF) 77 | 78 | #if defined(WIN32) || defined(_WIN32) 79 | # define LIBAPI __declspec(dllexport) 80 | # define EXTAPI __declspec(dllimport) 81 | #else 82 | # define LIBAPI 83 | # define EXTAPI 84 | #endif 85 | 86 | #ifndef KORA_PRT 87 | # define _PRT(p) p 88 | #else 89 | # define _PRT(p) p ## _p 90 | #endif 91 | 92 | #endif /* _KORA_MCRS_H */ 93 | -------------------------------------------------------------------------------- /include/kora/splock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KORA_SPLOCK_H 21 | #define _KORA_SPLOCK_H 1 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | extern void irq_reset(bool enable); 28 | extern bool irq_enable(); 29 | extern void irq_disable(); 30 | extern void irq_zero(); 31 | 32 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 33 | 34 | 35 | typedef atomic_int splock_t; 36 | 37 | #define INIT_SPLOCK 0 38 | 39 | /* Initialize and reset a spin-lock structure */ 40 | static inline void splock_init(splock_t *lock) 41 | { 42 | atomic_store(lock, 0); 43 | } 44 | 45 | /* Block the cpu until the lock might be taken */ 46 | static inline void splock_lock(splock_t *lock) 47 | { 48 | irq_disable(); 49 | for (;;) { 50 | if (atomic_xchg(lock, 1) == 0) 51 | return; 52 | while (*lock != 0) 53 | __asm_pause_; 54 | } 55 | } 56 | 57 | /* Release a lock */ 58 | static inline void splock_unlock(splock_t *lock) 59 | { 60 | atomic_store(lock, 0); 61 | irq_enable(); 62 | } 63 | 64 | /* Try to grab the lock but without blocking. */ 65 | static inline bool splock_trylock(splock_t *lock) 66 | { 67 | irq_disable(); 68 | if (atomic_xchg(lock, 1) == 0) 69 | return true; 70 | irq_enable(); 71 | return false; 72 | } 73 | 74 | /* Return a boolean that check the lock is hold by someone. */ 75 | static inline bool splock_locked(splock_t *lock) 76 | { 77 | return atomic_load(lock) != 0; 78 | } 79 | 80 | 81 | #endif /* _KORA_SPLOCK_H */ 82 | -------------------------------------------------------------------------------- /include/kora/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef __KORA_TIME_H 21 | #define __KORA_TIME_H 1 22 | 23 | typedef long long xtime_t; 24 | typedef enum xtime_name xtime_name_t; 25 | 26 | enum xtime_name { 27 | XTIME_CLOCK = 0, 28 | XTIME_UTC, 29 | XTIME_LOCAL, 30 | XTIME_MONOTONIC, 31 | XTIME_UPTIME, 32 | XTIME_THREAD, 33 | }; 34 | 35 | 36 | xtime_t xtime_read(xtime_name_t name); 37 | // xtime_t xtime_adjust(xtime_t expected); 38 | 39 | #endif /* __KORA_TIME_H */ 40 | -------------------------------------------------------------------------------- /include/mbstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _MBSTRING_H 21 | #define _MBSTRING_H 1 22 | 23 | #include 24 | 25 | 26 | #define _TVOID void 27 | #define _TCHAR unsigned char 28 | #define _SFM(n) mem ## n 29 | #define _SFX(n) mbs ## n 30 | #include 31 | #undef _TVOID 32 | #undef _TCHAR 33 | #undef _SFM 34 | #undef _SFX 35 | 36 | 37 | int mbtowc(wchar_t *wc, const char *str, size_t len); 38 | // size_t mbstowcs (wchar_t *ws, const char **str, size_t wn, mbstate_t *st); 39 | size_t mbstowcs(wchar_t *ws, const char *str, size_t wn); 40 | int mblen(const char *str, size_t len); 41 | 42 | #endif /* _MBSTRING_H */ 43 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _STRING_H 21 | #define _STRING_H 1 22 | 23 | #include 24 | 25 | 26 | #define _TVOID void 27 | #define _TCHAR char 28 | #define _SFM(n) mem ## n 29 | #define _SFX(n) str ## n 30 | #include 31 | #undef _TVOID 32 | #undef _TCHAR 33 | #undef _SFM 34 | #undef _SFX 35 | 36 | 37 | /* Gives an error message string. */ 38 | char *strerror_r(int errnum, char *buf, int len); 39 | /* Gives an error message string. */ 40 | char *strerror(int errnum); 41 | 42 | 43 | #endif /* _STRING_H */ 44 | -------------------------------------------------------------------------------- /include/sys/sem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef SYS_SEM_H 21 | #define SYS_SEM_H 1 22 | 23 | #include 24 | #include 25 | 26 | typedef struct sem sem_t; 27 | 28 | struct sem { 29 | mtx_t mtx; 30 | cnd_t cv; 31 | int count; 32 | }; 33 | 34 | __STDC_GUARD 35 | 36 | int sem_init(sem_t *sem, int count); 37 | void sem_destroy(sem_t *sem); 38 | void sem_acquire(sem_t *sem); 39 | int sem_timedacquire(sem_t *sem, const struct timespec *xt); 40 | void sem_acquire_many(sem_t *sem, int count); 41 | int sem_tryacquire(sem_t *sem); 42 | void sem_release(sem_t *sem); 43 | void sem_release_many(sem_t *sem, int count); 44 | 45 | __STDC_END 46 | 47 | #endif /* SYS_SEM_H */ 48 | -------------------------------------------------------------------------------- /make/build.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | $(outdir)/%.o: $(topdir)/%.c 18 | $(S) mkdir -p $(dir $@) 19 | $(Q) echo " CC $<" 20 | $(V) $(CC) -c -o $@ $< $(CFLAGS) 21 | 22 | $(outdir)/%.d: $(topdir)/%.c 23 | $(S) mkdir -p $(dir $@) 24 | $(Q) echo " CM $<" 25 | $(V) $(CC) -M $< $(CFLAGS) | sed "s%$(notdir $(@:.d=.o))%$(@:.d=.o)%" > $@ 26 | 27 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 28 | 29 | define comp_source 30 | $(outdir)/$(1)/%.o: $(topdir)/%.c 31 | $(S) mkdir -p $$(dir $$@) 32 | $(Q) echo " CC $$<" 33 | $(V) $(CC) -c -o $$@ $$< $($(2)) 34 | 35 | $(outdir)/$(1)/%.d: $(topdir)/%.c 36 | $(S) mkdir -p $$(dir $$@) 37 | $(Q) echo " CM $$<" 38 | $(V) $(CC) -M $$< $($(2)) | sed "s%$$(notdir $$(@:.d=.o))%$$(@:.d=.o)%" > $$@ 39 | endef 40 | 41 | define link_shared 42 | LIBS += $(libdir)/lib$(1).so 43 | lib$(1): $(libdir)/lib$(1).so 44 | install-lib$(1): $(prefix)/lib/lib$(1).so 45 | $(libdir)/lib$(1).so: $(call fn_objs,$(2),$(4)) 46 | $(S) mkdir -p $$(dir $$@) 47 | $(Q) echo " LD $$@" 48 | $(V) $(LDC) -shared -o $$@ $$^ $($(3)) 49 | endef 50 | 51 | define link_bin 52 | BINS += $(bindir)/$(1) 53 | $(1): $(bindir)/$(1) 54 | install-$(1): $(prefix)/bin/$(1) 55 | $(bindir)/$(1): $(call fn_objs,$(2),$(4)) 56 | $(S) mkdir -p $$(dir $$@) 57 | $(Q) echo " LD $$@" 58 | $(V) $(LDC) -o $$@ $$^ $($(3)) 59 | endef 60 | 61 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 62 | clean: 63 | $(V) rm -rf $(outdir) 64 | $(V) rm -rf $(libdir) 65 | $(V) rm -rf $(bindir) 66 | 67 | $(prefix)/lib/%: $(libdir)/% 68 | $(S) mkdir -p $(dir $@) 69 | $(Q) echo " INSTALL $@" 70 | $(V) $(INSTALL) $< $@ 71 | 72 | $(prefix)/bin/%: $(bindir)/% 73 | $(S) mkdir -p $(dir $@) 74 | $(Q) echo " INSTALL $@" 75 | $(V) $(INSTALL) $< $@ 76 | 77 | 78 | 79 | .PHONY: all clean deliveries 80 | -------------------------------------------------------------------------------- /make/check.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | SED_LCOV = -e '/SF:\/usr.*/,/end_of_record/d' 19 | SED_LCOV += -e '/SF:.*\/tests\/.*/,/end_of_record/d' 20 | 21 | 22 | check: $(patsubst %,val_%,$(CHECKS)) 23 | 24 | split_coverage: $(patsubst %,cov_%,$(CHECKS)) 25 | 26 | coverage.lcov: check 27 | $(V) lcov --rc lcov_branch_coverage=1 -c --directory . -b . -o coverage.lcov 28 | $(S) sed $(SED_LCOV) -i coverage.lcov 29 | 30 | do_coverage: 31 | $(V) lcov --rc lcov_branch_coverage=1 -c --directory . -b . -o coverage.lcov 32 | $(S) sed $(SED_LCOV) -i coverage.lcov 33 | $(V) genhtml --rc lcov_branch_coverage=1 -o coverage coverage.lcov 34 | 35 | coverage: coverage.lcov 36 | $(V) genhtml --rc lcov_branch_coverage=1 -o coverage coverage.lcov 37 | 38 | %.lcov: $(bindir)/% 39 | $(S) find -name *.gcda | xargs -r rm 40 | $(V) $< 41 | $(V) lcov --rc lcov_branch_coverage=1 -c --directory . -b . -o $@ >/dev/null 42 | $(S) sed $(SED_LCOV) -i $@ 43 | 44 | cov_%: %.lcov 45 | $(V) genhtml --rc lcov_branch_coverage=1 -o $@ $< >/dev/null 46 | 47 | val_%: $(bindir)/% 48 | $(V) valgrind --error-exitcode=9 --leak-check=full --show-leak-kinds=all $< 2>&1 | tee $@ 49 | 50 | .PHONY: check coverage 51 | -------------------------------------------------------------------------------- /make/drivers.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | $(outdir)/dr/%.o: $(topdir)/%.c 19 | $(S) mkdir -p $(dir $@) 20 | $(Q) echo " CC $<" 21 | $(V) $(CC) -c -o $@ $< $(CFLAGS_dr) 22 | 23 | $(outdir)/dr/%.d: $(topdir)/%.c 24 | $(S) mkdir -p $(dir $@) 25 | $(Q) echo " CM $<" 26 | $(V) $(CC) -M $< $(CFLAGS_dr) | sed "s%$(notdir $(@:.d=.o))%$(@:.d=.o)%" > $@ 27 | 28 | 29 | define link_driver 30 | DRVS += $(libdir)/$(1).ko 31 | INSTALL_DRVS += $(prefix)/boot/mods/$(1).ko 32 | $(1): $(libdir)/$(1).ko 33 | $(libdir)/$(1).ko: $(call fn_objs,$(1)_SRCS,dr) 34 | $(S) mkdir -p $$(dir $$@) 35 | $(Q) echo " LD $$@" 36 | $(V) $(LDC) -shared -nostdlib -o $$@ $$^ $($(1)_LFLAGS_dr) 37 | $(prefix)/boot/mods/$(1).ko: $(libdir)/$(1).ko 38 | $(S) mkdir -p $$(dir $$@) 39 | $(Q) echo " INSTALL $$@" 40 | $(V) $(INSTALL) $$< $$@ 41 | .PHONY:$(1) 42 | endef 43 | 44 | define link_sbin 45 | BINS += $(bindir)/$(1) 46 | INSTALL_BINS += $(prefix)/sbin/$(1) 47 | $(1): $(bindir)/$(1) 48 | $(bindir)/$(1): $(call fn_objs,$(1)_SRCS,dr) 49 | $(S) mkdir -p $$(dir $$@) 50 | $(Q) echo " LD $$@" 51 | $(V) $(CC) -o $$@ $$^ $($(1)_LFLAGS_dr) 52 | $(prefix)/sbin/$(1): $(bindir)/$(1) 53 | $(S) mkdir -p $$(dir $$@) 54 | $(Q) echo " INSTALL $$@" 55 | $(V) $(INSTALL) $$< $$@ 56 | endef 57 | -------------------------------------------------------------------------------- /make/global.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | # D I R E C T O R I E S -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 19 | prefix ?= /usr/local 20 | topdir ?= $(shell readlink -f $(dir $(word 1,$(MAKEFILE_LIST)))) 21 | gendir ?= $(shell pwd) 22 | srcdir := $(topdir) 23 | outdir := $(gendir)/obj 24 | bindir := $(gendir)/bin 25 | libdir := $(gendir)/lib 26 | 27 | # T A R G E T -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 28 | host ?= $(shell $(topdir)/make/host.sh) 29 | host_arch := $(word 1,$(subst -, ,$(host))) 30 | host_vendor := $(word 2,$(subst -, ,$(host))) 31 | host_os := $(patsubst $(host_arch)-$(host_vendor)-%,%,$(host)) 32 | 33 | target ?= $(host) 34 | target_arch := $(word 1,$(subst -, ,$(target))) 35 | target_vendor := $(word 2,$(subst -, ,$(target))) 36 | target_os := $(patsubst $(target_arch)-$(target_vendor)-%,%,$(target)) 37 | 38 | S := @ 39 | V := $(shell [ -z $(VERBOSE) ] && echo @) 40 | Q := $(shell [ -z $(QUIET) ] && echo @ || echo @true) 41 | 42 | # C O M M A N D S -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 43 | AS ?= $(CROSS)as 44 | AR ?= $(CROSS)ar 45 | CC ?= $(CROSS)gcc 46 | CXX ?= $(CROSS)g++ 47 | LD ?= $(CROSS)ld 48 | LDC ?= $(CC) 49 | LDCX ?= $(CXX) 50 | NM ?= nm 51 | INSTALL ?= install 52 | PKC ?= pkg-config 53 | 54 | ASM_EXT := s 55 | 56 | DATE := $(shell date '+%Y-%m-%d') 57 | GIT_H := $(shell git --git-dir=$(topdir)/.git rev-parse --short HEAD 2> /dev/null)$(shell if [ -n "$(git --git-dir=$(topdir)/.git status -suno)"]; then echo '+'; fi) 58 | GIT_V := $(shell git --git-dir=$(topdir)/.git describe 2> /dev/null) 59 | VERSION ?= $(GIT_V:v=) 60 | 61 | # A V O I D D E P E N D E N C Y -=-=-=-=-=-=-=-=-=-=-=- 62 | ifeq ($(shell [ -d $(outdir) ] || echo N ),N) 63 | NODEPS ?= 1 64 | endif 65 | ifeq ($(MAKECMDGOALS),help) 66 | NODEPS ?= 1 67 | endif 68 | ifeq ($(MAKECMDGOALS),clean) 69 | NODEPS ?= 1 70 | endif 71 | ifeq ($(MAKECMDGOALS),distclean) 72 | NODEPS ?= 1 73 | endif 74 | 75 | 76 | define fn_objs 77 | $(patsubst $(topdir)/%.c,$(outdir)/$(2)/%.o,$(patsubst $(topdir)/%.$(ASM_EXT),$(outdir)/%.o,$($(1)))) 78 | endef 79 | define fn_deps 80 | $(patsubst $(topdir)/%.c,$(outdir)/$(2)/%.d,$(patsubst $(topdir)/%.$(ASM_EXT),,$($(1)))) 81 | endef 82 | define fn_inst 83 | $(patsubst $(gendir)/%,$(prefix)/%,$(1)) 84 | endef 85 | define fn_flcp 86 | $(patsubst $(topdir)/%,$(prefix)/%,$(1)) 87 | endef 88 | -------------------------------------------------------------------------------- /make/host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | 19 | # Parse first argument if provided 20 | if [ -n "$1" ]; then 21 | IFS='-' read -ra THST <<< "$1" 22 | arch=${THST[0]} 23 | vendor=${THST[1]} 24 | req_vendor=${THST[1]} 25 | os=`tr ' ' '-' <<< "${THST[@]:2:${#THST[@]}}" ` 26 | fi 27 | 28 | # Find architecture 29 | if [ -z "$arch" ]; then 30 | arch=`uname -m` 31 | fi 32 | 33 | case "$arch" in 34 | i[3-7]86) 35 | arch=i386 36 | vendor=pc 37 | ;; 38 | x86_64|amd64) 39 | arch=x86_64 40 | vendor=pc 41 | ;; 42 | armv7l) 43 | arch=arm 44 | vendor=phone 45 | ;; 46 | aarch64) 47 | arch=aarch64 48 | vendor=phone 49 | ;; 50 | *) 51 | echo "Unsupported architecture '${arch}'" >&2 52 | exit 1 53 | ;; 54 | esac 55 | 56 | # Check vendor 57 | if [ -n "$1" ]; then 58 | if [ "$vendor" != "$req_vendor" ] ; then 59 | os=`tr ' ' '-' <<< "${THST[@]:1:${#THST[@]}}" ` 60 | fi 61 | fi 62 | 63 | # Resolve operating system 64 | if [ -z "$os" ]; then 65 | os=`uname -o` 66 | fi 67 | 68 | case "$os" in 69 | Android) 70 | os=linux-android 71 | ;; 72 | GNU/Linux|*Linux*) 73 | os=linux-gnu 74 | ;; 75 | kora) 76 | os=kora 77 | ;; 78 | [Mm]sys|win32) 79 | os='win32' 80 | ;; 81 | *) 82 | echo "Unsupported platform '${os}'" >&2 83 | exit 1 84 | ;; 85 | esac 86 | 87 | # Print final triplet result 88 | echo "$arch-$vendor-$os" 89 | -------------------------------------------------------------------------------- /make/targets.mk: -------------------------------------------------------------------------------- 1 | # This file is part of the KoraOS project. 2 | # Copyright (C) 2015-2021 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Affero General Public License as 6 | # published by the Free Software Foundation, either version 3 of the 7 | # License, or (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU Affero General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Affero General Public License 15 | # along with this program. If not, see . 16 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 17 | 18 | deliveries: $(BINS) $(LIBS) 19 | 20 | install: install-utilities install-shared install-headers install-pkgconfig 21 | 22 | install-utilities: $(call fn_inst, $(BINS)) 23 | 24 | install-shared: $(call fn_inst, $(LIBS)) 25 | 26 | ifeq (,$(wildcard $(topdir)/$(PACKAGE).pc.in)) 27 | install-pkgconfig: 28 | else 29 | install-pkgconfig: $(gendir)/$(PACKAGE).pc 30 | $(S) mkdir -p $(prefix)/lib/pkgconfig 31 | $(S) cp -RpP -f $< $(prefix)/lib/pkgconfig/ 32 | 33 | $(gendir)/$(PACKAGE).pc: $(topdir)/$(PACKAGE).pc.in 34 | $(S) echo "prefix=${prefix}" > $@ 35 | $(S) echo "version=${VERSION}" >> $@ 36 | $(S) cat $< >> $@ 37 | endif 38 | 39 | 40 | .PHONY: all install install-utilities install-shared install-headers install-pkgconfig 41 | -------------------------------------------------------------------------------- /scripts/bridge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | set -x 21 | 22 | # ip link add br0 type bridge 23 | # ip link set enp3s0 master br0 24 | 25 | switch=br0 26 | 27 | if [ -n "$1" ];then 28 | #tunctl -u `whoami` -t $1 29 | ip tuntap add $1 mode tap user `whoami` 30 | ip link set $1 up 31 | sleep 0.5s 32 | #brctl addif $switch $1 33 | ip link set $1 master $switch 34 | exit 0 35 | else 36 | echo "Error: no interface specified" 37 | exit 1 38 | fi 39 | 40 | 41 | # generate a random mac address for the qemu nic 42 | macaddress ='DE:AD:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256)) 43 | print $macaddress 44 | 45 | qemu-system-x86_64 -cdrom KoraOs.iso -device e1000,netdev=net0,mac=$macaddress -netdev tap,id=net0 46 | -------------------------------------------------------------------------------- /scripts/cfg/grub.cfg: -------------------------------------------------------------------------------- 1 | set default="0" 2 | set timeout="0" 3 | 4 | menuentry "Kora x86" { 5 | multiboot /boot/kora-x86.krn 6 | module /boot/x86.miniboot.tar 7 | } 8 | -------------------------------------------------------------------------------- /scripts/cfg/license.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | -------------------------------------------------------------------------------- /scripts/cfg/license.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This file is part of the KoraOS project. 4 | # Copyright (C) 2015-2019 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Affero General Public License as 8 | # published by the Free Software Foundation, either version 3 of the 9 | # License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Affero General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Affero General Public License 17 | # along with this program. If not, see . 18 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 19 | 20 | -------------------------------------------------------------------------------- /scripts/cfg/menu.lst: -------------------------------------------------------------------------------- 1 | default 0 2 | timeout 0 3 | 4 | title KoraOS x86 5 | kernel /boot/kora-x86.krn 6 | module /boot/x86.miniboot.tar 7 | -------------------------------------------------------------------------------- /scripts/cfg/stage2_eltorito: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/scripts/cfg/stage2_eltorito -------------------------------------------------------------------------------- /scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | 21 | LCOV="$SCRIPT_HOME/check.lcov" 22 | lcov --rc lcov_branch_coverage=1 -c --directory "$SCRIPT_HOME" -b "$SCRIPT_HOME" -o "$LCOV" 23 | sed -e '/SF:\/usr.*/,/end_of_record/d' -e '/SF:.*\/src\/tests\/.*/,/end_of_record/d' -i "$LCOV" 24 | genhtml --rc lcov_branch_coverage=1 -o coverage "$LCOV" 25 | 26 | # ./scripts/coverage.sh | grep ' lines......: [0-9.]*% ([0-9]* of [0-9]* lines)' 27 | -------------------------------------------------------------------------------- /scripts/cross_gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | 21 | export PREFIX="$SCRIPT_HOME/opt" 22 | export SOURCES="$PREFIX/src" 23 | export PATH="$PREFIX/bin:$PATH" 24 | 25 | # Versions of packages 26 | export BUTILS='binutils-2.30' 27 | export GCC='gcc-7.3.0' 28 | 29 | 30 | download() 31 | { 32 | cd "$SOURCES" 33 | wget "https://ftp.gnu.org/gnu/binutils/$BUTILS.tar.xz" 34 | wget "https://ftp.gnu.org/gnu/gcc/$GCC/$GCC.tar.xz" 35 | 36 | tar xvf "$BUTILS.tar.xz" 37 | tar xvf "$GCC.tar.xz" 38 | 39 | cd "$GCC" 40 | ./contrib/download_prerequisites 41 | } 42 | 43 | 44 | build_binutils() 45 | { 46 | cd "$SOURCES" 47 | 48 | mkdir "build-binutils-$TARGET" 49 | cd "build-binutils-$TARGET" 50 | "../$BUTILS/configure" --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror 51 | make 52 | make install 53 | } 54 | 55 | build_gcc() 56 | { 57 | cd "$SOURCES" 58 | # The $PREFIX/bin dir _must_ be in the PATH. We did that above. 59 | which -- "$TARGET"-as || echo "$TARGET"-as is not in the PATH 60 | 61 | mkdir build-gcc-$TARGET 62 | cd build-gcc-$TARGET 63 | "../$GCC/configure" --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers 64 | make all-gcc 65 | make all-target-libgcc 66 | make install-gcc 67 | make install-target-libgcc 68 | } 69 | 70 | clean () { 71 | rm -rf "$SOURCES" 72 | } 73 | 74 | look_arch() { 75 | case "$1" 76 | in 77 | i386|i486|i686) export TARGET='i386-elf' ;; 78 | raspi2) export TARGET='arm-none-eabi' ;; 79 | esac 80 | } 81 | 82 | look_arch $1 83 | mkdir -p "$PREFIX"/{bin,lib,src} 84 | 85 | download 86 | build_binutils 87 | build_gcc 88 | 89 | # echo '#!/bin/sh' > "$SCRIPT_HOME/.toolchain" 90 | # echo 'export PATH="'$PREFIX'/bin":$PATH' >> "$SCRIPT_HOME/.toolchain" 91 | # echo 'export CROSS="'$TARGET'-"' >> "$SCRIPT_HOME/.toolchain" 92 | -------------------------------------------------------------------------------- /scripts/drivers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | 21 | DIR="$SCRIPT_HOME/src/drivers" 22 | TMP="`readlink -f .`/drivers" 23 | PFX="`readlink -f .`/iso/boot" 24 | 25 | function parse_yaml { 26 | local prefix=$2 27 | local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') 28 | sed -ne "s|^\($s\):|\1|" \ 29 | -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ 30 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | 31 | awk -F$fs '{ 32 | indent = length($1)/2; 33 | vname[indent] = $2; 34 | for (i in vname) { 35 | if (i > indent) {delete vname[i]}} 36 | if (length($3) > 0) { 37 | vn=""; 38 | for (i=0; i 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | 19 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 20 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 21 | 22 | fixSrc_file="$SCRIPT_DIR/cfg/license.h" 23 | fixSh_file="$SCRIPT_DIR/cfg/license.txt" 24 | 25 | fixSrc() { 26 | TMP=`mktemp` 27 | cat "$1" > "$TMP" 28 | cat "$2" <(awk '/^#(include|ifndef)/ || c>0 {print;++c}' "$TMP") > "$1" 29 | rm "$TMP" 30 | } 31 | 32 | fixSh() { 33 | TMP=`mktemp` 34 | cat "$1" > "$TMP" 35 | cat $2 <(awk '/^SCRIPT_DIR/ || c>0 {print;++c}' "$TMP") > "$1" 36 | rm "$TMP" 37 | } 38 | 39 | 40 | checkDir () { 41 | FILE=$1'_file' 42 | MODEL=${!FILE} 43 | LICENSE=`head "$MODEL" -n 18` 44 | for src in $2 45 | do 46 | SRC_HEAD=`head -n18 $src` 47 | if [ "$LICENSE" != "$SRC_HEAD" ] 48 | then 49 | if [ "$FIX" != 'y' ] 50 | then 51 | echo "Missing license: $src" 52 | else 53 | echo "Editing license: $src" 54 | "$1" "$src" "$MODEL" 55 | fi 56 | else 57 | echo "License OK: $src" 58 | fi 59 | done 60 | } 61 | 62 | checkDir fixSrc "`find . -type f -a -name '*.c' -o -name '*.h'`" 63 | checkDir fixSh "`find . -type f -a -name '*.sh'`" 64 | -------------------------------------------------------------------------------- /scripts/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | 21 | # A hook script to verify what is about to be committed. 22 | # Called by "git commit" with no arguments. 23 | 24 | if git rev-parse --verify HEAD >/dev/null 2>&1 25 | then 26 | against=HEAD 27 | else 28 | # Initial commit: diff against an empty tree object 29 | against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 30 | fi 31 | 32 | # If you want to allow non-ASCII filenames set this variable to true. 33 | allownonascii=$(git config --bool hooks.allownonascii) 34 | 35 | # Redirect output to stderr. 36 | exec 1>&2 37 | 38 | # Cross platform projects tend to avoid non-ASCII filenames; prevent 39 | # them from being added to the repository. We exploit the fact that the 40 | # printable range starts at the space character and ends with tilde. 41 | if 42 | # Note that the use of brackets around a tr range is ok here, (it's 43 | # even required, for portability to Solaris 10's /usr/bin/tr), since 44 | # the square bracket bytes happen to fall in the designated range. 45 | test $(git diff --cached --name-only --diff-filter=A -z $against | 46 | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 47 | then 48 | echo 'Error: Attempt to add a non-ASCII file name.' 49 | exit 1 50 | fi 51 | 52 | # If there are whitespace errors, print the offending file names and fail. 53 | exec git diff-index --check --cached $against -- 54 | 55 | # astyle --style=kr --indent=spaces=4 --indent-col1-comments --min-conditional-indent=1 --pad-oper --pad-header --unpad-paren --align-pointer=name --align-reference=name --break-one-line-headers --remove-brackets --convert-tabs --lineend=linux --mode=c -r "*.c" "*.h" 56 | -------------------------------------------------------------------------------- /scripts/toolchain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the KoraOS project. 3 | # Copyright (C) 2015-2021 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 18 | SCRIPT_DIR=`dirname "$BASH_SOURCE{0}"` 19 | SCRIPT_HOME=`readlink -f "$SCRIPT_DIR/.."` 20 | 21 | 22 | PACK='kora-toolchain-x86_64.tar.bz2' 23 | URL="https://www.dropbox.com/s/wzjsiqbabyj1t7g/$PACK" 24 | 25 | install () { 26 | cd "$SCRIPT_HOME" 27 | wget "$URL" -o wget.log 28 | tar xjf "$PACK" 29 | } 30 | 31 | 32 | while (( $# > 0 )) 33 | do 34 | case "$1" 35 | in 36 | install) 37 | "$1" 38 | ;; 39 | esac 40 | shift 41 | done 42 | -------------------------------------------------------------------------------- /src/core/modules.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | // #include 23 | #include 24 | // #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 31 | 32 | // void arch_init() {} 33 | 34 | // int cpu_no() { return 0; } 35 | // void cpu_setup() {} 36 | // int cpu_save(task_t *task) {} 37 | // void cpu_prepare(task_t *task, void *func, void *arg) {} 38 | // _Noreturn void cpu_usermode(void *start, void *stack) {} 39 | 40 | // void mmu_enable() {} 41 | // void mmu_leave() {} 42 | // void mmu_create_uspace(mspace_t *mspace) {} 43 | // void mmu_destroy_uspace(mspace_t *mspace) {} 44 | // size_t mmu_read(size_t vaddr) {} 45 | // size_t mmu_resolve(size_t vaddr, size_t phys, int falgs) {} 46 | // int mmu_read_flags(size_t vaddr) {} 47 | // size_t mmu_drop(size_t vaddr) {} 48 | // bool mmu_dirty(size_t vaddr) {} 49 | // size_t mmu_protect(size_t vaddr, int falgs) {} 50 | 51 | 52 | // void *kmap(size_t len, void *ino, xoff_t off, int access) {} 53 | // void kunmap(void *ptr, size_t len) {} 54 | 55 | 56 | // blkmap_t *blk_open(inode_t *ino, size_t blocksize) { } 57 | 58 | -------------------------------------------------------------------------------- /src/core/scall_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 30 | 31 | void *sys_mmap(void *addr, size_t length, unsigned flags, int fd, size_t off) 32 | { 33 | inode_t *ino = NULL; 34 | if (fd >= 0) { 35 | // Lock fset 36 | file_t *file = resx_get(__current->fset, RESX_FILE, fd); 37 | if (file == NULL) { 38 | errno = EBADF; 39 | return (void *) -1; 40 | } 41 | ino = vfs_open_inode(file->ino); 42 | // UnLock fset 43 | } 44 | 45 | unsigned vma = flags & VM_RWX; 46 | if (ino != NULL) 47 | vma |= VMA_FILE; 48 | else if (flags & MAP_HEAP) 49 | vma |= VMA_HEAP; 50 | else if (flags & MAP_STACK) 51 | vma |= VMA_STACK; 52 | else 53 | vma |= VMA_ANON; 54 | if (flags & MAP_POPULATE && !(flags & MAP_SHARED)) 55 | vma |= VM_RESOLVE; 56 | 57 | // TODO - Transform flags ! 58 | void *ptr = vmsp_map(__current->vmsp, (size_t)addr, length, ino, off, vma); 59 | 60 | if (ino != NULL) 61 | vfs_close_inode(ino); 62 | return ptr != NULL ? ptr : (void *) -1; 63 | } 64 | 65 | long sys_munmap(void *addr, size_t length) 66 | { 67 | return vmsp_unmap(__current->vmsp, (size_t)addr, length); 68 | } 69 | 70 | 71 | long sys_mprotect(void *addr, size_t length, unsigned flags) 72 | { 73 | unsigned vma = flags & VM_RWX; 74 | // TODO - Transform flags ! 75 | return vmsp_protect(__current->vmsp, (size_t)addr, length, vma); 76 | } 77 | -------------------------------------------------------------------------------- /src/core/scall_sys.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 30 | 31 | static int copystr(bool access, const char *value, char *buf, size_t len) 32 | { 33 | if (!access || len < strlen(value) + 1) 34 | return -1; 35 | strncpy(buf, value, len); 36 | return 0; 37 | } 38 | 39 | long sys_ginfo(unsigned info, char *buf, size_t len) 40 | { 41 | if (vmsp_check(__current->vmsp, buf, len, VM_WR) != 0) 42 | return -1; 43 | 44 | switch (info) { 45 | case SNFO_ARCH: 46 | return copystr(true, __ARCH, buf, len); 47 | // case SNFO_GITH: 48 | // return copystr(true, _GITH_, buf, len); 49 | case SNFO_SNAME: 50 | return copystr(true, "Kora", buf, len); 51 | // case SNFO_VERSION: 52 | // return copystr(true, _MP_ " Kora core " _VTAG_ "-" _GITH_ " ("_DATE_")", buf, len); 53 | // case SNFO_RELEASE: 54 | // return copystr(true, _VTAG_"-"__ARCH, buf, len); 55 | case SNFO_OSNAME: 56 | return copystr(true, "KoraOS", buf, len); 57 | // case SNFO_USER: 58 | case SNFO_PWD: 59 | return vfs_readpath(__current->fsa, ".", __current->user, buf, len, false); 60 | // case SNFO_USERNAME: 61 | // case SNFO_USERMAIL: 62 | // case SNFO_HOSTNAME: 63 | // case SNFO_DOMAIN: 64 | default: 65 | errno = EINVAL; 66 | return -1; 67 | } 68 | } 69 | 70 | long sys_sinfo(unsigned info, const char *buf, size_t len) 71 | { 72 | if (vmsp_check(__current->vmsp, buf, len, VM_RD) != 0) 73 | return -1; 74 | 75 | switch (info) { 76 | // case SNFO_HOSTNAME: 77 | // case SNFO_DOMAIN: 78 | case SNFO_PWD: 79 | return vfs_chdir(__current->fsa, buf, NULL, false); 80 | default: 81 | errno = EINVAL; 82 | return -1; 83 | } 84 | } 85 | 86 | long sys_syslog(const char *log) 87 | { 88 | kprintf(KL_USR, "Task.%d] %s\n", __current->pid, log); 89 | return 0; 90 | } 91 | 92 | 93 | 94 | int sys_xtime(int name, xtime_t *ptime) 95 | { 96 | *ptime = xtime_read(name); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /src/mem/mcheck.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | 23 | /* - */ 24 | int vmsp_check(vmsp_t *vmsp, const void *ptr, size_t len, int flags) 25 | { 26 | splock_lock(&vmsp->lock); 27 | vma_t *vma = vmsp_find_area(vmsp, (size_t)ptr); 28 | if (vma == NULL) { 29 | splock_unlock(&vmsp->lock); 30 | errno = EINVAL; 31 | return -1; 32 | } 33 | 34 | size_t max = vma->node.value_ + vma->length - (size_t)ptr; 35 | if (max < len) { 36 | splock_unlock(&vmsp->lock); 37 | errno = EINVAL; 38 | return -1; 39 | } 40 | 41 | if ((flags & VM_WR) && !(vma->flags & VM_WR)) { 42 | splock_unlock(&vmsp->lock); 43 | errno = EPERM; 44 | return -1; 45 | } 46 | 47 | splock_unlock(&vmsp->lock); 48 | return 0; 49 | } 50 | 51 | /* - */ 52 | int vmsp_check_str(vmsp_t *vmsp, const char *str, size_t max) 53 | { 54 | splock_lock(&vmsp->lock); 55 | vma_t *vma = vmsp_find_area(vmsp, (size_t)str); 56 | if (vma == NULL) { 57 | splock_unlock(&vmsp->lock); 58 | errno = EINVAL; 59 | return -1; 60 | } 61 | 62 | max = MIN(max, vma->node.value_ + vma->length - (size_t)str); 63 | splock_unlock(&vmsp->lock); 64 | 65 | if (strnlen(str, max) >= max) { 66 | errno = EINVAL; 67 | return -1; 68 | } 69 | 70 | return 0; 71 | } 72 | 73 | /* - */ 74 | int vmsp_check_strarray(vmsp_t *vmsp, const char **str) 75 | { 76 | splock_lock(&vmsp->lock); 77 | vma_t *vma = vmsp_find_area(vmsp, (size_t)str); 78 | if (vma == NULL) { 79 | splock_unlock(&vmsp->lock); 80 | errno = EINVAL; 81 | return -1; 82 | } 83 | 84 | size_t max = vma->node.value_ + vma->length - (size_t)str; 85 | splock_unlock(&vmsp->lock); 86 | 87 | size_t len = sizeof(char *); 88 | for (int i = 0; len < max; ++i, len += sizeof(char*)) { 89 | if (*str == NULL) 90 | break; 91 | if (vmsp_check_str(vmsp, *str, 4096) != 0) 92 | return -1; 93 | } 94 | 95 | return len < max ? 0 : -1; 96 | } 97 | -------------------------------------------------------------------------------- /src/mem/vma_dlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | size_t vma_fetch_dlib(vmsp_t *vmsp, vma_t *vma, xoff_t offset, bool blocking) 12 | { 13 | if (!blocking) 14 | return dlib_fetch_page(vma->lib, offset, false); 15 | splock_unlock(&vmsp->lock); 16 | size_t page = dlib_fetch_page(vma->lib, offset, true); 17 | splock_lock(&vmsp->lock); 18 | return page; 19 | } 20 | 21 | void vma_release_dlib(vmsp_t *vmsp, vma_t *vma, xoff_t offset, size_t page) 22 | { 23 | dlib_release_page(vma->lib, offset, page); 24 | } 25 | 26 | void vma_resolve_dlib(vmsp_t *vmsp, vma_t *vma, size_t vaddr, size_t page) 27 | { 28 | vmsp->s_size++; 29 | int t = mmu_resolve(vaddr, page, VM_RD); 30 | vmsp->t_size += t; 31 | } 32 | 33 | int vma_shared_dlib(vmsp_t *vmsp, vma_t *vma, size_t address, size_t page) 34 | { 35 | xoff_t offset = vma->offset + (xoff_t)(address - vma->node.value_); 36 | size_t old = dlib_fetch_page(vma->lib, offset, false); 37 | if (old != 0) 38 | dlib_release_page(vma->lib, offset, old); 39 | if (old != 0 && old == page) 40 | return VPG_BACKEDUP; // This is a backedup page 41 | if (!page_shared(vmsp->share, page, 0)) 42 | return VPG_SHARED; // This is a shared page 43 | return VPG_PRIVATE; // This is a private page 44 | } 45 | 46 | void vma_unmap_dlib(vmsp_t *vmsp, vma_t *vma, size_t address) 47 | { 48 | size_t pg = mmu_drop(address); 49 | if (pg != 0) { 50 | int status = vma_shared_dlib(vmsp, vma, address, pg); 51 | if (status == VPG_PRIVATE) { 52 | vmsp->p_size--; 53 | page_release(pg); 54 | } else if (status == VPG_SHARED) { 55 | vmsp->s_size--; 56 | if (page_shared(vmsp->share, pg, -1)) 57 | page_release(pg); 58 | } else { 59 | xoff_t offset = vma->offset + (xoff_t)(address - vma->node.value_); 60 | vmsp->s_size--; 61 | dlib_release_page(vma->lib, offset, pg); 62 | } 63 | } 64 | } 65 | 66 | 67 | int vma_protect_dlib(vmsp_t *vmsp, vma_t *vma, int flags) 68 | { 69 | if (vma->flags != 0) 70 | return -1; 71 | if (flags != VM_RX && flags != VM_RW && flags != VM_RD) 72 | return -1; 73 | vma->flags = flags | VMA_COW | VMA_BACKEDUP; 74 | return 0; 75 | } 76 | 77 | void vma_split_dlib(vma_t *va1, vma_t *va2) 78 | { 79 | va2->flags = va1->flags; 80 | va2->lib = va1->lib; 81 | va2->offset = va1->offset + va1->length; 82 | } 83 | 84 | void vma_clone_dlib(vmsp_t *vmsp1, vmsp_t *vmsp2, vma_t *va1, vma_t *va2) 85 | { 86 | va1->lib = va2->lib; 87 | va1->offset = va2->offset; 88 | } 89 | 90 | char *vma_print_dlib(vma_t *vma, char *buf, size_t len) 91 | { 92 | char tmp[32]; 93 | snprintf(buf, len, "<%s>", dlib_name(vma->lib, tmp, 32)); 94 | return buf; 95 | } 96 | 97 | 98 | vma_ops_t vma_ops_dlib = { 99 | .fetch = vma_fetch_dlib, 100 | .release = vma_release_dlib, 101 | .resolve = vma_resolve_dlib, 102 | .shared = vma_shared_dlib, 103 | .unmap = vma_unmap_dlib, 104 | .protect = vma_protect_dlib, 105 | .split = vma_split_dlib, 106 | .clone = vma_clone_dlib, 107 | .print = vma_print_dlib, 108 | 109 | }; 110 | -------------------------------------------------------------------------------- /src/mem/vma_misc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | size_t vma_fetch_blank(vmsp_t *vmsp, vma_t *vma, xoff_t offset, bool blocking); 12 | void vma_release_blank(vmsp_t *vmsp, vma_t *vma, xoff_t offset, size_t page); 13 | void vma_resolve_blank(vmsp_t *vmsp, vma_t *vma, size_t vaddr, size_t page); 14 | void vma_unmap_blank(vmsp_t *vmsp, vma_t *vma, size_t address); 15 | 16 | 17 | char *vma_print_pipe(vma_t *vma, char *buf, size_t len) 18 | { 19 | snprintf(buf, len, "[pipe.#%d]", -1); // vma->tsk ? vma->tsk->pid : -1); 20 | return buf; 21 | } 22 | 23 | vma_ops_t vma_ops_pipe = { 24 | .fetch = vma_fetch_blank, 25 | .release = vma_release_blank, 26 | .resolve = vma_resolve_blank, 27 | .unmap = vma_unmap_blank, 28 | .print = vma_print_pipe, 29 | }; 30 | 31 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 32 | 33 | size_t vma_fetch_phys(vmsp_t *vmsp, vma_t *vma, xoff_t offset, bool blocking) 34 | { 35 | return vma->offset == 0 ? page_new() : (size_t)offset; 36 | } 37 | 38 | void vma_resolve_phys(vmsp_t *vmsp, vma_t *vma, size_t vaddr, size_t page) 39 | { 40 | int t = mmu_resolve(vaddr, page, vma->flags & (VM_UNCACHABLE | VM_RW)); 41 | vmsp->t_size += t; 42 | } 43 | 44 | void vma_unmap_phys(vmsp_t *vmsp, vma_t *vma, size_t address) 45 | { 46 | mmu_drop(address); 47 | } 48 | 49 | int vma_protect_phys(vmsp_t *vmsp, vma_t *vma, int flags) 50 | { 51 | size_t length = vma->length; 52 | size_t address = vma->node.value_; 53 | vma->flags = flags & (VM_RW | VM_UNCACHABLE); 54 | while (length) { 55 | mmu_protect(address, vma->flags & (VM_UNCACHABLE | VM_RW)); 56 | length -= PAGE_SIZE; 57 | address += PAGE_SIZE; 58 | } 59 | return 0; 60 | } 61 | 62 | char *vma_print_phys(vma_t *vma, char *buf, size_t len) 63 | { 64 | snprintf(buf, len, "phys=%p", (void *)(size_t)vma->offset); 65 | return buf; 66 | } 67 | 68 | vma_ops_t vma_ops_phys = { 69 | .fetch = vma_fetch_phys, 70 | .resolve = vma_resolve_phys, 71 | .unmap = vma_unmap_phys, 72 | .print = vma_print_phys, 73 | 74 | }; 75 | -------------------------------------------------------------------------------- /src/stdc/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _KORA_ALLOCATOR_H 21 | #define _KORA_ALLOCATOR_H 1 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define HEAP_PARANO (1 << 0) 29 | #define HEAP_CHECK (1 << 1) 30 | #define HEAP_CORRUPTED (1 << 2) 31 | #define HEAP_ARENA (1 << 3) 32 | #define HEAP_MAPPED (1 << 4) 33 | #define HEAP_OPTIONS (HEAP_PARANO | HEAP_CHECK) 34 | 35 | typedef struct heap_arena heap_arena_t; 36 | typedef struct heap_chunk heap_chunk_t; 37 | 38 | struct heap_arena { 39 | size_t address_; 40 | size_t length_; 41 | size_t used_; 42 | size_t max_chunk; 43 | int flags_; 44 | splock_t lock_; 45 | heap_chunk_t *free_; 46 | llnode_t node_; 47 | }; 48 | 49 | 50 | /* Initialize a memory area to serve as allocator arena */ 51 | void setup_arena(heap_arena_t *arena, size_t address, size_t length, 52 | size_t max, int option); 53 | /* Allocate a block of memory into an arena */ 54 | void *malloc_r(heap_arena_t *arena, size_t size); 55 | /* Release a block of memory previously allocated on the same arena */ 56 | void free_r(heap_arena_t *arena, void *ptr); 57 | 58 | /* Dynamicaly allocate a block of memory on the address space */ 59 | void *_PRT(malloc)(size_t size); 60 | /* Dynamicaly allocate a page align memory block */ 61 | void *_PRT(valloc)(size_t size); 62 | /* Dynamicaly allocate a page align memory block */ 63 | void *_PRT(calloc)(size_t nmemb, size_t size); 64 | /* Re-allocate a block memory */ 65 | void *_PRT(realloc)(void *ptr, size_t size); 66 | /* Release a block of memory previously allocated dynamicaly */ 67 | void _PRT(free)(void *ptr); 68 | /* */ 69 | void setup_allocator(void *address, size_t length); 70 | void sweep_allocator(); 71 | 72 | 73 | 74 | #endif /* _KORA_ALLOCATOR_H */ 75 | -------------------------------------------------------------------------------- /src/stdc/bits.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | 24 | void bitsclr(uint8_t *ptr, int start, int count) 25 | { 26 | int i = start / 8; 27 | int j = start % 8; 28 | while (count > 0 && j != 0) { 29 | ptr[i] &= ~(1 << j); 30 | j = (j + 1) % 8; 31 | count--; 32 | } 33 | i = ALIGN_UP(start, 8) / 8; 34 | while (count > 8) { 35 | ptr[i] = 0; 36 | i++; 37 | count -= 8; 38 | } 39 | j = 0; 40 | while (count > 0) { 41 | ptr[i] &= ~(1 << j); 42 | j++; 43 | count--; 44 | } 45 | } 46 | 47 | void bitsset(uint8_t *ptr, int start, int count) 48 | { 49 | int i = start / 8; 50 | int j = start % 8; 51 | while (count > 0 && j != 0) { 52 | ptr[i] |= (1 << j); 53 | j = (j + 1) % 8; 54 | count--; 55 | } 56 | i = ALIGN_UP(start, 8) / 8; 57 | while (count > 8) { 58 | ptr[i] = ~0; 59 | i++; 60 | count -= 8; 61 | } 62 | j = 0; 63 | while (count > 0) { 64 | ptr[i] |= (1 << j); 65 | j++; 66 | count--; 67 | } 68 | } 69 | 70 | int bitschrz(uint8_t *ptr, int len) 71 | { 72 | int i = 0, j = 0; 73 | while (i < len / 8 && ptr[i] == 0xFF) 74 | i++; 75 | if (i >= len / 8) 76 | return -1; 77 | uint8_t by = ptr[i]; 78 | while (by & 1) { 79 | j++; 80 | by = by >> 1; 81 | } 82 | return i * 8 + j; 83 | } 84 | 85 | bool bitstest(uint8_t *ptr, int start, int count) 86 | { 87 | bool test = true; 88 | int i = start / 8; 89 | int j = start % 8; 90 | while (count > 0 && j != 0) { 91 | ptr[i] &= ~(1 << j); 92 | j = (j + 1) % 8; 93 | count--; 94 | } 95 | i = ALIGN_UP(start, 8) / 8; 96 | while (count > 8) { 97 | if (ptr[i] == 0) 98 | test = false; 99 | i++; 100 | count -= 8; 101 | } 102 | j = 0; 103 | while (count > 0) { 104 | if ((ptr[i] & (1 << j)) == 0) 105 | test = false; 106 | j++; 107 | count--; 108 | } 109 | return test; 110 | } -------------------------------------------------------------------------------- /src/stdc/blkmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | 23 | static void *blk_map_(blkmap_t *map, size_t no, int rights) 24 | { 25 | xoff_t roff = no * map->block; 26 | xoff_t moff = ALIGN_DW(roff, map->msize); 27 | if (map->ptr == NULL || map->off != moff || map->rights != rights) { 28 | if (map->ptr != NULL) 29 | kunmap(map->ptr, map->msize); 30 | map->rights = rights; 31 | map->off = moff; 32 | map->ptr = kmap(map->msize, map->ino, map->off, rights); 33 | } 34 | return ADDR_OFF(map->ptr, roff - moff); 35 | } 36 | 37 | 38 | static blkmap_t *blk_clone_(blkmap_t *map) 39 | { 40 | blkmap_t *map2 = kalloc(sizeof(blkmap_t)); 41 | map2->ino = vfs_open_inode(map->ino); 42 | map2->block = map->block; 43 | map2->msize = map->msize; 44 | map2->map = map->map; 45 | map2->clone = map->clone; 46 | map2->close = map->close; 47 | return map2; 48 | } 49 | 50 | static void blk_close_(blkmap_t *map) 51 | { 52 | vfs_close_inode(map->ino); 53 | if (map->ptr != NULL) 54 | kunmap(map->ptr, map->msize); 55 | kfree(map); 56 | } 57 | 58 | blkmap_t *blk_open(inode_t *ino, size_t blocksize) 59 | { 60 | if (!POW2(blocksize)) 61 | return NULL; 62 | blkmap_t *map = kalloc(sizeof(blkmap_t)); 63 | map->ino = vfs_open_inode(ino); 64 | map->block = blocksize; 65 | map->msize = ALIGN_UP(blocksize, PAGE_SIZE); 66 | map->map = blk_map_; 67 | map->clone = blk_clone_; 68 | map->close = blk_close_; 69 | return map; 70 | } 71 | 72 | 73 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 74 | -------------------------------------------------------------------------------- /src/stdc/format_scanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | /* All of those methods are bind over vfscanf 29 | which is implemented in another file. */ 30 | int vfscanf(FILE *f, const char *format, va_list ap); 31 | 32 | /* Read from a string streaming */ 33 | static int _sread(FILE *fp, char *buf, size_t length) 34 | { 35 | size_t lg = MIN(length, (size_t)(fp->rbf_.end_ - fp->rbf_.pos_)); 36 | memcpy(buf, fp->rbf_.pos_, lg); 37 | fp->rbf_.pos_ += lg; 38 | return (length > lg) ? EOF : (int)lg; 39 | } 40 | 41 | 42 | 43 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 44 | #ifndef __NO_SYSCALL 45 | /* Read and parse standard input */ 46 | int scanf(const char *format, ...) 47 | { 48 | int ret; 49 | va_list ap; 50 | va_start(ap, format); 51 | ret = vfscanf(stdin, format, ap); 52 | va_end(ap); 53 | return ret; 54 | } 55 | 56 | 57 | /* Read and parse standard input */ 58 | int vscanf(const char *format, va_list ap) 59 | { 60 | return vfscanf(stdin, format, ap); 61 | } 62 | 63 | 64 | /* Read and parse an open file */ 65 | int fscanf(FILE *f, const char *format, ...) 66 | { 67 | int ret; 68 | va_list ap; 69 | va_start(ap, format); 70 | ret = vfscanf(f, format, ap); 71 | va_end(ap); 72 | return ret; 73 | } 74 | 75 | #endif 76 | 77 | /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 78 | 79 | /* Read and parse a string */ 80 | int sscanf(const char *str, const char *format, ...) 81 | { 82 | int ret; 83 | va_list ap; 84 | FILE fp; 85 | 86 | fp.rbf_.pos_ = (char *)str; 87 | fp.rbf_.end_ = (char *)~0; 88 | fp.read = _sread; 89 | fp.lock_ = -1; 90 | 91 | va_start(ap, format); 92 | ret = vfscanf(&fp, format, ap); 93 | va_end(ap); 94 | return ret; 95 | } 96 | 97 | 98 | /* Read and parse a string */ 99 | int vsscanf(const char *str, const char *format, va_list ap) 100 | { 101 | FILE fp; 102 | fp.rbf_.pos_ = (char *)str; 103 | fp.rbf_.end_ = (char *)~0; 104 | fp.read = _sread; 105 | fp.lock_ = -1; 106 | return vfscanf(&fp, format, ap); 107 | } 108 | 109 | // EXPORT_SYMBOL(sscanf, 0); 110 | // EXPORT_SYMBOL(vsscanf, 0); 111 | -------------------------------------------------------------------------------- /src/stdc/format_vfscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | int vfscanf(FILE *f, const char *format, va_list ap) 28 | { 29 | return -1; 30 | } 31 | -------------------------------------------------------------------------------- /src/stdc/lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | 22 | void __lock(atomic_int *lock) 23 | { 24 | if (*lock < 0) 25 | return; 26 | return; 27 | } 28 | 29 | void __unlock(atomic_int *lock) 30 | { 31 | if (*lock < 0) 32 | return; 33 | return; 34 | } 35 | -------------------------------------------------------------------------------- /src/stdc/mbstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | 23 | int mbtowc(wchar_t *wc, const char *str, size_t len) 24 | { 25 | wchar_t dummy; 26 | errno = 0; 27 | if (str == NULL) 28 | return 0; 29 | if (wc == NULL) 30 | wc = &dummy; 31 | 32 | if (len < 1) { 33 | errno = EILSEQ; 34 | return -1; 35 | } 36 | 37 | if (*str >= 0) 38 | /* Returns 0 if '\0' or 1 in other cases */ 39 | return !!(*wc = *str); 40 | 41 | 42 | *wc = 1; 43 | return -1; 44 | } 45 | 46 | /* 47 | size_t mbstowcs (wchar_t *ws, const char **str, size_t wn, mbstate_t *st) 48 | { 49 | return 0; 50 | } 51 | 52 | size_t mbstowcs (wchar_t *ws, const char *str, size_t wn) 53 | { 54 | return mbsrtowcs(ws, &s, wn, 0); 55 | } 56 | */ 57 | 58 | int mblen(const char *str, size_t len) 59 | { 60 | return mbtowc(0, str, len); 61 | } 62 | -------------------------------------------------------------------------------- /src/stdc/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | 22 | static unsigned int __seed; 23 | 24 | #define RAND_MAX 0x7FFF 25 | 26 | /* Sets the seed for a new sequence of pseudo-random integers. */ 27 | void srand(unsigned int seed) 28 | { 29 | __seed = seed; 30 | } 31 | 32 | /* Pseudo-random generator based on Minimal Standard by 33 | Lewis, Goodman, and Miller in 1969: I[j+1] = a*I[j] (mod m) */ 34 | int rand_r(unsigned int *seed) 35 | { 36 | long k; 37 | long s = (long)(*seed); 38 | if (s == 0) 39 | s = 0x12345987; 40 | k = s / 127773; 41 | s = 16807 * (s - k * 127773) - 2836 * k; 42 | if (s < 0) 43 | s += 2147483647; 44 | (*seed) = (unsigned int)s; 45 | return (int)(s & RAND_MAX); 46 | } 47 | 48 | /* Pseudo-random generator */ 49 | int rand(void) 50 | { 51 | return rand_r(&__seed); 52 | } 53 | -------------------------------------------------------------------------------- /src/tasks/dlib.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/src/tasks/dlib.c -------------------------------------------------------------------------------- /src/vfs/sock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | 23 | // 24 | //typedef struct socket socket_t; 25 | // 26 | // 27 | //int socket_read(inode_t *ino, char *buf, size_t len, xoff_t off, int flags) 28 | //{ 29 | // return -1; 30 | //} 31 | // 32 | //int socket_write(inode_t *ino, const char *buf, size_t len, xoff_t off, int flags) 33 | //{ 34 | // return -1; 35 | //} 36 | // 37 | //void socket_destroy(inode_t *ino) 38 | //{ 39 | //} 40 | // 41 | // 42 | ///* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ 43 | // 44 | //fl_ops_t socket_ops = { 45 | // .read = socket_read, 46 | // .write = socket_write, 47 | // .destroy = socket_destroy, 48 | //}; 49 | // 50 | //socket_t *socket_create() 51 | //{ 52 | // return NULL; 53 | //} 54 | -------------------------------------------------------------------------------- /tests/cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #ifndef _SRC_CLI_H 21 | #define _SRC_CLI_H 1 22 | 23 | #include 24 | #include 25 | 26 | #define ARGS_MAX 6 27 | 28 | typedef struct cli_cmd cli_cmd_t; 29 | typedef struct cli_cfg cli_cfg_t; 30 | 31 | struct cli_cmd 32 | { 33 | const char *name; 34 | const char *summary; 35 | char params[ARGS_MAX]; 36 | int (*call)(void *ctx, size_t *param); 37 | int min_arg; 38 | }; 39 | 40 | struct cli_cfg 41 | { 42 | void *context; 43 | bool is_interactive; 44 | }; 45 | 46 | #define CLI_END_OF_COMMANDS { NULL, NULL, { 0, 0, 0, 0, 0, 0 }, NULL, 0 } 47 | 48 | #define ARG_STR 1 49 | #define ARG_INT 2 50 | 51 | extern cli_cmd_t __commands[]; 52 | 53 | int cli_commands(FILE *fp, void *ctx, bool reecho); 54 | int cli_main(int argc, char **argv, void *context, void(*initialize)(), void(*teardown)()); 55 | 56 | size_t cli_read_size(char *str); 57 | 58 | void cli_store(char *name, void *obj, int type); 59 | void *cli_fetch(char *name, int type); 60 | void *cli_remove(char *name, int type); 61 | 62 | int cli_msg(int ret, const char *clr, const char *msg, ...); 63 | 64 | #define cli_info(...) cli_msg(0, "\033[34m", __VA_ARGS__) 65 | #define cli_warn(...) cli_msg(0, "\033[33m", __VA_ARGS__) 66 | #define cli_error(...) cli_msg(-1, "\033[31m", __VA_ARGS__) 67 | 68 | #endif /* _SRC_CLI_H */ 69 | -------------------------------------------------------------------------------- /tests/fs_ext2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | 4 | IMG_RM hdd.img 5 | ERROR ON 6 | 7 | IMG_CREATE hdd.img 24M 8 | 9 | IMG_OPEN hdd.img hdd 10 | FORMAT ext2 /hdd 11 | MOUNT /hdd ext2 /mnt/ldk 12 | CHROOT /mnt/ldk 13 | MOUNT - devfs /dev 14 | 15 | # --------------------------------------------------------------------------- 16 | 17 | LS . 18 | INCLUDE fs_mkdir.sh 19 | INCLUDE fs_rmdir.sh 20 | INCLUDE fs_open.sh 21 | INCLUDE fs_unlink.sh 22 | INCLUDE fs_symlink.sh 23 | INCLUDE fs_link.sh 24 | INCLUDE fs_chmod.sh 25 | # INCLUDE fs_chown.sh 26 | INCLUDE fs_truncate.sh 27 | INCLUDE fs_rename.sh 28 | INCLUDE fs_utimes.sh 29 | INCLUDE fs_readwrite.sh 30 | RESTART 31 | 32 | # --------------------------------------------------------------------------- 33 | 34 | IMG_RM hdd.img # Format should be enough 35 | IMG_CREATE hdd.img 24M 36 | IMG_OPEN hdd.img hdd 37 | FORMAT ext2 /hdd 38 | MOUNT /hdd ext2 /mnt/ldk 39 | CHROOT /mnt/ldk 40 | MOUNT - devfs /dev 41 | 42 | INCLUDE fs_persist_wr.sh # Create large files hierarchy 43 | RESTART 44 | 45 | # --------------------------------------------------------------------------- 46 | IMG_OPEN hdd.img hdd 47 | MOUNT /hdd ext2 /mnt/ldk 48 | CHROOT /mnt/ldk 49 | MOUNT - devfs /dev 50 | 51 | # INCLUDE fs_persist_rd.sh 52 | 53 | # --------------------------------------------------------------------------- 54 | # --------------------------------------------------------------------------- 55 | # Kah_Zig_Sto_Blaz_Dru_Goz_Lrz_Poo_Tbz_Gnee_Bnz_Glap 56 | # Kah Zig Sto Blaz Dru Goz Lrz Poo Tbz Gnee Bnz Glap 57 | -------------------------------------------------------------------------------- /tests/fs_fat12.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | 4 | IMG_RM fpy.img 5 | ERROR ON 6 | 7 | IMG_CREATE fpy.img 1440K 8 | IMG_OPEN fpy.img fpy 9 | FORMAT fat12 /fpy 10 | MOUNT /fpy fat12 /mnt/lfp '-o fat12' 11 | CHROOT /mnt/lfp 12 | MOUNT - devfs /dev 13 | 14 | # --------------------------------------------------------------------------- 15 | 16 | INCLUDE fs_mkdir.sh 17 | INCLUDE fs_rmdir.sh 18 | INCLUDE fs_open.sh 19 | INCLUDE fs_unlink.sh 20 | # INCLUDE fs_symlink.sh 21 | # INCLUDE fs_link.sh 22 | 23 | -------------------------------------------------------------------------------- /tests/fs_isofs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | 4 | ERROR ON 5 | 6 | IMG_OPEN dsk.iso cdrom 7 | MOUNT /cdrom iso /mnt/ldk 8 | CHROOT /mnt/ldk 9 | MOUNT - devfs /dev 10 | INCLUDE fs_persist_rd.sh 11 | -------------------------------------------------------------------------------- /tests/fs_main.sh: -------------------------------------------------------------------------------- 1 | 2 | IMG_RM vA.vhd 3 | IMG_RM vB.vhd 4 | IMG_RM vC.vhd 5 | IMG_RM vD.vhd 6 | 7 | ERROR ON 8 | 9 | 10 | # ---------------------------------------------------------------------------- 11 | # Pipe -- 12 | PIPE @pr @pw 13 | 14 | READ @bf0 random 64 15 | WRITE @bf0 @pw 64 16 | READ @bf1 @pr 64 17 | 18 | READ @bf0 random 2048 19 | WRITE @bf0 @pw 2048 20 | WRITE @bf0 @pw 2048 21 | WRITE @bf0 @pw 2048 22 | WRITE @bf0 @pw 2048 23 | READ @bf1 @pr 8196 24 | 25 | CLOSE @pw 26 | CLOSE @pr 27 | 28 | RMBUF @bf0 29 | RMBUF @bf1 30 | 31 | 32 | # ---------------------------------------------------------------------------- 33 | # Block device 34 | IMG_CREATE vA.vhd 1M 35 | IMG_CREATE vB.vhd 4M 36 | IMG_CREATE vC.vhd 4M 37 | IMG_CREATE vD.vhd 16M 38 | 39 | LS disk/by-uuid 0 40 | IMG_OPEN vA.vhd vA 41 | LS disk/by-uuid 1 42 | 43 | IMG_OPEN vB.vhd vB 44 | IMG_OPEN vC.vhd vC 45 | IMG_OPEN vD.vhd vD 46 | 47 | # ---------------------------------------------------------------------------- 48 | # Mount & unmount 49 | TAR dsk.tar dsk 50 | CHROOT /mnt/dsk 51 | MOUNT - devfs /dev 52 | UMOUNT /dev 53 | 54 | 55 | 56 | # ---------------------------------------------------------------------------- 57 | # Zombie case 58 | # MOUNT - devfs /dev 59 | # FORMAT ext2 /dev/vB 60 | # MOUNT /dev/vB ext2 /dev/mnt/dkb 61 | # CD /dev/mnt/dkb 62 | # PWD 63 | 64 | # MKDIR Poo 65 | 66 | # OPEN Poo/Foo RDONLY,CREATE,EXCL @fl 67 | # UNLINK Poo/Foo 68 | # CLOSE @fl 69 | 70 | # OPEN Poo/Bar RDONLY,CREATE,EXCL @fl 71 | # UNLINK Poo/Bar 72 | # RMDIR Poo 73 | # CLOSE @fl 74 | 75 | 76 | # CHROOT /dev 77 | # UMOUNT /mnt/ldk/dev 78 | # UMOUNT /mnt/ldk 79 | # RESTART 80 | # IMG_OPEN hdd.img hdd 81 | # MOUNT /hdd ext2 /mnt/ldk 82 | # CHROOT /mnt/ldk 83 | # MOUNT - devfs /dev 84 | # INCLUDE fs_persist2.sh # Read large files hierarchy 85 | # INCLUDE fs_rofs.sh 86 | 87 | # INCLUDE fs_paths.sh 88 | 89 | 90 | # # ---------------------------------------------------------------------------- 91 | # ERROR OFF 92 | 93 | # IMG_RM vA.vhd 94 | # IMG_RM vB.vhd 95 | # IMG_RM vC.vhd 96 | # IMG_RM vD.vhd 97 | -------------------------------------------------------------------------------- /tests/fs_paths.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | 4 | # Create folders and read path 5 | 6 | # Create symlink, read symlink 7 | 8 | # Search path with '.' and '..' 9 | 10 | # Test readir (count elements) 11 | 12 | # Test open (create / exclusif / open-only...) 13 | 14 | 15 | # --------------------------------------------------------------------------- 16 | 17 | # # 18 | # LS /dev/Foo 19 | 20 | 21 | # PUSHVFS open 22 | # CHDIR /dev/zero 23 | 24 | # POPVFS 25 | 26 | # PUSHVFS close 27 | # POPVFS 28 | 29 | 30 | # IMG_CLOSE hdd.img # vfs_rmdev 31 | 32 | 33 | # FORMAT glufs /dev/hdd # Unknown FS 34 | 35 | 36 | # STAT Kah/Sto/Blaz 37 | # STAT Kah/Zig/../Sto/./Blaz 38 | # STAT Kah/Zig/../Sto/Blaz 39 | # STAT Kah/Sto/./Blaz 40 | 41 | # SYMLINK Kah Sto 42 | # READLINK Sto Kah 43 | 44 | 45 | # CHDIR Foo/Bar 46 | # PWD L 47 | # PWD P 48 | 49 | 50 | # PIPE @f4 51 | # WRITE @f4 'Hello' 52 | # READ @f4 4 'Hell' 53 | # # RESIZE !? 54 | # # Several consummer (AIO) !? 55 | # # Several producer !? 56 | 57 | # CREATE Zig 58 | # OPEN Zig @f5 59 | # WRITE @f5 'Hello World' 60 | 61 | 62 | 63 | # SCAVENGE 64 | 65 | # IOCTL 66 | 67 | # MKDEV (>32 entry) 68 | # LS /dev/disk 69 | 70 | 71 | 72 | 73 | # WRITE /dev/null 74 | # READ /dev/null NOBLOCK # EWOULDBLOCK 75 | 76 | # # Entropy !? 77 | 78 | 79 | # OPEN Kah/Zig @f4 80 | # UNLINK Zig 81 | # RMDIR Kah 82 | # CLOSE @f4 83 | 84 | # CHDIR Kah/Zig 85 | # RMDIR Zig 86 | # RMDIR Kah 87 | # CHDIR .. 88 | 89 | 90 | # RMDIR /mnt/ldk # EBUZY 91 | 92 | 93 | # OPEN ** 94 | 95 | 96 | # MOUNT .. 97 | # UMOUNT .. 98 | 99 | 100 | 101 | # CHOWN 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /tests/fs_persist_rd.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | 4 | LS . 5 | LS ./Kah 6 | PWD 7 | 8 | # Check folder content 9 | STAT Kah/Bar.txt REG 0644 10 | SIZE Kah/Bar.txt 18309 11 | 12 | STAT Kah/Lorem.txt REG 0644 13 | SIZE Kah/Lorem.txt 18309 14 | 15 | STAT Kah/Foo.blank REG 0644 16 | SIZE Kah/Foo.blank 0 17 | 18 | STAT Kah/Bnz DIR 0755 19 | STAT Kah/Lrz DIR 0755 20 | STAT Kah/Sto DIR 0755 21 | STAT Kah/Zig DIR 0755 22 | 23 | 24 | # Folder Kah/Bnz/ contains files named sample_xx.txt 25 | 26 | 27 | # Path search 28 | STAT Kah/Lrz/Foo.txt REG 0644 29 | SIZE Kah/Lrz/Foo.txt 18309 30 | STAT Kah/Lrz/../Bar.txt REG 0644 31 | SIZE Kah/./Bar.txt 18309 32 | ERROR ENOENT 33 | STAT Kah/Bar/Foo.txt 34 | ERROR ON 35 | LS Kah/Lrz 1 36 | 37 | 38 | # Read 39 | CRC32 Kah/Bar.txt 3c8fb882 40 | CRC32 Kah/Lorem.txt 3c8fb882 41 | CRC32 Kah/Lrz/Foo.txt 3c8fb882 42 | 43 | -------------------------------------------------------------------------------- /tests/fs_persist_rd2.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | 4 | LS . 5 | LS ./Kah 6 | PWD 7 | 8 | # Check folder content 9 | STAT Kah/Bar.txt REG 0644 10 | SIZE Kah/Bar.txt 18309 11 | 12 | STAT Kah/Lorem.txt REG 0444 13 | SIZE Kah/Lorem.txt 18309 14 | 15 | STAT Kah/Foo.blank REG 0640 16 | SIZE Kah/Foo.blank 0 17 | 18 | STAT Kah/Bnz DIR 0755 19 | STAT Kah/Lrz DIR 0755 20 | STAT Kah/Sto DIR 0755 21 | STAT Kah/Zig DIR 0755 22 | 23 | 24 | # Folder Kah/Bnz/ contains files named sample_xx.txt 25 | 26 | 27 | # Path search 28 | STAT Kah/Lrz/Foo.txt REG 0644 29 | SIZE Kah/Lrz/Foo.txt 18309 30 | STAT Kah/Lrz/../Bar.txt REG 0644 31 | SIZE Kah/./Bar.txt 18309 32 | ERROR ENOENT 33 | STAT Kah/Bar/Foo.txt 34 | ERROR ON 35 | LS Kah/Lrz 1 36 | 37 | 38 | # Read 39 | CRC32 Kah/Bar.txt 3c8fb882 40 | CRC32 Kah/Lorem.txt 3c8fb882 41 | CRC32 Kah/Lrz/Foo.txt 3c8fb882 42 | 43 | -------------------------------------------------------------------------------- /tests/fs_readwrite.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | ERROR ON 4 | 5 | # --------------------------------------------------------------------------- 6 | # Write a dummy file, and read checksum 7 | MKDIR Foo 8 | 9 | IMG_OPEN lorem_sm.txt lorem_sm 10 | DD /dev/lorem_sm Foo/Bar 32 11 | CRC32 Foo/Bar 3c8fb882 12 | UNLINK Foo/Bar 13 | 14 | IMG_OPEN lorem_md.txt lorem_md 15 | DD /dev/lorem_md Foo/Gap 32 16 | CRC32 Foo/Gap b69a152f 17 | UNLINK Foo/Gap 18 | 19 | # DD /dev/lorem_md Foo/Bar 32 5581184 20 | # CRC32 Foo/Bar 21 | # UNLINK Foo/Bar 22 | 23 | RMDIR Foo 24 | 25 | # --------------------------------------------------------------------------- 26 | # Create a file with a hole, check size on disk, read is correct 27 | 28 | # --------------------------------------------------------------------------- 29 | # Write will extend the file as needed 30 | 31 | # --------------------------------------------------------------------------- 32 | # Write will update mtime but not ctime 33 | 34 | # --------------------------------------------------------------------------- 35 | # Read will update atime 36 | 37 | # --------------------------------------------------------------------------- 38 | # Create a really large file, check space left and integrity 39 | 40 | # --------------------------------------------------------------------------- 41 | # Create many file, then extend file to create partition, verify checksum 42 | 43 | # --------------------------------------------------------------------------- 44 | # Test randomize writing 45 | 46 | # --------------------------------------------------------------------------- 47 | # Test randomize reading 48 | 49 | 50 | -------------------------------------------------------------------------------- /tests/fs_tarfs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | 4 | ERROR ON 5 | 6 | TAR dsk.tar dsk 7 | CHROOT /mnt/dsk 8 | MOUNT - devfs /dev 9 | INCLUDE fs_persist_rd2.sh 10 | -------------------------------------------------------------------------------- /tests/fs_utimes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env cli_fs 2 | # --------------------------------------------------------------------------- 3 | # Highly inspirated from `pjdfstest` testing program 4 | # --------------------------------------------------------------------------- 5 | # License for all regression tests available with pjdfstest: 6 | # 7 | # Copyright (c) 2006-2012 Pawel Jakub Dawidek 8 | # All rights reserved. 9 | # 10 | # Redistribution and use in source and binary forms, with or without 11 | # modification, are permitted provided that the following conditions 12 | # are met: 13 | # 1. Redistributions of source code must retain the above copyright 14 | # notice, this list of conditions and the following disclaimer. 15 | # 2. Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 20 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | # SUCH DAMAGE. 30 | # --------------------------------------------------------------------------- 31 | ERROR ON 32 | 33 | # --------------------------------------------------------------------------- 34 | # utimes changes timestamps on any type of file 35 | CREATE Kah 36 | UTIMES Kah 1900000000 A # Sun Mar 17 11:46:40 MDT 2030 37 | UTIMES Kah 1950000000 M # Fri Oct 17 04:40:00 MDT 2031 38 | STAT Kah 39 | TIMES Kah A 1900000000 40 | TIMES Kah M 1950000000 41 | UNLINK Kah 42 | 43 | MKDIR Zig 44 | UTIMES Zig 1900000000 A # Sun Mar 17 11:46:40 MDT 2030 45 | UTIMES Zig 1950000000 M # Fri Oct 17 04:40:00 MDT 2031 46 | STAT Zig 47 | TIMES Zig A 1900000000 48 | TIMES Zig M 1950000000 49 | RMDIR Zig 50 | 51 | 52 | # --------------------------------------------------------------------------- 53 | # utimes with UTIME_NOW will set the will set typestamps to now 54 | # utimes with UTIME_OMIT will leave the time unchanged 55 | # utimes can update birthtimes 56 | # utimes can set mtime < atime or vice versa 57 | # utimes can follow symlinks 58 | # utimes with UTIME_NOW will work if the caller has write permission 59 | # utimes will work if the caller is the owner or root 60 | # utimes can set timestamps with subsecond precision 61 | # utimes is y2038 compliant 62 | 63 | # --------------------------------------------------------------------------- 64 | -------------------------------------------------------------------------------- /tests/mm_anon.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | # ---------------------------------------------------------------------------- 4 | # Memory mapping 5 | 6 | # map 7 | KMAP ANON 4k rw @ma1 8 | TOUCH @ma1 w 9 | SHOW 10 | 11 | # unmap 12 | KUNMAP @ma1 4k 13 | ERROR ENOMEM 14 | TOUCH @ma1 w 15 | ERROR ON 16 | 17 | # protect (r- => rw) 18 | KMAP ANON 8k r- @ma2 19 | TOUCH @ma2 r 20 | ERROR ENOMEM 21 | TOUCH @ma2 w 22 | ERROR ON 23 | KPROTECT @ma2 8k rw 24 | TOUCH @ma2 w 25 | KUNMAP @ma2 8k 26 | 27 | # protect (rw => r-) 28 | KMAP ANON 8k rw @ma3 29 | TOUCH @ma3 w 30 | KPROTECT @ma3 8k r- 31 | ERROR ENOMEM 32 | TOUCH @ma3 w 33 | ERROR ON 34 | TOUCH @ma3 r 35 | KUNMAP @ma3 8k 36 | 37 | # protect split !? 38 | KMAP ANON 8k r- @ma4 39 | KPROTECT @ma4+4k 4k rw 40 | SHOW 41 | TOUCH @ma4 r 42 | TOUCH @ma4+4k w 43 | ERROR ENOMEM 44 | TOUCH @ma4 w 45 | ERROR ON 46 | KUNMAP @ma4 4k 47 | SHOW 48 | TOUCH @ma4+4k r 49 | ERROR ENOMEM 50 | TOUCH @ma4 r 51 | ERROR ON 52 | KUNMAP @ma4+4k 4k 53 | SHOW 54 | 55 | # testing clone 56 | USPACE_CREATE @us1 57 | MMAP ANON 20k rw @ma5 58 | TOUCH @ma5 r 59 | TOUCH @ma5+4k rw 60 | TOUCH @ma5+8k rw 61 | SHOW 62 | 63 | USPACE_CLONE @us2 64 | SHOW 65 | USPACE_SELECT @us1 66 | SHOW 67 | 68 | TOUCH @ma5+12k rw 69 | TOUCH @ma5+4k rw 70 | SHOW 71 | 72 | USPACE_CLONE @us3 73 | TOUCH @ma5+8k rw 74 | SHOW 75 | 76 | USPACE_SELECT @us2 77 | TOUCH @ma5+4k rw 78 | SHOW 79 | 80 | USPACE_SELECT @us3 81 | USPACE_CLOSE @us3 82 | 83 | USPACE_SELECT @us1 84 | TOUCH @ma5+4k r 85 | TOUCH @ma5+12k rw 86 | 87 | USPACE_SELECT @us2 88 | USPACE_CLOSE @us2 89 | 90 | USPACE_SELECT @us1 91 | TOUCH @ma5 rw 92 | TOUCH @ma5+16k r 93 | 94 | USPACE_SELECT @us1 95 | USPACE_CLOSE @us1 96 | 97 | # protect update 98 | KMAP ANON 8k rw @ma6 99 | TOUCH @ma6 rw 100 | 101 | KPROTECT @ma6 8K r 102 | ERROR ENOMEM 103 | TOUCH @ma6 rw 104 | ERROR ON 105 | TOUCH @ma6+4K r 106 | 107 | KPROTECT @ma6 8K rw 108 | TOUCH @ma6 r 109 | TOUCH @ma6+4K rw 110 | TOUCH @ma6 rw 111 | 112 | KUNMAP @ma6 8K 113 | 114 | # protect and copy-on-write 115 | USPACE_CREATE @us1 116 | MMAP ANON 20k rw @ma7 117 | TOUCH @ma7 rw 118 | SHOW 119 | 120 | USPACE_CLONE @us2 121 | TOUCH @ma7+4k w 122 | MPROTECT @ma7 20k r 123 | ERROR ENOMEM 124 | TOUCH @ma7 w 125 | ERROR ON 126 | SHOW 127 | 128 | USPACE_CLONE @us3 129 | SHOW 130 | MPROTECT @ma7 20k rw 131 | SHOW 132 | 133 | TOUCH @ma7 rw 134 | SHOW 135 | 136 | USPACE_SELECT @us2 137 | MPROTECT @ma7 20k rw 138 | SHOW 139 | 140 | USPACE_SELECT @us3 141 | USPACE_CLOSE @us3 142 | USPACE_SELECT @us2 143 | USPACE_CLOSE @us2 144 | USPACE_SELECT @us1 145 | USPACE_CLOSE @us1 146 | 147 | # uspace open 148 | 149 | 150 | # cleanup 151 | DEL @ma1 152 | DEL @ma2 153 | DEL @ma3 154 | DEL @ma4 155 | DEL @ma5 156 | DEL @ma6 157 | DEL @ma7 158 | -------------------------------------------------------------------------------- /tests/mm_dlib.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | # ---------------------------------------------------------------------------- 4 | # Library mapping 5 | 6 | # basic mapping 7 | KDLIB bootrd/ata.ko 8 | SHOW 9 | 10 | KSYM ata_setup @a1 11 | TOUCH @a1 r 12 | SHOW 13 | ERROR ENOMEM 14 | TOUCH @a1 w 15 | ERROR ON 16 | 17 | KSYM ata_ino_ops @a2 18 | TOUCH @a2 r 19 | SHOW 20 | TOUCH @a2 w 21 | SHOW 22 | 23 | KSYM ata_teardown @a3 24 | TOUCH @a3 r 25 | SHOW 26 | 27 | DEL @a1 28 | DEL @a2 29 | DEL @a3 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/mm_elf.sh: -------------------------------------------------------------------------------- 1 | 2 | START 64M 64M 6K 3 | 4 | # KDLIB ../../../_i386-pc-kora/img/boot/mods/ext2.ko 5 | KDLIB ../../../_i386-pc-kora/img/boot/mods/e1000.ko 6 | # KDLIB ../../../_i386-pc-kora/img/boot/mods/ps2.ko 7 | 8 | -------------------------------------------------------------------------------- /tests/mm_file.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | # ---------------------------------------------------------------------------- 4 | # File mapping 5 | USPACE_CREATE @us1 6 | 7 | # map 8 | MMAPX FILE 20k r lorem_sm.txt 0 @mf1 9 | TOUCH @mf1 r 10 | TOUCH @mf1+4k r 11 | TOUCH @mf1+8k r 12 | TOUCH @mf1+12k r 13 | TOUCH @mf1+16k r 14 | SHOW 15 | 16 | MMAPX FILE 4k rw lorem_xs.txt 0 @mf2 17 | TOUCH @mf2 rw 18 | SHOW 19 | 20 | # unmap 21 | MUNMAP @mf2 4k 22 | SHOW 23 | 24 | MUNMAP @mf1+8k 12k 25 | MUNMAP @mf1 8k 26 | SHOW 27 | 28 | # protect 29 | MMAPX FILE 12k rw lorem_sm.txt 0 @mf3 30 | TOUCH @mf3 rw 31 | MPROTECT @mf3 12k r 32 | SHOW 33 | ERROR ENOMEM 34 | TOUCH @mf3+4k w 35 | ERROR ON 36 | 37 | MUNMAP @mf3 12k 38 | 39 | # clone 40 | MMAPX FILE 20k r lorem_sm.txt 0 @mf4 41 | MMAPX FILE 4k rw lorem_xs.txt 0 @mf5 42 | TOUCH @mf4 r 43 | TOUCH @mf5 w 44 | SHOW 45 | 46 | USPACE_CLONE @us2 47 | SHOW 48 | TOUCH @mf4 r 49 | TOUCH @mf5 w 50 | SHOW 51 | 52 | USPACE_SELECT @us1 53 | USPACE_CLOSE @us1 54 | USPACE_SELECT @us2 55 | USPACE_CLOSE @us2 56 | 57 | DEL @mf1 58 | DEL @mf2 59 | DEL @mf3 60 | DEL @mf4 61 | DEL @mf5 62 | -------------------------------------------------------------------------------- /tests/mm_filecpy.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | # ---------------------------------------------------------------------------- 4 | # Memory mapping 5 | 6 | # map 7 | KMAPX FILECPY 4k rw lorem_xs.txt 0 @ma1 8 | TOUCH @ma1 w 9 | SHOW 10 | 11 | # unmap 12 | KUNMAP @ma1 4k 13 | ERROR ENOMEM 14 | TOUCH @ma1 w 15 | ERROR ON 16 | 17 | # protect (r- => rw) 18 | KMAPX FILECPY 8k r- lorem_sm.txt 0 @ma2 19 | TOUCH @ma2 r 20 | ERROR ENOMEM 21 | TOUCH @ma2 w 22 | ERROR ON 23 | KPROTECT @ma2 8k rw 24 | TOUCH @ma2 w 25 | KUNMAP @ma2 8k 26 | 27 | # protect (rw => r-) 28 | KMAPX FILECPY 8k rw lorem_sm.txt 0 @ma3 29 | TOUCH @ma3 w 30 | KPROTECT @ma3 8k r- 31 | ERROR ENOMEM 32 | TOUCH @ma3 w 33 | ERROR ON 34 | TOUCH @ma3 r 35 | KUNMAP @ma3 8k 36 | 37 | # protect split !? 38 | KMAPX FILECPY 8k r- lorem_sm.txt 0 @ma4 39 | KPROTECT @ma4+4k 4k rw 40 | SHOW 41 | TOUCH @ma4 r 42 | TOUCH @ma4+4k w 43 | ERROR ENOMEM 44 | TOUCH @ma4 w 45 | ERROR ON 46 | KUNMAP @ma4 4k 47 | SHOW 48 | TOUCH @ma4+4k r 49 | ERROR ENOMEM 50 | TOUCH @ma4 r 51 | ERROR ON 52 | KUNMAP @ma4+4k 4k 53 | SHOW 54 | 55 | # testing clone 56 | USPACE_CREATE @us1 57 | MMAPX FILECPY 20k rw lorem_sm.txt 0 @ma5 58 | TOUCH @ma5 r 59 | TOUCH @ma5+4k rw 60 | TOUCH @ma5+8k rw 61 | SHOW 62 | 63 | USPACE_CLONE @us2 64 | SHOW 65 | USPACE_SELECT @us1 66 | SHOW 67 | 68 | TOUCH @ma5+12k rw 69 | TOUCH @ma5+4k rw 70 | SHOW 71 | 72 | USPACE_CLONE @us3 73 | TOUCH @ma5+8k rw 74 | SHOW 75 | 76 | USPACE_SELECT @us2 77 | TOUCH @ma5+4k rw 78 | SHOW 79 | 80 | USPACE_SELECT @us3 81 | USPACE_CLOSE @us3 82 | 83 | USPACE_SELECT @us1 84 | TOUCH @ma5+4k r 85 | TOUCH @ma5+12k rw 86 | 87 | USPACE_SELECT @us2 88 | SHOW 89 | USPACE_CLOSE @us2 90 | 91 | USPACE_SELECT @us1 92 | TOUCH @ma5 rw 93 | TOUCH @ma5+16k r 94 | 95 | USPACE_SELECT @us1 96 | USPACE_CLOSE @us1 97 | 98 | # protect update 99 | KMAPX FILECPY 8k rw lorem_sm.txt 0 @ma6 100 | TOUCH @ma6 rw 101 | 102 | KPROTECT @ma6 8K r 103 | ERROR ENOMEM 104 | TOUCH @ma6 rw 105 | ERROR ON 106 | TOUCH @ma6+4K r 107 | 108 | KPROTECT @ma6 8K rw 109 | TOUCH @ma6 r 110 | TOUCH @ma6+4K rw 111 | TOUCH @ma6 rw 112 | 113 | KUNMAP @ma6 8K 114 | 115 | # protect and copy-on-write 116 | USPACE_CREATE @us4 117 | MMAPX FILECPY 20k rw lorem_sm.txt 0 @ma7 118 | TOUCH @ma7 rw 119 | SHOW 120 | 121 | USPACE_CLONE @us5 122 | TOUCH @ma7+4k w 123 | MPROTECT @ma7 20k r 124 | ERROR ENOMEM 125 | TOUCH @ma7 w 126 | ERROR ON 127 | SHOW 128 | 129 | USPACE_CLONE @us6 130 | SHOW 131 | MPROTECT @ma7 20k rw 132 | SHOW 133 | 134 | TOUCH @ma7 rw 135 | SHOW 136 | 137 | USPACE_SELECT @us5 138 | MPROTECT @ma7 20k rw 139 | SHOW 140 | 141 | USPACE_SELECT @us6 142 | USPACE_CLOSE @us6 143 | USPACE_SELECT @us5 144 | USPACE_CLOSE @us5 145 | USPACE_SELECT @us4 146 | USPACE_CLOSE @us4 147 | 148 | 149 | # cleanup 150 | DEL @ma1 151 | DEL @ma2 152 | DEL @ma3 153 | DEL @ma4 154 | DEL @ma5 155 | DEL @ma6 156 | DEL @ma7 157 | -------------------------------------------------------------------------------- /tests/mm_heap.sh: -------------------------------------------------------------------------------- 1 | 2 | # ---------------------------------------------------------------------------- 3 | # Heap & Stack 4 | # map 5 | KMAP HEAP 16k rw @mh1 6 | TOUCH @mh1 w 7 | TOUCH @mh1+4k r 8 | 9 | KMAP STACK 16k rw @ms1 10 | TOUCH @ms1 w 11 | SHOW 12 | 13 | # unmap 14 | ERROR EINVAL 15 | KUNMAP @mh1 4k 16 | ERROR ON 17 | KUNMAP @mh1 16k 18 | ERROR ENOMEM 19 | TOUCH @mh1 w 20 | ERROR ON 21 | 22 | KUNMAP @ms1 16k 23 | 24 | # TODO protect, split forbidden 25 | # TODO clone work like anonymous 26 | # TODO clone for stack !? 27 | 28 | DEL @mh1 29 | DEL @ms1 30 | -------------------------------------------------------------------------------- /tests/mm_misc.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | # ---------------------------------------------------------------------------- 4 | # Pipe 5 | # Map & write 6 | KMAP PIPE 8k - @mp1 7 | TOUCH @mp1 w 8 | TOUCH @mp1+4k w 9 | SHOW 10 | 11 | # Remap (unmap) 12 | KMAP PIPE 16k - @mp2 13 | TOUCH @mp2 w 14 | TOUCH @mp2+4k w 15 | KUNMAP @mp1 8k 16 | SHOW 17 | 18 | # Resolving... 19 | TOUCH @mp2+8 r 20 | TOUCH @mp2+12 rw 21 | SHOW 22 | 23 | # Can't protect or clone 24 | ERROR EINVAL 25 | KPROTECT @mp2, 8k r 26 | KPROTECT @mp2, 16k r 27 | KUNMAP @mp2 12k 28 | ERROR ON 29 | 30 | KUNMAP @mp2 16k 31 | SHOW 32 | DEL @mp1 33 | DEL @mp2 34 | 35 | # ---------------------------------------------------------------------------- 36 | # Physique & DMA 37 | ERROR EINVAL 38 | KMAPX PHYS 1M ru - 0xcafe00 @mp1 39 | ERROR ON 40 | SHOW 41 | 42 | #KMAPX PHYS 4k r - 0 @mp2 43 | #TOUCH @mp2 r 44 | #MMUREAD @mp2 @pg1 45 | #KUNMAP @mp2 4k 46 | #MMURELEASE @pg1 47 | 48 | KMAPX PHYS 128k rwu - 0xbad00000 @mp1 49 | TOUCH @mp1 r 50 | KUNMAP @mp1 128k 51 | SHOW 52 | 53 | DEL @mp1 54 | -------------------------------------------------------------------------------- /tests/mm_start.sh: -------------------------------------------------------------------------------- 1 | 2 | ERROR ON 3 | 4 | START 64M 64M 6K 5 | 6 | INCLUDE mm_misc.sh 7 | INCLUDE mm_anon.sh 8 | INCLUDE mm_heap.sh 9 | INCLUDE mm_file.sh 10 | INCLUDE mm_filecpy.sh 11 | INCLUDE mm_dlib.sh 12 | 13 | 14 | # ---------------------------------------------------------------------------- 15 | # Manage user virtual memory space 16 | # Consumme lots of pages 17 | # Bad page-faults 18 | # Library resolve / Fixed & Hint address / Copy-on-write 19 | 20 | ERROR OFF 21 | QUIT 22 | EXIT 23 | 24 | -------------------------------------------------------------------------------- /tests/mm_test.sh: -------------------------------------------------------------------------------- 1 | ERROR ON 2 | 3 | CREATE vm0 4 | 5 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 6 | # Create heap 7 | HEAP 64k kh1 8 | 9 | # Test page fault on heap 10 | TOUCH @kh1 w 11 | TOUCH @kh1+4k r 12 | TOUCH @kh1+4k w 13 | SHOW p8K,v64k,s0 14 | 15 | HEAP 16k kh2 16 | TOUCH @kh2 w 17 | TOUCH @kh2+4k r 18 | TOUCH @kh2+8k w 19 | SHOW p20K,v80k,s0 20 | 21 | # Protection change are not allowed 22 | ERROR EPERM 23 | PROTECT @kh1 4M r 24 | ERROR ON 25 | 26 | # Shared heap are not allowed 27 | # MAP 2M kh3 H rw.s 28 | 29 | # We can unmap heap partial or complete 30 | UNMAP @kh2 16k 31 | SHOW p8K,v64k,s0 32 | 33 | # Stack work the same 34 | STACK 12k ks1 35 | SHOW p8K,v76k,s0 36 | 37 | # Stack can't be just unmap (!??) 38 | 39 | 40 | 41 | # On VM clone heaps (and stacks) goes on COW 42 | CLONE vm1 43 | 44 | # Test Heap COW (read PF) 45 | TOUCH @kh1 r 46 | 47 | 48 | # Test Heap COW (write PF) 49 | TOUCH @kh1+4k w 50 | 51 | SHOW 52 | 53 | # Clone a clone put all back into cow 54 | # Close on of the VM doesn't impact the other 55 | # Close last with both shared and private VMAs 56 | 57 | 58 | # Pipe test similar to heap without clone 59 | # Pipe can't be created into user vm 60 | 61 | # Phys test similar Pipe but auto resolve, 62 | # Mprotect always allow to set the write flags 63 | 64 | # Private anon are like heap (+cow) 65 | # mprotect, is complex 66 | 67 | # Shared anon 68 | 69 | 70 | # Private file 71 | 72 | # Shared file 73 | 74 | # Code 75 | 76 | # Some elf reading tests 77 | 78 | 79 | # CREATE vm0 80 | # STACK 1M 81 | # EXEC libc.so 20k 12k 82 | # EXEC libz.so 12K 4K 83 | # EXEC krish 24k 16k 84 | # SHOW 85 | # TOUCH 0x04FFFF0 w 86 | # TOUCH 0x02000000 x # libc.so 87 | # HEAP 8m 88 | # TOUCH 0x00500000 w # Heap.0 89 | # TOUCH 0x00501000 w # Heap.1 90 | # SHOW 91 | # TOUCH 0x02005000 w # libc.so .data 92 | # SHOW 93 | -------------------------------------------------------------------------------- /tests/net_ip0.sh: -------------------------------------------------------------------------------- 1 | # Network test 2 | 3 | ERROR ON 4 | 5 | NODE alice 1 6 | NODE bob 1 7 | IP4_CONFIG alice:eth:1 ip=192.168.0.1 8 | IP4_CONFIG bob:eth:1 ip=192.168.0.2 9 | LINK @nat0 alice:eth:1 10 | LINK @nat0 bob:eth:1 11 | TEMPO 12 | 13 | SOCKET alice @as0 udp/ip4 14 | EXPECT NONULL @as0 15 | BIND @as0 0.0.0.0:7003 16 | # ACCEPT @as0 @ac0 3 17 | 18 | SOCKET bob @bc0 udp/ip4 19 | EXPECT NONULL @bc0 20 | CONNECT @bc0 192.168.0.1:7003 21 | 22 | TEXT @bf0 "Hello, I'm Bob\n" 23 | SEND @bc0 @bf0 24 | TEMPO 25 | ACCEPT @as0 @ac1 3 26 | EXPECT NONULL @ac1 27 | RECV @ac1 @bf1 28 | EXPECT EQ @bf0 @bf1 29 | 30 | CLOSE @ac1 31 | CLOSE @bc0 32 | CLOSE @as0 33 | 34 | UNLINK @nat0 alice:eth:1 35 | UNLINK @nat0 bob:eth:1 36 | KILL alice 37 | KILL bob 38 | 39 | RMBUF @bf0 40 | RMBUF @bf1 41 | 42 | QUIT 43 | 44 | 45 | # Test ping 46 | 47 | #NODE gateway 2 48 | #NODE alice 1 49 | 50 | #IP4_CONFIG gateway:eth:1 ip=192.168.0.1 51 | #IP4_CONFIG gateway:eth:1 dhcp-server 52 | #TEMPO 53 | 54 | #LINK @nat0 gateway:eth:1 55 | #LINK @nat0 alice:eth:1 56 | 57 | #TEMPO 58 | 59 | #TEXT @bf2 "ABCD" 60 | #PING alice 192.168.0.1 @bf2 61 | #TEMPO 62 | 63 | # Check received ping !! 64 | 65 | -------------------------------------------------------------------------------- /tests/net_ping0.sh: -------------------------------------------------------------------------------- 1 | # Ping testing 2 | # Scenari: I connect my computer on a new network 3 | # and then send a ping address to the gateway 4 | ERROR ON 5 | 6 | # Initialize rooter 7 | NODE gateway 1 8 | IP4_CONFIG gateway:eth:1 dhcp-server 9 | LINK lan gateway:eth:1 10 | TEMPO 11 | 12 | # Initialize client 13 | NODE alice 1 14 | LINK lan alice:eth:1 15 | TEMPO 16 | 17 | # Send ping request 18 | PING alice 192.168.0.1 19 | 20 | # Cleaning 21 | UNLINK lan gateway:eth:1 22 | UNLINK lan alice:eth:1 23 | KILL alice 24 | KILL gateway 25 | QUIT 26 | 27 | -------------------------------------------------------------------------------- /tests/net_udp0.sh: -------------------------------------------------------------------------------- 1 | # Udp simple exchange testing 2 | # Scenari: I CONNECT to a UDP service and excahnge some packets 3 | NODE server 1 4 | IP4_CONFIG server:eth:1 ip=192.168.0.1 5 | LINK lan server:eth:1 6 | 7 | NODE alice 1 8 | IP4_CONFIG alice:eth:1 ip=192.168.0.4 9 | LINK lan alice:eth:1 10 | 11 | SOCKET server @sks udp 12 | BIND @sks 0.0.0.0:7003 13 | ACCEPT @sks @sk0 0 14 | 15 | SOCKET alice @ska udp 16 | CONNECT @ska 192.168.0.1:7003 17 | 18 | TEXT @ba "Hello, I'm Alice\n" 19 | SEND @ska @ba 20 | 21 | ACCEPT @sks @sk0 50 22 | RECV @sk0 @bs 23 | EXPECT EQ @ba @bs 24 | TEXT @bs "Hello Alice\n" 25 | SEND @sk0 @bs 26 | 27 | RECV @ska @ba 28 | # PRINT @ba 29 | CLOSE @ska 30 | 31 | # Create a second client 32 | 33 | NODE @bob 1 34 | IP4_CONFIG bob:eth:1 ip=192.168.0.5 35 | LINK lan bob:eth:1 36 | 37 | TEXT @ba "Nice to meet you!\n" 38 | SEND @ska @ba 39 | 40 | SOCKET @bob @skb udp 41 | CONNECT @skb 192.168.0.1:7003 42 | 43 | TEXT @bb "Hello, I'm Bob\n" 44 | SEND @skb @bb 45 | 46 | ACCEPT @sks @sk1 500 47 | 48 | RECV @sk0 @bs 49 | # PRINT @bs 50 | 51 | RECV @sk1 @bs 52 | # PRINT @bs 53 | 54 | TEXT @bs "Hello Bob\n" 55 | SEND @sk1 @bs 56 | 57 | TEXT @bs "Is someone there?\n" 58 | SEND @sks @bs 59 | 60 | -------------------------------------------------------------------------------- /tests/snd/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include "../cli.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | typedef int64_t xoff_t; 29 | size_t vfs_fetch_page(void *ino, xoff_t off) { return 0; } 30 | int vfs_release_page(void *ino, xoff_t off, size_t pg, bool dirty) { return -1; } 31 | char *vfs_inokey(void *ino, char *buf) { return buf; } 32 | 33 | 34 | void initialize() 35 | { 36 | } 37 | 38 | void teardown() 39 | { 40 | } 41 | 42 | void do_restart(void *ctx, size_t *param) 43 | { 44 | teardown(); 45 | // TODO -- Check all is clean 46 | initialize(); 47 | } 48 | 49 | 50 | cli_cmd_t __commands[] = { 51 | { "RESTART", "", { 0, 0, 0, 0, 0 }, (void*)do_restart, 1 }, 52 | 53 | CLI_END_OF_COMMANDS, 54 | }; 55 | 56 | int main(int argc, char **argv) 57 | { 58 | return cli_main(argc, argv, NULL, initialize, teardown); 59 | } 60 | -------------------------------------------------------------------------------- /tests/stub/stub_irq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | 24 | thread_local int __irq_semaphore = 0; 25 | 26 | void irq_reset(bool enable) 27 | { 28 | __irq_semaphore = 0; 29 | } 30 | 31 | bool irq_enable() 32 | { 33 | assert(__irq_semaphore > 0); 34 | --__irq_semaphore; 35 | return __irq_semaphore == 0; 36 | } 37 | 38 | void irq_disable() 39 | { 40 | ++__irq_semaphore; 41 | } 42 | 43 | void might_sleep(void) 44 | { 45 | assert(__irq_semaphore == 0); 46 | } 47 | -------------------------------------------------------------------------------- /tests/stub/stub_task.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #if defined(_WIN32) 26 | # include 27 | #endif 28 | 29 | 30 | 31 | struct task_data_start { 32 | char name[64]; 33 | void (*func)(void*); 34 | void* arg; 35 | }; 36 | 37 | static int _task_impl_start(void* arg) 38 | { 39 | struct task_data_start* data = arg; 40 | #ifdef _WIN32 41 | wchar_t wbuf[64]; 42 | size_t len; 43 | mbstowcs_s(&len, wbuf, 64, data->name, 64); 44 | SetThreadDescription(GetCurrentThread(), wbuf); 45 | #endif 46 | void(*func)(void*) = data->func; 47 | void* param = data->arg; 48 | free(data); 49 | func(param); 50 | return 0; 51 | } 52 | 53 | int task_start(const char* name, void *func, void* arg) 54 | { 55 | thrd_t thrd; 56 | struct task_data_start* data = malloc(sizeof(struct task_data_start)); 57 | assert(data != NULL); 58 | strncpy(data->name, name, 64); 59 | data->func = func; 60 | data->arg = arg; 61 | thrd_create(&thrd, _task_impl_start, data); 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tests/tasks/task_main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxFab/kora-kernel/a5688b37483f7d842cabfd899b965e4d560e7ce1/tests/tasks/task_main.c -------------------------------------------------------------------------------- /tests/threads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the KoraOS project. 3 | * Copyright (C) 2015-2021 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * - - - - - - - - - - - - - - - 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct impl_thrd_param { 28 | thrd_start_t func; 29 | void *arg; 30 | }; 31 | 32 | void *impl_thrd_routine(void *p) 33 | { 34 | struct impl_thrd_param pack = *((struct impl_thrd_param *)p); 35 | free(p); 36 | void *ret = (void *)(size_t)pack.func(pack.arg); 37 | return ret; 38 | } 39 | 40 | 41 | int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) 42 | { 43 | struct impl_thrd_param *pack; 44 | if (!thr) 45 | return thrd_error; 46 | pack = malloc(sizeof(struct impl_thrd_param)); 47 | if (!pack) 48 | return thrd_nomem; 49 | pack->func = func; 50 | pack->arg = arg; 51 | if (pthread_create(thr, NULL, impl_thrd_routine, pack) != 0) { 52 | free(pack); 53 | return thrd_error; 54 | } 55 | return thrd_success; 56 | } 57 | 58 | int thrd_detach(thrd_t thr) 59 | { 60 | return (pthread_detach(thr) == 0) ? thrd_success : thrd_error; 61 | } 62 | 63 | int thrd_equal(thrd_t thr0, thrd_t thr1) 64 | { 65 | return pthread_equal(thr0, thr1); 66 | } 67 | 68 | void thrd_exit(int res) 69 | { 70 | for (;;) 71 | pthread_exit((void *)(size_t)res); 72 | 73 | } 74 | 75 | int thrd_join(thrd_t thr, int *res) 76 | { 77 | void *code; 78 | if (pthread_join(thr, &code) != 0) 79 | return thrd_error; 80 | if (res) 81 | *res = (int)(size_t)code; 82 | return thrd_success; 83 | } 84 | 85 | int thrd_sleep(const struct timespec *req, struct timespec *res) 86 | { 87 | struct timespec tp = *(req); 88 | nanosleep(&tp, res); 89 | return 0; 90 | } 91 | 92 | void thrd_yield(void) 93 | { 94 | sched_yield(); 95 | } 96 | -------------------------------------------------------------------------------- /tests/tsk_main.sh: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Create and execute tasks 3 | START kloader.1 4 | START kloader.2 5 | TICK 5 1 6 | START net_demon 7 | TICK 2 2 8 | SPAWN launcher 9 | TICK 3 3 10 | SPAWN job5 11 | TICK 0 5 12 | WAIT @w5 13 | TICK 3 2 14 | STOP 15 | SHOW 0 16 | TICK 0 1 17 | WAIT @w1 18 | TICK 0 3 19 | WAIT @w3 20 | TICK 0 4 21 | WAIT @w4 22 | SHOW 0 23 | 24 | 25 | # ---------------------------------------------------------------------------- 26 | # Tasks on pause 27 | 28 | # ---------------------------------------------------------------------------- 29 | # Threads 30 | 31 | # ---------------------------------------------------------------------------- 32 | # Forks (later) 33 | 34 | # ---------------------------------------------------------------------------- 35 | # Signals 36 | 37 | # ---------------------------------------------------------------------------- 38 | # Exceptions and IRQ 39 | 40 | # ---------------------------------------------------------------------------- 41 | # Keep track of CPU time 42 | 43 | # ---------------------------------------------------------------------------- 44 | # Ressources 45 | 46 | # ---------------------------------------------------------------------------- 47 | # System time 48 | 49 | # ---------------------------------------------------------------------------- 50 | # Adjust time 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/vfs/cli-vfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLI_VFS_H 2 | #define __CLI_VFS_H 1 3 | 4 | #include "../cli.h" 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 11 | 12 | #define ST_INODE 1 13 | #define ST_BUFFER 2 14 | 15 | 16 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 17 | typedef struct vfs_ctx 18 | { 19 | fs_anchor_t *fsa; 20 | user_t *user; 21 | bool auto_scavenge; 22 | } vfs_ctx_t; 23 | 24 | typedef struct buf 25 | { 26 | size_t len; 27 | char ptr[0]; 28 | } buf_t; 29 | 30 | typedef struct file 31 | { 32 | inode_t *ino; 33 | int rights; 34 | } file_t; 35 | 36 | 37 | int do_dump(vfs_ctx_t *ctx, size_t *param); 38 | int do_umask(vfs_ctx_t *ctx, size_t *param); 39 | int do_ls(vfs_ctx_t *ctx, size_t *param); 40 | int do_stat(vfs_ctx_t *ctx, size_t *param); 41 | int do_lstat(vfs_ctx_t *ctx, size_t *param); 42 | int do_link(vfs_ctx_t *ctx, size_t *param); 43 | int do_links(vfs_ctx_t *ctx, size_t *param); 44 | int do_times(vfs_ctx_t *ctx, size_t *param); 45 | int do_cd(vfs_ctx_t *ctx, size_t *param); 46 | int do_chroot(vfs_ctx_t *ctx, size_t *param); 47 | int do_pwd(vfs_ctx_t *ctx, size_t *param); 48 | int do_open(vfs_ctx_t *ctx, size_t *param); 49 | int do_close(vfs_ctx_t *ctx, size_t *param); 50 | int do_read(vfs_ctx_t *ctx, size_t *param); 51 | int do_write(vfs_ctx_t *ctx, size_t *param); 52 | int do_rmbuf(vfs_ctx_t *ctx, size_t *param); 53 | int do_delay(vfs_ctx_t *ctx, size_t *param); 54 | int do_create(vfs_ctx_t *ctx, size_t *param); 55 | int do_unlink(vfs_ctx_t *ctx, size_t *param); 56 | int do_symlink(vfs_ctx_t *ctx, size_t *param); 57 | int do_mkdir(vfs_ctx_t *ctx, size_t *param); 58 | int do_rmdir(vfs_ctx_t *ctx, size_t *param); 59 | int do_dd(vfs_ctx_t *ctx, size_t *param); 60 | int do_truncate(vfs_ctx_t *ctx, size_t *param); 61 | int do_size(vfs_ctx_t *ctx, size_t *param); 62 | int do_clear_cache(vfs_ctx_t *ctx, size_t *param); 63 | int do_mount(vfs_ctx_t *ctx, size_t *param); 64 | int do_umount(vfs_ctx_t *ctx, size_t *param); 65 | int do_extract(vfs_ctx_t *ctx, size_t *param); 66 | int do_checksum(vfs_ctx_t *ctx, size_t *param); 67 | int do_img_open(vfs_ctx_t *ctx, size_t *param); 68 | int do_img_create(vfs_ctx_t *ctx, size_t *param); 69 | int do_img_copy(vfs_ctx_t *ctx, size_t *param); 70 | int do_img_remove(vfs_ctx_t *ctx, size_t *param); 71 | int do_tar_mount(vfs_ctx_t *ctx, size_t *param); 72 | int do_format(vfs_ctx_t *ctx, size_t *param); 73 | int do_chmod(vfs_ctx_t *ctx, size_t *param); 74 | int do_chown(vfs_ctx_t *ctx, size_t *param); 75 | int do_utimes(vfs_ctx_t *ctx, size_t *param); 76 | int do_ino(vfs_ctx_t *ctx, size_t *param); 77 | int do_rename(vfs_ctx_t *ctx, size_t *param); 78 | int do_pipe(vfs_ctx_t *ctx, size_t *param); 79 | 80 | 81 | int alloc_check(); 82 | 83 | #ifdef _EMBEDED_FS 84 | void fat_setup(); 85 | void fat_teardown(); 86 | void isofs_setup(); 87 | void isofs_teardown(); 88 | void ext2_setup(); 89 | void ext2_teardown(); 90 | #endif 91 | 92 | int imgdk_open(const char *path, const char *name); 93 | void imgdk_create(const char *name, size_t size); 94 | void vhd_create_dyn(const char *name, uint64_t size); 95 | uint32_t crc32_r(uint32_t checksum, const void *buf, size_t len); 96 | 97 | 98 | 99 | #endif /* __CLI_VFS_H */ 100 | --------------------------------------------------------------------------------