Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
93b1c80
First steps, paging for kernel process, kernel process can be load now
Dec 12, 2015
db20050
Kernel.c added
Dec 12, 2015
0012830
tried to communicate to kernel process
oezpeda Dec 12, 2015
f896516
Used idea from Alex, and finished implementing a malloc with argument…
Dec 12, 2015
fb273cb
added print and itoa for easier debugging
oezpeda Dec 12, 2015
79e6e96
Merge branch 'selfie-master-asg6to7' of github.com:useg1/SE-Winter-20…
oezpeda Dec 12, 2015
fae60d4
fixed little syntax typo
oezpeda Dec 12, 2015
948e870
Previous implementation of Malloc did not work, added amalloc which t…
oezpeda Dec 12, 2015
3482f1a
We can give the kernel params now, next implement the hypercalls and …
Dec 12, 2015
2bbccd5
Renamed kernel.c print doesent work well in userspace, we implement t…
Dec 12, 2015
3206469
We can boot in kernel now, amalloc implemented, hypercalls implementet
Dec 17, 2015
74f1e79
Implemented Create_Context
oezpeda Dec 17, 2015
d0413fd
Our Microkernel can now execute the kernel binary, load a binary call…
Dec 17, 2015
0b1d6d7
Small fix in delete context
Dec 17, 2015
e0e6921
Started to implement MapPageInContext as well as SwitchContext, could…
oezpeda Dec 17, 2015
6556600
Fixed small bug in mapPageInContext
Dec 18, 2015
7badc6b
Switch context now working. Switching after 3 instructions, see
Jan 5, 2016
1e99b6b
Makfile debug flag
Jan 5, 2016
bb8ff78
Merge branch 'selfie-master-asg6to7' of github.com:useg1/SE-Winter-20…
Jan 5, 2016
6eaf362
Workaround for Print and itoa over syscalls, itoa not testet
Jan 9, 2016
bebbb91
Added page recycling, implemented direktly in mappageincontext and de…
Jan 9, 2016
2f09ef3
Thread Fork implemented, p1 testfile now fork test
Jan 22, 2016
d03e708
Implemented CAS syscall
oezpeda Jan 24, 2016
dfa7273
tests and makefile for cas
Jan 24, 2016
cd6dc64
Fixed a bug in delete context
Jan 25, 2016
e13c9ce
Makefile improvements, changed instruction count in selfie.c to test …
Jan 25, 2016
b3aa1e7
Implemented push and pop methods in the cas implementation, we use a …
Jan 25, 2016
aa622d6
Few bugfixes, new treiberstack implementation
Jan 26, 2016
4a12064
rm p1.c
Jan 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ Martin Aigner <martin@maigner.net>
Christian Barthel <cbarthel@cs.uni-salzburg.at>
Christoph Kirsch <ck@cs.uni-salzburg.at>
Michael Lippautz <michael.lippautz@gmail.com>
Simone Oblasser <simone.oblasser@cs.uni-salzburg.at>
Simone Oblasser <simone.oblasser@cs.uni-salzburg.at>

Team Useg
Christian Kawalar <kawalarch@stud.sbg.ac.at>
Alexander Mayer
Daniel Schlager
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##-----------------##
##Christian Kawalar##
##12.2015 ##
##-----------------##

all: clean clang kernel p1 run

cas: clean clang kernel cas_ p1 run

ncas: clean clang kernel ncas_ p1 run;

tfork: clean clang kernel tfork_ p1 run;

.PHONY: clean
clean:
rm -rf *.mips32 selfie

clang:
clang -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

kernel:
./selfie -c kernel.c -o kernel.mips32

p1:
./selfie -c p1.c -o p1.mips32

run:
./selfie -l kernel.mips32 -m 128

cas_:
cp ./testPCP_CAS.c p1.c

ncas_:
cp ./testPCP_noCAS.c p1.c

tfork_:
cp ./testTFork.c p1.c

debug:
clang -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie -g && gdb selfie

selftest:
clang -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie -g && ./selfie -c selfie.c -o selfie.mips32
246 changes: 246 additions & 0 deletions kernel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
//Kernel.c
int* args;
int debug = 0; //Set from microkernel
int pMemSize = 0; //Set from microkernel
int bootPrep = 1;
int* node;
int* readyQ = (int*)0;
int* pFree = (int*)0;
int pId = 1;
int VMEMSIZE = 4194304;
int CMD_BOOT = 1;
int CMD_CREATECONTEXT = 2;
int CMD_SWITCHCONTEXT = 3;
int CMD_DELETECONTEXT = 4;
int CMD_MAPPAGEINCCONTEXT = 5;
int CMD_FLUSHPAGEINCCONTEXT = 6;
int CMD_HALT = 7;
int CMD_TFORK = 8;

void printBoot();
int* create_Context();
void delete_Context();
int* getPFree();
void addPFree(int* addr);

