Skip to content

Commit

Permalink
gcc: add more in-memory registers
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Kokosiński <[email protected]>
  • Loading branch information
fkokosinski committed Jun 28, 2024
1 parent f81517b commit c33516f
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 54 deletions.
18 changes: 9 additions & 9 deletions c-print-array/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ static int i = 0;
void _start(void)
{
/* TODO: handle sp/fp init better -- separate crt0.S? */
asm ("law 03000");
asm ("dac 209");
asm ("law 04000");
asm ("dac 208");
asm volatile ("law 03000");
asm volatile ("dac 0131");
asm volatile ("law 04000");
asm volatile ("dac 0130");

/* check with no iterators */
putc(x[0]);
Expand All @@ -23,19 +23,19 @@ void _start(void)

/* check with local iterator w/o func call */
for (int j = 0; j < 3; j++) {
asm ("lio %0" : : "r"(x[j]));
asm ("tyo");
asm volatile ("lio %0" : : "r"(x[j]) : "$io");
asm volatile ("tyo");
}

/* check with local iterator w/ func call */
for (int j = 0; j < 3; j++)
putc(x[j]);

asm ("hlt");
asm volatile ("hlt");
__builtin_unreachable();
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}
6 changes: 3 additions & 3 deletions c-print-fibonacci/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ static int fib(int);
void _start(void)
{
asm volatile ("law 04000");
asm volatile ("dac 209");
asm volatile ("dac 0131");
asm volatile ("law 03000");
asm volatile ("dac 208");
asm volatile ("dac 0130");

int n;

Expand All @@ -24,7 +24,7 @@ void _start(void)

static void putc(int c)
{
asm volatile ("lio %0" : : "r"(c) : "io");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}

Expand Down
14 changes: 7 additions & 7 deletions c-print-for-loop/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ static int get_char(int);

void _start(void)
{
asm ("law 04000");
asm ("dac 209");
asm ("law 03000");
asm ("dac 208");
asm volatile ("law 04000");
asm volatile ("dac 0131");
asm volatile ("law 03000");
asm volatile ("dac 0130");

int c;

Expand All @@ -15,13 +15,13 @@ void _start(void)
putc(c);
}

asm ("hlt");
asm volatile ("hlt");
__builtin_unreachable();
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}

static int get_char(int c)
Expand Down
11 changes: 6 additions & 5 deletions c-print-struct/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ static struct {

void _start(void)
{
asm ("law 04000");
asm ("dac 209");
asm ("dac 208");
asm volatile ("law 04000");
asm volatile ("dac 0131");
asm volatile ("law 03000");
asm volatile ("dac 0130");

x.field1 = 027;
x.field2 = 030;
Expand All @@ -26,6 +27,6 @@ void _start(void)
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}
17 changes: 9 additions & 8 deletions c-print-x/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ int y;

void _start(void)
{
asm ("law 04000");
asm ("dac 209");
asm ("dac 208");
asm volatile ("law 04000");
asm volatile ("dac 0131");
asm volatile ("law 03000");
asm volatile ("dac 0130");

asm ("lio %0" : : "r"(x));
asm ("tyo");
asm volatile ("lio %0" : : "r"(x) : "$io");
asm volatile ("tyo");

y = 027;
asm ("lio %0" : : "r"(y));
asm ("tyo");
asm volatile ("lio %0" : : "r"(y) : "$io");
asm volatile ("tyo");

asm ("hlt");
asm volatile ("hlt");

__builtin_unreachable();
}
14 changes: 7 additions & 7 deletions c-test-arith/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ int z;
void _start(void)
{
/* TODO: handle sp/fp init better -- separate crt0.S? */
asm ("law 03000");
asm ("dac 209");
asm ("law 04000");
asm ("dac 208");
asm volatile ("law 03000");
asm volatile ("dac 0131");
asm volatile ("law 04000");
asm volatile ("dac 0130");

x = 21;
y = 37;
Expand All @@ -23,11 +23,11 @@ void _start(void)
if (z == 4)
putc(027);

asm ("hlt");
asm volatile ("hlt");
__builtin_unreachable();
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}
14 changes: 7 additions & 7 deletions c-test-comparison/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ static void putc(int);
void _start(void)
{
/* TODO: handle sp/fp init better -- separate crt0.S? */
asm ("law 03000");
asm ("dac 209");
asm ("law 04000");
asm ("dac 208");
asm volatile ("law 03000");
asm volatile ("dac 0131");
asm volatile ("law 04000");
asm volatile ("dac 0130");

int x = 30;
int y = 30;
Expand Down Expand Up @@ -44,11 +44,11 @@ void _start(void)
if (x > y)
putc(071); // i

asm ("hlt");
asm volatile ("hlt");
__builtin_unreachable();
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}
14 changes: 7 additions & 7 deletions c-test-recursion/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ static void foo(int);
void _start(void)
{
/* TODO: handle sp/fp init better -- separate crt0.S? */
asm ("law 03000");
asm ("dac 209");
asm ("law 04000");
asm ("dac 208");
asm volatile ("law 03000");
asm volatile ("dac 0131");
asm volatile ("law 04000");
asm volatile ("dac 0130");

foo(20);

asm ("hlt");
asm volatile ("hlt");
__builtin_unreachable();
}

static void putc() {
asm ("lio %0" : : "r"(027) : "io");
asm ("tyo");
asm volatile ("lio %0" : : "r"(027) : "$io");
asm volatile ("tyo");
}

static void foo(int n)
Expand Down
2 changes: 1 addition & 1 deletion pdp1-gcc
Submodule pdp1-gcc updated 4536 files

0 comments on commit c33516f

Please sign in to comment.