BSS isn't stored in the image that the loader brought into memory. We
just use @func{memset} to zero it out. The other task of
@func{ram_init} is to read out the machine's memory size from where
-the loader stored it and put it into the @code{ram_pages} variable for
+the loader stored it and put it into the @code{init_ram_pages} variable for
later use.
Next, @func{main} calls @func{read_command_line} to break the kernel command
+#include "vm/swap.h"
/* Amount of physical memory, in 4 kB pages. */
- size_t ram_pages;
+ size_t init_ram_pages;
@@ -124,6 +126,9 @@ main (void)
filesys_init (format_filesys);
#endif
+
+ lock_init (&scan_lock);
+
-+ frames = malloc (sizeof *frames * ram_pages);
++ frames = malloc (sizeof *frames * init_ram_pages);
+ if (frames == NULL)
+ PANIC ("out of memory allocating page frames");
+
+#include "vm/swap.h"
/* Amount of physical memory, in 4 kB pages. */
- size_t ram_pages;
+ size_t init_ram_pages;
@@ -124,6 +126,9 @@ main (void)
filesys_init (format_filesys);
#endif
+
+ lock_init (&scan_lock);
+
-+ frames = malloc (sizeof *frames * ram_pages);
++ frames = malloc (sizeof *frames * init_ram_pages);
+ if (frames == NULL)
+ PANIC ("out of memory allocating page frames");
+
#endif
/* Amount of physical memory, in 4 kB pages. */
-size_t ram_pages;
+size_t init_ram_pages;
/* Page directory with kernel mappings only. */
uint32_t *init_page_dir;
console_init ();
/* Greet user. */
- printf ("Pintos booting with %'zu kB RAM...\n", ram_pages * PGSIZE / 1024);
+ printf ("Pintos booting with %'zu kB RAM...\n",
+ init_ram_pages * PGSIZE / 1024);
/* Initialize memory system. */
palloc_init (user_page_limit);
memset (&_start_bss, 0, &_end_bss - &_start_bss);
/* Get RAM size from loader. See loader.S. */
- ram_pages = *(uint32_t *) ptov (LOADER_RAM_PGS);
+ init_ram_pages = *(uint32_t *) ptov (LOADER_RAM_PGS);
}
/* Populates the base page directory and page table with the
pd = init_page_dir = palloc_get_page (PAL_ASSERT | PAL_ZERO);
pt = NULL;
- for (page = 0; page < ram_pages; page++)
+ for (page = 0; page < init_ram_pages; page++)
{
uintptr_t paddr = page * PGSIZE;
char *vaddr = ptov (paddr);
#include <stdint.h>
/* Physical memory size, in 4 kB pages. */
-extern size_t ram_pages;
+extern size_t init_ram_pages;
/* Page directory with kernel mappings only. */
extern uint32_t *init_page_dir;
/* Free memory. */
uint8_t *free_start = pg_round_up (&_end);
- uint8_t *free_end = ptov (ram_pages * PGSIZE);
+ uint8_t *free_end = ptov (init_ram_pages * PGSIZE);
size_t free_pages = (free_end - free_start) / PGSIZE;
size_t user_pages = free_pages / 2;
size_t kernel_pages;
ASSERT (pg_ofs (upage) == 0);
ASSERT (pg_ofs (kpage) == 0);
ASSERT (is_user_vaddr (upage));
- ASSERT (vtop (kpage) >> PTSHIFT < ram_pages);
+ ASSERT (vtop (kpage) >> PTSHIFT < init_ram_pages);
ASSERT (pd != init_page_dir);
pte = lookup_page (pd, upage, true);