shell can launch another user processgit add .git add .!

This commit is contained in:
2026-07-12 20:13:13 -05:00
parent e2ab130324
commit 5c7febbbf0
15 changed files with 403 additions and 220 deletions

Binary file not shown.

View File

@@ -1,3 +1,4 @@
#include "syscall.h"
#include <unistd.h>
#include <stdio.h>
#include <string.h>
@@ -7,6 +8,10 @@ const char* shell_prompt = "rocksh> ";
char buf[256];
size_t buf_offset = 0;
char path[256];
const char* bin_dir = "/bin/";
void parse_cmd() {
if (strcmp(buf, "exit") == 0) {
printf("bye!\n");
@@ -15,7 +20,25 @@ void parse_cmd() {
if (strcmp(buf, "motd") == 0) {
printf("rockos is the best!\n");
return;
}
// need a strcat
char* dst = path;
strcpy(dst, bin_dir);
dst = path + strlen(bin_dir);
strcpy(dst, buf);
int pid = fork();
if (pid == 0) {
if (!exec(path)) {
return;
}
}
int status;
waitpid(pid, &status);
printf("process exited with status %d\n", status);
}
void reset() {

View File

@@ -0,0 +1,36 @@
[
{
"arguments": [
"/home/slinky/opt/cross/bin/i686-elf-gcc",
"-ffreestanding",
"-O2",
"-Wall",
"-Wextra",
"-I../../rocklibc/include",
"-c",
"-o",
"crt0.o",
"crt0.S"
],
"directory": "/home/slinky/source/RockOS/programs/test",
"file": "/home/slinky/source/RockOS/programs/test/crt0.S",
"output": "/home/slinky/source/RockOS/programs/test/crt0.o"
},
{
"arguments": [
"/home/slinky/opt/cross/bin/i686-elf-gcc",
"-ffreestanding",
"-O2",
"-Wall",
"-Wextra",
"-I../../rocklibc/include",
"-c",
"-o",
"main.o",
"main.c"
],
"directory": "/home/slinky/source/RockOS/programs/test",
"file": "/home/slinky/source/RockOS/programs/test/main.c",
"output": "/home/slinky/source/RockOS/programs/test/main.o"
}
]

21
programs/test/crt0.S Normal file
View File

@@ -0,0 +1,21 @@
.global _start
.extern exit
.section .text
_start:
xor %ebp, %ebp
mov (%esp), %eax
lea 4(%esp), %ebx
lea 8(%esp,%eax,4), %ecx
and $-16, %esp
push %ecx
push %ebx
push %eax
call main
push %eax
call exit

31
programs/test/linker.ld Normal file
View File

@@ -0,0 +1,31 @@
ENTRY(_start)
SECTIONS
{
. = 0x40000000;
.text ALIGN(4K) :
{
/* Force the crt0.o entry code to be placed FIRST in memory */
KEEP(*crt0.o(.text))
*(.text .text.*)
}
.rodata ALIGN(4K) :
{
*(.rodata .rodata.*)
}
.data ALIGN(4K) :
{
*(.data .data.*)
}
.bss ALIGN(4K) :
{
_bss_start = .;
*(.bss .bss.*)
*(COMMON)
_bss_end = .;
}
}

6
programs/test/main.c Normal file
View File

@@ -0,0 +1,6 @@
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello, world!\n");
return 0;
}

23
programs/test/makefile Normal file
View File

@@ -0,0 +1,23 @@
CC = i686-elf-gcc
LD = i686-elf-ld
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include
LDFLAGS = -m elf_i386 -nostdlib
TARGET = test.elf
all: $(TARGET)
crt0.o: crt0.S
$(CC) $(CFLAGS) -c crt0.S -o crt0.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
$(TARGET): crt0.o main.o ../lib/rlibc.a
$(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET)
clean:
rm -f *.o $(TARGET)
.PHONY: all clean test