Working backdoor filesystem implementation.
[pintos-anon] / src / filesys / filesys-stub.c
1 #include "filesys-stub.h"
2 #include <stdarg.h>
3 #include "backdoor.h"
4 #include "debug.h"
5 #include "io.h"
6 #include "lib.h"
7 #include "synch.h"
8
9 static struct lock lock;
10
11 void 
12 filesys_stub_init (void)
13 {
14   lock_init (&lock, "filesys-stub");
15 }
16
17 void 
18 filesys_stub_lock (void)
19 {
20   lock_acquire (&lock);
21 }
22
23 void 
24 filesys_stub_unlock (void)
25 {
26   lock_release (&lock);
27 }
28 \f
29 static void
30 out_byte (uint8_t byte, void *aux UNUSED) 
31 {
32   outb (0x8901, byte);
33 }
34
35 void 
36 filesys_stub_put_bool (bool b)
37 {
38   backdoor_put_bool (b, out_byte, NULL);
39 }
40
41 void 
42 filesys_stub_put_bytes (const void *buffer, size_t cnt)
43 {
44   backdoor_put_bytes (buffer, cnt, out_byte, NULL);
45 }
46
47 void 
48 filesys_stub_put_file (struct file *file)
49 {
50   ASSERT (file != NULL);
51   filesys_stub_put_int32 ((int32_t) file - 1);
52 }
53
54 void 
55 filesys_stub_put_int32 (int32_t value)
56 {
57   backdoor_put_int32 (value, out_byte, NULL);
58 }
59
60 void 
61 filesys_stub_put_string (const char *string)
62 {
63   backdoor_put_string (string, out_byte, NULL);
64 }
65
66 void 
67 filesys_stub_put_uint32 (uint32_t value)
68 {
69   backdoor_put_uint32 (value, out_byte, NULL);
70 }
71
72 static uint8_t
73 in_byte (void *aux UNUSED) 
74 {
75   return inb (0x8901);
76 }
77
78 bool 
79 filesys_stub_get_bool (void)
80 {
81   return backdoor_get_bool (in_byte, NULL);
82 }
83
84 void 
85 filesys_stub_get_bytes (void *buffer, size_t size)
86 {
87   backdoor_get_bytes (buffer, size, in_byte, NULL);
88 }
89
90 struct file *
91 filesys_stub_get_file (void)
92 {
93   int32_t fd = filesys_stub_get_int32 ();
94   return fd < 0 ? NULL : (struct file *) (fd + 1);
95 }
96
97 int32_t 
98 filesys_stub_get_int32 (void)
99 {
100   return backdoor_get_int32 (in_byte, NULL);
101 }
102
103 void 
104 filesys_stub_match_string (const char *string)
105 {
106   if (backdoor_get_uint32 (in_byte, NULL) != strlen (string))
107     panic ("string match failed");
108   while (*string != '\0') 
109     {
110       uint8_t c = *string++;
111       if (c != in_byte (NULL))
112         panic ("string match failed"); 
113     }
114 }
115
116 uint32_t 
117 filesys_stub_get_uint32 (void)
118 {
119   return backdoor_get_uint32 (in_byte, NULL);
120 }
121