Import backup from 2004-03-08

This commit is contained in:
Josh Holtrop 2004-03-08 22:00:00 -05:00
parent 0b9d7fde22
commit 8d0e6de040
45 changed files with 243 additions and 219 deletions

116
Makefile Normal file
View File

@ -0,0 +1,116 @@
#####################################################################
# Author: Benjamen R. Meyer #
# Date: 2004-2-15 #
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
# Note: This makefile is for use on Linux & other Unix-like systems #
#####################################################################
##############
# Variables: #
##############
# Information for creating a floppy image
# Note: FLOPPY_FS and FLOPPY_FAT_SIZE are related fields.
# FLOPPY_FAT_SIZE should be either 12 or 16,
# depending on if FLOPPY_FS is FAT12 or FAT16, respectively.
MKDOSFS_PROG=/sbin/mkdosfs
FLOPPY_IMAGE=floppy.img
FLOPPY_BLOCK_COUNT=1440
FLOPPY_FS=FAT12
FLOPPY_FAT_SIZE=12
FLOPPY_MOUNT=./floppy_image
# Floppy images are good for programs like VMware and Bochs Pentium Emulator. ;-)
# Program for copying
COPY_BIN=cp
##########################################
# Build the IPL (Boot Loader) and Kernel #
##########################################
all:
# A word of warning to users :-> And a little helpful information ;-)
@echo "Installation must be done as root."
@echo "Type 'make install' to install to a floppy in drive '/dev/fd0'"
@echo "Type 'make install_img' to create a floppy image and install to it."
cd boot; make
cd kernel; make
#################################################
# Clean up the source directory of any binaries #
#################################################
clean:
cd boot; make clean
cd kernel; make clean
###########################################
# The following is for the floppy drive #
# Note: This must be done on *nix as root #
###########################################
##########################
# Make install to floppy #
##########################
install: Install_IPL File_Copy
############################################
# Write the Stage 1 IPL to the boot sector #
############################################
Install_IPL:
$(MKDOSFS_PROG) /dev/fd0
dd if=boot/stage1.bin of=/dev/fd0
#################################
# Copy the files onto the drive #
#################################
File_Copy:
mkdir floppy_mount
@echo "Mounting floppy to ./floppy_mount..."
mount /dev/fd0 ./floppy_mount
@echo "Copying stage 2 bootloader to the floppy..."
$(COPY_BIN) boot/stage2.bin ./floppy_mount
@echo "Copying kernel to the floppy..."
$(COPY_BIN) kernel/kernel.bin ./floppy_mount
@echo "Unmounting floppy..."
umount ./floppy_mount
rm -rf floppy_mount
############################################
# The following is for the floppy image. #
# Note: This must be done on *nix as root. #
############################################
######################################
# Create and Format the floppy image #
######################################
install_img: $(FLOPPY_IMAGE)
$(MKDOSFS_PROG) -C -F $(FLOPPY_FAT_SIZE) -r 112 $(FLOPPY_IMAGE) $(FLOPPY_BLOCK_COUNT)
############################################
# Write the Stage 1 IPL to the boot sector #
############################################
@echo "Writing boot sector to image..."
dd if=stage1.bin of=$(FLOPPY_IMAGE) seek=0
@echo "Mounting floppy image..."
mount $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) -o loop
#################################
# Copy the files onto the image #
#################################
@echo "Copying stage 2 bootloader to the floppy image..."
$(COPY_BIN) stage2.bin $(FLOPPY_MOUNT)
@echo "Copying kernel to the floppy image..."
$(COPY_BIN) kernel.bin $(FLOPPY_MOUNT)
@echo "Unmounting floppy image..."
mount $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) -o loop

71
kernel/Makefile Normal file
View File

