├── .gitattributes ├── .gitignore ├── Executable Tests ├── buildasm.bat ├── buildexec.bat ├── exec ├── exec.o ├── execasm ├── testexecutable.asm └── testexecutable.c ├── README.md ├── asm ├── disk.asm ├── gdt.asm ├── int.asm ├── multiboot.asm ├── paging.asm ├── print_util.asm ├── startup.asm └── syscall.asm ├── attach.sh ├── codeos2.img ├── copy.sh ├── kernel.map ├── libc ├── crt0.o ├── crt0.s ├── stdio.c └── stdio.h ├── linker.ld ├── logo.bmp ├── makefile ├── run.sh └── src ├── include └── kernel │ ├── ata.h │ ├── common.h │ ├── ehci.h │ ├── elf.h │ ├── ext2.h │ ├── fat32.h │ ├── gdt.h │ ├── heap.h │ ├── idt.h │ ├── irq.h │ ├── isr.h │ ├── keyboard.h │ ├── kmain.h │ ├── multiboot.h │ ├── paging.h │ ├── pci.h │ ├── pit.h │ ├── shell.h │ ├── stdio.h │ ├── syscall.h │ ├── tasking.h │ ├── tss.h │ └── vfs.h ├── kernel ├── ata.c ├── common.c ├── ehci.c ├── elf.c ├── ext2.c ├── fat32.c ├── gdt.c ├── heap.c ├── idt.c ├── irq.c ├── isr.c ├── keyboard.c ├── kmain.c ├── paging.c ├── pci.c ├── pit.c ├── shell.c ├── stdio.c ├── syscall.c ├── tasking.c ├── tss.c └── vfs.c └── unused ├── drivers └── VGA │ ├── VESA.c │ ├── VESA.h │ ├── VGA_13h.c │ └── VGA_13h.h ├── etc └── font │ └── font_8x8.h ├── logo.h └── util ├── draw ├── draw_util.c └── draw_util.h └── print ├── print_util_320_200_256.c ├── print_util_320_200_256.h ├── print_util_640_480_16.c └── print_util_640_480_16.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | #Other stuff 50 | bin 51 | tmp 52 | out 53 | buildandrun.sh 54 | loops 55 | -------------------------------------------------------------------------------- /Executable Tests/buildasm.bat: -------------------------------------------------------------------------------- 1 | nasm testexecutable.asm -f bin -o execasm 2 | pause -------------------------------------------------------------------------------- /Executable Tests/buildexec.bat: -------------------------------------------------------------------------------- 1 | i686-elf-gcc -c testexecutable.c -o exec.o -ffreestanding -std=gnu99 2 | i686-elf-ld exec.o -o exec -emain -Ttext 0x0 --oformat binary 3 | pause -------------------------------------------------------------------------------- /Executable Tests/exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/Executable Tests/exec -------------------------------------------------------------------------------- /Executable Tests/exec.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/Executable Tests/exec.o -------------------------------------------------------------------------------- /Executable Tests/execasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/Executable Tests/execasm -------------------------------------------------------------------------------- /Executable Tests/testexecutable.asm: -------------------------------------------------------------------------------- 1 | [bits 32] 2 | mov eax, 0 3 | mov ebx, 'H' 4 | int 0x80 5 | mov eax, 0 6 | mov ebx, 'e' 7 | int 0x80 8 | mov eax, 0 9 | mov ebx, 'l' 10 | int 0x80 11 | mov eax, 0 12 | mov ebx, 'l' 13 | int 0x80 14 | mov eax, 0 15 | mov ebx, 'o' 16 | int 0x80 17 | mov eax, 0 18 | mov ebx, ' ' 19 | int 0x80 20 | mov eax, 0 21 | mov ebx, 'W' 22 | int 0x80 23 | mov eax, 0 24 | mov ebx, 'o' 25 | int 0x80 26 | mov eax, 0 27 | mov ebx, 'r' 28 | int 0x80 29 | mov eax, 0 30 | mov ebx, 'l' 31 | int 0x80 32 | mov eax, 0 33 | mov ebx, 'd' 34 | int 0x80 35 | mov eax, 0 36 | mov ebx, '!' 37 | int 0x80 38 | ret -------------------------------------------------------------------------------- /Executable Tests/testexecutable.c: -------------------------------------------------------------------------------- 1 | void printf(char* c); 2 | //void syscall(unsigned int callid); 3 | 4 | void main(){ 5 | printf("Hello from C!"); 6 | //syscall(2); 7 | } 8 | 9 | #include "../libc/stdio.h" 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # codeOS2 2 | ### CodeOS Re-Written from scratch 3 | 4 | ### CODEOS2 MUST BE BOOTED FROM A HARD DRIVE (Or emulated hard drive). THERE IS NO USB SUPPORT YET. 5 | 6 | ## How to use codeOS2 7 | 8 | You can compile from source using the makefile. 9 | 10 | Also, you can use the provided codeos2.img file. However, this is not updated with the latest code changes very often. 11 | 12 | Use win32diskimager (or dd if you are on linux) to write codeos2.img to an HDD or USB drive. (This may not contain the latest code changes.) If you write it to a USB drive you cannot boot it off of a real computer since codeOS doesn't have USB support yet, but you can use it with VMWare player or VirtualBox physical disk mounting. 13 | 14 | You can also use the .img file directly with qemu. 15 | 16 | ## Goals (~~crossed out~~ means completed) 17 | 18 | * ~~Fat32 and Ext2 support (Once implemented, Ext2 will be the main filesystem.)~~ 19 | * Ext2 is now the main filesystem. 20 | * Be able to run executables 21 | * It kinda can at the moment, but they are loaded into a designated area of memory and run in kernel space. 22 | * VGA Driver(?) 23 | * User mode 24 | * Shell and shell scripts 25 | * At least partial POSIX compliance (someday...) 26 | * I'm not sure if I'm going to make it directly POSIX compatible, or have a compatibility layer for POSIX applications. It might just be easier to make it directly (partially) POSIX compatible. 27 | 28 | # Compile 29 | Make a new folder called out, and in that a folder called disk. 30 | Use make to compile, and then you will have to take all of the directories and files in out/disk and copy them to a drive with GRUB2 installed. Then use the multiboot2 command in grub with the file codeos2/system/krnl32. 31 | -------------------------------------------------------------------------------- /asm/disk.asm: -------------------------------------------------------------------------------- 1 | disk_load: ;Loads DH sectors into ES:BX from drive DL starting at cl 2 | ;Only works in 16-bit mode 3 | push dx 4 | mov ah,0x02 ;Read 5 | mov al, dh ;Read DH sectors 6 | mov ch,0x00 ;Cylinder 0 7 | mov dh,0x00 ;Head 0 8 | disk_load_go: 9 | int 0x13 10 | jc disk_error ;Something went wrong 11 | pop dx 12 | cmp dh,al ;Compare sectors expected vs sectors gotten 13 | jne disk_error 14 | ret 15 | 16 | disk_error: 17 | jmp $ -------------------------------------------------------------------------------- /asm/gdt.asm: -------------------------------------------------------------------------------- 1 | global gdt_flush 2 | extern gp 3 | gdt_flush: 4 | cli 5 | lgdt [gp] 6 | mov ax, 0x10 7 | mov ds, ax 8 | mov es, ax 9 | mov fs, ax 10 | mov gs, ax 11 | mov ss, ax 12 | jmp 0x08:flush2 13 | flush2: 14 | ret -------------------------------------------------------------------------------- /asm/int.asm: -------------------------------------------------------------------------------- 1 | global idt_load 2 | extern idtp 3 | extern preempt 4 | extern tasking_enabled 5 | idt_load: 6 | lidt [idtp] 7 | ret 8 | 9 | global isr0 10 | global isr1 11 | global isr2 12 | global isr3 13 | global isr4 14 | global isr5 15 | global isr6 16 | global isr7 17 | global isr8 18 | global isr9 19 | global isr10 20 | global isr11 21 | global isr12 22 | global isr13 23 | global isr14 24 | global isr15 25 | global isr16 26 | global isr17 27 | global isr18 28 | global isr19 29 | global isr20 30 | global isr21 31 | global isr22 32 | global isr23 33 | global isr24 34 | global isr25 35 | global isr26 36 | global isr27 37 | global isr28 38 | global isr29 39 | global isr30 40 | global isr31 41 | 42 | %macro ISR_NOCODE 1 ;These are ISRs that don't have codes already pushed onto the stack 43 | isr%1: 44 | cli 45 | push byte 0 46 | push byte %1 47 | jmp isr_common 48 | %endmacro 49 | 50 | %macro ISR_CODE 1 ;These are ISRs that have codes already pushed onto the stack 51 | isr%1: 52 | cli 53 | push byte %1 54 | jmp isr_common 55 | %endmacro 56 | 57 | ISR_CODE 0 ;Generated by CPU: Divide by zero 58 | ISR_CODE 1 ;Generated by CPU: Debug 59 | ISR_CODE 2 ;Generated by CPU: Non Maskable Interrupt 60 | ISR_CODE 3 ;Generated by CPU: Breakpoint 61 | ISR_CODE 4 ;Generated by CPU: Detected Overflow 62 | ISR_CODE 5 ;Generated by CPU: Out of Bounds 63 | ISR_CODE 6 ;Generated by CPU: Invalid Opcode 64 | ISR_CODE 7 ;Generated by CPU: No Coprocessor 65 | ISR_CODE 8 ;Generated by CPU: Double Fault 66 | ISR_CODE 9 ;Generated by CPU: Coprocessor Segment Overrun 67 | ISR_CODE 10 ;Generated by CPU: Bad TSS 68 | ISR_CODE 11 ;Generated by CPU: Segment Not Present 69 | ISR_CODE 12 ;Generated by CPU: Stack Fault 70 | ISR_CODE 13 ;Generated by CPU: General Protection Fault 71 | ISR_CODE 14 ;Generated by CPU: Page Fault 72 | ISR_CODE 15 ;Generated by CPU: Unknown Interrupt 73 | ISR_CODE 16 ;Generated by CPU: Coprocessor Fault 74 | ISR_CODE 17 ;Generated by CPU: Alignment Check 75 | ISR_CODE 18 ;Generated by CPU: Machine Check 76 | ISR_NOCODE 19 77 | ISR_NOCODE 20 78 | ISR_NOCODE 21 79 | ISR_NOCODE 22 80 | ISR_NOCODE 23 81 | ISR_NOCODE 24 82 | ISR_NOCODE 25 83 | ISR_NOCODE 26 84 | ISR_NOCODE 27 85 | ISR_NOCODE 28 86 | ISR_NOCODE 29 87 | ISR_NOCODE 30 88 | ISR_NOCODE 31 89 | 90 | [extern fault_handler] 91 | 92 | isr_common: 93 | pusha 94 | push ds 95 | push es 96 | push fs 97 | push gs 98 | mov ax, 0x10 99 | mov ds, ax 100 | mov es, ax 101 | mov fs, ax 102 | mov gs, ax 103 | mov eax, esp 104 | push eax 105 | mov eax, fault_handler 106 | call eax 107 | pop eax 108 | pop gs 109 | pop fs 110 | pop es 111 | pop ds 112 | popa 113 | add esp, 8 114 | iret 115 | 116 | global irq0 117 | global irq1 118 | global irq2 119 | global irq3 120 | global irq4 121 | global irq5 122 | global irq6 123 | global irq7 124 | global irq8 125 | global irq9 126 | global irq10 127 | global irq11 128 | global irq12 129 | global irq13 130 | global irq14 131 | global irq15 132 | 133 | %macro irq 1 134 | irq%1: 135 | cli 136 | push byte 0 137 | push byte %1+32 138 | jmp irq_common 139 | %endmacro 140 | 141 | irq0: 142 | push eax 143 | mov eax, 0x20 144 | out 0x20, al ; bytes only plz 145 | pop eax 146 | cmp byte [tasking_enabled], 0 147 | jne preempt_do 148 | iret 149 | preempt_do: 150 | call preempt 151 | iret 152 | irq 1 153 | irq 2 154 | irq 3 155 | irq 4 156 | irq 5 157 | irq 6 158 | irq 7 159 | irq 8 160 | irq 9 161 | irq 10 162 | irq 11 163 | irq 12 164 | irq 13 165 | irq 14 166 | irq 15 167 | 168 | [extern irq_handler] 169 | 170 | irq_common: 171 | pusha 172 | push ds 173 | push es 174 | push fs 175 | push gs 176 | mov ax, 0x10 177 | mov ds, ax 178 | mov es, ax 179 | mov fs, ax 180 | mov gs, ax 181 | mov eax, esp 182 | push eax 183 | mov eax, irq_handler 184 | call eax 185 | pop eax 186 | pop gs 187 | pop fs 188 | pop es 189 | pop ds 190 | popa 191 | add esp, 8 192 | iret 193 | 194 | global _iret 195 | _iret: 196 | iret 197 | -------------------------------------------------------------------------------- /asm/multiboot.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/asm/multiboot.asm -------------------------------------------------------------------------------- /asm/paging.asm: -------------------------------------------------------------------------------- 1 | [global load_page_dir] 2 | load_page_dir: 3 | push ebp ; 4 | mov ebp, esp ;Set the stack location to where we stored the passed variables in C 5 | push dword [ebp+8] ; 6 | pop eax ;The page directory variable 7 | 8 | pusha 9 | mov cr3, eax 10 | 11 | mov eax, cr0 12 | or eax, 0x80000000 13 | mov cr0, eax 14 | popa 15 | 16 | mov esp, ebp ; 17 | pop ebp ;Restore the stack 18 | ret -------------------------------------------------------------------------------- /asm/print_util.asm: -------------------------------------------------------------------------------- 1 | print_string: ;Will only work in 16-bit mode 2 | pusha 3 | mov ah, 0x0e 4 | print_loop: 5 | mov al, [bx] 6 | cmp al, 0 7 | je print_string_done 8 | int 0x10 9 | add bx, 1 10 | jmp print_loop 11 | print_string_done: 12 | popa 13 | ret 14 | 15 | print_char: 16 | pusha 17 | mov ah, 0x0e 18 | int 0x10 19 | popa 20 | ret 21 | 22 | print_hex: ;Will only work in 16 bit mode 23 | pusha 24 | 25 | mov cx,4 26 | char_loop: 27 | dec cx 28 | 29 | mov ax,dx 30 | shr dx,4 31 | and ax,0xf 32 | 33 | mov bx, HEX_OUT 34 | add bx, cx 35 | 36 | cmp ax,0xa 37 | jl set_letter 38 | add byte [bx],7 39 | jl set_letter 40 | 41 | set_letter: 42 | add byte [bx],al 43 | 44 | cmp cx,0 45 | je print_hex_done 46 | jmp char_loop 47 | 48 | print_hex_done: 49 | mov bx, HEX_OUT 50 | call print_string 51 | sub bx,3 52 | mov cx,4 53 | call reset_hex_loop 54 | popa 55 | ret 56 | 57 | reset_hex_loop: 58 | dec cx 59 | mov bx, HEX_OUT 60 | add bx,cx 61 | mov byte [bx],'0' 62 | cmp cx,0 63 | jne reset_hex_loop 64 | ret 65 | 66 | HEX_OUT: db '0000',0 -------------------------------------------------------------------------------- /asm/startup.asm: -------------------------------------------------------------------------------- 1 | [global start] 2 | [global load_gdt] 3 | [extern kmain] 4 | [global BootPageDirectory] 5 | 6 | global flagss 7 | 8 | KERNEL_VIRTUAL_BASE equ 0xC0000000 ; 3GiB 9 | KERNEL_PAGE_NUMBER equ (KERNEL_VIRTUAL_BASE >> 22) 10 | 11 | section .data 12 | align 0x1000 13 | BootPageDirectory: ;The page directory for mapping the higher-half. 14 | dd 0x00000083 15 | times (KERNEL_PAGE_NUMBER - 1) dd 0 16 | dd 0x00000083 ;Our kernel's page 17 | times (1024 - KERNEL_PAGE_NUMBER - 1) dd 0 18 | 19 | retfromkernel: db 0xa,"|-----------------------|",0xa,"| Returned from kernel. |",0xa,"|-----------------------|" ;The message that shows when (if?) the kernel exits. 20 | 21 | section .text 22 | align 4 23 | mboot: 24 | dd 0xe85250d6 25 | dd 0 26 | dd mboot_end-mboot 27 | dd -(0xe85250d6 + 0 + (mboot_end - mboot)) 28 | dw 0 29 | dw 0 30 | dd 8 31 | mboot_end: 32 | 33 | start: 34 | mov ecx, (BootPageDirectory - KERNEL_VIRTUAL_BASE) ;We're subtracting KERNEL_VIRTUAL_BASE because this whole thing is compiled with an offset of 0xc0000000, and we want physical addresses. 35 | mov cr3, ecx 36 | 37 | mov ecx, cr4 38 | or ecx, 0x00000010 ;Enable PAE 39 | mov cr4, ecx 40 | 41 | mov ecx, cr0 42 | or ecx, 0x80000000 ;Turn on paging 43 | mov cr0, ecx 44 | 45 | lea ecx, [start_hh] 46 | jmp ecx 47 | 48 | start_hh: 49 | mov dword [BootPageDirectory], 0 50 | invlpg [0] 51 | 52 | mov esp, stack+0x4000 53 | push dword ebx 54 | 55 | call kmain 56 | 57 | mov eax, 1 58 | mov ebx, retfromkernel 59 | int 0x80 60 | jmp $ 61 | 62 | ;%include 'asm/vesa.asm' I still gotta figure out how to deal with this in 32-bit mode 63 | %include 'asm/gdt.asm' 64 | %include 'asm/syscall.asm' 65 | %include 'asm/int.asm' 66 | %include 'asm/paging.asm' 67 | 68 | section .bss 69 | align 32 70 | stack: 71 | resb 0x4000 ; reserve 16k stack on a uint64_t boundary 72 | -------------------------------------------------------------------------------- /asm/syscall.asm: -------------------------------------------------------------------------------- 1 | [extern syscallHandler] 2 | global syscall_handler 3 | syscall_handler: 4 | push ebx 5 | push eax 6 | call syscallHandler 7 | pop eax 8 | pop ebx 9 | iret 10 | -------------------------------------------------------------------------------- /attach.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ $# -eq 0 ] 3 | then 4 | echo "No arguments supplied. use -a for attach, and -d for detach." 5 | else 6 | if [ "$1" == "-a" ] 7 | then 8 | sudo losetup -f > loops 9 | sudo losetup -f codeos2.img 10 | sudo losetup -f >> loops 11 | sudo losetup -f codeos2.img -o 1048576 12 | readarray loops < loops 13 | sudo mount ${loops[1]} /media/${USER}/codeOS2 -o sync 14 | echo "Attached! Loops:" 15 | cat loops 16 | elif [ "$1" == "-d" ] 17 | then 18 | readarray loops < loops 19 | sudo umount ${loops[1]} 20 | sudo losetup -d ${loops[0]} 21 | sudo losetup -d ${loops[1]} 22 | > loops 23 | echo "Detached!" 24 | else 25 | echo "Invalid argument $1!" 26 | fi 27 | fi 28 | -------------------------------------------------------------------------------- /codeos2.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/codeos2.img -------------------------------------------------------------------------------- /copy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo cp -a out/disk/. /media/${USER}/codeOS2/ 3 | -------------------------------------------------------------------------------- /kernel.map: -------------------------------------------------------------------------------- 1 | 2 | Allocating common symbols 3 | Common symbol size file 4 | 5 | cmdbuf 0x100 shell.o 6 | gp 0x6 gdt.o 7 | idtp 0x6 idt.o 8 | ata_buf2 0x200 ata.o 9 | gdt 0x28 gdt.o 10 | prog 0x1000 fat32.o 11 | dirbuf2 0x200 shell.o 12 | tss_high 0x2 kmain.o 13 | i 0x4 kmain.o 14 | heap_space 0x100000 heap.o 15 | exec_page_table 0x1000 paging.o 16 | frbuf 0xc heap.o 17 | tss_low 0x1 kmain.o 18 | kfreebuf 0x4 heap.o 19 | argbuf 0x100 shell.o 20 | idt 0x800 idt.o 21 | kbdbuf 0x100 keyboard.o 22 | dirbuf 0x200 shell.o 23 | ata_buf 0x200 ata.o 24 | kernel_proc 0x4 tasking.o 25 | frsbuf 0x10 heap.o 26 | page_directory 0x1000 paging.o 27 | frames 0x2000 heap.o 28 | input_i 0x1 keyboard.o 29 | currentfat32part 0x28 fat32.o 30 | current_proc 0x4 tasking.o 31 | 32 | Discarded input sections 33 | 34 | .group 0x0000000000000000 0x8 ata.o 35 | .group 0x0000000000000000 0x8 ata.o 36 | .group 0x0000000000000000 0x8 common.o 37 | .text.__x86.get_pc_thunk.ax 38 | 0x0000000000000000 0x4 common.o 39 | .group 0x0000000000000000 0x8 ehci.o 40 | .group 0x0000000000000000 0x8 ehci.o 41 | .text.__x86.get_pc_thunk.ax 42 | 0x0000000000000000 0x4 ehci.o 43 | .text.__x86.get_pc_thunk.bx 44 | 0x0000000000000000 0x4 ehci.o 45 | .group 0x0000000000000000 0x8 ext2.o 46 | .group 0x0000000000000000 0x8 ext2.o 47 | .text.__x86.get_pc_thunk.ax 48 | 0x0000000000000000 0x4 ext2.o 49 | .text.__x86.get_pc_thunk.bx 50 | 0x0000000000000000 0x4 ext2.o 51 | .group 0x0000000000000000 0x8 fat32.o 52 | .group 0x0000000000000000 0x8 fat32.o 53 | .group 0x0000000000000000 0x8 fat32.o 54 | .text.__x86.get_pc_thunk.ax 55 | 0x0000000000000000 0x4 fat32.o 56 | .text.__x86.get_pc_thunk.bx 57 | 0x0000000000000000 0x4 fat32.o 58 | .group 0x0000000000000000 0x8 gdt.o 59 | .group 0x0000000000000000 0x8 gdt.o 60 | .text.__x86.get_pc_thunk.ax 61 | 0x0000000000000000 0x4 gdt.o 62 | .text.__x86.get_pc_thunk.bx 63 | 0x0000000000000000 0x4 gdt.o 64 | .group 0x0000000000000000 0x8 heap.o 65 | .group 0x0000000000000000 0x8 heap.o 66 | .group 0x0000000000000000 0x8 heap.o 67 | .text.__x86.get_pc_thunk.ax 68 | 0x0000000000000000 0x4 heap.o 69 | .text.__x86.get_pc_thunk.bx 70 | 0x0000000000000000 0x4 heap.o 71 | .group 0x0000000000000000 0x8 idt.o 72 | .group 0x0000000000000000 0x8 idt.o 73 | .text.__x86.get_pc_thunk.ax 74 | 0x0000000000000000 0x4 idt.o 75 | .text.__x86.get_pc_thunk.bx 76 | 0x0000000000000000 0x4 idt.o 77 | .group 0x0000000000000000 0x8 irq.o 78 | .group 0x0000000000000000 0x8 irq.o 79 | .text.__x86.get_pc_thunk.ax 80 | 0x0000000000000000 0x4 irq.o 81 | .text.__x86.get_pc_thunk.bx 82 | 0x0000000000000000 0x4 irq.o 83 | .group 0x0000000000000000 0x8 isr.o 84 | .text.__x86.get_pc_thunk.bx 85 | 0x0000000000000000 0x4 isr.o 86 | .group 0x0000000000000000 0x8 keyboard.o 87 | .group 0x0000000000000000 0x8 keyboard.o 88 | .text.__x86.get_pc_thunk.ax 89 | 0x0000000000000000 0x4 keyboard.o 90 | .text.__x86.get_pc_thunk.bx 91 | 0x0000000000000000 0x4 keyboard.o 92 | .group 0x0000000000000000 0x8 kmain.o 93 | .group 0x0000000000000000 0x8 kmain.o 94 | .text.__x86.get_pc_thunk.dx 95 | 0x0000000000000000 0x4 kmain.o 96 | .text.__x86.get_pc_thunk.bx 97 | 0x0000000000000000 0x4 kmain.o 98 | .group 0x0000000000000000 0x8 paging.o 99 | .group 0x0000000000000000 0x8 paging.o 100 | .text.__x86.get_pc_thunk.ax 101 | 0x0000000000000000 0x4 paging.o 102 | .text.__x86.get_pc_thunk.bx 103 | 0x0000000000000000 0x4 paging.o 104 | .group 0x0000000000000000 0x8 pci.o 105 | .group 0x0000000000000000 0x8 pci.o 106 | .text.__x86.get_pc_thunk.ax 107 | 0x0000000000000000 0x4 pci.o 108 | .text.__x86.get_pc_thunk.bx 109 | 0x0000000000000000 0x4 pci.o 110 | .group 0x0000000000000000 0x8 pit.o 111 | .group 0x0000000000000000 0x8 pit.o 112 | .group 0x0000000000000000 0x8 pit.o 113 | .text.__x86.get_pc_thunk.ax 114 | 0x0000000000000000 0x4 pit.o 115 | .text.__x86.get_pc_thunk.dx 116 | 0x0000000000000000 0x4 pit.o 117 | .group 0x0000000000000000 0x8 shell.o 118 | .group 0x0000000000000000 0x8 shell.o 119 | .text.__x86.get_pc_thunk.ax 120 | 0x0000000000000000 0x4 shell.o 121 | .text.__x86.get_pc_thunk.bx 122 | 0x0000000000000000 0x4 shell.o 123 | .group 0x0000000000000000 0x8 stdio.o 124 | .group 0x0000000000000000 0x8 stdio.o 125 | .group 0x0000000000000000 0x8 stdio.o 126 | .group 0x0000000000000000 0x8 stdio.o 127 | .text.__x86.get_pc_thunk.ax 128 | 0x0000000000000000 0x4 stdio.o 129 | .text.__x86.get_pc_thunk.dx 130 | 0x0000000000000000 0x4 stdio.o 131 | .text.__x86.get_pc_thunk.cx 132 | 0x0000000000000000 0x4 stdio.o 133 | .text.__x86.get_pc_thunk.bx 134 | 0x0000000000000000 0x4 stdio.o 135 | .group 0x0000000000000000 0x8 syscall.o 136 | .text.__x86.get_pc_thunk.bx 137 | 0x0000000000000000 0x4 syscall.o 138 | .group 0x0000000000000000 0x8 tasking.o 139 | .group 0x0000000000000000 0x8 tasking.o 140 | .group 0x0000000000000000 0x8 tasking.o 141 | .text.__x86.get_pc_thunk.ax 142 | 0x0000000000000000 0x4 tasking.o 143 | .text.__x86.get_pc_thunk.dx 144 | 0x0000000000000000 0x4 tasking.o 145 | .text.__x86.get_pc_thunk.bx 146 | 0x0000000000000000 0x4 tasking.o 147 | 148 | Memory Configuration 149 | 150 | Name Origin Length Attributes 151 | *default* 0x0000000000000000 0xffffffffffffffff 152 | 153 | Linker script and memory map 154 | 155 | LOAD ata.o 156 | LOAD common.o 157 | LOAD ehci.o 158 | LOAD elf.o 159 | LOAD ext2.o 160 | LOAD fat32.o 161 | LOAD gdt.o 162 | LOAD heap.o 163 | LOAD idt.o 164 | LOAD irq.o 165 | LOAD isr.o 166 | LOAD keyboard.o 167 | LOAD kmain.o 168 | LOAD paging.o 169 | LOAD pci.o 170 | LOAD pit.o 171 | LOAD shell.o 172 | LOAD startup.o 173 | LOAD stdio.o 174 | LOAD syscall.o 175 | LOAD tasking.o 176 | LOAD tss.o 177 | LOAD vfs.o 178 | 0x00000000c0100000 . = 0xc0100000 179 | 0x00000000c0100000 krnlstart = . 180 | 181 | .text 0x00000000c0100000 0x747e load address 0x0000000000100000 182 | *(.text) 183 | .text 0x00000000c0100000 0x225 ata.o 184 | 0x00000000c0100000 prepareDisk 185 | 0x00000000c01000de readSector 186 | 0x00000000c010015c readSectors 187 | 0x00000000c01001a9 getFirstPartition 188 | 0x00000000c0100215 getFSType 189 | .text 0x00000000c0100225 0x8df common.o 190 | 0x00000000c0100225 outb 191 | 0x00000000c010024e outw 192 | 0x00000000c0100279 outl 193 | 0x00000000c010029b inb 194 | 0x00000000c01002c2 inw 195 | 0x00000000c01002eb inl 196 | 0x00000000c0100311 sgn 197 | 0x00000000c0100332 abs 198 | 0x00000000c0100361 memset 199 | 0x00000000c010039d memcpy 200 | 0x00000000c01003e1 numToHexString 201 | 0x00000000c0100433 nibbleToHexString 202 | 0x00000000c010046b itoa 203 | 0x00000000c0100642 isACharacter 204 | 0x00000000c0100672 strlen 205 | 0x00000000c01006a4 strcmp 206 | 0x00000000c0100735 indexOf 207 | 0x00000000c0100789 indexOfn 208 | 0x00000000c01007f0 substr 209 | 0x00000000c010081d substri 210 | 0x00000000c0100850 substrr 211 | 0x00000000c010088d strcpy 212 | 0x00000000c01008cc countOf 213 | 0x00000000c010091f contains 214 | 0x00000000c01009bf strToInt 215 | 0x00000000c0100a22 cli 216 | 0x00000000c0100a33 sti 217 | 0x00000000c0100a44 toUpper 218 | 0x00000000c0100a8d strcat 219 | .text 0x00000000c0100b04 0x130 ehci.o 220 | 0x00000000c0100b04 getFirstEHCIController 221 | 0x00000000c0100b4e EHCIDebug 222 | .text 0x00000000c0100c34 0x0 elf.o 223 | .text 0x00000000c0100c34 0xddb ext2.o 224 | 0x00000000c0100c34 isPartitionExt2 225 | 0x00000000c0100c78 ext2_probe 226 | 0x00000000c0100cda getExt2Superblock 227 | 0x00000000c0100d28 initExt2Partition 228 | 0x00000000c0100ea5 ext2_getBlockGroupOfInode 229 | 0x00000000c0100edb ext2_getIndexOfInode 230 | 0x00000000c0100f13 ext2_getBlockOfInode 231 | 0x00000000c0100f6d ext2_readInode 232 | 0x00000000c0101072 ext2_listDirectory 233 | 0x00000000c0101196 ext2_listDirectoryEntries 234 | 0x00000000c010128f ext2_findFile 235 | 0x00000000c0101513 ext2_getFile 236 | 0x00000000c01015da ext2_readFile 237 | 0x00000000c0101768 ext2_read_slink 238 | 0x00000000c0101834 ext2_read_dlink 239 | 0x00000000c010190c ext2_getSuperblock 240 | 0x00000000c0101921 ext2_getBlockSize 241 | 0x00000000c0101936 ext2_readBlock 242 | 0x00000000c0101983 ext2_allocBlock 243 | 0x00000000c01019b1 ext2_freeBlock 244 | 0x00000000c01019e3 ext2_blockToSector 245 | .text 0x00000000c0101a0f 0x1cf3 fat32.o 246 | 0x00000000c0101a0f isPartitionFAT32 247 | 0x00000000c0101a86 getFat32Part 248 | 0x00000000c0101ce8 listDir 249 | 0x00000000c01023c3 listCurrentDir 250 | 0x00000000c01023ee changeDir 251 | 0x00000000c01028ab getFile 252 | 0x00000000c0103095 isDirectory 253 | 0x00000000c01030ab exists 254 | 0x00000000c01030c3 getClusterChainSize 255 | 0x00000000c01031cd getNextCluster 256 | 0x00000000c0103299 printFileContents 257 | 0x00000000c01033e9 getCurrentFat32Part 258 | 0x00000000c0103441 executeFile 259 | 0x00000000c01035a0 printCurrentDir 260 | 0x00000000c01035ec getFATSectorForCluster 261 | 0x00000000c010360f getClusterOfEntry 262 | 0x00000000c010365d setCurrentFat32part 263 | 0x00000000c01036ae clusterToLBA 264 | 0x00000000c01036de clusterToLBAOther 265 | .text 0x00000000c0103702 0x152 gdt.o 266 | 0x00000000c0103702 gdt_set_gate 267 | 0x00000000c010379d load_gdt 268 | .text 0x00000000c0103854 0x617 heap.o 269 | 0x00000000c0103854 init_heap 270 | 0x00000000c010388b first_available_frame 271 | 0x00000000c0103961 first_available_frameset 272 | 0x00000000c0103ac4 fsalloc 273 | 0x00000000c0103ba8 getFrame 274 | 0x00000000c0103beb falloc 275 | 0x00000000c0103c96 ffree 276 | 0x00000000c0103cd9 kmalloc 277 | 0x00000000c0103d3e kfree 278 | 0x00000000c0103de7 String 279 | 0x00000000c0103e32 strfree 280 | .text 0x00000000c0103e6b 0xdb idt.o 281 | 0x00000000c0103e6b idt_set_gate 282 | 0x00000000c0103ef4 register_idt 283 | .text 0x00000000c0103f46 0x300 irq.o 284 | 0x00000000c0103f46 irq_add_handler 285 | 0x00000000c0103f63 irq_remove_handler 286 | 0x00000000c0103f81 irq_remap 287 | 0x00000000c010403e irq_init 288 | 0x00000000c01041db irq_handler 289 | .text 0x00000000c0104246 0x599 isr.o 290 | 0x00000000c0104246 isr_init 291 | 0x00000000c010455e fpanic 292 | 0x00000000c01045b4 fault_handler 293 | 0x00000000c01046ed print_regs 294 | .text 0x00000000c01047df 0x240 keyboard.o 295 | 0x00000000c01047df keyboard_handler 296 | 0x00000000c01049c1 getInput 297 | .text 0x00000000c0104a1f 0x361 kmain.o 298 | 0x00000000c0104a1f kmain 299 | 0x00000000c0104c3d kmain_late 300 | 0x00000000c0104cac parse_mboot 301 | 0x00000000c0104cfe interrupts_init 302 | .text 0x00000000c0104d80 0x1ff paging.o 303 | 0x00000000c0104d80 setupPaging 304 | 0x00000000c0104e1d exec 305 | 0x00000000c0104ea3 pageFaultHandler 306 | .text 0x00000000c0104f7f 0x63f pci.o 307 | 0x00000000c0104f7f PCIReadWord 308 | 0x00000000c010503a getPCIVendor 309 | 0x00000000c01050a0 getPCIDevice 310 | 0x00000000c01051da PCIDebug 311 | 0x00000000c0105373 printPCIClassCode 312 | .text 0x00000000c01055be 0x110 pit.o 313 | 0x00000000c01055be pit_handler 314 | 0x00000000c0105649 pit_init 315 | .text 0x00000000c01056ce 0x9a5 shell.o 316 | 0x00000000c01056ce initShell 317 | 0x00000000c010572e dummy 318 | 0x00000000c010573d shell 319 | 0x00000000c010587c progx 320 | 0x00000000c01058a7 findAndExecute 321 | *fill* 0x00000000c0106073 0xd 322 | .text 0x00000000c0106080 0x262 startup.o 323 | 0x00000000c0106098 start 324 | 0x00000000c01060e7 gdt_flush 325 | 0x00000000c0106105 syscall_handler 326 | 0x00000000c010610f idt_load 327 | 0x00000000c0106117 isr0 328 | 0x00000000c010611f isr1 329 | 0x00000000c0106127 isr2 330 | 0x00000000c010612f isr3 331 | 0x00000000c0106137 isr4 332 | 0x00000000c010613f isr5 333 | 0x00000000c0106147 isr6 334 | 0x00000000c010614f isr7 335 | 0x00000000c0106157 isr8 336 | 0x00000000c010615f isr9 337 | 0x00000000c0106167 isr10 338 | 0x00000000c010616f isr11 339 | 0x00000000c0106174 isr12 340 | 0x00000000c0106179 isr13 341 | 0x00000000c010617e isr14 342 | 0x00000000c0106183 isr15 343 | 0x00000000c0106188 isr16 344 | 0x00000000c010618d isr17 345 | 0x00000000c0106192 isr18 346 | 0x00000000c0106197 isr19 347 | 0x00000000c010619e isr20 348 | 0x00000000c01061a5 isr21 349 | 0x00000000c01061ac isr22 350 | 0x00000000c01061b3 isr23 351 | 0x00000000c01061ba isr24 352 | 0x00000000c01061c1 isr25 353 | 0x00000000c01061c8 isr26 354 | 0x00000000c01061cf isr27 355 | 0x00000000c01061d6 isr28 356 | 0x00000000c01061dd isr29 357 | 0x00000000c01061e4 isr30 358 | 0x00000000c01061eb isr31 359 | 0x00000000c010621b irq0 360 | 0x00000000c0106234 irq1 361 | 0x00000000c010623b irq2 362 | 0x00000000c0106242 irq3 363 | 0x00000000c0106249 irq4 364 | 0x00000000c0106250 irq5 365 | 0x00000000c0106257 irq6 366 | 0x00000000c010625e irq7 367 | 0x00000000c0106265 irq8 368 | 0x00000000c010626c irq9 369 | 0x00000000c0106273 irq10 370 | 0x00000000c010627a irq11 371 | 0x00000000c0106281 irq12 372 | 0x00000000c0106288 irq13 373 | 0x00000000c010628f irq14 374 | 0x00000000c0106296 irq15 375 | 0x00000000c01062c6 _iret 376 | 0x00000000c01062c7 load_page_dir 377 | .text 0x00000000c01062e2 0xacc stdio.o 378 | 0x00000000c01062e2 putch 379 | 0x00000000c0106323 print_color 380 | 0x00000000c0106377 print 381 | 0x00000000c01063a3 println_color 382 | 0x00000000c01063eb println 383 | 0x00000000c0106417 setColor 384 | 0x00000000c010643a center_print_base 385 | 0x00000000c01065a9 printHex 386 | 0x00000000c0106603 printHexw 387 | 0x00000000c0106689 printHexl 388 | 0x00000000c0106751 printNum 389 | 0x00000000c010678d printf 390 | 0x00000000c0106980 backspace 391 | 0x00000000c01069d2 PANIC 392 | 0x00000000c0106a41 putch_color 393 | 0x00000000c0106b5c clearScreen 394 | 0x00000000c0106bd0 setAllColor 395 | 0x00000000c0106c49 center_print 396 | 0x00000000c0106c77 update_cursor 397 | 0x00000000c0106d07 scroll 398 | .text 0x00000000c0106dae 0x98 syscall.o 399 | 0x00000000c0106dae syscallHandler 400 | .text 0x00000000c0106e46 0x638 tasking.o 401 | 0x00000000c0106e46 kthread 402 | 0x00000000c0106e67 createProcess 403 | 0x00000000c0106fef getProcess 404 | 0x00000000c0107037 printTasks 405 | 0x00000000c01070c5 __init__ 406 | 0x00000000c01070fc preempt_now 407 | 0x00000000c010711b __kill__ 408 | 0x00000000c01071ea __notify__ 409 | 0x00000000c010723d initTasking 410 | 0x00000000c01072ce getCurrentProcess 411 | 0x00000000c01072e5 addProcess 412 | 0x00000000c0107351 notify 413 | 0x00000000c010737a kill 414 | 0x00000000c0107402 preempt 415 | .text 0x00000000c010747e 0x0 tss.o 416 | .text 0x00000000c010747e 0x0 vfs.o 417 | 418 | .text.__x86.get_pc_thunk.ax 419 | 0x00000000c010747e 0x4 load address 0x000000000010747e 420 | .text.__x86.get_pc_thunk.ax 421 | 0x00000000c010747e 0x4 ata.o 422 | 0x00000000c010747e __x86.get_pc_thunk.ax 423 | 424 | .text.__x86.get_pc_thunk.bx 425 | 0x00000000c0107482 0x4 load address 0x0000000000107482 426 | .text.__x86.get_pc_thunk.bx 427 | 0x00000000c0107482 0x4 ata.o 428 | 0x00000000c0107482 __x86.get_pc_thunk.bx 429 | 430 | .iplt 0x00000000c0107488 0x0 load address 0x0000000000107488 431 | .iplt 0x00000000c0107488 0x0 ata.o 432 | 433 | .text.__x86.get_pc_thunk.dx 434 | 0x00000000c0107486 0x4 load address 0x0000000000107486 435 | .text.__x86.get_pc_thunk.dx 436 | 0x00000000c0107486 0x4 fat32.o 437 | 0x00000000c0107486 __x86.get_pc_thunk.dx 438 | 439 | .text.__x86.get_pc_thunk.si 440 | 0x00000000c010748a 0x4 load address 0x000000000010748a 441 | .text.__x86.get_pc_thunk.si 442 | 0x00000000c010748a 0x4 heap.o 443 | 0x00000000c010748a __x86.get_pc_thunk.si 444 | 445 | .text.__x86.get_pc_thunk.cx 446 | 0x00000000c010748e 0x4 load address 0x000000000010748e 447 | .text.__x86.get_pc_thunk.cx 448 | 0x00000000c010748e 0x4 pit.o 449 | 0x00000000c010748e __x86.get_pc_thunk.cx 450 | 451 | .eh_frame 0x00000000c0107494 0x164c load address 0x0000000000107494 452 | .eh_frame 0x00000000c0107494 0xec ata.o 453 | .eh_frame 0x00000000c0107580 0x3a4 common.o 454 | 0x3d0 (size before relaxing) 455 | .eh_frame 0x00000000c0107924 0x48 ehci.o 456 | 0x88 (size before relaxing) 457 | .eh_frame 0x00000000c010796c 0x2fc ext2.o 458 | 0x33c (size before relaxing) 459 | .eh_frame 0x00000000c0107c68 0x304 fat32.o 460 | 0x344 (size before relaxing) 461 | .eh_frame 0x00000000c0107f6c 0x48 gdt.o 462 | 0x88 (size before relaxing) 463 | .eh_frame 0x00000000c0107fb4 0x1ac heap.o 464 | 0x1ec (size before relaxing) 465 | .eh_frame 0x00000000c0108160 0x48 idt.o 466 | 0x88 (size before relaxing) 467 | .eh_frame 0x00000000c01081a8 0xac irq.o 468 | 0xec (size before relaxing) 469 | .eh_frame 0x00000000c0108254 0x98 isr.o 470 | 0xc4 (size before relaxing) 471 | .eh_frame 0x00000000c01082ec 0x44 keyboard.o 472 | 0x84 (size before relaxing) 473 | .eh_frame 0x00000000c0108330 0x90 kmain.o 474 | 0xd0 (size before relaxing) 475 | .eh_frame 0x00000000c01083c0 0x64 paging.o 476 | 0xa4 (size before relaxing) 477 | .eh_frame 0x00000000c0108424 0xb4 pci.o 478 | 0xf4 (size before relaxing) 479 | .eh_frame 0x00000000c01084d8 0x80 pit.o 480 | 0xc0 (size before relaxing) 481 | .eh_frame 0x00000000c0108558 0xd8 shell.o 482 | 0x118 (size before relaxing) 483 | .eh_frame 0x00000000c0108630 0x2b4 stdio.o 484 | 0x31c (size before relaxing) 485 | .eh_frame 0x00000000c01088e4 0x24 syscall.o 486 | 0x50 (size before relaxing) 487 | .eh_frame 0x00000000c0108908 0x1d8 tasking.o 488 | 0x22c (size before relaxing) 489 | 490 | .rodata 0x00000000c0108ae0 0xc66 load address 0x0000000000108ae0 491 | .rodata 0x00000000c0108ae0 0x7a ehci.o 492 | *fill* 0x00000000c0108b5a 0x2 493 | .rodata 0x00000000c0108b5c 0x5a ext2.o 494 | *fill* 0x00000000c0108bb6 0x2 495 | .rodata 0x00000000c0108bb8 0x6a fat32.o 496 | *fill* 0x00000000c0108c22 0x2 497 | .rodata 0x00000000c0108c24 0x93 heap.o 498 | *fill* 0x00000000c0108cb7 0x1 499 | .rodata 0x00000000c0108cb8 0x144 isr.o 500 | .rodata 0x00000000c0108dfc 0x16c kmain.o 501 | .rodata 0x00000000c0108f68 0x94 paging.o 502 | .rodata 0x00000000c0108ffc 0x230 pci.o 503 | .rodata 0x00000000c010922c 0x3b9 shell.o 504 | *fill* 0x00000000c01095e5 0x3 505 | .rodata 0x00000000c01095e8 0x75 stdio.o 506 | .rodata 0x00000000c010965d 0x10 syscall.o 507 | *fill* 0x00000000c010966d 0x3 508 | .rodata 0x00000000c0109670 0xd6 tasking.o 509 | 510 | .rel.dyn 0x00000000c0109748 0x0 load address 0x0000000000109748 511 | .rel.got 0x00000000c0109748 0x0 ata.o 512 | .rel.iplt 0x00000000c0109748 0x0 ata.o 513 | .rel.text 0x00000000c0109748 0x0 ata.o 514 | .rel.data.rel 0x00000000c0109748 0x0 ata.o 515 | 516 | .data 0x00000000c010a000 0x2058 load address 0x000000000010a000 517 | *(.data) 518 | .data 0x00000000c010a000 0x0 ata.o 519 | .data 0x00000000c010a000 0x0 common.o 520 | .data 0x00000000c010a000 0x0 ehci.o 521 | .data 0x00000000c010a000 0x0 elf.o 522 | .data 0x00000000c010a000 0x0 ext2.o 523 | .data 0x00000000c010a000 0x0 fat32.o 524 | .data 0x00000000c010a000 0x0 gdt.o 525 | .data 0x00000000c010a000 0x0 heap.o 526 | .data 0x00000000c010a000 0x0 idt.o 527 | .data 0x00000000c010a000 0x0 irq.o 528 | .data 0x00000000c010a000 0x0 isr.o 529 | .data 0x00000000c010a000 0x100 keyboard.o 530 | 0x00000000c010a000 kbdus 531 | .data 0x00000000c010a100 0x0 kmain.o 532 | .data 0x00000000c010a100 0x0 paging.o 533 | .data 0x00000000c010a100 0x0 pci.o 534 | .data 0x00000000c010a100 0x0 pit.o 535 | .data 0x00000000c010a100 0x0 shell.o 536 | *fill* 0x00000000c010a100 0xf00 537 | .data 0x00000000c010b000 0x104e startup.o 538 | 0x00000000c010b000 BootPageDirectory 539 | *fill* 0x00000000c010c04e 0x2 540 | .data 0x00000000c010c050 0x8 stdio.o 541 | 0x00000000c010c050 ccolor 542 | 0x00000000c010c054 vidmem 543 | .data 0x00000000c010c058 0x0 syscall.o 544 | .data 0x00000000c010c058 0x0 tasking.o 545 | .data 0x00000000c010c058 0x0 tss.o 546 | .data 0x00000000c010c058 0x0 vfs.o 547 | 548 | .got 0x00000000c010c058 0x0 load address 0x000000000010c058 549 | .got 0x00000000c010c058 0x0 ata.o 550 | 551 | .got.plt 0x00000000c010c058 0xc load address 0x000000000010c058 552 | .got.plt 0x00000000c010c058 0xc ata.o 553 | 0x00000000c010c058 _GLOBAL_OFFSET_TABLE_ 554 | 555 | .igot.plt 0x00000000c010c064 0x0 load address 0x000000000010c064 556 | .igot.plt 0x00000000c010c064 0x0 ata.o 557 | 558 | .data.rel.local 559 | 0x00000000c010c064 0x4 load address 0x000000000010c064 560 | .data.rel.local 561 | 0x00000000c010c064 0x4 fat32.o 562 | 0x00000000c010c064 fat32sig 563 | 564 | .data.rel 0x00000000c010c068 0x8 load address 0x000000000010c068 565 | .data.rel 0x00000000c010c068 0x8 fat32.o 566 | 0x00000000c010c068 buf 567 | 0x00000000c010c06c buf2 568 | 569 | .bss 0x00000000c010d000 0x10b6cd load address 0x000000000010d000 570 | *(COMMON) 571 | COMMON 0x00000000c010d000 0x400 ata.o 572 | 0x00000000c010d000 ata_buf2 573 | 0x00000000c010d200 ata_buf 574 | *fill* 0x00000000c010d400 0xc00 575 | COMMON 0x00000000c010e000 0x1028 fat32.o 576 | 0x00000000c010e000 prog 577 | 0x00000000c010f000 currentfat32part 578 | *fill* 0x00000000c010f028 0x18 579 | COMMON 0x00000000c010f040 0x48 gdt.o 580 | 0x00000000c010f040 gp 581 | 0x00000000c010f060 gdt 582 | *fill* 0x00000000c010f088 0x18 583 | COMMON 0x00000000c010f0a0 0x102020 heap.o 584 | 0x00000000c010f0a0 heap_space 585 | 0x00000000c020f0a0 frbuf 586 | 0x00000000c020f0ac kfreebuf 587 | 0x00000000c020f0b0 frsbuf 588 | 0x00000000c020f0c0 frames 589 | COMMON 0x00000000c02110c0 0x820 idt.o 590 | 0x00000000c02110c0 idtp 591 | 0x00000000c02110e0 idt 592 | COMMON 0x00000000c02118e0 0x101 keyboard.o 593 | 0x00000000c02118e0 kbdbuf 594 | 0x00000000c02119e0 input_i 595 | *fill* 0x00000000c02119e1 0x3 596 | COMMON 0x00000000c02119e4 0x9 kmain.o 597 | 0x00000000c02119e4 tss_high 598 | 0x00000000c02119e8 i 599 | 0x00000000c02119ec tss_low 600 | *fill* 0x00000000c02119ed 0x613 601 | COMMON 0x00000000c0212000 0x2000 paging.o 602 | 0x00000000c0212000 exec_page_table 603 | 0x00000000c0213000 page_directory 604 | COMMON 0x00000000c0214000 0x600 shell.o 605 | 0x00000000c0214000 cmdbuf 606 | 0x00000000c0214100 dirbuf2 607 | 0x00000000c0214300 argbuf 608 | 0x00000000c0214400 dirbuf 609 | COMMON 0x00000000c0214600 0x8 tasking.o 610 | 0x00000000c0214600 kernel_proc 611 | 0x00000000c0214604 current_proc 612 | *(.bss) 613 | .bss 0x00000000c0214608 0x1 ata.o 614 | 0x00000000c0214608 boot_disk 615 | .bss 0x00000000c0214609 0x0 common.o 616 | .bss 0x00000000c0214609 0x0 ehci.o 617 | .bss 0x00000000c0214609 0x0 elf.o 618 | .bss 0x00000000c0214609 0x0 ext2.o 619 | *fill* 0x00000000c0214609 0x3 620 | .bss 0x00000000c021460c 0x4 fat32.o 621 | 0x00000000c021460c cdir 622 | .bss 0x00000000c0214610 0x0 gdt.o 623 | .bss 0x00000000c0214610 0x0 heap.o 624 | .bss 0x00000000c0214610 0x0 idt.o 625 | *fill* 0x00000000c0214610 0x10 626 | .bss 0x00000000c0214620 0x40 irq.o 627 | 0x00000000c0214620 irq_routines 628 | .bss 0x00000000c0214660 0x0 isr.o 629 | .bss 0x00000000c0214660 0x4 keyboard.o 630 | 0x00000000c0214660 shift 631 | 0x00000000c0214661 input_mode 632 | 0x00000000c0214662 input_done 633 | 0x00000000c0214663 shell_mode 634 | .bss 0x00000000c0214664 0x1c kmain.o 635 | 0x00000000c0214664 fs 636 | .bss 0x00000000c0214680 0x0 paging.o 637 | .bss 0x00000000c0214680 0x0 pci.o 638 | .bss 0x00000000c0214680 0x0 pit.o 639 | .bss 0x00000000c0214680 0x24 shell.o 640 | 0x00000000c0214680 exitShell 641 | 0x00000000c0214684 currentDir 642 | 0x00000000c0214694 fileBuf 643 | *fill* 0x00000000c02146a4 0x1c 644 | .bss 0x00000000c02146c0 0x4000 startup.o 645 | .bss 0x00000000c02186c0 0x8 stdio.o 646 | 0x00000000c02186c0 xpos 647 | 0x00000000c02186c4 ypos 648 | .bss 0x00000000c02186c8 0x0 syscall.o 649 | .bss 0x00000000c02186c8 0x5 tasking.o 650 | 0x00000000c02186c8 __cpid__ 651 | 0x00000000c02186cc tasking_enabled 652 | .bss 0x00000000c02186cd 0x0 tss.o 653 | .bss 0x00000000c02186cd 0x0 vfs.o 654 | 0x00000000c02186cd krnlend = . 655 | OUTPUT(out/disk/boot/codek32 elf32-i386) 656 | 657 | .comment 0x0000000000000000 0x24 658 | .comment 0x0000000000000000 0x24 ata.o 659 | 0x25 (size before relaxing) 660 | .comment 0x0000000000000024 0x25 common.o 661 | .comment 0x0000000000000024 0x25 ehci.o 662 | .comment 0x0000000000000024 0x25 elf.o 663 | .comment 0x0000000000000024 0x25 ext2.o 664 | .comment 0x0000000000000024 0x25 fat32.o 665 | .comment 0x0000000000000024 0x25 gdt.o 666 | .comment 0x0000000000000024 0x25 heap.o 667 | .comment 0x0000000000000024 0x25 idt.o 668 | .comment 0x0000000000000024 0x25 irq.o 669 | .comment 0x0000000000000024 0x25 isr.o 670 | .comment 0x0000000000000024 0x25 keyboard.o 671 | .comment 0x0000000000000024 0x25 kmain.o 672 | .comment 0x0000000000000024 0x25 paging.o 673 | .comment 0x0000000000000024 0x25 pci.o 674 | .comment 0x0000000000000024 0x25 pit.o 675 | .comment 0x0000000000000024 0x25 shell.o 676 | .comment 0x0000000000000024 0x25 stdio.o 677 | .comment 0x0000000000000024 0x25 syscall.o 678 | .comment 0x0000000000000024 0x25 tasking.o 679 | .comment 0x0000000000000024 0x25 tss.o 680 | .comment 0x0000000000000024 0x25 vfs.o 681 | 682 | .note.GNU-stack 683 | 0x0000000000000000 0x0 684 | .note.GNU-stack 685 | 0x0000000000000000 0x0 ata.o 686 | .note.GNU-stack 687 | 0x0000000000000000 0x0 common.o 688 | .note.GNU-stack 689 | 0x0000000000000000 0x0 ehci.o 690 | .note.GNU-stack 691 | 0x0000000000000000 0x0 elf.o 692 | .note.GNU-stack 693 | 0x0000000000000000 0x0 ext2.o 694 | .note.GNU-stack 695 | 0x0000000000000000 0x0 fat32.o 696 | .note.GNU-stack 697 | 0x0000000000000000 0x0 gdt.o 698 | .note.GNU-stack 699 | 0x0000000000000000 0x0 heap.o 700 | .note.GNU-stack 701 | 0x0000000000000000 0x0 idt.o 702 | .note.GNU-stack 703 | 0x0000000000000000 0x0 irq.o 704 | .note.GNU-stack 705 | 0x0000000000000000 0x0 isr.o 706 | .note.GNU-stack 707 | 0x0000000000000000 0x0 keyboard.o 708 | .note.GNU-stack 709 | 0x0000000000000000 0x0 kmain.o 710 | .note.GNU-stack 711 | 0x0000000000000000 0x0 paging.o 712 | .note.GNU-stack 713 | 0x0000000000000000 0x0 pci.o 714 | .note.GNU-stack 715 | 0x0000000000000000 0x0 pit.o 716 | .note.GNU-stack 717 | 0x0000000000000000 0x0 shell.o 718 | .note.GNU-stack 719 | 0x0000000000000000 0x0 stdio.o 720 | .note.GNU-stack 721 | 0x0000000000000000 0x0 syscall.o 722 | .note.GNU-stack 723 | 0x0000000000000000 0x0 tasking.o 724 | .note.GNU-stack 725 | 0x0000000000000000 0x0 tss.o 726 | .note.GNU-stack 727 | 0x0000000000000000 0x0 vfs.o 728 | -------------------------------------------------------------------------------- /libc/crt0.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/libc/crt0.o -------------------------------------------------------------------------------- /libc/crt0.s: -------------------------------------------------------------------------------- 1 | .section .text 2 | .global _start 3 | _start: 4 | call main 5 | ret -------------------------------------------------------------------------------- /libc/stdio.c: -------------------------------------------------------------------------------- 1 | void putchar(int c){ 2 | asm volatile("int $0x80" : : "a"(0), "b"(c)); 3 | } 4 | 5 | void printf(char* c){ 6 | int i = 0; 7 | while(c[i] != 0){ 8 | putchar(c[i]); 9 | i++; 10 | } 11 | } 12 | 13 | void syscall(unsigned int callid){ 14 | asm volatile("int $0x80" : : "a"(callid)); 15 | } -------------------------------------------------------------------------------- /libc/stdio.h: -------------------------------------------------------------------------------- 1 | void putchar(int c); 2 | void printf(char* c); 3 | void syscall(unsigned int callid); 4 | 5 | #include "stdio.c" -------------------------------------------------------------------------------- /linker.ld: -------------------------------------------------------------------------------- 1 | ENTRY(start) 2 | 3 | SECTIONS { 4 | . = 0xC0100000; 5 | 6 | krnlstart = .; 7 | 8 | .text : AT(ADDR(.text) - 0xC0000000) 9 | { 10 | *(.text) 11 | } 12 | 13 | .data : AT(ADDR(.data) - 0xC0000000) 14 | { 15 | *(.data) 16 | } 17 | 18 | .bss : AT(ADDR(.bss) - 0xC0000000) 19 | { 20 | *(COMMON) 21 | *(.bss) 22 | } 23 | 24 | krnlend = .; 25 | } -------------------------------------------------------------------------------- /logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/logo.bmp -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | SRCS = $(wildcard src/kernel/*.c) 2 | CFILES = $(patsubst %.c,%.o,$(SRCS)) 3 | INC = -Isrc/include/kernel 4 | CFLAGS = -ffreestanding -std=gnu99 -Woverflow -m32 5 | FLAGS = 6 | CC = gcc 7 | LD = ld 8 | 9 | codeos2: $(CFILES) 10 | mv src/kernel/*.o . 11 | nasm asm/startup.asm -f elf -o startup.o 12 | ld -o out/disk/boot/codek32 *.o -T linker.ld -melf_i386 -Map kernel.map 13 | rm *.o 14 | ./copy.sh 15 | 16 | %.o: %.c 17 | $(CC) $(FLAGS) $(INC) $(CFLAGS) -c -o $@ $< 18 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | qemu-system-x86_64 -drive file=codeos2.img,cache=directsync,format=raw 3 | -------------------------------------------------------------------------------- /src/include/kernel/ata.h: -------------------------------------------------------------------------------- 1 | #ifndef ATA_H 2 | #define ATA_H 3 | 4 | void readSector(int disk, int address, uint8_t *sect); 5 | void prepareDisk(int disk, int address); 6 | void readSectors(int disk, int address, int sectors, uint8_t *sect); 7 | int getFSType(int disk); 8 | int getFirstPartition(int disk); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/include/kernel/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #define HIGHER_HALF 0xC0000000 5 | #define true 1 6 | #define false 0 7 | #define NULL ( (void *) 0) 8 | 9 | #define __va_argsiz(t) \ 10 | (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) 11 | 12 | 13 | #define va_start(ap, pN) \ 14 | ((ap) = ((va_list) __builtin_next_arg(pN))) 15 | 16 | 17 | 18 | #define va_end(ap) ((void)0) 19 | 20 | #define va_arg(ap, t) \ 21 | (((ap) = (ap) + __va_argsiz(t)), \ 22 | *((t*) (void*) ((ap) - __va_argsiz(t)))) 23 | 24 | typedef char* va_list; 25 | typedef unsigned int uint32_t; 26 | typedef signed int int32_t; 27 | typedef unsigned short uint16_t; 28 | typedef signed short int16_t; 29 | typedef unsigned char uint8_t; 30 | typedef signed char int8_t; 31 | typedef unsigned long long int uint64_t; 32 | typedef signed long long int int64_t; 33 | typedef char *string; 34 | typedef unsigned char bool; 35 | typedef int int32_t; 36 | typedef uint32_t size_t; 37 | typedef unsigned int uint; 38 | 39 | extern uint32_t krnlstart; 40 | extern uint32_t krnlend; 41 | 42 | struct __attribute__((packed)) registers{ 43 | unsigned int gs, fs, es, ds; 44 | unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; 45 | unsigned int num, err_code; 46 | unsigned int eip, cs, eflags, useresp, ss; 47 | }; 48 | 49 | void outb(uint16_t port, uint8_t value); 50 | void outw(uint16_t port, uint16_t value); 51 | void outl(uint16_t port, uint32_t value); 52 | uint8_t inb(uint16_t port); 53 | uint16_t inw(uint16_t port); 54 | uint32_t inl(uint16_t port); 55 | int sgn(int x); 56 | int abs(float x); 57 | void *memset(void *dest, char val, int count); 58 | void *memcpy(void *dest, const void *src, size_t count); 59 | void numToHexString(uint8_t num, char *str); 60 | char nibbleToHexString(uint8_t num); 61 | char *itoa(int i, char *p, int base); 62 | bool isACharacter(uint8_t num); 63 | int strlen(const char *str); 64 | bool strcmp(char *str1, char *str2); 65 | int indexOf(char c, char *str); 66 | int indexOfn(char c, int n, char *str); 67 | void substr(int i, char *src, char *dest); 68 | void substri(int i, char *src, char *dest); 69 | void substrr(int s, int e, char *src, char *dest); 70 | void strcpy(char *src, char *dest); 71 | int countOf(char c, char *str); 72 | bool contains(char *str, char *cont); 73 | void cli(); 74 | void sti(); 75 | int strToInt(char *str); 76 | void toUpper(char *str); 77 | char *strcat(char *dest, const char *src); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/include/kernel/ehci.h: -------------------------------------------------------------------------------- 1 | #ifndef EHCI_H 2 | #define EHCI_H 3 | 4 | typedef struct EHCIController{ 5 | PCIDevice pciDevice; 6 | uint8_t flags; 7 | } EHCIController; 8 | 9 | EHCIController getFirstEHCIController(); 10 | void EHCIDebug(); 11 | 12 | #endif -------------------------------------------------------------------------------- /src/include/kernel/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef ELF_H 2 | #define ELF_H 3 | 4 | #include 5 | 6 | typedef struct elf_header{ 7 | unsigned char e_ident[16]; 8 | uint16_t type; 9 | uint16_t machine; 10 | uint32_t version; 11 | uint32_t entry; 12 | uint32_t phoff; 13 | uint32_t shoff; 14 | uint32_t flags; 15 | uint16_t ehsize; 16 | uint16_t phentsize; 17 | uint16_t phnum; 18 | uint16_t shentsize; 19 | uint16_t shnum; 20 | uint16_t shstrndx; 21 | } elf_header; 22 | 23 | typedef struct elf_section_header{ 24 | uint32_t name; 25 | uint32_t type; 26 | uint32_t flags; 27 | uint32_t addr; 28 | uint32_t offset; 29 | uint32_t size; 30 | uint32_t link; 31 | uint32_t info; 32 | uint32_t addralign; 33 | uint32_t entsize; 34 | } elf_section_header; 35 | 36 | typedef struct elf_program_header{ 37 | uint32_t type; 38 | uint32_t offset; 39 | uint32_t vaddr; 40 | uint32_t paddr; 41 | uint32_t filesz; 42 | uint32_t memsz; 43 | uint32_t flags; 44 | uint32_t align; 45 | } elf_program_header; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/include/kernel/ext2.h: -------------------------------------------------------------------------------- 1 | #ifndef EXT2_H 2 | #define EXT2_H 3 | 4 | #include 5 | 6 | //inode constants 7 | #define ROOT_INODE 2 8 | #define EXT2_SIGNATURE 0x53EF 9 | 10 | //inode types 11 | #define EXT2_FIFO 0x1000 12 | #define EXT2_CHAR_DEVICE 0x2000 13 | #define EXT2_DIRECTORY 0x4000 14 | #define EXT2_BLOCK_DEVICE 0x6000 15 | #define EXT2_FILE 0x8000 16 | #define EXT2_SYMLINK 0xA000 17 | #define EXT2_SOCKET 0xC000 18 | 19 | //inode flags 20 | #define EXT2_SYNCHRONOUS 0x8 21 | #define EXT2_IMMUTABLE 0x10 22 | #define EXT2_APPEND_ONLY 0x20 23 | #define EXT2_DUMP_EXCLUDE 0x40 24 | #define EXT2_JOURNAL_FILE 0x40000 25 | 26 | typedef struct __attribute__((packed)) ext2_superblock{ 27 | uint32_t total_inodes; 28 | uint32_t total_blocks; 29 | uint32_t superuser_blocks; 30 | uint32_t unallocated_blocks; 31 | uint32_t unallocated_inodes; 32 | uint32_t superblock_block; 33 | uint32_t block_size; //do 1024 << block_size to get the block size 34 | uint32_t fragment_size; //Do 1024 << fragment_size to get the fragment size 35 | uint32_t blocks_per_group; 36 | uint32_t fragments_per_group; 37 | uint32_t inodes_per_group; 38 | uint32_t last_mount; 39 | uint32_t last_write; 40 | uint16_t times_mounted; //Since last fsck 41 | uint16_t mounts_allowed; //fsck must be done after this amount surpassed 42 | uint16_t signature; 43 | uint16_t state; 44 | uint16_t error_action; 45 | uint16_t version_minor; 46 | uint32_t last_check; //POSIX time of last fsck 47 | uint32_t check_interval; //POSIX time between fscks 48 | uint32_t os_id; 49 | uint32_t version_major; 50 | uint16_t reserved_user; 51 | uint16_t reserved_group; 52 | //Start extended fields 53 | uint32_t first_inode; 54 | uint16_t inode_size; 55 | uint16_t superblock_group; 56 | uint32_t optional_features; 57 | uint32_t required_features; 58 | uint32_t ro_features; 59 | uint8_t filesystem_id[16]; 60 | uint8_t volume_name[16]; 61 | uint8_t last_mount_path[64]; 62 | uint32_t compression; 63 | uint8_t file_prealloc_blocks; 64 | uint8_t directory_prealloc_blocks; 65 | uint16_t UNUSED_AARON_IS_THE_BEST; 66 | uint8_t journal_id[16]; 67 | uint32_t journal_inode; 68 | uint32_t journal_device; 69 | uint32_t orphan_inode_head; 70 | uint8_t extra[276]; 71 | } ext2_superblock; 72 | 73 | typedef struct __attribute__((packed)) ext2_partition{ 74 | uint32_t sector; 75 | uint8_t disk; 76 | uint32_t block_group_descriptor_table; 77 | uint32_t blocks_per_inode_table; 78 | uint32_t sectors_per_inode_table; 79 | uint32_t block_size; 80 | uint32_t sectors_per_block; 81 | uint32_t num_block_groups; 82 | uint32_t inodes_per_block; 83 | ext2_superblock *superblock; 84 | filesystem_t *filesystem; 85 | } ext2_partition; 86 | 87 | typedef struct __attribute__((packed)) ext2_block_group_descriptor{ 88 | uint32_t block_usage_bitmap; 89 | uint32_t inode_usage_bitmap; 90 | uint32_t inode_table; 91 | uint16_t unallocated_blocks; 92 | uint16_t allocated_blocks; 93 | uint16_t num_directories; 94 | uint8_t unused[14]; 95 | } ext2_block_group_descriptor; 96 | 97 | typedef struct __attribute__((packed)) ext2_inode{ 98 | uint16_t type; 99 | uint16_t user_id; 100 | uint32_t size_lower; 101 | uint32_t last_access_time; 102 | uint32_t creation_time; 103 | uint32_t last_modification_time; 104 | uint32_t deletion_time; 105 | uint16_t group_id; 106 | uint16_t hard_links; //Hard links to this node 107 | uint32_t sectors_in_use; //Hard disk sectors, not ext2 blocks. 108 | uint32_t flags; 109 | uint32_t os_specific_1; 110 | uint32_t block_pointers[12]; 111 | uint32_t s_pointer; 112 | uint32_t d_pointer; 113 | uint32_t t_pointer; 114 | uint32_t generation_number; 115 | uint32_t extended_attribute_block; 116 | uint32_t size_upper; 117 | uint32_t block_address; 118 | uint32_t os_specific_2[3]; 119 | } ext2_inode; 120 | 121 | typedef struct __attribute__((packed)) ext2_directory{ 122 | uint32_t inode; 123 | uint16_t size; 124 | uint8_t name_length; 125 | uint8_t type; 126 | } ext2_directory; 127 | 128 | bool isPartitionExt2(int disk, int sect); 129 | bool ext2_probe(filesystem_t *fs); 130 | void getExt2Superblock(int disk, int sect, ext2_superblock *sp); 131 | void initExt2Partition(int sect, device_t *device, ext2_superblock *sb, ext2_partition *part, filesystem_t *fs); 132 | uint32_t ext2_getBlockSize(ext2_partition *part); 133 | uint32_t ext2_getBlockGroupOfInode(uint32_t inode, ext2_partition *part); 134 | uint32_t ext2_getIndexOfInode(uint32_t inode, ext2_partition *part); 135 | uint32_t ext2_getBlockOfInode(uint32_t inode, ext2_partition *part); 136 | void ext2_readInode(uint32_t inode, ext2_inode *buf, ext2_partition *part); 137 | ext2_superblock *ext2_getSuperblock(ext2_partition *part); 138 | uint8_t *ext2_allocBlock(ext2_partition *part); 139 | void ext2_freeBlock(uint8_t *block, ext2_partition *part); 140 | bool ext2_getFile(char *fn, file_t *file, filesystem_t *fs); 141 | uint32_t ext2_blockToSector(uint32_t block, ext2_partition *part); 142 | uint8_t *ext2_readBlock(uint32_t block, uint8_t *buf, ext2_partition *part); 143 | void ext2_read_slink(uint32_t block, uint8_t *buf, ext2_partition *part); 144 | void ext2_read_dlink(uint32_t block, uint8_t *buf, ext2_partition *part); 145 | bool ext2_listDirectory(file_t *file, filesystem_t *fs); 146 | void ext2_listDirectoryEntries(ext2_directory *dir, ext2_partition *part); 147 | uint8_t ext2_readFile(file_t *file, uint8_t *buf, filesystem_t *fs); 148 | uint32_t ext2_findFile(char *name, uint32_t dir_inode, ext2_inode *inode, ext2_partition *part); 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /src/include/kernel/fat32.h: -------------------------------------------------------------------------------- 1 | #ifndef FAT32_H 2 | #define FAT32_H 3 | 4 | typedef struct fat32part{ 5 | uint8_t disk; 6 | uint16_t part_sect; 7 | uint8_t sectors_per_cluster; 8 | uint32_t root_dir_sect; 9 | uint32_t root_dir_clust; 10 | uint32_t cluster_begin_sect; 11 | uint8_t num_fats; 12 | uint32_t sectors_per_fat; 13 | uint16_t reserved_sectors; 14 | uint32_t fat_sect; 15 | uint32_t current_dir_clust; 16 | } fat32part; 17 | 18 | typedef struct fat32file{ 19 | uint32_t cluster; 20 | uint32_t size; 21 | uint32_t dir_cluster; 22 | uint8_t attrib; 23 | } fat32file; 24 | 25 | bool isPartitionFAT32(int disk, int sect); 26 | fat32part getFat32Part(int disk, int part_sect); 27 | uint32_t clusterToLBA(uint32_t cluster); 28 | uint32_t clusterToLBAOther(fat32part p, uint32_t cluster); 29 | void setCurrentFat32part(fat32part p); 30 | void listDir(uint32_t cluster, char *filter); 31 | void listCurrentDir(char *filter); 32 | uint8_t changeDir(char *dir); 33 | bool isDirectory(fat32file file); 34 | fat32file getFile(char *file); 35 | bool exists(fat32file file); 36 | static uint8_t changeOneDir(char *dir); 37 | uint32_t getClusterOfEntry(uint8_t *entry); 38 | uint32_t getClusterChainSize(uint32_t cluster); 39 | uint32_t getFATSectorForCluster(uint32_t cluster); 40 | uint32_t getNextCluster(uint32_t cluster); 41 | uint32_t getClusterOfFile(char *file); 42 | void printFileContents(fat32file f); 43 | void printCurrentDir(); 44 | void executeFile(fat32file f); 45 | fat32part getCurrentFat32Part(); 46 | 47 | #endif -------------------------------------------------------------------------------- /src/include/kernel/gdt.h: -------------------------------------------------------------------------------- 1 | #ifndef GDT_H 2 | #define GDT_H 3 | 4 | typedef struct GDTEntry{ 5 | uint16_t limit; 6 | uint16_t base_low; 7 | uint8_t base_middle; 8 | uint8_t access; 9 | uint8_t granularity; 10 | uint8_t base_high; 11 | } __attribute__((packed)) GDTEntry; 12 | 13 | typedef struct GDTPointer{ 14 | unsigned short limit; 15 | unsigned int base; 16 | } __attribute__((packed)) GDTPointer; 17 | 18 | void gdt_set_gate(uint32_t num, uint16_t limit, uint32_t base, uint8_t access, uint8_t gran); 19 | 20 | void load_gdt(); 21 | 22 | #endif -------------------------------------------------------------------------------- /src/include/kernel/heap.h: -------------------------------------------------------------------------------- 1 | #ifndef HEAP_H 2 | #define HEAP_H 3 | 4 | typedef struct Frame{ 5 | uint32_t num; //The number of the frame. 6 | uint32_t set; //The set the frame is in (There are 8 frames in a set) 7 | uint32_t pos; //Which number in the set it is. 8 | } Frame; 9 | 10 | typedef struct FrameSet{ 11 | Frame start; 12 | uint32_t len; 13 | } FrameSet; 14 | 15 | void init_heap(); 16 | Frame first_available_frame(); 17 | Frame falloc(); 18 | void ffree(Frame f); 19 | FrameSet first_available_frameset(uint32_t len); 20 | Frame getFrame(uint32_t i); 21 | FrameSet fsalloc(); 22 | void *kmalloc(uint32_t len); 23 | void kfree(void *ptr, uint32_t len); 24 | char *String(char *str); 25 | void strfree(char *str); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/include/kernel/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef IDT_H 2 | #define IDT_H 3 | 4 | struct IDTEntry{ 5 | unsigned short offset_low; //Offset bits 0-15 6 | unsigned short selector; //A code segment selector in the GDT 7 | unsigned char zero; //Always 0 8 | unsigned char attrs; //Type & Attributes 9 | unsigned short offset_high; //Offset bits 16-31 10 | }__attribute__((packed)); 11 | 12 | struct IDTPointer{ 13 | unsigned short size; 14 | unsigned int offset; 15 | }__attribute__((packed)); 16 | 17 | extern void idt_load(); 18 | 19 | void idt_set_gate(uint8_t num, uint32_t loc, uint16_t selector, uint8_t flags); 20 | void register_idt(); 21 | 22 | #endif -------------------------------------------------------------------------------- /src/include/kernel/irq.h: -------------------------------------------------------------------------------- 1 | #ifndef IRQ_H 2 | #define IRQ_H 3 | 4 | extern void irq0(); 5 | extern void irq1(); 6 | extern void irq2(); 7 | extern void irq3(); 8 | extern void irq4(); 9 | extern void irq5(); 10 | extern void irq6(); 11 | extern void irq7(); 12 | extern void irq8(); 13 | extern void irq9(); 14 | extern void irq10(); 15 | extern void irq11(); 16 | extern void irq12(); 17 | extern void irq13(); 18 | extern void irq14(); 19 | extern void irq15(); 20 | 21 | void irq_add_handler(int irq, void (*handler)(struct registers *r)); 22 | void irq_remove_handler(int irq); 23 | void irq_remap(void); 24 | void irq_init(); 25 | void irq_handler(struct registers *r); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/include/kernel/isr.h: -------------------------------------------------------------------------------- 1 | #ifndef ISR_H 2 | #define ISR_H 3 | 4 | extern void isr0(); 5 | extern void isr1(); 6 | extern void isr2(); 7 | extern void isr3(); 8 | extern void isr4(); 9 | extern void isr5(); 10 | extern void isr6(); 11 | extern void isr7(); 12 | extern void isr8(); 13 | extern void isr9(); 14 | extern void isr10(); 15 | extern void isr11(); 16 | extern void isr12(); 17 | extern void isr13(); 18 | extern void isr14(); 19 | extern void isr15(); 20 | extern void isr16(); 21 | extern void isr17(); 22 | extern void isr18(); 23 | extern void isr19(); 24 | extern void isr20(); 25 | extern void isr21(); 26 | extern void isr22(); 27 | extern void isr23(); 28 | extern void isr24(); 29 | extern void isr25(); 30 | extern void isr26(); 31 | extern void isr27(); 32 | extern void isr28(); 33 | extern void isr29(); 34 | extern void isr30(); 35 | extern void isr31(); 36 | 37 | void isr_init(); 38 | 39 | void fault_handler(struct registers *r); 40 | 41 | void print_regs(struct registers *r); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/include/kernel/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYBOARD_H 2 | #define KEYBOARD_H 3 | 4 | void getInput(); 5 | void keyboard_handler(struct registers* r); 6 | 7 | #endif -------------------------------------------------------------------------------- /src/include/kernel/kmain.h: -------------------------------------------------------------------------------- 1 | extern void syscall_handler(); 2 | extern void load_gdt(); 3 | extern uint8_t boot_disk; 4 | void interrupts_init(); 5 | void parse_mboot(uint32_t addr); 6 | 7 | int kmain(uint32_t mbootptr); 8 | void kmain_late(); 9 | -------------------------------------------------------------------------------- /src/include/kernel/multiboot.h: -------------------------------------------------------------------------------- 1 | /* multiboot2.h - Multiboot 2 header file. */ 2 | /* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY 17 | * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 19 | * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef MULTIBOOT_HEADER 23 | #define MULTIBOOT_HEADER 1 24 | 25 | /* How many bytes from the start of the file we search for the header. */ 26 | #define MULTIBOOT_SEARCH 32768 27 | #define MULTIBOOT_HEADER_ALIGN 8 28 | 29 | /* The magic field should contain this. */ 30 | #define MULTIBOOT2_HEADER_MAGIC 0xe85250d6 31 | 32 | /* This should be in %eax. */ 33 | #define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289 34 | 35 | /* Alignment of multiboot modules. */ 36 | #define MULTIBOOT_MOD_ALIGN 0x00001000 37 | 38 | /* Alignment of the multiboot info structure. */ 39 | #define MULTIBOOT_INFO_ALIGN 0x00000008 40 | 41 | /* Flags set in the 'flags' member of the multiboot header. */ 42 | 43 | #define MULTIBOOT_TAG_ALIGN 8 44 | #define MULTIBOOT_TAG_TYPE_END 0 45 | #define MULTIBOOT_TAG_TYPE_CMDLINE 1 46 | #define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2 47 | #define MULTIBOOT_TAG_TYPE_MODULE 3 48 | #define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4 49 | #define MULTIBOOT_TAG_TYPE_BOOTDEV 5 50 | #define MULTIBOOT_TAG_TYPE_MMAP 6 51 | #define MULTIBOOT_TAG_TYPE_VBE 7 52 | #define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8 53 | #define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9 54 | #define MULTIBOOT_TAG_TYPE_APM 10 55 | #define MULTIBOOT_TAG_TYPE_EFI32 11 56 | #define MULTIBOOT_TAG_TYPE_EFI64 12 57 | #define MULTIBOOT_TAG_TYPE_SMBIOS 13 58 | #define MULTIBOOT_TAG_TYPE_ACPI_OLD 14 59 | #define MULTIBOOT_TAG_TYPE_ACPI_NEW 15 60 | #define MULTIBOOT_TAG_TYPE_NETWORK 16 61 | #define MULTIBOOT_TAG_TYPE_EFI_MMAP 17 62 | #define MULTIBOOT_TAG_TYPE_EFI_BS 18 63 | 64 | #define MULTIBOOT_HEADER_TAG_END 0 65 | #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1 66 | #define MULTIBOOT_HEADER_TAG_ADDRESS 2 67 | #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3 68 | #define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4 69 | #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5 70 | #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6 71 | #define MULTIBOOT_HEADER_TAG_EFI_BS 7 72 | 73 | #define MULTIBOOT_ARCHITECTURE_I386 0 74 | #define MULTIBOOT_ARCHITECTURE_MIPS32 4 75 | #define MULTIBOOT_HEADER_TAG_OPTIONAL 1 76 | 77 | #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 78 | #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 79 | 80 | #ifndef ASM_FILE 81 | 82 | typedef unsigned char multiboot_uint8_t; 83 | typedef unsigned short multiboot_uint16_t; 84 | typedef unsigned int multiboot_uint32_t; 85 | typedef unsigned long long multiboot_uint64_t; 86 | 87 | struct multiboot_header 88 | { 89 | /* Must be MULTIBOOT_MAGIC - see above. */ 90 | multiboot_uint32_t magic; 91 | 92 | /* ISA */ 93 | multiboot_uint32_t architecture; 94 | 95 | /* Total header length. */ 96 | multiboot_uint32_t header_length; 97 | 98 | /* The above fields plus this one must equal 0 mod 2^32. */ 99 | multiboot_uint32_t checksum; 100 | }; 101 | 102 | struct multiboot_header_tag 103 | { 104 | multiboot_uint16_t type; 105 | multiboot_uint16_t flags; 106 | multiboot_uint32_t size; 107 | }; 108 | 109 | struct multiboot_header_tag_information_request 110 | { 111 | multiboot_uint16_t type; 112 | multiboot_uint16_t flags; 113 | multiboot_uint32_t size; 114 | multiboot_uint32_t requests[0]; 115 | }; 116 | 117 | struct multiboot_header_tag_address 118 | { 119 | multiboot_uint16_t type; 120 | multiboot_uint16_t flags; 121 | multiboot_uint32_t size; 122 | multiboot_uint32_t header_addr; 123 | multiboot_uint32_t load_addr; 124 | multiboot_uint32_t load_end_addr; 125 | multiboot_uint32_t bss_end_addr; 126 | }; 127 | 128 | struct multiboot_header_tag_entry_address 129 | { 130 | multiboot_uint16_t type; 131 | multiboot_uint16_t flags; 132 | multiboot_uint32_t size; 133 | multiboot_uint32_t entry_addr; 134 | }; 135 | 136 | struct multiboot_header_tag_console_flags 137 | { 138 | multiboot_uint16_t type; 139 | multiboot_uint16_t flags; 140 | multiboot_uint32_t size; 141 | multiboot_uint32_t console_flags; 142 | }; 143 | 144 | struct multiboot_header_tag_framebuffer 145 | { 146 | multiboot_uint16_t type; 147 | multiboot_uint16_t flags; 148 | multiboot_uint32_t size; 149 | multiboot_uint32_t width; 150 | multiboot_uint32_t height; 151 | multiboot_uint32_t depth; 152 | }; 153 | 154 | struct multiboot_header_tag_module_align 155 | { 156 | multiboot_uint16_t type; 157 | multiboot_uint16_t flags; 158 | multiboot_uint32_t size; 159 | }; 160 | 161 | struct multiboot_color 162 | { 163 | multiboot_uint8_t red; 164 | multiboot_uint8_t green; 165 | multiboot_uint8_t blue; 166 | }; 167 | 168 | struct multiboot_mmap_entry 169 | { 170 | multiboot_uint64_t addr; 171 | multiboot_uint64_t len; 172 | #define MULTIBOOT_MEMORY_AVAILABLE 1 173 | #define MULTIBOOT_MEMORY_RESERVED 2 174 | #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 175 | #define MULTIBOOT_MEMORY_NVS 4 176 | #define MULTIBOOT_MEMORY_BADRAM 5 177 | multiboot_uint32_t type; 178 | multiboot_uint32_t zero; 179 | }; 180 | typedef struct multiboot_mmap_entry multiboot_memory_map_t; 181 | 182 | struct multiboot_tag 183 | { 184 | multiboot_uint32_t type; 185 | multiboot_uint32_t size; 186 | }; 187 | 188 | struct multiboot_tag_string 189 | { 190 | multiboot_uint32_t type; 191 | multiboot_uint32_t size; 192 | char string[0]; 193 | }; 194 | 195 | struct multiboot_tag_module 196 | { 197 | multiboot_uint32_t type; 198 | multiboot_uint32_t size; 199 | multiboot_uint32_t mod_start; 200 | multiboot_uint32_t mod_end; 201 | char cmdline[0]; 202 | }; 203 | 204 | struct multiboot_tag_basic_meminfo 205 | { 206 | multiboot_uint32_t type; 207 | multiboot_uint32_t size; 208 | multiboot_uint32_t mem_lower; 209 | multiboot_uint32_t mem_upper; 210 | }; 211 | 212 | struct multiboot_tag_bootdev 213 | { 214 | multiboot_uint32_t type; 215 | multiboot_uint32_t size; 216 | multiboot_uint32_t biosdev; 217 | multiboot_uint32_t slice; 218 | multiboot_uint32_t part; 219 | }; 220 | 221 | struct multiboot_tag_mmap 222 | { 223 | multiboot_uint32_t type; 224 | multiboot_uint32_t size; 225 | multiboot_uint32_t entry_size; 226 | multiboot_uint32_t entry_version; 227 | struct multiboot_mmap_entry entries[0]; 228 | }; 229 | 230 | struct multiboot_vbe_info_block 231 | { 232 | multiboot_uint8_t external_specification[512]; 233 | }; 234 | 235 | struct multiboot_vbe_mode_info_block 236 | { 237 | multiboot_uint8_t external_specification[256]; 238 | }; 239 | 240 | struct multiboot_tag_vbe 241 | { 242 | multiboot_uint32_t type; 243 | multiboot_uint32_t size; 244 | 245 | multiboot_uint16_t vbe_mode; 246 | multiboot_uint16_t vbe_interface_seg; 247 | multiboot_uint16_t vbe_interface_off; 248 | multiboot_uint16_t vbe_interface_len; 249 | 250 | struct multiboot_vbe_info_block vbe_control_info; 251 | struct multiboot_vbe_mode_info_block vbe_mode_info; 252 | }; 253 | 254 | struct multiboot_tag_framebuffer_common 255 | { 256 | multiboot_uint32_t type; 257 | multiboot_uint32_t size; 258 | 259 | multiboot_uint64_t framebuffer_addr; 260 | multiboot_uint32_t framebuffer_pitch; 261 | multiboot_uint32_t framebuffer_width; 262 | multiboot_uint32_t framebuffer_height; 263 | multiboot_uint8_t framebuffer_bpp; 264 | #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 265 | #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 266 | #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 267 | multiboot_uint8_t framebuffer_type; 268 | multiboot_uint16_t reserved; 269 | }; 270 | 271 | struct multiboot_tag_framebuffer 272 | { 273 | struct multiboot_tag_framebuffer_common common; 274 | 275 | union 276 | { 277 | struct 278 | { 279 | multiboot_uint16_t framebuffer_palette_num_colors; 280 | struct multiboot_color framebuffer_palette[0]; 281 | }; 282 | struct 283 | { 284 | multiboot_uint8_t framebuffer_red_field_position; 285 | multiboot_uint8_t framebuffer_red_mask_size; 286 | multiboot_uint8_t framebuffer_green_field_position; 287 | multiboot_uint8_t framebuffer_green_mask_size; 288 | multiboot_uint8_t framebuffer_blue_field_position; 289 | multiboot_uint8_t framebuffer_blue_mask_size; 290 | }; 291 | }; 292 | }; 293 | 294 | struct multiboot_tag_elf_sections 295 | { 296 | multiboot_uint32_t type; 297 | multiboot_uint32_t size; 298 | multiboot_uint32_t num; 299 | multiboot_uint32_t entsize; 300 | multiboot_uint32_t shndx; 301 | char sections[0]; 302 | }; 303 | 304 | struct multiboot_tag_apm 305 | { 306 | multiboot_uint32_t type; 307 | multiboot_uint32_t size; 308 | multiboot_uint16_t version; 309 | multiboot_uint16_t cseg; 310 | multiboot_uint32_t offset; 311 | multiboot_uint16_t cseg_16; 312 | multiboot_uint16_t dseg; 313 | multiboot_uint16_t flags; 314 | multiboot_uint16_t cseg_len; 315 | multiboot_uint16_t cseg_16_len; 316 | multiboot_uint16_t dseg_len; 317 | }; 318 | 319 | struct multiboot_tag_efi32 320 | { 321 | multiboot_uint32_t type; 322 | multiboot_uint32_t size; 323 | multiboot_uint32_t pointer; 324 | }; 325 | 326 | struct multiboot_tag_efi64 327 | { 328 | multiboot_uint32_t type; 329 | multiboot_uint32_t size; 330 | multiboot_uint64_t pointer; 331 | }; 332 | 333 | struct multiboot_tag_smbios 334 | { 335 | multiboot_uint32_t type; 336 | multiboot_uint32_t size; 337 | multiboot_uint8_t major; 338 | multiboot_uint8_t minor; 339 | multiboot_uint8_t reserved[6]; 340 | multiboot_uint8_t tables[0]; 341 | }; 342 | 343 | struct multiboot_tag_old_acpi 344 | { 345 | multiboot_uint32_t type; 346 | multiboot_uint32_t size; 347 | multiboot_uint8_t rsdp[0]; 348 | }; 349 | 350 | struct multiboot_tag_new_acpi 351 | { 352 | multiboot_uint32_t type; 353 | multiboot_uint32_t size; 354 | multiboot_uint8_t rsdp[0]; 355 | }; 356 | 357 | struct multiboot_tag_network 358 | { 359 | multiboot_uint32_t type; 360 | multiboot_uint32_t size; 361 | multiboot_uint8_t dhcpack[0]; 362 | }; 363 | 364 | struct multiboot_tag_efi_mmap 365 | { 366 | multiboot_uint32_t type; 367 | multiboot_uint32_t size; 368 | multiboot_uint32_t descr_size; 369 | multiboot_uint32_t descr_vers; 370 | multiboot_uint8_t efi_mmap[0]; 371 | }; 372 | 373 | #endif /* ! ASM_FILE */ 374 | 375 | #endif /* ! MULTIBOOT_HEADER */ -------------------------------------------------------------------------------- /src/include/kernel/paging.h: -------------------------------------------------------------------------------- 1 | #ifndef PAGING_H 2 | #define PAGING_H 3 | 4 | extern long kstart; 5 | extern long kend; 6 | extern void load_page_dir(unsigned int*); 7 | void setupPaging(); 8 | void pageFaultHandler(struct registers *r); 9 | void exec(uint8_t* prog); 10 | 11 | #endif -------------------------------------------------------------------------------- /src/include/kernel/pci.h: -------------------------------------------------------------------------------- 1 | #ifndef PCI_H 2 | #define PCI_H 3 | 4 | typedef struct PCIDevice{ 5 | uint8_t bus; 6 | uint8_t slot; 7 | uint8_t flags; // Bit 0: exists Bit 1: Multiple devices with this device's class, subclass, and progIF 8 | } PCIDevice; 9 | uint16_t PCIReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); 10 | uint16_t getPCIVendor(uint8_t bus, uint8_t slot, uint8_t function); 11 | PCIDevice getPCIDevice(uint8_t class, uint8_t subClass, uint8_t progIF); 12 | void PCIDebug(); 13 | void printPCIClassCode(uint8_t classCode, uint8_t subClass, uint8_t progIF); 14 | 15 | #endif -------------------------------------------------------------------------------- /src/include/kernel/pit.h: -------------------------------------------------------------------------------- 1 | #ifndef PIT_H 2 | #define PIT_H 3 | 4 | #define PIT_COUNTER0 0x40 5 | #define PIT_COUNTER1 0x41 6 | #define PIT_COUNTER2 0x42 7 | #define PIT_CMD 0x43 8 | 9 | void pit_handler(); 10 | 11 | void pit_init(); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/include/kernel/shell.h: -------------------------------------------------------------------------------- 1 | #ifndef SHELL_H 2 | #define SHELL_H 3 | #include 4 | 5 | void initShell(filesystem_t *fsp); 6 | void shell(); 7 | static void command_eval(char *cmd, char *args); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/include/kernel/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef STDIO_H 2 | #define STDIO_H 3 | 4 | void print_color(char* c, char color); 5 | void println_color(char* c, char color); 6 | void putch(char c); 7 | void print(char* c); 8 | void println(char* c); 9 | void setColor(char color); 10 | void center_print_base(char* c, char color, int width); 11 | void printHex(uint8_t num); 12 | void printHexw(uint16_t num); 13 | void printHexl(uint32_t num); 14 | void printNum(int num); 15 | void printf(char *fmt, ...); 16 | void backspace(); 17 | void PANIC(char *error, char *msg, bool hang); 18 | void putch_color(char c, char color); 19 | void clearScreen(); 20 | void setAllColor(char color); 21 | void center_print(char* c, char color); 22 | void update_cursor(); 23 | void scroll(); 24 | #define SCREEN_CHAR_WIDTH 80 25 | #define SCREEN_CHAR_HEIGHT 25 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/include/kernel/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSCALL_H 2 | #define SYSCALL_H 3 | 4 | struct syscall{ 5 | unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; 6 | }; 7 | 8 | void syscallHandler(uint32_t eax, uint32_t ebx); 9 | 10 | #endif -------------------------------------------------------------------------------- /src/include/kernel/tasking.h: -------------------------------------------------------------------------------- 1 | #ifndef TASKING_H 2 | #define TASKING_H 3 | 4 | #include 5 | 6 | #define PROCESS_ALIVE 0 7 | #define PROCESS_ZOMBIE 1 8 | #define PROCESS_DEAD 2 9 | 10 | #define SIGTERM 15 11 | #define SIGILL 4 12 | 13 | typedef struct process_t{ 14 | char *name; 15 | uint32_t pid; 16 | uint32_t esp; 17 | uint32_t stack; 18 | uint32_t eip; 19 | uint32_t cr3; 20 | uint32_t state; 21 | void (*notify)(uint32_t); 22 | bool notExecuted; 23 | struct process_t *next, *prev; 24 | } process_t; 25 | 26 | void initTasking(); 27 | void printTasks(); 28 | uint32_t addProcess(process_t *p); 29 | process_t *getCurrentProcess(); 30 | void __init__(); 31 | void preempt_now(); 32 | void __kill__(); 33 | void __notify__(uint32_t sig); 34 | process_t *createProcess(char *name, uint32_t loc); 35 | process_t *getProcess(uint32_t pid); 36 | void preempt(); 37 | void notify(uint32_t sig); 38 | void kill(process_t *p); 39 | 40 | extern void _iret(); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/include/kernel/tss.h: -------------------------------------------------------------------------------- 1 | #ifndef TSS_H 2 | #define TSS_H 3 | 4 | typedef struct TssEntry 5 | { 6 | uint32_t prev_tss; 7 | uint32_t esp0; // The stack pointer to load when we change to kernel mode. 8 | uint32_t ss0; // The stack segment to load when we change to kernel mode. 9 | uint32_t esp1; 10 | uint32_t ss1; 11 | uint32_t esp2; 12 | uint32_t ss2; 13 | uint32_t cr3; 14 | uint32_t eip; 15 | uint32_t eflags; 16 | uint32_t eax; 17 | uint32_t ecx; 18 | uint32_t edx; 19 | uint32_t ebx; 20 | uint32_t esp; 21 | uint32_t ebp; 22 | uint32_t esi; 23 | uint32_t edi; 24 | uint32_t es; 25 | uint32_t cs; 26 | uint32_t ss; 27 | uint32_t ds; 28 | uint32_t fs; 29 | uint32_t gs; 30 | uint32_t ldt; 31 | uint16_t trap; 32 | uint16_t iomap_base; 33 | }__attribute__((packed)) TssEntry; 34 | 35 | uint16_t tss_high; 36 | uint8_t tss_low; 37 | 38 | #endif -------------------------------------------------------------------------------- /src/include/kernel/vfs.h: -------------------------------------------------------------------------------- 1 | #ifndef VFS_H 2 | #define VFS_H 3 | 4 | typedef struct device_t{ 5 | uint8_t disk; 6 | } device_t; 7 | 8 | typedef struct file_t{ 9 | uint32_t size; 10 | uint32_t sectors; 11 | bool isDirectory; 12 | uint32_t fs_id; 13 | } file_t; 14 | 15 | typedef struct filesystem_t{ 16 | char *type; 17 | bool (*probe)(struct filesystem_t *); 18 | bool (*read)(file_t *, char *, struct filesystem_t *); //fn, buf, fsdata; 19 | bool (*getFile)(char *, file_t *, struct filesystem_t *); 20 | bool (*listDir)(file_t *, struct filesystem_t *); 21 | void *fs_data; 22 | device_t *device; 23 | } filesystem_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/kernel/ata.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * This system is to read disks formatted with an MBR only. 6 | * For reading specific filesystems, see the respective files in c/drivers/disk. 7 | */ 8 | uint8_t boot_disk = 0; 9 | uint8_t ata_buf[512]; 10 | uint8_t ata_buf2[512]; 11 | 12 | void prepareDisk(int disk, int address){ 13 | outb(0x1F1,0x00); 14 | outb(0x1F2,0x01); 15 | outb(0x1F3,(uint8_t)address); 16 | outb(0x1F4,(uint8_t)(address >> 8)); 17 | outb(0x1F5,(uint8_t)(address >> 16)); 18 | outb(0x1F6,0xE0 | (disk << 4) | ((address >> 24) & 0x0F)); 19 | outb(0x1F7,0x20); 20 | while (!(inb(0x1F7) & 0x08)) {} 21 | } 22 | 23 | void readSector(int disk, int address, uint8_t *sect){ 24 | prepareDisk(disk, address); 25 | for(int i = 0; i < 256; i++){ 26 | uint16_t tmp = inw(0x1F0); 27 | sect[i*2] = (uint8_t)tmp; 28 | sect[i*2+1] = (uint8_t)(tmp >> 8); 29 | } 30 | } 31 | 32 | void readSectors(int disk, int address, int sectors, uint8_t *sect){ 33 | for(int i = 0; i < sectors; i++){ 34 | readSector(disk,address+i,sect+i*512); 35 | } 36 | } 37 | 38 | int getFirstPartition(int disk){ 39 | prepareDisk(disk,0); 40 | uint16_t pos = 0; 41 | for(int i = 0; i < 256; i++){ 42 | uint16_t tmpword = inw(0x1F0); 43 | if(i == 227){ 44 | pos = tmpword; 45 | } 46 | } 47 | return pos; 48 | } 49 | 50 | int getFSType(int disk){ 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/kernel/common.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void outb(uint16_t port, uint8_t value){ 5 | asm volatile ("outb %1, %0" : : "d" (port), "a" (value)); 6 | } 7 | 8 | void outw(uint16_t port, uint16_t value){ 9 | asm volatile ("outw %1, %0" : : "dN" (port), "a" (value)); 10 | } 11 | 12 | void outl(uint16_t port, uint32_t value){ 13 | asm volatile ("outl %1, %0" : : "dN" (port), "a" (value)); 14 | } 15 | 16 | uint8_t inb(uint16_t port){ 17 | uint8_t ret; 18 | asm volatile("inb %1, %0" : "=a" (ret) : "dN" (port)); 19 | return ret; 20 | } 21 | 22 | uint16_t inw(uint16_t port){ 23 | uint16_t ret; 24 | asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port)); 25 | return ret; 26 | } 27 | 28 | uint32_t inl(uint16_t port){ 29 | uint32_t ret; 30 | asm volatile ("inl %1, %0" : "=a" (ret) : "dN" (port)); 31 | return ret; 32 | } 33 | 34 | int sgn(int x){ 35 | if(x>0) return 1; 36 | else return -1; 37 | return 0; 38 | } 39 | 40 | int abs(float x){ 41 | return (int)x; 42 | } 43 | 44 | void *memset(void *dest, char val, int count){ 45 | char *temp = (char *)dest; 46 | for( ; count != 0; count--) *temp++ = val; 47 | return dest; 48 | } 49 | 50 | void *memcpy(void *dest, const void *src, size_t count){ 51 | const char *sp = (const char *)src; 52 | char *dp = (char *)dest; 53 | for(; count != 0; count--) *dp++ = *sp++; 54 | return dest; 55 | } 56 | 57 | void numToHexString(uint8_t num, char *str){ 58 | str[1] = nibbleToHexString(num); 59 | str[0] = nibbleToHexString(num >> 4); 60 | } 61 | 62 | char nibbleToHexString(uint8_t num){ 63 | uint8_t tmp = num & 0xF; 64 | if(tmp < 0xA){ 65 | return tmp+0x30; 66 | }else{ 67 | return tmp+0x57; 68 | } 69 | } 70 | 71 | char *itoa(int i, char *p, int base){ 72 | char const digit[] = "0123456789"; 73 | int nbcount = 0; 74 | bool flag = 0; 75 | int ind; 76 | switch(base){ 77 | case 10: 78 | if(i<0){ 79 | *p++ = '-'; 80 | i *= -1; 81 | } 82 | int shifter = i; 83 | do{ 84 | ++p; 85 | shifter = shifter/10; 86 | }while(shifter); 87 | *p = '\0'; 88 | do{ 89 | *--p = digit[i%10]; 90 | i = i/10; 91 | }while(i); 92 | break; 93 | //I figured out how to roll base 2 and 16 into one thing... Not sure how efficient it is though 94 | case 2: 95 | case 16: 96 | if(i == 0){p[0] = '0'; p[1] = '\0';}else{ 97 | uint8_t shift = base == 16 ? 4 : 1; 98 | for(uint32_t a = (base == 16 ? 0xF0000000 : 0x80000000); a > 0; a = a >> shift) 99 | if((i&a) != 0 || flag){ nbcount++; flag = true;} 100 | ind = nbcount; 101 | for(ind > 0; ind--;) 102 | p[-ind+nbcount-1] = base == 16 ? (nibbleToHexString((i >> (ind*4)) & 0xF)) : (((i >> ind) & 0x1) ? '1' : '0'); 103 | p[nbcount] = '\0'; 104 | } 105 | break; 106 | } 107 | return p; 108 | } 109 | 110 | bool isACharacter(uint8_t num){ 111 | return num >= 0x20 && num <= 0x7E; 112 | } 113 | 114 | int strlen(const char *str){ 115 | const char *s; 116 | 117 | for (s = str; *s; ++s) 118 | ; 119 | return (s - str); 120 | } 121 | 122 | bool strcmp(string str1,string str2){ 123 | int i = 0; 124 | bool flag = false; 125 | 126 | while(str1[i]!='\0' && str2[i]!='\0'){ 127 | if(str1[i]!=str2[i]){ 128 | flag=1; 129 | break; 130 | } 131 | i++; 132 | } 133 | 134 | return flag == 0 && str1[i] == '\0' && str2[i] == '\0'; 135 | 136 | } 137 | 138 | int indexOf(char c, char *str){ 139 | int i = 0; 140 | while(str[i] != '\0'){ 141 | if(str[i] == c) 142 | return i; 143 | i++; 144 | } 145 | return strlen(str); 146 | } 147 | 148 | int indexOfn(char c, int n, char *str){ //like indexOf, except ignores n instances of the character 149 | int i = 0; 150 | int count = 0; 151 | while(str[i] != '\0'){ 152 | if(str[i] == c) 153 | if(count == n) 154 | return i; 155 | else 156 | count++; 157 | i++; 158 | } 159 | return strlen(str); 160 | } 161 | 162 | void substr(int i, char *src, char *dest){ //substring exclusive 163 | memcpy(dest,src,i); 164 | dest[i] = '\0'; 165 | } 166 | 167 | void substri(int i, char *src, char *dest){ //substring inclusive 168 | memcpy(dest,src,i+1); 169 | dest[i+1] = '\0'; 170 | } 171 | 172 | void substrr(int s, int e, char *src, char *dest){ //substring exclusive range (end is exclusive, beginning is inclusive) 173 | memcpy(dest,&src[s],e-s); 174 | dest[e-s] = '\0'; 175 | } 176 | 177 | void strcpy(char *src, char *dest){ 178 | memcpy(dest, src, strlen(src)); 179 | dest[strlen(src)] = '\0'; 180 | } 181 | 182 | int countOf(char c, char *str){ //Returns number of instances of c in str 183 | int count = 0; 184 | for(int i = 0; i < strlen(str); i++){ 185 | if(str[i] == c) 186 | count++; 187 | } 188 | return count; 189 | } 190 | 191 | bool contains(char *str, char *cont){ //Returns true if str has cont in it. 192 | int i = 0; 193 | int contlen = strlen(cont); 194 | bool flaga = false; 195 | bool flagb = false; 196 | while(str[i+contlen-1] != '\0'){ 197 | flagb = true; 198 | for(int j = 0; j < strlen(cont); j++){ 199 | if(cont[j] != str[j+i]) 200 | flagb = false; 201 | } 202 | if(flagb) 203 | flaga = true; 204 | i++; 205 | } 206 | return flaga; 207 | } 208 | 209 | int strToInt(char *str){ 210 | int len = strlen(str); 211 | int ret = 0; 212 | for(int i = 0; i < len; i++){ 213 | ret = ret * 10 + (str[i] - '0'); 214 | } 215 | return ret; 216 | } 217 | 218 | void cli(){ 219 | asm volatile("cli"); 220 | } 221 | 222 | void sti(){ 223 | asm volatile("sti"); 224 | } 225 | 226 | void toUpper(char *str){ 227 | while(*str != '\0'){ 228 | if(*str >= 'a' && *str <= 'z') *str = *str - ('a' - 'A'); 229 | *str++; 230 | } 231 | } 232 | 233 | char *strcat(char *dest, const char *src){ 234 | uint32_t i,j; 235 | for (i = 0; dest[i] != '\0'; i++) 236 | ; 237 | for (j = 0; src[j] != '\0'; j++) 238 | dest[i+j] = src[j]; 239 | dest[i+j] = '\0'; 240 | return dest; 241 | } 242 | -------------------------------------------------------------------------------- /src/kernel/ehci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | EHCIController getFirstEHCIController(){ 8 | PCIDevice device = getPCIDevice(0x0C,0x03,0x20); 9 | EHCIController controller = {device,0}; 10 | return controller; 11 | } 12 | 13 | void EHCIDebug(){ 14 | println("Trying to find USB 2.0 controller(s)..."); 15 | EHCIController controller = getFirstEHCIController(); 16 | PCIDevice device = controller.pciDevice; 17 | if(device.flags & 0b00000001){ 18 | print("Found USB 2.0 controller at "); 19 | printHex(device.bus); 20 | print(","); 21 | printHex(device.slot); 22 | println("!"); 23 | if(device.flags & 0b00000010){ 24 | println("There are multiple."); 25 | } 26 | }else{ 27 | println("No USB 2.0 controller found."); 28 | } 29 | } -------------------------------------------------------------------------------- /src/kernel/elf.c: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /src/kernel/ext2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | extern uint8_t ata_buf[512], ata_buf2[512]; 10 | 11 | bool isPartitionExt2(int disk, int sect){ 12 | readSector(disk, sect+2, ata_buf); //Supercluster begins at partition sector + 2 13 | return ((ext2_superblock *)ata_buf)->signature != EXT2_SIGNATURE; 14 | } 15 | 16 | bool ext2_probe(filesystem_t *fs){ 17 | if(strcmp(fs->type,"EXT2")){ 18 | ext2_partition *part = (ext2_partition *)fs->fs_data; 19 | return isPartitionExt2(part->disk, part->sector); 20 | } 21 | return 0; 22 | } 23 | 24 | void getExt2Superblock(int disk, int sect, ext2_superblock *sp){ 25 | readSector(disk, sect+2, (char *)sp); 26 | if(sp->version_major < 1){ //If major version is less than 1, then use defaults for stuff 27 | sp->first_inode = 11; 28 | sp->inode_size = 128; 29 | } 30 | } 31 | 32 | void initExt2Partition(int sect, device_t *device, ext2_superblock *sb, ext2_partition *part, filesystem_t *fs){ 33 | part->sector = sect; 34 | part->disk = device->disk; 35 | part->block_size = 1024 << (sb->block_size); 36 | part->block_group_descriptor_table = sb->superblock_block+1; 37 | part->blocks_per_inode_table = (sb->inode_size*sb->inodes_per_group)/ext2_getBlockSize(part); 38 | part->sectors_per_inode_table = (sb->inode_size*sb->inodes_per_group)/512; 39 | part->sectors_per_block = ext2_getBlockSize(part)/512; 40 | part->num_block_groups = sb->total_blocks/sb->blocks_per_group + (sb->total_blocks % sb->blocks_per_group != 0); 41 | part->inodes_per_block = ext2_getBlockSize(part)/sb->inode_size; 42 | part->superblock = sb; 43 | fs->type = "EXT2"; 44 | fs->probe = ext2_probe; 45 | fs->read = (bool(*)(file_t *, char *, filesystem_t *))ext2_readFile; 46 | fs->fs_data = part; 47 | fs->getFile = (bool(*)(char *, file_t *, filesystem_t *))ext2_getFile; 48 | fs->listDir = (bool(*)(file_t *, filesystem_t *))ext2_listDirectory; 49 | fs->device = device; 50 | } 51 | 52 | uint32_t ext2_getBlockGroupOfInode(uint32_t node, ext2_partition *part){ 53 | return (node - 1) / ext2_getSuperblock(part)->inodes_per_group; 54 | } 55 | 56 | uint32_t ext2_getIndexOfInode(uint32_t node, ext2_partition *part){ 57 | return (node - 1) % ext2_getSuperblock(part)->inodes_per_group; 58 | } 59 | 60 | //inode is the actual number of the inode, not the index or anything. 61 | uint32_t ext2_getBlockOfInode(uint32_t node, ext2_partition *part){ 62 | return (ext2_getIndexOfInode(node, part) * ext2_getSuperblock(part)->inode_size) / ext2_getBlockSize(part); 63 | } 64 | 65 | void ext2_readInode(uint32_t inode, ext2_inode *buf, ext2_partition *part){ 66 | uint32_t bg = ext2_getBlockGroupOfInode(inode, part); 67 | uint8_t *read = ext2_allocBlock(part); 68 | ext2_block_group_descriptor *d = (ext2_block_group_descriptor *)ext2_readBlock(2, read, part); 69 | for(int i = 0; i < bg; i++) d++; //note to self - d++ adds to the pointer by sizeof(ext2_block_group_descriptor) 70 | 71 | ext2_readBlock(d->inode_table+ext2_getBlockOfInode(inode, part), (uint8_t *)buf, part); 72 | ext2_inode *in = (ext2_inode *)buf; 73 | uint32_t index = ext2_getIndexOfInode(inode, part) % part->inodes_per_block; 74 | for(int i = 0; i < index; i++) in++; //same here as above 75 | 76 | memcpy(buf, in, sizeof(ext2_inode)); 77 | ext2_freeBlock(read, part); 78 | } 79 | 80 | bool ext2_listDirectory(file_t *file, filesystem_t *fs){ 81 | ext2_partition *part = fs->fs_data; 82 | ext2_inode *inode = kmalloc(sizeof(inode)); 83 | ext2_readInode(file->fs_id,inode,part); 84 | if((inode->type & 0xF000) != EXT2_DIRECTORY){ 85 | printf("Given file is not a directory!\n"); 86 | kfree(inode, sizeof(inode)); 87 | return 0; 88 | }else{ 89 | uint8_t *buf = ext2_allocBlock(part); 90 | for(int i = 0; i < 12; i++){ 91 | uint32_t block = inode->block_pointers[i]; 92 | if(block == 0 || block > ext2_getSuperblock(part)->total_blocks) break; 93 | ext2_readBlock(block, buf, part); 94 | ext2_listDirectoryEntries((ext2_directory *)buf, part); 95 | } 96 | ext2_freeBlock(buf, part); 97 | } 98 | kfree(inode, sizeof(inode)); 99 | return 1; 100 | } 101 | 102 | void ext2_listDirectoryEntries(ext2_directory *dir, ext2_partition *part){ 103 | uint32_t add = 0; 104 | while(dir->inode != 0 && add < ext2_getBlockSize(part)){ 105 | char *name = kmalloc(dir->name_length + 1); 106 | name[dir->name_length] = '\0'; 107 | memcpy(name, &dir->type+1, dir->name_length); 108 | if(name[0] != '.' && name[0] != '\0') printf("%s\n", name); 109 | kfree(name, dir->name_length + 1); 110 | add+=dir->size; 111 | dir = (ext2_directory *)((uint32_t)dir + dir->size); 112 | } 113 | } 114 | 115 | //dir_inode will be set to 2 if find_name starts with '/' 116 | uint32_t ext2_findFile(char *find_name, uint32_t dir_inode, ext2_inode *inode, ext2_partition *part){ 117 | if(find_name[0] == '/'){ 118 | find_name++; 119 | dir_inode = 2; 120 | } 121 | uint32_t namelen = strlen(find_name); 122 | if(namelen == 0) return dir_inode; 123 | uint8_t *buf = ext2_allocBlock(part); 124 | char *cfind_name = kmalloc(namelen); 125 | while(*find_name != 0){ 126 | uint32_t strindex = indexOf('/',find_name); 127 | substrr(0,strindex,find_name,cfind_name); 128 | find_name+=strindex+(strindex == strlen(find_name) ? 0 : 1); 129 | ext2_readInode(dir_inode,inode,part); 130 | bool found = 0; 131 | for(int i = 0; i < 12 && !found; i++){ 132 | uint32_t block = inode->block_pointers[i]; 133 | if(block == 0 || block > ext2_getSuperblock(part)->total_blocks) break; 134 | ext2_readBlock(block, buf, part); 135 | ext2_directory *dir = (ext2_directory *)buf; 136 | uint32_t add = 0; 137 | while(dir->inode != 0 && add < ext2_getBlockSize(part) && !found){ 138 | char *name = kmalloc(dir->name_length + 1); 139 | name[dir->name_length] = '\0'; 140 | memcpy(name, &dir->type+1, dir->name_length); 141 | if(strcmp(name, cfind_name)){ 142 | dir_inode = dir->inode; 143 | ext2_readInode(dir_inode,inode,part); 144 | found = 1; 145 | } 146 | kfree(name, dir->name_length + 1); 147 | add+=dir->size; 148 | dir = (ext2_directory *)((uint32_t)dir + dir->size); 149 | } 150 | } 151 | if(!found){ 152 | dir_inode = 0; 153 | find_name+= strlen(find_name); 154 | } 155 | } 156 | kfree(cfind_name, namelen); 157 | ext2_freeBlock(buf,part); 158 | return dir_inode; 159 | } 160 | 161 | bool ext2_getFile(char *fn, file_t *file, filesystem_t *fs){ 162 | ext2_inode *inode = kmalloc(sizeof(ext2_inode)); 163 | uint32_t id = ext2_findFile(fn, 2, inode, (ext2_partition *)(fs->fs_data)); 164 | file->size = id ? inode->size_lower : 0; 165 | file->sectors = id ? inode->sectors_in_use : 0; 166 | file->fs_id = id; 167 | file->isDirectory = id ? (inode->type & 0xF000) == EXT2_DIRECTORY : 0; 168 | kfree(inode, sizeof(ext2_inode)); 169 | return id ? true : false; //not casting to uint8_t because if id has zero in lower 8 bits then it will return false 170 | } 171 | 172 | //buf must be a multiple of the blocksize 173 | bool ext2_readFile(file_t *file, uint8_t *buf, filesystem_t *fs){ 174 | if(!file->fs_id) return 0; 175 | ext2_partition *part = (ext2_partition *)(fs->fs_data); 176 | ext2_inode *inode = kmalloc(sizeof(ext2_inode)); 177 | ext2_readInode(file->fs_id, inode, part); 178 | for(int i = 0; i < 12; i++){ 179 | uint32_t block = inode->block_pointers[i]; 180 | if(block == 0 || block > ext2_getSuperblock(part)->total_blocks){break;} 181 | ext2_readBlock(block, buf, part); 182 | } 183 | if(inode->s_pointer) 184 | ext2_read_slink(inode->s_pointer, buf+12*ext2_getBlockSize(part), part); 185 | if(inode->d_pointer) 186 | ext2_read_dlink(inode->d_pointer, buf+(ext2_getBlockSize(part)/sizeof(uint32_t))*ext2_getBlockSize(part)+12*ext2_getBlockSize(part), part); 187 | if(inode->t_pointer) 188 | printf("WARNING! File uses t_pointer. Will not work.\n"); 189 | kfree(inode, sizeof(ext2_inode)); 190 | return 1; 191 | } 192 | 193 | void ext2_read_slink(uint32_t block, uint8_t *buf, ext2_partition *part){ 194 | uint8_t *bbuf = ext2_allocBlock(part); 195 | ext2_readBlock(block, bbuf, part); 196 | uint32_t *blocks = (uint32_t *)bbuf; 197 | uint32_t numblocks = ext2_getBlockSize(part)/sizeof(uint32_t); 198 | for(int i = 0; i < numblocks; i++){ 199 | if(blocks[i] == 0) break; 200 | ext2_readBlock(blocks[i], buf+i*ext2_getBlockSize(part), part); 201 | } 202 | ext2_freeBlock(bbuf,part); 203 | } 204 | 205 | void ext2_read_dlink(uint32_t block, uint8_t *buf, ext2_partition *part){ 206 | uint8_t *bbuf = ext2_allocBlock(part); 207 | ext2_readBlock(block, bbuf, part); 208 | uint32_t *blocks = (uint32_t *)bbuf; 209 | uint32_t numblocks = ext2_getBlockSize(part)/sizeof(uint32_t); 210 | uint32_t singsize = numblocks*ext2_getBlockSize(part); 211 | for(int i = 0; i < numblocks; i++){ 212 | if(blocks[i] == 0) break; 213 | ext2_readBlock(blocks[i], buf+i*singsize, part); 214 | } 215 | ext2_freeBlock(bbuf, part); 216 | } 217 | 218 | ext2_superblock *ext2_getSuperblock(ext2_partition *part){ 219 | return part->superblock; 220 | } 221 | 222 | uint32_t ext2_getBlockSize(ext2_partition *part){ 223 | return part->block_size; 224 | } 225 | 226 | uint8_t *ext2_readBlock(uint32_t block, uint8_t *buf, ext2_partition *part){ 227 | readSectors(part->disk, ext2_blockToSector(block, part), part->sectors_per_block, buf); 228 | return buf; 229 | } 230 | 231 | uint8_t *ext2_allocBlock(ext2_partition *part){ 232 | return kmalloc(ext2_getBlockSize(part)); 233 | } 234 | 235 | void ext2_freeBlock(uint8_t *block, ext2_partition *part){ 236 | kfree(block, ext2_getBlockSize(part)); 237 | } 238 | 239 | uint32_t ext2_blockToSector(uint32_t block, ext2_partition *part){ 240 | return part->sector+(ext2_getBlockSize(part)/512)*block; 241 | } 242 | -------------------------------------------------------------------------------- /src/kernel/fat32.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | const char *fat32sig = "FAT32 "; 9 | fat32part currentfat32part; 10 | char *cdir = 0; 11 | extern int xpos, ypos; 12 | extern uint8_t ata_buf[512], ata_buf2[512]; 13 | uint8_t *buf = ata_buf, *buf2 = ata_buf2; 14 | 15 | bool isPartitionFAT32(int disk, int sect){ 16 | readSector(disk, sect, buf); 17 | bool flag = true; 18 | for(int i = 0; i < 8; i++){ 19 | if(buf[0x52+i] != fat32sig[i]) 20 | flag = false; 21 | } 22 | return flag; 23 | } 24 | 25 | fat32part getFat32Part(int disk, int part_sect){ 26 | fat32part temp; 27 | temp.disk = disk; 28 | temp.part_sect = part_sect; 29 | readSector(disk, part_sect, buf); 30 | for(int i = 0; i < 512; i++){ 31 | if(i == 0xD){ 32 | temp.sectors_per_cluster = buf[i]; 33 | } 34 | if(i >= 0xE && i <= 0xF){ 35 | if(i == 0x0E){ 36 | temp.reserved_sectors = 0; 37 | } 38 | temp.reserved_sectors += ((uint16_t)buf[i]) << (i-0xE)*8; 39 | } 40 | if(i == 0x10){ 41 | temp.num_fats = buf[i]; 42 | } 43 | if(i >= 0x24 && i <=0x28){ 44 | if(i == 0x24){ 45 | temp.sectors_per_fat = 0; 46 | } 47 | if(i >= 0x24 && i <= 0x25){ 48 | temp.sectors_per_fat += ((uint32_t)buf[i]) << (i-0x24)*8; 49 | }else{ 50 | temp.sectors_per_fat += ((uint32_t)buf[i]) << (i-0x27)*8+16; 51 | } 52 | } 53 | if(i >= 0x2C && i <= 0x2F){ 54 | if(i == 0x2C){ 55 | temp.root_dir_clust = 0; 56 | } 57 | if(i >= 0x2C && i <= 0x2D){ 58 | temp.root_dir_clust += ((uint32_t)buf[i]) << (i-0x2C)*8; 59 | }else{ 60 | temp.root_dir_clust += ((uint32_t)buf[i]) << (i-0x2E)*8+16; 61 | } 62 | } 63 | } 64 | temp.cluster_begin_sect = part_sect + temp.reserved_sectors + (temp.num_fats * temp.sectors_per_fat); 65 | temp.root_dir_sect = clusterToLBAOther(temp, temp.root_dir_clust); 66 | temp.fat_sect = part_sect + temp.reserved_sectors; 67 | temp.current_dir_clust = temp.root_dir_clust; 68 | return temp; 69 | } 70 | 71 | void listDir(uint32_t cluster, char *filter){ 72 | bool done = false; 73 | uint32_t ccluster = cluster; 74 | uint32_t sector = clusterToLBA(ccluster); 75 | uint16_t dir_size = 0; 76 | uint8_t current_col = 0; 77 | uint8_t current_row = 0; 78 | uint8_t oypos = ypos; 79 | bool filtered = !strcmp(filter,""); 80 | bool shouldPrintln = false; 81 | while(!done){ 82 | readSector(currentfat32part.disk, sector, buf); 83 | for(uint8_t i = 0; i < 16; i++){ 84 | uint16_t loc = 0x20*i; 85 | bool lcfn = ((buf[loc+0xC] >> 3) & 0x01); //If filename is all lowercase 86 | bool lcex = ((buf[loc+0xC] >> 4) & 0x01); //If extension is all lowercase 87 | if(buf[loc] != 0xE5 /*Is not unused*/ 88 | && (buf[loc+0xB] & 0xF) != 0xF /*Is not a long filename entry*/ 89 | && (buf[loc+0xB] & 0xA) == 0 /*Is a file or directory and should be shown*/ 90 | && buf[loc] != 0 /*Is not empty */){ 91 | dir_size++; 92 | uint8_t lastChar = 0; 93 | for(int i = 0; i < 8; i++){ 94 | if(buf[loc+i] != ' '){ 95 | lastChar = i; 96 | } 97 | } 98 | 99 | xpos = current_col*13; 100 | 101 | shouldPrintln = true; 102 | 103 | if(buf[loc+0xB] & 0x10){ //Is a directory 104 | char name[lastChar+2]; 105 | for(int i = 0; i < lastChar+1; i++){ 106 | if(lcfn) //If filename is all lowercase 107 | if(buf[loc+i] > 0x40 && buf[loc+i] < 0x5B) //If current character is a letter 108 | name[i] = buf[loc+i]+32; 109 | else 110 | name[i] = buf[loc+i]; 111 | else 112 | name[i] = buf[loc+i]; 113 | } 114 | name[lastChar+1] = 0; 115 | setColor(0x0a); 116 | if(filtered){ 117 | if(contains(name,filter)) 118 | print(name); 119 | else 120 | shouldPrintln = false; 121 | }else{ 122 | print(name); 123 | } 124 | }else{ //Is a file 125 | char name[lastChar+6]; 126 | for(int i = 0; i < lastChar+1; i++){ 127 | if(lcfn) //If filename is all lowercase 128 | if(buf[loc+i] > 0x40 && buf[loc+i] < 0x5B) //If current character is a letter 129 | name[i] = buf[loc+i]+32; 130 | else 131 | name[i] = buf[loc+i]; 132 | else 133 | name[i] = buf[loc+i]; 134 | } 135 | if(!(buf[loc+8] == ' ' && buf[loc+9] == ' ' && buf[loc+10] == ' ')){ //If there is not no extension 136 | for(int i = 0; i < 3; i++){ 137 | if(lcex) //If extension is all lowercase 138 | if(buf[loc+i+8] > 0x40 && buf[loc+i+8] < 0x5B) //If current character is a letter 139 | name[i+lastChar+2] = buf[loc+8+i]+32; 140 | else 141 | name[i+lastChar+2] = buf[loc+8+i]; 142 | else 143 | name[i+lastChar+2] = buf[loc+8+i]; 144 | } 145 | name[lastChar+5] = 0; 146 | name[lastChar+1] = '.'; 147 | }else{ 148 | name[lastChar+1] = 0; 149 | } 150 | setColor(0x07); 151 | if(filtered){ 152 | if(contains(name,filter)) 153 | print(name); 154 | else 155 | shouldPrintln = false; 156 | }else{ 157 | print(name); 158 | } 159 | } 160 | if(shouldPrintln) 161 | current_row++; 162 | if(current_row >= SCREEN_CHAR_HEIGHT){ 163 | if(current_col == 0){ 164 | for(int i = 0; i <= oypos; i++) 165 | scroll(); 166 | } 167 | current_row = 1; 168 | current_col++; 169 | ypos = 0; 170 | if(current_col*13 >= SCREEN_CHAR_WIDTH){ 171 | current_col = 0; 172 | } 173 | }else{ 174 | if(shouldPrintln) 175 | println(""); 176 | } 177 | }else{ 178 | 179 | } 180 | } 181 | sector++; 182 | if(sector % currentfat32part.sectors_per_cluster == 0){ 183 | ccluster = getNextCluster(ccluster); 184 | if(ccluster >= 0x0FFFFFF8){ 185 | done = true; 186 | } 187 | sector = clusterToLBA(ccluster); 188 | } 189 | } 190 | setColor(0x07); 191 | if(current_col > 0){ 192 | ypos = SCREEN_CHAR_HEIGHT-1; 193 | println(""); 194 | } 195 | } 196 | 197 | void listCurrentDir(char *filter){ 198 | listDir(currentfat32part.current_dir_clust, filter); 199 | } 200 | 201 | uint8_t changeDir(char *dir){ //Returns 0 if success, 1 if is not a directory, and 2 if doesn't exist. 202 | int index = indexOf('/',dir); 203 | uint32_t prevClust = currentfat32part.current_dir_clust; 204 | int s = 0; 205 | int i = 0; 206 | if(index != strlen(dir)){ //If it has a '/' in it 207 | char dirbuf[strlen(dir)]; 208 | if(index == 0){ //If it starts with '/', this means start at the root directory. 209 | currentfat32part.current_dir_clust = currentfat32part.root_dir_clust; 210 | s = 1; 211 | i++; 212 | } 213 | bool done = false; 214 | while(!done){ 215 | index = indexOfn('/', i, dir); 216 | substrr(s, index, dir, dirbuf); 217 | if(index == strlen(dir)){ 218 | done = true; 219 | } 220 | if(s == strlen(dir)) 221 | break; 222 | switch(changeOneDir(dirbuf)){ 223 | case 0: 224 | i++; 225 | s = index+1; 226 | break; 227 | case 1: 228 | currentfat32part.current_dir_clust = prevClust; 229 | return 1; 230 | case 2: 231 | currentfat32part.current_dir_clust = prevClust; 232 | return 2; 233 | } 234 | } 235 | return 0; 236 | }else{ 237 | return changeOneDir(dir); 238 | } 239 | } 240 | 241 | static uint8_t changeOneDir(char *dir){ //Returns 0 if success, 1 if is not a directory, and 2 if doesn't exist. 242 | char folder[indexOf('/',dir)+1]; 243 | substr(indexOf('/',dir), dir, folder); 244 | fat32file file = getFile(folder); 245 | if(exists(file)){ 246 | if(isDirectory(file)){ 247 | if(file.cluster >= currentfat32part.root_dir_clust){ 248 | currentfat32part.current_dir_clust = file.cluster; 249 | }else{ 250 | currentfat32part.current_dir_clust = currentfat32part.root_dir_clust; 251 | } 252 | if(cdir == 0) cdir = String("/"); 253 | if(strcmp(dir,"..")){ 254 | char *tmp = String(cdir); 255 | strfree(cdir); 256 | uint8_t olen = strlen(tmp); 257 | substr(indexOfn('/',countOf('/',tmp)-1, tmp), tmp, tmp); 258 | cdir = String(tmp); 259 | kfree(tmp, olen); 260 | }else if(strcmp(dir,".")){}else{ 261 | if(strcmp(cdir,"/")) cdir[0] = 0; 262 | char *tmp = String(cdir); 263 | strfree(cdir); 264 | cdir = kmalloc(strlen(tmp)+strlen(folder)+1); 265 | strcpy(tmp,cdir); 266 | cdir[strlen(tmp)]='/'; 267 | strcpy(folder,&cdir[strlen(tmp)+1]); 268 | strfree(tmp); 269 | } 270 | if(strcmp(cdir,"")) strcpy("/",cdir); 271 | return 0; 272 | }else{ 273 | return 1; 274 | } 275 | }else{ 276 | return 2; 277 | } 278 | } 279 | 280 | fat32file getFile(char *file){ //If file doesn't have any clusters allocated to it, cluster == 0 and if it doesn't exist, cluster = 0xFFFFFFFF 281 | bool done = false; 282 | uint32_t ccluster = currentfat32part.current_dir_clust; 283 | uint32_t sector = clusterToLBA(ccluster); 284 | uint32_t intbuf = 0; 285 | fat32file ret = {0xFFFFFFFF,0,0}; 286 | while(!done){ 287 | readSector(currentfat32part.disk, sector, buf); 288 | for(uint8_t i = 0; i < 16; i++){ 289 | uint16_t loc = 0x20*i; 290 | bool lcfn = ((buf[loc+0xC] >> 3) & 0x01); //If filename is all lowercase 291 | bool lcex = ((buf[loc+0xC] >> 4) & 0x01); //If extension is all lowercase 292 | if(buf[loc] == 0){ //End of directory 293 | done = true; 294 | i = 16; 295 | }else if(buf[loc] != 0xE5 /*Is not unused*/ 296 | && (buf[loc+0xB] & 0xF) != 0xF /*Is not a long filename entry*/ 297 | && (buf[loc+0xB] & 0x8) == 0 /*Is a file or directory*/){ 298 | uint8_t lastChar = 0; 299 | for(int i = 0; i < 8; i++){ 300 | if(buf[loc+i] != ' '){ 301 | lastChar = i; 302 | } 303 | } 304 | if(buf[loc+0xB] & 0x10){ //Is a directory 305 | char name[lastChar+2]; 306 | for(int i = 0; i < lastChar+1; i++){ 307 | if(lcfn) //If filename is all lowercase 308 | if(buf[loc+i] > 0x40 && buf[loc+i] < 0x5B) //If current character is a letter 309 | name[i] = buf[loc+i]+32; 310 | else 311 | name[i] = buf[loc+i]; 312 | else 313 | name[i] = buf[loc+i]; 314 | } 315 | name[lastChar+1] = 0; 316 | if(strcmp(name,file) && !done){ 317 | intbuf = 0; 318 | intbuf += ((uint32_t)buf[loc+0x14] << 16); 319 | intbuf += ((uint32_t)buf[loc+0x15] << 24); 320 | intbuf += ((uint32_t)buf[loc+0x1A]); 321 | intbuf += ((uint32_t)buf[loc+0x1B] << 8); 322 | ret.cluster = intbuf; 323 | intbuf = 0; 324 | intbuf += ((uint32_t)buf[loc+0x1C]); 325 | intbuf += ((uint32_t)buf[loc+0x1D] << 8); 326 | intbuf += ((uint32_t)buf[loc+0x1E] << 16); 327 | intbuf += ((uint32_t)buf[loc+0x1F] << 24); 328 | ret.size = intbuf; 329 | ret.dir_cluster = currentfat32part.current_dir_clust; 330 | ret.attrib = buf[loc+0xB]; 331 | done = true; 332 | } 333 | }else{ //Is a file 334 | char name[lastChar+6]; 335 | for(int i = 0; i < lastChar+1; i++){ 336 | if(lcfn) //If filename is all lowercase 337 | if(buf[loc+i] > 0x40 && buf[loc+i] < 0x5B) //If current character is a letter 338 | name[i] = buf[loc+i]+32; 339 | else 340 | name[i] = buf[loc+i]; 341 | else 342 | name[i] = buf[loc+i]; 343 | } 344 | if(!(buf[loc+8] == ' ' && buf[loc+9] == ' ' && buf[loc+10] == ' ')){ //If there is not no extension 345 | for(int i = 0; i < 3; i++){ 346 | if(lcex) //If extension is all lowercase 347 | if(buf[loc+i+8] > 0x40 && buf[loc+i+8] < 0x5B) //If current character is a letter 348 | name[i+lastChar+2] = buf[loc+8+i]+32; 349 | else 350 | name[i+lastChar+2] = buf[loc+8+i]; 351 | else 352 | name[i+lastChar+2] = buf[loc+8+i]; 353 | } 354 | name[lastChar+5] = 0; 355 | name[lastChar+1] = '.'; 356 | }else{ 357 | name[lastChar+1] = 0; 358 | } 359 | if(strcmp(name,file) && !done){ 360 | intbuf = 0; 361 | intbuf += ((uint32_t)buf[loc+0x14] << 16); 362 | intbuf += ((uint32_t)buf[loc+0x15] << 24); 363 | intbuf += ((uint32_t)buf[loc+0x1A]); 364 | intbuf += ((uint32_t)buf[loc+0x1B] << 8); 365 | ret.cluster = intbuf; 366 | intbuf = 0; 367 | intbuf += ((uint32_t)buf[loc+0x1C]); 368 | intbuf += ((uint32_t)buf[loc+0x1D] << 8); 369 | intbuf += ((uint32_t)buf[loc+0x1E] << 16); 370 | intbuf += ((uint32_t)buf[loc+0x1F] << 24); 371 | ret.size = intbuf; 372 | ret.dir_cluster = currentfat32part.current_dir_clust; 373 | ret.attrib = buf[loc+0xB]; 374 | done = true; 375 | } 376 | } 377 | }else{ 378 | 379 | } 380 | } 381 | sector++; 382 | if(sector % currentfat32part.sectors_per_cluster == 0){ 383 | ccluster = getNextCluster(ccluster); 384 | sector = clusterToLBA(ccluster); 385 | if(ccluster >= 0x0FFFFFF8){ 386 | done = true; 387 | } 388 | } 389 | } 390 | return ret; 391 | } 392 | 393 | bool isDirectory(fat32file file){ 394 | return file.attrib & 0x10; 395 | } 396 | 397 | bool exists(fat32file file){ 398 | return file.cluster != 0xFFFFFFFF; 399 | } 400 | 401 | uint32_t getClusterChainSize(uint32_t cluster){ 402 | bool done = false; 403 | uint32_t ccluster = cluster; 404 | uint16_t cbyte; 405 | uint32_t nextCluster = 0; 406 | uint32_t chain_size = 0; 407 | while(!done){ 408 | chain_size++; 409 | nextCluster = 0; 410 | readSector(currentfat32part.disk, getFATSectorForCluster(ccluster), buf2); 411 | cbyte = (ccluster % 128)*4; 412 | nextCluster += ((uint32_t)buf2[cbyte]); 413 | nextCluster += ((uint32_t)buf2[cbyte+1] << 8); 414 | nextCluster += ((uint32_t)buf2[cbyte+2] << 16); 415 | nextCluster += (((uint32_t)buf2[cbyte+3] & 0xF) << 24); // & 0xF is because we are ignoring the top 4 bits because they are reserved 416 | if(nextCluster >= 0x0FFFFFF8){ 417 | done = true; 418 | } 419 | ccluster = nextCluster; 420 | } 421 | return chain_size; 422 | } 423 | 424 | uint32_t getNextCluster(uint32_t cluster){ 425 | readSector(currentfat32part.disk, getFATSectorForCluster(cluster), buf2); 426 | uint16_t cbyte = (cluster % 128)*4; 427 | uint32_t ret = 0; 428 | ret += ((uint32_t)buf2[cbyte]); 429 | ret += ((uint32_t)buf2[cbyte+1] << 8); 430 | ret += ((uint32_t)buf2[cbyte+2] << 16); 431 | ret += (((uint32_t)buf2[cbyte+3] & 0xF) << 24); // & 0xF is because we are ignoring the top 4 bits because they are reserved 432 | return ret; 433 | } 434 | 435 | void printFileContents(fat32file file){ 436 | if(exists(file)){ 437 | if(isDirectory(file)){ 438 | println("File is a directory."); 439 | return; 440 | } 441 | bool done = false; 442 | uint32_t ccluster = file.cluster; 443 | while(!done){ 444 | for(int j = 0; j < currentfat32part.sectors_per_cluster; j++){ 445 | readSector(currentfat32part.disk, clusterToLBA(ccluster)+j, buf2); 446 | for(int i = 0; i < 256; i++){ 447 | if(buf2[i] != 0) 448 | putch(buf2[i]); 449 | } 450 | } 451 | ccluster = getNextCluster(ccluster); 452 | if(ccluster >= 0x0FFFFFF8) 453 | done = true; 454 | } 455 | println(""); 456 | } 457 | } 458 | 459 | fat32part getCurrentFat32Part(){ 460 | return currentfat32part; 461 | } 462 | 463 | //Please ignore how horrible this is atm 464 | //This is a VERY VERY VERY rudimentary executable implementation 465 | //Executables run in kernel space, and they are put into the main kernel heap. 466 | //I will definitely make a better system sometime in the future (Maybe *MAYBE* Elf loading) where programs run in userspace 467 | //and don't use a horrible system for memory allocation. But for now this is what we have. 468 | 469 | uint8_t prog[0x1000] __attribute__((aligned(0x1000))); //MAX 4KiB program size 470 | 471 | void executeFile(fat32file file){ 472 | if(exists(file)){ 473 | if(isDirectory(file)){ 474 | println("File is a directory."); 475 | return; 476 | }else if(file.size > 0x1000){ 477 | println("Executable is too large. (More than 4KiB)"); 478 | println("This is stupid, I know."); 479 | return; 480 | } 481 | bool done = false; 482 | uint32_t ccluster = file.cluster; 483 | uint32_t csector = 0; 484 | while(!done){ 485 | for(int j = 0; j < currentfat32part.sectors_per_cluster; j++){ 486 | readSector(currentfat32part.disk, clusterToLBA(ccluster)+j, &prog[csector*512]); 487 | csector++; 488 | } 489 | ccluster = getNextCluster(ccluster); 490 | if(ccluster >= 0x0FFFFFF8) 491 | done = true; 492 | } 493 | exec(prog); 494 | println(""); 495 | } 496 | } 497 | 498 | void printCurrentDir(){ 499 | if(cdir == 0) cdir = String("/"); 500 | println(cdir); 501 | return; 502 | } 503 | 504 | uint32_t getFATSectorForCluster(uint32_t cluster){ 505 | return currentfat32part.fat_sect+((cluster * 4) / 512); 506 | } 507 | 508 | uint32_t getClusterOfEntry(uint8_t *entry){ 509 | return (((uint32_t)(entry[0x1A])))+(((uint32_t)(entry[0x1B])) << 8)+(((uint32_t)(entry[0x14])) << 16)+(((uint32_t)(entry[0x15])) << 24); 510 | } 511 | 512 | void setCurrentFat32part(fat32part p){ 513 | currentfat32part = p; 514 | } 515 | 516 | uint32_t clusterToLBA(uint32_t cluster){ 517 | return currentfat32part.cluster_begin_sect+(currentfat32part.sectors_per_cluster * (cluster-2)); 518 | } 519 | 520 | uint32_t clusterToLBAOther(fat32part p, uint32_t cluster){ 521 | return p.cluster_begin_sect+(p.sectors_per_cluster * (cluster-2)); 522 | } 523 | -------------------------------------------------------------------------------- /src/kernel/gdt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define GDT_ENTRIES 5 5 | GDTEntry gdt[GDT_ENTRIES]; 6 | GDTPointer gp; 7 | 8 | extern void gdt_flush(); 9 | 10 | void gdt_set_gate(uint32_t num, uint16_t limit, uint32_t base, uint8_t access, uint8_t gran){ 11 | gdt[num].base_low = (base & 0xFFFF); 12 | gdt[num].base_middle = (base >> 16) & 0xFF; 13 | gdt[num].base_high = (base >> 24) & 0xFF; 14 | 15 | gdt[num].limit = limit; 16 | gdt[num].granularity = gran; 17 | 18 | gdt[num].access = access; 19 | } 20 | void load_gdt(){ 21 | gp.limit = (sizeof(GDTEntry) * GDT_ENTRIES) - 1; 22 | gp.base = (uint32_t)&gdt; 23 | 24 | gdt_set_gate(0, 0, 0, 0, 0); //Null 25 | gdt_set_gate(1, 0xFFFF, 0, 0b10011010, 0b11001111); //Kernel Code 26 | gdt_set_gate(2, 0xFFFF, 0, 0b10010010, 0b11001111); //Kernel Data 27 | gdt_set_gate(3, 0xFFFF, 0, 0b11111010, 0b11001111); //User code 28 | gdt_set_gate(4, 0xFFFF, 0, 0b11110010, 0b11001111); //User data 29 | 30 | gdt_flush(); 31 | } 32 | -------------------------------------------------------------------------------- /src/kernel/heap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | uint8_t heap_space[0x100000]; //1MiB of heap space 6 | uint8_t frames[0x2000]; //16byte Frames, 1 bit each. 1 = used, 0 = free 7 | Frame frbuf; 8 | FrameSet frsbuf; 9 | 10 | void init_heap(){ 11 | for(int i = 0; i < 0x2000; i++){ 12 | frames[i] = 0; 13 | } 14 | } 15 | 16 | Frame first_available_frame(){ 17 | for(int i = 0; i < 0x2000; i++){ 18 | for(int j = 0; j < 8; j++){ 19 | if(!(frames[i] >> j & 1)){ 20 | frbuf.num = i*8+j; 21 | frbuf.set = i; 22 | frbuf.pos = j; 23 | return frbuf; 24 | } 25 | } 26 | } 27 | PANIC("NO_HEAP_SPACE","The heap ran out of memory.",true); 28 | } 29 | 30 | FrameSet first_available_frameset(uint32_t len){ //len is the amount of 16byte frames, not bytes. 31 | uint32_t numFrames = 0; 32 | for(int i = 0; i < 0x2000; i++){ 33 | for(int j = 0; j < 8; j++){ 34 | if(!(frames[i] >> j & 1)){ 35 | if(numFrames == 0){ 36 | frbuf.num = i*8+j; 37 | frbuf.set = i; 38 | frbuf.pos = j; 39 | } 40 | numFrames++; 41 | }else{ 42 | numFrames = 0; 43 | } 44 | if(numFrames == len){ 45 | frsbuf.start = frbuf; 46 | frsbuf.len = numFrames; 47 | return frsbuf; 48 | } 49 | } 50 | } 51 | PANIC("NO_VAR_SPACE","The heap doesn't have enough consecutive frames to fit a variable.",false); 52 | print("Variable size: ~"); printHexl(len*16); println("bytes"); 53 | while(true); 54 | } 55 | 56 | FrameSet fsalloc(uint32_t len){ 57 | first_available_frameset(len); 58 | Frame buf; 59 | for(int i = 0; i < frsbuf.len; i++){ 60 | buf = getFrame(i+frsbuf.start.num); 61 | frames[buf.set] |= 1 << buf.pos; 62 | } 63 | FrameSet fs; 64 | fs.start = getFrame(frsbuf.start.num); 65 | fs.len = len; 66 | return fs; 67 | } 68 | 69 | Frame getFrame(uint32_t i){ 70 | Frame f; 71 | f.set = i/8; 72 | f.pos = i%8; 73 | f.num = i; 74 | return f; 75 | } 76 | 77 | Frame falloc(){ 78 | first_available_frame(); 79 | frames[frbuf.set] = frames[frbuf.set] | (1 << frbuf.pos); 80 | Frame f; 81 | f.set = frbuf.set; 82 | f.num = frbuf.num; 83 | f.pos = frbuf.pos; 84 | return frbuf; 85 | } 86 | 87 | void ffree(Frame f){ 88 | frames[f.set] &= ~(1 << f.pos); 89 | } 90 | 91 | void *kmalloc(uint32_t len){ 92 | frsbuf = fsalloc(len/0x10+1); 93 | return &heap_space[frsbuf.start.num*0x10]; 94 | } 95 | 96 | uint32_t kfreebuf; 97 | 98 | void kfree(void *ptr, uint32_t len){ 99 | kfreebuf = (uint32_t)ptr-(uint32_t)&heap_space; 100 | kfreebuf/=0x10; 101 | for(int i = 0; i < len/0x10+1; i++){ 102 | frbuf = getFrame(i+kfreebuf); 103 | ffree(frbuf); 104 | } 105 | } 106 | 107 | char *String(char *str){ 108 | char* str1 = kmalloc(strlen(str)+1); 109 | strcpy(str,str1); 110 | return str1; 111 | } 112 | 113 | void strfree(char *str){ 114 | kfree(str, strlen(str)+1); 115 | } 116 | -------------------------------------------------------------------------------- /src/kernel/idt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct IDTEntry idt[256]; 5 | struct IDTPointer idtp; 6 | 7 | void idt_set_gate(uint8_t num, uint32_t loc, uint16_t selector, uint8_t attrs){ 8 | idt[num].offset_low = (loc & 0xFFFF); 9 | idt[num].offset_high = (loc >> 16) & 0xFFFF; 10 | idt[num].selector = selector; 11 | idt[num].zero = 0; 12 | idt[num].attrs = attrs; 13 | } 14 | 15 | void register_idt(){ 16 | idtp.size = (sizeof(struct IDTEntry) * 256) - 1; 17 | idtp.offset = (int)&idt; 18 | 19 | memset(&idt, 0, sizeof(struct IDTEntry) * 256); 20 | 21 | idt_load(); 22 | } -------------------------------------------------------------------------------- /src/kernel/irq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void *irq_routines[16] = { 7 | 0,0,0,0,0,0,0,0, 8 | 0,0,0,0,0,0,0,0 9 | }; 10 | 11 | void irq_add_handler(int irq, void (*handler)(struct registers *r)){ 12 | irq_routines[irq] = handler; 13 | } 14 | 15 | void irq_remove_handler(int irq){ 16 | irq_routines[irq] = 0; 17 | } 18 | 19 | void irq_remap(){ 20 | outb(0x20, 0x11); 21 | outb(0xA0, 0x11); 22 | outb(0x21, 0x20); 23 | outb(0xA1, 0x28); 24 | outb(0x21, 0x04); 25 | outb(0xA1, 0x02); 26 | outb(0x21, 0x01); 27 | outb(0xA1, 0x01); 28 | outb(0x21, 0x0); 29 | outb(0xA1, 0x0); 30 | } 31 | 32 | void irq_init(){ 33 | irq_remap(); 34 | idt_set_gate(32, (unsigned)irq0, 0x08, 0x8E); 35 | idt_set_gate(33, (unsigned)irq1, 0x08, 0x8E); 36 | idt_set_gate(34, (unsigned)irq2, 0x08, 0x8E); 37 | idt_set_gate(35, (unsigned)irq3, 0x08, 0x8E); 38 | idt_set_gate(36, (unsigned)irq4, 0x08, 0x8E); 39 | idt_set_gate(37, (unsigned)irq5, 0x08, 0x8E); 40 | idt_set_gate(38, (unsigned)irq6, 0x08, 0x8E); 41 | idt_set_gate(39, (unsigned)irq7, 0x08, 0x8E); 42 | idt_set_gate(40, (unsigned)irq8, 0x08, 0x8E); 43 | idt_set_gate(41, (unsigned)irq9, 0x08, 0x8E); 44 | idt_set_gate(42, (unsigned)irq10, 0x08, 0x8E); 45 | idt_set_gate(43, (unsigned)irq11, 0x08, 0x8E); 46 | idt_set_gate(44, (unsigned)irq12, 0x08, 0x8E); 47 | idt_set_gate(45, (unsigned)irq13, 0x08, 0x8E); 48 | idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E); 49 | idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E); 50 | } 51 | 52 | void irq_handler(struct registers *r){ 53 | void (*handler)(struct registers *r); 54 | 55 | handler = irq_routines[r->num - 32]; 56 | if(handler /*If it is not 0, AKA it is registered*/){ 57 | handler(r); 58 | } 59 | 60 | if(r->num >= 40){ 61 | outb(0xA0, 0x20); //If it is greater than 40, send an end of interrupt to slave controller 62 | } 63 | 64 | outb(0x20, 0x20); //Send EOI to controller 65 | } 66 | -------------------------------------------------------------------------------- /src/kernel/isr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void isr_init(){ 9 | idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E); 10 | idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E); 11 | idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E); 12 | idt_set_gate(3, (unsigned)isr3, 0x08, 0x8E); 13 | idt_set_gate(4, (unsigned)isr4, 0x08, 0x8E); 14 | idt_set_gate(5, (unsigned)isr5, 0x08, 0x8E); 15 | idt_set_gate(6, (unsigned)isr6, 0x08, 0x8E); 16 | idt_set_gate(7, (unsigned)isr7, 0x08, 0x8E); 17 | idt_set_gate(8, (unsigned)isr8, 0x08, 0x8E); 18 | idt_set_gate(9, (unsigned)isr9, 0x08, 0x8E); 19 | idt_set_gate(10, (unsigned)isr10, 0x08, 0x8E); 20 | idt_set_gate(11, (unsigned)isr11, 0x08, 0x8E); 21 | idt_set_gate(12, (unsigned)isr12, 0x08, 0x8E); 22 | idt_set_gate(13, (unsigned)isr13, 0x08, 0x8E); 23 | idt_set_gate(14, (unsigned)isr14, 0x08, 0x8E); 24 | idt_set_gate(15, (unsigned)isr15, 0x08, 0x8E); 25 | idt_set_gate(16, (unsigned)isr16, 0x08, 0x8E); 26 | idt_set_gate(17, (unsigned)isr17, 0x08, 0x8E); 27 | idt_set_gate(18, (unsigned)isr18, 0x08, 0x8E); 28 | idt_set_gate(19, (unsigned)isr19, 0x08, 0x8E); 29 | idt_set_gate(20, (unsigned)isr20, 0x08, 0x8E); 30 | idt_set_gate(21, (unsigned)isr21, 0x08, 0x8E); 31 | idt_set_gate(22, (unsigned)isr22, 0x08, 0x8E); 32 | idt_set_gate(23, (unsigned)isr23, 0x08, 0x8E); 33 | idt_set_gate(24, (unsigned)isr24, 0x08, 0x8E); 34 | idt_set_gate(25, (unsigned)isr25, 0x08, 0x8E); 35 | idt_set_gate(26, (unsigned)isr26, 0x08, 0x8E); 36 | idt_set_gate(27, (unsigned)isr27, 0x08, 0x8E); 37 | idt_set_gate(28, (unsigned)isr28, 0x08, 0x8E); 38 | idt_set_gate(29, (unsigned)isr29, 0x08, 0x8E); 39 | idt_set_gate(30, (unsigned)isr30, 0x08, 0x8E); 40 | idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E); 41 | } 42 | 43 | bool fpanic(char *a, char *b, uint32_t sig){ 44 | if(getCurrentProcess()->pid == 1){ 45 | cli(); 46 | PANIC(a,b,false); 47 | return true; 48 | }else{ 49 | notify(sig); 50 | return false; 51 | } 52 | } 53 | 54 | void fault_handler(struct registers *r){ 55 | if(r->num < 32){ 56 | switch(r->num){ 57 | case 0: 58 | if(fpanic("DIVIDE_BY_ZERO", "Instruction pointer:", SIGILL)){ 59 | printHexl(r->err_code); 60 | while(true); 61 | } 62 | break; 63 | 64 | case 13: //GPF 65 | if(fpanic("GENERAL_PROTECTION_FAULT", "Instruction pointer, error code, and registers:", SIGILL)){ 66 | print_regs(r); 67 | while(true); 68 | } 69 | break; 70 | 71 | case 14: //Page fault 72 | if(getCurrentProcess()->pid == 1) 73 | pageFaultHandler(r); 74 | else 75 | notify(SIGILL); 76 | break; 77 | 78 | default: 79 | if(fpanic("Something weird happened.", "Fault and Instruction pointer:", SIGILL)){ 80 | printHex(r->num); 81 | print(" and "); 82 | printHexl(r->err_code); 83 | while(true); 84 | } 85 | break; 86 | } 87 | } 88 | } 89 | 90 | void print_regs(struct registers *r){ 91 | asm volatile("mov %%ss, %%eax":"=a"(r->ss)); 92 | printf("eip:0x%X err:%d\n", r->eip, r->err_code); 93 | printf("cs:0x%X ds:0x%X es:0x%X gs:0x%X fs:0x%X ss:0x%X\n",r->cs,r->ds,r->es,r->gs,r->fs,r->ss); 94 | printf("e?x: a:0x%X b:0x%X c:0x%X d:0x%X\n",r->eax,r->ebx,r->ecx,r->edx); 95 | printf("edi: 0x%X esi: 0x%X ebp: 0x%X\n",r->edi,r->esi,r->ebp); 96 | printf("EFLAGS: 0x%X",r->eflags); 97 | } 98 | -------------------------------------------------------------------------------- /src/kernel/keyboard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | bool shift = 0; 6 | char kbdbuf[256]; 7 | volatile bool input_mode = false; 8 | volatile bool input_done = false; 9 | uint8_t input_i; 10 | volatile bool shell_mode = false; 11 | 12 | unsigned char kbdus[256] = { 13 | 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */ 14 | '9', '0', '-', '=', '\b', /* Backspace */ 15 | '\t', /* Tab */ 16 | 'q', 'w', 'e', 'r', /* 19 */ 17 | 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */ 18 | 0, /* 29 - Control */ 19 | 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */ 20 | '\'', '`', 0, /* Left shift */ 21 | '\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */ 22 | 'm', ',', '.', '/', 0, /* Right shift */ 23 | '*', 24 | 0, /* Alt */ 25 | ' ', /* Space bar */ 26 | 0, /* Caps lock */ 27 | 0, /* 59 - F1 key ... > */ 28 | 0, 0, 0, 0, 0, 0, 0, 0, 29 | 0, /* < ... F10 */ 30 | 0, /* 69 - Num lock*/ 31 | 0, /* Scroll Lock */ 32 | 0, /* Home key */ 33 | 0, /* Up Arrow */ 34 | 0, /* Page Up */ 35 | '-', 36 | 0, /* Left Arrow */ 37 | 0, 38 | 0, /* Right Arrow */ 39 | '+', 40 | 0, /* 79 - End key*/ 41 | 0, /* Down Arrow */ 42 | 0, /* Page Down */ 43 | 0, /* Insert Key */ 44 | 0, /* Delete Key */ 45 | 0, 0, 0, 46 | 0, /* F11 Key */ 47 | 0, /* F12 Key */ 48 | 0, 49 | 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 50 | '\b', '\t', 51 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 52 | 0, 53 | 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', 54 | '\"', '~', 0, '|', 55 | 'Z', 'X', 'C', 'V', 'B', 'N', 'M', 56 | '<', '>', '?', 0, '*', 57 | 0, /* Alt */ 58 | ' ', /* Space bar */ 59 | 0, /* Caps lock */ 60 | 0, /* 59 - F1 key ... > */ 61 | 0, 0, 0, 0, 0, 0, 0, 0, 62 | 0, /* < ... F10 */ 63 | 0, /* 69 - Num lock*/ 64 | 0, /* Scroll Lock */ 65 | 0, /* Home key */ 66 | 0, /* Up Arrow */ 67 | 0, /* Page Up */ 68 | '-', 69 | 0, /* Left Arrow */ 70 | 0, 71 | 0, /* Right Arrow */ 72 | '+', 73 | 0, /* 79 - End key*/ 74 | 0, /* Down Arrow */ 75 | 0, /* Page Down */ 76 | 0, /* Insert Key */ 77 | 0, /* Delete Key */ 78 | 0, 0, 0, 79 | 0, /* F11 Key */ 80 | 0, /* F12 Key */ 81 | 0 82 | 83 | }; 84 | 85 | void keyboard_handler(struct registers *r){ 86 | uint8_t scancode; 87 | 88 | scancode = inb(0x60); 89 | 90 | if (scancode & 0x80){ 91 | if(scancode == 0xAA) 92 | shift = false; 93 | }else{ 94 | if(scancode == 0x2a){shift = 1;return;} 95 | if(scancode == 0x1c){ 96 | putch('\n'); 97 | if(input_mode) 98 | input_done = true; 99 | return; 100 | } 101 | if(scancode == 0x0e){ 102 | if(shell_mode){ 103 | if(input_i > 0){ 104 | backspace(); 105 | } 106 | }else{ 107 | backspace(); 108 | } 109 | 110 | if(input_mode && input_i > 0) 111 | input_i--; 112 | 113 | return; 114 | } 115 | if(isACharacter(kbdus[scancode])){ 116 | if(shift){ 117 | putch(kbdus[scancode+90]); 118 | if(input_mode){ 119 | kbdbuf[input_i] = kbdus[scancode+90]; 120 | input_i++; 121 | } 122 | }else{ 123 | putch(kbdus[scancode]); 124 | if(input_mode){ 125 | kbdbuf[input_i] = kbdus[scancode]; 126 | input_i++; 127 | } 128 | } 129 | } 130 | } 131 | } 132 | 133 | void getInput(){ //Puts characters into kbdbuf until enter is pressed or you reach 255 characters 134 | input_mode = true; 135 | input_done = false; 136 | input_i = 0; 137 | while(!input_done && input_i < 255){} 138 | kbdbuf[input_i] = '\0'; 139 | input_mode = false; 140 | } -------------------------------------------------------------------------------- /src/kernel/kmain.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | int i; 22 | filesystem_t fs = {}; 23 | 24 | int kmain(uint32_t mbootptr){ 25 | load_gdt(); 26 | interrupts_init(); 27 | setupPaging(); 28 | init_heap(); 29 | parse_mboot(mbootptr+HIGHER_HALF); 30 | clearScreen(); 31 | center_print("Now in 32-bit protected mode!",0x07); 32 | //drawMonoBitmap(logo,320,50,0,0,0x2f); 33 | //ypos = 7; 34 | uint8_t sect[512]; 35 | readSector(boot_disk, 0, sect); 36 | if(sect[1] == 0xFF){ 37 | println_color("WARNING: I think you may be booting codeOS2 off of a USB drive or other unsupported device. Disk reading functions may not work.",0x0C); 38 | } 39 | uint32_t fp = getFirstPartition(boot_disk); 40 | if(isPartitionExt2(boot_disk,fp)){ 41 | println("Partition is ext2!"); 42 | }else{ 43 | println("Partition is not ext2!"); 44 | while(true); 45 | } 46 | ext2_superblock sb = {}; 47 | getExt2Superblock(boot_disk,fp,&sb); 48 | if(sb.version_major < 1){ 49 | printf("Unsupported ext2 version %d.%d. Must be at least 1.", sb.version_major, sb.version_minor); 50 | while(true); 51 | } 52 | ext2_partition ext2 = {}; 53 | device_t dev = {boot_disk}; 54 | initExt2Partition(fp,&dev,&sb,&ext2,&fs); 55 | if(ext2_getSuperblock(&ext2)->inode_size != 128){ 56 | printf("Unsupported inode size %d. codeOS2 only supports an inode size of 128 at this time.", ext2_getSuperblock(&ext2)->inode_size); 57 | } 58 | initTasking(); 59 | //shell(&fs); 60 | } 61 | 62 | //called from kthread 63 | void kmain_late(){ 64 | initShell(&fs); 65 | addProcess(createProcess("shell",(uint32_t)shell)); 66 | while(getProcess(2)); 67 | printf("\n\nShell exited.\n\n"); 68 | while(1); 69 | PANIC("Kernel process stopped!","That should not happen.",true); 70 | __kill__(); 71 | } 72 | 73 | void parse_mboot(uint32_t addr){ 74 | struct multiboot_tag *tag; 75 | for (tag = (struct multiboot_tag *) (addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag *) ((multiboot_uint8_t *) tag + ((tag->size + 7) & ~7))){ 76 | switch (tag->type){ 77 | case MULTIBOOT_TAG_TYPE_BOOTDEV: 78 | boot_disk = (uint8_t)(((struct multiboot_tag_bootdev *) tag)->biosdev & 0xFF); 79 | break; 80 | } 81 | } 82 | } 83 | 84 | void interrupts_init(){ 85 | register_idt(); 86 | isr_init(); 87 | idt_set_gate(0x80, (unsigned)syscall_handler, 0x08, 0x8E); 88 | idt_set_gate(0x81, (unsigned)preempt, 0x08, 0x8E); //for preempting without PIT 89 | irq_add_handler(1, keyboard_handler); 90 | //irq_add_handler(0, pit_handler); 91 | pit_init(200); 92 | irq_init(); 93 | asm volatile("sti"); 94 | } 95 | -------------------------------------------------------------------------------- /src/kernel/paging.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | uint32_t page_directory[1024] __attribute__((aligned(4096))); 7 | uint32_t exec_page_table[1024] __attribute__((aligned(4096))); 8 | #define krnlstartPhys = &kernelstart-HIGHER_HALF; 9 | #define krnlendPhys = &krnlend-HIGHER_HALF; 10 | extern uint32_t BootPageDirectory; 11 | 12 | void setupPaging(){ 13 | uint32_t i,j; 14 | page_directory[0]= 0x83; 15 | for(i = 1; i < (HIGHER_HALF >> 22); i++){ 16 | page_directory[i] = 0x0; 17 | } 18 | page_directory[i] = 0x83; 19 | i++; 20 | for(i=i; i < 1024; i++){ 21 | page_directory[i] = 0; 22 | } 23 | uint32_t *d = (uint32_t*)0x1000; 24 | load_page_dir((uint32_t *)((uint32_t)&page_directory[0]-HIGHER_HALF)); 25 | } 26 | 27 | void exec(uint8_t *prog){ 28 | exec_page_table[0] = ((uint32_t)&prog[0]-HIGHER_HALF) | 0x3; 29 | page_directory[0] = ((uint32_t)&exec_page_table[0]-HIGHER_HALF) | 0x3; 30 | load_page_dir((uint32_t *)((uint32_t)&page_directory[0]-HIGHER_HALF)); 31 | ((void(*)())0)(); 32 | exec_page_table[0] = 0x83; 33 | load_page_dir((uint32_t *)((uint32_t)&page_directory[0]-HIGHER_HALF)); 34 | } 35 | 36 | void pageFaultHandler(struct registers *r){ 37 | cli(); 38 | //uint32_t err_pos; 39 | //asm("mov %0, %%cr2" : "=r" (err_pos)); 40 | bool other = false; 41 | switch(r->err_code){ 42 | case 0: 43 | case 1: 44 | PANIC("KRNL_READ_NONPAGED_AREA", "", false); 45 | break; 46 | case 2: 47 | case 3: 48 | PANIC("KRNL_WRITE_NONPAGED_AREA", "", false); 49 | break; 50 | case 4: 51 | case 5: 52 | PANIC("USR_READ_NONPAGED_AREA", "", false); 53 | break; 54 | case 6: 55 | case 7: 56 | PANIC("USR_WRITE_NONPAGED_AREA", "", false); 57 | break; 58 | default: 59 | PANIC("UNKNOWN_PAGE_FAULT", "", false); 60 | other = true; 61 | break; 62 | } 63 | 64 | //printf("At 0x%X\n\n",err_pos); 65 | print_regs(r); 66 | while(true); 67 | } 68 | -------------------------------------------------------------------------------- /src/kernel/pci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | uint16_t PCIReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset){ 6 | uint32_t address; 7 | uint32_t lbus = (uint32_t)bus; 8 | uint32_t lslot = (uint32_t)slot; 9 | uint32_t lfunc = (uint32_t)func; 10 | uint16_t tmp = 0; 11 | address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | ((uint32_t)0x80000000)); 12 | outl(0xCF8, address); 13 | tmp = (uint16_t)((inl(0xCFC) >> ((offset & 2) * 8)) & 0xffff); 14 | return (tmp); 15 | } 16 | 17 | uint16_t getPCIVendor(uint8_t bus, uint8_t slot, uint8_t function){ 18 | uint16_t vendor, device; 19 | vendor = PCIReadWord(bus, slot, function, 0); 20 | if(vendor != 0xFFFF){ 21 | //The device exists if the vendor is not 0xFFFF 22 | device = PCIReadWord(bus, slot, 0, 2); 23 | //Then we can do other stuff here 24 | } 25 | return vendor; 26 | } 27 | 28 | PCIDevice getPCIDevice(uint8_t tclass, uint8_t tsubclass, uint8_t tprogIF){ 29 | uint16_t classAndSub; 30 | uint8_t class; 31 | uint8_t subclass; 32 | uint8_t progIF; 33 | PCIDevice pcidevice = {.bus=0,.slot=0,.flags=0}; 34 | bool foundDevice = 0; 35 | for(int bus = 0; bus < 256; bus++){ 36 | for(int device = 0; device < 32; device++){ 37 | if(getPCIVendor(bus, device, 0) != 0xFFFF){ 38 | classAndSub = PCIReadWord(bus, device, 0, 10); 39 | class = (uint8_t)(classAndSub >> 8); 40 | subclass = (uint8_t)classAndSub; 41 | progIF = (uint8_t)(PCIReadWord(bus,device,0,8) >> 8); 42 | if(class == tclass && subclass == tsubclass && progIF == tprogIF){ 43 | if(!foundDevice){ 44 | pcidevice.bus = bus; 45 | pcidevice.slot = device; 46 | pcidevice.flags = pcidevice.flags | 0b00000001; 47 | }else{ 48 | pcidevice.flags = pcidevice.flags | 0b00000010; 49 | } 50 | } 51 | } 52 | } 53 | } 54 | return pcidevice; 55 | } 56 | 57 | void PCIDebug(){ 58 | println("Checking all PCI buses..."); 59 | for(int bus = 0; bus < 256; bus++){ 60 | for(int device = 0; device < 32; device++){ 61 | if(getPCIVendor(bus, device, 0) != 0xFFFF){ 62 | print("Found "); 63 | uint16_t classAndSub = PCIReadWord(bus, device, 0, 10); 64 | printPCIClassCode((uint8_t)(classAndSub >> 8), (uint8_t)classAndSub, (uint8_t)(PCIReadWord(bus, device, 0, 8) >> 8)); 65 | print(" at "); 66 | printHex(bus); 67 | print(","); 68 | printHex(device); 69 | if(((uint8_t)(PCIReadWord(bus,device,0,14) & 0xFF)) & 0x80 != 0){ 70 | print(" With Multiple functions"); 71 | /*for(uint8_t func = 0; func < 8; func++){ 72 | if(getPCIVendor(bus,device,func) != 0xFFFF){ 73 | classAndSub = PCIReadWord(bus, device, func, 10); 74 | printPCIClassCode((uint8_t)(classAndSub >> 8), (uint8_t)classAndSub, (uint8_t)(PCIReadWord(bus, device, func, 8) >> 8)); 75 | print(","); 76 | } 77 | }*/ 78 | } 79 | println(""); 80 | } 81 | } 82 | } 83 | println("Done!"); 84 | } 85 | 86 | void printPCIClassCode(uint8_t classCode, uint8_t subClass, uint8_t progIF){ 87 | switch(classCode){ 88 | case 0x1: 89 | print("Mass Storage Controller"); 90 | break; 91 | case 0x2: 92 | print("Network Controller"); 93 | break; 94 | case 0x3: 95 | print("Display Controller"); 96 | break; 97 | case 0x04: 98 | print("Multimedia Controller"); 99 | break; 100 | case 0x05: 101 | print("Memory Controller"); 102 | break; 103 | case 0x06: 104 | print("Bridge Device"); 105 | break; 106 | case 0x07: 107 | print("Simple Communication Controller"); 108 | break; 109 | case 0x08: 110 | print("Base System Peripheral"); 111 | break; 112 | case 0x09: 113 | print("Input Device"); 114 | break; 115 | case 0x0A: 116 | print("Docking Station"); 117 | break; 118 | case 0x0B: 119 | print("Processor"); 120 | break; 121 | case 0x0c: 122 | print("Serial Bus Controller"); 123 | break; 124 | case 0x0D: 125 | print("Wireless Controller"); 126 | break; 127 | case 0x0E: 128 | print("Intelligent IO Controller"); 129 | break; 130 | case 0x0F: 131 | print("Satellite Communication Controller"); 132 | break; 133 | case 0x10: 134 | print("Encryption Controller"); 135 | break; 136 | case 0x11: 137 | print("Data Acquisition and Signal Processing Controller"); 138 | break; 139 | default: 140 | print("Other Device ("); 141 | printHex(classCode); 142 | print(")"); 143 | break; 144 | } 145 | print(" (Sub "); 146 | printHex(subClass); 147 | print(","); 148 | printHex(progIF); 149 | print(")"); 150 | } -------------------------------------------------------------------------------- /src/kernel/pit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern bool tasking_enabled; 7 | 8 | void pit_handler(){ 9 | asm volatile("pusha"); 10 | outb(0x20, 0x20); 11 | asm volatile("popa"); 12 | //asm volatile("iret"); 13 | } 14 | 15 | static inline void pit_send_data(uint16_t data, uint8_t counter){ 16 | uint8_t port = (counter==0) ? PIT_COUNTER0 : ((counter==1) ? PIT_COUNTER1 : PIT_COUNTER2); 17 | outb(port, (uint8_t)data); 18 | } 19 | 20 | void pit_init(uint32_t frequency){ 21 | uint16_t divisor = (uint16_t)( 1193181 / (uint16_t)frequency); 22 | 23 | uint8_t ocw = 0; 24 | ocw = (ocw & ~0xE) | 0x6; 25 | ocw = (ocw & ~0x30) | 0x30; 26 | ocw = (ocw & ~0xC0) | 0; 27 | outb(PIT_CMD, ocw); 28 | 29 | // set frequency rate 30 | pit_send_data(divisor & 0xff, 0); 31 | pit_send_data((divisor >> 8) & 0xff, 0); 32 | } 33 | -------------------------------------------------------------------------------- /src/kernel/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | char cmdbuf[256]; 10 | char argbuf[256]; 11 | char dirbuf[512]; 12 | char dirbuf2[512]; 13 | bool exitShell = false; 14 | file_t currentDir = {}, fileBuf = {}; 15 | extern bool shell_mode; 16 | extern uint8_t kbdbuf[256]; 17 | filesystem_t *fs; 18 | extern bool tasking_enabled; 19 | 20 | void initShell(filesystem_t *fsp){ 21 | fs = fsp; 22 | fs->getFile("/",¤tDir,fs); 23 | dirbuf[0] = '/'; 24 | dirbuf[1] = '\0'; 25 | } 26 | 27 | void dummy(){ 28 | while(1); 29 | } 30 | 31 | void shell(){ 32 | while(!exitShell){ 33 | printf("codeOS2:%s$ ", dirbuf); 34 | shell_mode = true; 35 | getInput(); 36 | shell_mode = false; 37 | setColor(0x07); 38 | substr(indexOf(' ',kbdbuf), kbdbuf, cmdbuf); 39 | if(indexOf(' ', kbdbuf)+1 <= strlen(kbdbuf)){ 40 | substrr(indexOf(' ', kbdbuf)+1, strlen(kbdbuf), kbdbuf, argbuf); 41 | }else{ 42 | argbuf[0] = 0; 43 | } 44 | command_eval(cmdbuf, argbuf); 45 | setColor(0x0f); 46 | } 47 | __kill__(); 48 | } 49 | 50 | uint8_t prog[0x1000]; 51 | 52 | void progx(){ 53 | exec(prog); 54 | } 55 | 56 | bool findAndExecute(char *cmd, bool wait){ 57 | file_t *file = kmalloc(sizeof(file_t)); 58 | if(fs->getFile(cmd, file, fs) && !file->isDirectory){ 59 | if(file->sectors*512 > 0x1000) 60 | printf("Executable too large.\n"); 61 | else{ 62 | fs->read(file, prog, fs); 63 | process_t *proc = createProcess(cmd, (uint32_t)progx); 64 | uint32_t pid = addProcess(proc); 65 | while(wait && proc->state == PROCESS_ALIVE); 66 | } 67 | kfree(file, sizeof(file_t)); 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | static void command_eval(char *cmd, char *args){ 74 | if(strcmp(cmd,"help")){ 75 | println("ls: List the files in the current directory. Use -h for help."); 76 | println("cd: Change the current directory."); 77 | println("pwd: Print the working directory."); 78 | println("about: Shows some information about the system."); 79 | println("help: Shows this message."); 80 | println("cat: Prints a file's contents."); 81 | println("about: Prints some information."); 82 | //println("partinfo: Prints information about the current partition."); 83 | println("pagefault: Triggers a page fault, in case you wanted to."); 84 | println("tasks: Prints all running tasks."); 85 | println("bg: Run a program in the background."); 86 | println("kill: Kill a program."); 87 | println("dummy: Create a dummy process."); 88 | println("exit: Pretty self explanatory."); 89 | }else if(strcmp(cmd,"ls")){ 90 | if(strcmp(args,"")){ 91 | fs->listDir(¤tDir, fs); 92 | }else{ 93 | /*uint32_t inodeID = ext2_findFile(args, current_inode, inode_buf, ext2); 94 | if(!inodeID) printf("That directory does not exist.\n"); else{ 95 | ext2_inode *inode = kmalloc(sizeof(ext2_inode)); 96 | ext2_readInode(inodeID, inode, ext2); 97 | if((inode->type & 0xF000) != EXT2_DIRECTORY) printf("%s is not a directory.\n",args); else ext2_listDirectory(inodeID, ext2); 98 | }*/ 99 | } 100 | }else if(strcmp(cmd,"cd")){ 101 | strcpy(dirbuf, dirbuf2); 102 | strcat(dirbuf2,args); 103 | strcat(dirbuf2,"/"); 104 | if(!fs->getFile(dirbuf2, &fileBuf, fs)) printf("That directory does not exist.\n"); else{ 105 | if(!fileBuf.isDirectory) printf("%s is not a directory.\n",args); else{ 106 | currentDir = fileBuf; 107 | strcpy(dirbuf2, dirbuf); 108 | } 109 | } 110 | }else if(strcmp(cmd,"pwd")){ 111 | printf("%s\n",dirbuf); 112 | }else if(strcmp(cmd,"about")){ 113 | println("CodeOS2 v0.0"); 114 | }/*else if(strcmp(cmd, "partinfo")){ 115 | printf("Disk: %d\nBlock size: %d (%d sectors)\nBlocks per group: %d (%d block groups)\nInodes per group: %d\nSuperblock sector: %d\nInode table size: %d blocks\nName: %s\n", 116 | ext2->disk, ext2_getBlockSize(ext2), ext2->sectors_per_block, ext2_getSuperblock(ext2)->blocks_per_group, ext2->num_block_groups, ext2_getSuperblock(ext2)->inodes_per_group, ext2->sector+2, ext2->blocks_per_inode_table, ext2_getSuperblock(ext2)->volume_name); 117 | }/*else if(strcmp(cmd, "inode")){ 118 | if(strcmp(args, "")) 119 | printf("Usage: \ninode - prints information about an inode.\n"); 120 | else{ 121 | ext2_inode *inode = kmalloc(sizeof(ext2_inode)); 122 | ext2_readInode(strToInt(args),inode,ext2); 123 | printf("inode %d:\n",strToInt(args)); 124 | printf("inode type: 0x%x\ninode size: 0x%x bytes\n", inode->type, inode->size_lower); 125 | printf("inode flags: %b\n", inode->flags); 126 | } 127 | }*/else if(strcmp(cmd,"cat")){ 128 | file_t file = {}; 129 | strcpy(dirbuf, dirbuf2); 130 | strcat(dirbuf2,args); 131 | strcat(dirbuf2,"/"); 132 | if(fs->getFile(dirbuf2, &file, fs)){ 133 | uint8_t *buf = kmalloc(file.sectors*512); 134 | fs->read(&file, buf, fs); 135 | for(int i = 0; i < file.size; i++) 136 | putch(buf[i]); 137 | kfree(buf, file.sectors*512); 138 | }else{ 139 | printf("Cannot find %s.\n",args); 140 | } 141 | }else if(strcmp(cmd,"pagefault")){ 142 | if(strcmp(args,"-r")){ 143 | char i = ((char*)0xDEADC0DE)[0]; 144 | }else if(strcmp(args,"-w")){ 145 | ((char*)0xDEADC0DE)[0]='F'; 146 | }else{ 147 | println("Usage: pagefault [-r,-w]"); 148 | println("-r: Triggers a page fault by reading."); 149 | println("-w: Triggers a page fault by writing."); 150 | } 151 | }else if(strcmp(cmd,"exit")){ 152 | exitShell = true; 153 | }else if(strcmp(cmd,"tasks")){ 154 | printTasks(); 155 | }else if(strcmp(cmd,"bg")){ 156 | if(strcmp(args,"") || !findAndExecute(args, false)) printf("Cannot find \"%s\".\n", args); 157 | }else if(strcmp(cmd,"kill")){ 158 | uint32_t pid = strToInt(args); 159 | process_t *proc = getProcess(pid); 160 | if(proc != NULL && proc->pid != 1){ 161 | kill(proc); 162 | printf("Sent SIGTERM (%d) to %s (PID %d).\n", SIGTERM, proc->name, proc->pid); 163 | }else if(proc->pid == 1) 164 | printf("Cannot kill kernel!\n"); 165 | else 166 | printf("No process with PID %d.\n", pid); 167 | }else if(strcmp(cmd, "dummy")){ 168 | addProcess(createProcess("dummy", (uint32_t)dummy)); 169 | }else{ 170 | if(!findAndExecute(cmd, true)) printf("\"%s\" is not a recognized command, file, or program.\n", cmd); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/kernel/stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int xpos = 0; 5 | int ypos = 0; 6 | char ccolor = 0x0f; 7 | 8 | // Specific mode print_util should implement: 9 | // putch_color(char c, char color); 10 | // clearScreen(); 11 | // center_print(char c, char color); (Should provide a wrapper for center_print_base(c,color,width)) 12 | 13 | void putch(char c){ 14 | if(c == '\b') 15 | backspace(); 16 | else 17 | putch_color(c, ccolor); 18 | } 19 | 20 | void print_color(char* c, char color){ 21 | int i = 0; 22 | while(c[i] != 0){ 23 | putch_color(c[i], color); 24 | i++; 25 | } 26 | } 27 | 28 | void print(char* c){ 29 | print_color(c, ccolor); 30 | } 31 | 32 | void println_color(char* c, char color){ 33 | print_color(c, color); 34 | print_color("\n", color); 35 | } 36 | 37 | void println(char* c){ 38 | println_color(c,ccolor); 39 | } 40 | 41 | void setColor(char color){ 42 | ccolor = color; 43 | } 44 | 45 | void center_print_base(char* c, char color, int width){ 46 | if(xpos > 0){ 47 | print_color("\n",color); 48 | } 49 | int i = 0; 50 | while(c[i]){ 51 | i++; 52 | } 53 | if(i > width){ 54 | print_color(c,color); 55 | }else{ 56 | if(i % 2 == 0){ 57 | int h = (width-i)/2; 58 | int j = 0; 59 | while(j < h){ 60 | putch_color(' ', color); 61 | j++; 62 | } 63 | print_color(c,color); 64 | j = 0; 65 | while(j < h){ 66 | putch_color(' ', color); 67 | j++; 68 | } 69 | }else{ 70 | int h = (width-i)/2; 71 | int j = 0; 72 | while(j < h){ 73 | putch_color(' ', color); 74 | j++; 75 | } 76 | print_color(c,color); 77 | j = 0; 78 | h--; 79 | while(j < h+2){ 80 | putch_color(' ', color); 81 | j++; 82 | } 83 | } 84 | } 85 | } 86 | 87 | void printHex(uint8_t num){ 88 | char *str = " "; 89 | numToHexString(num, str); 90 | print("0x"); 91 | print(str); 92 | } 93 | 94 | void printHexw(uint16_t num){ 95 | char *str = " "; 96 | print("0x"); 97 | numToHexString(num >> 8, str); 98 | print(str); 99 | numToHexString(num, str); 100 | print(str); 101 | } 102 | 103 | void printHexl(uint32_t num){ 104 | char *str = " "; 105 | print("0x"); 106 | numToHexString(num >> 24, str); 107 | print(str); 108 | numToHexString(num >> 16, str); 109 | print(str); 110 | numToHexString(num >> 8, str); 111 | print(str); 112 | numToHexString(num, str); 113 | print(str); 114 | } 115 | 116 | void printNum(int num){ 117 | char str[11]; 118 | itoa(num,str,10); 119 | print(str); 120 | } 121 | 122 | void printf(char *fmt, ...){ 123 | const char *p; 124 | va_list argp; 125 | int i; 126 | char *s; 127 | char fmtbuf[256]; 128 | 129 | va_start(argp, fmt); 130 | 131 | for(p = fmt; *p != '\0'; p++){ 132 | if(*p != '%'){ 133 | putch(*p); 134 | continue; 135 | } 136 | switch(*++p){ 137 | case 'c': 138 | i = va_arg(argp, int); 139 | putch(i); 140 | break; 141 | 142 | case 'd': 143 | i = va_arg(argp, int); 144 | s = itoa(i, fmtbuf, 10); 145 | print(s); 146 | break; 147 | 148 | case 's': 149 | s = va_arg(argp, char *); 150 | print(s); 151 | break; 152 | 153 | case 'x': 154 | i = va_arg(argp, int); 155 | s = itoa(i, fmtbuf, 16); 156 | print(s); 157 | break; 158 | 159 | case 'X': 160 | i = va_arg(argp, int); 161 | s = itoa(i, fmtbuf, 16); 162 | toUpper(s); 163 | print(s); 164 | break; 165 | 166 | case 'b': 167 | i = va_arg(argp, int); 168 | s = itoa(i, fmtbuf, 2); 169 | print(s); 170 | break; 171 | 172 | case '%': 173 | putch('%'); 174 | break; 175 | } 176 | } 177 | va_end(argp); 178 | } 179 | 180 | void backspace(){ 181 | if(xpos != 0){ 182 | xpos--; 183 | putch(' '); 184 | xpos--; 185 | update_cursor(); 186 | } 187 | } 188 | 189 | void PANIC(char *error, char *msg, bool hang){ 190 | clearScreen(); 191 | setAllColor(0x9f); 192 | println("Good job, you crashed it.\nAnyway, here's the details, since you probably need them.\nDon't mess it up again.\n"); 193 | println(error); 194 | println(msg); 195 | if(hang) cli(); 196 | while(hang); 197 | } 198 | 199 | unsigned char* vidmem = (char*)0xB8000+HIGHER_HALF; //It would be 0xb8000, but we mapped the kernel to 0xc0000000. 200 | void putch_color(char c, char color){ 201 | if(c == '\r'){ 202 | xpos = 0; 203 | }else if(c == '\n'){ 204 | xpos = 0; 205 | ypos++; 206 | }else if(c == '\t'){ 207 | for(uint8_t i = 0; i < 5; i++) 208 | putch_color(' ',color); 209 | }else{ 210 | int pos = (xpos+(ypos*80))*2; 211 | vidmem[pos] = c; 212 | vidmem[pos+1] = color; 213 | xpos++; 214 | if(xpos >= 80){ 215 | ypos++; 216 | xpos = 0; 217 | } 218 | } 219 | while(ypos >= 25){ 220 | scroll(); 221 | } 222 | update_cursor(); 223 | } 224 | 225 | void clearScreen(){ 226 | for(int y=0; y<25; y++){ 227 | for(int x=0; x<80; x++){ 228 | vidmem[(x+(y*80))*2] = ' '; 229 | } 230 | } 231 | xpos = 0; 232 | ypos = 0; 233 | } 234 | 235 | void setAllColor(char color){ 236 | for(int y=0; y<25; y++){ 237 | for(int x=0; x<80; x++){ 238 | vidmem[(x+(y*80))*2+1] = color; 239 | } 240 | } 241 | setColor(color); 242 | } 243 | 244 | void center_print(char* c, char color){ 245 | center_print_base(c, color, 80); 246 | } 247 | 248 | void update_cursor(){ 249 | uint16_t position=(ypos*80) + xpos; 250 | outb(0x3D4, 0x0F); 251 | outb(0x3D5, (uint8_t)(position&0xFF)); 252 | outb(0x3D4, 0x0E); 253 | outb(0x3D5, (uint8_t)((position>>8)&0xFF)); 254 | } 255 | 256 | void scroll(){ 257 | uint16_t i = 80*2; 258 | while(i < 80*25*2){ 259 | vidmem[i-(80*2)] = vidmem[i]; 260 | i++; 261 | } 262 | i = 80*2*24; 263 | while(i < 80*25*2){ 264 | vidmem[i++] = ' '; 265 | vidmem[i++] = 0x07; 266 | } 267 | ypos--; 268 | } 269 | -------------------------------------------------------------------------------- /src/kernel/syscall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void syscallHandler(uint32_t eax, uint32_t ebx){ 7 | switch(eax){ 8 | case 0: 9 | ;char c = (char)ebx; 10 | putch(c); 11 | break; 12 | case 1: 13 | ;char* c2 = (char*)ebx; 14 | print(c2); 15 | break; 16 | case 2: 17 | __kill__(); 18 | break; 19 | default: 20 | print("Other syscall "); 21 | printHex(eax); 22 | println(""); 23 | break; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/kernel/tasking.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | //big thanks to levOS (levex on GitHub) for some bits of the tasking code 9 | //Also, big thanks to /r/osdev and specifically /u/DSMan195276 and /u/NasenSpray for help getting it to work! 10 | 11 | process_t *current_proc; 12 | process_t *kernel_proc; 13 | uint32_t __cpid__ = 0; 14 | bool tasking_enabled = false; 15 | 16 | void kthread(){ 17 | tasking_enabled = true; 18 | kmain_late(); 19 | while(1); 20 | } 21 | 22 | process_t *createProcess(char *name, uint32_t loc){ 23 | process_t *p = kmalloc(sizeof(process_t)); 24 | memset(p,0,sizeof(process_t)); //make sure everything's clean 25 | 26 | p->name = name; 27 | p->pid = ++__cpid__; 28 | p->state = PROCESS_ALIVE; 29 | p->notify = __notify__; 30 | p->eip = loc; 31 | p->esp = (uint32_t) kmalloc(4096); 32 | p->notExecuted = true; 33 | asm volatile("mov %%cr3, %%eax":"=a"(p->cr3)); 34 | uint32_t *stack = (uint32_t *)(p->esp + 4096); 35 | p->stack = p->esp; 36 | 37 | //pushing registers on to the stack 38 | *--stack = 0x202; // eflags 39 | *--stack = 0x8; // cs 40 | *--stack = loc; // eip 41 | *--stack = 0; // eax 42 | *--stack = 0; // ebx 43 | *--stack = 0; // ecx; 44 | *--stack = 0; //edx 45 | *--stack = 0; //esi 46 | *--stack = 0; //edi 47 | *--stack = p->esp + 4096; //ebp 48 | *--stack = 0x10; // ds 49 | *--stack = 0x10; // fs 50 | *--stack = 0x10; // es 51 | *--stack = 0x10; // gs 52 | 53 | p->esp = (uint32_t)stack; 54 | return p; 55 | } 56 | 57 | process_t *getProcess(uint32_t pid){ 58 | process_t *current = kernel_proc; 59 | do{ 60 | if(current->pid == pid) return current; 61 | current = current->next; 62 | }while(current != kernel_proc); 63 | return NULL; 64 | } 65 | 66 | void printTasks(){ 67 | process_t *current = kernel_proc; 68 | printf("Running processes: (PID, name, state, * = is current)\n"); 69 | do{ 70 | printf("%c[%d] '%s' %d\n", current == current_proc ? '*' : ' ', current->pid, current->name, current->state); 71 | current = current->next; 72 | }while(current != kernel_proc); 73 | } 74 | 75 | void __init__(){ 76 | current_proc->notExecuted = false; 77 | asm volatile("mov %%eax, %%esp": :"a"(current_proc->esp)); 78 | asm volatile("pop %gs"); 79 | asm volatile("pop %fs"); 80 | asm volatile("pop %es"); 81 | asm volatile("pop %ds"); 82 | asm volatile("pop %ebp"); 83 | asm volatile("pop %edi"); 84 | asm volatile("pop %esi"); 85 | asm volatile("pop %edx"); 86 | asm volatile("pop %ecx"); 87 | asm volatile("pop %ebx"); 88 | asm volatile("pop %eax"); 89 | asm volatile("iret"); 90 | } 91 | 92 | void preempt_now(){ 93 | if(!tasking_enabled) return; 94 | asm volatile("int $0x81"); 95 | } 96 | 97 | void __kill__(){ 98 | if(current_proc->pid != 1){ 99 | tasking_enabled = false; 100 | kfree((uint8_t *)current_proc->stack,4096); 101 | kfree(current_proc, sizeof(process_t)); 102 | current_proc->prev->next = current_proc->next; 103 | current_proc->next->prev = current_proc->prev; 104 | current_proc->state = PROCESS_DEAD; 105 | tasking_enabled = true; 106 | preempt_now(); 107 | }else{ 108 | PANIC("KERNEL KILLED","EVERYONE PANIC THIS ISN'T GOOD",true); 109 | } 110 | } 111 | 112 | void __notify__(uint32_t sig){ 113 | switch(sig){ 114 | case SIGTERM: 115 | __kill__(); 116 | break; 117 | case SIGILL: 118 | printf("\n(PID %d) Illegal operation! Aborting.\n",current_proc->pid); 119 | __kill__(); 120 | } 121 | } 122 | 123 | void initTasking(){ 124 | kernel_proc = createProcess("codek32", (uint32_t)kthread); 125 | kernel_proc->next = kernel_proc; 126 | kernel_proc->prev = kernel_proc; 127 | current_proc = kernel_proc; 128 | __init__(); 129 | //pop all of the registers off of the stack and get started 130 | PANIC("Failed to init tasking", "Something went wrong..", true); 131 | } 132 | 133 | process_t *getCurrentProcess(){ 134 | return current_proc; 135 | } 136 | 137 | uint32_t addProcess(process_t *p){ 138 | bool en = tasking_enabled; 139 | tasking_enabled = false; 140 | p->next = current_proc->next; 141 | p->next->prev = p; 142 | p->prev = current_proc; 143 | current_proc->next = p; 144 | tasking_enabled = en; 145 | return p->pid; 146 | } 147 | 148 | void notify(uint32_t sig){ 149 | current_proc->notify(sig); 150 | } 151 | 152 | void kill(process_t *p){ 153 | if(getProcess(p->pid) != NULL){ 154 | tasking_enabled = false; 155 | kfree((uint8_t *)p->stack,4096); 156 | kfree(p, sizeof(process_t)); 157 | p->prev->next = p->next; 158 | p->next->prev = p->prev; 159 | p->state = PROCESS_DEAD; 160 | tasking_enabled = true; 161 | } 162 | } 163 | 164 | void preempt(){ 165 | //push current_proc process' registers on to its stack 166 | asm volatile("push %eax"); 167 | asm volatile("push %ebx"); 168 | asm volatile("push %ecx"); 169 | asm volatile("push %edx"); 170 | asm volatile("push %esi"); 171 | asm volatile("push %edi"); 172 | asm volatile("push %ebp"); 173 | asm volatile("push %ds"); 174 | asm volatile("push %es"); 175 | asm volatile("push %fs"); 176 | asm volatile("push %gs"); 177 | asm volatile("mov %%esp, %%eax":"=a"(current_proc->esp)); 178 | current_proc = current_proc->next; 179 | if(current_proc->notExecuted){ 180 | __init__(); 181 | return; 182 | } 183 | //pop all of next process' registers off of its stack 184 | asm volatile("mov %%eax, %%cr3": :"a"(current_proc->cr3)); 185 | asm volatile("mov %%eax, %%esp": :"a"(current_proc->esp)); 186 | asm volatile("pop %gs"); 187 | asm volatile("pop %fs"); 188 | asm volatile("pop %es"); 189 | asm volatile("pop %ds"); 190 | asm volatile("pop %ebp"); 191 | asm volatile("pop %edi"); 192 | asm volatile("pop %esi"); 193 | //asm volatile("out %%al, %%dx": :"d"(0x20), "a"(0x20)); 194 | asm volatile("pop %edx"); 195 | asm volatile("pop %ecx"); 196 | asm volatile("pop %ebx"); 197 | asm volatile("pop %eax"); 198 | //asm volatile("add $0x0C, %esp"); 199 | //while(wait); 200 | //asm volatile("iret"); 201 | } 202 | -------------------------------------------------------------------------------- /src/kernel/tss.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include -------------------------------------------------------------------------------- /src/kernel/vfs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteduck/codeOS2/d9b65dba8a36b4154344541e84b7fa2fdbb8716b/src/kernel/vfs.c -------------------------------------------------------------------------------- /src/unused/drivers/VGA/VESA.c: -------------------------------------------------------------------------------- 1 | void initVESA(){ 2 | 3 | } -------------------------------------------------------------------------------- /src/unused/drivers/VGA/VESA.h: -------------------------------------------------------------------------------- 1 | void initVESA(); 2 | #include "VESA.c" -------------------------------------------------------------------------------- /src/unused/drivers/VGA/VGA_13h.c: -------------------------------------------------------------------------------- 1 | void putPixel(int x, int y, char color){ 2 | if(x <= 320 && y <= 200){ 3 | char* vidmem = (char*)0xA0000; 4 | vidmem[x+y*320] = color; 5 | } 6 | } 7 | 8 | void setPalette(char id, char r, char g, char b){ 9 | outb(0x3c8,id); 10 | outb(0x3c9,r); 11 | outb(0x3c9,g); 12 | outb(0x3c9,b); 13 | } -------------------------------------------------------------------------------- /src/unused/drivers/VGA/VGA_13h.h: -------------------------------------------------------------------------------- 1 | int VGA_WIDTH = 320; 2 | int VGA_HEIGHT = 200; 3 | char VGA_MODE = 0x13; 4 | void putPixel(int x, int y, char color); 5 | void setPalette(char id, char r, char g, char b); 6 | #include "VGA_13h.c" -------------------------------------------------------------------------------- /src/unused/etc/font/font_8x8.h: -------------------------------------------------------------------------------- 1 | // CREDIT TO dhepper 2 | // (I'm too lazy to make a font myself) 3 | char font_8x8[128][8] = { 4 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) 5 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 6 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002 7 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003 8 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004 9 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005 10 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006 11 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007 12 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008 13 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009 14 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A 15 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B 16 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C 17 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D 18 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E 19 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F 20 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010 21 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011 22 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012 23 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013 24 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014 25 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015 26 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016 27 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017 28 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018 29 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019 30 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A 31 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B 32 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C 33 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D 34 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E 35 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F 36 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space) 37 | { 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!) 38 | { 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (") 39 | { 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#) 40 | { 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($) 41 | { 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%) 42 | { 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&) 43 | { 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (') 44 | { 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (() 45 | { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ()) 46 | { 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*) 47 | { 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+) 48 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,) 49 | { 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-) 50 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.) 51 | { 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/) 52 | { 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0) 53 | { 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1) 54 | { 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2) 55 | { 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3) 56 | { 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4) 57 | { 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5) 58 | { 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6) 59 | { 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7) 60 | { 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8) 61 | { 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9) 62 | { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:) 63 | { 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (//) 64 | { 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<) 65 | { 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=) 66 | { 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>) 67 | { 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?) 68 | { 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@) 69 | { 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A) 70 | { 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B) 71 | { 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C) 72 | { 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D) 73 | { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E) 74 | { 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F) 75 | { 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G) 76 | { 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H) 77 | { 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I) 78 | { 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J) 79 | { 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K) 80 | { 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L) 81 | { 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M) 82 | { 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N) 83 | { 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O) 84 | { 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P) 85 | { 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q) 86 | { 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R) 87 | { 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S) 88 | { 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T) 89 | { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U) 90 | { 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V) 91 | { 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W) 92 | { 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X) 93 | { 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y) 94 | { 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z) 95 | { 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([) 96 | { 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\) 97 | { 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (]) 98 | { 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^) 99 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_) 100 | { 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`) 101 | { 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a) 102 | { 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b) 103 | { 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c) 104 | { 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d) 105 | { 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e) 106 | { 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f) 107 | { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g) 108 | { 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h) 109 | { 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i) 110 | { 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j) 111 | { 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k) 112 | { 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l) 113 | { 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m) 114 | { 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n) 115 | { 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o) 116 | { 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p) 117 | { 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q) 118 | { 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r) 119 | { 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s) 120 | { 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t) 121 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u) 122 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v) 123 | { 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w) 124 | { 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x) 125 | { 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y) 126 | { 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z) 127 | { 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({) 128 | { 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|) 129 | { 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (}) 130 | { 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~) 131 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F 132 | }; -------------------------------------------------------------------------------- /src/unused/logo.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File generated by LCD Assistant 3 | // http://en.radzio.dxp.pl/bitmap_converter/ 4 | //------------------------------------------------------------------------------ 5 | 6 | const unsigned char logo [] = { 7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0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0xFF, 0xFF, 123 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 124 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 125 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 126 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 127 | 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 128 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 129 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 132 | }; 133 | -------------------------------------------------------------------------------- /src/unused/util/draw/draw_util.c: -------------------------------------------------------------------------------- 1 | void drawLine(int x1, int y1, int x2, int y2, char color){ 2 | int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py; 3 | 4 | dx=x2-x1; 5 | dy=y2-y1; 6 | dxabs=abs(dx); 7 | dyabs=abs(dy); 8 | sdx=sgn(dx); 9 | sdy=sgn(dy); 10 | x=dyabs>>1; 11 | y=dxabs>>1; 12 | px=x1; 13 | py=y1; 14 | 15 | if(dxabs>=dyabs){ 16 | for(i=0;i=dxabs){ 19 | y-=dxabs; 20 | py+=sdy; 21 | } 22 | px+=sdx; 23 | putPixel(px,py,color); 24 | } 25 | }else{ 26 | for(i=0;i=dyabs){ 29 | x-=dyabs; 30 | px+=sdx; 31 | } 32 | py+=sdy; 33 | putPixel(px,py,color); 34 | } 35 | } 36 | } 37 | 38 | void drawMonoBitmap(const char* bmp, int width, int height, int px, int py, char color){ 39 | int apos = 0; 40 | int spos = 7; 41 | for(int y = 0; y < height; y++){ 42 | for(int x = 0; x < width; x++){ 43 | if(!((bmp[apos] >> spos) & 0x01)) 44 | putPixel(x+px,y+py,color); 45 | spos--; 46 | if(spos < 0){ 47 | spos = 7; 48 | apos++; 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/unused/util/draw/draw_util.h: -------------------------------------------------------------------------------- 1 | void drawLine(int x1, int y1, int x2, int y2, char color); 2 | #include "draw_util.c" -------------------------------------------------------------------------------- /src/unused/util/print/print_util_320_200_256.c: -------------------------------------------------------------------------------- 1 | unsigned char* vidmem = (char*)0xA0000; 2 | void putch_color(char c, char color){ 3 | if(c == '\r'){ 4 | xpos = 0; 5 | }else if(c == '\n'){ 6 | xpos = 0; 7 | ypos++; 8 | }else{ 9 | for(int x = 0; x < 8; x++){ 10 | for(int y = 0; y < 8; y++){ 11 | if(((font_8x8[c][y] >> x) & 0x01)) 12 | vidmem[xpos*8+x+(ypos*320*8)+y*320] = color; 13 | } 14 | } 15 | xpos++; 16 | if(xpos >= 40){ 17 | ypos++; 18 | xpos = 0; 19 | if(ypos >= 25){ 20 | ypos = 0; 21 | } 22 | } 23 | } 24 | } 25 | 26 | void clearScreen(){ 27 | for(int y=0; y<200; y++){ 28 | for(int x=0; x<320; x++){ 29 | vidmem[(x+(y*320))] = 0; 30 | } 31 | } 32 | xpos = 0; 33 | ypos = 0; 34 | } 35 | 36 | void center_print(char* c, char color){ 37 | center_print_base(c,color,40); 38 | } -------------------------------------------------------------------------------- /src/unused/util/print/print_util_320_200_256.h: -------------------------------------------------------------------------------- 1 | #include "../../etc/font/font_8x8.h" 2 | void putch_color(char c, char color); 3 | void clearScreen(); 4 | void center_print(char* c, char color); 5 | #include "print_util_base.h" 6 | #include "print_util_320_200_256.c" -------------------------------------------------------------------------------- /src/unused/util/print/print_util_640_480_16.c: -------------------------------------------------------------------------------- 1 | void putch_color(char c, char color){ 2 | unsigned char* vidmem = (char*)0xA0000; 3 | if(c == '\r'){ 4 | xpos = 0; 5 | }else if(c == '\n'){ 6 | xpos = 0; 7 | ypos++; 8 | }else{ 9 | for(int x = 0; x < 8; x++){ 10 | for(int y = 0; y < 8; y++){ 11 | if(((font_8x8[c][y] >> x) & 0x01)) 12 | putPixel(xpos*8+x,ypos*8+y] = color; 13 | } 14 | } 15 | xpos++; 16 | if(xpos >= 80){ 17 | ypos++; 18 | xpos = 0; 19 | if(ypos >= 60){ 20 | ypos = 0; 21 | } 22 | } 23 | } 24 | } 25 | 26 | void clearScreen(){ 27 | unsigned char* vidmem = (char*)0xA0000; 28 | for(int y=0; y<480; y++){ 29 | for(int x=0; x<640; x++){ 30 | vidmem[(x+(y*640))] = 0x00; 31 | } 32 | } 33 | xpos = 0; 34 | ypos = 0; 35 | } 36 | 37 | void center_print(char* c, char color){ 38 | center_print_base(c,color,80); 39 | } -------------------------------------------------------------------------------- /src/unused/util/print/print_util_640_480_16.h: -------------------------------------------------------------------------------- 1 | #include "../../etc/font/font_8x8.h" 2 | void putch_color(char c, char color); 3 | void clearScreen(); 4 | void center_print(char* c, char color); 5 | #include "print_util_base.h" --------------------------------------------------------------------------------