cp: allow prefixing all console messages with the guest name
[hvf.git] / cp / nucleus / direct_grammar.y
blob888cfc261394af61f6949fa6ac4a69e35e79891c
1 %{
3 #include <util.h>
4 #include <slab.h>
5 #include <directory.h>
7 static void merge_props(struct directory_prop *out, struct directory_prop *a,
8 struct directory_prop *b)
10 out->got_storage = a->got_storage || b->got_storage;
12 if (a->got_storage && !b->got_storage)
13 out->storage = a->storage;
14 else if (!a->got_storage && b->got_storage)
15 out->storage = b->storage;
16 else if (a->got_storage && b->got_storage)
17 BUG();
20 static struct directory_vdev *__alloc_spool_vdev(enum directory_vdevtype type,
21 u64 devnum, u64 typenum)
23 struct directory_vdev *vdev;
25 assert(devnum <= 0xffff);
26 assert(typenum <= 0xffff);
27 assert((type == VDEV_CONS) || (type == VDEV_SPOOL));
29 vdev = malloc(sizeof(struct directory_vdev), ZONE_NORMAL);
30 assert(vdev);
32 vdev->type = type;
33 vdev->vdev = devnum;
35 if (type == VDEV_SPOOL) {
36 vdev->u.spool.type = typenum;
37 vdev->u.spool.model = 0;
40 return vdev;
43 static struct directory_vdev *__alloc_mdisk_vdev(u64 devnum, u64 typenum,
44 u64 start, u64 len, u64 rdev)
46 struct directory_vdev *vdev;
48 assert(devnum <= 0xffff);
49 assert(typenum <= 0xffff);
50 assert(start <= 0xffff);
51 assert(len <= 0xffff);
52 assert(rdev <= 0xffff);
54 vdev = malloc(sizeof(struct directory_vdev), ZONE_NORMAL);
55 assert(vdev);
57 vdev->type = VDEV_MDISK;
58 vdev->vdev = devnum;
59 vdev->u.mdisk.cyloff = start;
60 vdev->u.mdisk.cylcnt = len;
61 vdev->u.mdisk.rdev = rdev;
63 return vdev;
66 static int __auth_str(char *in)
68 int a = 0;
70 for(; *in; in++) {
71 if (*in == 'A')
72 a |= AUTH_A;
73 else if (*in == 'B')
74 a |= AUTH_B;
75 else if (*in == 'C')
76 a |= AUTH_C;
77 else if (*in == 'D')
78 a |= AUTH_D;
79 else if (*in == 'E')
80 a |= AUTH_E;
81 else if (*in == 'F')
82 a |= AUTH_F;
83 else if (*in == 'G')
84 a |= AUTH_G;
85 else
86 return -1;
89 return a;
92 static int __auth_int(u64 in)
94 FIXME("");
95 return AUTH_G;
100 %union {
101 struct directory_vdev *vdev;
102 struct list_head list;
103 struct directory_prop prop;
104 char *ptr;
105 u64 num;
108 %token <ptr> WORD
109 %token <num> STORSPEC NUM
110 %token USER MACHINE STORAGE CONSOLE SPOOL READER PUNCH PRINT MDISK
111 %token NLINE COMMENT
113 %type <prop> props prop
114 %type <list> vdevs
115 %type <vdev> vdev
119 users : users NLINE user
120 | user
121 | NLINE /* an empty line */
124 user : USER WORD WORD NLINE props vdevs { directory_alloc_user($2, __auth_str($3), &$5, &$6); }
125 | USER WORD NUM NLINE props vdevs { directory_alloc_user($2, __auth_int($3), &$5, &$6); }
128 props : props prop { merge_props(&$$, &$1, &$2); }
129 | prop { memcpy(&$$, &$1, sizeof($$)); }
132 vdevs : vdevs vdev { INIT_LIST_HEAD(&$$);
133 list_splice(&$1, &$$);
134 list_add(&$2->list, &$$);
136 | vdev { INIT_LIST_HEAD(&$$);
137 list_add(&$1->list, &$$);
141 prop : MACHINE WORD NUM NLINE { memset(&$$, 0, sizeof($$));
142 free($2);
144 | STORAGE STORSPEC NLINE { $$.got_storage = 1;
145 $$.storage = $2; }
146 | STORAGE NUM NLINE { $$.got_storage = 1;
147 assert(!bcd2dec($2, &$$.storage));
151 vdev : CONSOLE NUM NUM NLINE { $$ = __alloc_spool_vdev(VDEV_CONS, $2, $3); }
152 | SPOOL NUM NUM READER NLINE { $$ = __alloc_spool_vdev(VDEV_SPOOL, $2, $3); }
153 | SPOOL NUM NUM PUNCH NLINE { $$ = __alloc_spool_vdev(VDEV_SPOOL, $2, $3); }
154 | SPOOL NUM NUM PRINT NLINE { $$ = __alloc_spool_vdev(VDEV_SPOOL, $2, $3); }
155 | MDISK NUM NUM NUM NUM NUM NLINE { $$ = __alloc_mdisk_vdev($2, $3, $4, $5, $6); }