Commit 57e6723fac85450f8ff3807310b029af6e0513a8
- Diff rendering mode:
- inline
- side by side
kernel/arch/x86/paging.cc
(8 / 8)
|   | |||
| 27 | 27 | namespace paging | |
| 28 | 28 | { | |
| 29 | 29 | // A bitset storing the used and free frames | |
| 30 | u32int * frames; | ||
| 30 | uintptr * frames; | ||
| 31 | 31 | u32int n_frames; | |
| 32 | 32 | ||
| 33 | 33 | // Paging function prototypes | |
| 34 | 34 | void set_frame(uintptr address); | |
| 35 | 35 | void clear_frame(uintptr address); | |
| 36 | u32int test_frame(uintptr address); | ||
| 37 | u32int first_frame(); | ||
| 36 | uintptr test_frame(uintptr address); | ||
| 37 | uintptr first_frame(); | ||
| 38 | 38 | page_table_t * clone_table(page_table_t * src, uintptr * physAddr); | |
| 39 | 39 | ||
| 40 | 40 | void initialise() | |
| … | … | ||
| 48 | 48 | // Work out the number of frames we can fit in our memory, allocate | |
| 49 | 49 | // space for them, and then clear that memory | |
| 50 | 50 | n_frames = memory_end / PAGE_SIZE; | |
| 51 | frames = (u32int *) kmalloc(INDEX_FROM_BIT(n_frames)); | ||
| 51 | frames = (uintptr *) kmalloc(INDEX_FROM_BIT(n_frames)); | ||
| 52 | 52 | memset(frames, 0, INDEX_FROM_BIT(n_frames)); | |
| 53 | 53 | ||
| 54 | 54 | // Make a page directory for the kernel, and set its physical address | |
| 55 | 55 | kernel_directory = (page_directory_t *) kmalloc(sizeof(page_directory_t), true); | |
| 56 | 56 | memset(kernel_directory, 0, sizeof(page_directory_t)); | |
| 57 | kernel_directory->physicalAddress = (u32int)kernel_directory->tablesPhysical; | ||
| 57 | kernel_directory->physicalAddress = (uintptr)kernel_directory->tablesPhysical; | ||
| 58 | 58 | ||
| 59 | 59 | // Set the kernel directory as the current directory | |
| 60 | 60 | current_directory = kernel_directory; | |
| … | … | ||
| 76 | 76 | while(i < placement_address + PAGE_SIZE) | |
| 77 | 77 | { | |
| 78 | 78 | // Set the kernel code as readable but not writable from the userspace | |
| 79 | allocate_frame(get_page(i, true, kernel_directory), false, false); | ||
| 79 | allocate_frame(get_page(i, true, kernel_directory), true, false); | ||
| 80 | 80 | ||
| 81 | 81 | i += PAGE_SIZE; | |
| 82 | 82 | } | |
| … | … | ||
| 84 | 84 | // Allocate the pages for the kernel heap (mapped earlier) | |
| 85 | 85 | for(i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i += PAGE_SIZE) | |
| 86 | 86 | { | |
| 87 | allocate_frame(get_page(i, true, kernel_directory), false, false); | ||
| 87 | allocate_frame(get_page(i, true, kernel_directory), true, false); | ||
| 88 | 88 | } | |
| 89 | 89 | ||
| 90 | 90 | // Register the page fault handler before enabling paging | |
| … | … | ||
| 98 | 98 | ||
| 99 | 99 | // Clone the kernel directory and switch to the clone | |
| 100 | 100 | current_directory = clone_directory(kernel_directory); | |
| 101 | //switch_directory(current_directory); | ||
| 101 | switch_directory(current_directory); | ||
| 102 | 102 | ||
| 103 | 103 | // Sucess! | |
| 104 | 104 | debug::startup_status(true); |
kernel/fs/initrd.cc
(4 / 4)
|   | |||
| 67 | 67 | ||
| 68 | 68 | struct fs::dirent dirent; | |
| 69 | 69 | ||
| 70 | u32int read(fs::node * node, u32int offset, size_t size, u8int * buffer); | ||
| 70 | size_t read(fs::node * node, u32int offset, size_t size, u8int * buffer); | ||
| 71 | 71 | struct fs::dirent * readdir(fs::node * dir, u32int index); | |
| 72 | 72 | fs::node * finddir(fs::node * dir, const char * name); | |
| 73 | 73 | ||
| 74 | 74 | // Mount the initrd on the VFS | |
| 75 | 75 | // This function returns the root node of the ramdisk, which | |
| 76 | 76 | // is also the root of the filesystem at this time. | |
| 77 | fs::node * initialise(u32int initrd_address) | ||
| 77 | fs::node * initialise(uintptr initrd_address) | ||
| 78 | 78 | { | |
| 79 | 79 | debug::startup_message("Mounting Root Filesystem"); | |
| 80 | 80 | ||
| … | … | ||
| 202 | 202 | } | |
| 203 | 203 | ||
| 204 | 204 | // Read a file from the initrd | |
| 205 | u32int read(fs::node * node, u32int offset, size_t size, u8int * buffer) | ||
| 205 | size_t read(fs::node * node, u32int offset, size_t size, u8int * buffer) | ||
| 206 | 206 | { | |
| 207 | 207 | uintptr address = initrd_start; | |
| 208 | u32int file_size; | ||
| 208 | size_t file_size; | ||
| 209 | 209 | ||
| 210 | 210 | tar_header * header = (tar_header *) address; | |
| 211 | 211 |
kernel/mm/kheap.cc
(9 / 9)
|   | |||
| 40 | 40 | ASSERT(end % PAGE_SIZE == 0); | |
| 41 | 41 | ||
| 42 | 42 | // Initialise our index | |
| 43 | temp->heap_index = create_index((u32int *)start, HEAP_INDEX_SIZE); | ||
| 43 | temp->heap_index = create_index((uintptr *)start, HEAP_INDEX_SIZE); | ||
| 44 | 44 | ||
| 45 | 45 | // Move the start address past the index | |
| 46 | start += sizeof(u32int *) * HEAP_INDEX_SIZE; | ||
| 46 | start += sizeof(uintptr *) * HEAP_INDEX_SIZE; | ||
| 47 | 47 | ||
| 48 | 48 | // Make sure the start address is page aligned | |
| 49 | 49 | if ((start & 0xFFFFF000) != 0) | |
| … | … | ||
| 78 | 78 | index temp; | |
| 79 | 79 | ||
| 80 | 80 | // Set the array address to the address argument | |
| 81 | temp.array = (u32int **)address; | ||
| 81 | temp.array = (uintptr **)address; | ||
| 82 | 82 | ||
| 83 | 83 | // Clear the array | |
| 84 | 84 | memset(temp.array, 0, max_size * sizeof(u32int *)); | |
| … | … | ||
| 252 | 252 | ||
| 253 | 253 | while(new_size < i) | |
| 254 | 254 | { | |
| 255 | paging::free_frame(paging::get_page(heap->start_address + i, 0, kernel_directory)); | ||
| 255 | paging::free_frame(paging::get_page(heap->start_address + i, false, kernel_directory)); | ||
| 256 | 256 | i -= PAGE_SIZE; | |
| 257 | 257 | } | |
| 258 | 258 | ||
| … | … | ||
| 275 | 275 | *phys = (page->frame * PAGE_SIZE) + ((uintptr)address & 0xFFF); | |
| 276 | 276 | } | |
| 277 | 277 | ||
| 278 | return (u32int)address; | ||
| 278 | return (uintptr)address; | ||
| 279 | 279 | } | |
| 280 | 280 | else | |
| 281 | 281 | { | |
| … | … | ||
| 285 | 285 | ||
| 286 | 286 | // We check if we want to page-allign the memory, and whether it | |
| 287 | 287 | // is already page aligned | |
| 288 | if(align && (placement_address & 0xFFFFF000) ) | ||
| 288 | if(align && (placement_address & 0xFFFFF000)) | ||
| 289 | 289 | { | |
| 290 | 290 | // If it's not aligned... | |
| 291 | 291 | placement_address &= 0xFFFFF000; | |
| … | … | ||
| 402 | 402 | ||
| 403 | 403 | // Check if we want to page align the data, and page align it if it is not coincidentally | |
| 404 | 404 | // already aligned. Also, make a hole in front of the block to not waste space | |
| 405 | if(page_align && (original_hole_pos & 0xFFFFF000) == 1) | ||
| 405 | if(page_align && (original_hole_pos & 0xFFFFF000)) | ||
| 406 | 406 | { | |
| 407 | 407 | uintptr new_location = original_hole_pos + PAGE_SIZE - (original_hole_pos & 0xFFF) - sizeof(header); | |
| 408 | 408 | ||
| … | … | ||
| 584 | 584 | // commands. | |
| 585 | 585 | ||
| 586 | 586 | // This version of kmalloc can return a physical address | |
| 587 | u32int kmalloc(size_t sz, u32int * phys, bool align) | ||
| 587 | uintptr kmalloc(size_t sz, uintptr * phys, bool align) | ||
| 588 | 588 | { | |
| 589 | 589 | return heap::kmalloc_internal(sz, align, phys); | |
| 590 | 590 | } | |
| 591 | 591 | ||
| 592 | 592 | // Normal kmalloc - can also optionally page align | |
| 593 | u32int kmalloc(size_t sz, bool align) | ||
| 593 | uintptr kmalloc(size_t sz, bool align) | ||
| 594 | 594 | { | |
| 595 | 595 | return heap::kmalloc_internal(sz, align, NULL); | |
| 596 | 596 | } |

