diff options
Diffstat (limited to 'CS3871/os')
-rw-r--r-- | CS3871/os/boot.s | 37 | ||||
-rw-r--r-- | CS3871/os/copy.c | 95 | ||||
-rw-r--r-- | CS3871/os/os.s | 159 |
3 files changed, 291 insertions, 0 deletions
diff --git a/CS3871/os/boot.s b/CS3871/os/boot.s new file mode 100644 index 0000000..6dc9464 --- /dev/null +++ b/CS3871/os/boot.s @@ -0,0 +1,37 @@ + bits 16 + org 7c00h + mov si, loading + call print + + mov ax, 7d00h + mov es, ax + mov bx, $0 + + mov dl, 0 + mov dh, 0 + mov ch, 0 + mov cl, 2 + mov al, 1 + mov ah, 2h + + int 13h + mov si, loaded + call print + + jmp 7d00h + + + +loading: db 'Loading OS into RAM...', 10, 13, 0 +loaded: db 'Jumping to OS...', 10, 13, 10, 13, 0 + +print: + mov ah, 0eh +.loop: + lodsb + cmp al, 0 + je .done + int 10h + jmp .loop +.done: + ret diff --git a/CS3871/os/copy.c b/CS3871/os/copy.c new file mode 100644 index 0000000..6e21083 --- /dev/null +++ b/CS3871/os/copy.c @@ -0,0 +1,95 @@ +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> +#include <stdlib.h> + +int main(argc, argv) +int argc; +char ** argv; +{ + int val; + char buf[512], *dev; + int file, floppy; + + if (argc < 3 ) { + perror("usage: copy path_to_bootloader path_to_os [path_to_device]\n"); + exit(1); + } + if (argc >= 4) { + dev = argv[3]; + } else { + dev = "/dev/fd0"; + } + + memset(buf, 0, 512); + + floppy = open(dev, O_RDWR); + if (file < 0) { + perror("Could not open floppy: "); + exit(1); + } + + /****************************** + * Write Bootloader to Floppy * + ******************************/ + + file = open(argv[1], O_RDONLY); + if (file < 0) { + perror("Could not open bootloader: "); + exit(1); + } + + val = read(file, buf, 510); + close(file); + if (val < 0) { + perror("Could not read bootloader: "); + exit(1); + } + + buf[510] = 0x55; + buf[511] = 0xaa; + + lseek(floppy, 0, SEEK_CUR); + + val = write(floppy, buf, 512); + if (val < 0) { + perror("Error writing to floppy: "); + close(floppy); + exit(1); + } + + + /********************** + * Write OS to Floppy * + **********************/ + + file = open(argv[2], O_RDONLY); + if (file < 0) { + perror("Could not open os: "); + exit(1); + } + + val = read(file, buf, 512); + close(file); + if (val < 0) { + perror("Could not read os: "); + exit(1); + } + + val = write(floppy, buf, 512); + if (val < 0) { + perror("Error writing to floppy: "); + close(floppy); + exit(1); + } + + syncfs(floppy); + close(floppy); + + printf("Floppy successfully copied!\n"); + return 0; +} diff --git a/CS3871/os/os.s b/CS3871/os/os.s new file mode 100644 index 0000000..c77c583 --- /dev/null +++ b/CS3871/os/os.s @@ -0,0 +1,159 @@ + mov ax, base + add ax, 120h + mov ss, ax + mov sp, 1000h + + mov ax, data ; Set data segment to safe? area of memory + mov ds, ax + + call clear + + call load_strings + mov si, 0h ;promt + call print + mov di, 30h ;Q + + +start: + mov ah, 0 + int 16h + cmp al, 8 + je back + cmp al, 13 + je deal_nl + call print_char + call save_char + jmp start +deal_nl: + call print_string + mov di, 30h + mov si, 10h ;newline + call print + mov si, 0h ;prompt + call print + jmp start +back: + dec di + call print_char + jmp start + +data: db 00h, 20h +base: db 6h, 66h + +print: + mov ah, 0eh +.loop: + lodsb + cmp al, 0 + je .done + int 10h + jmp .loop +.done: + ret + +print_char: + mov ah, 0eh + int 10h + ret + +save_char: + mov [di], al + inc di + mov al, 0 + mov [di], al + ret + +print_string: + mov si, 10h ;newline + call print + mov si, 20h ;Prog: + call print + mov si, 30h ;Q +ps_loop: + mov al, [si] + cmp al, 0 + je ps_done + cmp al, 32 + je space + call print_char + jmp ps_next +space: + mov di, si + mov si, 10h ;newline + call print + mov si, 27h ;Args: + call print + mov si, di + jmp ps_next +ps_next: + inc si + jmp ps_loop +ps_done: + ret + +clear: + mov ah, 0h + int 10h + ret + +load_strings: + mov di, 0h + mov byte [di], 'F' + inc di + mov byte [di], 'l' + inc di + mov byte [di], 'o' + inc di + mov byte [di], 'p' + inc di + mov byte [di], 'p' + inc di + mov byte [di], 'y' + inc di + mov byte [di], 'O' + inc di + mov byte [di], 'S' + inc di + mov byte [di], '#' + inc di + mov byte [di], 0 + +;NEWLINE + mov di, 10h + mov byte [di], 10 + inc di + mov byte [di], 13 + inc di + mov byte [di], 0 +;PROG: + mov di, 20h + mov byte [di], 'P' + inc di + mov byte [di], 'r' + inc di + mov byte [di], 'o' + inc di + mov byte [di], 'g' + inc di + mov byte [di], ':' + inc di + mov byte [di], ' ' + inc di + mov byte [di], 0 + inc di + +;ARGS + mov byte [di], 'A' + inc di + mov byte [di], 'r' + inc di + mov byte [di], 'g' + inc di + mov byte [di], 's' + inc di + mov byte [di], ':' + inc di + mov byte [di], ' ' + inc di + mov byte [di], 0 +ret |