@ -0,0 +1,71 @@
#####################################################################
# Author: Benjamen R. Meyer #
# Date: 2004-2-15 #
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
# Note: This makefile is for use on Linux & other Unix-like systems #
#####################################################################
##############
# Variables: #
##############
# Format of kernel object files:
# Do not change unless you know what you are doing
KERNEL_FORMAT=aout
# Assembler information:
NASM_BIN=nasm
NASM_FLAGS=-f $(KERNEL_FORMAT)
# C Compile Information:
CC=gcc
CC_FLAGS=-ffreestanding -fno-builtin -nostdlib -nodefaultlibs -I.
# Linker Information:
LD=ld
LD_FLAGS=-nodefaultlibs -nostdlib -T link.ld
###############################
# Linking the kernel together #
###############################
all: Asm_Kernel Asm_Functions C_Kernel
$(LD) $(LD_FLAGS) -o kernel.bin -Map ./lst/LDout.doc ks.o fdc.o functions.o kernel.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.o asmfuncs.o
##########################
# Assembly Kernel Loader #
##########################
Asm_Kernel: kernel.asm
$(NASM_BIN) $(NASM_FLAGS) -o ks.o -l ./lst/kernel.lst kernel.asm
#################################
# Assembly Functions for Kernel #
#################################
Asm_Functions: asmfuncs.asm
$(NASM_BIN) $(NASM_FLAGS) -o asmfuncs.o -l ./lst/asmfuncs.lst asmfuncs.asm
############
# C Kernel #
############
C_Kernel:
$(CC) $(CC_FLAGS) -c kernel.c -o kernel.o
$(CC) $(CC_FLAGS) -c kio.c -o kio.o
$(CC) $(CC_FLAGS) -c functions.c -o functions.o
$(CC) $(CC_FLAGS) -c sys/rtc.c -o rtc.o
$(CC) $(CC_FLAGS) -c sys/pic.c -o pic.o
$(CC) $(CC_FLAGS) -c sys/io.c -o io.o
$(CC) $(CC_FLAGS) -c sys/cmos.c -o cmos.o
$(CC) $(CC_FLAGS) -c string/string.c -o string.o
$(CC) $(CC_FLAGS) -c video/stdfont.c -o stdfont.o
$(CC) $(CC_FLAGS) -c video/video.c -o video.o
$(CC) $(CC_FLAGS) -c block/fdc.c -o fdc.o
$(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o
$(CC) $(CC_FLAGS) -c char/mouse.c -o mouse.o
$(CC) $(CC_FLAGS) -c mm/mm.c -o mm.o
$(CC) $(CC_FLAGS) -c mm/vmm.c -o vmm.o
#################################################
# Clean up the source directory of any binaries #
#################################################
clean:
- rm *.o ./lst/*.lst *.bin

View File

@ -6,6 +6,8 @@
#ifndef __HOS_FDC__
#define __HOS_FDC__ __HOS_FDC__
#include "sys/io.h"
#define FDC_DOR 0x3f2
#define FDC_MSR 0x3f4

View File

@ -3,11 +3,12 @@
//for HOS
//Modified: 02/26/04
#include "hos_defines.h"
#ifndef __HOS_FUNCTIONS__
#define __HOS_FUNCTIONS__ __HOS_FUNCTIONS__
#include "hos_defines.h"
#include "sys/io.h"
extern dword _code;
extern dword _bss;
extern dword _end;

View File

@ -65,7 +65,7 @@ VIDEO_GRAPHICS equ $-gdt
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
dt_end:
gdt_end:

View File

@ -2,7 +2,7 @@
// Author: Josh Holtrop
// Date: 08/13/03
// Holtrop's Operating System - Version 0.13
// Modified: 03/02/04
// Modified: 03/08/04
#include "hos_defines.h" //#DEFINE's for kernel
@ -41,22 +41,20 @@ void k_init()
mouse_init();
pic1_mask(0); //unmask IRQ's 0-7
pic2_mask(0); //unmask IRQ's 8-15
vfs_init();
enable_ints();
kbd_resetLEDs(); //after enabling interrupts!!
if (videoMode)
if (video_Mode())
{
int p = video_mode.XResolution*video_mode.YResolution-1;
int p = video_getWidth()*video_getHeight()-1;
for (; p >= 0; p--)
video_psetp(p, 0x00000077);
video_drawConsole();
}
printf("HOS 0.13 - Kernel File Size: %u kb\tData Size: %u bytes\n", kernel_size()>>10, (dword)(&_end)-(dword)(&_code));
printf("Memory available to OS: %u MB (%u bytes)\n", mm_megabytes, mm_totalmem);
printf("Memory available to OS: %u MB (%u bytes)\n", mm_getTotalMegs(), mm_getTotalMem());
printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12);
printf("%d/%d/%d\t%d:%d:%d\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
printf("Root Directory: %s/\n", rootDevice->id);
dword key = 0;
for (;;)

View File

@ -87,7 +87,7 @@ void putc(dword chr)
}
else
{
if (videoMode)
if (video_Mode())
{
console_memory[cursorPosition] = charac | 0x0700;
video_drawConsoleChar(cursorPosition);
@ -103,10 +103,10 @@ void putc(dword chr)
{
console_scroll();
cursorPosition = 2000-80;
if (videoMode)
if (video_Mode())
video_drawConsole();
}
if (!videoMode)
if (!video_Mode())
writeCursorPosition(cursorPosition);
}

View File

@ -1,7 +1,7 @@
// mm.c
// Author: Josh Holtrop
// Created: 09/01/03
// Modified: 03/02/04
// Modified: 03/08/04
#include "hos_defines.h"
#include "mm.h"
@ -9,7 +9,7 @@
//The total amount of physical memory available (bytes, 1 bit per page)
#define BITMAP_SIZE 0x20000
dword mm_totalmem = 0;
dword mm_megabytes;
dword mm_megabytes = 0;
byte page_bitmap[BITMAP_SIZE]; //used to store a bit for each page that is used, 0 if available
//0x20000*(8 bits/byte)=0x100000 pages in 4gb total
@ -113,8 +113,16 @@ dword mm_freemem()
}
dword mm_getTotalMem()
{
return mm_totalmem;
}
dword mm_getTotalMegs()
{
return mm_megabytes;
}

View File

@ -1,13 +1,12 @@
// mm.c
// Author: Josh Holtrop
// Created: 09/01/03
// Modified: 03/02/04
#include "hos_defines.h"
// Modified: 03/08/04
#ifndef __HOS_MM__
#define __HOS_MM__ __HOS_MM__
#include "hos_defines.h"
typedef struct {
qword base;
@ -21,6 +20,8 @@ void mm_pfreen(dword base, dword pages);
void mm_pfree(dword base);
void *mm_palloc();
dword mm_freemem();
dword mm_getTotalMem();
dword mm_getTotalMegs();
#endif

1
kernel/search.bat Executable file
View File

@ -0,0 +1 @@
grep -R -n -i %1 *

View File

@ -3,11 +3,11 @@
// Created: 02/26/04
// Implements basic port input/output functions
#include "hos_defines.h"
#ifndef __HOS_IO__
#define __HOS_IO__ __HOS_IO__
#include "hos_defines.h"
inline void outportb(unsigned int port, unsigned char value);
inline void outportw(unsigned int port, unsigned int value);
inline unsigned char inportb(unsigned short port);

View File

@ -1,6 +1,6 @@
// video.c
// 08/13/03 Josh Holtrop
// Modified: 03/02/04
// Modified: 03/08/04
#include "hos_defines.h"
#include "video.h"
@ -186,3 +186,18 @@ void video_drawConsoleChar(dword position)
}
int video_getWidth()
{
return video_mode.XResolution;
}
int video_getHeight()
{
return video_mode.YResolution;
}
dword video_Mode()
{
return videoMode;
}

View File

@ -1,12 +1,12 @@
// video.h
// 08/18/03 Josh Holtrop
// Modified: 03/02/04
#include "hos_defines.h"
// Modified: 03/08/04
#ifndef __HOS_VIDEO__
#define __HOS_VIDEO__ __HOS_VIDEO__
#include "hos_defines.h"
void video_init();
void video_horiz(int y, int x1, int x2, dword color);
void video_vert(int x, int y1, int y2, dword color);
@ -21,6 +21,9 @@ void video_psetpnull(int pixel, dword color);
void video_renderChar(int x, int y, int character, dword color);
void video_drawConsole();
void video_drawConsoleChar(dword position);
int video_getWidth();
int video_getHeight();
dword video_Mode();
typedef struct{

View File

@ -7,8 +7,8 @@ It was written by me, Josh Holtrop, with help from a few others along the way.
History
-------------
Change Log
----------
0.14
03/01/04 - Thanks to Ben Meyer for helping me get a Makefile working and building on linux to work!

View File

@ -1,192 +0,0 @@
#####################################################################
# Author: Benjamen R. Meyer #
# Date: 2004-2-15 #
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
# Note: This makefile is for use on Linux & other Unix-like systems #
#####################################################################
##############
# Variables: #
##############
# Format of kernel binary:
# Do not change unless you know what you are doing
# Original:
KERNEL_FORMAT=aout
# CygWin: ??
#KERNEL_FORMAT=
# Assembler information:
NASM_BIN=nasm
NASM_FLAGS_IPL=-f bin
NASM_FLAGS_KERNEL=-f $(KERNEL_FORMAT)
# C Compile Information:
CC=gcc
CC_FLAGS=-ffreestanding -fno-builtin -nostdlib -nodefaultlibs -I.
# Linker Information:
LD=ld
LD_FLAGS=-nodefaultlibs -nostdlib -T link.ld
# Information for creating a floppy image
# Note: FLOPPY_FS and FLOPPY_FAT_SIZE are related fields.
# FLOPPY_FAT_SIZE should be either 12 or 16,
# depending on if FLOPPY_FS is FAT12 or FAT16, respectively.
MKDOSFS_PROG=/sbin/mkdosfs
FLOPPY_IMAGE=floppy.img
FLOPPY_BLOCK_COUNT=1440
FLOPPY_FS=FAT12
FLOPPY_FAT_SIZE=12
FLOPPY_MOUNT=./floppy_image
# Floppy images are good for programs like VMware and Bochs Pentium Emulator. ;-)
# Program for copying
COPY_BIN=cp
##########################################
# Build the IPL (Boot Loader) and Kernel #
##########################################
all: Boot Link_Kernel
# A word of warning to users :-> And a little helpful information ;-)
@echo "Installation must be done as root."
@echo "Type 'make install' to install to a floppy in drive '/dev/fd0'"
@echo "Type 'make install_img' to create a floppy image and install to it."
#################################################
# Clean up the source directory of any binaries #
#################################################
clean:
- rm *.o ./lst/*.lst *.bin $(FLOPPY_IMAGE)
#################
# Build the IPL #
#################
Boot:
boot/make
###############################
# Linking the kernel together #
###############################
Link_Kernel: Asm_Kernel Asm_Functions FAT_12 FDC Functions Keyboard KIO MM Mouse RD STDFONT VFS Video VMM C_Kernel
$(LD) $(LD_FLAGS) -o kernel.bin -Map ./lst/LDout.doc ks.o fat12.o fdc.o functions.o kernel.o keyboard.o kio.o mm.o mouse.o rd.o stdfont.o vfs.o video.o vmm.o asmfuncs.o
##########################
# Assembly Kernel Loader #
##########################
Asm_Kernel: kernel.asm
$(NASM_BIN) $(NASM_FLAGS_KERNEL) -o ks.o -l ./lst/kernel.lst kernel.asm
#################################
# Assembly Functions for Kernel #
#################################
Asm_Functions: asmfuncs.asm
$(NASM_BIN) $(NASM_FLAGS_KERNEL) -o asmfuncs.o -l ./lst/asmfuncs.lst asmfuncs.asm
############
# C Kernel #
############
FAT_12: fat12.c fat12.h k_defines.h vfs.h
$(CC) $(CC_FLAGS) -c fat12.c -o fat12.o
FDC: fdc.c fdc.h k_defines.h
$(CC) $(CC_FLAGS) -c fdc.c -o fdc.o
Functions: functions.c functions.h k_defines.h
$(CC) $(CC_FLAGS) -c functions.c -o functions.o
Keyboard: keyboard.c keyboard.h k_defines.h
$(CC) $(CC_FLAGS) -c keyboard.c -o keyboard.o
KIO: kio.c kio.h k_defines.h video.h
$(CC) $(CC_FLAGS) -c kio.c -o kio.o
MM: mm.c mm.h k_defines.h
$(CC) $(CC_FLAGS) -c mm.c -o mm.o
Mouse: mouse.c mouse.h k_defines.h video.h
$(CC) $(CC_FLAGS) -c mouse.c -o mouse.o
RD: rd.c rd.h k_defines.h vfs.h
$(CC) $(CC_FLAGS) -c rd.c -o rd.o
STDFONT: stdfont.h stdfont.c
$(CC) $(CC_FLAGS) -c stdfont.c -o stdfont.o
VFS: vfs.c vfs.h k_defines.h
$(CC) $(CC_FLAGS) -c vfs.c -o vfs.o
Video: video.c video.h k_defines.h stdfont.h
$(CC) $(CC_FLAGS) -c video.c -o video.o
# Why does this rely on video.h???
VMM: vmm.c vmm.h k_defines.h video.h
$(CC) $(CC_FLAGS) -c vmm.c -o vmm.o
C_Kernel: kernel.c k_defines.h fat12.h fdc.h functions.h keyboard.h kio.h mm.h mouse.h rd.h vfs.h video.h vmm.h
$(CC) $(CC_FLAGS) -c kernel.c -o kernel.o
###########################################
# The following is for the floppy drive #
# Note: This must be done on *nix as root #
###########################################
##########################
# Make install to floppy #
##########################
install: Install_IPL File_Copy
############################################
# Write the Stage 1 IPL to the boot sector #
############################################
Install_IPL:
boot/make install
#################################
# Copy the files onto the drive #
#################################
File_Copy: kernel.bin
@echo -n "Copying kernel to the floppy: "
cp kernel.bin /dev/fd0
############################################
# The following is for the floppy image. #
# Note: This must be done on *nix as root. #
############################################
########################
# Make a floppy image: #
########################
floppy_image: image_IPL image_file_copy
######################################
# Create and Format the floppy image #
######################################
install_img: $(FLOPPY_IMAGE)
$(MKDOSFS_PROG) -C -F $(FLOPPY_FAT_SIZE) -r 112 $(FLOPPY_IMAGE) $(FLOPPY_BLOCK_COUNT)
##########################################
# Mount the floppy on a loop back device #
##########################################
floppy_mount:
@echo "Mounting a file as a drive..."
mount $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) -o loop
############################################
# Write the Stage 1 IPL to the boot sector #
############################################
image_IPL: stage1.bin floppy_format
@echo "Writing boot sector to image..."
dd if=stage1.bin of=$(FLOPPY_MOUNT) seek=0
#################################
# Copy the files onto the image #
#################################
image_file_copy: stage2.bin kernel.bin
@echo -n "Copying files onto it: "
@echo -n "IPL Stage 2 "
$(COPY_BIN) stage2.bin $(FLOPPY_MOUNT)
@echo ", HOS Kernel"
$(COPY_BIN) kernel.bin $(FLOPPY_MOUNT)