Added a shell, a few programs, and added support for SIGINT.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-27 23:03:39 +02:00
parent 2f9d08a800
commit 34e9ca277d
15 changed files with 189 additions and 2 deletions

View File

@ -5,7 +5,7 @@ endif
REMOTE=192.168.2.6 REMOTE=192.168.2.6
REMOTEUSER=sortie REMOTEUSER=sortie
REMOTECOPYDIR:=/home/$(REMOTEUSER)/Desktop/MaxsiOS REMOTECOPYDIR:=/home/$(REMOTEUSER)/Desktop/MaxsiOS
MODULES=libmaxsi hello pong mkinitrd sortix MODULES=libmaxsi hello pong mkinitrd utils sortix
VERSION=0.4 VERSION=0.4
DEBNAME:=sortix_$(VERSION)_$(CPU) DEBNAME:=sortix_$(VERSION)_$(CPU)
@ -103,7 +103,7 @@ iso: all debsource
mkdir -p $(INITRDDIR) mkdir -p $(INITRDDIR)
cp hello/hello $(INITRDDIR) cp hello/hello $(INITRDDIR)
cp pong/pong $(INITRDDIR) cp pong/pong $(INITRDDIR)
cp $(INITRDDIR)/hello $(INITRDDIR)/init for F in init cat sh mxsh clear; do cp utils/$$F $(INITRDDIR); done
(cd $(INITRDDIR) && ../mkinitrd/mkinitrd * -o ../$(ISODIR)/boot/sortix.initrd) (cd $(INITRDDIR) && ../mkinitrd/mkinitrd * -o ../$(ISODIR)/boot/sortix.initrd)
rm -rf $(INITRDDIR) rm -rf $(INITRDDIR)
cp builds/$(DEBSRCNAME)-src.tar.gz $(ISODIR) cp builds/$(DEBSRCNAME)-src.tar.gz $(ISODIR)

View File

@ -62,6 +62,7 @@ namespace Maxsi
const uint32_t NONE = 0x40000000 + 30; const uint32_t NONE = 0x40000000 + 30;
const uint32_t ALTGR = 0x40000000 + 31; const uint32_t ALTGR = 0x40000000 + 31;
const uint32_t NUMLCK = 0x40000000 + 32; const uint32_t NUMLCK = 0x40000000 + 32;
const uint32_t SIGINT = 0x40000000 + 33;
const uint32_t DEPRESSED = (1<<31); const uint32_t DEPRESSED = (1<<31);
} }
} }

View File

@ -36,8 +36,18 @@ _start:
push $0 # argc push $0 # argc
call main call main
# HACK: Just restart the shell!
mov $10, %eax
mov $SH, %ebx
int $0x80
# Now return mains result when exiting the process # Now return mains result when exiting the process
mov %eax, %ebx mov %eax, %ebx
mov $1, %eax mov $1, %eax
mov $0x0, %ebx # TODO: This syscall exits a thread, not a process! mov $0x0, %ebx # TODO: This syscall exits a thread, not a process!
int $0x80 int $0x80
.section .data
SH:
.asciz "sh"

View File

