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/_wc\
$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_FILE 2 // File
#define T_DEVICE 3 // Device
#define T_DIR 1 // Directory
#define T_FILE 2 // File
#define T_DEVICE 3 // Device
#include "types.h"
struct stat {
int dev; // File system's disk device

View File

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