URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Subversion Repositories eco32
Compare Revisions
- This comparison shows the changes necessary to convert path
/eco32/tags/eco32-0.22/simtest/disk
- from Rev 9 to Rev 21
- ↔ Reverse comparison
Rev 9 → Rev 21
/mkdisk/mkdisk.c
0,0 → 1,75
/* |
* mkdisk.c -- make an empty physical disk |
*/ |
|
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdarg.h> |
|
|
#define SECTOR_SIZE 512 |
#define MIN_NUMBER_SECTORS 100 |
#define SECTORS_PER_MB ((1 << 20) / SECTOR_SIZE) |
#define DATA_BYTE 0xE5 |
|
|
void error(char *fmt, ...) { |
va_list ap; |
|
va_start(ap, fmt); |
fprintf(stderr, "Error: "); |
vfprintf(stderr, fmt, ap); |
fprintf(stderr, "\n"); |
va_end(ap); |
exit(1); |
} |
|
|
void usage(void) { |
fprintf(stderr, "Usage: mkdisk <file name> <n>[M]\n"); |
fprintf(stderr, " <n>: decimal number of sectors\n"); |
fprintf(stderr, " if 'M' appended: megabytes instead of sectors\n"); |
fprintf(stderr, " (sector size is always %d bytes)\n", SECTOR_SIZE); |
exit(1); |
} |
|
|
int main(int argc, char *argv[]) { |
FILE *dskFile; |
int numSectors; |
unsigned char sectorBuffer[SECTOR_SIZE]; |
int i; |
|
if (argc != 3) { |
usage(); |
} |
numSectors = atoi(argv[2]); |
i = strlen(argv[2]) - 1; |
if (argv[2][i] == 'M') { |
numSectors *= SECTORS_PER_MB; |
} |
if (numSectors < MIN_NUMBER_SECTORS) { |
error("this disk is too small to be useful (minimum size is %d sectors)", |
MIN_NUMBER_SECTORS); |
} |
dskFile = fopen(argv[1], "wb"); |
if (dskFile == NULL) { |
error("cannot open file '%s' for write", argv[1]); |
} |
fprintf(stdout, |
"Creating disk '%s' with %d sectors (around %d MB)...\n", |
argv[1], numSectors, |
(numSectors + SECTORS_PER_MB / 2) / SECTORS_PER_MB); |
for (i = 0; i < SECTOR_SIZE; i++) { |
sectorBuffer[i] = DATA_BYTE; |
} |
for (i = 0; i < numSectors; i++) { |
if (fwrite(sectorBuffer, SECTOR_SIZE, 1, dskFile) != 1) { |
error("write error on file '%s', sector %d", argv[1], i); |
} |
} |
fclose(dskFile); |
return 0; |
} |
/mkdisk/Makefile
0,0 → 1,36
# |
# Makefile for disk creator |
# |
|
BUILD = ../../../build |
|
CC = gcc -m32 |
CFLAGS = -g -Wall |
LDFLAGS = -g |
LDLIBS = -lm |
|
SRCS = mkdisk.c |
OBJS = $(patsubst %.c,%.o,$(SRCS)) |
BIN = mkdisk |
|
.PHONY: all install clean |
|
all: $(BIN) |
|
install: $(BIN) |
mkdir -p $(BUILD)/simtest |
cp $(BIN) $(BUILD)/simtest |
|
$(BIN): $(OBJS) |
$(CC) $(LDFLAGS) -o $(BIN) $(OBJS) $(LDLIBS) |
|
%.o: %.c |
$(CC) $(CFLAGS) -o $@ -c $< |
|
depend.mak: |
$(CC) -MM -MG $(CFLAGS) $(SRCS) > depend.mak |
|
-include depend.mak |
|
clean: |
rm -f *~ $(OBJS) $(BIN) depend.mak |
/mkmbr/mbr.s
0,0 → 1,49
; |
; mbr.s -- the master boot record |
; |
|
; $8 I/O base address |
; $9 temporary value |
; $10 character |
; $11 pointer to string |
; $29 stack pointer |
; $31 return address |
|
.set tba,0xF0300000 ; terminal base address |
|
start: |
sub $29,$29,4 ; save return register |
stw $31,$29,0 |
add $8,$0,tba ; set I/O base address |
add $11,$0,msg ; pointer to string |
loop: |
ldbu $10,$11,0 ; get char |
beq $10,$0,stop ; null - finished |
jal out ; output char |
add $11,$11,1 ; bump pointer |
j loop ; next char |
stop: |
ldw $31,$29,0 ; restore return register |
add $29,$29,4 |
jr $31 ; return |
|
out: |
ldw $9,$8,8 ; get status |
and $9,$9,1 ; xmtr ready? |
beq $9,$0,out ; no - wait |
stw $10,$8,12 ; send char |
jr $31 ; return |
|
msg: |
.byte 0x0D, 0x0A |
.byte "Error: This is the default MBR, " |
.byte "which cannot load anything." |
.byte 0x0D, 0x0A |
.byte "Please replace the disk, or " |
.byte "write an operating system onto it." |
.byte 0x0D, 0x0A |
.byte 0x0D, 0x0A, 0 |
|
.locate 512-2 |
sign: |
.byte 0x55, 0xAA |
/mkmbr/Makefile
0,0 → 1,27
# |
# Makefile for assembling the master boot record |
# |
|
BUILD = ../../../build |
|
SFILES = $(wildcard *.s) |
OBJFILES = $(patsubst %.s,%.o,$(SFILES)) |
BINFILES = $(patsubst %.s,%.bin,$(SFILES)) |
|
.PHONY: all install clean |
.PRECIOUS: $(OBJFILES) |
|
all: $(BINFILES) |
|
install: $(BINFILES) |
mkdir -p $(BUILD)/simtest |
cp $(BINFILES) $(BUILD)/simtest |
|
%.bin: %.o |
$(BUILD)/bin/ld -h -rc 0xC0000000 -o $@ $< |
|
%.o: %.s |
$(BUILD)/bin/as -o $@ $< |
|
clean: |
rm -f *~ *.bin *.o |
/wrtmbr/Makefile
0,0 → 1,36
# |
# Makefile for a program which writes the master boot record to the disk |
# |
|
BUILD = ../../../build |
|
CC = gcc -m32 |
CFLAGS = -g -Wall |
LDFLAGS = -g |
LDLIBS = -lm |
|
SRCS = wrtmbr.c |
OBJS = $(patsubst %.c,%.o,$(SRCS)) |
BIN = wrtmbr |
|
.PHONY: all install clean |
|
all: $(BIN) |
|
install: $(BIN) |
mkdir -p $(BUILD)/simtest |
cp $(BIN) $(BUILD)/simtest |
|
$(BIN): $(OBJS) |
$(CC) $(LDFLAGS) -o $(BIN) $(OBJS) $(LDLIBS) |
|
%.o: %.c |
$(CC) $(CFLAGS) -o $@ -c $< |
|
depend.mak: |
$(CC) -MM -MG $(CFLAGS) $(SRCS) > depend.mak |
|
-include depend.mak |
|
clean: |
rm -f *~ $(OBJS) $(BIN) depend.mak |
/wrtmbr/wrtmbr.c
0,0 → 1,76
/* |
* wrtmbr.c -- write the master boot record to the disk |
*/ |
|
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdarg.h> |
|
|
#define SECTOR_SIZE 512 |
|
|
void error(char *fmt, ...) { |
va_list ap; |
|
va_start(ap, fmt); |
fprintf(stderr, "Error: "); |
vfprintf(stderr, fmt, ap); |
fprintf(stderr, "\n"); |
va_end(ap); |
exit(1); |
} |
|
|
void usage(char *myself) { |
fprintf(stderr, |
"Usage: %s <disk file> <master boot record file>\n", |
myself); |
exit(1); |
} |
|
|
int main(int argc, char *argv[]) { |
FILE *diskFile; |
FILE *bootFile; |
unsigned char sectorBuffer[SECTOR_SIZE]; |
|
if (argc != 3) { |
usage(argv[0]); |
} |
diskFile = fopen(argv[1], "r+b"); |
if (diskFile == NULL) { |
error("cannot open disk file '%s'", argv[1]); |
} |
bootFile = fopen(argv[2], "rb"); |
if (bootFile == NULL) { |
error("cannot open boot sector file '%s'", argv[2]); |
} |
if (fseek(bootFile, 0, SEEK_END) != 0) { |
error("cannot position to end of boot sector file"); |
} |
if (ftell(bootFile) != SECTOR_SIZE) { |
error("'%s' is not a proper boot sector file (wrong length)", argv[2]); |
} |
if (fseek(bootFile, 0, SEEK_SET) != 0) { |
error("cannot position to start of boot sector file"); |
} |
if (fread(sectorBuffer, SECTOR_SIZE, 1, bootFile) != 1) { |
error("cannot read data from boot sector file"); |
} |
fclose(bootFile); |
if (sectorBuffer[SECTOR_SIZE - 2] != 0x55 || |
sectorBuffer[SECTOR_SIZE - 1] != 0xAA) { |
error("'%s' is not a proper boot sector file (no signature)", argv[2]); |
} |
if (fseek(diskFile, 0, SEEK_SET) != 0) { |
error("cannot position to start of disk file"); |
} |
if (fwrite(sectorBuffer, 1, SECTOR_SIZE, diskFile) != SECTOR_SIZE) { |
error("cannot write boot sector to disk file"); |
} |
fclose(diskFile); |
return 0; |
} |
/Makefile
0,0 → 1,25
# |
# Makefile for building disk tools for simulator tests |
# |
|
BUILD = ../build |
|
DIRS = mkdisk mkmbr wrtmbr |
|
.PHONY: all install clean |
|
all: |
for i in $(DIRS) ; do \ |
$(MAKE) -C $$i all ; \ |
done |
|
install: |
for i in $(DIRS) ; do \ |
$(MAKE) -C $$i install ; \ |
done |
|
clean: |
for i in $(DIRS) ; do \ |
$(MAKE) -C $$i clean ; \ |
done |
rm -f *~ |