Skip to content

Commit

Permalink
Work on /dev/rtc. Still very broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Miller committed Nov 17, 2023
1 parent 00a6e07 commit 67b78ad
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ - (intptr_t)boot {
if (err != 0)
return err;
generic_mknodat(AT_PWD, "/dev/location", S_IFCHR|0666, dev_make(DYN_DEV_MAJOR, DEV_LOCATION_MINOR));
//generic_mknodat(AT_PWD, "/dev/rtc0", S_IFCHR|0666, dev_make(DEV_RTC_MAJOR, DEV_RTC_MINOR));
generic_linkat(AT_PWD, "/dev/rtc0", AT_PWD, "/dev/rtc");
//generic_linkat(<#struct fd *src_at#>, <#const char *src_raw#>, <#struct fd *dst_at#>, <#const char *dst_raw#>)
// The following does nothing for now. Placeholder
generic_mknodat(AT_PWD, "/dev/rtc0", S_IFCHR|0666, dev_make(DEV_RTC_MAJOR, DEV_RTC_MINOR));
generic_symlinkat("/dev/rtc0", AT_PWD, "/dev/rtc");

do_mount(&procfs, "proc", "/proc", "", 0);
do_mount(&devptsfs, "devpts", "/dev/pts", "", 0);
Expand Down
2 changes: 1 addition & 1 deletion app/PasteboardDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int clipboard_close(clip_fd *fd) {
return 0;
}

static int clipboard_open(int major, int minor, clip_fd *fd) {
static intptr_t clipboard_open(int major, int minor, clip_fd *fd) {
// Zero fd_priv data
memset(&fd_priv(fd), 0, sizeof(fd_priv(fd)));

Expand Down
2 changes: 1 addition & 1 deletion fs/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct dev_ops *char_devs[256] = {
[TTY_ALTERNATE_MAJOR] = &tty_dev,
[TTY_PSEUDO_MASTER_MAJOR] = &tty_dev,
[TTY_PSEUDO_SLAVE_MAJOR] = &tty_dev,
[DEV_RTC_MAJOR] = &rtc_dev,

[DYN_DEV_MAJOR] = &dyn_dev_char,
};

Expand Down
13 changes: 6 additions & 7 deletions fs/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ static inline dev_t_ dev_fake_from_real(dev_t dev) {
#define DEV_BLOCK 0
#define DEV_CHAR 1

//struct dev_rtc {
// int (*open)(int major, int minor, struct fd *fd);
// int (*close)(int major, int minor, struct fd *fd);
// struct tm (*read)(struct tm *);
//};
struct dev_rtc {
intptr_t (*open)(int major, int minor, struct fd *fd);
int (*close)(int major, int minor, struct fd *fd);
ssize_t (*read)(void *buf, size_t count);
};

struct dev_ops {
int (*open)(int major, int minor, struct fd *fd);
intptr_t (*open)(int major, int minor, struct fd *fd);
struct fd_ops fd;
struct rtc_time (*read)(struct tm *);
};

extern struct dev_ops *block_devs[];
Expand Down
28 changes: 17 additions & 11 deletions fs/dyndev.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ int dyn_dev_register(struct dev_ops *ops, int type, int major, int minor) {
return 0;
}

static int dyn_open(int type, int major, int minor, struct fd *fd) {
static intptr_t dyn_open(int type, int major, int minor, struct fd *fd) {
assert((type == DEV_CHAR) || (type == DEV_BLOCK));
assert(major == DYN_DEV_MAJOR || major == DEV_RTC_MAJOR); // mkemkemke
// it's safe to access devs without locking (read-only)

if(major == DEV_RTC_MAJOR) {
struct dev_ops *ops = dyn_info_char.devs[minor];
return ops->open(major, minor, fd);
return rtc_dev.open(major, minor, fd); // This should be dead code. Leaving for now to test. -mke
} else {
struct dev_ops *ops = dyn_info_char.devs[minor];
if (ops == NULL) {
Expand All @@ -72,12 +71,13 @@ static int dyn_open(int type, int major, int minor, struct fd *fd) {
}
}

static int dyn_open_char(int major, int minor, struct fd *fd) {
static intptr_t dyn_open_char(int major, int minor, struct fd *fd) {
return dyn_open(DEV_CHAR, major, minor, fd);
}

static int rtc_open(int major, int minor, struct fd *fd) {
return dyn_open(DEV_BLOCK, major, minor, fd);
static intptr_t rtc_open(int major, int minor, struct fd *fd) {
//return &(intptr_t)(major, minor, fd);
return (intptr_t)fd;
}

struct rtc_time {
Expand All @@ -89,7 +89,12 @@ struct rtc_time {
int tm_year; /* year */
};

struct rtc_time rtc_read(struct tm *timeinfo) {
ssize_t rtc_read(void *buf, size_t count) {
if (count < sizeof(struct rtc_time)) {
errno = EFAULT;
return -1;
}

time_t now;
struct tm *tm_now;
struct rtc_time emulatedRTC;
Expand All @@ -101,17 +106,18 @@ struct rtc_time rtc_read(struct tm *timeinfo) {
emulatedRTC.tm_min = tm_now->tm_min;
emulatedRTC.tm_hour = tm_now->tm_hour;
emulatedRTC.tm_mday = tm_now->tm_mday;
emulatedRTC.tm_mon = tm_now->tm_mon; // Note: Month in struct tm is 0 to 11
emulatedRTC.tm_year = tm_now->tm_year + 1900; // tm_year is years since 1900
emulatedRTC.tm_mon = tm_now->tm_mon;
emulatedRTC.tm_year = tm_now->tm_year + 1900;

return emulatedRTC;
memcpy(buf, &emulatedRTC, sizeof(emulatedRTC));
return sizeof(emulatedRTC);
}

struct dev_ops dyn_dev_char = {
.open = dyn_open_char,
};

struct dev_ops rtc_dev = {
struct dev_rtc rtc_dev = {
.open = rtc_open,
.read = rtc_read,
};
2 changes: 1 addition & 1 deletion fs/dyndev.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extern struct dev_ops dyn_dev_char;

// Implement fake rtc -mke
extern struct dev_ops rtc_dev;
extern struct dev_rtc rtc_dev;

// Registeres new block/character device with provided major and
// minor numbers, handled by provided ops
Expand Down

0 comments on commit 67b78ad

Please sign in to comment.