Virtual Memory Management fucking works!
git-svn-id: https://spexeah.com:8443/svn/Asuro@125 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								bin/kernel.bin
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/kernel.bin
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/console.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/console.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/gdt.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/gdt.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/idt.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/idt.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/irq.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/irq.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr0.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr0.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr1.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr1.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr10.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr10.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr11.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr11.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr12.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr12.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr13.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr13.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr14.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr14.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr15.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr15.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr16.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr16.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr17.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr17.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr18.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr18.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr2.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr2.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr3.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr3.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr32.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr32.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr33.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr33.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr4.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr4.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr40.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr40.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr5.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr5.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr6.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr6.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr7.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr7.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr8.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr8.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/isr9.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/isr9.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/kernel.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/kernel.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/keyboard.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/keyboard.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/libpsystem.a
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/libpsystem.a
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/system.o
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/system.o
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/system.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/system.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/util.ppu
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/util.ppu
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -14,8 +14,8 @@ uses | ||||
|      bios_data_area, | ||||
|      keyboard, | ||||
|      vmemorymanager, | ||||
|      pmemorymanager, | ||||
|      scheduler; | ||||
|      pmemorymanager; | ||||
|      //scheduler; | ||||
|   | ||||
| procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; | ||||
|   | ||||
| @@ -53,7 +53,13 @@ begin | ||||
|      irq.init(); | ||||
|      pmemorymanager.init(); | ||||
|      vmemorymanager.init(); | ||||
|      scheduler.init(); | ||||
|  | ||||
|      vmemorymanager.new_page(0); | ||||
|      pint:= puint32(0); | ||||
|      console.writestringln('Writing 1234 to Logical Address $00000000'); | ||||
|      pint^:= 1234; | ||||
|      if pint^ = 1234 then console.writestringln('Read 1234 back from Logical Address $00000000!!!'); | ||||
|      //scheduler.init(); | ||||
|  | ||||
|      STI; | ||||
|      isr32.hook(uint32(@bios_data_area.tick_update)); | ||||
|   | ||||
| @@ -14,8 +14,8 @@ type | ||||
|     TPhysicalMemory = array[0..1023] of TPhysicalMemoryEntry; | ||||
|  | ||||
| procedure init; | ||||
| function newblock(caller : uint32) : uint16; | ||||
| procedure freeblock(block : uint16; caller : uint32); | ||||
| function new_block(caller : uint32) : uint16; | ||||
| procedure free_block(block : uint16; caller : uint32); | ||||
|  | ||||
| implementation | ||||
|  | ||||
| @@ -24,6 +24,7 @@ var | ||||
|  | ||||
| procedure init; | ||||
| begin | ||||
|     console.writestringln('PMM: INIT BEGIN.'); | ||||
|     with PhysicalMemory[0] do begin | ||||
|         Present:= True; | ||||
|         MappedTo:= 0; | ||||
| @@ -32,25 +33,33 @@ begin | ||||
|         Present:= True; | ||||
|         MappedTo:= 0; | ||||
|     end; | ||||
|     console.writestringln('PMM: INIT END.'); | ||||
| end; | ||||
|  | ||||
| function newblock(caller : uint32) : uint16; | ||||
| function new_block(caller : uint32) : uint16; | ||||
| var | ||||
|     i : uint16; | ||||
|  | ||||
| begin | ||||
|     newblock:= 0; | ||||
|     new_block:= 0; | ||||
|     for i:=2 to 1023 do begin | ||||
|         if not PhysicalMemory[i].Present then begin | ||||
|             PhysicalMemory[i].Present:= True; | ||||
|             PhysicalMemory[i].MappedTo:= caller; | ||||
|             newblock:= i; | ||||
|             new_block:= i; | ||||
|             console.writestring('4MiB Block Added @ '); | ||||
|             console.writeword(i); | ||||
|             console.writestring(' ['); | ||||
|             console.writeword(i SHL 22); | ||||
|             console.writestring(' - '); | ||||
|             console.writeword((i+1 SHL 22)-1); | ||||
|             console.writestringln(']'); | ||||
|             exit; | ||||
|         end; | ||||
|     end;  | ||||
| end; | ||||
|  | ||||
| procedure freeblock(block : uint16; caller : uint32); | ||||
| procedure free_block(block : uint16; caller : uint32); | ||||
| begin | ||||
|     if block > 1023 then begin | ||||
|         GPF; | ||||
| @@ -60,7 +69,7 @@ begin | ||||
|         GPF; | ||||
|         exit; | ||||
|     end; | ||||
|     if PhysicalMemory[block].caller <> caller then begin | ||||
|     if PhysicalMemory[block].MappedTo <> caller then begin | ||||
|         GPF; | ||||
|         exit; | ||||
|     end; | ||||
|   | ||||
| @@ -5,7 +5,7 @@ interface | ||||
| uses | ||||
|     console, | ||||
|     isr32, | ||||
|     pmemorymanager; | ||||
|     lmemorymanager; | ||||
|  | ||||
| const | ||||
|     Quantum = 64; | ||||
|   | ||||
| @@ -33,6 +33,7 @@ procedure init; | ||||
| function new_page(page_number : uint16) : boolean; | ||||
| function new_page_at_address(address : uint32) : boolean; | ||||
| procedure free_page(page_number : uint16); | ||||
| procedure free_page_at_address(address : uint32); | ||||
|  | ||||
| implementation | ||||
|  | ||||
| @@ -63,20 +64,42 @@ function new_page(page_number : uint16) : boolean; | ||||
| var | ||||
|     block : uint16; | ||||
|     page  : uint16; | ||||
|     rldpd : uint32; | ||||
|  | ||||
| begin | ||||
|     new_page:= false; | ||||
|     if PageDirectory^[block].Present then exit; | ||||
|     if PageDirectory^[block].Reserved then exit; | ||||
|     block:= pmemorymanager.newblock(uint32(PageDirectory)); | ||||
|     if PageDirectory^[page_number].Present then exit; | ||||
|     if PageDirectory^[page_number].Reserved then exit; | ||||
|     block:= pmemorymanager.new_block(uint32(PageDirectory)); | ||||
|     if block < 2 then begin | ||||
|         GPF; | ||||
|         exit; | ||||
|     end else begin | ||||
|         PageDirectory^[block].Present:= true; | ||||
|         PageDirectory^[block].Address:= block; | ||||
|         PageDirectory^[block].PageSize:= true; | ||||
|         PageDirectory^[page_number].Present:= true; | ||||
|         PageDirectory^[page_number].Address:= block; | ||||
|         PageDirectory^[page_number].PageSize:= true; | ||||
|         rldpd:= uint32(PageDirectory) - KERNEL_VIRTUAL_BASE; | ||||
|         asm | ||||
|             mov eax, rldpd | ||||
|             mov CR3, eax | ||||
|         end; | ||||
|         new_page:= true; | ||||
|         console.writestringln('New Page Added:'); | ||||
|  | ||||
|         console.writestring('- P:'); | ||||
|         console.writeword(page_number); | ||||
|         console.writestring('-->B:'); | ||||
|         console.writewordln(block); | ||||
|          | ||||
|         console.writestring('- P:['); | ||||
|         console.writeword(page_number SHL 22); | ||||
|         console.writestring(' - '); | ||||
|         console.writeword((page_number+1 SHL 22) - 1); | ||||
|         console.writestring(']-->B:['); | ||||
|         console.writeword(block SHL 22); | ||||
|         console.writestring(' - '); | ||||
|         console.writeword((block+1 SHL 22) - 1); | ||||
|         console.writestringln(']'); | ||||
|     end; | ||||
| end; | ||||
|  | ||||
| @@ -90,17 +113,22 @@ begin | ||||
| end; | ||||
|  | ||||
| procedure free_page(page_number : uint16); | ||||
| var | ||||
|     block : uint16; | ||||
|  | ||||
| begin | ||||
|     if PageDirectory^[page_number].Present then begin | ||||
|         block:= PageDirectory^[page_number].Address; | ||||
|         asm | ||||
|             invlpg [page_number] | ||||
|         end;     | ||||
|         end; | ||||
|         pmemorymanager.free_block(block, uint32(PageDirectory)); | ||||
|     end else begin | ||||
|         GPF; | ||||
|     end; | ||||
| end; | ||||
|  | ||||
| function free_page_at_address(address : uint32); | ||||
| procedure free_page_at_address(address : uint32); | ||||
| var | ||||
|     page_number : uint16; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 kieron
					kieron