
Prehistory
Hello! I strongly welcome everyone, today I would like to tell you about my experience in writing a workable OS for the x86 architecture.
One spring night I had a brilliant idea - try yourself in writing your own OS, which can allow you to run programs, work with devices, and generally squeeze all the power out of Intel's architecture in your needs: for example, for your factory or something else. My goal was and is to write such an OS that could allow maximum performance for some specific tasks without spending CPU time on all sorts of excesses. Basically, I am pursuing only sports interest, gaining experience for myself in system programming and writing drivers for devices that are used everywhere. What came of it is up to you, I immediately say that you don’t need to write comments about creating your own Linux distribution, and pursued an interest to write everything from scratch from scratch in order to immerse yourself in the OSDev theme. Just want to express my deep gratitude to Benjamin Lunt and the OSDev forum, as well as their wiki. Ben helped me deal with EHCI, which undoubtedly made a huge contribution to my OS - USB devices, they are everywhere! I was also faced with the task of creating my own architecture convenient for me, not excluding the use of ELF file standards.
Well, let's get to the point.
UPD: all the info can be found in the
pump group, there is also a post with docks and a way (old, now I finish writing docks for the stable version)
')
What is done?
Now my OS is able to work with USB flash drives, mice, keyboards, AHCI disks, PCI IDE controller, APIC and ACPI, preemptive multitasking is implemented, program launch is implemented, streamline work with files, SVB driver running on 0x118 VBE mode, DNS, DHCP, TCP, UPD, IPv4, HTTP, full FAT32 driver, RTL8139 (69) driver and Intel Gigabit Ethernet are working.
The window system along with my SVGA implementation makes it possible to produce as much as 120 FPS when the screen is completely redrawn. Let's move on to how this is all implemented and generally can work.
How it works?
To begin with, I wrote a bootloader that reads the secondary bootloader with the kernel from FAT32. The second boot loader switches to protected mode and jumps into the kernel, there I load and configure IDT, then I initialize the PCI devices, start the kernels, and launch CMD.
Someone will ask, how did you achieve such a performance with SVGA? The answer is simple: an assembler, an assembler, and an assembler again. Not without SSE instructions that greatly speed up the copying of memory. For example, here is the code for copying the video buffer in the LFB (Linear Frame Buffer):
.byte 0x60#Save registers in stack
mov %2,%%ecx #Repeat count to ecx
mov %0,%%edi #Video memory start to edi
mov %1,%%esi #Video buffer start to esi
ww1sse2:
movaps (%%esi),%%xmm0 #Copy 16 bytes to xmm0 from buffer
movaps %%xmm0,(%%edi) #Copy from xmm0 to video memory
movaps 16(%%esi),%%xmm0 #16 again, but + 16 from current
movaps %%xmm0,16(%%edi) #16 again, but + 16 from current
movaps 32(%%esi),%%xmm0 #16 again, but + 32 from current
movaps %%xmm0,32(%%edi) #16 again, but + 32 from current
movaps 48(%%esi),%%xmm0 #16 again, but + 48 from current
movaps %%xmm0,48(%%edi) #16 again, but + 48 from current
add $64,%%edi #Add 64 bytes to edi
add $64,%%esi #Add 64 bytes to esi
dec%%ecx#Decrement count
#test %%ecx,%%ecx #Compare ecx with zero
jnz ww1sse2 #If not zero, repeat again
.byte 0x61 #Restore registers from stack
, , , .
— «Watermark Allocator». , , , ..
-, .
MS-DOS: — . MBR , GPT .
— - , — .
, , — , , : , VIM.
, : , , return , - . , , - , .
: , , , , . — , , — — return'.
, , -, .
— - , - - , , ( , ) — , , .
!