int* dummyP1;
int* dummyP2;
int i;
int main()
{
if (bootPrep == 1) {
args = amalloc(4 * 4, 2); //IPC Microkernel <-> kernel process
bootPrep = 0;
}
if (*args == CMD_BOOT) { //BOOT
debug = *(args + 3);
pMemSize = *(args + 2);
printBoot();
node = create_Context();
mc_loadBinary(*(node + 1), *(node + 2), *(node + 3), *(node + 4));
}
else if (*args == CMD_MAPPAGEINCCONTEXT) {
node = (int*)*(readyQ + 2);
node = node + *(args + 1); //vpn
if ((int)pFree == 0) {
*node = (int)amalloc(1024 * 4, 1); //Aligned Malloc with 4KB = 1Page
}
else {
*node = (int)getPFree();
}
mapPageInContext();
}
else if (*args == CMD_FLUSHPAGEINCCONTEXT) {
}
else if (*args == CMD_SWITCHCONTEXT) {
if ((int)readyQ == 0) {
exit(1);
}
*(readyQ + 1) = *(args + 1); //Save pc
*(readyQ + 2) = *(args + 2); //Save pT
*(readyQ + 3) = *(args + 3); //Save registers
readyQ = (int*)*readyQ;
switchContext(*(readyQ + 1), *(readyQ + 2), *(readyQ + 3), *(readyQ + 4));
}
else if (*args == CMD_DELETECONTEXT) {
delete_Context();
if ((int)readyQ == 0) {
deleteContext(0, 0, 0, 0);
}
else {
deleteContext(*(readyQ + 1), *(readyQ + 2), *(readyQ + 3), *(readyQ + 4));
}
}
else if (*args == CMD_CREATECONTEXT) {
node = create_Context();
createContext(*(node + 1), *(node + 2), *(node + 3), *(node + 4));
}else if(*args == CMD_TFORK){
*(readyQ + 1) = *(args + 1); //Save pc
*(readyQ + 2) = *(args + 2); //Save pT
*(readyQ + 3) = *(args + 3); //Save registers
node = create_Context();
//Copy pageTable unitl we read a zero, or we are on the last 8KB
dummyP1 = (int*)*(node+2);
dummyP2 =(int*)*(readyQ + 2);
i = 0;
while(*(dummyP2+i) != 0){
*(dummyP1 + i) = *(dummyP2 + i);
i = i + 1;
}
*(dummyP1 + 1023) = (int)amalloc(1024 * 4 , 1);
//*(dummyP1 + (VMEMSIZE / 4)-2) = amalloc(1024 * 4, 1);
dummyP1 = (int*)*(dummyP1 + (VMEMSIZE /4));
dummyP2 = (int*)*(dummyP2 + (VMEMSIZE /4));
i = 0;
while(*(dummyP2+i) != 0){
*(dummyP1 +i) = *(dummyP2 + i);
i = i + 1;
}
i = 0;
dummyP1 = (int*)*(node + 3);
dummyP2 = (int*)*(readyQ + 3);
while(i < 32){
*(dummyP1 + i) = *(dummyP2 + i);
i = i + 1;
}
*(dummyP1 + 2) = 0; //Child has internal PID 0 after fork
*(dummyP2 + 2) = *(node + 4); //Parent has in REG_V0 the pid of the child
*(node + 1) = *(readyQ + 1);
createContext(*(readyQ + 1), *(readyQ + 2), *(readyQ + 3), *(readyQ + 4)); //Restore Parent
}
else if (*args == CMD_HALT) {
exit(0);
}
}
//PList
//| Next |
//| PC |
//| pT |
//| reg |
//| pId |
int* create_Context()
{
int* node;
int* ptr;
ptr = readyQ;
node = malloc(5 * 4);
if ((int)readyQ == 0) {
readyQ = node;
*node = (int)readyQ;
}
else {
while (*ptr != (int)readyQ) {
ptr = (int*)*ptr;
}
*ptr = (int)node;
*node = (int)readyQ;
}
*(node + 1) = 0;
*(node + 2) = (int)malloc(VMEMSIZE / 4);
*(node + 3) = (int)malloc(32 * 4);
*(node + 4) = pId;
pId = pId + 1;
ptr = (int*)*(node + 3);
*(ptr + 29) = VMEMSIZE - 4;
//We Hardcode for now:
//We set the first 8kb vmem to
//load the binary later we will do this
//in the OS
ptr = (int*)*(node + 2);
*ptr = (int)amalloc(1024 * 4, 1);
*(ptr + 1) = (int)amalloc(1024 * 4, 1);
return node;
}

void delete_Context()
{
int* ptr;
int* newStart;
int i;
int* pTable;
i = 0;
ptr = readyQ;
//pTable = (int*)*(ptr + 2);
//Recycle pages
//while (i < 1024) {
// if (*(pTable + i) != 0) {
// addPFree(pTable + i);
// }
// i = i + 1;
//}
//Is last entry?
if (*ptr == (int)ptr) {
readyQ = (int*)0;
}
else {
newStart = (int*)*ptr;
while (*ptr != (int)readyQ) {
ptr = (int*)*ptr;
}
*ptr = (int)newStart;
readyQ = newStart;
}
}

void printBoot()
{
int i;
i = 0;
putchar(10);
putchar(10);
while (i < 100) {
putchar('=');
i = i + 1;
}
i = 0;
putchar(10);
l_print((int*)"USEG MICROKERNEL");
while (i < 100) {
putchar('=');
i = i + 1;
}
putchar(10);
if (debug == 1) {
l_print((int*)"Debug: True");
}
else {
l_print((int*)"Debug: False");
}
putchar(10);
}

//Freelist
//|Next|
//|addr|

int* getPFree()
{
int* addr;
if ((int)pFree != 0) {
addr = (int*)*(pFree + 1);
pFree = (int*)*pFree;
return addr;
}
return (int*)0;
}

void addPFree(int* addr)
{
int* node;
int* ptr;
if ((int)pFree == 0) {
pFree = malloc(2 * 4);
*pFree = 0;
*(pFree + 1) = (int)addr;
}
else {
node = malloc(2 * 4);
*(node + 1) = (int)addr;
*node = 0;
ptr = pFree;
while (*ptr != 0) {
ptr = (int*)*ptr;
}
*ptr = (int)node;
}
}
Loading