almost got the term emu working and shell
This commit is contained in:
1
programs/compile_commands.json
Normal file
1
programs/compile_commands.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
Binary file not shown.
@@ -1,46 +1,13 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char* shell_prompt = "rocksh> ";
|
||||
|
||||
static void process_cmd(const char* cmd) {
|
||||
size_t cmd_len = strlen(cmd);
|
||||
if (cmd_len < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "exit") == 0) {
|
||||
printf("bye!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("command not recognized: %s\n", cmd);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char cmd[128];
|
||||
size_t p = 0;
|
||||
|
||||
printf("%s", shell_prompt);
|
||||
printf(shell_prompt);
|
||||
|
||||
while (1) {
|
||||
char c = getchar();
|
||||
printf("%c", c);
|
||||
if (c != '\n') {
|
||||
cmd[p++] = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd[p] = 0;
|
||||
process_cmd(cmd);
|
||||
memset(cmd, 0, 128);
|
||||
p = 0;
|
||||
printf("%s", shell_prompt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 3;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
@@ -1,21 +0,0 @@
|
||||
.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
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
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 = .;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "syscall.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
if (fork() == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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
|
||||
@@ -1,5 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void term();
|
||||
|
||||
int ptys;
|
||||
int ptym;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
ptym = pty(&ptys);
|
||||
|
||||
if (fork() == 0) {
|
||||
close(ptym);
|
||||
dup2(ptys, 0);
|
||||
dup2(0, 1);
|
||||
dup2(0, 2);
|
||||
|
||||
exec("/rocksh.elf");
|
||||
}
|
||||
|
||||
close(ptys);
|
||||
dup2(ptym, 0);
|
||||
dup2(0, 1);
|
||||
dup2(0, 2);
|
||||
|
||||
term();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void term() {
|
||||
int vga_fd = open("/dev/tvga");
|
||||
if (vga_fd == -1) return;
|
||||
|
||||
while (1) {
|
||||
char c;
|
||||
int rd = read(0, &c, 1);
|
||||
if (rd > 0) {
|
||||
write(vga_fd, &c, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user