@ -34,6 +34,8 @@ const char* exceptions[] = { "Divide by zero", "Debug", "Non maskable interrupt"
if ( Regs->int_no < 32 ) if ( Regs->int_no < 32 )
{ {
const char* message = ( Regs->int_no < numknownexceptions ) ? exceptions[Regs->int_no] : "Unknown"; const char* message = ( Regs->int_no < numknownexceptions ) ? exceptions[Regs->int_no] : "Unknown";
//Sortix::Log::PrintF("eax=0x%x\tebx=0x%x\tecx=0x%x\tedx=0x%x\tesi=0x%x\tedi=0x%x\tesp=0x%x\tuseresp=0x%x\tebp=0x%x\teip=0x%x\n", Regs->eax, Regs->ebx, Regs->ecx, Regs->edx, Regs->esi, Regs->edi, Regs->esp, Regs->useresp, Regs->ebp, Regs->eip);
Sortix::PanicF("Unhandled CPU Exception id %zu '%s' at eip=0x%zx (cr2=0x%p, err_code=0x%p)", Regs->int_no, message, Regs->eip, Regs->cr2, Regs->err_code); Sortix::PanicF("Unhandled CPU Exception id %zu '%s' at eip=0x%zx (cr2=0x%p, err_code=0x%p)", Regs->int_no, message, Regs->eip, Regs->cr2, Regs->err_code);
} }

View File

@ -30,6 +30,8 @@
#include "panic.h" #include "panic.h"
#include "keyboard.h" #include "keyboard.h"
#include "isr.h" #include "isr.h"
#include "process.h"
#include "scheduler.h"
#include "pong.h" #include "pong.h"
@ -578,6 +580,7 @@ namespace Sortix
nat Mask = 0; nat Mask = 0;
nat LockMask = 0; nat LockMask = 0;
bool control;
const nat Shift = (1<<0); const nat Shift = (1<<0);
const nat AltGr = (1<<1); const nat AltGr = (1<<1);
@ -600,6 +603,7 @@ namespace Sortix
if ( CodePoint == LSHFT ) { Mask &= ~Shift; } if ( CodePoint == LSHFT ) { Mask &= ~Shift; }
if ( CodePoint == ALTGR ) { Mask &= ~AltGr; } if ( CodePoint == ALTGR ) { Mask &= ~AltGr; }
if ( CodePoint == SCRLCK ) { Mask &= ~ScrLck; } if ( CodePoint == SCRLCK ) { Mask &= ~ScrLck; }
if ( CodePoint == CTRL ) { control = false; }
} }
else else
{ {
@ -607,6 +611,12 @@ namespace Sortix
if ( CodePoint == ALTGR ) { Mask |= AltGr; } if ( CodePoint == ALTGR ) { Mask |= AltGr; }
if ( CodePoint == SCRLCK ) { Mask |= ScrLck; } if ( CodePoint == SCRLCK ) { Mask |= ScrLck; }
if ( CodePoint == CAPS ) { LockMask ^= Shift; SetLEDs(LEDCapsLck); } if ( CodePoint == CAPS ) { LockMask ^= Shift; SetLEDs(LEDCapsLck); }
if ( CodePoint == CTRL ) { control = true; }
}
if ( control && ( CodePoint == 'c' || CodePoint == 'C' ) )
{
CodePoint = SIGINT;
} }
return CodePoint; return CodePoint;
@ -666,6 +676,12 @@ namespace Sortix
uint32_t CodePoint = Layouts::GetCodePoint(Scancode); uint32_t CodePoint = Layouts::GetCodePoint(Scancode);
if ( CodePoint == SIGINT )
{
SigInt();
return;
}
bool KeyUp = (Scancode & 0x80); bool KeyUp = (Scancode & 0x80);
if ( KeyUp ) { CodePoint |= DEPRESSED; } if ( KeyUp ) { CodePoint |= DEPRESSED; }

View File

@ -52,6 +52,7 @@ namespace Sortix
_addrspace = addrspace; _addrspace = addrspace;
_endcodesection = 0x400000UL; _endcodesection = 0x400000UL;
segments = NULL; segments = NULL;
sigint = false;
} }
Process::~Process() Process::~Process()
@ -81,6 +82,7 @@ namespace Sortix
void SysExecute(CPU::InterruptRegisters* R) void SysExecute(CPU::InterruptRegisters* R)
{ {
const char* programname = (const char*) R->ebx; const char* programname = (const char*) R->ebx;
size_t programsize = 0; size_t programsize = 0;
byte* program = InitRD::Open(programname, &programsize); byte* program = InitRD::Open(programname, &programsize);
if ( program == NULL ) { R->eax = -1; return; } if ( program == NULL ) { R->eax = -1; return; }
@ -93,5 +95,6 @@ namespace Sortix
// This is a hacky way to set up the thread! // This is a hacky way to set up the thread!
R->eip = entry; R->eip = entry;
R->useresp = 0x80000000UL; R->useresp = 0x80000000UL;
R->ebp = 0x80000000UL;
} }
} }

View File

@ -62,6 +62,9 @@ namespace Sortix
DescriptorTable descriptors; DescriptorTable descriptors;
ProcessSegment* segments; ProcessSegment* segments;
public:
bool sigint;
public: public:
addr_t _endcodesection; // HACK addr_t _endcodesection; // HACK

View File

