LoginSignup
2
2

More than 5 years have passed since last update.

PDP-11(エミュ)で動作するコマンドプロンプトみたいなもの

Last updated at Posted at 2015-09-27

PDP-11(エミュ)上で動作するコマンドプロンプトのひな形みたいなプログラムを書いてみた。
打った文字をそのまま表示するだけものだが、Input/Outputの基本となるものだ。

ソースコード

cmdline.c
#define KL11_TTY_REG_ADDRESS 0177560;
#define TXRDY (1<<7)
#define NRETRY 5000

static volatile struct kl11_tty {
  int in_csr;
  int in_dbr;
  int out_csr;
  int out_dbr;
} *pkl11 = (struct kl11_tty*)KL11_TTY_REG_ADDRESS;

void bzero(char *, int);
void putchar(const int);
void puts(const char*);
int getchar(void);
int getline(char *);

int cstart()
{
  char buf[256];

  bzero(buf, sizeof(buf));
  do {
      puts("> ");
      if(getline(buf)>0) {
          puts("\r\n");
          puts(buf);
          bzero(buf, sizeof(buf));
      }
      puts("\r\n");
  } while(1);
}
void putchar(const int c)
{
    while(!(pkl11->out_csr & TXRDY))
        ;
    pkl11->out_dbr = c;
}
void puts(const char *s)
{
  while(*s)
    putchar(*s++);
}
int getchar()
{
  while(!(pkl11->in_csr & TXRDY))
      ;
  return pkl11->in_dbr;
}
int getline(char *buf)
{
    char c;
    int nc = 0;

    while((c=getchar()) != '\r') {
        putchar(c);
        *buf++ = c;
        nc++;
    }
    return nc;
}
void bzero(char *buf, int len)
{
    while(len--)
        *buf++ = 0;
}
start.S
    .global start
    .global _cstart

    STACK = 0x1000

    .text
start:
    mov     $STACK, sp
    jsr     pc, _cstart
    halt

    .end
ld.script
ENTRY(start)
SECTIONS
{
    . = 01000;
    .text : {
        *(.text)
        *(.rodata)
        . = ALIGN(0100);
    }
    .data : {
        *(.data)
        . = ALIGN(0100);
    }
    .bss : {
        *(.bss)
        . = ALIGN(0100);
    }
    end = .;
}
Makefile
CC = pdp11-aout-gcc
AS = pdp11-aout-as

CFLAGS = -ffreestanding

all: $(TARGET).lda

run: rc-pdp11
    pdp11 $<

rc-pdp11: $(TARGET).lda
    @echo "l " $< > rc-pdp11

$(TARGET).lda: $(TARGET).out
    bin2load -a -f $< -o $@

$(TARGET).out: $(OBJS) ld.script
    pdp11-aout-ld -T ld.script $(OBJS) -o $@

.c.o:
    $(CC) $(CFLAGS) -c $< -o $@

.c.s:
    $(CC) -S $< -o $@

.S.o:
    $(AS) $< -o $@

clean:
    rm -f *.lda
    rm -f *.out
    rm -f *.o
    rm -f rc-pdp11

ビルド方法

ファイルを入れたディレクトリにて、

$ make

と打つ。

実行方法

$make run
pdp11 rc-pdp11

PDP-11 simulator V3.9-0
sim> g
> feqfeqko
feqfeqko
> ffqq
ffqq
>

make runと打つとrc-pdp11という設定ファイルを読み込んでpdp11を実行する。
起動した後に、’g’と打つことで、PDP-11エミュ上にロードされた本プログラムが実行される。

このプログラムでは'>'を表示して入力待ちとし、
適当に文字を打ってエンターを押すと、打った文字列を次の行に表示する。

必要なツール環境

(1) PDP-11のgccクロス環境構築は以下記事を参照
http://qiita.com/hifistar/items/187fd7ad780c6aa26141

(2) bin2loadは以下から
The Ancient Bits adventure: Writing PDP11 assembly code from Linux (and running it on bare -simulated- metal!) 

(3) simh
http://simh.trailing-edge.com/

以上。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2