* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab5 / lib / libmain.c
blobabdd31b20ad4e037da357fe0397dfe4b7002913b
1 // Called from entry.S to get us going.
2 // entry.S already took care of defining envs, pages, vpd, and vpt.
4 #include <inc/lib.h>
6 asmlinkage void umain(int argc, char **argv);
8 const volatile struct Env *thisenv;
9 // Make "env" (which you used in the last lab) a synonym for "thisenv"
10 // (which you will use in future labs).
11 static const volatile struct Env *env __attribute__((alias("thisenv")));
12 const char *binaryname = "<unknown>";
14 asmlinkage void
15 libmain(int argc, char **argv)
17 extern uintptr_t sctors[], ectors[];
18 uintptr_t *ctorva;
20 // set env to point at our env structure in envs[].
21 thisenv = 0; /* Really? */
23 // save the name of the program so that panic() can use it
24 if (argc > 0)
25 binaryname = argv[0];
27 // Call any global constructors (e.g., defined by C++).
28 // This relies on linker script magic to define the 'sctors' and
29 // 'ectors' symbols; see user/user.ld.
30 for (ctorva = ectors; ctorva > sctors; )
31 ((void(*)()) *--ctorva)();
33 // call user main routine
34 umain(argc, argv);
36 // exit gracefully
37 exit();