From 349b6861063ab5e529f77d59ba95bbc7a37fecd5 Mon Sep 17 00:00:00 2001
From: Adam Blank <blank@caltech.edu>
Date: Sun, 2 Jun 2019 10:01:38 -0700
Subject: [PATCH] Revert "Merge branch 'submit' into 'master'"

This reverts merge request !1
---
 sthreads/Makefile   |   9 ++----
 sthreads/glue.s     |  69 +++++------------------------------------
 sthreads/sthread.c  |  74 +++++---------------------------------------
 sthreads/test_arg.c |  14 ---------
 sthreads/test_ret.c |  22 -------------
 syscalls/Makefile   |   3 --
 syscalls/greeting   | Bin 9912 -> 0 bytes
 syscalls/greeting.c |   3 +-
 syscalls/output.s   |  11 -------
 9 files changed, 18 insertions(+), 187 deletions(-)
 delete mode 100644 sthreads/test_arg.c
 delete mode 100644 sthreads/test_ret.c
 delete mode 100755 syscalls/greeting
 delete mode 100644 syscalls/output.s

diff --git a/sthreads/Makefile b/sthreads/Makefile
index ce67212..9b25ef9 100644
--- a/sthreads/Makefile
+++ b/sthreads/Makefile
@@ -9,13 +9,8 @@ CFLAGS = -Wall -g -std=c99 -pedantic
 ASFLAGS = -g
 
 
-all: test test_arg test_ret
+all: test
 
-test_arg: sthread.o queue.o glue.o test_arg.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-
-test_ret: sthread.o queue.o glue.o test_ret.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
 
 # The simple test program
 test: sthread.o queue.o glue.o test.o
@@ -24,7 +19,7 @@ test: sthread.o queue.o glue.o test.o
 
 # pseudo-target to clean up
 clean:
-	$(RM) -f *.o core* *~ test test_arg test_ret
+	$(RM) -f *.o core* *~ test
 
 
 .PHONY: all clean
diff --git a/sthreads/glue.s b/sthreads/glue.s
index 485480c..da4cd00 100644
--- a/sthreads/glue.s
+++ b/sthreads/glue.s
@@ -28,24 +28,7 @@ scheduler_context:      .quad   0
 __sthread_switch:
 
         # Save the process state onto its stack
-        pushq   %rax
-        pushq   %rbx
-        pushq   %rcx
-        pushq   %rdx
-        pushq   %rsi
-        pushq   %rdi
-        pushq   %rbp
-
-        pushq   %r8
-        pushq   %r9
-        pushq   %r10
-        pushq   %r11
-        pushq   %r12
-        pushq   %r13
-        pushq   %r14
-        pushq   %r15
-
-        pushf
+        # TODO
 
         # Call the high-level scheduler with the current context as an argument
         movq    %rsp, %rdi
@@ -56,27 +39,7 @@ __sthread_switch:
         # Restore the context to resume the thread.
 __sthread_restore:
 
-        # returned context is new stack
-        movq %rax, %rsp
-
-        popf 
-
-        popq   %r15
-        popq   %r14
-        popq   %r13
-        popq   %r12
-        popq   %r11
-        popq   %r10
-        popq   %r9
-        popq   %r8
-
-        popq   %rbp
-        popq   %rdi
-        popq   %rsi
-        popq   %rdx
-        popq   %rcx
-        popq   %rbx
-        popq   %rax
+        # TODO
 
         ret
 
@@ -99,29 +62,11 @@ __sthread_restore:
         .globl __sthread_initialize_context
 __sthread_initialize_context:
 
-        # %rdi - stackp, %rsi - f, %rdx - arg
-        # return value in %rax is the stack pointer,
-        # leave 144 bytes for thread context details and return address.
-        movq    %rdi, %rax
-        subq    $144, %rax
-
-        leaq    __sthread_finish(%rip), %rdi      
-        movq    %rdi,  136(%rax)          # kill thread when done with f
-        movq    %rsi,  128(%rax)          # address of f to come back to
-        movq    $0,    120(%rax)          # rax = 0
-        movq    $0,    112(%rax)          # rcx = 0
-        movq    $0,    96(%rax)           # rdx = 0
-        movq    $0,    88(%rax)           # rsi = 0
-        movq    %rdx,  80(%rax)           # rdi = arg
-        movq    $0,    72(%rax)           # rbp = 0
-        movq    $0,    64(%rax)           # r9  = 0
-        movq    $0,    48(%rax)           # r10 = 0
-        movq    $0,    40(%rax)           # r11 = 0
-        movq    $0,    32(%rax)           # r12 = 0
-        movq    $0,    24(%rax)           # r13 = 0
-        movq    $0,    16(%rax)           # r14 = 0
-        movq    $0,    8(%rax)            # r15 = 0
-        movq    $0,    (%rax)             # rflags = 0
+        # TODO
+
+        # TODO - Make sure you completely document every part of your
+        #        thread context; what it is, and why you set each value
+        #        to what you choose.
 
         ret
 
