├── .gitignore
├── .vscode
└── settings.json
├── README.md
├── a.out
├── apps
└── hello_asm
│ ├── build.sh
│ ├── hello_asm
│ ├── main.asm
│ └── main.o
├── boot
└── boot.asm
├── build.py
├── build
├── boot
│ └── boot.asm.o
├── core
│ ├── gtree.c.o
│ ├── kpanic.c.o
│ ├── list.c.o
│ ├── print.c.o
│ ├── stdlib.c.o
│ ├── string.c.o
│ ├── tga.c.o
│ └── time.c.o
├── drivers
│ ├── ac97.c.o
│ ├── debug.c.o
│ ├── keyboard.c.o
│ ├── mouse.c.o
│ ├── pci.c.o
│ ├── sound_blaster.c.o
│ ├── vesa.c.o
│ └── vga.c.o
├── fs
│ ├── ata.c.o
│ ├── device.c.o
│ ├── ext2.c.o
│ └── vfs.c.o
├── iso
│ └── boot
│ │ ├── grub
│ │ └── grub.cfg
│ │ └── kernel.elf
├── kernel
│ ├── asm
│ │ ├── bios32_call.asm.o
│ │ ├── gdt.asm.o
│ │ ├── idt.asm.o
│ │ ├── interrupts.asm.o
│ │ ├── irq.asm.o
│ │ ├── paging.asm.o
│ │ ├── syscalls.asm.o
│ │ └── task.asm.o
│ ├── init.c.o
│ ├── kernel.c.o
│ ├── kernel_menu.c.o
│ ├── kmode.c.o
│ ├── memory.c.o
│ └── module.c.o
├── net
│ ├── ethernet.c.o
│ ├── socket.c.o
│ └── unix.c.o
├── quantumos.iso
├── sys
│ ├── cmos.c.o
│ ├── ksyms.c.o
│ ├── paging.c.o
│ ├── pmm.c.o
│ ├── process.c.o
│ ├── task.c.o
│ └── x86_64
│ │ ├── acpi.c.o
│ │ ├── idt.c.o
│ │ ├── isr.c.o
│ │ ├── kgdt.c.o
│ │ ├── lapic.c.o
│ │ ├── mio.c.o
│ │ ├── pic.c.o
│ │ ├── pio.c.o
│ │ └── pit.c.o
└── userspace
│ ├── elf.c.o
│ ├── syscalls.c.o
│ ├── usermode.c.o
│ ├── userspace.c.o
│ └── window.c.o
├── clib
├── build_clib.sh
├── build_test.sh
├── include
│ ├── stdarg.h
│ ├── stdio.h
│ └── sys
│ │ └── syscall.h
├── src
│ ├── crt0.asm
│ ├── crt0.asm.o
│ ├── stdio.c
│ ├── stdio.c.o
│ └── sys
│ │ ├── syscall.c
│ │ └── syscall.c.o
└── test
│ ├── a.out
│ └── main.c
├── config
├── grub.cfg
└── linker.ld
├── core
├── gtree.c
├── kpanic.c
├── list.c
├── print.c
├── stdlib.c
├── string.c
├── tga.c
└── time.c
├── count_src_lines.sh
├── drivers
├── ac97.c
├── debug.c
├── keyboard.c
├── mouse.c
├── pci.c
├── sound_blaster.c
├── vesa.c
└── vga.c
├── ext2.img
├── fs
├── ata.c
├── device.c
├── ext2.c
└── vfs.c
├── include
├── core
│ ├── errno.h
│ ├── gtree.h
│ ├── kpanic.h
│ ├── list.h
│ ├── print.h
│ ├── stdarg.h
│ ├── stdlib.h
│ ├── string.h
│ ├── tga.h
│ └── time.h
├── drivers
│ ├── ac97.h
│ ├── debug.h
│ ├── font.h
│ ├── keyboard.h
│ ├── mouse.h
│ ├── pci.h
│ ├── sound_blaster.h
│ ├── vesa.h
│ └── vga.h
├── fs
│ ├── ata.h
│ ├── device.h
│ ├── ext2.h
│ └── vfs.h
├── net
│ ├── ethernet.h
│ ├── socket.h
│ └── unix.h
├── quantum
│ ├── init.h
│ ├── kernel.h
│ ├── kernel_menu.h
│ ├── kmode.h
│ ├── module.h
│ └── multiboot.h
├── sys
│ ├── acpi.h
│ ├── cmos.h
│ ├── idt.h
│ ├── isr.h
│ ├── kgdt.h
│ ├── ksyms.h
│ ├── lapic.h
│ ├── memory.h
│ ├── mio.h
│ ├── paging.h
│ ├── pic.h
│ ├── pio.h
│ ├── pit.h
│ ├── pmm.h
│ ├── process.h
│ └── task.h
└── userspace
│ ├── elf.h
│ ├── syscalls.h
│ ├── usermode.h
│ ├── userspace.h
│ └── window.h
├── kernel
├── asm
│ ├── bios32_call.asm
│ ├── gdt.asm
│ ├── idt.asm
│ ├── interrupts.asm
│ ├── irq.asm
│ ├── paging.asm
│ ├── syscalls.asm
│ └── task.asm
├── init.c
├── kernel.c
├── kernel_menu.c
├── kmode.c
├── memory.c
└── module.c
├── mkdisk_ext2.sh
├── net
├── ethernet.c
├── socket.c
└── unix.c
├── rootfs
└── hello.txt
├── screenshots
├── F9838711-A50F-44C9-8CC5-C9C84AD35576.jpeg
└── screenshot1.png
├── sys
├── cmos.c
├── ksyms.c
├── paging.c
├── pmm.c
├── process.c
├── task.c
└── x86_64
│ ├── acpi.c
│ ├── idt.c
│ ├── isr.c
│ ├── kgdt.c
│ ├── lapic.c
│ ├── mio.c
│ ├── pic.c
│ ├── pio.c
│ └── pit.c
└── userspace
├── elf.c
├── syscalls.c
├── usermode.c
├── userspace.c
└── window.c
/.gitignore:
--------------------------------------------------------------------------------
1 | ./build/*
2 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.associations": {
3 | "ata.h": "c",
4 | "ext2.h": "c",
5 | "stdlib.h": "c",
6 | "memory.h": "c",
7 | "debug.h": "c",
8 | "print.h": "c",
9 | "string.h": "c",
10 | "list.h": "c",
11 | "kpanic.h": "c",
12 | "pci.h": "c",
13 | "init.h": "c",
14 | "multiboot.h": "c",
15 | "vesa.h": "c",
16 | "tga.h": "c",
17 | "font.h": "c",
18 | "pit.h": "c",
19 | "stdarg.h": "c",
20 | "keyboard.h": "c",
21 | "pio.h": "c",
22 | "userspace.h": "c",
23 | "mouse.h": "c",
24 | "cmos.h": "c",
25 | "module.h": "c",
26 | "pmm.h": "c",
27 | "usermode.h": "c",
28 | "window.h": "c"
29 | }
30 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QuantumOS
2 |
3 | ## About
4 | A simple operating system written in C and Assembly.
5 |
6 | ## Screenshots
7 | 
8 | 
9 |
10 | ## Project Map
11 | - `boot`: Multiboot assembly code
12 | - `clib`: C-Library (aiming for POSIX-like userland)
13 | - `config`: Compilation time configuration like linker config
14 | - `core`: Source for data-structures, stdio, stdlib, string
15 | - `drivers`: Source for drivers, e.g mouse, keyboard
16 | - `fs`: Source for ATA drivers and Filesystem implementations
17 | - `include`: All includes except C-Lib
18 | - `kernel`: All kernel-side sources including IDT, IRQ, GDT assembly
19 | - `net`: Networking implementations
20 | - `sys`: All system sources
21 | - `userspace`: Userspace sources, e.g syscalls
22 |
23 | ## Todo List
24 | - [] Implement ATA Drivers
25 | - [] Reimplement ACPI
26 | - [] Reimplement PCI
27 | - [] Custom bootloader
28 | - [] Implement EXT2 and FAT32
29 | - [] Implement IWL-Wifi drivers
30 | - [] Implement sound-card drivers
31 | - [] More...
32 |
33 |
34 |
--------------------------------------------------------------------------------
/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/a.out
--------------------------------------------------------------------------------
/apps/hello_asm/build.sh:
--------------------------------------------------------------------------------
1 | CC="gcc"
2 | ASM="nasm"
3 | LD="ld"
4 |
5 | $ASM -f elf32 main.asm -o main.o
6 | $LD -m elf_i386 main.o -o hello_asm
7 |
--------------------------------------------------------------------------------
/apps/hello_asm/hello_asm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/apps/hello_asm/hello_asm
--------------------------------------------------------------------------------
/apps/hello_asm/main.asm:
--------------------------------------------------------------------------------
1 | section .data
2 | hello db "Hello from assembler!", 10
3 | hello_len equ $ - hello
4 |
5 | section .text
6 | global _start
7 |
8 | _start:
9 | mov eax, 4
10 | mov ebx, 1
11 | mov ecx, hello
12 | mov edx, hello_len
13 | int 0x80
14 |
15 | mov eax, 1
16 | mov ebx, 0
17 | int 0x80
--------------------------------------------------------------------------------
/apps/hello_asm/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/apps/hello_asm/main.o
--------------------------------------------------------------------------------
/boot/boot.asm:
--------------------------------------------------------------------------------
1 | ; Magic header
2 | FLAGS equ 0x4
3 | MAGIC_HEADER equ 0x1BADB002
4 | CHECKSUM equ -(MAGIC_HEADER + FLAGS)
5 |
6 | ; Bootloader magic number
7 | BOOTLOADER_MAGIC equ 0x2BADB002
8 |
9 | ; Section .multiboot
10 | section .multiboot
11 | align 4
12 | dd MAGIC_HEADER
13 | dd FLAGS
14 | dd CHECKSUM
15 | dd 0
16 | dd 0
17 | dd 0
18 | dd 0
19 | dd 0
20 | dd 0
21 | dd 1280
22 | dd 720
23 | dd 32
24 |
25 | section .data
26 | align 4096
27 |
28 | section .initial_stack, nobits
29 | align 4
30 |
31 | stack_bottom:
32 | resb 104856
33 | stack_top:
34 |
35 | section .text
36 | global _start
37 | global MAGIC_HEADER
38 | global BOOTLOADER_MAGIC
39 |
40 | _start:
41 | extern quantum_kernel_init ; Extern c function
42 |
43 | mov esp, stack_top
44 | mov eax, BOOTLOADER_MAGIC
45 |
46 | push ebx
47 | push eax
48 |
49 | call quantum_kernel_init
50 | jmp $
--------------------------------------------------------------------------------
/build.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | CFLAGS='-m32 -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -I include '
4 | ASFLAGS='-f elf '
5 |
6 | csources = []
7 | ssources = []
8 |
9 | import fnmatch
10 | import os
11 |
12 | for root, dirnames, filenames in os.walk('.'):
13 | for filename in fnmatch.filter(filenames, '*.c'):
14 | if "apps" not in os.path.join(root, filename) and "clib" not in os.path.join(root, filename):
15 | csources.append(os.path.join(root, filename))
16 |
17 | for root, dirnames, filenames in os.walk('.'):
18 | for filename in fnmatch.filter(filenames, '*.asm'):
19 | if "apps" not in os.path.join(root, filename) and "clib" not in os.path.join(root, filename):
20 | ssources.append(os.path.join(root, filename))
21 |
22 | for i in range(len(csources)):
23 | c = csources[i]
24 |
25 | os.system("mkdir -p build/" + c)
26 |
27 | print("[" + str(i + 1) + "/" + str(len(csources)) + "] " + "Compiling: [" + c + "]")
28 |
29 | os.system("gcc " + CFLAGS + c + " -o build/" + c + ".o")
30 |
31 | for i in range(len(ssources)):
32 | s = ssources[i]
33 |
34 | os.system("mkdir -p build/" + s)
35 |
36 | print("[" + str(i + 1) + "/" + str(len(ssources)) + "] "+ "Compiling: [" + s + "]")
37 |
38 | os.system("nasm " + ASFLAGS + s + " -o build/" + s + ".o")
39 |
40 | total = ""
41 |
42 | os.system("mkdir -p build/iso/boot/grub/")
43 |
44 | for c in csources:
45 | total += "build/"
46 | total += c
47 | total += ".o "
48 |
49 | for s in ssources:
50 | total += "build/"
51 | total += s
52 | total += ".o "
53 |
54 | print("\nLinking kernel...\n")
55 |
56 | os.system("ld -m elf_i386 -Tconfig/linker.ld -o build/iso/boot/kernel.elf " + total)
57 | os.system("cp -f config/grub.cfg build/iso/boot/grub/")
58 | os.system("grub-mkrescue -o build/quantumos.iso build/iso")
59 |
60 | print("Done!\nRunning kernel...")
61 |
62 | os.system("qemu-system-x86_64 -cdrom ./build/quantumos.iso -drive file=ext2.img,format=raw -m 3G -vga vmware -serial stdio -device ac97")
--------------------------------------------------------------------------------
/build/boot/boot.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/boot/boot.asm.o
--------------------------------------------------------------------------------
/build/core/gtree.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/gtree.c.o
--------------------------------------------------------------------------------
/build/core/kpanic.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/kpanic.c.o
--------------------------------------------------------------------------------
/build/core/list.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/list.c.o
--------------------------------------------------------------------------------
/build/core/print.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/print.c.o
--------------------------------------------------------------------------------
/build/core/stdlib.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/stdlib.c.o
--------------------------------------------------------------------------------
/build/core/string.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/string.c.o
--------------------------------------------------------------------------------
/build/core/tga.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/tga.c.o
--------------------------------------------------------------------------------
/build/core/time.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/core/time.c.o
--------------------------------------------------------------------------------
/build/drivers/ac97.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/ac97.c.o
--------------------------------------------------------------------------------
/build/drivers/debug.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/debug.c.o
--------------------------------------------------------------------------------
/build/drivers/keyboard.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/keyboard.c.o
--------------------------------------------------------------------------------
/build/drivers/mouse.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/mouse.c.o
--------------------------------------------------------------------------------
/build/drivers/pci.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/pci.c.o
--------------------------------------------------------------------------------
/build/drivers/sound_blaster.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/sound_blaster.c.o
--------------------------------------------------------------------------------
/build/drivers/vesa.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/vesa.c.o
--------------------------------------------------------------------------------
/build/drivers/vga.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/drivers/vga.c.o
--------------------------------------------------------------------------------
/build/fs/ata.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/fs/ata.c.o
--------------------------------------------------------------------------------
/build/fs/device.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/fs/device.c.o
--------------------------------------------------------------------------------
/build/fs/ext2.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/fs/ext2.c.o
--------------------------------------------------------------------------------
/build/fs/vfs.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/fs/vfs.c.o
--------------------------------------------------------------------------------
/build/iso/boot/grub/grub.cfg:
--------------------------------------------------------------------------------
1 | menuentry "Quantum OS" {
2 | multiboot "/boot/kernel.elf"
3 | }
4 |
--------------------------------------------------------------------------------
/build/iso/boot/kernel.elf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/iso/boot/kernel.elf
--------------------------------------------------------------------------------
/build/kernel/asm/bios32_call.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/bios32_call.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/gdt.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/gdt.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/idt.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/idt.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/interrupts.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/interrupts.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/irq.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/irq.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/paging.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/paging.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/syscalls.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/syscalls.asm.o
--------------------------------------------------------------------------------
/build/kernel/asm/task.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/asm/task.asm.o
--------------------------------------------------------------------------------
/build/kernel/init.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/init.c.o
--------------------------------------------------------------------------------
/build/kernel/kernel.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/kernel.c.o
--------------------------------------------------------------------------------
/build/kernel/kernel_menu.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/kernel_menu.c.o
--------------------------------------------------------------------------------
/build/kernel/kmode.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/kmode.c.o
--------------------------------------------------------------------------------
/build/kernel/memory.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/memory.c.o
--------------------------------------------------------------------------------
/build/kernel/module.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/kernel/module.c.o
--------------------------------------------------------------------------------
/build/net/ethernet.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/net/ethernet.c.o
--------------------------------------------------------------------------------
/build/net/socket.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/net/socket.c.o
--------------------------------------------------------------------------------
/build/net/unix.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/net/unix.c.o
--------------------------------------------------------------------------------
/build/quantumos.iso:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/quantumos.iso
--------------------------------------------------------------------------------
/build/sys/cmos.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/cmos.c.o
--------------------------------------------------------------------------------
/build/sys/ksyms.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/ksyms.c.o
--------------------------------------------------------------------------------
/build/sys/paging.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/paging.c.o
--------------------------------------------------------------------------------
/build/sys/pmm.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/pmm.c.o
--------------------------------------------------------------------------------
/build/sys/process.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/process.c.o
--------------------------------------------------------------------------------
/build/sys/task.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/task.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/acpi.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/acpi.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/idt.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/idt.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/isr.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/isr.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/kgdt.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/kgdt.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/lapic.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/lapic.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/mio.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/mio.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/pic.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/pic.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/pio.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/pio.c.o
--------------------------------------------------------------------------------
/build/sys/x86_64/pit.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/sys/x86_64/pit.c.o
--------------------------------------------------------------------------------
/build/userspace/elf.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/userspace/elf.c.o
--------------------------------------------------------------------------------
/build/userspace/syscalls.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/userspace/syscalls.c.o
--------------------------------------------------------------------------------
/build/userspace/usermode.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/userspace/usermode.c.o
--------------------------------------------------------------------------------
/build/userspace/userspace.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/userspace/userspace.c.o
--------------------------------------------------------------------------------
/build/userspace/window.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/build/userspace/window.c.o
--------------------------------------------------------------------------------
/clib/build_clib.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CC='gcc'
4 | AS='nasm'
5 |
6 | C_SOURCES=`find ./src/ -name "*.c"`
7 | AS_SOURCES=`find ./src/ -name "*.asm"`
8 |
9 | CFLAGS='-m32 -c -nostdlib -nostdinc -fno-pie -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -I include'
10 | ASFLAGS='-f elf32'
11 |
12 | for c_file in $C_SOURCES
13 | do
14 | $CC $CFLAGS $c_file -o $c_file.o
15 | done
16 |
17 | for asm_file in $AS_SOURCES
18 | do
19 | $AS $ASFLAGS $asm_file -o $asm_file.o
20 | done
--------------------------------------------------------------------------------
/clib/build_test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CC='gcc'
4 | AS='nasm'
5 |
6 | SYS_SYSCALL_O='./src/sys/syscall.c.o'
7 | STDIO_O='./src/stdio.c.o'
8 | CTR0_O='./src/crt0.asm.o'
9 |
10 | CFLAGS='-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -I include'
11 |
12 | $CC $CFLAGS ./test/main.c $STDIO_O $CTR0_O $SYS_SYSCALL_O -o ./test/a.out
--------------------------------------------------------------------------------
/clib/include/stdarg.h:
--------------------------------------------------------------------------------
1 | /*
2 | https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdarg.h
3 | */
4 |
5 | /* Copyright (C) 1989-2022 Free Software Foundation, Inc.
6 | This file is part of GCC.
7 | GCC is free software; you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation; either version 3, or (at your option)
10 | any later version.
11 | GCC 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 General Public License for more details.
15 | Under Section 7 of GPL version 3, you are granted additional
16 | permissions described in the GCC Runtime Library Exception, version
17 | 3.1, as published by the Free Software Foundation.
18 | You should have received a copy of the GNU General Public License and
19 | a copy of the GCC Runtime Library Exception along with this program;
20 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 | . */
22 |
23 | /*
24 | * ISO C Standard: 7.15 Variable arguments
25 | */
26 |
27 | #ifndef _STDARG_H
28 | #ifndef _ANSI_STDARG_H_
29 | #ifndef __need___va_list
30 | #define _STDARG_H
31 | #define _ANSI_STDARG_H_
32 | #endif /* not __need___va_list */
33 | #undef __need___va_list
34 |
35 | /* Define __gnuc_va_list. */
36 |
37 | #ifndef __GNUC_VA_LIST
38 | #define __GNUC_VA_LIST
39 | typedef __builtin_va_list __gnuc_va_list;
40 | #endif
41 |
42 | /* Define the standard macros for the user,
43 | if this invocation was from the user program. */
44 | #ifdef _STDARG_H
45 |
46 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
47 | #define va_start(v, ...) __builtin_va_start(v, 0)
48 | #else
49 | #define va_start(v,l) __builtin_va_start(v,l)
50 | #endif
51 | #define va_end(v) __builtin_va_end(v)
52 | #define va_arg(v,l) __builtin_va_arg(v,l)
53 | #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L \
54 | || __cplusplus + 0 >= 201103L
55 | #define va_copy(d,s) __builtin_va_copy(d,s)
56 | #endif
57 | #define __va_copy(d,s) __builtin_va_copy(d,s)
58 |
59 | /* Define va_list, if desired, from __gnuc_va_list. */
60 | /* We deliberately do not define va_list when called from
61 | stdio.h, because ANSI C says that stdio.h is not supposed to define
62 | va_list. stdio.h needs to have access to that data type,
63 | but must not use that name. It should use the name __gnuc_va_list,
64 | which is safe because it is reserved for the implementation. */
65 |
66 | #ifdef _BSD_VA_LIST
67 | #undef _BSD_VA_LIST
68 | #endif
69 |
70 | #if defined(__svr4__) || (defined(_SCO_DS) && !defined(__VA_LIST))
71 | /* SVR4.2 uses _VA_LIST for an internal alias for va_list,
72 | so we must avoid testing it and setting it here.
73 | SVR4 uses _VA_LIST as a flag in stdarg.h, but we should
74 | have no conflict with that. */
75 | #ifndef _VA_LIST_
76 | #define _VA_LIST_
77 | #ifdef __i860__
78 | #ifndef _VA_LIST
79 | #define _VA_LIST va_list
80 | #endif
81 | #endif /* __i860__ */
82 | typedef __gnuc_va_list va_list;
83 | #ifdef _SCO_DS
84 | #define __VA_LIST
85 | #endif
86 | #endif /* _VA_LIST_ */
87 | #else /* not __svr4__ || _SCO_DS */
88 |
89 | /* The macro _VA_LIST_ is the same thing used by this file in Ultrix.
90 | But on BSD NET2 we must not test or define or undef it.
91 | (Note that the comments in NET 2's ansi.h
92 | are incorrect for _VA_LIST_--see stdio.h!) */
93 | #if !defined (_VA_LIST_) || defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__) || defined(WINNT)
94 | /* The macro _VA_LIST_DEFINED is used in Windows NT 3.5 */
95 | #ifndef _VA_LIST_DEFINED
96 | /* The macro _VA_LIST is used in SCO Unix 3.2. */
97 | #ifndef _VA_LIST
98 | /* The macro _VA_LIST_T_H is used in the Bull dpx2 */
99 | #ifndef _VA_LIST_T_H
100 | /* The macro __va_list__ is used by BeOS. */
101 | #ifndef __va_list__
102 | typedef __gnuc_va_list va_list;
103 | #endif /* not __va_list__ */
104 | #endif /* not _VA_LIST_T_H */
105 | #endif /* not _VA_LIST */
106 | #endif /* not _VA_LIST_DEFINED */
107 | #if !(defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__))
108 | #define _VA_LIST_
109 | #endif
110 | #ifndef _VA_LIST
111 | #define _VA_LIST
112 | #endif
113 | #ifndef _VA_LIST_DEFINED
114 | #define _VA_LIST_DEFINED
115 | #endif
116 | #ifndef _VA_LIST_T_H
117 | #define _VA_LIST_T_H
118 | #endif
119 | #ifndef __va_list__
120 | #define __va_list__
121 | #endif
122 |
123 | #endif /* not _VA_LIST_, except on certain systems */
124 |
125 | #endif /* not __svr4__ */
126 |
127 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
128 | #define __STDC_VERSION_STDARG_H__ 202311L
129 | #endif
130 |
131 | #endif /* _STDARG_H */
132 |
133 | #endif /* not _ANSI_STDARG_H_ */
134 | #endif /* not _STDARG_H */
--------------------------------------------------------------------------------
/clib/include/stdio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #ifndef _STDIO_H
7 | #define _STDIO_H
8 |
9 | #include
10 |
11 | /* OS */
12 | #define QUANTUM_OS 1
13 |
14 | #define __linux__ 1
15 | #define __linux 1
16 |
17 | #define __unix__ 1
18 | #define __unix 1
19 |
20 | /* Some important macros */
21 | #define BUFSIZ 8192
22 | #define EOF -1
23 |
24 | #ifndef NULL
25 | # define NULL (void*)0
26 | #endif
27 |
28 | #define P_tmpdir "/tmp"
29 |
30 | /* Types */
31 |
32 | #define __WINT_TYPE__ unsigned int
33 |
34 | typedef long __off_t;
35 | typedef unsigned long __size_t;
36 | typedef long int __ssize_t;
37 |
38 | /* mbstate structure */
39 | typedef struct __mbstate_t {
40 | int __count;
41 | union {
42 | __WINT_TYPE__ __wch;
43 | char __wchb[4];
44 | } __value; /* Value so far. */
45 | } __mbstate_t;
46 |
47 | /* fpos structure */
48 | typedef struct __fpos_t {
49 | __off_t __pos;
50 | __mbstate_t __state;
51 | } __fpos_t;
52 |
53 | /* FILE structure */
54 | struct _IO_FILE;
55 | struct _IO_marker;
56 | struct _IO_codecvt;
57 | struct _IO_wide_data;
58 |
59 | typedef void _IO_lock_t;
60 |
61 | typedef struct _IO_FILE {
62 | int _flags;
63 |
64 | char* _IO_read_ptr;
65 | char* _IO_read_end;
66 | char* _IO_read_base;
67 | char* _IO_write_base;
68 | char* _IO_write_ptr;
69 | char* _IO_write_end;
70 | char* _IO_buf_base;
71 | char* _IO_buf_end;
72 |
73 | char* _IO_save_base;
74 | char* _IO_backup_base;
75 | char* _IO_save_end;
76 |
77 | struct _IO_marker* _markers;
78 |
79 | struct _IO_FILE* _chain;
80 |
81 | int _fileno;
82 | int _flags2;
83 | __off_t _old_offset;
84 |
85 | unsigned short _cur_column;
86 | signed char _vtable_offset;
87 | char _shortbuf[1];
88 |
89 | _IO_lock_t *_lock;
90 | } __FILE;
91 |
92 | typedef __FILE FILE;
93 | typedef __fpos_t fpos_t;
94 | typedef __off_t off_t;
95 | typedef __size_t size_t;
96 | typedef __ssize_t ssize_t;
97 |
98 | /* IO Functions */
99 | #ifdef __cplusplus
100 | extern "C" {
101 | #endif
102 |
103 | void clearerr(FILE *);
104 |
105 | char *ctermid(char *);
106 |
107 | int dprintf(int, const char *restrict, ...);
108 |
109 | int fclose(FILE *);
110 |
111 | FILE *fdopen(int, const char *);
112 |
113 | int feof(FILE *);
114 |
115 | int ferror(FILE *);
116 |
117 | int fflush(FILE *);
118 |
119 | int fgetc(FILE *);
120 |
121 | int fgetpos(FILE *restrict, fpos_t *_restrict);
122 |
123 | char *fgets(char *restrict, int, FILE *_restrict);
124 |
125 | int fileno(FILE *);
126 |
127 | void flockfile(FILE *);
128 |
129 | FILE *fmemopen(void *restrict, size_t, const char *_restrict);
130 |
131 | FILE *fopen(const char *restrict, const char *_restrict);
132 |
133 | int fprintf(FILE *restrict, const char *_restrict, ...);
134 |
135 | int fputc(int, FILE *);
136 |
137 | int fputs(const char *restrict, FILE *_restrict);
138 |
139 | size_t fread(void *restrict, size_t, size_t, FILE *_restrict);
140 |
141 | FILE *freopen(const char *restrict, const char *_restrict, FILE *__restrict);
142 |
143 | int fscanf(FILE *restrict, const char *_restrict, ...);
144 |
145 | int fseek(FILE *, long, int);
146 |
147 | int fseeko(FILE *, off_t, int);
148 |
149 | int fsetpos(FILE *, const fpos_t *);
150 |
151 | long ftell(FILE *);
152 |
153 | off_t ftello(FILE *);
154 |
155 | int ftrylockfile(FILE *);
156 |
157 | void funlockfile(FILE *);
158 |
159 | size_t fwrite(const void *restrict, size_t, size_t, FILE *_restrict);
160 |
161 | int getc(FILE *);
162 |
163 | int getchar(void);
164 |
165 | int getc_unlocked(FILE *);
166 |
167 | int getchar_unlocked(void);
168 |
169 | ssize_t getdelim(char **restrict, size_t *_restrict, int, FILE *__restrict);
170 |
171 | ssize_t getline(char **restrict, size_t *_restrict, FILE *__restrict);
172 |
173 | char *gets(char *);
174 |
175 | FILE *open_memstream(char **, size_t *);
176 |
177 | int pclose(FILE *);
178 |
179 | void perror(const char *);
180 |
181 | FILE *popen(const char *, const char *);
182 |
183 | int printf(const char *restrict, ...);
184 |
185 | int putc(int, FILE *);
186 |
187 | int putchar(int);
188 |
189 | int putc_unlocked(int, FILE *);
190 |
191 | int putchar_unlocked(int);
192 |
193 | int puts(const char *);
194 |
195 | int remove(const char *);
196 |
197 | int rename(const char *, const char *);
198 |
199 | int renameat(int, const char *, int, const char *);
200 |
201 | void rewind(FILE *);
202 |
203 | int scanf(const char *restrict, ...);
204 |
205 | void setbuf(FILE *restrict, char *_restrict);
206 |
207 | int setvbuf(FILE *restrict, char *_restrict, int, size_t);
208 |
209 | int snprintf(char *restrict, size_t, const char *_restrict, ...);
210 |
211 | int sprintf(char *restrict, const char *_restrict, ...);
212 |
213 | int sscanf(const char *restrict, const char *_restrict, ...);
214 |
215 | char *tempnam(const char *, const char *);
216 |
217 | FILE *tmpfile(void);
218 |
219 | char *tmpnam(char *);
220 |
221 | int ungetc(int, FILE *);
222 |
223 | int vdprintf(int, const char *restrict, va_list);
224 |
225 | int vfprintf(FILE *restrict, const char *_restrict, va_list);
226 |
227 | int vfscanf(FILE *restrict, const char *_restrict, va_list);
228 |
229 | int vprintf(const char *restrict, va_list);
230 |
231 | int vscanf(const char *restrict, va_list);
232 |
233 | int vsnprintf(char *restrict, size_t, const char *_restrict, va_list);
234 |
235 | int vsprintf(char *restrict, const char *_restrict, va_list);
236 |
237 | int vsscanf(const char *restrict, const char *_restrict, va_list);
238 |
239 | #ifdef __cplusplus
240 | }
241 | #endif
242 |
243 | #endif /* _STDIO_H */
--------------------------------------------------------------------------------
/clib/include/sys/syscall.h:
--------------------------------------------------------------------------------
1 | #ifndef _SYS_SYSCALL_H
2 | #define _SYS_SYSCALL_H
3 |
4 | #define SYS_read 3
5 | #define SYS_write 4
6 | #define SYS_open 5
7 | #define SYS_creat 8
8 | #define SYS_time 13
9 |
10 | #define MAX_SYSCALLS SYS_rseq
11 |
12 | #define ASM__SET_REG(reg, value) asm volatile ("mov %0, %%" reg : : "r" (value) : );
13 |
14 | #define ASM__SYSCALL() asm volatile("int $0x80");
15 |
16 | #ifndef _SYSCALL0_FUNC__
17 | # define _SYSCALL0_FUNC__
18 | unsigned int
19 | syscall0(unsigned int _syscall);
20 | #endif /* _SYSCALL0_FUNC__ */
21 |
22 | #ifndef _SYSCALL1_FUNC__
23 | # define _SYSCALL1_FUNC__
24 | unsigned int
25 | syscall1(unsigned int _syscall, unsigned int arg1);
26 | #endif /* _SYSCALL1_FUNC__ */
27 |
28 | #ifndef _SYSCALL2_FUNC__
29 | # define _SYSCALL2_FUNC__
30 | unsigned int
31 | syscall2(unsigned int _syscall, unsigned int arg1, unsigned int arg2);
32 | #endif /* _SYSCALL2_FUNC__ */
33 |
34 | #ifndef _SYSCALL3_FUNC__
35 | # define _SYSCALL3_FUNC__
36 | unsigned int
37 | syscall3(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3);
38 | #endif /* _SYSCALL3_FUNC__ */
39 |
40 | #ifndef _SYSCALL4_FUNC__
41 | # define _SYSCALL4_FUNC__
42 | unsigned int
43 | syscall4(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4);
44 | #endif /* _SYSCALL4_FUNC__ */
45 |
46 | #ifndef _SYSCALL5_FUNC__
47 | # define _SYSCALL5_FUNC__
48 | unsigned int
49 | syscall5(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
50 | #endif /* _SYSCALL5_FUNC__ */
51 |
52 | #ifndef _SYSCALL6_FUNC__
53 | # define _SYSCALL6_FUNC__
54 | unsigned int
55 | syscall6(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5, unsigned int arg6);
56 | #endif /* _SYSCALL6_FUNC__ */
57 |
58 | #endif /* _SYS_SYSCALL_H */
--------------------------------------------------------------------------------
/clib/src/crt0.asm:
--------------------------------------------------------------------------------
1 | ;
2 | ; QuantumOS Copyright (c) 2022-2023
3 | ; - Solindek
4 | ;
5 |
6 | section .text
7 | global _start
8 |
9 | extern main
10 |
11 | _start:
12 | ; TODO: get the arguments from the stack etc.
13 | call main
14 |
15 | ; Exit syscall
16 | mov ebx, eax ; Move value returned from main to ebx
17 | mov eax, 1
18 | int 0x80
19 |
--------------------------------------------------------------------------------
/clib/src/crt0.asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/clib/src/crt0.asm.o
--------------------------------------------------------------------------------
/clib/src/stdio.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include "../include/sys/syscall.h"
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | void clearerr(FILE *);
16 |
17 | char *ctermid(char *);
18 |
19 | int dprintf(int, const char *restrict, ...);
20 |
21 | int fclose(FILE *);
22 |
23 | FILE *fdopen(int, const char *);
24 |
25 | int feof(FILE *);
26 |
27 | int ferror(FILE *);
28 |
29 | int fflush(FILE *);
30 |
31 | int fgetc(FILE *);
32 |
33 | int fgetpos(FILE *restrict, fpos_t *_restrict);
34 |
35 | char *fgets(char *restrict, int, FILE *_restrict);
36 |
37 | int fileno(FILE *);
38 |
39 | void flockfile(FILE *);
40 |
41 | FILE *fmemopen(void *restrict, size_t, const char *_restrict);
42 |
43 | FILE *fopen(const char *restrict, const char *_restrict);
44 |
45 | int fprintf(FILE *restrict, const char *_restrict, ...);
46 |
47 | int fputc(int, FILE *);
48 |
49 | int fputs(const char *restrict, FILE *_restrict);
50 |
51 | size_t fread(void *restrict, size_t, size_t, FILE *_restrict);
52 |
53 | FILE *freopen(const char *restrict, const char *_restrict, FILE *__restrict);
54 |
55 | int fscanf(FILE *restrict, const char *_restrict, ...);
56 |
57 | int fseek(FILE *, long, int);
58 |
59 | int fseeko(FILE *, off_t, int);
60 |
61 | int fsetpos(FILE *, const fpos_t *);
62 |
63 | long ftell(FILE *);
64 |
65 | off_t ftello(FILE *);
66 |
67 | int ftrylockfile(FILE *);
68 |
69 | void funlockfile(FILE *);
70 |
71 | size_t fwrite(const void *restrict, size_t, size_t, FILE *_restrict);
72 |
73 | int getc(FILE *);
74 |
75 | int getchar(void);
76 |
77 | int getc_unlocked(FILE *);
78 |
79 | int getchar_unlocked(void);
80 |
81 | ssize_t getdelim(char **restrict, size_t *_restrict, int, FILE *__restrict);
82 |
83 | ssize_t getline(char **restrict, size_t *_restrict, FILE *__restrict);
84 |
85 | char *gets(char *);
86 |
87 | FILE *open_memstream(char **, size_t *);
88 |
89 | int pclose(FILE *);
90 |
91 | void perror(const char *);
92 |
93 | FILE *popen(const char *, const char *);
94 |
95 | int printf(const char* __format, ...)
96 | {
97 | va_list arg;
98 | va_start(arg, __format);
99 | // int __return = vprintf(__format, arg);
100 | int __return = 0;
101 | va_end(arg);
102 |
103 | return __return;
104 | }
105 |
106 | int putc(int, FILE *);
107 |
108 | int putchar(int);
109 |
110 | int putc_unlocked(int, FILE *);
111 |
112 | int putchar_unlocked(int);
113 |
114 | int puts(const char* __msg)
115 | {
116 | int __msg_index = 0;
117 | int __msg_len = 0;
118 | int __fd = 0;
119 |
120 | while (__msg[__msg_index] != '\0')
121 | __msg_index++;
122 |
123 | syscall3(SYS_write, __fd, __msg, __msg_len);
124 | }
125 |
126 | int remove(const char *);
127 |
128 | int rename(const char *, const char *);
129 |
130 | int renameat(int, const char *, int, const char *);
131 |
132 | void rewind(FILE *);
133 |
134 | int scanf(const char *restrict, ...);
135 |
136 | void setbuf(FILE *restrict, char *_restrict);
137 |
138 | int setvbuf(FILE *restrict, char *_restrict, int, size_t);
139 |
140 | int snprintf(char *restrict, size_t, const char *_restrict, ...);
141 |
142 | int sprintf(char *restrict, const char *_restrict, ...);
143 |
144 | int sscanf(const char *restrict, const char *_restrict, ...);
145 |
146 | char *tempnam(const char *, const char *);
147 |
148 | FILE *tmpfile(void);
149 |
150 | char *tmpnam(char *);
151 |
152 | int ungetc(int, FILE *);
153 |
154 | int vdprintf(int, const char *restrict, va_list);
155 |
156 | int vfprintf(FILE *restrict, const char *_restrict, va_list);
157 |
158 | int vfscanf(FILE *restrict, const char *_restrict, va_list);
159 |
160 | int vprintf(const char *restrict, va_list);
161 |
162 | int vscanf(const char *restrict, va_list);
163 |
164 | int vsnprintf(char *restrict, size_t, const char *_restrict, va_list);
165 |
166 | int vsprintf(char *restrict, const char *_restrict, va_list);
167 |
168 | int vsscanf(const char *restrict, const char *_restrict, va_list);
169 |
170 | #ifdef __cplusplus
171 | }
172 | #endif
--------------------------------------------------------------------------------
/clib/src/stdio.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/clib/src/stdio.c.o
--------------------------------------------------------------------------------
/clib/src/sys/syscall.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | unsigned int
4 | syscall0(unsigned int _syscall)
5 | {
6 | ASM__SET_REG("eax", _syscall);
7 | ASM__SYSCALL();
8 | }
9 |
10 | unsigned int
11 | syscall1(unsigned int _syscall, unsigned int arg1)
12 | {
13 | ASM__SET_REG("ebx", arg1);
14 | ASM__SET_REG("eax", _syscall);
15 | ASM__SYSCALL();
16 | }
17 |
18 | unsigned int
19 | syscall2(unsigned int _syscall, unsigned int arg1, unsigned int arg2)
20 | {
21 | ASM__SET_REG("ebx", arg1);
22 | ASM__SET_REG("ecx", arg2);
23 | ASM__SET_REG("eax", _syscall);
24 | ASM__SYSCALL();
25 | }
26 |
27 | unsigned int
28 | syscall3(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3)
29 | {
30 | ASM__SET_REG("ebx", arg1);
31 | ASM__SET_REG("ecx", arg2);
32 | ASM__SET_REG("edx", arg3);
33 | ASM__SET_REG("eax", _syscall);
34 | ASM__SYSCALL();
35 | }
36 |
37 | unsigned int
38 | syscall4(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4)
39 | {
40 | ASM__SET_REG("ebx", arg1);
41 | ASM__SET_REG("ecx", arg2);
42 | ASM__SET_REG("edx", arg3);
43 | ASM__SET_REG("esi", arg4);
44 | ASM__SET_REG("eax", _syscall);
45 | ASM__SYSCALL();
46 | }
47 |
48 | unsigned int
49 | syscall5(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5)
50 | {
51 | ASM__SET_REG("ebx", arg1);
52 | ASM__SET_REG("ecx", arg2);
53 | ASM__SET_REG("edx", arg3);
54 | ASM__SET_REG("esi", arg4);
55 | ASM__SET_REG("edi", arg5);
56 | ASM__SET_REG("eax", _syscall);
57 | ASM__SYSCALL();
58 | }
59 |
60 | unsigned int
61 | syscall6(unsigned int _syscall, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5, unsigned int arg6)
62 | {
63 | ASM__SET_REG("ebx", arg1);
64 | ASM__SET_REG("ecx", arg2);
65 | ASM__SET_REG("edx", arg3);
66 | ASM__SET_REG("esi", arg4);
67 | ASM__SET_REG("edi", arg5);
68 | ASM__SET_REG("ebp", arg6);
69 | ASM__SET_REG("eax", _syscall);
70 | ASM__SYSCALL();
71 | }
--------------------------------------------------------------------------------
/clib/src/sys/syscall.c.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/clib/src/sys/syscall.c.o
--------------------------------------------------------------------------------
/clib/test/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/clib/test/a.out
--------------------------------------------------------------------------------
/clib/test/main.c:
--------------------------------------------------------------------------------
1 | #include "../include/stdio.h"
2 |
3 | int main(int argc, char** argv)
4 | {
5 | puts("Hello, World");
6 | return 0;
7 | }
--------------------------------------------------------------------------------
/config/grub.cfg:
--------------------------------------------------------------------------------
1 | menuentry "Quantum OS" {
2 | multiboot "/boot/kernel.elf"
3 | }
4 |
--------------------------------------------------------------------------------
/config/linker.ld:
--------------------------------------------------------------------------------
1 | ENTRY(_start)
2 |
3 | SECTIONS
4 | {
5 | __kernel_section_start = .;
6 | . = 1M;
7 |
8 | .text : {
9 | __kernel_text_section_start = .;
10 | *(.multiboot)
11 | *(.text)
12 | . = ALIGN(4096);
13 | __kernel_text_section_end = .;
14 | }
15 |
16 | .rodata : {
17 | __kernel_rodata_section_start = .;
18 | *(.rodata)
19 | __kernel_rodata_section_end = .;
20 | }
21 |
22 | .data : {
23 | __kernel_data_section_start = .;
24 | *(.data)
25 | . = ALIGN(4096);
26 | __kernel_data_section_end = .;
27 | }
28 |
29 | .bss : {
30 | __kernel_bss_section_start = .;
31 | bss = .; _bss = .; __bss = .;
32 | *(.bss)
33 | . = ALIGN(4096);
34 | __kernel_bss_section_end = .;
35 | }
36 |
37 | end = .; _end = .; __end = .;
38 | __kernel_section_end = .;
39 | }
40 |
--------------------------------------------------------------------------------
/core/gtree.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | __gtree_t *gtree_create(void)
13 | {
14 | return (__gtree_t *) kcalloc(1, sizeof(__gtree_t));
15 | }
16 |
17 | __gtreenode_t *gtree_node_create(void *__value)
18 | {
19 | __gtreenode_t *__node = kcalloc(1, sizeof(__gtreenode_t));
20 |
21 | __node->__children = list_create();
22 | __node->__val = __value;
23 |
24 | return __node;
25 | }
26 |
27 | __gtreenode_t *gtree_insert(__gtree_t *__tree, __gtreenode_t *__subroot, void *__value)
28 | {
29 | __gtreenode_t *__treenode = kcalloc(1, sizeof(__gtreenode_t));
30 |
31 | __treenode->__children = list_create();
32 | __treenode->__val = __value;
33 |
34 | if (!__tree->__root)
35 | {
36 | __tree->__root = __treenode;
37 |
38 | return __treenode;
39 | }
40 |
41 | list_insert_front(__subroot->__children, __treenode);
42 |
43 | return __treenode;
44 | }
45 |
46 | __gtreenode_t *gtree_find_parent(__gtree_t *__tree, __gtreenode_t *__node, int *__cindex)
47 | {
48 | if (__node == __tree->__root)
49 | {
50 | return NULL;
51 | }
52 |
53 | return gtree_find_parent_recur(__tree, __node, __tree->__root, __cindex);
54 | }
55 |
56 | __gtreenode_t *gtree_find_parent_recur(__gtree_t *__tree, __gtreenode_t *__node, __gtreenode_t *__subroot, int *__cindex)
57 | {
58 | int i = 0;
59 |
60 | if ((i == list_contains(__subroot->__children, __node)) != -1)
61 | {
62 | *__cindex = i;
63 |
64 | return __subroot;
65 | }
66 |
67 | FOREACH(__child, __subroot->__children)
68 | {
69 | __gtreenode_t *__ret = gtree_find_parent_recur(__tree, __node, __child->__val, __cindex);
70 |
71 | if (__ret != NULL)
72 | {
73 | return __ret;
74 | }
75 | }
76 |
77 | return NULL;
78 | }
79 |
80 | void gtree_remove(__gtree_t *__tree, __gtreenode_t *__node)
81 | {
82 | int __cindex = -1;
83 |
84 | __gtreenode_t *__parent = gtree_find_parent(__tree, __node, &__cindex);
85 |
86 | if (__parent != NULL)
87 | {
88 | __gtreenode_t *__target = list_remove_by_index(__parent->__children, __cindex);
89 |
90 | kfree(__target);
91 | }
92 | }
93 |
94 | void gtree_to_list_recur(__gtreenode_t *__subroot, __list_t *__list)
95 | {
96 | if (__subroot == NULL)
97 | {
98 | return;
99 | }
100 |
101 | FOREACH(__child, __subroot->__children)
102 | {
103 | __gtreenode_t *__curr = (__gtreenode_t *) __child->__val;
104 |
105 | void *__val = __curr->__val;
106 |
107 | list_insert_back(__list, __val);
108 |
109 | gtree_to_list_recur(__child->__val, __list);
110 | }
111 | }
112 |
113 | void gtree_to_list(__gtree_t *__tree, __list_t *__list)
114 | {
115 | gtree_to_list_recur(__tree->__root, __list);
116 | }
117 |
118 | void gtree_to_array_recur(__gtreenode_t *__subroot, void **__array, int *__size)
119 | {
120 | if (__subroot == NULL)
121 | {
122 | return;
123 | }
124 |
125 | void *__val = (void *) __subroot->__val;
126 |
127 | __array[*__size] = __val;
128 |
129 | *__size = (*__size + 1);
130 |
131 | FOREACH(__child, __subroot->__children)
132 | {
133 | gtree_to_array_recur(__child->__val, __array, __size);
134 | }
135 | }
136 |
137 | void gtree_to_array(__gtree_t *__tree, void **__array, int *__size)
138 | {
139 | gtree_to_array_recur(__tree->__root, __array, __size);
140 | }
141 |
--------------------------------------------------------------------------------
/core/kpanic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | * - CodeSploit
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include
14 |
15 | void kpanic(const char *__message)
16 | {
17 | debug_printf("KERNEL PANIC: [%s]\nHALTING THE SYSTEM!", __message);
18 | print_set_color(220, 0, 0);
19 | printf("KERNEL PANIC: [%s]\nHALTING THE SYSTEM!\n", __message);
20 |
21 | stack_frame_t* call_stack;
22 | asm volatile ("mov %%ebp, %0" : "=r"(call_stack));
23 |
24 | printf("Call stack:\n");
25 | for (int frame = 0; call_stack && (frame < 10); frame++)
26 | {
27 | elf32_sym_t* sym = get_ksym_by_address(call_stack->eip);
28 | if (sym != NULL)
29 | printf("- 0x%x [%s] \n", call_stack->eip, (char*)get_shdr_string(sym->name));
30 | else
31 | printf("- 0x%x [unknown_function] \n", call_stack->eip);
32 | call_stack = (stack_frame_t*)call_stack->ebp;
33 | }
34 |
35 | for (;;)
36 | asm volatile ("hlt");
37 | }
38 |
--------------------------------------------------------------------------------
/core/list.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | __list_t *list_create(void)
13 | {
14 | __list_t *__list = kcalloc(1, sizeof(__list_t));
15 |
16 | return __list;
17 | }
18 |
19 | unsigned int list_size(__list_t *__list)
20 | {
21 | if (!__list)
22 | {
23 | return 0;
24 | }
25 |
26 | return __list->__size;
27 | }
28 |
29 | __listnode_t *list_insert_front(__list_t *__list, void *__val)
30 | {
31 | __listnode_t *__node = kcalloc(1, sizeof(__listnode_t));
32 |
33 | __list->__head->__prev = __node;
34 |
35 | __node->__next = __list->__head;
36 | __node->__val = __val;
37 |
38 | if (!__list->__head)
39 | {
40 | __list->__tail = __node;
41 | }
42 |
43 | __list->__head = __node;
44 | __list->__size++;
45 |
46 | return __node;
47 | }
48 |
49 | void list_insert_back(__list_t *__list, void *__val)
50 | {
51 | __listnode_t *__node = kcalloc(1, sizeof(__listnode_t));
52 |
53 | __node->__prev = __list->__tail;
54 |
55 | if (__list->__tail)
56 | {
57 | __list->__tail->__next = __node;
58 |
59 | __node->__val = __val;
60 |
61 | if (!__list->__head)
62 | {
63 | __list->__head = __node;
64 | }
65 |
66 | __list->__tail = __node;
67 | __list->__size++;
68 | }
69 | }
70 |
71 | void *list_remove_node(__list_t *__list, __listnode_t *__node)
72 | {
73 | void *__val = __node->__val;
74 |
75 | if (__list->__head == __node)
76 | {
77 | return list_remove_front(__list);
78 | }
79 | else if (__list->__tail == __node)
80 | {
81 | return list_remove_back(__list);
82 | }
83 | else
84 | {
85 | __node->__next->__prev = __node->__prev;
86 | __node->__prev->__next = __node->__next;
87 |
88 | __list->__size--;
89 |
90 | kfree(__node);
91 | }
92 |
93 | return __val;
94 | }
95 |
96 | void *list_remove_front(__list_t *__list)
97 | {
98 | if (!__list->__head)
99 | {
100 | return 0;
101 | }
102 |
103 | __listnode_t *__node = __list->__head;
104 |
105 | void *__val = __node->__val;
106 |
107 | __list->__head = __node->__next;
108 |
109 | if (__list->__head)
110 | {
111 | __list->__head->__prev = NULL;
112 | }
113 |
114 | kfree(__node);
115 |
116 | __list->__size--;
117 |
118 | return __val;
119 | }
120 |
121 | void *list_remove_back(__list_t *__list)
122 | {
123 | if (!__list->__head)
124 | {
125 | return 0;
126 | }
127 |
128 | __listnode_t *__node = __list->__tail;
129 |
130 | void *__val = __node->__val;
131 |
132 | __list->__tail = __node->__prev;
133 |
134 | if (__list->__tail)
135 | {
136 | __list->__tail->__next = NULL;
137 | }
138 |
139 | kfree(__node);
140 |
141 | __list->__size--;
142 |
143 | return __val;
144 | }
145 |
146 | void list_push(__list_t *__list, void *__val)
147 | {
148 | list_insert_back(__list, __val);
149 | }
150 |
151 | __listnode_t *list_pop(__list_t *__list)
152 | {
153 | if (!__list->__head)
154 | {
155 | return NULL;
156 | }
157 |
158 | __listnode_t *__node = __list->__tail;
159 |
160 | __list->__tail = __node->__prev;
161 |
162 | if (__list->__tail)
163 | {
164 | __list->__tail->__next = NULL;
165 | }
166 |
167 | __list->__size--;
168 |
169 | return __node;
170 | }
171 |
172 | void list_enqueue(__list_t *__list, void *__val)
173 | {
174 | list_insert_front(__list, __val);
175 | }
176 |
177 | __listnode_t *list_dequeue(__list_t *__list)
178 | {
179 | return list_pop(__list);
180 | }
181 |
182 | void *list_peek_front(__list_t *__list)
183 | {
184 | if (!__list->__head)
185 | {
186 | return NULL;
187 | }
188 |
189 | return __list->__head->__val;
190 | }
191 |
192 | void *list_peek_back(__list_t *__list)
193 | {
194 | if (!__list->__tail)
195 | {
196 | return NULL;
197 | }
198 |
199 | return __list->__tail->__val;
200 | }
201 |
202 | void list_destroy(__list_t *__list)
203 | {
204 | __listnode_t *__node = __list->__head;
205 |
206 | while (__node != NULL)
207 | {
208 | __listnode_t *__temp = __node;
209 |
210 | __node = __node->__next;
211 |
212 | kfree(__temp);
213 | }
214 |
215 | kfree(__list);
216 | }
217 |
218 | void listnode_destroy(__listnode_t *__node)
219 | {
220 | kfree(__node);
221 | }
222 |
223 | int list_contains(__list_t *__list, void *__val)
224 | {
225 | int i = 0;
226 |
227 | FOREACH(__listnode, __list)
228 | {
229 | if (__listnode->__val == __val)
230 | {
231 | return i;
232 | }
233 |
234 | i++;
235 | }
236 |
237 | return -1;
238 | }
239 |
240 | __listnode_t *list_get_node_by_index(__list_t *__list, int __index)
241 | {
242 | if (__index < 0 || __index >= list_size(__list))
243 | {
244 | return NULL;
245 | }
246 |
247 | int c = 0;
248 |
249 | FOREACH(__listnode, __list)
250 | {
251 | if (__index == c)
252 | {
253 | return __listnode;
254 | }
255 |
256 | c++;
257 | }
258 |
259 | return NULL;
260 | }
261 |
262 | void *list_remove_by_index(__list_t *__list, int __index)
263 | {
264 | __listnode_t *__node = list_get_node_by_index(__list, __index);
265 |
266 | return list_remove_node(__list, __node);
267 | }
268 |
--------------------------------------------------------------------------------
/core/tga.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | tga_structure_t* parse_tga(char* data, int data_size)
13 | {
14 | quantum_info(__FILE__, 2, " TGA ", "Parsing tga");
15 |
16 | tga_structure_t* tga_structure = kmalloc(sizeof(tga_header_t));
17 | tga_structure->header = (tga_header_t*)data;
18 |
19 | if (tga_structure->header->signature != 0)
20 | {
21 | quantum_info(__FILE__, 1, " TGA ", "This isn't an tga file format");
22 | return NULL;
23 | }
24 |
25 | if (tga_structure->header->colormap != 0)
26 | {
27 | quantum_info(__FILE__, 1, " TGA ", "This isn't an tga file format or it is not correct");
28 | return NULL;
29 | }
30 |
31 | if (tga_structure->header->encoding != 2)
32 | {
33 | quantum_info(__FILE__, 1, " TGA ", "Unsupported encoding of tga file");
34 | return NULL;
35 | }
36 |
37 | if (tga_structure->header->bpp != 32)
38 | {
39 | quantum_info(__FILE__, 1, " TGA ", "This tga file is not correct because bpp is not 32");
40 | return NULL;
41 | }
42 |
43 | quantum_info(__FILE__, 0, " TGA ", "This is an tga file format");
44 | quantum_info(__FILE__, 0, " TGA ", "Image size: %dx%d", tga_structure->header->h, tga_structure->header->w);
45 | quantum_info(__FILE__, 0, " TGA ", "Encoding: %d", tga_structure->header->encoding);
46 | quantum_info(__FILE__, 0, " TGA ", "BPP: %d", tga_structure->header->bpp);
47 | quantum_info(__FILE__, 0, " TGA ", "Pixel type: %d", tga_structure->header->pixeltype);
48 |
49 | tga_structure->pixel_data = data + sizeof(tga_header_t);
50 | return tga_structure;
51 | }
--------------------------------------------------------------------------------
/core/time.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | const unsigned char month_days[] = {
11 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
12 | };
13 |
14 | unsigned long date_to_timestamp(date_t* date)
15 | {
16 | unsigned long unixtime = 0;
17 |
18 | unsigned long unixyears = date->year - 1970;
19 | unixtime += ((unixyears + 2) / 4) * 86400;
20 | unixtime += unixyears * 86400 * 365;
21 |
22 | if (((date->year % 100) || (((date->year % 400) == 0))) && ((date->year % 4) == 0) && (date->month < 3))
23 | {
24 | unixtime -= 86400;
25 | }
26 |
27 | date->month--;
28 | while (date->month)
29 | {
30 | date->month--;
31 | unixtime += month_days[date->month] * 86400;
32 | }
33 |
34 | unixtime += (unsigned long)date->second;
35 | unixtime += ((unsigned long)date->minute) * 60;
36 | unixtime += ((unsigned long)date->hour) * 3600;
37 | unixtime += ((unsigned long)date->day - 1) * 86400;
38 |
39 | return unixtime;
40 | }
--------------------------------------------------------------------------------
/count_src_lines.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "C: "
4 | for f in $(find . -name "*.c"); do cat $f; done | wc -l
5 |
6 | echo "ASM: "
7 | for f in $(find . -name "*.asm"); do cat $f; done | wc -l
8 |
9 | echo "H: "
10 | for f in $(find . -name "*.h"); do cat $f; done | wc -l
11 |
--------------------------------------------------------------------------------
/drivers/ac97.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | void ac97_write_global_control(unsigned short bar0, unsigned short bar1, unsigned int port)
13 | {
14 |
15 | }
16 |
17 | int ac97_initialize(__pci_device_t* dev)
18 | {
19 | quantum_info(__FILE__, 0, " AC97 ", "Initializng AC97 driver sound card");
20 |
21 | // Get the pci common header so we can get the bar0 and bar1
22 |
23 | /* The following lines are commented because of PCI rewrite >:)
24 | - Sincerely yours Code-Sploit
25 | */
26 | /*
27 | Hi, thanks for writing a cool looking PCI rewrite... long time no meet, anyways
28 | ac97 drivers will be writted when i will have time :)
29 | - Only yours handsome Solindek
30 | */
31 |
32 | // GET_COMMON_HEADER_PCI(pci_header, dev);
33 | // GET_BAR_FROM_PCI_HEADER(pci_header, ac_bar0, ac_bar1);
34 |
35 | // Write to global control register 0x02, but we need pci_write to this!
36 | // Code-Sploit implement pci_write please my handsome boy
37 |
38 | return 0;
39 | }
40 |
41 | void ac97_play_sound(unsigned char* sound_data);
--------------------------------------------------------------------------------
/drivers/debug.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 |
14 | void debug_putc(char c)
15 | {
16 | pio_outb(DEBUG_PORT, c);
17 | }
18 |
19 | void debug_print(char* buf)
20 | {
21 | int i = 0;
22 | while (buf[i] != '\0')
23 | debug_putc(buf[i]);
24 | }
25 |
26 | void debug_printf_va(char* format, va_list arg)
27 | {
28 | int format_int;
29 | double format_double;
30 | float format_float;
31 | long format_long;
32 | char format_char;
33 | char *format_str;
34 | char bufprint[1024];
35 |
36 | for (int i = 0; i < strlen(format); i++)
37 | {
38 | char c = format[i];
39 |
40 | if (c == '%')
41 | {
42 | i++;
43 | c = format[i];
44 |
45 | switch (c)
46 | {
47 | case '%':
48 | debug_putc('%');
49 | break;
50 | case 'd':
51 | case 'i':
52 | case 'D':
53 | case 'I':
54 | case 'o':
55 | case 'O':
56 | case 'x':
57 | case 'X':
58 | case 'h':
59 | case 'H':
60 | format_int = va_arg(arg, int);
61 | if (format_int < 0)
62 | {
63 | debug_putc('-');
64 | format_int *= -1;
65 | }
66 |
67 | if (c == 'd' || c == 'i' || c == 'D' || c == 'I') // Decimal
68 | itoa(format_int, bufprint, 10);
69 | else if (c == 'o' || c == 'O') // Octals
70 | itoa(format_int, bufprint, 8);
71 | else if (c == 'x' || c == 'X' || c == 'h' || c == 'H') // Hexadecimal
72 | itoa(format_int, bufprint, 16);
73 |
74 | for (int i = 0; bufprint[i] != '\0'; i++)
75 | debug_putc(bufprint[i]);
76 | kmemset((unsigned char *)bufprint, 0, 1024);
77 | break;
78 | case 'c':
79 | case 'C':
80 | format_char = va_arg(arg, int);
81 | debug_putc((char)format_char);
82 | break;
83 | case 's':
84 | case 'S':
85 | format_str = va_arg(arg, char *);
86 | for (int i2 = 0; i2 < strlen(format_str); i2++)
87 | debug_putc(format_str[i2]);
88 | break;
89 | case 'l':
90 | case 'L':
91 | format_long = va_arg(arg, long long);
92 | ltoa(format_long, bufprint);
93 | for (int i = 0; bufprint[i] != '\0'; i++)
94 | debug_putc(bufprint[i]);
95 | kmemset((unsigned char *)bufprint, 0, 1024);
96 | default:
97 | break;
98 | }
99 | }
100 | else
101 | debug_putc(c);
102 | }
103 | }
104 |
105 | void debug_printf(char* format, ...)
106 | {
107 | va_list arg;
108 | va_start(arg, format);
109 | debug_printf_va(format, arg);
110 | va_end(arg);
111 | }
--------------------------------------------------------------------------------
/drivers/mouse.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 | #include
12 |
13 | #include
14 |
15 | static int mouse_x = 0;
16 | static int mouse_y = 0;
17 |
18 | static unsigned char mouse_cycle = 0;
19 | static char mouse_byte[3];
20 |
21 | void quantum_mouse_init()
22 | {
23 | // Set default mouse cords
24 | mouse_x = get_screen_x() / 2;
25 | mouse_y = get_screen_y() / 2;
26 |
27 | // Enable mouse device
28 | mouse_wait(1);
29 | pio_outb(0x64, 0x20);
30 |
31 | // Enable interrupts
32 | mouse_wait(1);
33 | pio_outb(0x64, 0x20);
34 | mouse_wait(0);
35 | unsigned int status = pio_inb(0x60) | 2;
36 | mouse_wait(1);
37 | pio_outb(0x64, 0x60);
38 | mouse_wait(1);
39 | pio_outb(0x60, status);
40 |
41 | // Defulat settings
42 | mouse_write(0xF6);
43 | mouse_read();
44 |
45 | // Enable mouse
46 | mouse_write(0xF4);
47 | mouse_read();
48 | isr_register_interrupt_handler(IRQ_BASE + 12, mouse_handler);
49 |
50 | // Log that we successfully initialized ps2 mouse
51 | quantum_info(__FILE__, 0, " Mouse ", "Successfully initialized mouse drivers");
52 | }
53 |
54 | int get_mouse_x()
55 | {
56 | return mouse_x;
57 | }
58 |
59 | int get_mouse_y()
60 | {
61 | return mouse_y;
62 | }
63 |
64 | void mouse_wait(unsigned char type)
65 | {
66 | unsigned int _time_out=100000;
67 | if (type == 0)
68 | {
69 | while (_time_out--)
70 | {
71 | if ((pio_inb(0x64) & 1) == 1)
72 | {
73 | return;
74 | }
75 | }
76 | return;
77 | } else {
78 | while (_time_out--)
79 | {
80 | if ((pio_inb(0x64) & 2) == 0)
81 | {
82 | return;
83 | }
84 | }
85 | return;
86 | }
87 | }
88 |
89 | void mouse_write(unsigned char write)
90 | {
91 | mouse_wait(1);
92 | pio_outb(0x64, 0xD4);
93 | mouse_wait(1);
94 | pio_outb(0x60, write);
95 | }
96 |
97 | unsigned char mouse_read()
98 | {
99 | mouse_wait(0);
100 | return pio_inb(0x60);
101 | }
102 |
103 | void mouse_handler(__registers_t* regs)
104 | {
105 | switch(mouse_cycle)
106 | {
107 | case 0:
108 | mouse_byte[0] = pio_inb(0x60);
109 | mouse_cycle++;
110 | break;
111 | case 1:
112 | mouse_byte[1] = pio_inb(0x60);
113 | mouse_cycle++;
114 | break;
115 | case 2:
116 | mouse_byte[2] = pio_inb(0x60);
117 | int dx, dy;
118 | dx = (mouse_byte[0] & (1 << 4)) ? (char)mouse_byte[1] : mouse_byte[1];
119 | dy = (mouse_byte[0] & (1 << 5)) ? (char)mouse_byte[2] : mouse_byte[2];
120 | mouse_x += dx;
121 | mouse_y -= dy;
122 | mouse_cycle = 0;
123 | break;
124 | }
125 | }
126 |
127 |
128 |
--------------------------------------------------------------------------------
/drivers/pci.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | unsigned int __pci_size_map[100];
12 |
13 | __pci_device_t __pci_dev_zero;
14 |
15 | unsigned int pci_read(__pci_device_t __device, unsigned int __field)
16 | {
17 | __device.__field_num = (__field & 0xFC) >> 2;
18 |
19 | __device.__enable = 1;
20 |
21 | pio_outl(PCI_CONFIG_ADDRESS, __device.__bits);
22 |
23 | unsigned int __size = __pci_size_map[__field];
24 |
25 | if (__size == 1)
26 | {
27 | unsigned char __target = pio_inb(PCI_CONFIG_DATA + (__field & 3));
28 |
29 | return __target;
30 | }
31 | else if (__size == 2)
32 | {
33 | unsigned short __target = pio_ins(PCI_CONFIG_DATA + (__field & 2));
34 |
35 | return __target;
36 | }
37 | else if (__size == 4)
38 | {
39 | unsigned int __target = pio_inl(PCI_CONFIG_DATA);
40 |
41 | return __target;
42 | }
43 |
44 | return 0xFFFF;
45 | }
46 |
47 | unsigned int pci_get_device_type(__pci_device_t __device)
48 | {
49 | unsigned int __type = pci_read(__device, PCI_CLASS) << 8;
50 |
51 | return __type | pci_read(__device, PCI_SUBCLASS);
52 | }
53 |
54 | unsigned int pci_get_secondary_bus(__pci_device_t __device)
55 | {
56 | return pci_read(__device, PCI_SECONDARY_BUS);
57 | }
58 |
59 | unsigned int pci_reach_end(__pci_device_t __device)
60 | {
61 | unsigned int __end = pci_read(__device, PCI_HEADER_TYPE);
62 |
63 | return !__end;
64 | }
65 |
66 | __pci_device_t pci_scan_function(unsigned short __vendor_id, unsigned short __device_id, unsigned int __device,
67 | unsigned int __bus, unsigned int __function, int __device_type)
68 | {
69 | __pci_device_t __dev = {0};
70 |
71 | __dev.__bus_num = __bus;
72 | __dev.__device_num = __device;
73 | __dev.__function_num = __function;
74 |
75 | if (pci_get_device_type(__dev) == PCI_TYPE_BRIDGE)
76 | {
77 | pci_scan_bus(__vendor_id, __device_id, pci_get_secondary_bus(__dev), __device_type);
78 | }
79 |
80 | if (__device_type == -1 || __device_type == pci_get_device_type(__dev))
81 | {
82 | unsigned int __devid = pci_read(__dev, PCI_DEVICE_ID);
83 | unsigned int __venid = pci_read(__dev, PCI_VENDOR_ID);
84 |
85 | if (__devid == __device_id && __venid == __vendor_id)
86 | {
87 | return __dev;
88 | }
89 | }
90 |
91 | return __pci_dev_zero;
92 | }
93 |
94 | __pci_device_t pci_scan_device(unsigned short __vendor_id, unsigned short __device_id, unsigned int __bus,
95 | unsigned int __device, int __device_type)
96 | {
97 | __pci_device_t __dev = {0};
98 |
99 | __dev.__bus_num = __bus;
100 | __dev.__device_num = __device;
101 |
102 | if (pci_read(__dev, PCI_VENDOR_ID) == PCI_NONE)
103 | {
104 | return __pci_dev_zero;
105 | }
106 |
107 | __pci_device_t __target = pci_scan_function(__vendor_id, __device_id, __bus, __device, 0, __device_type);
108 |
109 | if (__target.__bits)
110 | {
111 | return __target;
112 | }
113 |
114 | if (pci_reach_end(__dev))
115 | {
116 | return __pci_dev_zero;
117 | }
118 |
119 | for (int f = 1; f < FUNCTION_PER_DEVICE; f++)
120 | {
121 | if (pci_read(__dev, PCI_VENDOR_ID) != PCI_NONE)
122 | {
123 | __target = pci_scan_function(__vendor_id, __device_id, __bus, __device, f, __device_type);
124 |
125 | if (__target.__bits)
126 | {
127 | return __target;
128 | }
129 | }
130 | }
131 |
132 | return __pci_dev_zero;
133 | }
134 |
135 | __pci_device_t pci_scan_bus(unsigned short __vendor_id, unsigned short __device_id, unsigned int __bus,
136 | int __device_type)
137 | {
138 | for (int d = 0; d < DEVICE_PER_BUS; d++)
139 | {
140 | __pci_device_t __target = pci_scan_bus(__vendor_id, __device_id, d, __device_type);
141 |
142 | if (__target.__bits)
143 | {
144 | return __target;
145 | }
146 | }
147 |
148 | return __pci_dev_zero;
149 | }
150 |
151 | __pci_device_t pci_get_device(unsigned short __vendor_id, unsigned short __device_id, int __device_type)
152 | {
153 | __pci_device_t __target = pci_scan_bus(__vendor_id, __device_id, 0, __device_type);
154 |
155 | if (__target.__bits)
156 | {
157 | return __target;
158 | }
159 |
160 | if (pci_reach_end(__pci_dev_zero))
161 | {
162 | /* Failed */
163 |
164 | #ifdef DEBUG_PCI
165 | printf("PCI Get Device Failed\n");
166 | #endif
167 | }
168 |
169 | for (int f = 1; f < FUNCTION_PER_DEVICE; f++)
170 | {
171 | __pci_device_t __dev = {0};
172 |
173 | __dev.__function_num = f;
174 |
175 | if (pci_read(__dev, PCI_VENDOR_ID) == PCI_NONE)
176 | {
177 | break;
178 | }
179 |
180 | __target = pci_scan_bus(__vendor_id, __device_id, f, __device_type);
181 |
182 | if (__target.__bits)
183 | {
184 | return __target;
185 | }
186 | }
187 |
188 | return __pci_dev_zero;
189 | }
190 |
191 | void pci_write(__pci_device_t __device, unsigned int __field, unsigned int __value)
192 | {
193 | __device.__field_num = (__field & 0xFC) >> 2;
194 | __device.__enable = 1;
195 |
196 | pio_outl(PCI_CONFIG_ADDRESS, __device.__bits);
197 | pio_outl(PCI_CONFIG_DATA, __value);
198 | }
199 |
200 | int pci_initialize(void)
201 | {
202 | __pci_size_map[PCI_VENDOR_ID] = 2;
203 | __pci_size_map[PCI_DEVICE_ID] = 2;
204 | __pci_size_map[PCI_COMMAND] = 2;
205 | __pci_size_map[PCI_STATUS] = 2;
206 | __pci_size_map[PCI_SUBCLASS] = 1;
207 | __pci_size_map[PCI_CLASS] = 1;
208 | __pci_size_map[PCI_CACHE_LINE_SIZE] = 1;
209 | __pci_size_map[PCI_LATENCY_TIMER] = 1;
210 | __pci_size_map[PCI_HEADER_TYPE] = 1;
211 | __pci_size_map[PCI_BIST] = 1;
212 | __pci_size_map[PCI_BAR0] = 4;
213 | __pci_size_map[PCI_BAR1] = 4;
214 | __pci_size_map[PCI_BAR2] = 4;
215 | __pci_size_map[PCI_BAR3] = 4;
216 | __pci_size_map[PCI_BAR4] = 4;
217 | __pci_size_map[PCI_BAR5] = 4;
218 | __pci_size_map[PCI_INTERRUPT_LINE] = 1;
219 | __pci_size_map[PCI_SECONDARY_BUS] = 1;
220 |
221 | return 0;
222 | }
--------------------------------------------------------------------------------
/drivers/sound_blaster.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | BOOL sound_blaster_found = FALSE;
16 |
17 | void quantum_sound_blaster_init()
18 | {
19 | // Reset sound blaster device
20 | sound_blaster_reset();
21 |
22 | // If this port return 0xAA this means that sound blaster
23 | // have been found
24 | unsigned char dsp_status = pio_inb(DSP_READ);
25 | if (dsp_status == 0xAA)
26 | {
27 | quantum_info(__FILE__, 0, " Sb16 ", "Successfully detected sound blaster device");
28 | quantum_info(__FILE__, 0, " Sb16 ", "DSP_READ port returned 0x%x", dsp_status);
29 | sound_blaster_found = TRUE;
30 |
31 | // Turn on speakers
32 | sound_blaster_turn_on();
33 |
34 | // Get the IRQ port and set it
35 | sound_blaster_irq();
36 | }
37 | else
38 | {
39 | quantum_info(__FILE__, 1, " Sb16 ", "Can't detect sound blaster device");
40 | quantum_info(__FILE__, 1, " Sb16 ", "DSP_READ port returned 0x%x", dsp_status);
41 | sound_blaster_found = FALSE;
42 | }
43 |
44 | }
45 |
46 | void sound_blaster_reset()
47 | {
48 | pio_outb(DSP_RESET, 1); // Send 1 to DSP_RESET
49 | pio_sleep(); // Wait 3 microseconds
50 | pio_outb(DSP_RESET, 0); // Send 0 to DSP_RESET
51 | }
52 |
53 | void sound_blaster_turn_on()
54 | {
55 | pio_outb(DSP_WRITE, 0xD1);
56 | }
57 |
58 | BOOL is_sound_blaster_found()
59 | {
60 | return sound_blaster_found;
61 | }
62 |
63 | void sound_blaster_irq_handler(__registers_t* regs)
64 | {
65 | printf("Got an interrupt from SB16\n");
66 | }
67 |
68 | void sound_blaster_dma_channel_16(unsigned char channel_number, unsigned char* sound_data, int sound_data_length)
69 | {
70 | unsigned char channel = channel_number + 0x04;
71 | unsigned char transfer_mode = channel_number + 0x48; // single mode + channel
72 |
73 | char buf[32] = { 0 };
74 | itoa((int)sound_data, buf, 16);
75 |
76 | unsigned char page_data = (unsigned char)((int)sound_data >> (strlen(buf) - 2) * 4); // if sound_data ptr = 0x71e241 then page_data = 0x71
77 | unsigned char high_bits_pos = (unsigned char)(((int)sound_data & 0xff00) >> 8); // if sound_data ptr = 0x71e241 then high_bits_pos = 0xe2
78 | unsigned char low_bits_pos = (unsigned char)((int)sound_data & 0xff); // if sound_data ptr = 0x71e241 then low_bits_pos = 0x41
79 |
80 | char buf2[32] = { 0 };
81 | itoa((int)sound_data_length, buf2, 16);
82 |
83 | unsigned char low_bits_length = (unsigned char)(sound_data_length >> (strlen(buf2) * 4));
84 | unsigned char high_bits_length = (unsigned char)(sound_data_length & 0xff);
85 |
86 | pio_outb(0xD4, channel); // disable channel, channel number + 0x04
87 | pio_outb(0xD8, 69); // write any value to 0xD8, i will write 69 ^_^
88 | pio_outb(0xD6, transfer_mode); // send transfer mode
89 | pio_outb(0x8B, page_data); // send page of sound data, for example if sound data is at 0x71e241, page is 0x71
90 | pio_outb(0xC4, low_bits_pos); // send low bit of sound data, for example if sound data is at 0x71e241, page is 0x41
91 | pio_outb(0xC4, high_bits_pos); // send high bit of sound data, for example if sound data is at 0x71e241, page is 0xe2
92 | pio_outb(0xC6, low_bits_length); // send low bits of sound data length
93 | pio_outb(0xC6, high_bits_length); // send high bits of sound data length
94 | pio_outb(0xD4, channel_number); // send channel number that need to be enabled
95 | }
96 |
97 | void sound_blaster_irq()
98 | {
99 | unsigned char irq_set = 0x02; // IRQ 5
100 | pio_outb(DSP_MIXER_PORT, 0x80); // Send 0x80 to Mixer port, because we want to set irq
101 | pio_outb(DSP_MIXER_DATA_PORT, irq_set); // Send 0x02 (IRQ 5) to Mixer data port now IRQ 5 will be the sb16 IRQ
102 |
103 | // Check is it set successfully
104 | unsigned char irq_sb16 = pio_inb(DSP_MIXER_DATA_PORT);
105 | if (irq_sb16 == irq_set)
106 | {
107 | quantum_info(__FILE__, 0, " Sb16 ", "Sound blaster is set to IRQ 5, (DSP_MIXER_DATA_PORT returned 0x%x)", irq_sb16);
108 | quantum_info(__FILE__, 0, " Sb16 ", "Setting IRQ 5 to sound blaster output");
109 | isr_register_interrupt_handler(IRQ5_RESERVED, sound_blaster_irq_handler);
110 | }
111 | else
112 | {
113 | quantum_info(__FILE__, 1, " Sb16 ", "Could not set sound blaster to IRQ 5");
114 | sound_blaster_found = FALSE;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/drivers/vga.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | void vga_set_cursor(int __offset)
11 | {
12 | __offset /= 2;
13 |
14 | pio_outb(VGA_CTRL_REGISTER, VGA_OFFSET_HIGH);
15 | pio_outb(VGA_DATA_REGISTER, (unsigned char) (__offset >> 8));
16 | pio_outb(VGA_CTRL_REGISTER, VGA_OFFSET_LOW);
17 | pio_outb(VGA_DATA_REGISTER, (unsigned char) (__offset & 0xff));
18 | }
19 |
20 | int vga_get_cursor(void)
21 | {
22 | pio_outb(VGA_CTRL_REGISTER, VGA_OFFSET_HIGH);
23 |
24 | int __offset = pio_inb(VGA_DATA_REGISTER) << 8;
25 |
26 | pio_outb(VGA_CTRL_REGISTER, VGA_OFFSET_LOW);
27 |
28 | __offset += pio_inb(VGA_DATA_REGISTER);
29 |
30 | return __offset * 2;
31 | }
32 |
33 | int vga_row_from_offset(int __offset)
34 | {
35 | return __offset / (2 * SCREEN_SIZE_COLS);
36 | }
37 |
38 | int vga_line_from_offset(int __col, int __row)
39 | {
40 | return 2 * (__row * SCREEN_SIZE_COLS + __col);
41 | }
42 |
43 | void vga_newline(void)
44 | {
45 | VGA_CURSOR = vga_line_from_offset(0, vga_row_from_offset(VGA_CURSOR) + 1);
46 | }
47 |
48 | void vga_tab(void)
49 | {
50 | int offset = (SCREEN_SIZE_COLS * SCREEN_SIZE_BLEN) - (VGA_CURSOR % SCREEN_SIZE_COLS);
51 |
52 | if (offset < 4)
53 | {
54 | int remaining = 4 - offset;
55 |
56 | vga_newline();
57 |
58 | VGA_CURSOR = (VGA_CURSOR) + remaining;
59 |
60 | return;
61 | }
62 |
63 | VGA_CURSOR = (VGA_CURSOR + 4);
64 | }
65 |
66 | void vga_putchar(char __c, unsigned short __cl)
67 | {
68 | if (__c == '\0')
69 | {
70 | return;
71 | }
72 |
73 | if (VGA_CURSOR >= SCREEN_SIZE)
74 | {
75 | vga_clear();
76 | }
77 |
78 | if (__c == '\n')
79 | {
80 | vga_newline();
81 |
82 | return;
83 | }
84 |
85 | if (__c == '\t')
86 | {
87 | vga_tab();
88 |
89 | return;
90 | }
91 |
92 | VGA_POINTER[VGA_CURSOR] = __c;
93 | VGA_POINTER[VGA_CURSOR + 1] = __cl;
94 |
95 | VGA_CURSOR = (VGA_CURSOR + 2);
96 | }
97 |
98 | void vga_clear(void)
99 | {
100 | VGA_CURSOR = 0;
101 |
102 | unsigned int __viter = VGA_CURSOR;
103 |
104 | while (__viter < SCREEN_SIZE)
105 | {
106 | vga_putchar(' ', ATTR_BYTE_BLK_ON_BLK);
107 |
108 | __viter = VGA_CURSOR;
109 | }
110 |
111 | VGA_CURSOR = 0;
112 | }
113 |
114 | void vga_backspace(void)
115 | {
116 | VGA_CURSOR = (VGA_CURSOR - 2);
117 |
118 | VGA_POINTER[VGA_CURSOR] = ' ';
119 | VGA_POINTER[VGA_CURSOR + 1] = ATTR_BYTE_BLK_ON_BLK;
120 | }
121 |
--------------------------------------------------------------------------------
/ext2.img:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/ext2.img
--------------------------------------------------------------------------------
/fs/device.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | __device_t *__devices = 0;
13 |
14 | unsigned int __lastid = 0;
15 |
16 | void device_init(void)
17 | {
18 | __devices = (__device_t *) kmalloc(64 * sizeof(__device_t));
19 |
20 | kmemset(__devices, 0, 64 * sizeof(__device_t));
21 |
22 | __lastid = 0;
23 |
24 | quantum_info(__FILE__, 0, " Devmgr ", "Device Manager Initialized!");
25 | }
26 |
27 | void device_print(void)
28 | {
29 | for (int i = 0; i < __lastid; i++)
30 | {
31 | quantum_info(__FILE__, 0, " Devmgr ", "ID: %d | UNIQUE: %d, %s, %s", i, __devices[i].__unique_id, __devices[i].__dev_type == DEVICE_CHAR ? "CHAR" : "BLOCK", __devices[i].__name);
32 | }
33 | }
34 |
35 | int device_add(__device_t *__device)
36 | {
37 | __devices[__lastid] = *__device;
38 |
39 | quantum_info(__FILE__, 0, " Devmgr ", "Registered Device [%s] (%d) as Device #%d\n", __device->__name, __device->__unique_id, __lastid);
40 |
41 | __lastid++;
42 |
43 | return (__lastid - 1);
44 | }
45 |
46 | __device_t *device_get(unsigned int __id)
47 | {
48 | return &__devices[__id];
49 | }
50 |
51 | __device_t *device_get_by_id(unsigned int __id)
52 | {
53 | for (int i = 0; i < 64; i++)
54 | {
55 | if (__devices[i].__unique_id == __id)
56 | {
57 | return &__devices[i];
58 | }
59 | }
60 |
61 | return 0;
62 | }
63 |
64 | int device_get_number(void)
65 | {
66 | return __lastid;
67 | }
68 |
--------------------------------------------------------------------------------
/include/core/gtree.h:
--------------------------------------------------------------------------------
1 | #ifndef GTREE_H
2 | #define GTREE_H
3 |
4 | #include
5 |
6 | typedef struct __gtreenode
7 | {
8 | __list_t *__children;
9 |
10 | void *__val;
11 | } __gtreenode_t;
12 |
13 | typedef struct __gtree
14 | {
15 | __gtreenode_t *__root;
16 | } __gtree_t;
17 |
18 | __gtree_t *gtree_create(void);
19 |
20 | __gtreenode_t *gtree_node_create(void *__value);
21 | __gtreenode_t *gtree_insert(__gtree_t *__tree, __gtreenode_t *__subroot, void *__value);
22 | __gtreenode_t *gtree_find_parent(__gtree_t *__tree, __gtreenode_t *__node, int *__cindex);
23 | __gtreenode_t *gtree_find_parent_recur(__gtree_t *__tree, __gtreenode_t *__node, __gtreenode_t *__subroot, int *__cindex);
24 |
25 | void gtree_remove(__gtree_t *__tree, __gtreenode_t *__node);
26 |
27 | void gtree_to_list_recur(__gtreenode_t *__subroot, __list_t *__list);
28 | void gtree_to_list(__gtree_t *__tree, __list_t *__list);
29 | void gtree_to_array_recur(__gtreenode_t *__subroot, void **__array, int *__size);
30 | void gtree_to_array(__gtree_t *__tree, void **__array, int *__size);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/core/kpanic.h:
--------------------------------------------------------------------------------
1 | #ifndef KPANIC_H
2 | #define KPANIC_H
3 |
4 | typedef struct stack_frame_t {
5 | struct stack_frame_t* ebp;
6 | unsigned int eip;
7 | } stack_frame_t;
8 |
9 | void kpanic(const char *__message);
10 |
11 | #endif
12 |
--------------------------------------------------------------------------------
/include/core/list.h:
--------------------------------------------------------------------------------
1 | #ifndef LIST_H
2 | #define LIST_H
3 |
4 | #include
5 |
6 | typedef struct __listnode
7 | {
8 | struct __listnode *__prev;
9 | struct __listnode *__next;
10 |
11 | void *__val;
12 | } __listnode_t;
13 |
14 | typedef struct __list
15 | {
16 | __listnode_t *__head;
17 | __listnode_t *__tail;
18 |
19 | unsigned int __size;
20 | } __list_t;
21 |
22 | #define FOREACH(__T, __LIST) for (__listnode_t *__T = __LIST->__head; __T != NULL; __T = __T->__next)
23 |
24 | __list_t *list_create(void);
25 |
26 | unsigned int list_size(__list_t *__list);
27 |
28 | __listnode_t *list_insert_front(__list_t *__list, void *__val);
29 |
30 | void list_insert_back(__list_t *__list, void *__val);
31 |
32 | void *list_remove_node(__list_t *__list, __listnode_t *__node);
33 | void *list_remove_front(__list_t *__list);
34 | void *list_remove_back(__list_t *__list);
35 |
36 | void list_push(__list_t *__list, void *__val);
37 |
38 | __listnode_t *list_pop(__list_t *__list);
39 |
40 | void list_enqueue(__list_t *__list, void *__val);
41 |
42 | __listnode_t *list_dequeue(__list_t *__list);
43 |
44 | void *list_peek_front(__list_t *__list);
45 | void *list_peek_back(__list_t *__list);
46 |
47 | void list_destroy(__list_t *__list);
48 | void listnode_destroy(__listnode_t *__node);
49 |
50 | int list_contains(__list_t *__list, void *__val);
51 |
52 | __listnode_t *list_get_node_by_index(__list_t *__list, int __index);
53 |
54 | void *list_remove_by_index(__list_t *__list, int __index);
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/include/core/print.h:
--------------------------------------------------------------------------------
1 | #ifndef PRINT_H
2 | #define PRINT_H
3 |
4 | #include
5 |
6 | int set_print_x(int x);
7 |
8 | int set_print_y(int y);
9 |
10 | void quantum_print_init();
11 |
12 | void set_default_pos();
13 |
14 | void insert_tab();
15 |
16 | void insert_newline();
17 |
18 | void insert_backspace();
19 |
20 | void putc(char c);
21 |
22 | void printf(const char* format, ...);
23 |
24 | void printf_va(char* format, va_list arg);
25 |
26 | void print_set_color(int r, int g, int b);
27 |
28 | void print_set_color_bg(int r, int g, int b);
29 |
30 | #endif
--------------------------------------------------------------------------------
/include/core/stdarg.h:
--------------------------------------------------------------------------------
1 | /*
2 | https://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/stdarg.h
3 | */
4 |
5 | /* Copyright (C) 1989-2022 Free Software Foundation, Inc.
6 | This file is part of GCC.
7 | GCC is free software; you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation; either version 3, or (at your option)
10 | any later version.
11 | GCC 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 General Public License for more details.
15 | Under Section 7 of GPL version 3, you are granted additional
16 | permissions described in the GCC Runtime Library Exception, version
17 | 3.1, as published by the Free Software Foundation.
18 | You should have received a copy of the GNU General Public License and
19 | a copy of the GCC Runtime Library Exception along with this program;
20 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 | . */
22 |
23 | /*
24 | * ISO C Standard: 7.15 Variable arguments
25 | */
26 |
27 | #ifndef _STDARG_H
28 | #ifndef _ANSI_STDARG_H_
29 | #ifndef __need___va_list
30 | #define _STDARG_H
31 | #define _ANSI_STDARG_H_
32 | #endif /* not __need___va_list */
33 | #undef __need___va_list
34 |
35 | /* Define __gnuc_va_list. */
36 |
37 | #ifndef __GNUC_VA_LIST
38 | #define __GNUC_VA_LIST
39 | typedef __builtin_va_list __gnuc_va_list;
40 | #endif
41 |
42 | /* Define the standard macros for the user,
43 | if this invocation was from the user program. */
44 | #ifdef _STDARG_H
45 |
46 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
47 | #define va_start(v, ...) __builtin_va_start(v, 0)
48 | #else
49 | #define va_start(v,l) __builtin_va_start(v,l)
50 | #endif
51 | #define va_end(v) __builtin_va_end(v)
52 | #define va_arg(v,l) __builtin_va_arg(v,l)
53 | #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L \
54 | || __cplusplus + 0 >= 201103L
55 | #define va_copy(d,s) __builtin_va_copy(d,s)
56 | #endif
57 | #define __va_copy(d,s) __builtin_va_copy(d,s)
58 |
59 | /* Define va_list, if desired, from __gnuc_va_list. */
60 | /* We deliberately do not define va_list when called from
61 | stdio.h, because ANSI C says that stdio.h is not supposed to define
62 | va_list. stdio.h needs to have access to that data type,
63 | but must not use that name. It should use the name __gnuc_va_list,
64 | which is safe because it is reserved for the implementation. */
65 |
66 | #ifdef _BSD_VA_LIST
67 | #undef _BSD_VA_LIST
68 | #endif
69 |
70 | #if defined(__svr4__) || (defined(_SCO_DS) && !defined(__VA_LIST))
71 | /* SVR4.2 uses _VA_LIST for an internal alias for va_list,
72 | so we must avoid testing it and setting it here.
73 | SVR4 uses _VA_LIST as a flag in stdarg.h, but we should
74 | have no conflict with that. */
75 | #ifndef _VA_LIST_
76 | #define _VA_LIST_
77 | #ifdef __i860__
78 | #ifndef _VA_LIST
79 | #define _VA_LIST va_list
80 | #endif
81 | #endif /* __i860__ */
82 | typedef __gnuc_va_list va_list;
83 | #ifdef _SCO_DS
84 | #define __VA_LIST
85 | #endif
86 | #endif /* _VA_LIST_ */
87 | #else /* not __svr4__ || _SCO_DS */
88 |
89 | /* The macro _VA_LIST_ is the same thing used by this file in Ultrix.
90 | But on BSD NET2 we must not test or define or undef it.
91 | (Note that the comments in NET 2's ansi.h
92 | are incorrect for _VA_LIST_--see stdio.h!) */
93 | #if !defined (_VA_LIST_) || defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__) || defined(WINNT)
94 | /* The macro _VA_LIST_DEFINED is used in Windows NT 3.5 */
95 | #ifndef _VA_LIST_DEFINED
96 | /* The macro _VA_LIST is used in SCO Unix 3.2. */
97 | #ifndef _VA_LIST
98 | /* The macro _VA_LIST_T_H is used in the Bull dpx2 */
99 | #ifndef _VA_LIST_T_H
100 | /* The macro __va_list__ is used by BeOS. */
101 | #ifndef __va_list__
102 | typedef __gnuc_va_list va_list;
103 | #endif /* not __va_list__ */
104 | #endif /* not _VA_LIST_T_H */
105 | #endif /* not _VA_LIST */
106 | #endif /* not _VA_LIST_DEFINED */
107 | #if !(defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__))
108 | #define _VA_LIST_
109 | #endif
110 | #ifndef _VA_LIST
111 | #define _VA_LIST
112 | #endif
113 | #ifndef _VA_LIST_DEFINED
114 | #define _VA_LIST_DEFINED
115 | #endif
116 | #ifndef _VA_LIST_T_H
117 | #define _VA_LIST_T_H
118 | #endif
119 | #ifndef __va_list__
120 | #define __va_list__
121 | #endif
122 |
123 | #endif /* not _VA_LIST_, except on certain systems */
124 |
125 | #endif /* not __svr4__ */
126 |
127 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
128 | #define __STDC_VERSION_STDARG_H__ 202311L
129 | #endif
130 |
131 | #endif /* _STDARG_H */
132 |
133 | #endif /* not _ANSI_STDARG_H_ */
134 | #endif /* not _STDARG_H */
--------------------------------------------------------------------------------
/include/core/stdlib.h:
--------------------------------------------------------------------------------
1 | #ifndef STDLIB_H
2 | #define STDLIB_H
3 |
4 | typedef enum
5 | {
6 | FALSE,
7 | TRUE,
8 | } BOOL;
9 |
10 | #define OPTIONAL(type) type \
11 |
12 | #define OPTIONAL_NIL() NULL \
13 |
14 | #define __SET_REGISTER__(reg, value) \
15 | __asm__ __volatile__ ("mov %0, %%" reg : : "r" (value) : ) \
16 |
17 | #define __SYSCALL__() \
18 | __asm__ __volatile__ ("int $0x80"); \
19 |
20 | int kstrlen(const char *__data);
21 |
22 | void kstrcat(char *__dest, const char *__src);
23 |
24 | int isalpha(char c);
25 |
26 | int isdigit(char c);
27 |
28 | int isspace(char c);
29 |
30 | void snprintf(char* buf, int buf_size, char* format, ...);
31 |
32 | void sprintf(char* buf, char* format, ...);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/include/core/string.h:
--------------------------------------------------------------------------------
1 | #ifndef STRING_H
2 | #define STRING_H
3 |
4 | #include
5 | #include
6 |
7 | #define NULL (void *) 0
8 |
9 | int strlen(const char* str);
10 |
11 | char to_uppercase(char c);
12 |
13 | char to_lowercase(char c);
14 |
15 | void reverse(char* str);
16 |
17 | int strcmp(const char *s1, char *s2);
18 |
19 | void pop_last_str(char* str);
20 |
21 | void append_str(char* str, char c);
22 |
23 | char* strcpy(char* dest, const char* src);
24 |
25 | char* strtok(char* str, char* delim);
26 |
27 | char* strpbrk(const char* str, const char* accept);
28 |
29 | char* strdup(const char* str);
30 |
31 | char* strrchr(const char* str, int c);
32 |
33 | void itoa(int num, char* str, int base);
34 |
35 | void ltoa(long long value, char* buf);
36 |
37 | int strncmp(const char *__s1, const char *__s2, int __c);
38 |
39 | char *strstr(const char *__in, const char *__str);
40 |
41 | char *strsep(char **__stringp, const char *__delim);
42 |
43 | char *list_to_str(__list_t *__list, const char *__delim);
44 |
45 | __list_t *list_strtok(const char *__str, const char *__delim, unsigned int *__ntok);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/include/core/tga.h:
--------------------------------------------------------------------------------
1 | #ifndef TGA_H
2 | #define TGA_H
3 |
4 | #pragma pack(push) // save the original data alignment
5 | #pragma pack(1) // Set data alignment to 1 byte boundary
6 |
7 | typedef struct {
8 | unsigned char signature; // must be zero
9 | unsigned char colormap; // must be zero
10 | unsigned char encoding; // must be 2
11 | unsigned short cmaporig, cmaplen; // must be zero
12 | unsigned char cmapent; // must be zero
13 | unsigned short x; // must be zero
14 | unsigned short y; // image's height
15 | unsigned short h; // image's height
16 | unsigned short w; // image's width
17 | unsigned char bpp; // must be 32
18 | unsigned char pixeltype; // must be 40
19 | } __attribute__((packed)) tga_header_t;
20 |
21 | #pragma pack(pop) // restore the previous pack setting
22 |
23 | typedef struct __tga_structure_t {
24 | tga_header_t* header;
25 | unsigned char* pixel_data;
26 | } tga_structure_t;
27 |
28 | tga_structure_t* parse_tga(char* data, int data_size);
29 |
30 | #endif
--------------------------------------------------------------------------------
/include/core/time.h:
--------------------------------------------------------------------------------
1 | #ifndef TIME_H
2 | #define TIME_H
3 |
4 | #include
5 |
6 | unsigned long date_to_timestamp(date_t* date);
7 |
8 | #endif
--------------------------------------------------------------------------------
/include/drivers/ac97.h:
--------------------------------------------------------------------------------
1 | #ifndef AC97_H
2 | #define AC97_H
3 |
4 | #include
5 |
6 | #define AC97_bar0_RESET_REGISTER 0x00
7 | #define AC97_bar0_SET_MASTER_OUTPUT_VOLUME 0x02
8 | #define AC97_bar0_SET_MICROPHONE_VOLUME 0x0E
9 | #define AC97_bar0_SET_OUPUT_VOLUME_PCM 0x18
10 | #define AC97_bar0_SELECT_INPUT_DEVICE 0x1A
11 | #define AC97_bar0_SET_INPUT_GAIN 0x1C
12 | #define AC97_bar0_SET_GAIN_MICROPHONE 0x1E
13 | #define AC97_bar0_SUPPORTED_EXTENDED_FUNCS 0x28
14 | #define AC97_bar0_ENABLE_EXTENDED_FUNCS 0x2A
15 | #define AC97_bar0_SAMPLE_RATE_FRONT_SPEAKERS 0x2C
16 |
17 | void ac97_write_global_control(unsigned short bar0, unsigned short bar1, unsigned int port);
18 |
19 | int ac97_initialize(__pci_device_t* dev);
20 |
21 | void ac97_play_sound(unsigned char* sound_data);
22 |
23 | #endif
--------------------------------------------------------------------------------
/include/drivers/debug.h:
--------------------------------------------------------------------------------
1 | #ifndef DEBUG_H
2 | #define DEBUG_H
3 |
4 | #include
5 |
6 | #define DEBUG_PORT 0x3F8
7 |
8 | void debug_putc(char c);
9 |
10 | void debug_print(char* buf);
11 |
12 | void debug_printf_va(char* format, va_list arg);
13 |
14 | void debug_printf(char* format, ...);
15 |
16 | #endif
--------------------------------------------------------------------------------
/include/drivers/keyboard.h:
--------------------------------------------------------------------------------
1 | #ifndef KEYBOARD_H
2 | #define KEYBOARD_H
3 |
4 | #define KEYBOARD_COMMAND_PORT 0x64
5 | #define KEYBOARD_STATUS_PORT 0x64
6 | #define KEYBOARD_DATA_PORT 0x60
7 |
8 | #define KEYBOARD_KEY_UP 0x80
9 | #define KEYBOARD_KEY_DOWN 0x7F
10 |
11 | #define KEYBOARD_READY 1
12 |
13 | #define KEYBOARD_BACKSPACE_SC 0x0E
14 | #define KEYBOARD_TAB_SC 0x0F
15 | #define KEYBOARD_ENTER_SC 0x1C
16 | #define KEYBOARD_CAPS_LOCK_SC 0x3A
17 | #define KEYBOARD_LSHIFT_SC 0x2A
18 | #define KEYBOARD_RSHIFT_SC 0x36
19 |
20 | /* English keyboard map */
21 | #define KEYBOARD_MAP_ENG { \
22 | 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', \
23 | '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', \
24 | 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, \
25 | '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ', \
26 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', 0, 0, \
27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
29 | }
30 |
31 | void keyboard_set_key_map(char* key_map);
32 |
33 | char* keyboard_get_key_map();
34 |
35 | char keyboard_getchar();
36 |
37 | char keyboard_getchar_no_wait();
38 |
39 | char *keyboard_getchar_until(char __c);
40 |
41 | char keyboard_getsc();
42 |
43 | void keyboard_enable();
44 |
45 | #endif
--------------------------------------------------------------------------------
/include/drivers/mouse.h:
--------------------------------------------------------------------------------
1 | #ifndef MOUSE_H
2 | #define MOUSE_H
3 |
4 | #include
5 |
6 | int get_mouse_x();
7 |
8 | int get_mouse_y();
9 |
10 | void mouse_wait(unsigned char type);
11 |
12 | void mouse_write(unsigned char write);
13 |
14 | unsigned char mouse_read();
15 |
16 | void mouse_handler(__registers_t* regs);
17 |
18 | void quantum_mouse_init();
19 |
20 | #endif
--------------------------------------------------------------------------------
/include/drivers/pci.h:
--------------------------------------------------------------------------------
1 | #ifndef PCI_H
2 | #define PCI_H
3 |
4 | typedef union __pci_device
5 | {
6 | unsigned int __bits;
7 |
8 | struct {
9 | unsigned int __always_zero : 2;
10 | unsigned int __field_num : 6;
11 | unsigned int __function_num : 3;
12 | unsigned int __device_num : 5;
13 | unsigned int __bus_num : 8;
14 | unsigned int __reserved : 7;
15 | unsigned int __enable : 1;
16 | };
17 | } __pci_device_t;
18 |
19 | /* PIO Ports */
20 | #define PCI_CONFIG_ADDRESS 0xCF8
21 | #define PCI_CONFIG_DATA 0xCFC
22 |
23 | /* Config Address Register */
24 |
25 | /* Offset */
26 | #define PCI_VENDOR_ID 0x00
27 | #define PCI_DEVICE_ID 0x02
28 | #define PCI_COMMAND 0x04
29 | #define PCI_STATUS 0x06
30 | #define PCI_REVISION_ID 0x08
31 | #define PCI_PROG_IF 0x09
32 | #define PCI_SUBCLASS 0x0a
33 | #define PCI_CLASS 0x0b
34 | #define PCI_CACHE_LINE_SIZE 0x0c
35 | #define PCI_LATENCY_TIMER 0x0d
36 | #define PCI_HEADER_TYPE 0x0e
37 | #define PCI_BIST 0x0f
38 | #define PCI_BAR0 0x10
39 | #define PCI_BAR1 0x14
40 | #define PCI_BAR2 0x18
41 | #define PCI_BAR3 0x1C
42 | #define PCI_BAR4 0x20
43 | #define PCI_BAR5 0x24
44 | #define PCI_INTERRUPT_LINE 0x3C
45 | #define PCI_SECONDARY_BUS 0x09
46 |
47 | /* Device Type */
48 | #define PCI_HEADER_TYPE_DEVICE 0
49 | #define PCI_HEADER_TYPE_BRIDGE 1
50 | #define PCI_HEADER_TYPE_CARDBUS 2
51 | #define PCI_TYPE_BRIDGE 0x0604
52 | #define PCI_TYPE_SATA 0x0106
53 | #define PCI_NONE 0xFFFF
54 |
55 | #define DEVICE_PER_BUS 32
56 | #define FUNCTION_PER_DEVICE 32
57 |
58 | unsigned int pci_read(__pci_device_t __device, unsigned int __field);
59 | unsigned int pci_get_device_type(__pci_device_t __device);
60 | unsigned int pci_get_secondary_bus(__pci_device_t __device);
61 | unsigned int pci_reach_end(__pci_device_t __device);
62 |
63 | __pci_device_t pci_scan_function(unsigned short __vendor_id, unsigned short __device_id, unsigned int __device,
64 | unsigned int __bus, unsigned int __function, int __device_type);
65 |
66 | __pci_device_t pci_scan_device(unsigned short __vendor_id, unsigned short __device_id, unsigned int __bus,
67 | unsigned int __device, int __device_type);
68 |
69 | __pci_device_t pci_scan_bus(unsigned short __vendor_id, unsigned short __device_id, unsigned int __bus,
70 | int __device_type);
71 |
72 | __pci_device_t pci_get_device(unsigned short __vendor_id, unsigned short __device_id, int __device_type);
73 |
74 | void pci_write(__pci_device_t __device, unsigned int __field, unsigned int __value);
75 |
76 | int pci_initialize(void);
77 |
78 | #endif
--------------------------------------------------------------------------------
/include/drivers/sound_blaster.h:
--------------------------------------------------------------------------------
1 | #ifndef SOUND_BLASTER_H
2 | #define SOUND_BLASTER_H
3 |
4 | #include
5 |
6 | #define DSP_MIXER_PORT 0x224
7 | #define DSP_MIXER_DATA_PORT 0x225
8 | #define DSP_RESET 0x226
9 | #define DSP_READ 0x22A
10 | #define DSP_WRITE 0x22C
11 | #define DSP_READ_STATUS 0x22E
12 | #define DSP_16BIT_INTERRUPT 0x22F
13 |
14 | void quantum_sound_blaster_init();
15 |
16 | BOOL is_sound_blaster_found();
17 |
18 | void sound_blaster_dma_channel_16(unsigned char channel_number, unsigned char* sound_data, int sound_data_length);
19 |
20 | void sound_blaster_irq();
21 |
22 | void sound_blaster_reset();
23 |
24 | void sound_blaster_turn_on();
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/include/drivers/vesa.h:
--------------------------------------------------------------------------------
1 | #ifndef VESA_H
2 | #define VESA_H
3 |
4 | typedef enum __image_format_t {
5 | IMAGE_TGA,
6 | IMAGE_PNG,
7 | IMAGE_JPG,
8 | } image_format_t;
9 |
10 | void quantum_back_buffer_init();
11 |
12 | void quantum_vesa_init(unsigned long mbinfo_ptr);
13 |
14 | unsigned long get_global_mutliboot_addr();
15 |
16 | void toggle_double_framebuffer();
17 |
18 | void swap_buffers();
19 |
20 | int get_screen_x();
21 |
22 | int get_screen_y();
23 |
24 | void vesa_clear();
25 |
26 | void clear_back_buffer();
27 |
28 | void vesa_put_pixel(int x, int y, int r, int g, int b);
29 |
30 | void vesa_put_pixel_double_buffering(int x, int y, int r, int g, int b);
31 |
32 | void vesa_draw_rect(int x, int y, int w, int h, int r, int g, int b);
33 |
34 | void vesa_draw_circle(int center_x, int center_y, int radius, int r, int g, int b);
35 |
36 | void vesa_draw_line(int start_x, int start_y, int end_x, int end_y, int r, int g, int b);
37 |
38 | void vesa_draw_char(char c, int x, int y, int fg_r, int fg_g, int fg_b, int bg_r, int bg_g, int bg_b);
39 |
40 | int vesa_draw_image(char* img_data, int img_data_size, image_format_t format);
41 |
42 | #endif
--------------------------------------------------------------------------------
/include/drivers/vga.h:
--------------------------------------------------------------------------------
1 | #ifndef VGA_H
2 | #define VGA_H
3 |
4 | #define VGA_CTRL_REGISTER 0x3d4
5 | #define VGA_DATA_REGISTER 0x3d5
6 | #define VGA_OFFSET_LOW 0x0f
7 | #define VGA_OFFSET_HIGH 0x0e
8 |
9 | #define SCREEN_SIZE_COLS 80
10 | #define SCREEN_SIZE_ROWS 25
11 | #define SCREEN_SIZE_BLEN 2
12 |
13 | #define SCREEN_SIZE (SCREEN_SIZE_COLS * SCREEN_SIZE_ROWS * SCREEN_SIZE_BLEN)
14 |
15 | #define ATTR_BYTE_BLK_ON_BLK 0x00 /* BLACK ON BLACK */
16 | #define ATTR_BYTE_BLU_ON_BLK 0x01 /* BLUE ON BLACK */
17 | #define ATTR_BYTE_GRN_ON_BLK 0x02 /* GREEN ON BLACK */
18 | #define ATTR_BYTE_AQU_ON_BLK 0x03 /* AQUA ON BLACK */
19 | #define ATTR_BYTE_RED_ON_BLK 0x04 /* RED ON BLACK */
20 | #define ATTR_BYTE_MAG_ON_BLK 0x05 /* MAGENTA ON BLACK */
21 | #define ATTR_BYTE_ORG_ON_BLK 0x06 /* ORANGE ON BLACK */
22 | #define ATTR_BYTE_LGR_ON_BLK 0x07 /* L-GRAY ON BLACK */
23 | #define ATTR_BYTE_DGR_ON_BLK 0x08 /* D-GRAY ON BLACK */
24 | #define ATTR_BYTE_DBL_ON_BLK 0x09 /* DODGER-BLUE ON BLACK */
25 |
26 | #define ATTR_BYTE_TEXT_COLOR_STD ATTR_BYTE_LGR_ON_BLK
27 |
28 | static char *VGA_POINTER = (char*)0xb8000;
29 |
30 | static int VGA_CURSOR = 0;
31 |
32 | void vga_set_cursor(int __offset);
33 |
34 | int vga_get_cursor(void);
35 |
36 | void vga_newline(void);
37 | void vga_tab(void);
38 |
39 | void vga_putchar(char __c, unsigned short __cl);
40 |
41 | void vga_clear(void);
42 | void vga_backspace(void);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/include/fs/ata.h:
--------------------------------------------------------------------------------
1 | #ifndef ATA_H
2 | #define ATA_H
3 |
4 | #include
5 |
6 | #define ATA_REG_DATA 0x00
7 | #define ATA_REG_ERROR 0x01
8 | #define ATA_REG_FEATURES 0x01
9 | #define ATA_REG_SECCOUNT0 0x02
10 | #define ATA_REG_LBA0 0x03
11 | #define ATA_REG_LBA1 0x04
12 | #define ATA_REG_LBA2 0x05
13 | #define ATA_REG_HDDEVSEL 0x06
14 | #define ATA_REG_COMMAND 0x07
15 | #define ATA_REG_STATUS 0x07
16 | #define ATA_REG_SECCOUNT1 0x08
17 | #define ATA_REG_LBA3 0x09
18 | #define ATA_REG_LBA4 0x0A
19 | #define ATA_REG_LBA5 0x0B
20 | #define ATA_REG_CONTROL 0x0C
21 | #define ATA_REG_ALTSTATUS 0x0C
22 | #define ATA_REG_DEVADDRESS 0x0D
23 |
24 | // ATA drive status
25 | #define ATA_SR_BSY 0x80 // Busy
26 | #define ATA_SR_DRDY 0x40 // Drive ready
27 | #define ATA_SR_DF 0x20 // Drive write fault
28 | #define ATA_SR_DSC 0x10 // Drive seek complete
29 | #define ATA_SR_DRQ 0x08 // Data request ready
30 | #define ATA_SR_CORR 0x04 // Corrected data
31 | #define ATA_SR_IDX 0x02 // Index
32 | #define ATA_SR_ERR 0x01 // Error
33 |
34 | // ATA drive error status
35 | #define ATA_ER_BBK 0x80 // Bad block
36 | #define ATA_ER_UNC 0x40 // Uncorrectable data
37 | #define ATA_ER_MC 0x20 // Media changed
38 | #define ATA_ER_IDNF 0x10 // ID mark not found
39 | #define ATA_ER_MCR 0x08 // Media change request
40 | #define ATA_ER_ABRT 0x04 // Command aborted
41 | #define ATA_ER_TK0NF 0x02 // Track 0 not found
42 | #define ATA_ER_AMNF 0x01 // No address mark
43 |
44 |
45 | // Channels
46 | #define ATA_PRIMARY 0x00
47 | #define ATA_SECONDARY 0x01
48 |
49 | // IDE types
50 | #define IDE_ATA 0x00
51 | #define IDE_ATAPI 0x01
52 |
53 | // Command types
54 | #define ATA_CMD_READ_PIO 0x20
55 | #define ATA_CMD_READ_PIO_EXT 0x24
56 | #define ATA_CMD_READ_DMA 0xC8
57 | #define ATA_CMD_READ_DMA_EXT 0x25
58 | #define ATA_CMD_WRITE_PIO 0x30
59 | #define ATA_CMD_WRITE_PIO_EXT 0x34
60 | #define ATA_CMD_WRITE_DMA 0xCA
61 | #define ATA_CMD_WRITE_DMA_EXT 0x35
62 | #define ATA_CMD_CACHE_FLUSH 0xE7
63 | #define ATA_CMD_CACHE_FLUSH_EXT 0xEA
64 | #define ATA_CMD_PACKET 0xA0
65 | #define ATA_CMD_IDENTIFY_PACKET 0xA1
66 | #define ATA_CMD_IDENTIFY 0xEC
67 |
68 | // Identify types
69 | #define ATA_IDENT_DEVICETYPE 0
70 | #define ATA_IDENT_CYLINDERS 2
71 | #define ATA_IDENT_HEADS 6
72 | #define ATA_IDENT_SECTORS 12
73 | #define ATA_IDENT_SERIAL 20
74 | #define ATA_IDENT_MODEL 54
75 | #define ATA_IDENT_CAPABILITIES 98
76 | #define ATA_IDENT_FIELDVALID 106
77 | #define ATA_IDENT_MAX_LBA 120
78 | #define ATA_IDENT_COMMANDSETS 164
79 | #define ATA_IDENT_MAX_LBA_EXT 200
80 |
81 | /* Human error codes */
82 |
83 | #define ATA_ERROR_CODE_DF 19
84 | #define ATA_ERROR_CODE_AMNF 7
85 | #define ATA_ERROR_CODE_TK0NF 3
86 | #define ATA_ERROR_CODE_ABRT 20
87 | #define ATA_ERROR_CODE_MCR 3
88 | #define ATA_ERROR_CODE_IDNF 21
89 | #define ATA_ERROR_CODE_MC 3
90 | #define ATA_ERROR_CODE_UNC 22
91 | #define ATA_ERROR_CODE_BBK 13
92 |
93 | #define ATA_ERROR_CODE_NULL_READ 23
94 | #define ATA_ERROR_CODE_WRITE_PROTECTED 8
95 |
96 | /* Sector size */
97 |
98 | #define ATA_SECTOR_SIZE 512
99 |
100 | // Directions
101 | #define ATA_READ 0x00
102 | #define ATA_WRITE 0x01
103 |
104 | // LBA(Linear Block Address) modes
105 | #define LBA_MODE_48 0x02
106 | #define LBA_MODE_28 0x01
107 | #define LBA_MODE_CHS 0x00
108 |
109 | #define ATA_MODEL_SIZE 41
110 | #define ATA_MAX_CHANNELS 2
111 | #define ATA_MAX_DEVICES 5
112 |
113 | typedef struct __ata_channel
114 | {
115 | unsigned short __base;
116 | unsigned short __ctrl;
117 | unsigned short __bmid;
118 | unsigned short __nint;
119 | } __ata_channel_t;
120 |
121 | typedef struct __ata_device
122 | {
123 | unsigned char __active;
124 | unsigned char __channel;
125 | unsigned char __drive;
126 |
127 | unsigned short __type;
128 | unsigned short __sign;
129 | unsigned short __features;
130 |
131 | unsigned int __commands;
132 | unsigned int __size;
133 |
134 | unsigned char __model[ATA_MODEL_SIZE];
135 | } __ata_device_t;
136 |
137 | void ata_handler(unsigned int __prim_channel_base_addr, unsigned int __prim_channel_control_addr,
138 | unsigned int __sec_channel_base_addr, unsigned int __sec_channel_control_addr,
139 | unsigned int __bus_master_addr);
140 |
141 | unsigned char ata_read_register(unsigned char __channel, unsigned char __register);
142 |
143 | void ata_write_register(unsigned char __channel, unsigned char __register, unsigned char __data);
144 |
145 | void ata_flush_cache(unsigned char __drive);
146 |
147 | void ata_read_buffer(unsigned char __channel, unsigned char __register, unsigned int *__buffer, unsigned int __quads);
148 | void ata_write_buffer(unsigned char __channel, unsigned char __register, unsigned int *__buffer, unsigned int __quads);
149 |
150 | unsigned char ata_probe_drive(unsigned char __channel, unsigned char __advanced);
151 | unsigned char ata_print_error(unsigned int __drive, unsigned char __error);
152 |
153 | int ata_read_sectors(unsigned char __drive, unsigned char __sectors, unsigned int __lba, unsigned int* __buffer);
154 | int ata_write_sectors(unsigned char __drive, unsigned char __sectors, unsigned int __lba, unsigned int* __buffer);
155 |
156 | int ata_initialize(__pci_device_t *__dev);
157 |
158 | #endif
--------------------------------------------------------------------------------
/include/fs/device.h:
--------------------------------------------------------------------------------
1 | #ifndef DEVICE_H
2 | #define DEVICE_H
3 |
4 | #include
5 |
6 | typedef enum __device_type
7 | {
8 | DEVICE_UNKNOWN = 0,
9 | DEVICE_CHAR = 1,
10 | DEVICE_BLOCK = 2,
11 | } __device_type;
12 |
13 | typedef struct __device_t
14 | {
15 | char *__name;
16 |
17 | unsigned int __unique_id;
18 |
19 | __device_type __dev_type;
20 |
21 | __vfs_node_t *__fs;
22 |
23 | unsigned char (*__read)(unsigned char *__buffer, unsigned int __offset, unsigned int __len, void *__device);
24 | unsigned char (*__write)(unsigned char *__buffer, unsigned int __offset, unsigned int __len, void *__device);
25 |
26 | void *__private;
27 | } __device_t;
28 |
29 | void device_print(void);
30 | void device_init(void);
31 |
32 | int device_add(__device_t *__device);
33 |
34 | __device_t *device_get(unsigned int __id);
35 | __device_t *device_get_by_id(unsigned int __id);
36 |
37 | int device_get_number(void);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/include/fs/ext2.h:
--------------------------------------------------------------------------------
1 | #ifndef EXT2_H
2 | #define EXT2_H
3 |
4 | #define HARDDISK 0
5 |
6 | #define EXT2_MAGIC 0xEF53
7 |
8 | #define EXT2_CREATOR_ID_LINUX 0
9 | #define EXT2_CREATOR_ID_GNU_HURD 1
10 | #define EXT2_CREATOR_ID_MASIX 2
11 | #define EXT2_CREATOR_ID_FREEBSD 3
12 | #define EXT2_CREATOR_ID_OTHER 4
13 |
14 | #define EXT2_FILE_SYSTEM_CLEAN 1
15 | #define EXT2_FILE_SYSTEM_ERROR 2
16 |
17 | #pragma pack(push)
18 | #pragma push(1)
19 |
20 | typedef struct ext2_superblock_t {
21 | unsigned int total_inodes;
22 | unsigned int total_blocks;
23 | unsigned int su_blocks;
24 | unsigned int free_blocks;
25 | unsigned int free_inodes;
26 | unsigned int superblock_idx;
27 | unsigned int log2block_size;
28 | unsigned int log2frag_size;
29 | unsigned int blocks_per_group;
30 | unsigned int frags_per_group;
31 | unsigned int inodes_per_group;
32 | unsigned int mtime;
33 | unsigned int wtime;
34 | unsigned short mount_count;
35 | unsigned short mount_allowed_count;
36 | unsigned short ext2_magic;
37 | unsigned short fs_state;
38 | unsigned short err;
39 | unsigned short minor;
40 | unsigned int last_check;
41 | unsigned int interval;
42 | unsigned int os_id;
43 | unsigned int major;
44 | unsigned short r_userid;
45 | unsigned short r_groupid;
46 | unsigned int first_inode;
47 | unsigned short inode_size;
48 | unsigned short superblock_group;
49 | unsigned int optional_feature;
50 | unsigned int required_feature;
51 | unsigned int readonly_feature;
52 | char fs_id[16];
53 | char vol_name[16];
54 | char last_mount_path[64];
55 | unsigned int compression_method;
56 | unsigned char file_pre_alloc_blocks;
57 | unsigned char dir_pre_alloc_blocks;
58 | unsigned short unused1;
59 | char journal_id[16];
60 | unsigned int journal_inode;
61 | unsigned int journal_device;
62 | unsigned int orphan_head;
63 | } ext2_superblock_t;
64 |
65 | typedef struct ext2_bgd_t {
66 | unsigned int addrblockbmp;
67 | unsigned int addrinodebmp;
68 | unsigned int inodetable;
69 | unsigned short unallocb;
70 | unsigned short unalloci;
71 | unsigned short dircnt;
72 | unsigned short unused[7];
73 | } ext2_bgd_t;
74 |
75 | typedef struct ext2_inode_t {
76 | unsigned short perms;
77 | unsigned short uid;
78 | unsigned int sizelo;
79 | unsigned int accesstime;
80 | unsigned int creationtime;
81 | unsigned int modifiedtime;
82 | unsigned int deletedtime;
83 | unsigned short gid;
84 | unsigned short hardlinkcnt;
85 | unsigned int sectors;
86 | unsigned int flags;
87 | unsigned int oss;
88 | unsigned int blocks[15];
89 | unsigned int gennum;
90 | unsigned int eab;
91 | unsigned int sizehi;
92 | unsigned int fragaddr;
93 | unsigned char reserved[12];
94 | } ext2_inode_t;
95 |
96 | typedef struct ext2_direntry_t {
97 | unsigned int inode;
98 | unsigned int direntsize;
99 | unsigned int namelen;
100 | unsigned int type;
101 | char* name;
102 | } ext2_direntry_t;
103 |
104 | typedef struct ext2_t {
105 | ext2_inode_t* root_inode;
106 | ext2_superblock_t* superblock;
107 | ext2_bgd_t* bgds;
108 |
109 | unsigned int blocks_per_group;
110 | unsigned int inodes_per_group;
111 | unsigned int total_groups;
112 |
113 | unsigned int bgd_blocks;
114 | } ext2_t;
115 |
116 | void quantum_ext2_init();
117 |
118 | ext2_inode_t* ext2_read_inode(int inode_idx);
119 |
120 | void ext2_read_superblock(ext2_superblock_t* superblock);
121 |
122 | void ext2_show_superblock_info(ext2_superblock_t* superblock);
123 |
124 | char* ext2_creator_os(unsigned int creator_os);
125 |
126 | #endif
127 |
--------------------------------------------------------------------------------
/include/fs/vfs.h:
--------------------------------------------------------------------------------
1 | #ifndef VFS_H
2 | #define VFS_H
3 |
4 | #include
5 | #include
6 |
7 | #define VFS_PATH_SEPERATOR '/'
8 | #define VFS_PATH_UP ".."
9 | #define VFS_PATH_DOT "."
10 |
11 | #define VFS_EXT2_MAGIC 0xeeee2222
12 |
13 | #define O_RDONLY 0x0000
14 | #define O_WRONLY 0x0001
15 | #define O_RDWR 0x0002
16 | #define O_APPEND 0x0008
17 | #define O_CREAT 0x0200
18 | #define O_TRUNC 0x0400
19 | #define O_EXCL 0x0800
20 | #define O_NOFOLLOW 0x1000
21 | #define O_PATH 0x2000
22 |
23 | #define FS_FILE 0x01
24 | #define FS_DIRECTORY 0x02
25 | #define FS_CHARDEVICE 0x04
26 | #define FS_BLOCKDEVICE 0x08
27 | #define FS_PIPE 0x10
28 | #define FS_SYMLINK 0x20
29 | #define FS_MOUNTPOINT 0x40
30 | #define FS_SOCKET 0x80000000
31 |
32 | #define _IFMT 0170000 /* type of file */
33 | #define _IFDIR 0040000 /* directory */
34 | #define _IFCHR 0020000 /* character special */
35 | #define _IFBLK 0060000 /* block special */
36 | #define _IFREG 0100000 /* regular */
37 | #define _IFLNK 0120000 /* symbolic link */
38 | #define _IFSOCK 0140000 /* socket */
39 | #define _IFIFO 0010000 /* fifo */
40 |
41 | struct __vfs_node;
42 |
43 | #include
44 |
45 | typedef unsigned int (*get_file_size_callback) (struct __vfs_node *__node);
46 | typedef unsigned int (*read_callback) (struct __vfs_node *, unsigned int, unsigned int, char *);
47 | typedef unsigned int (*write_callback) (struct __vfs_node *, unsigned int, unsigned int, char *);
48 | typedef void (*open_callback) (struct __vfs_node *, unsigned int __flags);
49 | typedef void (*close_callback) (struct __vfs_node *);
50 | typedef struct dirent *(*readdir_callback) (struct __vfs_node *, unsigned int);
51 | typedef struct vfs_node *(*finddir_callback) (struct __vfs_node *, char *__name);
52 | typedef void (*create_callback) (struct __vfs_node *, char *__name, unsigned short __permission);
53 | typedef void (*unlink_callback) (struct __vfs_node *, char *__name);
54 | typedef void (*mkdir_callback) (struct __vfs_node *, char *__name, unsigned short __permission);
55 | typedef int (*ioctl_callback) (struct __vfs_node *, int __request, void *__argp);
56 | typedef int (*get_size_callback) (struct __vfs_node *);
57 | typedef void (*chmod_callback) (struct __vfs_node *, unsigned int __mode);
58 | typedef char ** (*listdir_callback) (struct __vfs_node *);
59 |
60 | typedef struct __vfs_node {
61 | // Baisc information about a file(note: in linux, everything is file, so the vfs_node could be used to describe a file, directory or even a device!)
62 | char __name[256];
63 |
64 | void *__device;
65 |
66 | unsigned int __mask;
67 | unsigned int __uid;
68 | unsigned int __gid;
69 | unsigned int __flags;
70 | unsigned int __inode_num;
71 | unsigned int __size;
72 | unsigned int __fs_type;
73 | unsigned int __open_flags;
74 | // Time
75 | unsigned int __create_time;
76 | unsigned int __access_time;
77 | unsigned int __modified_time;
78 |
79 | unsigned int __offset;
80 |
81 | unsigned __nlink;
82 |
83 | int __refcount;
84 |
85 | socket_t* socket;
86 |
87 | // File operations
88 | read_callback read;
89 | write_callback write;
90 | open_callback open;
91 | close_callback close;
92 | readdir_callback readdir;
93 | finddir_callback finddir;
94 | create_callback create;
95 | unlink_callback unlink;
96 | mkdir_callback mkdir;
97 | ioctl_callback ioctl;
98 | get_size_callback get_size;
99 | chmod_callback chmod;
100 | get_file_size_callback get_file_size;
101 |
102 | listdir_callback listdir;
103 | } __vfs_node_t;
104 |
105 | struct dirent {
106 | char __name[256];
107 |
108 | unsigned int __inode_num;
109 | };
110 |
111 | typedef struct __vfs_entry {
112 | char *__name;
113 |
114 | __vfs_node_t *__file;
115 | } __vfs_entry_t;
116 |
117 | unsigned int vfs_get_file_size(__vfs_node_t *node);
118 |
119 | unsigned int vfs_read(__vfs_node_t *__node, unsigned int __offset, unsigned int __size, char *__buffer);
120 | unsigned int vfs_write(__vfs_node_t *__node, unsigned int __offset, unsigned int __size, char *__buffer);
121 |
122 | void vfs_open(__vfs_node_t *__node, unsigned int __flags);
123 | void vfs_close(__vfs_node_t *__node);
124 |
125 | __vfs_node_t *vfs_finddir(__vfs_node_t *node, char *name);
126 |
127 | void vfs_mkdir(char *__name, unsigned short __permission);
128 |
129 | void vfs_mkfile(char *__name, unsigned short __permission);
130 |
131 | int vfs_create_file(char *__name, unsigned short __permission);
132 |
133 | __vfs_node_t *file_open(const char *__file, unsigned int __flags);
134 |
135 | char *expand_path(char *__input);
136 |
137 | int vfs_ioctl(__vfs_node_t *__node, int __request, void *__argp);
138 |
139 | void vfs_chmod(__vfs_node_t *__node, unsigned int __mode);
140 |
141 | void vfs_unlink(char *__name);
142 |
143 | int vfs_symlink(char *__value, char *__name);
144 | int vfs_readlink(__vfs_node_t *node, char *__buf, unsigned int __size);
145 |
146 | void vfs_init(void);
147 | void vfs_mount(char *__path, __vfs_node_t *__fs);
148 |
149 | typedef __vfs_node_t *(* __vfs_mount_callback) (char *__arg, char *__mountpoint);
150 |
151 | void vfs_register(char *__name, __vfs_mount_callback __caller);
152 | void vfs_mount_dev(char *_mountpoint, __vfs_node_t *_node);
153 | void vfs_mount_recur(char *__path, __gtreenode_t *__subroot, __vfs_node_t *__fs);
154 |
155 | void print_vfstree(void);
156 | void vfs_db_listdir(char *__name);
157 |
158 | __vfs_node_t *vfs_get_mountpoint_recur(char **__path, __gtreenode_t *__subroot);
159 | __vfs_node_t *vfs_get_mountpoint(char **__path);
160 |
161 |
162 | #endif
163 |
--------------------------------------------------------------------------------
/include/net/ethernet.h:
--------------------------------------------------------------------------------
1 | #ifndef ETHERNET_H
2 | #define ETHERNET_H
3 |
4 | #include
5 |
6 | int ethernet_initalize(__pci_device_t* __dev);
7 |
8 | #endif
--------------------------------------------------------------------------------
/include/net/socket.h:
--------------------------------------------------------------------------------
1 | #ifndef SOCKET_H
2 | #define SOCKET_H
3 |
4 | typedef struct __socket_t {
5 | int domain;
6 | int type;
7 | int protocol;
8 |
9 | long ref;
10 | void* p;
11 | } socket_t;
12 |
13 | #include
14 |
15 | /* Took from sys/socket.h linux header */
16 | #define AF_UNSPEC 0 /* Unspecified. */
17 | #define AF_LOCAL 1 /* Local to host (pipes and file-domain). */
18 | #define AF_UNIX AF_LOCAL /* POSIX name for PF_LOCAL. */
19 | #define AF_FILE AF_LOCAL /* Another non-standard name for PF_LOCAL. */
20 | #define AF_INET 2 /* IP protocol family. */
21 | #define AF_AX25 3 /* Amateur Radio AX.25. */
22 | #define AF_IPX 4 /* Novell Internet Protocol. */
23 | #define AF_APPLETALK 5 /* Appletalk DDP. */
24 | #define AF_NETROM 6 /* Amateur radio NetROM. */
25 | #define AF_BRIDGE 7 /* Multiprotocol bridge. */
26 | #define AF_ATMPVC 8 /* ATM PVCs. */
27 | #define AF_X25 9 /* Reserved for X.25 project. */
28 | #define AF_INET6 10 /* IP version 6. */
29 | #define AF_ROSE 11 /* Amateur Radio X.25 PLP. */
30 | #define AF_DECnet 12 /* Reserved for DECnet project. */
31 | #define AF_NETBEUI 13 /* Reserved for 802.2LLC project. */
32 | #define AF_SECURITY 14 /* Security callback pseudo AF. */
33 | #define AF_KEY 15 /* PF_KEY key management API. */
34 | #define AF_NETLINK 16
35 | #define AF_ROUTE AF_NETLINK /* Alias to emulate 4.4BSD. */
36 | #define AF_PACKET 17 /* Packet family. */
37 | #define AF_ASH 18 /* Ash. */
38 | #define AF_ECONET 19 /* Acorn Econet. */
39 | #define AF_ATMSVC 20 /* ATM SVCs. */
40 | #define AF_RDS 21 /* RDS sockets. */
41 | #define AF_SNA 22 /* Linux SNA Project */
42 | #define AF_IRDA 23 /* IRDA sockets. */
43 | #define AF_PPPOX 24 /* PPPoX sockets. */
44 | #define AF_WANPIPE 25 /* Wanpipe API sockets. */
45 | #define AF_LLC 26 /* Linux LLC. */
46 | #define AF_IB 27 /* Native InfiniBand address. */
47 | #define AF_MPLS 28 /* MPLS. */
48 | #define AF_CAN 29 /* Controller Area Network. */
49 | #define AF_TIPC 30 /* TIPC sockets. */
50 | #define AF_BLUETOOTH 31 /* Bluetooth sockets. */
51 | #define AF_IUCV 32 /* IUCV sockets. */
52 | #define AF_RXRPC 33 /* RxRPC sockets. */
53 | #define AF_ISDN 34 /* mISDN sockets. */
54 | #define AF_PHONET 35 /* Phonet sockets. */
55 | #define AF_IEEE802154 36 /* IEEE 802.15.4 sockets. */
56 | #define AF_CAIF 37 /* CAIF sockets. */
57 | #define AF_ALG 38 /* Algorithm sockets. */
58 | #define AF_NFC 39 /* NFC sockets. */
59 | #define AF_VSOCK 40 /* vSockets. */
60 | #define AF_KCM 41 /* Kernel Connection Multiplexor. */
61 | #define AF_QIPCRTR 42 /* Qualcomm IPC Router. */
62 | #define AF_SMC 43 /* SMC sockets. */
63 | #define AF_XDP 44 /* XDP sockets. */
64 | #define AF_MAX 45 /* For now.. */
65 |
66 | #define SOCK_STREAM 1
67 | #define SOCK_DGRAM 2
68 | #define SOCK_RAW 3
69 | #define SOCK_RDM 4
70 | #define SOCK_SEQPACKET 5
71 | #define SOCK_DCCP 6
72 | #define SOCK_PACKET 10
73 | #define SOCK_CLOEXEC 02000000
74 | #define SOCK_NONBLOCK 00004000
75 |
76 | typedef unsigned int socklen_t;
77 | typedef struct __sockaddr {
78 | unsigned short int sa_family;
79 | unsigned char sa_data[14];
80 | } sockaddr;
81 |
82 | int socket_create(struct __vfs_node* file, int domain, int type, int protocol);
83 |
84 | int socket_accept(struct __vfs_node* file, struct __vfs_node* conn, sockaddr* addr, socklen_t* len);
85 |
86 | int socket_bind(struct __vfs_node* file, sockaddr* addr, unsigned int len);
87 |
88 | int socket_connect(struct __vfs_node* file, sockaddr* addr, unsigned int len);
89 |
90 | int socket_listen(struct __vfs_node* file, int backlog);
91 |
92 | int socket_send(struct __vfs_node* file, void* buf, unsigned long len, int flags);
93 |
94 | int socket_recv(struct __vfs_node* file, void* buf, unsigned long len, int flags);
95 |
96 | int socket_can_read(struct __vfs_node* file, unsigned long len);
97 |
98 | int socket_can_write(struct __vfs_node* file, unsigned long len);
99 |
100 | int socket_shutdown(struct __vfs_node* file, int how);
101 |
102 | #endif
--------------------------------------------------------------------------------
/include/net/unix.h:
--------------------------------------------------------------------------------
1 | #ifndef SOCKET_UNIX_H
2 | #define SOCKET_UNIX_H
3 |
4 | #include
5 |
6 | int unix_socket_create(struct __vfs_node* file, int domain, int type, int protocol);
7 |
8 | int unix_socket_accept(struct __vfs_node* file, struct __vfs_node* conn, sockaddr* addr, socklen_t* len);
9 |
10 | int unix_socket_bind(struct __vfs_node* file, sockaddr* addr, unsigned int len);
11 |
12 | int unix_socket_connect(struct __vfs_node* file, sockaddr* addr, unsigned int len);
13 |
14 | int unix_socket_listen(struct __vfs_node* file, int backlog);
15 |
16 | int unix_socket_send(struct __vfs_node* file, void* buf, unsigned long len, int flags);
17 |
18 | int unix_socket_recv(struct __vfs_node* file, void* buf, unsigned long len, int flags);
19 |
20 | int unix_socket_can_read(struct __vfs_node* file, unsigned long len);
21 |
22 | int unix_socket_can_write(struct __vfs_node* file, unsigned long len);
23 |
24 | int unix_socket_shutdown(struct __vfs_node* file, int how);
25 |
26 | #endif
--------------------------------------------------------------------------------
/include/quantum/init.h:
--------------------------------------------------------------------------------
1 | #ifndef INIT_H
2 | #define INIT_H
3 |
4 | #include
5 | #include
6 |
7 | int quantum_get_kernel_mmap(KERNEL_MEMORY_MAP *__map, multiboot_info_t *__mboot);
8 |
9 | void quantum_info(char* file, int __status, char* header, char* format, ...);
10 |
11 | void quantum_gdt_init(void);
12 |
13 | void quantum_idt_init(void);
14 |
15 | void quantum_memory_init(void);
16 |
17 | void quantum_keyboard_init(void);
18 |
19 | void quantum_pmm_init(unsigned long __addr);
20 |
21 | void quantum_vfs_init(void);
22 |
23 | void quantum_ata_init(void);
24 |
25 | void quantum_devmgr_init(void);
26 |
27 | void quantum_pci_init(void);
28 |
29 | void quantum_migrate_to_kernel_mode(void);
30 |
31 | void quantum_migrate_to_userspace(void);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/include/quantum/kernel.h:
--------------------------------------------------------------------------------
1 | #ifndef KERNEL_H
2 | #define KERNEL_H
3 |
4 | // symbols from linker.ld for section addresses
5 | extern unsigned char __kernel_section_start;
6 | extern unsigned char __kernel_section_end;
7 | extern unsigned char __kernel_text_section_start;
8 | extern unsigned char __kernel_text_section_end;
9 | extern unsigned char __kernel_data_section_start;
10 | extern unsigned char __kernel_data_section_end;
11 | extern unsigned char __kernel_rodata_section_start;
12 | extern unsigned char __kernel_rodata_section_end;
13 | extern unsigned char __kernel_bss_section_start;
14 | extern unsigned char __kernel_bss_section_end;
15 |
16 | typedef struct
17 | {
18 | struct
19 | {
20 | unsigned int __kernel_start;
21 | unsigned int __kernel_end;
22 | unsigned int __kernel_len;
23 |
24 | unsigned int __text_start;
25 | unsigned int __text_end;
26 | unsigned int __text_len;
27 |
28 | unsigned int __data_start;
29 | unsigned int __data_end;
30 | unsigned int __data_len;
31 |
32 | unsigned int __rodata_start;
33 | unsigned int __rodata_end;
34 | unsigned int __rodata_len;
35 |
36 | unsigned int __bss_start;
37 | unsigned int __bss_end;
38 | unsigned int __bss_len;
39 | } __kernel;
40 |
41 | struct
42 | {
43 | unsigned int __total_memory;
44 | } __system;
45 |
46 | struct
47 | {
48 | unsigned long __start;
49 | unsigned long __end;
50 | unsigned long __size;
51 | } __available;
52 | } KERNEL_MEMORY_MAP;
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/include/quantum/kernel_menu.h:
--------------------------------------------------------------------------------
1 | #ifndef KERNEL_MENU_H
2 | #define KERNEL_MENU_H
3 |
4 | typedef struct __kernel_menu_selection_item_t {
5 | char* name;
6 | } kernel_menu_selection_item_t;
7 |
8 | void quantum_menu();
9 |
10 | #endif
--------------------------------------------------------------------------------
/include/quantum/kmode.h:
--------------------------------------------------------------------------------
1 | #ifndef KMODE_H
2 | #define KMODE_H
3 |
4 | #define KMODE_PROMPT "QuantumOS > "
5 |
6 | void kmode_initialize(void);
7 |
8 | #endif
--------------------------------------------------------------------------------
/include/quantum/module.h:
--------------------------------------------------------------------------------
1 | #ifndef MODULE_H
2 | #define MODULE_H
3 |
4 | #define MODULE_NAME(__NAME) static char *__MODULE_NAME __attribute__((unused)) = __NAME;
5 | #define MODULE_INIT(__FUNC) static void *__MODULE_INIT_POINTER __attribute__((unused)) = &__FUNC;
6 | #define MODULE_EXIT(__FUNC) static void *__MODULE_EXIT_POINTER __attribute__((unused)) = &__FUNC;
7 |
8 | #define EXPORT_SYMBOL(__FUNC) __module_add(#__FUNC, __FUNC);
9 |
10 | void __module_init(void);
11 | void __module_call(char *__func);
12 | void __module_add(char *__func, unsigned int __addr);
13 |
14 | void __module_wakeup(void);
15 |
16 | #endif
--------------------------------------------------------------------------------
/include/sys/acpi.h:
--------------------------------------------------------------------------------
1 | #ifndef ACPI_H
2 | #define ACPI_H
3 |
4 | #define KEYBOARD_CONTROL 0x64
5 | #define KEYBOARD_RESET 0xFE
6 | #define KEYBOARD_DATA 0x60
7 |
8 | #define KEYBOARD_BIT_KDATA 0
9 | #define KEYBOARD_BIT_UDATA 1
10 |
11 | #define RSD_SIGNATURE "RSD PTR "
12 |
13 | typedef struct rsdp_t {
14 | unsigned char signature[8];
15 | unsigned char check_sum;
16 | unsigned char oem_id[6];
17 | unsigned char revision;
18 | unsigned short* rsdp_addr;
19 | } rsdp_t;
20 |
21 | typedef struct rsdt_t {
22 | char signature[4];
23 | unsigned int length;
24 | unsigned char revision;
25 | unsigned char checksum;
26 | char oem_id[6];
27 | char oem_table_id[6];
28 | unsigned int oem_revision;
29 | unsigned int creator_id;
30 | unsigned int creator_revision;
31 | char data[];
32 | } rsdt_t;
33 |
34 | #define __acpi_set_bit(__n) (1 << (__n))
35 | #define __acpi_check_bit(__flags, __n) ((__flags) & __acpi_set_bit(__n))
36 |
37 | void quantum_acpi_init();
38 |
39 | void acpi_reboot(void);
40 |
41 | void acpi_shutdown();
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/include/sys/cmos.h:
--------------------------------------------------------------------------------
1 | #ifndef CMOS_H
2 | #define CMOS_H
3 |
4 | #include
5 |
6 | #define CMOS_ADDRESS 0x70
7 | #define CMOS_DATA 0x71
8 |
9 | #define RTC_REGISTER_SECOND 0x00
10 | #define RTC_REGISTER_MINUT 0x02
11 | #define RTC_REGISTER_HOUR 0x04
12 | #define RTC_REGISTER_DAY 0x07
13 | #define RTC_REGISTER_MONTH 0x08
14 | #define RTC_REGISTER_YEAR 0x09
15 | #define RTC_REGISTER_CENTURY NULL
16 |
17 | #define RTC_REGISTER_MEMORY_LOW 0x30
18 | #define RTC_REGISTER_MEMORY_HIGH 0x31
19 |
20 | #define RTC_REGISTER_B 0x0B
21 |
22 | typedef struct __date_t {
23 | int milisecond;
24 | int second;
25 | int minute;
26 | int hour;
27 | int day;
28 | int month;
29 | int year;
30 | int century;
31 | } date_t;
32 |
33 | typedef enum __time_zone_t {
34 | TIME_ZONES_UTC_MINUS_12, // UTC -12:00
35 | TIME_ZONES_UTC_MINUS_11, // UTC -11:00
36 | TIME_ZONES_UTC_MINUS_10, // UTC -10:00
37 | TIME_ZONES_UTC_MINUS_9_30, // UTC -09:30
38 | TIME_ZONES_UTC_MINUS_9, // UTC -09:00
39 | TIME_ZONES_UTC_MINUS_8, // UTC -08:00
40 | TIME_ZONES_UTC_MINUS_7, // UTC -07:00
41 | TIME_ZONES_UTC_MINUS_6, // UTC -06:00
42 | TIME_ZONES_UTC_MINUS_5, // UTC -05:00
43 | TIME_ZONES_UTC_MINUS_4, // UTC -04:00
44 | TIME_ZONES_UTC_MINUS_3_30, // UTC -03:30
45 | TIME_ZONES_UTC_MINUS_3, // UTC -03:00
46 | TIME_ZONES_UTC_MINUS_2, // UTC -02:00
47 | TIME_ZONES_UTC_MINUS_1, // UTC -01:00
48 | TIME_ZONES_UTC_0, // UTC -00:00
49 | TIME_ZONES_UTC_PLUS_1, // UTC +01:00
50 | TIME_ZONES_UTC_PLUS_2, // UTC +02:00
51 | TIME_ZONES_UTC_PLUS_3, // UTC +03:00
52 | TIME_ZONES_UTC_PLUS_3_30, // UTC +03:30
53 | TIME_ZONES_UTC_PLUS_4, // UTC +04:00
54 | TIME_ZONES_UTC_PLUS_4_30, // UTC +04:30
55 | TIME_ZONES_UTC_PLUS_5, // UTC +05:00
56 | TIME_ZONES_UTC_PLUS_5_30, // UTC +05:30
57 | TIME_ZONES_UTC_PLUS_5_45, // UTC +05:45
58 | TIME_ZONES_UTC_PLUS_6, // UTC +06:00
59 | TIME_ZONES_UTC_PLUS_6_30, // UTC +06:30
60 | TIME_ZONES_UTC_PLUS_7, // UTC +07:00
61 | TIME_ZONES_UTC_PLUS_8, // UTC +08:00
62 | TIME_ZONES_UTC_PLUS_8_45, // UTC +08:45
63 | TIME_ZONES_UTC_PLUS_9, // UTC +09:00
64 | TIME_ZONES_UTC_PLUS_9_30, // UTC +09:30
65 | TIME_ZONES_UTC_PLUS_10, // UTC +10:00
66 | TIME_ZONES_UTC_PLUS_10_30, // UTC +10:30
67 | TIME_ZONES_UTC_PLUS_11, // UTC +11:00
68 | TIME_ZONES_UTC_PLUS_12, // UTC +12:00
69 | TIME_ZONES_UTC_PLUS_12_45, // UTC +12:45
70 | TIME_ZONES_UTC_PLUS_13, // UTC +13:00
71 | TIME_ZONES_UTC_PLUS_14, // UTC +14:00
72 | } time_zone_t;
73 |
74 | typedef struct __time_zone_struct_t {
75 | int offset_hour;
76 | int offset_minute;
77 | } time_zone_struct_t;
78 |
79 | void quantum_time_init();
80 |
81 | void set_time_zone(time_zone_t __time_zone);
82 |
83 | time_zone_t convert_str_to_time_zone(char* time_zone_str);
84 |
85 | BOOL get_update_in_progress_flag();
86 |
87 | unsigned char get_rtc_register(int reg);
88 |
89 | date_t get_date_cmos();
90 |
91 | #endif
--------------------------------------------------------------------------------
/include/sys/idt.h:
--------------------------------------------------------------------------------
1 | #ifndef IDT_H
2 | #define IDT_H
3 |
4 | #define IDE_DESCRIPTOR_COUNT 256
5 |
6 | typedef struct
7 | {
8 | unsigned short __base_low;
9 | unsigned short __segment_selector;
10 |
11 | unsigned char __zero;
12 | unsigned char __type;
13 |
14 | unsigned short __base_high;
15 | } __attribute__((packed)) IDT;
16 |
17 | typedef struct
18 | {
19 | unsigned short __limit;
20 |
21 | unsigned int __base;
22 | } __attribute__((packed)) IDT_PTR;
23 |
24 | extern void load_idt(unsigned int __idt_ptr);
25 |
26 | void idt_set_entry(int __index, unsigned int __base, unsigned short __seg, unsigned char __flags);
27 | void idt_enable(void);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/sys/isr.h:
--------------------------------------------------------------------------------
1 | #ifndef ISR_H
2 | #define ISR_H
3 |
4 | #define NULL (void *) 0
5 |
6 | #define IRQ_BASE 0x20
7 | #define IRQ0_TIMER 0x00
8 | #define IRQ1_KEYBOARD 0x01
9 | #define IRQ2_CASCADE 0x02
10 | #define IRQ3_SERIAL_PORT2 0x03
11 | #define IRQ4_SERIAL_PORT1 0x04
12 | #define IRQ5_RESERVED 0x05
13 | #define IRQ6_DISKETTE_DRIVE 0x06
14 | #define IRQ7_PARALLEL_PORT 0x07
15 | #define IRQ8_CMOS_CLOCK 0x08
16 | #define IRQ9_CGA 0x09
17 | #define IRQ10_RESERVED 0x0A
18 | #define IRQ11_RESERVED 0x0B
19 | #define IRQ12_AUXILIARY 0x0C
20 | #define IRQ13_FPU 0x0D
21 | #define IRQ14_HARD_DISK 0x0E
22 | #define IRQ15_RESERVED 0x0F
23 |
24 | #define INTERRUPT_HANDLERS_COUNT 256
25 |
26 | typedef struct registers
27 | {
28 | unsigned int ds;
29 | unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
30 | unsigned int int_no, err_code;
31 | unsigned int eip, cs, eflags, useresp, ss;
32 | } __registers_t;
33 |
34 | typedef struct registers16
35 | {
36 | unsigned short di, si, bp, sp, bx, dx, cx, ax;
37 | unsigned short ds, es, fs, gs, ss, eflags;
38 | } __registers16_t;
39 |
40 | typedef void (*ISR) (__registers_t *);
41 |
42 | void isr_register_interrupt_handler(int __index, ISR __handler);
43 | void isr_end_interrupt(int __index);
44 | void isr_exception_handler(__registers_t __regs);
45 | void isr_irq_handler(__registers_t *__regs);
46 |
47 | extern void exception_0();
48 | extern void exception_1();
49 | extern void exception_2();
50 | extern void exception_3();
51 | extern void exception_4();
52 | extern void exception_5();
53 | extern void exception_6();
54 | extern void exception_7();
55 | extern void exception_8();
56 | extern void exception_9();
57 | extern void exception_10();
58 | extern void exception_11();
59 | extern void exception_12();
60 | extern void exception_13();
61 | extern void exception_14();
62 | extern void exception_15();
63 | extern void exception_16();
64 | extern void exception_17();
65 | extern void exception_18();
66 | extern void exception_19();
67 | extern void exception_20();
68 | extern void exception_21();
69 | extern void exception_22();
70 | extern void exception_23();
71 | extern void exception_24();
72 | extern void exception_25();
73 | extern void exception_26();
74 | extern void exception_27();
75 | extern void exception_28();
76 | extern void exception_29();
77 | extern void exception_30();
78 | extern void exception_31();
79 | extern void exception_128();
80 |
81 | extern void irq_0();
82 | extern void irq_1();
83 | extern void irq_2();
84 | extern void irq_3();
85 | extern void irq_4();
86 | extern void irq_5();
87 | extern void irq_6();
88 | extern void irq_7();
89 | extern void irq_8();
90 | extern void irq_9();
91 | extern void irq_10();
92 | extern void irq_11();
93 | extern void irq_12();
94 | extern void irq_13();
95 | extern void irq_14();
96 | extern void irq_15();
97 |
98 | #endif
--------------------------------------------------------------------------------
/include/sys/kgdt.h:
--------------------------------------------------------------------------------
1 | #ifndef GDT_H
2 | #define GDT_H
3 |
4 | #define GDT_DESCRIPTOR_COUNT 8
5 |
6 | struct tss_entry_struct
7 | {
8 | unsigned int prev_tss;
9 | unsigned int esp0;
10 | unsigned int ss0;
11 | unsigned int esp1;
12 | unsigned int ss1;
13 | unsigned int esp2;
14 | unsigned int ss2;
15 | unsigned int cr3;
16 | unsigned int eip;
17 | unsigned int eflags;
18 | unsigned int eax;
19 | unsigned int ecx;
20 | unsigned int edx;
21 | unsigned int ebx;
22 | unsigned int esp;
23 | unsigned int ebp;
24 | unsigned int esi;
25 | unsigned int edi;
26 | unsigned int es;
27 | unsigned int cs;
28 | unsigned int ss;
29 | unsigned int ds;
30 | unsigned int fs;
31 | unsigned int gs;
32 | unsigned int ldt;
33 | unsigned short trap;
34 | unsigned short iomap_base;
35 | } __attribute__((packed));
36 |
37 | typedef struct tss_entry_struct tss_entry_t;
38 |
39 | typedef struct
40 | {
41 | unsigned short __segment_limit;
42 | unsigned short __base_low;
43 |
44 | unsigned char __base_mid;
45 | unsigned char __access;
46 | unsigned char __granularity;
47 | unsigned char __base_high;
48 | } __attribute__((packed)) GDT;
49 |
50 | typedef struct
51 | {
52 | unsigned short __limit;
53 |
54 | unsigned int __base;
55 | } __attribute__((packed)) GDT_PTR;
56 |
57 | void gdt_set_entry(int __index, unsigned int __base, unsigned int __limit, unsigned char __access, unsigned char __gran);
58 |
59 | void gdt_enable(void);
60 |
61 | #endif
--------------------------------------------------------------------------------
/include/sys/ksyms.h:
--------------------------------------------------------------------------------
1 | #ifndef KSYMS_H
2 | #define KSYMS_H
3 |
4 | #include
5 |
6 | typedef struct elf32_shdr_t {
7 | unsigned int name;
8 | unsigned int type;
9 | unsigned int flags;
10 | unsigned int addr;
11 | unsigned int offset;
12 | unsigned int size;
13 | unsigned int link;
14 | unsigned int info;
15 | unsigned int addralign;
16 | unsigned int entsize;
17 | } elf32_shdr_t;
18 |
19 | typedef struct elf32_sym_t {
20 | unsigned int name;
21 | unsigned int value;
22 | unsigned int size;
23 | unsigned char info;
24 | unsigned char other;
25 | unsigned short shndx;
26 | } elf32_sym_t;
27 |
28 | void quantum_ksyms_init(unsigned long addr);
29 |
30 | elf32_sym_t* get_ksym_by_address(unsigned int addr);
31 |
32 | char* get_shdr_string(unsigned int index);
33 |
34 | #endif
--------------------------------------------------------------------------------
/include/sys/lapic.h:
--------------------------------------------------------------------------------
1 | #ifndef LAPIC_H
2 | #define LAPIC_H
3 |
4 | #define LAPIC_ID 0x0020 // Local APIC ID
5 | #define LAPIC_VER 0x0030 // Local APIC Version
6 | #define LAPIC_TPR 0x0080 // Task Priority
7 | #define LAPIC_APR 0x0090 // Arbitration Priority
8 | #define LAPIC_PPR 0x00a0 // Processor Priority
9 | #define LAPIC_EOI 0x00b0 // EOI
10 | #define LAPIC_RRD 0x00c0 // Remote Read
11 | #define LAPIC_LDR 0x00d0 // Logical Destination
12 | #define LAPIC_DFR 0x00e0 // Destination Format
13 | #define LAPIC_SVR 0x00f0 // Spurious Interrupt Vector
14 | #define LAPIC_ISR 0x0100 // In-Service (8 registers)
15 | #define LAPIC_TMR 0x0180 // Trigger Mode (8 registers)
16 | #define LAPIC_IRR 0x0200 // Interrupt Request (8 registers)
17 | #define LAPIC_ESR 0x0280 // Error Status
18 | #define LAPIC_ICRLO 0x0300 // Interrupt Command
19 | #define LAPIC_ICRHI 0x0310 // Interrupt Command [63:32]
20 | #define LAPIC_TIMER 0x0320 // LVT Timer
21 | #define LAPIC_THERMAL 0x0330 // LVT Thermal Sensor
22 | #define LAPIC_PERF 0x0340 // LVT Performance Counter
23 | #define LAPIC_LINT0 0x0350 // LVT LINT0
24 | #define LAPIC_LINT1 0x0360 // LVT LINT1
25 | #define LAPIC_ERROR 0x0370 // LVT Error
26 | #define LAPIC_TICR 0x0380 // Initial Count (for Timer)
27 | #define LAPIC_TCCR 0x0390 // Current Count (for Timer)
28 | #define LAPIC_TDCR 0x03e0 // Divide Configuration (for Timer)
29 |
30 | // ------------------------------------------------------------------------------------------------
31 | // Interrupt Command Register
32 |
33 | // Delivery Mode
34 | #define ICR_FIXED 0x00000000
35 | #define ICR_LOWEST 0x00000100
36 | #define ICR_SMI 0x00000200
37 | #define ICR_NMI 0x00000400
38 | #define ICR_INIT 0x00000500
39 | #define ICR_STARTUP 0x00000600
40 |
41 | // Destination Mode
42 | #define ICR_PHYSICAL 0x00000000
43 | #define ICR_LOGICAL 0x00000800
44 |
45 | // Delivery Status
46 | #define ICR_IDLE 0x00000000
47 | #define ICR_SEND_PENDING 0x00001000
48 |
49 | // Level
50 | #define ICR_DEASSERT 0x00000000
51 | #define ICR_ASSERT 0x00004000
52 |
53 | // Trigger Mode
54 | #define ICR_EDGE 0x00000000
55 | #define ICR_LEVEL 0x00008000
56 |
57 | // Destination Shorthand
58 | #define ICR_NO_SHORTHAND 0x00000000
59 | #define ICR_SELF 0x00040000
60 | #define ICR_ALL_INCLUDING_SELF 0x00080000
61 | #define ICR_ALL_EXCLUDING_SELF 0x000c0000
62 |
63 | // Destination Field
64 | #define ICR_DESTINATION_SHIFT 24
65 |
66 | extern unsigned char *__global_apic_addr;
67 |
68 | unsigned int lapic_in(unsigned int __register);
69 |
70 | void lapic_out(unsigned int __register, unsigned int __data);
71 |
72 | void lapic_init(void);
73 | void lapic_send_init(unsigned int __id);
74 | void lapic_send_startup(unsigned int __id, unsigned int __vector);
75 |
76 | unsigned int lapic_getid(void);
77 |
78 | #endif
--------------------------------------------------------------------------------
/include/sys/memory.h:
--------------------------------------------------------------------------------
1 | #ifndef MEMORY_H
2 | #define MEMORY_H
3 |
4 | #include
5 |
6 | typedef struct __kmem_memory_block
7 | {
8 | struct
9 | {
10 | unsigned int __size;
11 | unsigned char __is_free;
12 | } __metainfo;
13 |
14 | struct __kmem_memory_block *__next;
15 |
16 | void *__address;
17 | } __attribute__((packed)) MEMORY_BLOCK;
18 |
19 | BOOL kmem_is_free(MEMORY_BLOCK *__block);
20 |
21 | MEMORY_BLOCK *kmem_get_worst_fit(int __size);
22 | MEMORY_BLOCK *kmem_new_block(int __size);
23 |
24 | void kmem_initialize(void *__start, void *__end);
25 |
26 | void *kbrk(int __size);
27 |
28 | void *kmalloc(int __size);
29 | void *kcalloc(int __n, int __size);
30 | void *krealloc(void *__address, int __nsize);
31 |
32 | void *kmemcpy(void *__dest, const void *__src, unsigned int __n);
33 | void *kmemcpys(void *__dest, char *__src, unsigned int __n);
34 | void kmemswap(unsigned char* a, unsigned char* b, unsigned int len);
35 | void *kmemset(void *__dest, char __c, unsigned int __n);
36 | void *memset(void *__dest, char __c, unsigned int __n);
37 | int kmemcmp(char *m1, char *m2, int n);
38 |
39 | unsigned long kmem_get_memory_usage();
40 | unsigned long kmem_get_total_memory_size();
41 | unsigned long kmem_get_memory_usage_precent();
42 |
43 | void kfree(void *__address);
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/include/sys/mio.h:
--------------------------------------------------------------------------------
1 | #ifndef MIO_H
2 | #define MIO_H
3 |
4 | void mio_out8(void *__ptr, unsigned char __data);
5 | void mio_out16(void *__ptr, unsigned short __data);
6 | void mio_out32(void *__ptr, unsigned int __data);
7 |
8 | unsigned char mio_in8(void *__ptr);
9 | unsigned short mio_in16(void *__ptr);
10 | unsigned int mio_in32(void *__ptr);
11 |
12 | #endif
--------------------------------------------------------------------------------
/include/sys/paging.h:
--------------------------------------------------------------------------------
1 | #ifndef PAGING_H
2 | #define PAGING_H
3 |
4 | typedef struct __page_t {
5 | unsigned int present : 1;
6 | unsigned int rw : 1;
7 | unsigned int user : 1;
8 | unsigned int accessed : 1;
9 | unsigned int dirty : 1;
10 | unsigned int unused : 7;
11 | unsigned int frame : 20;
12 | } page_t;
13 |
14 | void quantum_paging_init();
15 |
16 | unsigned int* alloc_page();
17 |
18 | #endif
--------------------------------------------------------------------------------
/include/sys/pic.h:
--------------------------------------------------------------------------------
1 | #ifndef PIC_H
2 | #define PIC_H
3 |
4 | #define PIC1 0x20
5 | #define PIC2 0xA0
6 |
7 | #define PIC1_COMMAND PIC1
8 | #define PIC1_DATA (PIC1 + 1)
9 | #define PIC2_COMMAND PIC2
10 | #define PIC2_DATA (PIC2 + 1)
11 |
12 | #define PIC_EOI 0x20
13 |
14 | #define ICW1 0x11
15 | #define ICW4_8086 0x01
16 |
17 | void pic_init(void);
18 |
19 | void pic_eoi(unsigned char __irq);
20 |
21 | #endif
--------------------------------------------------------------------------------
/include/sys/pio.h:
--------------------------------------------------------------------------------
1 | #ifndef PIO_H
2 | #define PIO_H
3 |
4 | void pio_outb(unsigned short __port, unsigned char __data);
5 | void pio_outs(unsigned short __port, unsigned short __data);
6 | void pio_outl(unsigned short __port, unsigned int __data);
7 |
8 | unsigned char pio_inb(unsigned short __port);
9 | unsigned short pio_ins(unsigned short __port);
10 | unsigned int pio_inl(unsigned short __port);
11 |
12 | void pio_sleep(void);
13 |
14 | unsigned short pio_mminw(unsigned int* addr);
15 |
16 | void pio_qinl(unsigned short __register, unsigned int *__buffer, int __quads);
17 | void pio_qoutl(unsigned short __register, unsigned int *__buffer, int __quads);
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/sys/pit.h:
--------------------------------------------------------------------------------
1 | #ifndef PIT_H
2 | #define PIT_H
3 |
4 | #include
5 |
6 | #define PIT_CHANNEL_O_DATA_PORT 0x40
7 | #define PIT_CHANNEL_1_DATA_PORT 0x41
8 | #define PIT_CHANNEL_2_DATA_PORT 0x42
9 |
10 | #define PIT_MODE_COMMAND_REG 0x43
11 |
12 | void quantum_pit_init();
13 |
14 | void pit_set_freq(int freq);
15 |
16 | void pit_handler(__registers_t* regs);
17 |
18 | void pit_sleep(int ms);
19 |
20 | unsigned long pit_get_ticks();
21 |
22 | #endif
--------------------------------------------------------------------------------
/include/sys/pmm.h:
--------------------------------------------------------------------------------
1 | #ifndef PMM_H
2 | #define PMM_H
3 |
4 | #define PMM_BIT_SIZE 32
5 | #define PMM_BLOCK_SIZE 4096
6 |
7 | /* TODO:
8 | * Move this into a new header
9 | */
10 |
11 | typedef unsigned int __pmm_physical_address;
12 |
13 | typedef struct __pmm_mem_info
14 | {
15 | unsigned int __memsize;
16 | unsigned int __maxblocks;
17 | unsigned int __usedblocks;
18 | unsigned int __mapend;
19 |
20 | unsigned int *__map_array;
21 | } __pmm_mem_info_t;
22 |
23 | void pmm_mmap_set(int __address);
24 | void pmm_mmap_unset(int __address);
25 | char pmm_mmap_get(int __address);
26 |
27 | int pmm_first_free(void);
28 | int pmm_next_free(unsigned int __size);
29 |
30 | void pmm_initialize(__pmm_physical_address __bitmap, unsigned int __memsize);
31 | void pmm_initialize_region(__pmm_physical_address __base, unsigned int __region_size);
32 | void pmm_uninitialize_region(__pmm_physical_address __base, unsigned int __region_addr);
33 |
34 | void *pmm_allocate_block(void);
35 | void *pmm_allocate_blocks(unsigned int __size);
36 |
37 | void pmm_free_block(void *__address);
38 | void pmm_free_blocks(void *__address, unsigned int __size);
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/include/sys/process.h:
--------------------------------------------------------------------------------
1 | #ifndef PROCESS_H
2 | #define PROCESS_H
3 |
4 | #define PROCESS_MODE_KERNEL 0
5 | #define PROCESS_MODE_USER 1
6 |
7 | #include
8 |
9 | typedef enum
10 | {
11 | PROCESS_RUNNING,
12 | PROCESS_SLEEPING,
13 | PROCESS_ZOMBIE,
14 | } __process_status;
15 |
16 | typedef struct process_t
17 | {
18 | unsigned int __memsize;
19 | unsigned int __mode;
20 | unsigned int __pid;
21 |
22 | int __priority;
23 | int __pstatus;
24 |
25 | struct process_t *__next;
26 |
27 | task_t *__task;
28 | void *__entry;
29 | } process_t;
30 |
31 | process_t *process_find_by_pid(unsigned int __pid);
32 |
33 | void process_initialize(void);
34 | void process_alloc(process_t *__p);
35 | void process_run(process_t *__p);
36 |
37 | unsigned int process_spawn(void *__entry, unsigned int __mode, unsigned int __memsize, unsigned int __pstatus, unsigned int __instant_run);
38 |
39 | void process_kill(unsigned int __pid);
40 | void process_set_status(unsigned int __pid, __process_status __status);
41 |
42 | unsigned int process_get_pid(void);
43 |
44 | #endif
--------------------------------------------------------------------------------
/include/sys/task.h:
--------------------------------------------------------------------------------
1 | #ifndef TASK_H
2 | #define TASK_H
3 |
4 | #include
5 |
6 | typedef struct __registers_task_t {
7 | unsigned int eax;
8 | unsigned int ebx;
9 | unsigned int ecx;
10 | unsigned int edx;
11 | unsigned int esi;
12 | unsigned int edi;
13 | unsigned int esp;
14 | unsigned int ebp;
15 | unsigned int eip;
16 | unsigned int eflags;
17 | unsigned int cr3;
18 | } registers_task_t;
19 |
20 | typedef struct __task_t {
21 | registers_task_t regs;
22 | struct __task_t *next;
23 | } task_t;
24 |
25 | typedef void (*task_main_t)();
26 |
27 | void quantum_task_init();
28 |
29 | void create_and_run_task(task_t* task, task_main_t main);
30 |
31 | void create_task(task_t* task, task_main_t main, unsigned int flags, unsigned int *pagedir);
32 |
33 | void reset_registers_task(task_t* task);
34 |
35 | void fork();
36 |
37 | extern void switch_task(registers_task_t* _old, registers_task_t* _new);
38 |
39 | #endif
--------------------------------------------------------------------------------
/include/userspace/elf.h:
--------------------------------------------------------------------------------
1 | #ifndef ELF_H
2 | #define ELF_H
3 |
4 | /* ELF Types */
5 | typedef unsigned short Elf32_Half;
6 | typedef unsigned short Elf64_Half;
7 |
8 | typedef unsigned int Elf32_Word;
9 | typedef int Elf32_Sword;
10 | typedef unsigned int Elf64_Word;
11 | typedef int Elf64_Sword;
12 |
13 | typedef unsigned long Elf32_Xword;
14 | typedef long Elf32_Sxword;
15 | typedef unsigned long Elf64_Xword;
16 | typedef long Elf64_Sxword;
17 |
18 | typedef unsigned int Elf32_Addr;
19 | typedef unsigned long Elf64_Addr;
20 |
21 | typedef unsigned int Elf32_Off;
22 | typedef unsigned long Elf64_Off;
23 |
24 | typedef unsigned short Elf32_Section;
25 | typedef unsigned short Elf64_Section;
26 |
27 | typedef Elf32_Half Elf32_Versym;
28 | typedef Elf64_Half Elf64_Versym;
29 |
30 | /* ELF Headers */
31 |
32 | #define EI_NIDENT (16)
33 |
34 | typedef struct __elf32_ehdr_t {
35 | unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
36 | Elf32_Half e_type; /* Object file type */
37 | Elf32_Half e_machine; /* Architecture */
38 | Elf32_Word e_version; /* Object file version */
39 | Elf32_Addr e_entry; /* Entry point virtual address */
40 | Elf32_Off e_phoff; /* Program header table file offset */
41 | Elf32_Off e_shoff; /* Section header table file offset */
42 | Elf32_Word e_flags; /* Processor-specific flags */
43 | Elf32_Half e_ehsize; /* ELF header size in bytes */
44 | Elf32_Half e_phentsize; /* Program header table entry size */
45 | Elf32_Half e_phnum; /* Program header table entry count */
46 | Elf32_Half e_shentsize; /* Section header table entry size */
47 | Elf32_Half e_shnum; /* Section header table entry count */
48 | Elf32_Half e_shstrndx; /* Section header string table index */
49 | } elf32_ehdr_t;
50 |
51 |
52 | /* Magic number */
53 | enum Elf_Ident {
54 | EI_MAG0 = 0, // 0x7F
55 | EI_MAG1 = 1, // 'E'
56 | EI_MAG2 = 2, // 'L'
57 | EI_MAG3 = 3, // 'F'
58 | EI_CLASS = 4, // Architecture (32/64)
59 | EI_DATA = 5, // Byte Order
60 | EI_VERSION = 6, // ELF Version
61 | EI_OSABI = 7, // OS Specific
62 | EI_ABIVERSION = 8, // OS Specific
63 | EI_PAD = 9 // Padding
64 | };
65 |
66 | #define ELFMAG0 0x7f /* Magic number byte 0 */
67 | #define ELFMAG1 'E' /* Magic number byte 1 */
68 | #define ELFMAG2 'L' /* Magic number byte 2 */
69 | #define ELFMAG3 'F' /* Magic number byte 3 */
70 |
71 | #define ELFCLASSNONE 0 /* Invalid class */
72 | #define ELFCLASS32 1 /* 32-bit objects */
73 | #define ELFCLASS64 2 /* 64-bit objects */
74 | #define ELFCLASSNUM 3
75 |
76 | #define ELFOSABI_NONE 0 /* UNIX System V ABI */
77 | #define ELFOSABI_SYSV 0 /* Alias. */
78 | #define ELFOSABI_HPUX 1 /* HP-UX */
79 | #define ELFOSABI_NETBSD 2 /* NetBSD. */
80 | #define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */
81 | #define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */
82 | #define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
83 | #define ELFOSABI_AIX 7 /* IBM AIX. */
84 | #define ELFOSABI_IRIX 8 /* SGI Irix. */
85 | #define ELFOSABI_FREEBSD 9 /* FreeBSD. */
86 | #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
87 | #define ELFOSABI_MODESTO 11 /* Novell Modesto. */
88 | #define ELFOSABI_OPENBSD 12 /* OpenBSD. */
89 | #define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
90 | #define ELFOSABI_ARM 97 /* ARM */
91 | #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
92 |
93 | /* e_types values */
94 | #define ET_NONE 0 /* No file type */
95 | #define ET_REL 1 /* Relocatable file */
96 | #define ET_EXEC 2 /* Executable file */
97 | #define ET_DYN 3 /* Shared object file */
98 | #define ET_CORE 4 /* Core file */
99 | #define ET_NUM 5 /* Number of defined types */
100 | #define ET_LOOS 0xfe00 /* OS-specific range start */
101 | #define ET_HIOS 0xfeff /* OS-specific range end */
102 | #define ET_LOPROC 0xff00 /* Processor-specific range start */
103 | #define ET_HIPROC 0xffff /* Processor-specific range end */
104 |
105 | /* e_machine values (only 2 because we don't need all of them) */
106 | #define EM_NONE 0 /* No machine */
107 | #define EM_386 3 /* Intel 80386 */
108 |
109 | /* EI_DATA value in magic number */
110 | #define ELFDATA2LSB 1
111 |
112 | /* e_version value (only correct one that we support) */
113 | #define EV_CURRENT 1
114 |
115 | typedef struct __elf32_phdr_t {
116 | Elf32_Word p_type; /* Segment type */
117 | Elf32_Off p_offset; /* Segment file offset */
118 | Elf32_Addr p_vaddr; /* Segment virtual address */
119 | Elf32_Addr p_paddr; /* Segment physical address */
120 | Elf32_Word p_filesz; /* Segment size in file */
121 | Elf32_Word p_memsz; /* Segment size in memory */
122 | Elf32_Word p_flags; /* Segment flags */
123 | Elf32_Word p_align; /* Segment alignment */
124 | } elf32_phdr_t;
125 |
126 | /* correct values of p_type */
127 | #define PT_LOAD 1
128 |
129 | #define INVALID_ELF -1
130 | #define NCORRECT_ELF -2
131 |
132 | int load_elf(char* data, elf32_ehdr_t* header);
133 |
134 | int is_elf_correct(elf32_ehdr_t* header);
135 |
136 | int is_elf_magic(elf32_ehdr_t* header);
137 |
138 | #endif
--------------------------------------------------------------------------------
/include/userspace/syscalls.h:
--------------------------------------------------------------------------------
1 | #ifndef SYSCALLS_H
2 | #define SYSCALLS_H
3 |
4 | #include
5 |
6 | #define MAX_SYSCALLS 325
7 |
8 | typedef int (*syscall_func_t) (
9 | int, // arg0 (eax)
10 | int, // arg1 (ebx)
11 | int, // arg2 (ecx)
12 | int, // arg3 (edx)
13 | int, // arg4 (esi)
14 | int, // arg5 (edi)
15 | int); // arg6 (ebp)
16 |
17 | void syscall_interrupt_handler(__registers_t* regs);
18 |
19 | void quantum_syscalls_init();
20 |
21 | // Syscalls
22 | int sys_read(int eax, int fd, int buf, int count, int esi, int edi, int ebp);
23 |
24 | int sys_write(int eax, int fd, int buf, int count, int esi, int edi, int ebp);
25 |
26 | int sys_creat(int eax, int filename, int mode, int edx, int esi, int edi, int ebp);
27 |
28 | int sys_open(int eax, int filename, int mode, int edx, int esi, int edi, int ebp);
29 |
30 | int sys_time(int eax, int time_ptr, int ecx, int edx, int esi, int edi, int ebp);
31 |
32 | int sys_uname(int eax, int uname_ptr, int ecx, int edx, int esi, int edi, int ebp);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/include/userspace/usermode.h:
--------------------------------------------------------------------------------
1 | #ifndef USERMODE_H
2 | #define USERMODE_H
3 |
4 | void switch_to_user_mode();
5 |
6 | #endif
--------------------------------------------------------------------------------
/include/userspace/userspace.h:
--------------------------------------------------------------------------------
1 | #ifndef USERSPACE_H
2 | #define USERSPACE_H
3 |
4 | void userspace_initialize(void);
5 |
6 | #endif
--------------------------------------------------------------------------------
/include/userspace/window.h:
--------------------------------------------------------------------------------
1 | #ifndef WINDOW_H
2 | #define WINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | typedef struct __window_t {
8 | char* window_name;
9 |
10 | int size_x;
11 | int size_y;
12 |
13 | int pos_x;
14 | int pos_y;
15 |
16 | unsigned char* framebuffer;
17 | BOOL should_redraw;
18 | } window_t;
19 |
20 | window_t create_window(char* window_name, int size_x, int size_y, int pos_x, int pos_y);
21 |
22 | void draw_windows();
23 |
24 | void render_window(window_t window);
25 |
26 | void put_pixel_window(window_t window, int x, int y, int r, int g, int b);
27 |
28 | #endif
--------------------------------------------------------------------------------
/kernel/asm/bios32_call.asm:
--------------------------------------------------------------------------------
1 | [bits 32]
2 |
3 | %define REBASE_ADDRESS(x) (0x7c00 + ((x) - BIOS32_START))
4 |
5 | section .text
6 | global BIOS32_START ; start memory address
7 | global BIOS32_END ; end memory address
8 |
9 | global bios32_gdt_ptr ; GDT pointer
10 | global bios32_gdt_entries ; GDT array entries
11 | global bios32_idt_ptr ; IDT pointer
12 | global bios32_in_reg16_ptr ; IN REGISTERS16
13 | global bios32_out_reg16_ptr ; OUT REGISTERS16
14 | global bios32_int_number_ptr ; bios interrupt number to be called
15 |
16 | ; 32 bit protected mode
17 | BIOS32_START:use32
18 | pusha
19 | ; save current esp to edx
20 | mov edx, esp
21 | ; jumping to 16 bit protected mode
22 | ; disable interrupts
23 | cli
24 | ; clear cr3 by saving cr3 data in ebx register
25 | xor ecx, ecx
26 | mov ebx, cr3
27 | mov cr3, ecx
28 | ; load new empty GDT
29 | lgdt [REBASE_ADDRESS(bios32_gdt_ptr)]
30 | ; load new empty IDT
31 | lidt [REBASE_ADDRESS(bios32_idt_ptr)]
32 | ; jump to 16 bit protected mode
33 | jmp 0x30:REBASE_ADDRESS(__protected_mode_16)
34 |
35 | ; 16 bit protected mode
36 | __protected_mode_16:use16
37 | ; jumping to 16 bit real mode
38 | mov ax, 0x38
39 | mov ds, ax
40 | mov es, ax
41 | mov fs, ax
42 | mov gs, ax
43 | mov ss, ax
44 | ; turn off protected mode
45 | ; set bit 0 to 0
46 | mov eax, cr0
47 | and al, ~0x01
48 | mov cr0, eax
49 | jmp 0x0:REBASE_ADDRESS(__real_mode_16)
50 |
51 | ; 16 bit real mode
52 | __real_mode_16:use16
53 | xor ax, ax
54 | mov ds, ax
55 | mov es, ax
56 | mov fs, ax
57 | mov gs, ax
58 | mov ss, ax
59 | mov sp, 0x8c00
60 | ; enable bios interrupts to call
61 | sti
62 | ; save current context, all general, segment registers, flags
63 | pusha
64 | mov cx, ss
65 | push cx
66 | mov cx, gs
67 | push cx
68 | mov cx, fs
69 | push cx
70 | mov cx, es
71 | push cx
72 | mov cx, ds
73 | push cx
74 | pushf
75 | ; get current stack pointer & save it to current_esp
76 | mov ax, sp
77 | mov edi, current_esp
78 | stosw
79 | ; load our custom registers context
80 | mov esp, REBASE_ADDRESS(bios32_in_reg16_ptr)
81 | ; only use some general register from the given context
82 | popa
83 | ; set a new stack for bios interrupt
84 | mov sp, 0x9c00
85 | ; call immediate interrupt opcode to execute context
86 | db 0xCD
87 |
88 | bios32_int_number_ptr: ; will be bios interrupt number passed
89 | ; put the actual interrupt number here
90 | db 0x00
91 | ; get our output context here
92 | mov esp, REBASE_ADDRESS(bios32_out_reg16_ptr)
93 | add sp, 28 ; restore stack used for calling our context
94 | ; save current context, all general, segment registers, flags
95 | pushf
96 | mov cx, ss
97 | push cx
98 | mov cx, gs
99 | push cx
100 | mov cx, fs
101 | push cx
102 | mov cx, es
103 | push cx
104 | mov cx, ds
105 | push cx
106 | pusha
107 | ; restore the current_esp to continue
108 | mov esi, current_esp
109 | lodsw
110 | mov sp, ax
111 | ; restore all current context, all general, segment registers, flags
112 | popf
113 | pop cx
114 | mov ds, cx
115 | pop cx
116 | mov es, cx
117 | pop cx
118 | mov fs, cx
119 | pop cx
120 | mov gs, cx
121 | pop cx
122 | mov ss, cx
123 | popa
124 |
125 | ; jumping to 32 bit protected mode
126 | ; set bit 0 in cr0 to 1
127 | mov eax, cr0
128 | inc eax
129 | mov cr0, eax
130 | jmp 0x08:REBASE_ADDRESS(__protected_mode_32)
131 |
132 | ; 32 bit protected mode
133 | __protected_mode_32:use32
134 | mov ax, 0x10
135 | mov ds, ax
136 | mov es, ax
137 | mov fs, ax
138 | mov gs, ax
139 | mov ss, ax
140 | ; restore cr3
141 | mov cr3, ebx
142 | ; restore esp
143 | mov esp, edx
144 | sti
145 | popa
146 | ret
147 |
148 |
149 | __padding:
150 | db 0x0
151 | db 0x0
152 | db 0x0
153 | bios32_gdt_entries:
154 | ; 8 gdt entries
155 | resb 64
156 | bios32_gdt_ptr:
157 | dd 0x00000000
158 | dd 0x00000000
159 | bios32_idt_ptr:
160 | dd 0x00000000
161 | dd 0x00000000
162 | bios32_in_reg16_ptr:
163 | resw 14
164 | bios32_out_reg16_ptr:
165 | dd 0xaaaaaaaa
166 | dd 0xaaaaaaaa
167 | dd 0xaaaaaaaa
168 | dd 0xaaaaaaaa
169 | dd 0xaaaaaaaa
170 | dd 0xaaaaaaaa
171 | dd 0xaaaaaaaa
172 | current_esp:
173 | dw 0x0000
174 |
175 | BIOS32_END:
--------------------------------------------------------------------------------
/kernel/asm/gdt.asm:
--------------------------------------------------------------------------------
1 | ; GDT Loader
2 |
3 | section .text
4 | global load_gdt
5 | global tss_flush
6 |
7 | tss_flush:
8 | mov ax, 0x2B
9 | ltr ax
10 | ret
11 |
12 | load_gdt:
13 | mov eax, [esp + 4]
14 |
15 | lgdt [eax]
16 |
17 | mov ax, 0x10
18 | mov ds, ax
19 | mov es, ax
20 | mov fs, ax
21 | mov gs, ax
22 | mov ss, ax
23 |
24 | cli
25 |
26 | mov eax, cr0
27 |
28 | or eax, 1
29 |
30 | mov cr0, eax
31 |
32 | jmp 0x08:far_jump
33 |
34 | far_jump:
35 | ret
--------------------------------------------------------------------------------
/kernel/asm/idt.asm:
--------------------------------------------------------------------------------
1 | section .text
2 | global load_idt
3 |
4 | load_idt:
5 | mov eax, [esp + 4]
6 |
7 | lidt [eax]
8 |
9 | ret
--------------------------------------------------------------------------------
/kernel/asm/irq.asm:
--------------------------------------------------------------------------------
1 | section .text
2 | extern isr_irq_handler
3 |
4 | irq_handler:
5 | pusha
6 |
7 | mov ax, ds
8 |
9 | push eax
10 |
11 | mov ax, 0x10
12 | mov ds, ax
13 | mov es, ax
14 | mov fs, ax
15 | mov gs, ax
16 |
17 | push esp
18 |
19 | call isr_irq_handler
20 |
21 | pop esp
22 | pop ebx
23 |
24 | mov ds, bx
25 | mov es, bx
26 | mov fs, bx
27 | mov gs, bx
28 |
29 | popa
30 |
31 | add esp, 0x8
32 |
33 | sti
34 |
35 | iret
36 |
37 | %macro IRQ 2
38 | global irq_%1
39 |
40 | irq_%1:
41 | cli
42 | push byte 0
43 | push byte %2
44 | jmp irq_handler
45 | %endmacro
46 |
47 | IRQ 0, 32
48 | IRQ 1, 33
49 | IRQ 2, 34
50 | IRQ 3, 35
51 | IRQ 4, 36
52 | IRQ 5, 37
53 | IRQ 6, 38
54 | IRQ 7, 39
55 | IRQ 8, 40
56 | IRQ 9, 41
57 | IRQ 10, 42
58 | IRQ 11, 43
59 | IRQ 12, 44
60 | IRQ 13, 45
61 | IRQ 14, 46
62 | IRQ 15, 47
--------------------------------------------------------------------------------
/kernel/asm/paging.asm:
--------------------------------------------------------------------------------
1 | global load_page_directory
2 | load_page_directory:
3 | push ebp
4 | mov ebp, esp
5 | mov eax, [esp + 8]
6 | mov cr3, eax
7 | mov esp, ebp
8 | pop ebp
9 | ret
10 |
11 | global enable_paging
12 | enable_paging:
13 | push ebp
14 | mov ebp, esp
15 | mov eax, cr0
16 | mov ebx, 0x80000000
17 | or ebx, eax
18 | mov cr0, eax
19 | mov esp, ebp
20 | pop ebp
21 | ret
--------------------------------------------------------------------------------
/kernel/asm/syscalls.asm:
--------------------------------------------------------------------------------
1 | global test_syscall
2 |
3 | hello db "Hello", 10
4 | num resb 5
5 |
6 | test_syscall:
7 | mov eax, 4
8 | mov ebx, 1
9 | mov ecx, hello
10 | mov edx, 6
11 | int 0x80
12 |
13 | mov eax, 3
14 | mov ebx, 1
15 | mov ecx, num
16 | mov edx, 5
17 | int 0x80
18 |
19 | mov eax, 4
20 | mov ebx, 1
21 | mov ecx, hello
22 | mov edx, 5
23 | int 0x80
--------------------------------------------------------------------------------
/kernel/asm/task.asm:
--------------------------------------------------------------------------------
1 | section .text
2 | global switch_task
3 |
4 | switch_task:
5 | pusha
6 | pushf
7 |
8 | mov eax, cr3
9 | push eax
10 |
11 | mov eax, [esp + 44]
12 | mov [eax + 4], ebx
13 | mov [eax + 8], ecx
14 | mov [eax + 12], edx
15 | mov [eax + 16], esi
16 | mov [eax + 20], edi
17 |
18 | mov ebx, [esp + 36]
19 | mov ecx, [esp + 40]
20 | mov edx, [esp + 20]
21 | add edx, 4
22 |
23 | mov esi, [esp + 16]
24 | mov edi, [esp + 4]
25 |
26 | mov [eax], ebx
27 | mov [eax + 24], edx
28 | mov [eax + 28], esi
29 | mov [eax + 32], ecx
30 | mov [eax + 36], edi
31 | pop ebx
32 | mov [eax + 40], ebx
33 | push ebx
34 |
35 | mov eax, [esp + 48]
36 | mov ebx, [eax + 4]
37 | mov ecx, [eax + 8]
38 | mov edx, [eax + 12]
39 | mov esi, [eax + 16]
40 | mov edi, [eax + 20]
41 | mov ebp, [eax + 28]
42 |
43 | push eax
44 | mov eax, [eax + 36]
45 | push eax
46 | popf
47 | pop eax
48 | mov esp, [eax + 24]
49 | push eax
50 | mov eax, [eax + 40]
51 | mov cr3, eax
52 | pop eax
53 | push eax
54 | mov eax, [eax + 32]
55 | xchg eax, [esp]
56 | mov eax, [eax]
57 | ret
--------------------------------------------------------------------------------
/kernel/kernel.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | * - CodeSploit
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | void quantum_kernel_init(unsigned long magic, unsigned long addr)
36 | {
37 | quantum_vesa_init(addr);
38 | quantum_print_init();
39 | quantum_gdt_init();
40 | quantum_idt_init();
41 | quantum_pmm_init(addr);
42 | quantum_ksyms_init(addr);
43 | quantum_memory_init();
44 | quantum_paging_init();
45 | quantum_keyboard_init();
46 | quantum_back_buffer_init();
47 | quantum_mouse_init();
48 | quantum_devmgr_init();
49 | quantum_vfs_init();
50 | quantum_pci_init();
51 | quantum_pit_init();
52 | quantum_acpi_init();
53 | quantum_time_init(TIME_ZONES_UTC_PLUS_1);
54 | quantum_syscalls_init();
55 | quantum_sound_blaster_init();
56 | ata_handler(0x1F0, 0x3F6, 0x170, 0x376, 0x000);
57 | quantum_ext2_init();
58 |
59 | printf("KERNEL: Essential systems bootup... [DONE]\n");
60 | printf("(Press any key to continue...)\n");
61 |
62 | keyboard_getchar();
63 | vesa_clear();
64 |
65 | quantum_menu();
66 |
67 | return;
68 | }
69 |
--------------------------------------------------------------------------------
/kernel/kernel_menu.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | static int menu_position_selected = 0;
16 | static int all_menu_position = 4;
17 |
18 | kernel_menu_selection_item_t items[4] = {
19 | {
20 | .name = "Boot into userspace"
21 | },
22 | {
23 | .name = "Boot into kernel-mode"
24 | },
25 | {
26 | .name = "Reboot"
27 | },
28 | {
29 | .name = "Shutdown"
30 | },
31 | };
32 |
33 | void draw_menu_title()
34 | {
35 | print_set_color_bg(0, 0, 0);
36 | print_set_color(255, 255, 255);
37 | set_print_x((get_screen_x() / 2) - ((9 * 9) / 2));
38 | set_print_y(get_screen_y() / 4);
39 | printf("Quantum OS");
40 | }
41 |
42 | void draw_menu_selection_item(int index, int menu_x, int menu_y)
43 | {
44 | if (menu_position_selected == index)
45 | {
46 | vesa_draw_rect(
47 | menu_x + 3, (menu_y + 3) + (60) * (index + 0),
48 | 390 - 6, 60, 255, 255, 255
49 | );
50 |
51 | set_print_x(menu_x + 3 + 15);
52 | set_print_y((menu_y + 3) + ((26) * (index + 1)) + index * 30);
53 |
54 | print_set_color_bg(255, 255, 255);
55 | print_set_color(0, 0, 0);
56 |
57 | printf(items[index].name);
58 | }
59 | else
60 | {
61 | set_print_x(menu_x + 3 + 15);
62 | set_print_y((menu_y + 3) + ((26) * (index + 1)) + index * 30);
63 |
64 | print_set_color_bg(0, 0, 0);
65 | print_set_color(255, 255, 255);
66 |
67 | printf(items[index].name);
68 | }
69 |
70 | }
71 |
72 | void draw_menu_selection_bar()
73 | {
74 | int selection_bar_height = 3 * 60 + 100;
75 | int selection_bar_width = 390;
76 |
77 | int x_start = (get_screen_x() / 2) - (selection_bar_width / 2);
78 | int y_start = (get_screen_y() / 4 + 30);
79 |
80 | vesa_draw_line(
81 | x_start , y_start - 7,
82 | x_start + selection_bar_width, y_start - 7,
83 | 255, 255, 255
84 | );
85 |
86 | for (int i = 0; i < all_menu_position; i++)
87 | draw_menu_selection_item(i, (get_screen_x() / 2) - (selection_bar_width / 2), (get_screen_y() / 4 + 30));
88 | }
89 |
90 | void draw_menu()
91 | {
92 | draw_menu_title();
93 | draw_menu_selection_bar();
94 | }
95 |
96 | void quantum_menu()
97 | {
98 | char sc = 0;
99 |
100 | draw_menu();
101 |
102 | for (;;)
103 | {
104 | sc = keyboard_getsc();
105 | if (sc == 80)
106 | {
107 | menu_position_selected++;
108 | if (menu_position_selected >= 4)
109 | {
110 | menu_position_selected = 0;
111 | }
112 | vesa_clear();
113 | draw_menu();
114 | }
115 | else if (sc == 72)
116 | {
117 | menu_position_selected--;
118 | if (menu_position_selected == -1)
119 | {
120 | menu_position_selected = 3;
121 | }
122 | vesa_clear();
123 | draw_menu();
124 | }
125 | else if (sc == KEYBOARD_ENTER_SC)
126 | {
127 | vesa_clear();
128 | set_default_pos();
129 | print_set_color_bg(0, 0, 0);
130 | print_set_color(255, 255, 255);
131 | switch (menu_position_selected)
132 | {
133 | case 0:
134 | quantum_migrate_to_userspace();
135 | break;
136 | case 1:
137 | quantum_migrate_to_kernel_mode();
138 | break;
139 | case 2:
140 | acpi_reboot();
141 | break;
142 | case 3:
143 | acpi_shutdown();
144 | break;
145 | default:
146 | break;
147 | }
148 | }
149 | }
150 |
151 | }
--------------------------------------------------------------------------------
/kernel/kmode.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | * - CodeSploit
5 | */
6 |
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 |
16 | #include
17 | #include
18 |
19 | #include
20 |
21 | void kmode_initialize(void)
22 | {
23 | printf(KMODE_PROMPT);
24 |
25 | printf("Testing ATA Read\n");
26 |
27 | unsigned int __buffer[ATA_SECTOR_SIZE];
28 |
29 | ata_read_sectors(0, 1, 1, __buffer);
30 |
31 | for (int i = 0; i < ATA_SECTOR_SIZE; i++)
32 | {
33 | printf("0x%x ", __buffer[i]);
34 | }
35 |
36 | printf("\n");
37 |
38 | while (1)
39 | {
40 | printf(KMODE_PROMPT);
41 |
42 | char *__command = keyboard_getchar_until('\n');
43 | if (!__command)
44 | {
45 | printf("err!\n");
46 | }
47 | char *__basecmd = strtok(__command, " ");
48 |
49 | printf("\n");
50 |
51 | while (__basecmd != NULL)
52 | {
53 | if (strcmp(__basecmd, "help") == 0)
54 | {
55 | printf("Help page:\n\
56 | reboot: Reboot the system.\n\
57 | shutdown: Shutdown the system.\n\
58 | time: Show current time.\n\
59 | userspace: Quit kernel-mode and go into userspace!\n\
60 | stz: Set time zone.\n\
61 | help: Display this help window.\n");
62 | }
63 | else if (strcmp(__basecmd, "reboot") == 0)
64 | {
65 | acpi_reboot();
66 | }
67 | else if (strcmp(__basecmd, "stz") == 0)
68 | {
69 | __basecmd = strtok(NULL, " ");
70 | if (__basecmd == NULL)
71 | {
72 | printf("stz: expected --help/-h or time zone argument\n");
73 | break;
74 | }
75 | else if (strcmp(__basecmd, "--help") == 0 || strcmp(__basecmd, "-h") == 0)
76 | {
77 | printf("stz - kernel mode program to set time zone in quantumos\n\
78 | avaliable time zones:\n\
79 | - UTC -12:00, UTC -11:00, UTC -10:00, UTC -09:30, UTC -09:00, UTC -08:00, UTC -07:00, UTC -06:00, UTC -05:00, \n\
80 | UTC -04:00, UTC -03:30, UTC -03:00, UTC -02:00, UTC -01:00\n\
81 | - UTC 0 \n\
82 | - UTC +01:00, UTC +02:00, UTC +03:00, UTC +03:30, UTC +04:00, UTC +04:30, UTC +05:00, UTC +05:30, UTC +05:45, \n\
83 | UTC +06:00, UTC +06:30, UTC +07:00, UTC +08:00, UTC +08:45, UTC +09:00, UTC +09:30, UTC +10:00, UTC +10:30, \n\
84 | UTC +11:00, UTC +12:00, UTC +12:45, UTC +13:00, UTC +14:00 \n");
85 | break;
86 | }
87 |
88 | time_zone_t time_zone = convert_str_to_time_zone(__basecmd);
89 | if (time_zone == -1)
90 | {
91 | printf("stz: unknown time zone \"%s\"\n", __basecmd);
92 | break;
93 | }
94 |
95 | set_time_zone(time_zone);
96 | }
97 | else if (strcmp(__basecmd, "shutdown") == 0)
98 | {
99 | acpi_shutdown();
100 | }
101 | else if (strcmp(__basecmd, "userspace") == 0)
102 | {
103 | userspace_initialize();
104 | }
105 | else if (strcmp(__basecmd, "time") == 0)
106 | {
107 | date_t date = get_date_cmos();
108 | printf("%s%d:%s%d:%s%d %d%d:%s%d:%s%d\n",
109 | date.hour <= 9 ? "0" : "",
110 | date.hour, date.minute <= 9 ? "0" : "",
111 | date.minute, date.second <= 9 ? "0" : "",
112 | date.second,
113 | date.century,
114 | date.year,
115 | date.month <= 9 ? "0" : "", date.month,
116 | date.day <= 9 ? "0" : "", date.day);
117 | }
118 | else
119 | {
120 | printf("Invalid command: [%s]\n", __basecmd);
121 | }
122 |
123 | __basecmd = strtok(NULL, " ");
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/kernel/module.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 |
6 | #include
7 |
8 | MODULE_NAME("QUANTUM_MODULE_C");
9 |
10 | #define MODULES_MAX 256
11 |
12 | static char **__modules_list;
13 |
14 | static unsigned int *__modules_addr = 0;
15 | static unsigned int __modules_r = 0;
16 |
17 | void __module_init(void)
18 | {
19 | __modules_list = (char **) kmalloc(MODULES_MAX * sizeof(unsigned int));
20 | __modules_addr = (unsigned int *) kmalloc(MODULES_MAX * sizeof(unsigned int));
21 | }
22 |
23 | void __module_call(char *__func)
24 | {
25 | for (int i = 0; i < __modules_r; i++)
26 | {
27 | if (strcmp(__func, __modules_list[i]) == 0)
28 | {
29 | asm volatile ("call *%%eax": :"a"(__modules_addr[i]));
30 |
31 | return;
32 | }
33 | }
34 |
35 | quantum_info(__FILE__, 1, " KMOD\t", "Error: Kernel module: [%s] not found", __func);
36 | }
37 |
38 | void __module_add(char *__func, unsigned int __addr)
39 | {
40 | quantum_info(__FILE__, 0, " KMOD\t", "Initializing kernel module: [%s] Address: [0x%x]", __func, __addr);
41 |
42 | __modules_list[__modules_r] = __func;
43 | __modules_addr[__modules_r] = __addr;
44 |
45 | __modules_r++;
46 | }
47 |
48 | void __module_wakeup(void)
49 | {
50 | for (int i = 0; i < __modules_r; i++)
51 | {
52 | quantum_info(__FILE__, 0, " KMOD\t", "Waking up module: [%s] at address: [0x%x]", __modules_list[i], __modules_addr[i]);
53 |
54 | asm volatile ("call *%%eax": :"a"(__modules_addr[i]));
55 | }
56 | }
--------------------------------------------------------------------------------
/mkdisk_ext2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | printf "Creating Disk...\n"
3 | dd if=/dev/zero of=ext2.img bs=1024 count=10000 > /dev/zero
4 | mkfs -t ext2 -i 1024 -b 1024 -F ext2.img > /dev/zero
5 | printf "Mounting...\n"
6 | rm -rf /mnt/ext2
7 | mkdir /mnt/ext2
8 | mount ext2.img /mnt/ext2
9 | printf "MOUNTED!\n"
10 | cp -r rootfs/* /mnt/ext2
11 | umount ext2.img
12 | printf "Done!\n"
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/net/ethernet.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | int ethernet_initalize(__pci_device_t* __dev)
13 | {
14 | quantum_info(__FILE__, 0, "Ethernet", "Initializing Ethernet driver");
15 | }
--------------------------------------------------------------------------------
/net/socket.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | int socket_create(__vfs_node_t* file, int domain, int type, int protocol)
14 | {
15 | if (domain == AF_UNIX)
16 | {
17 |
18 | }
19 |
20 | return -EAFNOSUPPORT;
21 | }
22 |
23 | int socket_accept(__vfs_node_t* file, __vfs_node_t* conn, sockaddr* addr, socklen_t* len);
24 |
25 | int socket_bind(__vfs_node_t* file, sockaddr* addr, unsigned int len);
26 |
27 | int socket_connect(__vfs_node_t* file, sockaddr* addr, unsigned int len);
28 |
29 | int socket_listen(__vfs_node_t* file, int backlog);
30 |
31 | int socket_send(__vfs_node_t* file, void* buf, unsigned long len, int flags);
32 |
33 | int socket_recv(__vfs_node_t* file, void* buf, unsigned long len, int flags);
34 |
35 | int socket_can_read(__vfs_node_t* file, unsigned long len);
36 |
37 | int socket_can_write(__vfs_node_t* file, unsigned long len);
38 |
39 | int socket_shutdown(__vfs_node_t* file, int how);
--------------------------------------------------------------------------------
/net/unix.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | int unix_socket_create(struct __vfs_node* file, int domain, int type, int protocol)
15 | {
16 | socket_t* socket = kmalloc(sizeof(socket_t));
17 | if (socket == NULL) return -ENOMEM;
18 |
19 | socket->domain = domain;
20 | socket->type = type;
21 | socket->protocol = protocol;
22 | socket->p = NULL;
23 | socket->ref = 1;
24 |
25 | file->__flags |= FS_SOCKET;
26 | file->socket = socket;
27 |
28 | return 0;
29 | }
30 |
31 | int unix_socket_accept(struct __vfs_node* file, struct __vfs_node* conn, sockaddr* addr, socklen_t* len);
32 |
33 | int unix_socket_bind(struct __vfs_node* file, sockaddr* addr, unsigned int len);
34 |
35 | int unix_socket_connect(struct __vfs_node* file, sockaddr* addr, unsigned int len);
36 |
37 | int unix_socket_listen(struct __vfs_node* file, int backlog);
38 |
39 | int unix_socket_send(struct __vfs_node* file, void* buf, unsigned long len, int flags);
40 |
41 | int unix_socket_recv(struct __vfs_node* file, void* buf, unsigned long len, int flags);
42 |
43 | int unix_socket_can_read(struct __vfs_node* file, unsigned long len);
44 |
45 | int unix_socket_can_write(struct __vfs_node* file, unsigned long len);
46 |
47 | int unix_socket_shutdown(struct __vfs_node* file, int how);
--------------------------------------------------------------------------------
/rootfs/hello.txt:
--------------------------------------------------------------------------------
1 | Hello, World! This was read by the ATA Drivers :)
2 |
--------------------------------------------------------------------------------
/screenshots/F9838711-A50F-44C9-8CC5-C9C84AD35576.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/screenshots/F9838711-A50F-44C9-8CC5-C9C84AD35576.jpeg
--------------------------------------------------------------------------------
/screenshots/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QuantumOSDev/QuantumOS/362250411f9db7304f17004fef0455c36e921d02/screenshots/screenshot1.png
--------------------------------------------------------------------------------
/sys/ksyms.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | static multiboot_elf_section_header_table_t* mb_elf_section_header_table;
11 | static elf32_shdr_t* elf_shdr;
12 |
13 | void quantum_ksyms_init(unsigned long addr)
14 | {
15 | multiboot_info_t* mbinfo = (multiboot_info_t*)addr;
16 |
17 | mb_elf_section_header_table = &mbinfo->u.elf_sec;
18 | elf_shdr = (elf32_shdr_t*)mb_elf_section_header_table->addr;
19 | }
20 |
21 | elf32_sym_t* get_ksym_by_address(unsigned int addr)
22 | {
23 | void* candidate = NULL;
24 | int offset = -1;
25 |
26 | for (int i = 0; i < mb_elf_section_header_table->num; i++)
27 | {
28 | elf32_sym_t* sym_table = (elf32_sym_t*)elf_shdr[i].addr;
29 |
30 | for (int j = 0; j < elf_shdr[i].size / sizeof(elf32_sym_t); j++)
31 | {
32 | if ((offset == -1 || (addr - sym_table[j].value) < offset))
33 | {
34 | candidate = &sym_table[j];
35 | offset = addr - sym_table[j].value;
36 | }
37 | }
38 | }
39 |
40 | if (candidate)
41 | return (elf32_sym_t*)candidate;
42 |
43 | return NULL;
44 | }
45 |
46 | char* get_shdr_string(unsigned int index)
47 | {
48 | for (int i = 0; i < mb_elf_section_header_table->num; i++)
49 | {
50 | if (elf_shdr[i].type == 3)
51 | return (char*)elf_shdr[i].addr + index;
52 | }
53 |
54 | return NULL;
55 | }
--------------------------------------------------------------------------------
/sys/paging.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | unsigned int page_directory[1024] __attribute__((aligned(4096)));
11 | unsigned int first_page_table[1024] __attribute__((aligned(4096)));
12 |
13 | int page_directory_curr = 0;
14 |
15 | extern void load_page_directory(unsigned int* page_ptr);
16 | extern void enable_paging();
17 |
18 | void quantum_paging_init()
19 | {
20 | for(int i = 0; i < 1024; i++)
21 | page_directory[i] = 0x00000002;
22 |
23 | for(unsigned int i = 0; i < 1024; i++)
24 | first_page_table[i] = (i * 0x1000) | 3;
25 |
26 | page_directory[0] = ((unsigned int)first_page_table) | 3;
27 |
28 | load_page_directory(((unsigned int*)page_directory));
29 | enable_paging();
30 | }
31 |
32 | unsigned int* alloc_page()
33 | {
34 | int copy_curr = page_directory_curr;
35 | page_directory_curr++;
36 | return ((unsigned int*)page_directory[copy_curr]);
37 | }
--------------------------------------------------------------------------------
/sys/process.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | * - CodeSploit
5 | */
6 |
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | static process_t *__phead;
16 | int __pid = 1;
17 |
18 | process_t *process_find_by_pid(unsigned int __pid)
19 | {
20 | process_t *__head = __phead;
21 |
22 | if (!__head)
23 | {
24 | quantum_info(__FILE__, 1, " PROC ", "Fatal error process head is NULL!");
25 |
26 | kpanic("Fatal error occured kernel crashed");
27 | }
28 |
29 | while (__head != NULL)
30 | {
31 | if (__head->__pid == __pid)
32 | {
33 | return __head;
34 | }
35 |
36 | __head = __head->__next;
37 | }
38 |
39 | return NULL;
40 | }
41 |
42 | void process_initialize(void)
43 | {
44 | __phead = kmalloc(sizeof(*__phead));
45 |
46 | __phead->__entry = NULL;
47 | __phead->__memsize = 0;
48 | __phead->__mode = PROCESS_MODE_KERNEL;
49 | __phead->__next = NULL;
50 | __phead->__pstatus = PROCESS_SLEEPING;
51 | __phead->__priority = 0;
52 |
53 | quantum_info(__FILE__, 0, " PROC ", "Successfully initialized processes");
54 | }
55 |
56 | void process_alloc(process_t *__p)
57 | {
58 | __p->__entry = kmalloc(__p->__memsize);
59 | }
60 |
61 | void process_run(process_t *__p)
62 | {
63 | quantum_info(__FILE__, 0, " PROC ", "Running process [%d]...", __p->__pid);
64 |
65 | // int __exit = ((int (*) (void)) __p->__entry)();
66 | create_and_run_task(__p->__task, __p->__entry);
67 |
68 | quantum_info(__FILE__, 0, " PROC ", "Process [%d] finished and is now a zombie process...", __p->__pid);
69 |
70 | process_kill(__p->__pid);
71 | }
72 |
73 | unsigned int process_spawn(void *__entry, unsigned int __mode, unsigned int __memsize, unsigned int __pstatus, unsigned int __instant_run)
74 | {
75 | process_t *__p = kmalloc(sizeof(*__p));
76 |
77 | __p->__memsize = __memsize;
78 | __p->__pstatus = __pstatus;
79 | __p->__mode = __mode;
80 | __p->__next = NULL;
81 |
82 | process_alloc(__p);
83 |
84 | __p->__entry = __entry;
85 | __p->__task = (task_t*)kmalloc(sizeof(task_t));
86 |
87 | __p->__pid = process_get_pid();
88 |
89 | process_t *__head = __phead;
90 |
91 | while (__head->__next != NULL && __head->__pstatus != PROCESS_ZOMBIE)
92 | {
93 | __head = __head->__next;
94 | }
95 |
96 | __head->__next = __p;
97 |
98 | if (__instant_run == 1)
99 | {
100 | process_run(__p);
101 | }
102 |
103 | return __p->__pid;
104 | }
105 |
106 | void process_kill(unsigned int __pid)
107 | {
108 | process_t *__head = __phead;
109 |
110 | while (__head != NULL)
111 | {
112 | if (__head->__pid == __pid)
113 | {
114 | process_set_status(__pid, PROCESS_ZOMBIE);
115 |
116 | kfree(__head->__entry);
117 | }
118 |
119 | __head = __head->__next;
120 | }
121 | }
122 |
123 | void process_set_status(unsigned int __pid, __process_status __status)
124 | {
125 | process_t *__head = __phead;
126 |
127 | while (__head != NULL)
128 | {
129 | if (__head->__pid == __pid)
130 | {
131 | __head->__pstatus = __status;
132 | }
133 |
134 | __head = __head->__next;
135 | }
136 | }
137 |
138 | unsigned int process_get_pid(void)
139 | {
140 | return __pid++;
141 | }
--------------------------------------------------------------------------------
/sys/task.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | static task_t* current_task;
12 | static task_t main_task;
13 | static task_t other_task;
14 |
15 | void other_main()
16 | {
17 | fork();
18 | }
19 |
20 | void quantum_task_init()
21 | {
22 | asm volatile("movl %%cr3, %%eax\nmovl %%eax, %0\n" : "=m"(main_task.regs.cr3) : : "%eax");
23 | asm volatile("pushfl\nmovl (%%esp), %%eax\nmovl %%eax, %0\npopfl\n" : "=m"(main_task.regs.eflags) : : "%eax");
24 |
25 | create_task(&other_task, other_main, main_task.regs.eflags, (unsigned int*)main_task.regs.cr3);
26 | main_task.next = &other_task;
27 | other_task.next = &main_task;
28 |
29 | current_task = &main_task;
30 | ((void (*)())current_task->next->regs.eip)();
31 | }
32 |
33 | void create_and_run_task(task_t* task, task_main_t main)
34 | {
35 | asm volatile("movl %%cr3, %%eax\nmovl %%eax, %0\n" : "=m"(main_task.regs.cr3) : : "%eax");
36 | asm volatile("pushfl\nmovl (%%esp), %%eax\nmovl %%eax, %0\npopfl\n" : "=m"(main_task.regs.eflags) : : "%eax");
37 |
38 | create_task(task, main, main_task.regs.eflags, (unsigned int*)main_task.regs.cr3);
39 | main_task.next = task;
40 | task->next = &main_task;
41 |
42 | current_task = &main_task;
43 | ((void (*)())current_task->next->regs.eip)();
44 | }
45 |
46 | void reset_registers_task(task_t* task)
47 | {
48 | task->regs.eax = 0;
49 | task->regs.ebx = 0;
50 | task->regs.ecx = 0;
51 | task->regs.edx = 0;
52 | task->regs.esi = 0;
53 | task->regs.edi = 0;
54 | }
55 |
56 | void set_task_structure(task_t* task, task_main_t main, unsigned int flags, unsigned int *pagedir)
57 | {
58 | task->regs.eflags = flags;
59 | task->regs.eip = (unsigned int)main;
60 | task->regs.cr3 = (unsigned int)pagedir;
61 | task->regs.esp = (unsigned int)alloc_page() + 0x1000;
62 | task->next = 0;
63 | }
64 |
65 | void create_task(task_t* task, task_main_t main, unsigned int flags, unsigned int *pagedir)
66 | {
67 | reset_registers_task(task);
68 | set_task_structure(task, main, flags, pagedir);
69 | }
70 |
71 | void fork()
72 | {
73 | task_t* last = current_task;
74 | current_task = current_task->next;
75 |
76 | switch_task(&last->regs, ¤t_task->regs);
77 | }
--------------------------------------------------------------------------------
/sys/x86_64/acpi.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | * - CodeSploit
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | static BOOL machine_support_acpi = TRUE;
21 |
22 | static rsdp_t* rsdp = NULL;
23 | static rsdp_t* rsdt = NULL;
24 |
25 | /* Took from limine-bootloader/limine, it did hep me a lot, thanks */
26 | unsigned char acpi_checksum(void*ptr, unsigned long size)
27 | {
28 | unsigned char* _ptr = ptr;
29 | unsigned char sum = 0;
30 |
31 | for (unsigned long i = 0; i < size; i++)
32 | sum += _ptr[i];
33 |
34 | return sum;
35 | }
36 |
37 | unsigned long acpi_get_ebda()
38 | {
39 | unsigned int* ebda = ((unsigned int*)(pio_mminw((unsigned int*)0x40e) << 4));
40 | if (ebda < (unsigned int*)0x80000 || ebda >= (unsigned int*)0xa0000)
41 | ebda = (unsigned int*)0x80000;
42 | return (unsigned long)ebda;
43 | }
44 |
45 | void* acpi_get_rsdp(void)
46 | {
47 | unsigned long ebda = acpi_get_ebda();
48 |
49 | for (unsigned long i = ebda; i < 0x100000; i += 16)
50 | {
51 | if (i == ebda + 1024)
52 | i = 0xe0000;
53 |
54 | if (!kmemcmp((char*)i, RSD_SIGNATURE, 8) && !acpi_checksum((void*)i, 20))
55 | {
56 | quantum_info(__FILE__, 0, " ACPI ", "Found RSDP at 0x%x", i);
57 | return (void*)i;
58 | }
59 | }
60 |
61 | return NULL;
62 | }
63 |
64 | BOOL is_rsdp_header_validate(rsdp_t* rsdp_header)
65 | {
66 | signed char* rsdp_header_ptr = (signed char*)rsdp_header;
67 | int checksum = 0;
68 |
69 | for (int i = 0; i < sizeof(rsdp_t); i++)
70 | checksum += (int)rsdp_header_ptr[i];
71 |
72 | if ((checksum & 0x000000ff) != 0)
73 | return FALSE;
74 |
75 | if (rsdp->revision == 0)
76 | return TRUE;
77 | else if (rsdp->revision != 2)
78 | return FALSE;
79 |
80 | // TODO: check chcecksum of extended rsdp part
81 | return FALSE;
82 | }
83 |
84 | void quantum_acpi_init()
85 | {
86 | rsdp = (rsdp_t*)acpi_get_rsdp();
87 | if (rsdp == NULL)
88 | {
89 | quantum_info(__FILE__, 1, " ACPI ", "Your machine don't support ACPI");
90 | machine_support_acpi = FALSE;
91 | return;
92 | }
93 |
94 | if (is_rsdp_header_validate(rsdp) == FALSE)
95 | {
96 | quantum_info(__FILE__, 1, " ACPI ", "RSDP Header is not validate");
97 | machine_support_acpi = FALSE;
98 | return;
99 | }
100 |
101 | quantum_info(__FILE__, 0, " ACPI ", "Successfully initialized ACPI");
102 | }
103 |
104 | void acpi_reboot(void)
105 | {
106 | unsigned char __value;
107 |
108 | asm volatile ("cli");
109 |
110 | do
111 | {
112 | __value = pio_inb(KEYBOARD_CONTROL);
113 |
114 | if (__acpi_check_bit(__value, KEYBOARD_BIT_KDATA) != 0)
115 | {
116 | pio_inb (KEYBOARD_DATA);
117 | }
118 | } while (__acpi_check_bit(__value, KEYBOARD_BIT_UDATA) != 0);
119 |
120 | pio_outb(KEYBOARD_CONTROL, KEYBOARD_RESET);
121 |
122 | __rescue_loop:
123 | asm volatile ("hlt");
124 |
125 | goto __rescue_loop;
126 | }
127 |
128 | void acpi_shutdown()
129 | {
130 | // If machine supports ACPI, shutdown with ACPI
131 | /* if (machine_support_acpi == TRUE)
132 | {
133 | // acpi_enable();
134 | pio_outs((unsigned int)PM1a_CNT, SLP_TYPa | SLP_EN);
135 | if (PM1b_CNT != 0)
136 | pio_outs((unsigned int)PM1b_CNT, SLP_TYPb | SLP_EN);
137 | } */
138 |
139 | printf("Something gone wrong while trying to shutdown with ACPI\n");
140 | printf("Wait 1s to shutdown\n");
141 |
142 | pit_sleep(1000);
143 |
144 | pio_outs(0xB004, 0x2000);
145 | pio_outs(0x604, 0x2000);
146 | pio_outs(0x4004, 0x3400);
147 | }
--------------------------------------------------------------------------------
/sys/x86_64/idt.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | IDT __idt_descriptors[IDE_DESCRIPTOR_COUNT];
14 | IDT_PTR __idt;
15 |
16 | void idt_set_entry(int __index, unsigned int __base, unsigned short __seg, unsigned char __flags)
17 | {
18 | IDT *__current = &__idt_descriptors[__index];
19 |
20 | __current->__base_low = (__base & 0xFFFF);
21 | __current->__segment_selector = __seg;
22 | __current->__zero = 0;
23 | __current->__type = (__flags | 0x60);
24 | __current->__base_high = (__base >> 16) & 0xFFFF;
25 | }
26 |
27 | void idt_enable(void)
28 | {
29 | __idt.__base = (unsigned int) __idt_descriptors;
30 | __idt.__limit = 256 * sizeof(IDT) - 1;
31 |
32 | pic_init();
33 |
34 | idt_set_entry(0, (unsigned int)exception_0, 0x08, 0x8E);
35 | idt_set_entry(1, (unsigned int)exception_1, 0x08, 0x8E);
36 | idt_set_entry(2, (unsigned int)exception_2, 0x08, 0x8E);
37 | idt_set_entry(3, (unsigned int)exception_3, 0x08, 0x8E);
38 | idt_set_entry(4, (unsigned int)exception_4, 0x08, 0x8E);
39 | idt_set_entry(5, (unsigned int)exception_5, 0x08, 0x8E);
40 | idt_set_entry(6, (unsigned int)exception_6, 0x08, 0x8E);
41 | idt_set_entry(7, (unsigned int)exception_7, 0x08, 0x8E);
42 | idt_set_entry(8, (unsigned int)exception_8, 0x08, 0x8E);
43 | idt_set_entry(9, (unsigned int)exception_9, 0x08, 0x8E);
44 | idt_set_entry(10, (unsigned int)exception_10, 0x08, 0x8E);
45 | idt_set_entry(11, (unsigned int)exception_11, 0x08, 0x8E);
46 | idt_set_entry(12, (unsigned int)exception_12, 0x08, 0x8E);
47 | idt_set_entry(13, (unsigned int)exception_13, 0x08, 0x8E);
48 | idt_set_entry(14, (unsigned int)exception_14, 0x08, 0x8E);
49 | idt_set_entry(15, (unsigned int)exception_15, 0x08, 0x8E);
50 | idt_set_entry(16, (unsigned int)exception_16, 0x08, 0x8E);
51 | idt_set_entry(17, (unsigned int)exception_17, 0x08, 0x8E);
52 | idt_set_entry(18, (unsigned int)exception_18, 0x08, 0x8E);
53 | idt_set_entry(19, (unsigned int)exception_19, 0x08, 0x8E);
54 | idt_set_entry(20, (unsigned int)exception_20, 0x08, 0x8E);
55 | idt_set_entry(21, (unsigned int)exception_21, 0x08, 0x8E);
56 | idt_set_entry(22, (unsigned int)exception_22, 0x08, 0x8E);
57 | idt_set_entry(23, (unsigned int)exception_23, 0x08, 0x8E);
58 | idt_set_entry(24, (unsigned int)exception_24, 0x08, 0x8E);
59 | idt_set_entry(25, (unsigned int)exception_25, 0x08, 0x8E);
60 | idt_set_entry(26, (unsigned int)exception_26, 0x08, 0x8E);
61 | idt_set_entry(27, (unsigned int)exception_27, 0x08, 0x8E);
62 | idt_set_entry(28, (unsigned int)exception_28, 0x08, 0x8E);
63 | idt_set_entry(29, (unsigned int)exception_29, 0x08, 0x8E);
64 | idt_set_entry(30, (unsigned int)exception_30, 0x08, 0x8E);
65 | idt_set_entry(31, (unsigned int)exception_31, 0x08, 0x8E);
66 | idt_set_entry(32, (unsigned int)irq_0, 0x08, 0x8E);
67 | idt_set_entry(33, (unsigned int)irq_1, 0x08, 0x8E);
68 | idt_set_entry(34, (unsigned int)irq_2, 0x08, 0x8E);
69 | idt_set_entry(35, (unsigned int)irq_3, 0x08, 0x8E);
70 | idt_set_entry(36, (unsigned int)irq_4, 0x08, 0x8E);
71 | idt_set_entry(37, (unsigned int)irq_5, 0x08, 0x8E);
72 | idt_set_entry(38, (unsigned int)irq_6, 0x08, 0x8E);
73 | idt_set_entry(39, (unsigned int)irq_7, 0x08, 0x8E);
74 | idt_set_entry(40, (unsigned int)irq_8, 0x08, 0x8E);
75 | idt_set_entry(41, (unsigned int)irq_9, 0x08, 0x8E);
76 | idt_set_entry(42, (unsigned int)irq_10, 0x08, 0x8E);
77 | idt_set_entry(43, (unsigned int)irq_11, 0x08, 0x8E);
78 | idt_set_entry(44, (unsigned int)irq_12, 0x08, 0x8E);
79 | idt_set_entry(45, (unsigned int)irq_13, 0x08, 0x8E);
80 | idt_set_entry(46, (unsigned int)irq_14, 0x08, 0x8E);
81 | idt_set_entry(47, (unsigned int)irq_15, 0x08, 0x8E);
82 | idt_set_entry(128, (unsigned int)exception_128, 0x08, 0x8E);
83 |
84 | load_idt((unsigned int) &__idt);
85 |
86 | quantum_info(__FILE__, 0, " IDT ", "Successfully initialized IDT");
87 |
88 | asm volatile ("sti");
89 | }
--------------------------------------------------------------------------------
/sys/x86_64/isr.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | ISR __interrupt_handlers[INTERRUPT_HANDLERS_COUNT];
13 |
14 | char *exception_messages[32] = {
15 | "Division By Zero",
16 | "Debug",
17 | "Non Maskable Interrupt",
18 | "Breakpoint",
19 | "Overflow",
20 | "BOUND Range Exceeded",
21 | "Invalid Opcode",
22 | "Device Not Available (No Math Coprocessor)",
23 | "Double Fault",
24 | "Coprocessor Segment Overrun",
25 | "Invalid TSS",
26 | "Segment Not Present",
27 | "Stack-Segment Fault",
28 | "General Protection",
29 | "Page Fault",
30 | "Unknown Interrupt (intel reserved)",
31 | "x87 FPU Floating-Point Error (Math Fault)",
32 | "Alignment Check",
33 | "Machine Check",
34 | "SIMD Floating-Point Exception",
35 | "Virtualization Exception",
36 | "Reserved",
37 | "Reserved",
38 | "Reserved",
39 | "Reserved",
40 | "Reserved",
41 | "Reserved",
42 | "Reserved",
43 | "Reserved",
44 | "Reserved",
45 | "Reserved",
46 | "Reserved"
47 | };
48 |
49 | void isr_register_interrupt_handler(int __index, ISR __handler)
50 | {
51 | if (__index < INTERRUPT_HANDLERS_COUNT)
52 | {
53 | __interrupt_handlers[__index] = __handler;
54 | }
55 | }
56 |
57 | void isr_end_interrupt(int __index)
58 | {
59 | pic_eoi((unsigned char) __index);
60 | }
61 |
62 | void isr_irq_handler(__registers_t *__regs)
63 | {
64 | if (__interrupt_handlers[__regs->int_no] != NULL)
65 | {
66 | ISR __handler = __interrupt_handlers[__regs->int_no];
67 |
68 | __handler(__regs);
69 | }
70 |
71 | pic_eoi((unsigned char) __regs->int_no);
72 | }
73 |
74 | void isr_exception_handler(__registers_t __regs)
75 | {
76 | if (__regs.int_no < 32)
77 | {
78 | printf("ISR ERROR 0x%x: %s\n", __regs.int_no, exception_messages[__regs.int_no]);
79 |
80 | asm volatile ("hlt");
81 | }
82 |
83 | if (__interrupt_handlers[__regs.int_no] != NULL)
84 | {
85 | ISR __handler = __interrupt_handlers[__regs.int_no];
86 |
87 | __handler(&__regs);
88 | }
89 | }
--------------------------------------------------------------------------------
/sys/x86_64/kgdt.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | GDT __gdt_descriptors[GDT_DESCRIPTOR_COUNT];
13 | GDT_PTR __gdt;
14 |
15 | extern void tss_flush();
16 | extern void load_gdt(unsigned int __gdt_ptr);
17 |
18 | tss_entry_t tss_entry;
19 |
20 | static void write_tss(int num, unsigned short ss0, unsigned int esp0)
21 | {
22 | unsigned int base = (unsigned int) &tss_entry;
23 | unsigned int limit = base + sizeof(tss_entry);
24 |
25 | gdt_set_entry(num, base, limit, 0xE9, 0x00);
26 | kmemset(&tss_entry, 0, sizeof(tss_entry));
27 |
28 | tss_entry.ss0 = ss0;
29 | tss_entry.esp0 = esp0;
30 |
31 | tss_entry.cs = 0x0b;
32 | tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13;
33 | }
34 |
35 | void gdt_set_entry(int __index, unsigned int __base, unsigned int __limit, unsigned char __access, unsigned char __gran)
36 | {
37 | GDT *__current = &__gdt_descriptors[__index];
38 |
39 | __current->__segment_limit = (__limit & 0xFFFF);
40 | __current->__base_low = (__base & 0xFFFF);
41 | __current->__base_mid = (__base >> 16) & 0xFF;
42 | __current->__access = __access;
43 |
44 | __current->__granularity = (__limit >> 16) & 0x0F;
45 | __current->__granularity = (__current->__granularity | (__gran & 0xF0));
46 |
47 | __current->__base_high = (__base >> 24 & 0xFF);
48 | }
49 |
50 | void gdt_enable(void)
51 | {
52 | __gdt.__limit = sizeof(__gdt_descriptors) - 1;
53 | __gdt.__base = (unsigned int) __gdt_descriptors;
54 |
55 | gdt_set_entry(0, 0, 0, 0, 0);
56 | gdt_set_entry(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
57 | gdt_set_entry(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
58 | gdt_set_entry(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
59 | gdt_set_entry(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
60 | write_tss(5, 0x10, 0x0);
61 |
62 | load_gdt((unsigned int) &__gdt);
63 | tss_flush();
64 |
65 | quantum_info(__FILE__, 0, " GDT ", "Successfully initialized GDT");
66 | quantum_info(__FILE__, 0, " TSS ", "Successfully initialized TSS");
67 | }
--------------------------------------------------------------------------------
/sys/x86_64/lapic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 | #include
8 |
9 | // unsigned int lapic_in(unsigned int __register)
10 | // {
11 | // return mio_in32(__global_apic_addr + __register);
12 | // }
13 |
14 | // void lapic_out(unsigned int __register, unsigned int __data)
15 | // {
16 | // mio_out32(__global_apic_addr + __register, __data);
17 | // }
18 |
19 | // void lapic_init(void)
20 | // {
21 | // lapic_out(LAPIC_TPR, 0);
22 |
23 | // lapic_out(LAPIC_DFR, 0xffffffff);
24 | // lapic_out(LAPIC_LDR, 0x01000000);
25 |
26 | // lapic_out(LAPIC_SVR, 0x100 | 0xff);
27 | // }
28 |
29 | // void lapic_send_init(unsigned int __id)
30 | // {
31 | // lapic_out(LAPIC_ICRHI, __id << ICR_DESTINATION_SHIFT);
32 | // lapic_out(LAPIC_ICRLO, ICR_INIT | ICR_PHYSICAL | ICR_ASSERT | ICR_EDGE | ICR_NO_SHORTHAND);
33 |
34 | // while (lapic_in(LAPIC_ICRLO) & ICR_SEND_PENDING);
35 | // {
36 | // /* Wait */
37 | // }
38 | // }
39 |
40 | // void lapic_send_startup(unsigned int __id, unsigned int __vector)
41 | // {
42 | // lapic_out(LAPIC_ICRHI, __id << ICR_DESTINATION_SHIFT);
43 | // lapic_out(LAPIC_ICRLO, ICR_STARTUP | ICR_PHYSICAL | ICR_ASSERT | ICR_EDGE | ICR_NO_SHORTHAND);
44 |
45 | // while (lapic_in(LAPIC_ICRLO) & ICR_SEND_PENDING);
46 | // {
47 | // /* Wait */
48 | // }
49 | // }
50 |
51 | // unsigned int lapic_getid(void)
52 | // {
53 | // return lapic_in(LAPIC_ID) >> 24;
54 | // }
--------------------------------------------------------------------------------
/sys/x86_64/mio.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | void mio_out8(void *__ptr, unsigned char __data)
9 | {
10 | *(volatile unsigned char *) (__ptr) = __data;
11 | }
12 |
13 | void mio_out16(void *__ptr, unsigned short __data)
14 | {
15 | *(volatile unsigned short *) (__ptr) = __data;
16 | }
17 |
18 | void mio_out32(void *__ptr, unsigned int __data)
19 | {
20 | *(volatile unsigned int *) (__ptr) = __data;
21 | }
22 |
23 | unsigned char mio_in8(void *__ptr)
24 | {
25 | return *(volatile unsigned char *) (__ptr);
26 | }
27 |
28 | unsigned short mio_in16(void *__ptr)
29 | {
30 | return *(volatile unsigned short *) (__ptr);
31 | }
32 |
33 | unsigned int mio_in32(void *__ptr)
34 | {
35 | return *(volatile unsigned int *) (__ptr);
36 | }
--------------------------------------------------------------------------------
/sys/x86_64/pic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | void pic_init(void)
12 | {
13 | unsigned char __a1, __a2;
14 |
15 | __a1 = pio_inb(PIC1_DATA);
16 | __a2 = pio_inb(PIC2_DATA);
17 |
18 | pio_outb(PIC1_COMMAND, ICW1);
19 | pio_outb(PIC2_COMMAND, ICW1);
20 |
21 | pio_outb(PIC1_DATA, 0x20);
22 | pio_outb(PIC2_DATA, 0x28);
23 |
24 | pio_outb(PIC1_DATA, 4);
25 | pio_outb(PIC2_DATA, 2);
26 |
27 | pio_outb(PIC1_DATA, ICW4_8086);
28 | pio_outb(PIC2_DATA, ICW4_8086);
29 |
30 | pio_outb(PIC1_DATA, __a1);
31 | pio_outb(PIC2_DATA, __a2);
32 |
33 | quantum_info(__FILE__, 0, " PIC ", "Successfully initialized PIC");
34 | }
35 |
36 | void pic_eoi(unsigned char __irq)
37 | {
38 | if (__irq >= 0x28)
39 | {
40 | pio_outb(PIC2, PIC_EOI);
41 | }
42 |
43 | pio_outb(PIC1, PIC_EOI);
44 | }
--------------------------------------------------------------------------------
/sys/x86_64/pio.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - CodeSploit
4 | */
5 |
6 | #include
7 |
8 | void pio_outb(unsigned short __port, unsigned char __data)
9 | {
10 | asm volatile ("outb %1, %0" :: "dN"(__port), "a"(__data));
11 | }
12 |
13 | void pio_outs(unsigned short __port, unsigned short __data)
14 | {
15 | asm volatile ("outw %1, %0" :: "dN" (__port), "a" (__data));
16 | }
17 |
18 | void pio_outl(unsigned short __port, unsigned int __data)
19 | {
20 | asm volatile ("outl %%eax, %%dx" :: "dN" (__port), "a" (__data));
21 | }
22 |
23 | unsigned char pio_inb(unsigned short __port)
24 | {
25 | unsigned char __result;
26 |
27 | asm volatile ("inb %1, %0" : "=a" (__result) : "Nd"(__port));
28 |
29 | return __result;
30 | }
31 |
32 | unsigned short pio_ins(unsigned short __port)
33 | {
34 | unsigned short __result;
35 |
36 | asm volatile ("inw %1, %0" : "=a" (__result) : "dN" (__port));
37 |
38 | return __result;
39 | }
40 |
41 | unsigned int pio_inl(unsigned short __port)
42 | {
43 | unsigned int __result;
44 |
45 | asm volatile ("inl %%dx, %%eax" : "=a" (__result) : "dN" (__port));
46 |
47 | return __result;
48 | }
49 |
50 | void pio_sleep(void)
51 | {
52 | pio_outb(0x80, 0);
53 | }
54 |
55 | unsigned short pio_mminw(unsigned int* addr)
56 | {
57 | unsigned short ret;
58 | asm volatile (
59 | "movw (%1), %0"
60 | : "=r" (ret)
61 | : "r" (addr)
62 | : "memory"
63 | );
64 | return ret;
65 | }
66 |
67 | void pio_qinl(unsigned short __register, unsigned int *__buffer, int __quads)
68 | {
69 | for (int i = 0; i < __quads; i++)
70 | {
71 | __buffer[i] = pio_inl(__register);
72 | }
73 | }
74 |
75 | void pio_qoutl(unsigned short __register, unsigned int *__buffer, int __quads)
76 | {
77 | for (int i = 0; i < __quads; i++)
78 | {
79 | pio_outl(__register, __buffer[i]);
80 | }
81 | }
--------------------------------------------------------------------------------
/sys/x86_64/pit.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | static unsigned long ticks = 0;
12 |
13 | void quantum_pit_init()
14 | {
15 | // Disable interrupts
16 | __asm__("cli");
17 |
18 | // Set PIT timer frequency to 1000 so the timer runs every 0.001s
19 | // which is 1 milisecond, also set the irq handler to 0x20 (32)
20 | // which is PIT timer irq gate
21 | pit_set_freq(1000);
22 | isr_register_interrupt_handler(IRQ_BASE, pit_handler);
23 |
24 | // Enable interrupts
25 | __asm__("sti");
26 | }
27 |
28 |
29 | void pit_set_freq(int freq)
30 | {
31 | int divisor = 1193180 / freq; /// Calculate our divisor
32 |
33 | // Send our frequency to PIT to set it!
34 | pio_outb(PIT_MODE_COMMAND_REG, 0x36);
35 | pio_outb(PIT_CHANNEL_O_DATA_PORT, divisor & 0xFF);
36 | pio_outb(PIT_CHANNEL_O_DATA_PORT, divisor >> 8);
37 | }
38 |
39 | void pit_handler(__registers_t* regs)
40 | {
41 | ticks++;
42 | }
43 |
44 | unsigned long pit_get_ticks()
45 | {
46 | return ticks;
47 | }
48 |
49 | void pit_sleep(int ms)
50 | {
51 | unsigned long eticks = ticks + ms;
52 | while (ticks < eticks) ;
53 | }
--------------------------------------------------------------------------------
/userspace/elf.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 |
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | #include
13 |
14 | int is_elf_magic(elf32_ehdr_t* header)
15 | {
16 | if (!(header->e_ident[0] == ELFMAG0 && header->e_ident[1] == ELFMAG1 &&
17 | header->e_ident[2] == ELFMAG2 && header->e_ident[3] == ELFMAG3))
18 | return 0;
19 | }
20 |
21 | int is_elf_correct(elf32_ehdr_t* header)
22 | {
23 | if (header->e_ident[EI_CLASS] != ELFCLASS32)
24 | {
25 | quantum_info(__FILE__, 1, " ELF ", "Unsupported ELF File Class");
26 | return 0;
27 | }
28 | else if (header->e_ident[EI_DATA] != ELFDATA2LSB)
29 | {
30 | quantum_info(__FILE__, 1, " ELF ", "Unsupported ELF File byte order");
31 | return 0;
32 | }
33 | else if (header->e_machine != EM_386)
34 | {
35 | quantum_info(__FILE__, 1, " ELF ", "Unsupported ELF File target");
36 | return 0;
37 | }
38 | else if (header->e_ident[EI_VERSION] != EV_CURRENT)
39 | {
40 | quantum_info(__FILE__, 1, " ELF ", "Unsupported ELF File version");
41 | return 0;
42 | }
43 | else if (header->e_type != ET_REL && header->e_type != ET_EXEC)
44 | {
45 | quantum_info(__FILE__, 1, " ELF ", "Unsupported ELF File type");
46 | return 0;
47 | }
48 | }
49 |
50 | int load_elf(char* data, elf32_ehdr_t* header)
51 | {
52 | header = (elf32_ehdr_t*)data;
53 |
54 | if (!is_elf_magic(header))
55 | {
56 | quantum_info(__FILE__, 1, " ELF ", "This is not an ELF File");
57 | return INVALID_ELF;
58 | }
59 |
60 | if (!is_elf_correct(header))
61 | {
62 | quantum_info(__FILE__, 1, " ELF ", "This is not an correct ELF File");
63 | return NCORRECT_ELF;
64 | }
65 |
66 | quantum_info(__FILE__, 0, " ELF ", "Fully correct file");
67 |
68 | // Load this program better please :)
69 | for (int i = 0; i < header->e_phnum; i++)
70 | {
71 | elf32_phdr_t* program_header;
72 | program_header = (elf32_phdr_t*)(data + (header->e_phoff + (i * header->e_phentsize)));
73 |
74 | if (program_header->p_type == PT_LOAD)
75 | {
76 | unsigned char* mem = (unsigned char*)program_header->p_paddr;
77 |
78 | kmemcpy(mem, data + program_header->p_offset, program_header->p_memsz);
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/userspace/usermode.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | void switch_to_user_mode()
9 | {
10 | asm volatile(" \
11 | cli; \
12 | mov $0x23, %ax; \
13 | mov %ax, %ds; \
14 | mov %ax, %es; \
15 | mov %ax, %fs; \
16 | mov %ax, %gs; \
17 | mov %esp, %eax; \
18 | pushl $0x23; \
19 | pushl %eax; \
20 | pushf; \
21 | pushl $0x1B; \
22 | push $1f; \
23 | iret; \
24 | 1: \
25 | ");
26 | }
--------------------------------------------------------------------------------
/userspace/userspace.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include
32 |
33 | static unsigned char mouse_bitmap[11 * 18] = {
34 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
35 | 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2
36 | 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, // 3
37 | 1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, // 4
38 | 1, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, // 5
39 | 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, // 6
40 | 1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, // 7
41 | 1, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, // 8
42 | 1, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, // 9
43 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, // 10
44 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, // 11
45 | 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, // 12
46 | 1, 2, 2, 2, 1, 2, 2, 1, 0, 0, 0, // 13
47 | 1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 0, // 14
48 | 1, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, // 15
49 | 1, 1, 0, 0, 0, 0, 1, 2, 2, 1, 0, // 16
50 | 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 0, // 17
51 | 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, // 18
52 | };
53 |
54 | static short fps = 0;
55 |
56 | static int mouse_x = 0;
57 | static int mouse_y = 0;
58 |
59 | void draw_mouse()
60 | {
61 | for (int y = 0; y < 18; y++)
62 | {
63 | for (int x = 0; x < 11; x++)
64 | {
65 | if (mouse_bitmap[x + (y * 11)] == 0)
66 | continue;
67 | else if (mouse_bitmap[x + (y * 11)] == 1)
68 | vesa_put_pixel_double_buffering(mouse_x + x, mouse_y + y, 0, 0, 0);
69 | else if (mouse_bitmap[x + (y * 11)] == 2)
70 | vesa_put_pixel_double_buffering(mouse_x + x, mouse_y + y, 255, 255, 255);
71 | }
72 | }
73 | }
74 |
75 | void render()
76 | {
77 | draw_windows();
78 | draw_mouse();
79 | swap_buffers();
80 | }
81 |
82 | void inputs()
83 | {
84 | mouse_x = get_mouse_x();
85 | mouse_y = get_mouse_y();
86 | }
87 |
88 | void userspace_initialize(void)
89 | {
90 | vesa_clear();
91 | set_default_pos();
92 |
93 | toggle_double_framebuffer();
94 |
95 | create_window("Terminal", 700, 450, 100, 100);
96 |
97 | unsigned long last_second = 0;
98 | unsigned long now = pit_get_ticks();
99 |
100 | short frames = 0;
101 |
102 | while (1)
103 | {
104 | now = pit_get_ticks();
105 | if (now - last_second > 1000)
106 | {
107 | fps = frames;
108 | frames = 0;
109 | last_second = now;
110 | quantum_info(__FILE__, 0, " GUI ", "FPS: %d", fps);
111 | }
112 |
113 | frames++;
114 | clear_back_buffer();
115 | inputs();
116 | render();
117 | }
118 |
119 | for (;;)
120 | {}
121 | }
--------------------------------------------------------------------------------
/userspace/window.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QuantumOS Copyright (c) 2022-2023
3 | * - Solindek
4 | */
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | #include
13 |
14 | window_t* windows;
15 | int windows_len = 0;
16 |
17 | void init_windows()
18 | {
19 | windows = (window_t*)kmalloc(sizeof(window_t) * 3);
20 | }
21 |
22 | window_t create_window(char* window_name, int size_x, int size_y, int pos_x, int pos_y)
23 | {
24 | window_t window;
25 |
26 | int max_offset_framebuffer = (size_x * 4) + (size_y * (size_x * 4));
27 | window.framebuffer = kmalloc(sizeof(unsigned char) * max_offset_framebuffer);
28 |
29 | window.size_x = size_x;
30 | window.size_y = size_y;
31 | window.pos_x = pos_x;
32 | window.pos_y = pos_y;
33 | window.should_redraw = TRUE;
34 |
35 | strcpy(window.window_name, window_name);
36 |
37 | windows[windows_len] = window;
38 | windows_len++;
39 | return window;
40 | }
41 |
42 | void draw_windows()
43 | {
44 | for (int i = 0; i < windows_len; i++)
45 | {
46 | window_t current_window = windows[i];
47 | debug_printf("%s\n", current_window.window_name);
48 | if (current_window.should_redraw == TRUE)
49 | render_window(current_window);
50 | }
51 | }
52 |
53 | void render_window(window_t window)
54 | {
55 | vesa_draw_rect(window.pos_x, window.pos_y, window.size_x, window.size_y, 255, 255, 255);
56 | }
57 |
58 | void put_pixel_window(window_t window, int x, int y, int r, int g, int b)
59 | {
60 | unsigned int offset = (x * 4) + (y * (x * 4));
61 | window.framebuffer[offset ] = b;
62 | window.framebuffer[offset + 1] = g;
63 | window.framebuffer[offset + 2] = r;
64 | }
--------------------------------------------------------------------------------