Draft: lab 5 failed

This commit is contained in:
2025-05-03 20:45:34 +08:00
parent 981cae803b
commit e73f90395d
39 changed files with 588 additions and 429 deletions

View File

@@ -13,6 +13,8 @@ LD := $(GNU)-ld
LDFLAGS += -g -nostdlib -no-pie
OBJCOPY := $(GNU)-objcopy
INCLUDE := -I../include -Iinclude
LD_SCRIPT := linker.ld
SRCS := $(shell find . -name '*.[cS]')
OBJS := $(SRCS:%=%.o)
@@ -29,11 +31,11 @@ userprog.elf: $(LD_SCRIPT) $(OBJS)
%.S.o: %.S
mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(CCFLAGS)
$(CC) -c $< -o $@ $(INCLUDE) $(CCFLAGS)
%.c.o: %.c
mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(CCFLAGS)
$(CC) -c $< -o $@ $(INCLUDE) $(CCFLAGS)
clean:
-rm $(OBJS) userprog userprog.elf

View File

@@ -0,0 +1,14 @@
#pragma once
#include <stddef.h>
uint64_t syscall(int32_t num, ...);
int32_t getpid(void);
size_t uart_read(char buf[], size_t size);
size_t uart_write(const char buf[], size_t size);
int32_t exec(const char *name, char *const argv[]);
int32_t fork(void);
void exit(int32_t status);
int32_t mbox_call(uint8_t ch, uint32_t *mbox);
void kill(int32_t pid);

13
userprog/lib/syscall.S Normal file
View File

@@ -0,0 +1,13 @@
.global syscall
syscall:
mov x8, x0
mov x0, x1
mov x1, x2
mov x2, x3
mov x3, x4
mov x4, x5
mov x5, x6
mov x6, x7
svc 0
ret

25
userprog/lib/syscall.c Normal file
View File

@@ -0,0 +1,25 @@
#include <syscall.h>
int32_t getpid()
{ return (int32_t)syscall(0); }
size_t uart_read(char buf[], size_t size)
{ return (size_t)syscall(1, buf, size); }
size_t uart_write(const char buf[], size_t size)
{ return (size_t)syscall(2, buf, size); }
int32_t exec(const char *name, char *const argv[])
{ return (int32_t)syscall(3, name, argv); }
int32_t fork(void)
{ return (int32_t)syscall(4); }
void exit(int32_t status)
{ syscall(5); __builtin_unreachable(); }
int32_t mbox_call(uint8_t ch, uint32_t *mbox)
{ return (int32_t)syscall(6, ch, mbox); }
void kill(int32_t pid)
{ syscall(7, pid); }