no more pminit, or ELF header at 0x10000
kinit() knows about end and PHYSTOP map all of kernel read/write (rather than r/o instructions) thanks, austin
This commit is contained in:
		
							parent
							
								
									880ee18ab1
								
							
						
					
					
						commit
						8d774afb2d
					
				
					 5 changed files with 13 additions and 49 deletions
				
			
		
							
								
								
									
										3
									
								
								defs.h
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								defs.h
									
										
									
									
									
								
							|  | @ -62,7 +62,7 @@ void            ioapicinit(void); | ||||||
| // kalloc.c
 | // kalloc.c
 | ||||||
| char*           kalloc(void); | char*           kalloc(void); | ||||||
| void            kfree(char*); | void            kfree(char*); | ||||||
| void            kinit(char*,uint); | void            kinit(); | ||||||
| 
 | 
 | ||||||
| // kbd.c
 | // kbd.c
 | ||||||
| void            kbdintr(void); | void            kbdintr(void); | ||||||
|  | @ -151,7 +151,6 @@ void            uartintr(void); | ||||||
| void            uartputc(int); | void            uartputc(int); | ||||||
| 
 | 
 | ||||||
| // vm.c
 | // vm.c
 | ||||||
| void            pminit(void); |  | ||||||
| void            ksegment(void); | void            ksegment(void); | ||||||
| void            kvmalloc(void); | void            kvmalloc(void); | ||||||
| void            vmenable(void); | void            vmenable(void); | ||||||
|  |  | ||||||
							
								
								
									
										8
									
								
								kalloc.c
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								kalloc.c
									
										
									
									
									
								
							|  | @ -19,11 +19,13 @@ struct { | ||||||
| 
 | 
 | ||||||
| // Initialize free list of physical pages.
 | // Initialize free list of physical pages.
 | ||||||
| void | void | ||||||
| kinit(char *p, uint len) | kinit(void) | ||||||
| { | { | ||||||
|  |   extern char end[]; | ||||||
|  | 
 | ||||||
|   initlock(&kmem.lock, "kmem"); |   initlock(&kmem.lock, "kmem"); | ||||||
|   char *p1 = (char*)PGROUNDUP((uint)p); |   char *p1 = (char*)PGROUNDUP((uint)end); | ||||||
|   char *p2 = PGROUNDDOWN(p + len); |   char *p2 = PGROUNDDOWN(PHYSTOP); | ||||||
|   for( ; p1 < p2; p1 += 4096) |   for( ; p1 < p2; p1 += 4096) | ||||||
|     kfree(p1); |     kfree(p1); | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								main.c
									
										
									
									
									
								
							|  | @ -21,7 +21,7 @@ main(void) | ||||||
|   ioapicinit();    // another interrupt controller
 |   ioapicinit();    // another interrupt controller
 | ||||||
|   consoleinit();   // I/O devices & their interrupts
 |   consoleinit();   // I/O devices & their interrupts
 | ||||||
|   uartinit();      // serial port
 |   uartinit();      // serial port
 | ||||||
|   pminit();        // discover how much memory there is
 |   kinit();         // initialize memory allocator
 | ||||||
|   jkstack();       // call mainc() on a properly-allocated stack 
 |   jkstack();       // call mainc() on a properly-allocated stack 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								mkfs.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								mkfs.c
									
										
									
									
									
								
							|  | @ -82,7 +82,7 @@ main(int argc, char *argv[]) | ||||||
|   usedblocks = ninodes / IPB + 3 + bitblocks; |   usedblocks = ninodes / IPB + 3 + bitblocks; | ||||||
|   freeblock = usedblocks; |   freeblock = usedblocks; | ||||||
| 
 | 
 | ||||||
|   printf("used %d (bit %d ninode %u) free %u total %d\n", usedblocks, |   printf("used %d (bit %d ninode %lu) free %u total %d\n", usedblocks, | ||||||
|          bitblocks, ninodes/IPB + 1, freeblock, nblocks+usedblocks); |          bitblocks, ninodes/IPB + 1, freeblock, nblocks+usedblocks); | ||||||
| 
 | 
 | ||||||
|   assert(nblocks + usedblocks == size); |   assert(nblocks + usedblocks == size); | ||||||
|  | @ -230,7 +230,7 @@ balloc(int used) | ||||||
|   for(i = 0; i < used; i++) { |   for(i = 0; i < used; i++) { | ||||||
|     buf[i/8] = buf[i/8] | (0x1 << (i%8)); |     buf[i/8] = buf[i/8] | (0x1 << (i%8)); | ||||||
|   } |   } | ||||||
|   printf("balloc: write bitmap block at sector %u\n", ninodes/IPB + 3); |   printf("balloc: write bitmap block at sector %lu\n", ninodes/IPB + 3); | ||||||
|   wsect(ninodes / IPB + 3, buf); |   wsect(ninodes / IPB + 3, buf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										45
									
								
								vm.c
									
										
									
									
									
								
							
							
						
						
									
										45
									
								
								vm.c
									
										
									
									
									
								
							|  | @ -17,8 +17,8 @@ | ||||||
| // setupkvm() and exec() set up every page table like this:
 | // setupkvm() and exec() set up every page table like this:
 | ||||||
| //   0..640K          : user memory (text, data, stack, heap)
 | //   0..640K          : user memory (text, data, stack, heap)
 | ||||||
| //   640K..1M         : mapped direct (for IO space)
 | //   640K..1M         : mapped direct (for IO space)
 | ||||||
| //   1M..kernend      : mapped direct (for the kernel's text and data)
 | //   1M..end          : mapped direct (for the kernel's text and data)
 | ||||||
| //   kernend..PHYSTOP : mapped direct (kernel heap and user pages)
 | //   end..PHYSTOP     : mapped direct (kernel heap and user pages)
 | ||||||
| //   0xfe000000..0    : mapped direct (devices such as ioapic)
 | //   0xfe000000..0    : mapped direct (devices such as ioapic)
 | ||||||
| //
 | //
 | ||||||
| // The kernel allocates memory for its heap and for user memory
 | // The kernel allocates memory for its heap and for user memory
 | ||||||
|  | @ -31,12 +31,6 @@ | ||||||
| 
 | 
 | ||||||
| #define USERTOP  0xA0000 | #define USERTOP  0xA0000 | ||||||
| 
 | 
 | ||||||
| static uint kerntext;  // Linker starts kernel at 1MB
 |  | ||||||
| static uint kerntsz;    |  | ||||||
| static uint kerndata; |  | ||||||
| static uint kerndsz; |  | ||||||
| static uint kernend; |  | ||||||
| static uint freesz; |  | ||||||
| static pde_t *kpgdir;  // for use in scheduler()
 | static pde_t *kpgdir;  // for use in scheduler()
 | ||||||
| 
 | 
 | ||||||
| // return the address of the PTE in page table pgdir
 | // return the address of the PTE in page table pgdir
 | ||||||
|  | @ -161,14 +155,8 @@ setupkvm(void) | ||||||
|   // Map IO space from 640K to 1Mbyte
 |   // Map IO space from 640K to 1Mbyte
 | ||||||
|   if (!mappages(pgdir, (void *)USERTOP, 0x60000, USERTOP, PTE_W)) |   if (!mappages(pgdir, (void *)USERTOP, 0x60000, USERTOP, PTE_W)) | ||||||
|     return 0; |     return 0; | ||||||
|   // Map kernel text read-only
 |   // Map kernel and free memory pool
 | ||||||
|   if (!mappages(pgdir, (void *) kerntext, kerntsz, kerntext, 0)) |   if (!mappages(pgdir, (void *)0x100000, PHYSTOP-0x100000, 0x100000, PTE_W)) | ||||||
|     return 0; |  | ||||||
|   // Map kernel data read/write
 |  | ||||||
|   if (!mappages(pgdir, (void *) kerndata, kerndsz, kerndata, PTE_W)) |  | ||||||
|     return 0; |  | ||||||
|   // Map dynamically-allocated memory read/write (kernel stacks, user mem)
 |  | ||||||
|   if (!mappages(pgdir, (void *) kernend, freesz, PADDR(kernend), PTE_W)) |  | ||||||
|     return 0; |     return 0; | ||||||
|   // Map devices such as ioapic, lapic, ...
 |   // Map devices such as ioapic, lapic, ...
 | ||||||
|   if (!mappages(pgdir, (void *)0xFE000000, 0x2000000, 0xFE000000, PTE_W)) |   if (!mappages(pgdir, (void *)0xFE000000, 0x2000000, 0xFE000000, PTE_W)) | ||||||
|  | @ -333,31 +321,6 @@ copyuvm(pde_t *pgdir, uint sz) | ||||||
|   return d; |   return d; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Gather information about physical memory layout.
 |  | ||||||
| // Called once during boot.
 |  | ||||||
| // Really should find out how much physical memory
 |  | ||||||
| // there is rather than assuming PHYSTOP.
 |  | ||||||
| void |  | ||||||
| pminit(void) |  | ||||||
| { |  | ||||||
|   extern char end[]; |  | ||||||
|   struct proghdr *ph; |  | ||||||
|   struct elfhdr *elf = (struct elfhdr*)0x10000;  // scratch space
 |  | ||||||
| 
 |  | ||||||
|   if (elf->magic != ELF_MAGIC || elf->phnum != 2) |  | ||||||
|     panic("pminit: need a text and data segment\n"); |  | ||||||
| 
 |  | ||||||
|   ph = (struct proghdr*)((uchar*)elf + elf->phoff); |  | ||||||
|   kernend = ((uint)end + PGSIZE) & ~(PGSIZE-1); |  | ||||||
|   kerntext = ph[0].va; |  | ||||||
|   kerndata = ph[1].va; |  | ||||||
|   kerntsz = ph[0].memsz; |  | ||||||
|   kerndsz = ph[1].memsz; |  | ||||||
|   freesz = PHYSTOP - kernend; |  | ||||||
| 
 |  | ||||||
|   kinit((char *)kernend, freesz); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Allocate one page table for the machine for the kernel address
 | // Allocate one page table for the machine for the kernel address
 | ||||||
| // space for scheduler processes.
 | // space for scheduler processes.
 | ||||||
| void | void | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Robert Morris
						Robert Morris