Skip to content

Instantly share code, notes, and snippets.

@utam0k
Created November 11, 2018 05:22
Show Gist options
  • Select an option

  • Save utam0k/1c04a96d7d1f16885f85562a5747bcf7 to your computer and use it in GitHub Desktop.

Select an option

Save utam0k/1c04a96d7d1f16885f85562a5747bcf7 to your computer and use it in GitHub Desktop.
diff --git a/mkdir.c b/mkdir.c
index 6e4c954..f1a0a41 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -1,11 +1,13 @@
#include "types.h"
#include "stat.h"
+#include "date.h"
#include "user.h"
int
main(int argc, char *argv[])
{
int i;
+ struct rtcdate rtc;
if(argc < 2){
printf(2, "Usage: mkdir files...\n");
@@ -19,5 +21,8 @@ main(int argc, char *argv[])
}
}
+ utc(&rtc);
+ printf(2, "time: %d\n", rtc.day);
+
exit();
}
diff --git a/syscall.c b/syscall.c
index ee85261..30e59cc 100644
--- a/syscall.c
+++ b/syscall.c
@@ -103,6 +103,7 @@ extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
extern int sys_uptime(void);
+extern int sys_utc(void);
static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
@@ -126,6 +127,7 @@ static int (*syscalls[])(void) = {
[SYS_link] sys_link,
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
+[SYS_utc] sys_utc,
};
void
diff --git a/syscall.h b/syscall.h
index bc5f356..9beb96f 100644
--- a/syscall.h
+++ b/syscall.h
@@ -20,3 +20,4 @@
#define SYS_link 19
#define SYS_mkdir 20
#define SYS_close 21
+#define SYS_utc 22
diff --git a/sysfile.c b/sysfile.c
index 87e508b..be6942d 100644
--- a/sysfile.c
+++ b/sysfile.c
@@ -16,6 +16,8 @@
#include "file.h"
#include "fcntl.h"
+#include "date.h"
+
// Fetch the nth word-sized system call argument as a file descriptor
// and return both the descriptor and the corresponding struct file.
static int
@@ -443,3 +445,12 @@ sys_pipe(void)
fd[1] = fd1;
return 0;
}
+
+int sys_utc(void)
+{
+ struct rtcdate *rtc;
+ if(argptr(0, (void*)&rtc, sizeof(*rtc)) < 0)
+ return -1;
+ cmostime(rtc);
+ return 1;
+}
diff --git a/user.h b/user.h
index 4f99c52..42b7bd5 100644
--- a/user.h
+++ b/user.h
@@ -23,6 +23,7 @@ int getpid(void);
char* sbrk(int);
int sleep(int);
int uptime(void);
+int utc(struct rtcdate*);
// ulib.c
int stat(const char*, struct stat*);
diff --git a/usys.S b/usys.S
index 8bfd8a1..d3dff42 100644
--- a/usys.S
+++ b/usys.S
@@ -29,3 +29,4 @@ SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
SYSCALL(uptime)
+SYSCALL(utc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment