sleep finished

This commit is contained in:
2025-02-21 14:51:15 +08:00
parent 6aa7311ce6
commit 18f6d55004
71 changed files with 1530 additions and 42 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -188,6 +188,7 @@ UPROGS=\
$U/_grind\ $U/_grind\
$U/_wc\ $U/_wc\
$U/_zombie\ $U/_zombie\
$U/_sleep\

1486
compile_commands.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
#define T_DIR 1 // Directory #define T_DIR 1 // Directory
#define T_FILE 2 // File #define T_FILE 2 // File
#define T_DEVICE 3 // Device #define T_DEVICE 3 // Device
#include "types.h"
struct stat { struct stat {
int dev; // File system's disk device int dev; // File system's disk device

View File

@ -1,26 +1,20 @@
#include "kernel/types.h"
#include "kernel/stat.h" #include "kernel/stat.h"
#include "kernel/types.h"
#include "user/user.h" #include "user/user.h"
#include <stdarg.h> #include <stdarg.h>
static char digits[] = "0123456789ABCDEF"; static char digits[] = "0123456789ABCDEF";
static void static void putc(int fd, char c) { write(fd, &c, 1); }
putc(int fd, char c)
{
write(fd, &c, 1);
}
static void static void printint(int fd, int xx, int base, int sgn) {
printint(int fd, int xx, int base, int sgn)
{
char buf[16]; char buf[16];
int i, neg; int i, neg;
uint x; uint x;
neg = 0; neg = 0;
if(sgn && xx < 0){ if (sgn && xx < 0) {
neg = 1; neg = 1;
x = -xx; x = -xx;
} else { } else {
@ -28,18 +22,17 @@ printint(int fd, int xx, int base, int sgn)
} }
i = 0; i = 0;
do{ do {
buf[i++] = digits[x % base]; buf[i++] = digits[x % base];
}while((x /= base) != 0); } while ((x /= base) != 0);
if(neg) if (neg)
buf[i++] = '-'; buf[i++] = '-';
while(--i >= 0) while (--i >= 0)
putc(fd, buf[i]); putc(fd, buf[i]);
} }
static void static void printptr(int fd, uint64 x) {
printptr(int fd, uint64 x) {
int i; int i;
putc(fd, '0'); putc(fd, '0');
putc(fd, 'x'); putc(fd, 'x');
@ -48,41 +41,39 @@ printptr(int fd, uint64 x) {
} }
// Print to the given fd. Only understands %d, %x, %p, %s. // Print to the given fd. Only understands %d, %x, %p, %s.
void void vprintf(int fd, const char *fmt, va_list ap) {
vprintf(int fd, const char *fmt, va_list ap)
{
char *s; char *s;
int c, i, state; int c, i, state;
state = 0; state = 0;
for(i = 0; fmt[i]; i++){ for (i = 0; fmt[i]; i++) {
c = fmt[i] & 0xff; c = fmt[i] & 0xff;
if(state == 0){ if (state == 0) {
if(c == '%'){ if (c == '%') {
state = '%'; state = '%';
} else { } else {
putc(fd, c); putc(fd, c);
} }
} else if(state == '%'){ } else if (state == '%') {
if(c == 'd'){ if (c == 'd') {
printint(fd, va_arg(ap, int), 10, 1); printint(fd, va_arg(ap, int), 10, 1);
} else if(c == 'l') { } else if (c == 'l') {
printint(fd, va_arg(ap, uint64), 10, 0); printint(fd, va_arg(ap, uint64), 10, 0);
} else if(c == 'x') { } else if (c == 'x') {
printint(fd, va_arg(ap, int), 16, 0); printint(fd, va_arg(ap, int), 16, 0);
} else if(c == 'p') { } else if (c == 'p') {
printptr(fd, va_arg(ap, uint64)); printptr(fd, va_arg(ap, uint64));
} else if(c == 's'){ } else if (c == 's') {
s = va_arg(ap, char*); s = va_arg(ap, char *);
if(s == 0) if (s == 0)
s = "(null)"; s = "(null)";
while(*s != 0){ while (*s != 0) {
putc(fd, *s); putc(fd, *s);
s++; s++;
} }
} else if(c == 'c'){ } else if (c == 'c') {
putc(fd, va_arg(ap, uint)); putc(fd, va_arg(ap, uint));
} else if(c == '%'){ } else if (c == '%') {
putc(fd, c); putc(fd, c);
} else { } else {
// Unknown % sequence. Print it to draw attention. // Unknown % sequence. Print it to draw attention.
@ -94,18 +85,14 @@ vprintf(int fd, const char *fmt, va_list ap)
} }
} }
void void fprintf(int fd, const char *fmt, ...) {
fprintf(int fd, const char *fmt, ...)
{
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vprintf(fd, fmt, ap); vprintf(fd, fmt, ap);
} }
void void printf(const char *fmt, ...) {
printf(const char *fmt, ...)
{
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);

View File

@ -0,0 +1,13 @@
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(2, "Usage: sleep <time>\n");
exit(1);
}
int time = atoi(argv[1]);
// printf("time: %d\n", time);
sleep(time);
exit(0);
}