Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • y2-rhymansaib/pintos_student
1 result
Select Git revision
Show changes
Commits on Source (625)
This is a variant of the Pintos Operating System for use as part of Operating Systems module at the University of the West of England (UWE).
start the project
Pintos, including its documentation, is subject to the following
license:
Copyright (C) 2004, 2005, 2006 Board of Trustees, Leland Stanford
Jr. University. All rights reserved.
......
......@@ -40,7 +40,7 @@ endif
# Compiler and assembler invocation.
DEFINES =
WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers
CFLAGS = -g -msoft-float -O -DBEN_MODS -std=gnu99
CFLAGS = -g -msoft-float -O
CPPFLAGS = -nostdinc -I$(SRCDIR) -I$(SRCDIR)/lib
ASFLAGS = -Wa,--gstabs
LDFLAGS =
......
......@@ -40,4 +40,5 @@ bool intq_full (const struct intq *);
uint8_t intq_getc (struct intq *);
void intq_putc (struct intq *, uint8_t);
#endif /* devices/intq.h */
......@@ -7,7 +7,7 @@
#include "threads/interrupt.h"
#include "threads/synch.h"
#include "threads/thread.h"
/* See [8254] for hardware details of the 8254 timer chip. */
#if TIMER_FREQ < 19
......@@ -33,7 +33,7 @@ static void real_time_delay (int64_t num, int32_t denom);
/* Sets up the timer to interrupt TIMER_FREQ times per second,
and registers the corresponding interrupt. */
void
timer_init (void)
timer_init (void)
{
pit_configure_channel (0, 2, TIMER_FREQ);
intr_register_ext (0x20, timer_interrupt, "8254 Timer");
......@@ -41,7 +41,7 @@ timer_init (void)
/* Calibrates loops_per_tick, used to implement brief delays. */
void
timer_calibrate (void)
timer_calibrate (void)
{
unsigned high_bit, test_bit;
......@@ -51,7 +51,7 @@ timer_calibrate (void)
/* Approximate loops_per_tick as the largest power-of-two
still less than one timer tick. */
loops_per_tick = 1u << 10;
while (!too_many_loops (loops_per_tick << 1))
while (!too_many_loops (loops_per_tick << 1))
{
loops_per_tick <<= 1;
ASSERT (loops_per_tick != 0);
......@@ -68,7 +68,7 @@ timer_calibrate (void)
/* Returns the number of timer ticks since the OS booted. */
int64_t
timer_ticks (void)
timer_ticks (void)
{
enum intr_level old_level = intr_disable ();
int64_t t = ticks;
......@@ -79,7 +79,7 @@ timer_ticks (void)
/* Returns the number of timer ticks elapsed since THEN, which
should be a value once returned by timer_ticks(). */
int64_t
timer_elapsed (int64_t then)
timer_elapsed (int64_t then)
{
return timer_ticks () - then;
}
......@@ -87,19 +87,24 @@ timer_elapsed (int64_t then)
/* Sleeps for approximately TICKS timer ticks. Interrupts must
be turned on. */
void
timer_sleep (int64_t ticks)
timer_sleep (int64_t ticks)
{
int64_t start = timer_ticks ();
ASSERT (intr_get_level () == INTR_ON);
while (timer_elapsed (start) < ticks)
thread_yield ();
enum intr_level old_level = intr_disable ();
// sleep the thread for `ticks` seconds,
// until the tick becomes [start + ticks]
thread_sleep_until (start + ticks);
intr_set_level (old_level);
}
/* Sleeps for approximately MS milliseconds. Interrupts must be
turned on. */
void
timer_msleep (int64_t ms)
timer_msleep (int64_t ms)
{
real_time_sleep (ms, 1000);
}
......@@ -107,7 +112,7 @@ timer_msleep (int64_t ms)
/* Sleeps for approximately US microseconds. Interrupts must be
turned on. */
void
timer_usleep (int64_t us)
timer_usleep (int64_t us)
{
real_time_sleep (us, 1000 * 1000);
}
......@@ -115,7 +120,7 @@ timer_usleep (int64_t us)
/* Sleeps for approximately NS nanoseconds. Interrupts must be
turned on. */
void
timer_nsleep (int64_t ns)
timer_nsleep (int64_t ns)
{
real_time_sleep (ns, 1000 * 1000 * 1000);
}
......@@ -128,7 +133,7 @@ timer_nsleep (int64_t ns)
will cause timer ticks to be lost. Thus, use timer_msleep()
instead if interrupts are enabled. */
void
timer_mdelay (int64_t ms)
timer_mdelay (int64_t ms)
{
real_time_delay (ms, 1000);
}
......@@ -141,7 +146,7 @@ timer_mdelay (int64_t ms)
will cause timer ticks to be lost. Thus, use timer_usleep()
instead if interrupts are enabled. */
void
timer_udelay (int64_t us)
timer_udelay (int64_t us)
{
real_time_delay (us, 1000 * 1000);
}
......@@ -154,30 +159,30 @@ timer_udelay (int64_t us)
will cause timer ticks to be lost. Thus, use timer_nsleep()
instead if interrupts are enabled.*/
void
timer_ndelay (int64_t ns)
timer_ndelay (int64_t ns)
{
real_time_delay (ns, 1000 * 1000 * 1000);
}
/* Prints timer statistics. */
void
timer_print_stats (void)
timer_print_stats (void)
{
printf ("Timer: %"PRId64" ticks\n", timer_ticks ());
}
/* Timer interrupt handler. */
static void
timer_interrupt (struct intr_frame *args UNUSED)
{
ticks++;
thread_tick ();
thread_tick ( timer_ticks() );
}
/* Returns true if LOOPS iterations waits for more than one timer
tick, otherwise false. */
static bool
too_many_loops (unsigned loops)
too_many_loops (unsigned loops)
{
/* Wait for a timer tick. */
int64_t start = ticks;
......@@ -201,7 +206,7 @@ too_many_loops (unsigned loops)
differently in different places the results would be difficult
to predict. */
static void NO_INLINE
busy_wait (int64_t loops)
busy_wait (int64_t loops)
{
while (loops-- > 0)
barrier ();
......@@ -209,12 +214,12 @@ busy_wait (int64_t loops)
/* Sleep for approximately NUM/DENOM seconds. */
static void
real_time_sleep (int64_t num, int32_t denom)
real_time_sleep (int64_t num, int32_t denom)
{
/* Convert NUM/DENOM seconds into timer ticks, rounding down.
(NUM / DENOM) s
---------------------- = NUM * TIMER_FREQ / DENOM ticks.
(NUM / DENOM) s
---------------------- = NUM * TIMER_FREQ / DENOM ticks.
1 s / TIMER_FREQ ticks
*/
int64_t ticks = num * TIMER_FREQ / denom;
......@@ -224,14 +229,14 @@ real_time_sleep (int64_t num, int32_t denom)
{
/* We're waiting for at least one full timer tick. Use
timer_sleep() because it will yield the CPU to other
processes. */
timer_sleep (ticks);
processes. */
timer_sleep (ticks);
}
else
else
{
/* Otherwise, use a busy-wait loop for more accurate
sub-tick timing. */
real_time_delay (num, denom);
real_time_delay (num, denom);
}
}
......@@ -242,5 +247,5 @@ real_time_delay (int64_t num, int32_t denom)
/* Scale the numerator and denominator down by 1000 to avoid
the possibility of overflow. */
ASSERT (denom % 1000 == 0);
busy_wait (loops_per_tick * num / 1000 * TIMER_FREQ / (denom / 1000));
busy_wait (loops_per_tick * num / 1000 * TIMER_FREQ / (denom / 1000));
}
......@@ -8,6 +8,7 @@
#include "threads/interrupt.h"
#include "threads/vaddr.h"
/* VGA text screen support. See [FREEVGA] for more information. */
/* Number of columns and rows on the text display. */
......
cat
cmp
cp
echo
halt
hex-dump
ls
mcat
mcp
mkdir
pwd
rm
shell
bubsort
insult
lineup
matmult
recursor
*.d
SRCDIR = ..
# Test programs to compile, and a list of sources for each.
# To add a new test, put its name on the PROGS list
# and then add a name_SRC line that lists its source files.
PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \
bubsort insult lineup matmult recursor my
bubsort insult lineup matmult recursor
# Should work from project 2 onward.
cat_SRC = cat.c
cmp_SRC = cmp.c
cp_SRC = cp.c
......@@ -18,15 +14,10 @@ lineup_SRC = lineup.c
ls_SRC = ls.c
recursor_SRC = recursor.c
rm_SRC = rm.c
my_SRC = my.c
# Should work in project 3; also in project 4 if VM is included.
bubsort_SRC = bubsort.c
matmult_SRC = matmult.c
mcat_SRC = mcat.c
mcp_SRC = mcp.c
# Should work in project 4.
mkdir_SRC = mkdir.c
pwd_SRC = pwd.c
shell_SRC = shell.c
......
/* sort.c
/* sort.c
Test program to sort a large number of integers.
Intention is to stress virtual memory system.
Ideally, we could read the unsorted array off of the file
system, and store the result back to the file system! */
#include <stdio.h>
......
......@@ -6,21 +6,21 @@
#include <syscall.h>
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
bool success = true;
int i;
for (i = 1; i < argc; i++)
for (i = 1; i < argc; i++)
{
int fd = open (argv[i]);
if (fd < 0)
if (fd < 0)
{
printf ("%s: open failed\n", argv[i]);
success = false;
continue;
}
for (;;)
for (;;)
{
char buffer[1024];
int bytes_read = read (fd, buffer, sizeof buffer);
......
......@@ -6,11 +6,11 @@
#include <syscall.h>
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
int fd[2];
if (argc != 3)
if (argc != 3)
{
printf ("usage: cmp A B\n");
return EXIT_FAILURE;
......@@ -18,20 +18,20 @@ main (int argc, char *argv[])
/* Open files. */
fd[0] = open (argv[1]);
if (fd[0] < 0)
if (fd[0] < 0)
{
printf ("%s: open failed\n", argv[1]);
return EXIT_FAILURE;
}
fd[1] = open (argv[2]);
if (fd[1] < 0)
if (fd[1] < 0)
{
printf ("%s: open failed\n", argv[1]);
return EXIT_FAILURE;
}
/* Compare data. */
for (;;)
for (;;)
{
int pos;
char buffer[2][1024];
......@@ -47,7 +47,7 @@ main (int argc, char *argv[])
break;
for (i = 0; i < min_read; i++)
if (buffer[0][i] != buffer[1][i])
if (buffer[0][i] != buffer[1][i])
{
printf ("Byte %d is %02hhx ('%c') in %s but %02hhx ('%c') in %s\n",
pos + i,
......
......@@ -6,11 +6,11 @@ Copies one file to another. */
#include <syscall.h>
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
int in_fd, out_fd;
if (argc != 3)
if (argc != 3)
{
printf ("usage: cp OLD NEW\n");
return EXIT_FAILURE;
......@@ -18,33 +18,33 @@ main (int argc, char *argv[])
/* Open input file. */
in_fd = open (argv[1]);
if (in_fd < 0)
if (in_fd < 0)
{
printf ("%s: open failed\n", argv[1]);
return EXIT_FAILURE;
}
/* Create and open output file. */
if (!create (argv[2], filesize (in_fd)))
if (!create (argv[2], filesize (in_fd)))
{
printf ("%s: create failed\n", argv[2]);
return EXIT_FAILURE;
}
out_fd = open (argv[2]);
if (out_fd < 0)
if (out_fd < 0)
{
printf ("%s: open failed\n", argv[2]);
return EXIT_FAILURE;
}
/* Copy data. */
for (;;)
for (;;)
{
char buffer[1024];
int bytes_read = read (in_fd, buffer, sizeof buffer);
if (bytes_read == 0)
break;
if (write (out_fd, buffer, bytes_read) != bytes_read)
if (write (out_fd, buffer, bytes_read) != bytes_read)
{
printf ("%s: write failed\n", argv[2]);
return EXIT_FAILURE;
......
......@@ -4,7 +4,7 @@
int
main (int argc, char **argv)
{
int i,j;
int i;
for (i = 0; i < argc; i++)
printf ("%s ", argv[i]);
......
#include <syscall.h>
#include <stdio.h>
int main(void) {
int fd = 0; // Assume file descriptor 0 represents stdin
unsigned position = tell(fd);
printf("Current position of file pointer for fd %d: %u\n", fd, position);
return 0;
}
/* halt.c
Simple program to test whether running a user program works.
Just invokes a system call that shuts down the OS. */
#include <syscall.h>
......
......@@ -6,21 +6,21 @@
#include <syscall.h>
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
bool success = true;
int i;
for (i = 1; i < argc; i++)
for (i = 1; i < argc; i++)
{
int fd = open (argv[i]);
if (fd < 0)
if (fd < 0)
{
printf ("%s: open failed\n", argv[i]);
success = false;
continue;
}
for (;;)
for (;;)
{
char buffer[1024];
int pos = tell (fd);
......
/* Insult.c
This is a version of the famous CS 107 random sentence
generator. I wrote a program that reads a grammar definition
file and writes a C file containing that grammar as hard code
static C strings. Thus the majority of the code below in
machine generated and totally unreadable. The arrays created
are specially designed to make generating the sentences as
easy as possible.
Originally by Greg Hutchins, March 1998.
Modified by Ben Pfaff for Pintos, Sept 2004. */
char *start[] =
{ "You", "1", "5", ".", "May", "13", ".", "With", "the", "19", "of", "18",
",", "may", "13", "."
......@@ -250,13 +239,13 @@ usage (int ret_code, const char *message, ...)
{
va_list args;
if (message != NULL)
if (message != NULL)
{
va_start (args, message);
vprintf (message, args);
va_end (args);
}
printf ("\n"
"Usage: insult [OPTION]...\n"
"Prints random insults to screen.\n\n"
......@@ -273,7 +262,7 @@ main (int argc, char *argv[])
{
int sentence_cnt, new_seed, i, file_flag, sent_flag, seed_flag;
int handle;
new_seed = 4951;
sentence_cnt = 4;
file_flag = 0;
......@@ -310,10 +299,6 @@ main (int argc, char *argv[])
if (++i >= argc)
usage (-1, "Missing value for -f");
/* Because files have fixed length in the basic Pintos
file system, the 0 argument means that this option
will not be useful until project 4 is
implemented. */
create (argv[i], 0);
handle = open (argv[i]);
if (handle < 0)
......@@ -337,7 +322,7 @@ main (int argc, char *argv[])
expand (0, daGrammar, daGLoc, handle);
hprintf (handle, "\n\n");
}
if (file_flag)
close (handle);
......