-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Filip Kokosiński <filip.kokosinski@gmail.com>
- Loading branch information
0 parents
commit 8947f85
Showing
23 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: PDP-1 Playground | ||
on: [push] | ||
jobs: | ||
Test-Toolchain: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout pdp1-playground | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y git build-essential flex bison texinfo libgmp3-dev libmpfr-dev libmpc-dev simh dejagnu | ||
- name: Build binutils-gdb for PDP-1 | ||
run: | | ||
cd pdp1-binutils | ||
./configure --target=pdp1-elf --disable-sim | ||
make -j $(nproc) | ||
sudo make install | ||
- name: Build gcc for PDP-1 | ||
run: | | ||
cd pdp1-gcc | ||
./configure --target=pdp1-elf --enable-languages=c --disable-bootstrap | ||
make -j $(nproc) all-gcc | ||
- name: Build samples | ||
run: | | ||
for sample in asm-*; do make -C $sample clean main.rim; done | ||
for sample in c-*; do make -C $sample clean main.s main.rim; done | ||
- name: Run tests | ||
run: | | ||
runtest --srcdir $(pwd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.bin | ||
*.o | ||
*.rim | ||
*.s | ||
*.log | ||
*.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "pdp1-binutils"] | ||
path = pdp1-binutils | ||
url = https://github.com/fkokosinski/binutils-gdb.git | ||
branch = pdp1 | ||
[submodule "pdp1-gcc"] | ||
path = pdp1-gcc | ||
url = https://github.com/fkokosinski/gcc.git | ||
branch = pdp1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Filip Kokosiński | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# PDP-1 Playground | ||
|
||
## Dependencies | ||
``` | ||
sudo apt-get install git build-essential flex bison texinfo libgmp3-dev libmpfr-dev libmpc-dev simh dejagnu | ||
``` | ||
|
||
## Building binutils | ||
``` | ||
cd pdp1-binutils | ||
./configure --target=pdp1-elf --disable-sim | ||
make -j $(nproc) | ||
sudo make install | ||
``` | ||
|
||
## Building gcc | ||
``` | ||
cd pdp1-gcc | ||
./configure --target=pdp1-elf --enable-languages=c --disable-bootstrap | ||
make -j $(nproc) all-gcc | ||
``` | ||
|
||
## Building and running samples | ||
|
||
``` | ||
cd c-print-for-loop | ||
make main.s main.rim run | ||
``` | ||
|
||
## Running tests | ||
``` | ||
runtest --srcdir $(pwd) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* Simple asm program that prints out 'hello, world' on standard output */ | ||
|
||
.section .data | ||
i: | ||
.byte 0 | ||
ptr: | ||
.byte str | ||
len: | ||
.byte end - str | ||
str: | ||
/* TOOD: use .ascii-derived FIODEC directive here */ | ||
.byte 070 | ||
.byte 065 | ||
.byte 043 | ||
.byte 043 | ||
.byte 046 | ||
.byte 033 | ||
.byte 000 | ||
.byte 026 | ||
.byte 046 | ||
.byte 051 | ||
.byte 043 | ||
.byte 064 | ||
end: | ||
|
||
.section .text | ||
.global _start | ||
_start: | ||
/* load IO register with *ptr and print it */ | ||
lio.i ptr | ||
tyo | ||
|
||
/* ptr++, i++ */ | ||
idx ptr | ||
idx i | ||
|
||
/* if (i == len) goto _start */ | ||
lac i | ||
sas len | ||
jmp _start | ||
|
||
/* halt */ | ||
hlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* Simple asm program that prints out 'x' on standard output */ | ||
|
||
.section .data | ||
x: | ||
/* 027 is 'x' in FIO DEC encoding */ | ||
.byte 027 | ||
|
||
.section .text | ||
.global _start | ||
_start: | ||
/* load IO register with *x */ | ||
lio x | ||
tyo | ||
|
||
/* halt */ | ||
hlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
static void putc(int); | ||
static int get_char(int); | ||
|
||
static int x[] = {027, 030, 031}; | ||
|
||
void _start(void) | ||
{ | ||
asm ("law 04000"); | ||
asm ("dac 209"); | ||
asm ("dac 208"); | ||
|
||
putc(x[0]); | ||
putc(x[1]); | ||
putc(x[2]); | ||
|
||
asm ("hlt"); | ||
__builtin_unreachable(); | ||
} | ||
|
||
static void putc(int c) { | ||
asm ("lio %0" : : "r"(c)); | ||
asm ("tyo"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
static void putc(int); | ||
static int get_char(int); | ||
|
||
void _start(void) | ||
{ | ||
asm ("law 04000"); | ||
asm ("dac 209"); | ||
asm ("dac 208"); | ||
|
||
int c; | ||
|
||
for (int i = 0; i != 8; i++) { | ||
c = get_char(i); | ||
putc(c); | ||
} | ||
|
||
asm ("hlt"); | ||
__builtin_unreachable(); | ||
} | ||
|
||
static void putc(int c) { | ||
asm ("lio %0" : : "r"(c)); | ||
asm ("tyo"); | ||
} | ||
|
||
static int get_char(int c) | ||
{ | ||
if (c != 4) | ||
return 027; | ||
else | ||
return 030; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
static void putc(int); | ||
|
||
static struct { | ||
int field1; | ||
char field2; | ||
short field3; | ||
} x; | ||
|
||
void _start(void) | ||
{ | ||
asm ("law 04000"); | ||
asm ("dac 209"); | ||
asm ("dac 208"); | ||
|
||
x.field1 = 027; | ||
x.field2 = 030; | ||
x.field3 = 031; | ||
|
||
putc(x.field1); | ||
putc(x.field2); | ||
putc(x.field3); | ||
|
||
|
||
asm ("hlt"); | ||
__builtin_unreachable(); | ||
} | ||
|
||
static void putc(int c) { | ||
asm ("lio %0" : : "r"(c)); | ||
asm ("tyo"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
int x = 027; | ||
|
||
void _start(void) | ||
{ | ||
asm ("law 04000"); | ||
asm ("dac 209"); | ||
asm ("dac 208"); | ||
|
||
asm ("lio %0" : : "r"(x)); | ||
asm ("tyo"); | ||
|
||
asm ("hlt"); | ||
|
||
__builtin_unreachable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
OUTPUT_FORMAT("elf32-pdp1") | ||
ENTRY(_start) | ||
|
||
MEMORY | ||
{ | ||
ram (rwx) : ORIGIN = 0x0, LENGTH = 64K | ||
} | ||
|
||
SECTIONS | ||
{ | ||
.text : | ||
{ | ||
*(.text) | ||
} > ram | ||
|
||
.data 0x400 : | ||
{ | ||
*(.data) | ||
} > ram | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
APP_NAME ?= main | ||
objects-asm := $(patsubst %.S,%.o,$(wildcard *.S)) | ||
objects-c := $(patsubst %.c,%.o,$(wildcard *.c)) | ||
objects := $(objects-asm) $(objects-c) | ||
|
||
default: $(APP_NAME).rim | ||
|
||
%.s: %.c | ||
../pdp1-gcc/host-x86_64-pc-linux-gnu/gcc/cc1 $< | ||
|
||
%.o: %.S | ||
pdp1-elf-as $< -o $@ | ||
|
||
%.o: %.s | ||
pdp1-elf-as $< -o $@ | ||
|
||
$(APP_NAME).bin: ../common/common.ld $(objects) | ||
pdp1-elf-ld -o $@ -T $^ | ||
|
||
%.rim: %.bin | ||
pdp1-elf-objcopy -O dec_rim $< $@ | ||
|
||
run: $(APP_NAME).rim | ||
pdp1 ../common/startup.pdp1 | ||
|
||
clean: | ||
rm -rf *.o *.s *.bin *.rim | ||
|
||
.PHONY: default run clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
att ptr main.rim | ||
boot ptr | ||
quit |
Submodule pdp1-binutils
added at
955d3f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
set timeout 1 | ||
|
||
proc run_test { demo_name expected_output } { | ||
spawn "pdp1" | ||
send "attach ptr $demo_name/main.rim\n" | ||
expect { | ||
"PTR: creating new file" { fail "Didn't find the RIM tape file\n" } | ||
"sim>" { pass "Successfully loaded the RIM tape file\n" } | ||
default { fail "Test failed unexpectedly\n" } | ||
} | ||
|
||
send "boot ptr\n" | ||
expect { | ||
"$expected_output" { pass "Encountered expected output\n" } | ||
default { fail "Didn't encounter expected output\n" } | ||
} | ||
expect { | ||
-re "HALT instruction,.*" { pass "Program finished running normally\n" } | ||
default { fail "Program halted unexpectedly\n" } | ||
} | ||
|
||
send "quit\n" | ||
} | ||
|
||
run_test "asm-print-x" "x" | ||
run_test "asm-hello-world" "hello, world" | ||
run_test "c-print-x" "x" | ||
run_test "c-print-struct" "xyz" | ||
run_test "c-print-array" "xyz" | ||
run_test "c-print-for-loop" "xxxxyxxx" |