@ -183,11 +183,16 @@ namespace Sortix
SetState(UNRUNNABLE); SetState(UNRUNNABLE);
} }
bool sigintpending = false;
void SigInt() { sigintpending = true; }
namespace Scheduler namespace Scheduler
{ {
// Initializes the scheduling subsystem. // Initializes the scheduling subsystem.
void Init() void Init()
{ {
sigintpending = false;
currentThread = NULL; currentThread = NULL;
firstRunnableThread = NULL; firstRunnableThread = NULL;
firstUnrunnableThread = NULL; firstUnrunnableThread = NULL;
@ -332,6 +337,15 @@ namespace Sortix
{ {
//Log::PrintF("Scheduling while at eip=0x%p...", R->eip); //Log::PrintF("Scheduling while at eip=0x%p...", R->eip);
if ( currentThread != NoopThread && currentThread->GetProcess() && sigintpending )
{
const char* programname = "sh";
R->ebx = (uint32_t) programname;
SysExecute(R);
sigintpending = false;
Log::Print("^C\n");
}
WakeSleeping(TimePassed); WakeSleeping(TimePassed);
// Find the next thread to be run. // Find the next thread to be run.

View File

@ -115,6 +115,9 @@ namespace Sortix
// Scheduling // Scheduling
Thread* CurrentThread(); Thread* CurrentThread();
// HACK
void SigInt();
} }
#endif #endif

23
utils/Makefile Normal file
View File

@ -0,0 +1,23 @@
# Set up variables such that we can easily cross-compile.
OSROOT=..
include ../crosscompilemakefile.mak
BINARIES:=\
init \
cat \
sh \
mxsh \
clear \
all: $(BINARIES)
%: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c $< -o $@.o
$(LD) $(LDFLAGS) $@.o -o $@ $(LIBS)
sh: mxsh
cp mxsh sh
clean:
rm -f $(BINARIES) *.o

30
utils/cat.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <libmaxsi/sortix-keyboard.h>
int main(int argc, char* argv[])
{
bool lastwasesc = false;
while (true)
{
unsigned method = System::Keyboard::POLL;
uint32_t codepoint = System::Keyboard::ReceieveKeystroke(method);
if ( codepoint == 0 ) { continue; }
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
if ( codepoint == Maxsi::Keyboard::UP ) { printf("\e[A"); continue; }
if ( codepoint == Maxsi::Keyboard::DOWN ) { printf("\e[B"); continue; }
if ( codepoint == Maxsi::Keyboard::RIGHT ) { printf("\e[C"); continue; }
if ( codepoint == Maxsi::Keyboard::LEFT ) { printf("\e[D"); continue; }
if ( codepoint == Maxsi::Keyboard::ESC ) { printf("\e["); lastwasesc = true; continue; }
if ( lastwasesc && codepoint == '[' ) { continue; }
if ( codepoint >= 0x80 ) { continue; }
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
printf(msg);
lastwasesc = false;
}
return 0;
}

7
utils/clear.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("\e[H\e[2J");
return 0;
}

15
utils/init.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <libmaxsi/process.h>
int main(int argc, char* argv[])
{
// Reset the terminal's color and the rest of it.
printf("\e[m\e[J");
const char* programname = "sh";
const char* newargv[] = { programname };
Maxsi::Process::Execute(programname, 1, newargv);
return 1;
}

53
utils/mxsh.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <libmaxsi/process.h>
#include <libmaxsi/sortix-keyboard.h>
using namespace Maxsi;
void command()
{
printf("root@sortix / # ");
const size_t commandsize = 128;
char command[commandsize + 1];
size_t commandused = 0;
while (true)
{
unsigned method = System::Keyboard::POLL;
uint32_t codepoint = System::Keyboard::ReceieveKeystroke(method);
if ( codepoint == 0 ) { continue; }
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
if ( codepoint >= 0x80 ) { continue; }
if ( codepoint == '\b' )
{
if ( 0 < commandused ) { printf("\b"); commandused--; }
continue;
}
if ( commandsize <= commandused && codepoint != '\n' ) { continue; }
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
printf(msg);
if ( codepoint == '\n' ) { command[commandused] = '\0'; break; }
command[commandused++] = codepoint;
}
if ( command[0] == '\0' ) { return; }
// Replace the current process with another process image.
Process::Execute(command, 0, NULL);
// This is clever. This only happens if the program didn't change.
printf("%s: command not found\n", command);
}
int main(int argc, char* argv[])
{
while ( true ) { command(); }
}

7
utils/uname.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("Sortix\n");
return 0;
}