46static bool format_filesys;
50static const char *filesys_bdev_name;
51static const char *scratch_bdev_name;
53static const char *swap_bdev_name;
66static void usage (
void);
69static void locate_block_devices (
void);
70static void locate_block_device (
enum block_type,
const char *
name);
126 locate_block_devices ();
130 printf (
"Boot complete.\n");
153 extern char _start_bss, _end_bss;
154 memset (&_start_bss, 0, &_end_bss - &_start_bss);
166 extern char _start, _end_kernel_text;
173 char *vaddr =
ptov (paddr);
174 size_t pde_idx =
pd_no (vaddr);
175 size_t pte_idx =
pt_no (vaddr);
176 bool in_kernel_text = &
_start <= vaddr && vaddr < &_end_kernel_text;
178 if (pd[pde_idx] == 0)
208 for (i = 0; i < argc; i++)
211 PANIC (
"command line arguments overflow");
219 printf (
"Kernel command line:");
220 for (i = 0; i < argc; i++)
224 printf (
" '%s'", argv[i]);
235 for (; *argv !=
NULL && **argv ==
'-'; argv++)
249 format_filesys =
true;
251 filesys_bdev_name =
value;
253 scratch_bdev_name =
value;
256 swap_bdev_name =
value;
268 PANIC (
"unknown option `%s' (use -h for help)",
name);
288 const char *task = argv[1];
290 printf (
"Executing '%s':\n", task);
296 printf (
"Execution of '%s' complete.\n", task);
309 void (*
function) (
char **argv);
313 static const struct action actions[] =
326 while (*argv !=
NULL)
328 const struct action *a;
332 for (a = actions; ; a++)
334 PANIC (
"unknown action `%s' (use -h for help)", *argv);
335 else if (!
strcmp (*argv, a->name))
339 for (i = 1; i < a->argc; i++)
341 PANIC (
"action `%s' requires %d argument(s)", *argv, a->argc - 1);
355 printf (
"\nCommand line syntax: [OPTION...] [ACTION...]\n"
356 "Options must precede actions.\n"
357 "Actions are executed in the order specified.\n"
358 "\nAvailable actions:\n"
360 " run 'PROG [ARG...]' Run PROG and wait for it to complete.\n"
362 " run TEST Run TEST.\n"
365 " ls List files in the root directory.\n"
366 " cat FILE Print FILE to the console.\n"
367 " rm FILE Delete FILE.\n"
368 "Use these actions indirectly via `pintos' -g and -p options:\n"
369 " extract Untar from scratch device into file system.\n"
370 " append FILE Append FILE to tar file on scratch device.\n"
373 " -h Print this help message and power off.\n"
374 " -q Power off VM after actions or on panic.\n"
375 " -r Reboot after actions.\n"
377 " -f Format file system device during startup.\n"
378 " -filesys=BDEV Use BDEV for file system instead of default.\n"
379 " -scratch=BDEV Use BDEV for scratch instead of default.\n"
381 " -swap=BDEV Use BDEV for swap instead of default.\n"
384 " -rs=SEED Set random number seed to SEED.\n"
385 " -mlfqs Use multi-level feedback queue scheduler.\n"
387 " -ul=COUNT Limit user memory to COUNT pages.\n"
396locate_block_devices (
void)
401 locate_block_device (
BLOCK_SWAP, swap_bdev_name);
418 PANIC (
"No such block device \"%s\"",
name);
struct block * block_first(void)
Returns the first block device in kernel probe order, or a null pointer if no block devices are regis...
struct block * block_get_by_name(const char *name)
Returns the block device with the given NAME, or a null pointer if no block device has that name.
const char * block_type_name(enum block_type type)
Returns a human-readable name for the given block device TYPE.
void block_set_role(enum block_type role, struct block *block)
Assigns BLOCK the given ROLE.
const char * block_name(struct block *block)
Returns BLOCK's name (e.g.
struct block * block_next(struct block *block)
Returns the block device following BLOCK in kernel probe order, or a null pointer if BLOCK is the las...
block_type
Type of a block device.
@ BLOCK_FILESYS
File system.
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
void _start(int argc, char *argv[])
void exception_init(void)
Registers handlers for interrupts that can be caused by user programs.
void filesys_init(bool format)
Initializes the file system module.
void fsutil_cat(char **argv)
Prints the contents of file ARGV[1] to the system console as hex and ASCII.
void fsutil_ls(char **argv UNUSED)
List files in the root directory.
void fsutil_append(char **argv)
Copies file FILE_NAME from the file system to the scratch device, in ustar format.
void fsutil_extract(char **argv UNUSED)
Extracts a ustar-format tar archive from the scratch block device into the Pintos file system.
void fsutil_rm(char **argv)
Deletes file ARGV[1].
void gdt_init(void)
Sets up a proper GDT.
void ide_init(void)
Initialize the disk subsystem and detect disks.
static void run_actions(char **argv)
Executes all of the actions specified in ARGV[] up to the null pointer sentinel.
uint32_t * init_page_dir
Page directory with kernel mappings only.
int pintos_init(void)
Pintos main entry point.
static char ** parse_options(char **argv)
Parses options in ARGV[] and returns the first non-option argument.
static void paging_init(void)
Populates the base page directory and page table with the kernel virtual mapping, and then sets up th...
static void bss_init(void)
Clear the "BSS", a segment that should be initialized to zeros.
static void usage(void)
Prints a kernel command line help message and powers off the machine.
static char ** read_command_line(void)
Breaks the kernel command line into words and returns them as an argv-like array.
static size_t user_page_limit
-ul: Maximum number of pages to put into palloc's user pool.
static void run_task(char **argv)
Runs the task specified in ARGV[1].
void intr_init(void)
Initializes the interrupt system.
void kbd_init(void)
Initializes the keyboard.
void console_init(void)
Enable console locking.
int printf(const char *format,...)
Writes formatted output to the console.
int atoi(const char *s)
Converts a string representation of a signed decimal integer in S into an ‘int’, which is returned.
uint32_t init_ram_pages
Amount of physical memory, in 4 kB pages.
#define LOADER_ARGS
Command-line args.
#define LOADER_ARG_CNT
Number of args.
void malloc_init(void)
Initializes the malloc() descriptors.
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
void palloc_init(size_t user_page_limit)
Initializes the page allocator.
@ PAL_ZERO
Zero page contents.
@ PAL_ASSERT
Panic on failure.
tid_t process_execute(const char *file_name)
Starts a new thread running a user program loaded from FILENAME.
int process_wait(tid_t child_tid UNUSED)
Waits for thread TID to die and returns its exit status.
static unsigned pt_no(const void *va)
Obtains page table index from a virtual address.
static uint32_t pde_create(uint32_t *pt)
Returns a PDE that points to page table PT.
static uintptr_t pd_no(const void *va)
Obtains page directory index from a virtual address.
static uint32_t pte_create_kernel(void *page, bool writable)
Returns a PTE that points to PAGE.
void random_init(unsigned seed)
Initializes or reinitializes the PRNG with the given SEED.
time_t rtc_get_time(void)
Returns number of seconds since Unix epoch of January 1,.
void serial_init_queue(void)
Initializes the serial port device for queued interrupt-driven I/O.
void shutdown(void)
Shuts down the machine in the way configured by shutdown_configure().
void shutdown_configure(enum shutdown_type type)
Sets TYPE as the way that machine will shut down when Pintos execution is complete.
void shutdown_power_off(void)
Powers down the machine we're running on, as long as we're running on Bochs or QEMU.
@ SHUTDOWN_POWER_OFF
Power off the machine (if possible).
@ SHUTDOWN_REBOOT
Reboot the machine (if possible).
#define SIZE_MAX
lib/stdint.h
size_t strnlen(const char *string, size_t maxlen)
If STRING is less than MAXLEN characters in length, returns its actual length.
char * strchr(const char *string, int c_)
Finds and returns the first occurrence of C in STRING, or a null pointer if C does not appear in STRI...
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
char * strtok_r(char *s, const char *delimiters, char **save_ptr)
Breaks a string into tokens separated by DELIMITERS.
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
void run_test(const char *name)
Runs the test named NAME.
void thread_start(void)
Starts preemptive thread scheduling by enabling interrupts.
bool thread_mlfqs
If false (default), use round-robin scheduler.
void thread_exit(void)
Deschedules the current thread and destroys it.
void timer_init(void)
Sets up the timer to interrupt TIMER_FREQ times per second, and registers the corresponding interrupt...
void timer_calibrate(void)
Calibrates loops_per_tick, used to implement brief delays.
void tss_init(void)
Initializes the kernel TSS.
void syscall_init(void)
userprog/syscall.h
static uintptr_t vtop(const void *vaddr)
Returns physical address at which kernel virtual address VADDR is mapped.
#define PGSIZE
Bytes in a page.
static void * ptov(uintptr_t paddr)
Returns kernel virtual address at which physical address PADDR is mapped.