diff --git a/sthreads/sthread.c b/sthreads/sthread.c
index c20720a..653257a 100644
--- a/sthreads/sthread.c
+++ b/sthreads/sthread.c
@@ -129,43 +129,8 @@ static void enqueue_thread(Thread *threadp) {
  */
 ThreadContext *__sthread_scheduler(ThreadContext *context) {
 
-    if (context != NULL) {
-        /* Save the context argument into the current thread. */
-        current->context = context;
-        /* Either queue up or deallocate the current thread, based on its state. */
-        switch(current->state) {
-            case ThreadRunning:
-                current->state = ThreadReady; //change to ready and enqueue
-                enqueue_thread(current);
-                break;
-            case ThreadBlocked:
-                enqueue_thread(current); // enqueue to blocked queue
-                break;
-            case ThreadFinished:
-                __sthread_delete(current); // delete thread
-                break;
-            default:
-                fprintf(stderr, "Thread state has been corrupted: %d\n",
-                    current->state);
-                exit(1);
-        }
-    }
-
-    Thread *next = queue_take(&ready_queue); // get next ready thread
-    // if next exists set current to next and set it to running
-    if (next != NULL) { 
-        current = next;
-        current->state = ThreadRunning;
-    } else {
-        // otherwise if no blocked threads done, if blocked threads deadlock
-        if (queue_empty(&blocked_queue)) {
-            printf("All threads completed successfully\n");
-            exit(0);
-        } else {
-            fprintf(stderr, "System deadlock\n");
-            exit(1);
-        }
-    }
+    /* TODO:  Replace these lines with your implementation */
+    /* TODO */ assert(0); /* TODO */
 
     /* Return the next thread to resume executing. */
     return current->context;
@@ -191,32 +156,9 @@ void sthread_start(void)
  * structure, and it adds the thread to the Ready queue.
  */
 Thread * sthread_create(void (*f)(void *arg), void *arg) {
-    // allocate stack space for thread
-    void *memory = (void *) malloc(DEFAULT_STACKSIZE);
-    if (memory == NULL) {
-        fprintf(stderr, "No memory to allocate thread stack\n");
-        exit(1);
-    }
-
-    // allocate thread struct
-    Thread *threadp = (Thread *) malloc(sizeof(Thread));
-    if (threadp == NULL) {
-        fprintf(stderr, "No memory to allocate thread struct\n");
-        free(memory); // no leaks
-        exit(1);
-    }
-
-    // set state and memory
-    threadp->state = ThreadReady;
-    threadp->memory = memory;
-
-    // stack pointer at start of region allocated for stack
-    void *stackp = (void *) ((char *) memory + DEFAULT_STACKSIZE);
-    threadp->context = __sthread_initialize_context(stackp, f, arg);
-    // enqueue to ready queue
-    enqueue_thread(threadp);
-    
-    return threadp;
+    /* TODO:  Replace this function's body with your implementation */
+    /* TODO */ assert(0); /* TODO */
+    return NULL;
 }
 
 
@@ -241,10 +183,8 @@ void __sthread_finish(void) {
  * context, as well as the memory for the Thread struct.
  */
 void __sthread_delete(Thread *threadp) {
-    // free memory for context
-    free(threadp->memory);
-    // free thread struct 
-    free(threadp);
+    /* TODO:  Replace this function's body with your implementation */
+    /* TODO */ assert(0); /* TODO */
 }
 
 
diff --git a/sthreads/test_arg.c b/sthreads/test_arg.c
deleted file mode 100644
index f065cba..0000000
--- a/sthreads/test_arg.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include "sthread.h"
-
-/* thread prints int arg */
-static void test(void *arg) {
-	printf("%zd\n", (intptr_t) arg);
-}
-
-int main(int argc, char **argv) {
-    sthread_create(test, (void *) 3);
-    sthread_start();
-    return 0;
-}
\ No newline at end of file
diff --git a/sthreads/test_ret.c b/sthreads/test_ret.c
deleted file mode 100644
index 2994798..0000000
--- a/sthreads/test_ret.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include "sthread.h"
-
-/* print HELLO! arg times yield thread each time */
-static void loop(void *arg) {
-	int i;
-	for (i = 0; i < (intptr_t) arg; i++) {
-		printf("HELLO!\n");
-		sthread_yield();
-	}
-}
-
-int main(int argc, char **argv) {
-	/* threads with different lifetimes */
-	sthread_create(loop, (void *) 1);
-	sthread_create(loop, (void *) 2);
-	sthread_create(loop, (void *) 3);
-	sthread_create(loop, (void *) 4);
-	sthread_start();
-    return 0;
-}
\ No newline at end of file
diff --git a/syscalls/Makefile b/syscalls/Makefile
index 56ac174..8bc0922 100644
--- a/syscalls/Makefile
+++ b/syscalls/Makefile
@@ -4,9 +4,6 @@ CFLAGS = -Wall -Werror -g -O0
 
 all: greeting
 
-greeting.o: greeting.c
-output.o: output.s
-
 
 greeting: greeting.o output.o
 	$(CC) $(CFLAGS) greeting.o output.o -o greeting $(LDFLAGS)
diff --git a/syscalls/greeting b/syscalls/greeting
deleted file mode 100755
index 0b82be7de95002d4e1aa52cef7b4583e66490548..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 9912
zcmeHNeQaCR6~FH}{%DgrPScjO1^R$?3kW+&Nkd9k`kch=GfF?!CJeTPSI2&_4UQez
z&t1|X!WN2Tm9kc2qtcjGF(!2r8fE`1VpE%{h?HqaWfNO9wy8{jQodF`)<xQ=cg}tH
zIQEN!5YqnZk$lfRzkANP_nvp({dyh`^=_3Vi4n={PKMI18kIv<%Gl&}TohO*Tf|hh
zmfgTyfH>i&@)G1$j`*x_P23~&9KdVf*C|^-r>yb}@oO!Z5vLX+$NJ_-6<Le_-ffA*
z8B;ibcGy;*my5vn@(l52(T-NZ$qq%dYZi9R!jAYk(J<oFKkOU+`h>qeSp^AY6&dT{
z=^RI0q+M^BG0Z=Mm2$3D@OCaSMx5-v3U;FFLgTZUPZaMK^(_>aOQL_og~(b`$-$2H
zmQ>82N~ZIp{?X13e@A;DmkF%r{YL+&yKP55uZiNQfP`&c20t7FSibqx*u8)G<sY11
z`R(cZPoE8M{PrK0uSHw>LH2V~Eod&SqK)II8Xf>#siM!Ie^KmC2h;VO8HqliM-va|
zLy=?(04zi_YwE+1WEzn8a3(Dfoo(w4cXjLQ1M34DN_qakWZq}2PGU0eA3cZss^lV!
z$Yv-*Y*{k7gn>>Nm4RmK_i~QI0^>&1<lD=$`0O!WL`oT68q!dxO}yvP4mv-rRhV{Q
z%5=_b;^2#(GnQp>!$(k5T=xm2^=nkfp`5_Nix-MO>)t^btGalO%fAA7=&)tYSlj#I
z!mIabg@0%hZ(iEf7oMIv>{6LFeOlpcdaF}qGrtDIPloE(^uWBb1sd9~`8$DW6SH2e
z@YcT7ljse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ugzk?>-`@Y93w!#eeaxkD)nmfmu1_-Y=Y>5rlg>Z%
zzk_z}Z7v}@LQdK2>6~<4)c*-73T}_z%YehKy!0)b_Mh}W1iQXnehqBv%k1gg)r3xg
z?D}^34bZ{yBZgb)oS}S9`?tXsyGr(Sj-&sHoI~e8A{?dm(D*wFW##qL_x)My6p+2W
zBoqH9=#<-+&V{0aX6|J!Av@x;HhbFlHVb=dCwU+{lCMApG3r0<BRhqmU0;NQ%$WlK
z#9B*;l_7ik_#=Dbb;90e&QhX&yI-;+{nZQDKPBw1w;9+(_T>faUudvuu&>f~`wa`&
z-zr{cgBmKh-99Mn?fpC=?D1StPGnCUn@P{ETrVLOPCSQ|lTGB$j^>VXy+orW(L8Vy
ei1;jNJka`q^INt0RWb3?|FJA@)>xrD^8W#cO$K}b

diff --git a/syscalls/greeting.c b/syscalls/greeting.c
index d8ac7f3..b5c2fc7 100644
--- a/syscalls/greeting.c
+++ b/syscalls/greeting.c
@@ -1,6 +1,7 @@
 #include <stdint.h>
 
-extern int64_t output(void *data, uint64_t size);
+int64_t output(void *data, uint64_t size);
+
 
 /* INCOMING TRANSMISSION... */
 int main() {
diff --git a/syscalls/output.s b/syscalls/output.s
deleted file mode 100644
index d85f18c..0000000
--- a/syscalls/output.s
+++ /dev/null
@@ -1,11 +0,0 @@
-# function outputs alien message (writes msg to stdout)
-# arg1 (msg address) at %rdi, arg2 (msg size) at %rsi
-# returns size of outputted msg stored in %rax
-.globl output
-output:
-	movq $1, %rax # syscall write is 1
-	movq %rsi, %rdx # write arg3 (count) is sizeof(msg)
-	movq %rdi, %rsi # write arg2 (*buf) is msg
-	movq $1, %rdi # write arg1 (fd) is 1
-	syscall # make syscall
-	
\ No newline at end of file
-- 
GitLab