Added uptime(1).
This commit is contained in:
parent
f232a054d3
commit
8c146f14c0
|
@ -60,6 +60,7 @@ init.o \
|
||||||
signal.o \
|
signal.o \
|
||||||
$(CPU)/signal.o \
|
$(CPU)/signal.o \
|
||||||
start.o \
|
start.o \
|
||||||
|
time.o \
|
||||||
random.o \
|
random.o \
|
||||||
|
|
||||||
MAXSIHEADERS=\
|
MAXSIHEADERS=\
|
||||||
|
|
|
@ -172,7 +172,9 @@ int unlink(const char*);
|
||||||
ssize_t write(int, const void*, size_t);
|
ssize_t write(int, const void*, size_t);
|
||||||
|
|
||||||
#ifdef SORTIX_EXTENSIONS
|
#ifdef SORTIX_EXTENSIONS
|
||||||
|
@include(intn_t.h)
|
||||||
int memstat(size_t* memused, size_t* memtotal);
|
int memstat(size_t* memused, size_t* memtotal);
|
||||||
|
int uptime(uintmax_t* mssinceboot);
|
||||||
int writeall(int fd, const void* buffer, size_t len);
|
int writeall(int fd, const void* buffer, size_t len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/******************************************************************************
|
||||||
|
|
||||||
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||||
|
|
||||||
|
This file is part of LibMaxsi.
|
||||||
|
|
||||||
|
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU Lesser General Public License as published by the Free
|
||||||
|
Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||||
|
more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
time.cpp
|
||||||
|
Useful time functions.
|
||||||
|
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "syscall.h"
|
||||||
|
|
||||||
|
namespace Maxsi
|
||||||
|
{
|
||||||
|
namespace Time
|
||||||
|
{
|
||||||
|
DEFN_SYSCALL1(int, SysUptime, 34, uintmax_t*);
|
||||||
|
|
||||||
|
extern "C" int uptime(uintmax_t* mssinceboot)
|
||||||
|
{
|
||||||
|
return SysUptime(mssinceboot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,7 +59,8 @@
|
||||||
#define SYSCALL_KILL 31
|
#define SYSCALL_KILL 31
|
||||||
#define SYSCALL_MEMSTAT 32
|
#define SYSCALL_MEMSTAT 32
|
||||||
#define SYSCALL_ISATTY 33
|
#define SYSCALL_ISATTY 33
|
||||||
#define SYSCALL_MAX_NUM 34 /* index of highest constant + 1 */
|
#define SYSCALL_UPTIME 34
|
||||||
|
#define SYSCALL_MAX_NUM 35 /* index of highest constant + 1 */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
#include "syscall.h"
|
||||||
|
|
||||||
#ifdef PLATFORM_SERIAL
|
#ifdef PLATFORM_SERIAL
|
||||||
#include "serialterminal.h"
|
#include "serialterminal.h"
|
||||||
|
@ -84,6 +85,13 @@ namespace Sortix
|
||||||
|
|
||||||
bool didUglyIRQ0Hack;
|
bool didUglyIRQ0Hack;
|
||||||
|
|
||||||
|
int SysUptime(uintmax_t* mssinceboot)
|
||||||
|
{
|
||||||
|
// TODO: HACK!
|
||||||
|
*mssinceboot = ((size_t)microsecondssinceboot) / 1000;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
// Initialize our variables.
|
// Initialize our variables.
|
||||||
|
@ -94,6 +102,8 @@ namespace Sortix
|
||||||
Interrupt::RegisterHandler(Interrupt::IRQ0, &OnIRQ0);
|
Interrupt::RegisterHandler(Interrupt::IRQ0, &OnIRQ0);
|
||||||
Interrupt::RegisterHandler(177, &OnInt177);
|
Interrupt::RegisterHandler(177, &OnInt177);
|
||||||
|
|
||||||
|
Syscall::Register(SYSCALL_UPTIME, (void*) SysUptime);
|
||||||
|
|
||||||
didUglyIRQ0Hack = false;
|
didUglyIRQ0Hack = false;
|
||||||
|
|
||||||
RequestIQR0();
|
RequestIQR0();
|
||||||
|
@ -118,6 +128,6 @@ namespace Sortix
|
||||||
if ( !didUglyIRQ0Hack ) { RequestIQR0(); didUglyIRQ0Hack = true; }
|
if ( !didUglyIRQ0Hack ) { RequestIQR0(); didUglyIRQ0Hack = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement all the other useful functions regarding tiem.
|
// TODO: Implement all the other useful functions regarding time.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ mxsh \
|
||||||
clear \
|
clear \
|
||||||
ls \
|
ls \
|
||||||
help \
|
help \
|
||||||
|
uptime \
|
||||||
memstat \
|
memstat \
|
||||||
uname \
|
uname \
|
||||||
idle \
|
idle \
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
size_t Seconds(size_t ms)
|
||||||
|
{
|
||||||
|
return (ms / 1000UL) % (60UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Minutes(size_t ms)
|
||||||
|
{
|
||||||
|
return (ms / (1000UL * 60UL)) % (60UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Hours(size_t ms)
|
||||||
|
{
|
||||||
|
return (ms / (1000UL * 60UL * 60UL)) % (24UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Days(size_t ms)
|
||||||
|
{
|
||||||
|
return (ms / (1000UL * 60UL * 60UL * 24UL)) % (24UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintElement(size_t num, const char* single, const char* multiple)
|
||||||
|
{
|
||||||
|
static const char* prefix = "";
|
||||||
|
if ( !num ) { return; }
|
||||||
|
const char* str = (num>1) ? multiple : single;
|
||||||
|
printf("%s%zu %s", prefix, num, str);
|
||||||
|
prefix = ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
uintmax_t mssinceboot;
|
||||||
|
if ( uptime(&mssinceboot) ) { perror("uptime"); return 1; }
|
||||||
|
|
||||||
|
PrintElement(Days(mssinceboot), "day", "days");
|
||||||
|
PrintElement(Hours(mssinceboot), "hour", "hours");
|
||||||
|
PrintElement(Minutes(mssinceboot), "min", "mins");
|
||||||
|
PrintElement(Seconds(mssinceboot), "sec", "secs");
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue