parent
2859704c47
commit
9c8cbfaa3b
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Below is the given application for lab1_2.
|
||||
* This app attempts to issue M-mode instruction in U-mode, and consequently raises an exception.
|
||||
*/
|
||||
|
||||
#include "user_lib.h"
|
||||
#include "util/types.h"
|
||||
|
||||
int main(void) {
|
||||
printu("Going to hack the system by running privilege instructions.\n");
|
||||
// we are now in U(user)-mode, but the "csrw" instruction requires M-mode privilege.
|
||||
// Attempting to execute such instruction will raise illegal instruction exception.
|
||||
asm volatile("csrw sscratch, 0");
|
||||
exit(0);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Below is the given application for lab1_3.
|
||||
* This app performs a long loop, during which, timers are
|
||||
* generated and pop messages to our screen.
|
||||
*/
|
||||
|
||||
#include "user_lib.h"
|
||||
#include "util/types.h"
|
||||
|
||||
int main(void) {
|
||||
printu("Hello world!\n");
|
||||
int i;
|
||||
for (i = 0; i < 100000000; ++i) {
|
||||
if (i % 5000000 == 0) printu("wait %d\n", i);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue