Skip to content

Commit

Permalink
+ Add codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansimov committed Oct 4, 2020
1 parent fce7806 commit 96d586d
Show file tree
Hide file tree
Showing 1,111 changed files with 598,713 additions and 0 deletions.
Binary file added _codes/code-all.tar
Binary file not shown.
Binary file added _codes/code.tar
Binary file not shown.
22 changes: 22 additions & 0 deletions _codes/code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all:
echo "Please specify a rule"

dist:
(cd opt; make dist)

clean:
(cd arch; make clean)
(cd asm; make clean)
(cd conc; make clean)
(cd data; make clean)
(cd ecf; make clean)
(cd error; make clean)
(cd intro; make clean)
(cd io; make clean)
(cd link; make clean)
(cd mem; make clean)
(cd netp; make clean)
(cd opt; make clean)
(cd perf; make clean)
(cd src; make clean)
(cd vm; make clean)
29 changes: 29 additions & 0 deletions _codes/code/arch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CFLAGS = -O1 -m64
ISADIR = ../../im/labs/archlab/src/misc
YAS = $(ISADIR)/yas
YIS = $(ISADIR)/yis

pushpoptest: pushpoptest.c pp.s
$(CC) $(CFLAGS) -o pushpoptest pushpoptest.c pp.s
cp -p pp.s pp.sa


.SUFFIXES: .c .s .o .ys .yo .yis .txt

.c.s:
$(CC) $(CFLAGS) -S $*.c -o $*.s

.ys.yo:
$(YAS) $*.ys

# Extracting code fragments
.yo.txt:
egrep "\| #|:[ a-f0-9]*\|" $*.yo | \
perl -ne "s/:[ a-f0-9]+\|/:/; s/[ ]*\|[ ]*#/#/; print;" > $*.txt

.yo.yis: $(YIS)
$(YIS) $*.yo > $*.yis

clean:
rm -f *~ pushpoptest

43 changes: 43 additions & 0 deletions _codes/code/arch/pp.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* $begin pushtest-s 0 */
.text
.globl pushtest
pushtest:
movq %rsp, %rax # Copy stack pointer
pushq %rsp # Push stack pointer
popq %rdx # Pop it back
subq %rdx, %rax # Return 0 or 8
ret
/* $end pushtest-s 0 */

/* $begin poptest-s 0 */
.text
.globl poptest
poptest:
movq %rsp, %rdi # Save stack pointer
pushq $0xabcd # Push test value
popq %rsp # Pop to stack pointer
movq %rsp, %rax # Set popped value as return value
movq %rdi, %rsp # Restore stack pointer
ret
/* $end poptest-s 0 */

.text
.globl _pushtest
_pushtest:
movq %rsp, %rax # Copy stack pointer
pushq %rsp # Push stack pointer
popq %rdx # Pop it back
subq %rdx, %rax # Return 0 or 8
ret

.text
.globl _poptest
_poptest:
movq %rsp, %rdi # Save stack pointer
pushq $0xabcd # Push test value
popq %rsp # Pop to stack pointer
movq %rsp, %rax # Set popped value as return value
movq %rdi, %rsp # Restore stack pointer
ret


43 changes: 43 additions & 0 deletions _codes/code/arch/pp.sa
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* $begin pushtest-s 0 */
.text
.globl pushtest
pushtest:
movq %rsp, %rax # Copy stack pointer
pushq %rsp # Push stack pointer
popq %rdx # Pop it back
subq %rdx, %rax # Return 0 or 8
ret
/* $end pushtest-s 0 */

/* $begin poptest-s 0 */
.text
.globl poptest
poptest:
movq %rsp, %rdi # Save stack pointer
pushq $0xabcd # Push test value
popq %rsp # Pop to stack pointer
movq %rsp, %rax # Set popped value as return value
movq %rdi, %rsp # Restore stack pointer
ret
/* $end poptest-s 0 */

.text
.globl _pushtest
_pushtest:
movq %rsp, %rax # Copy stack pointer
pushq %rsp # Push stack pointer
popq %rdx # Pop it back
subq %rdx, %rax # Return 0 or 8
ret

.text
.globl _poptest
_poptest:
movq %rsp, %rdi # Save stack pointer
pushq $0xabcd # Push test value
popq %rsp # Pop to stack pointer
movq %rsp, %rax # Set popped value as return value
movq %rdi, %rsp # Restore stack pointer
ret


13 changes: 13 additions & 0 deletions _codes/code/arch/pushpoptest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Experiments to test pushl %esp */

#include <stdio.h>
#include <stdlib.h>

long pushtest();
long poptest();

int main()
{
printf("pushtest -> 0x%lx\n", pushtest());
printf("poptest -> 0x%lx\n", poptest());
}
18 changes: 18 additions & 0 deletions _codes/code/asm/#010-main.c#
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* $begin 010-multmain-c */
#include <stdio.h>

void multstore(long, long, long *);

int main() {
long d;
multstore(2, 3, &d);
printf("2 * 3 --> %ld\n", d);
return 0;
}

long mult2(long a, long b) {
long s = a * b;
return s;
}
/* $end 010-multmain-c */

21 changes: 21 additions & 0 deletions _codes/code/asm/010-code-gdb.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /afs/cs.cmu.edu/project/ics3/code/asm/prog...(no debugging symbols found)...done.
Breakpoint 1 at 0x400540

Breakpoint 1, 0x0000000000400540 in multstore ()
$1 = 0x7fffffffe818
$2 = 0x400540
0x0000000000400544 in multstore ()
$3 = 0x400544
0x000000000040054d in multstore ()
$4 = 0x40054d
2 * 3 --> 6
[Inferior 1 (process 29584) exited normally]
10 changes: 10 additions & 0 deletions _codes/code/asm/010-code.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
break multstore
run
print /x $rsp
print /x $rip
nexti 2
print /x $rip
nexti 3
print /x $rip
cont
quit
Loading

0 comments on commit 96d586d

Please sign in to comment.