Import backup from 2004-05-21
This commit is contained in:
1 parent
38f009f2ca
commit
6b6e19effd
42 files changed
+251
-1669
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#####################################################################
|
||||
# Author: Benjamen R. Meyer #
|
||||
# Date: 2004-2-15 #
|
||||
# Author: Josh Holtrop / Benjamen R. Meyer #
|
||||
# Date: 02/15/04 Modified: 05/21/04 #
|
||||
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
|
||||
# Note: This makefile is for use on Linux & other Unix-like systems #
|
||||
#####################################################################
|
||||
@@ -13,7 +13,7 @@
|
||||
# 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
|
||||
MKDOSFS_PROG=mkdosfs
|
||||
FLOPPY_IMAGE=floppy.img
|
||||
FLOPPY_BLOCK_COUNT=1440
|
||||
FLOPPY_FS=FAT12
|
||||
|
||||
-107
@@ -1,107 +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: #
|
||||
##############
|
||||
|
||||
# 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=format
|
||||
FLOPPY_IMAGE=floppy.img
|
||||
FLOPPY_BLOCK_COUNT=1440
|
||||
FLOPPY_FS=FAT12
|
||||
FLOPPY_FAT_SIZE=12
|
||||
|
||||
# Floppy images are good for programs like VMware and Bochs Pentium Emulator. ;-)
|
||||
|
||||
# Program for copying
|
||||
COPY_BIN=copy
|
||||
|
||||
##########################################
|
||||
# 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 -f Makefile.ms
|
||||
|
||||
#################################################
|
||||
# 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) a: /q /v:HOS
|
||||
partcopy stage1.bin 0 200 -f0
|
||||
|
||||
#################################
|
||||
# Copy the files onto the drive #
|
||||
#################################
|
||||
File_Copy:
|
||||
@echo "Copying stage 2 bootloader to the floppy..."
|
||||
$(COPY_BIN) boot/stage2.bin a:\
|
||||
|
||||
@echo "Copying kernel to the floppy..."
|
||||
$(COPY_BIN) kernel/kernel.bin a:\
|
||||
|
||||
|
||||
############################################
|
||||
# The following is for the floppy image. #
|
||||
# Note: This must be done on *nix as root. #
|
||||
############################################
|
||||
|
||||
######################################
|
||||
# Create and Format the floppy image #
|
||||
######################################
|
||||
install_img:
|
||||
$(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
|
||||
|
||||
#################################
|
||||
# Copy the files onto the image #
|
||||
#################################
|
||||
@echo "Mounting floppy image..."
|
||||
mount $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) -o loop
|
||||
|
||||
@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
|
||||
|
||||
|
||||
+6
-4
@@ -1,7 +1,9 @@
|
||||
########################
|
||||
# Author: Josh Holtrop #
|
||||
# Date: 2004-2-15 #
|
||||
########################
|
||||
#####################################################################
|
||||
# Author: Josh Holtrop / Benjamen R. Meyer #
|
||||
# Date: 02/15/04 #
|
||||
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
|
||||
# Note: This makefile is for use on Linux & other Unix-like systems #
|
||||
#####################################################################
|
||||
|
||||
# Assembler information:
|
||||
NASM_BIN=nasm
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
%define VERSION "0.14" ;HOS version
|
||||
%define VERSION "0.03" ;HOS bootloader version
|
||||
|
||||
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector
|
||||
%define BOOT_ROOT_SEG 0x0900 ;right after FAT
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
|
||||
;stage1.asm
|
||||
;This is the stage1 section of the HOS bootloader
|
||||
;It is 512 bytes to be put on the first sector of a floppy
|
||||
;Author: Josh Holtrop
|
||||
;Date: 03/11/04
|
||||
;Modified: 05/21/04
|
||||
|
||||
%include "bootdef.inc"
|
||||
|
||||
[bits 16]
|
||||
|
||||
+8
-1
@@ -1,4 +1,11 @@
|
||||
|
||||
;stage2.asm
|
||||
;This is the stage2 section of the HOS bootloader
|
||||
;It is to be copied into the normal FAT12 filesystem to be loaded by stage1
|
||||
;Author: Josh Holtrop
|
||||
;Date: 03/11/04
|
||||
;Modified: 05/21/04
|
||||
|
||||
%include "bootdef.inc"
|
||||
|
||||
%define VESA_MODEINFO_SEG 0x0120
|
||||
@@ -851,7 +858,7 @@ puthex2_goon2:
|
||||
ret
|
||||
|
||||
;------------------------------------------------------
|
||||
txt_welcome: db " Welcome to HOS v", VERSION, "! ", 0
|
||||
txt_welcome: db " HOS bootloader v", VERSION, "! ", 0
|
||||
txt_rd1: db "1. Do not load an initial ram disk", 0
|
||||
txt_rd2: db "2. Load initial ram disk from boot media", 0
|
||||
txt_input: db "Enter your selection: ", 0
|
||||
|
||||
+20
-20
@@ -1,6 +1,6 @@
|
||||
#####################################################################
|
||||
# Author: Benjamen R. Meyer #
|
||||
# Date: 2004-2-15 #
|
||||
# Author: Josh Holtrop / Benjamen R. Meyer #
|
||||
# Date: 02/15/04 Modified: 05/21/04 #
|
||||
# Purpose: To build Josh Holtrop's OS (HOS) using GNU make #
|
||||
# Note: This makefile is for use on Linux & other Unix-like systems #
|
||||
#####################################################################
|
||||
@@ -18,8 +18,8 @@ NASM_BIN=nasm
|
||||
NASM_FLAGS=-f $(KERNEL_FORMAT)
|
||||
|
||||
# C Compile Information:
|
||||
CC=gcc
|
||||
CC_FLAGS=-ffreestanding -fleading-underscore -fno-builtin -nostdlib -nodefaultlibs -I. -Wall
|
||||
CPP=g++
|
||||
CPP_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostdinc++ -nostartfiles -fno-rtti -fno-exceptions -nodefaultlibs -I. -Wall
|
||||
|
||||
# Linker Information:
|
||||
LD=ld
|
||||
@@ -30,7 +30,7 @@ LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -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 kernel.o asmfuncs.o fdc.o functions.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.o rtc.o pic.o io.o string.o cmos.o
|
||||
$(LD) $(LD_FLAGS) -o kernel.bin -Map ./lst/LDout.doc ks.o kernel.o asmfuncs.o fdc.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.o rtc.o pic.o io.o string.o cmos.o hos_defines.o
|
||||
|
||||
##########################
|
||||
# Assembly Kernel Loader #
|
||||
@@ -48,21 +48,21 @@ Asm_Functions: 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
|
||||
$(CPP) $(CPP_FLAGS) -c kernel.cpp -o kernel.o
|
||||
$(CPP) $(CPP_FLAGS) -c kio.cpp -o kio.o
|
||||
$(CPP) $(CPP_FLAGS) -c sys/rtc.cpp -o rtc.o
|
||||
$(CPP) $(CPP_FLAGS) -c sys/pic.cpp -o pic.o
|
||||
$(CPP) $(CPP_FLAGS) -c sys/io.cpp -o io.o
|
||||
$(CPP) $(CPP_FLAGS) -c sys/cmos.cpp -o cmos.o
|
||||
$(CPP) $(CPP_FLAGS) -c string/string.cpp -o string.o
|
||||
$(CPP) $(CPP_FLAGS) -c video/stdfont.cpp -o stdfont.o
|
||||
$(CPP) $(CPP_FLAGS) -c video/video.cpp -o video.o
|
||||
$(CPP) $(CPP_FLAGS) -c block/fdc.cpp -o fdc.o
|
||||
$(CPP) $(CPP_FLAGS) -c char/keyboard.cpp -o keyboard.o
|
||||
$(CPP) $(CPP_FLAGS) -c char/mouse.cpp -o mouse.o
|
||||
$(CPP) $(CPP_FLAGS) -c mm/mm.cpp -o mm.o
|
||||
$(CPP) $(CPP_FLAGS) -c mm/vmm.cpp -o vmm.o
|
||||
$(CPP) $(CPP_FLAGS) -c hos_defines.cpp -o hos_defines.o
|
||||
|
||||
#################################################
|
||||
# Clean up the source directory of any binaries #
|
||||
|
||||
+23
-18
@@ -1,30 +1,35 @@
|
||||
// asmfuncs.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Modified: 05/21/04
|
||||
|
||||
#ifndef __HOS_ASMFUNCS__
|
||||
#define __HOS_ASMFUNCS__ __HOS_ASMFUNCS__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
dword write_cr0(dword cr0);
|
||||
dword read_cr0();
|
||||
dword write_cr3(dword cr3);
|
||||
dword read_cr2();
|
||||
dword read_cr3();
|
||||
void writeCursorPosition(dword pos);
|
||||
dword getCursorPosition();
|
||||
int puts(char *str);
|
||||
int putDec(int number);
|
||||
int putDecu(dword number);
|
||||
void strcpy(char *dest, char *src);
|
||||
void memcpy(void *dest, void *src, dword n);
|
||||
void memcpyd(void *dest, void *src, dword n);
|
||||
void *memset(void *buffer, int c, int num);
|
||||
void *memsetw(void *buffer, int c, int num);
|
||||
void *memsetd(void *buffer, int c, int num);
|
||||
dword strlen(char *str);
|
||||
void invlpg_(dword addr);
|
||||
extern "C" {
|
||||
|
||||
dword write_cr0(dword cr0);
|
||||
dword read_cr0();
|
||||
dword write_cr3(dword cr3);
|
||||
dword read_cr2();
|
||||
dword read_cr3();
|
||||
void writeCursorPosition(dword pos);
|
||||
dword getCursorPosition();
|
||||
int puts(char *str);
|
||||
int putDec(int number);
|
||||
int putDecu(dword number);
|
||||
void strcpy(char *dest, char *src);
|
||||
void memcpy(void *dest, void *src, dword n);
|
||||
void memcpyd(void *dest, void *src, dword n);
|
||||
void *memset(void *buffer, int c, int num);
|
||||
void *memsetw(void *buffer, int c, int num);
|
||||
void *memsetd(void *buffer, int c, int num);
|
||||
dword strlen(char *str);
|
||||
void invlpg_(dword addr);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -26,8 +26,8 @@ byte ackReason = 0; //used to record the reason why we would get an acknowledge
|
||||
|
||||
//these arrays convert a keyboard scan code to an ASCII character value
|
||||
//nul esc bksp tab lctl lsft rsft lalt caps F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 numScrlNumPad------- unknown---- F11 F12 unknown....
|
||||
const byte SCAN2ASCII[128] = "\000\0331234567890-=\010\011qwertyuiop[]\n\001asdfghjkl;'`\001\\zxcvbnm,./\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001-\001\001\001+\001\001\001\001\001\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
|
||||
const byte SCAN2ASCIISHIFT[128] = "\000\033!@#$%^&*()_+\010\011QWERTYUIOP{}\n\001ASDFGHJKL:\"~\001|ZXCVBNM<>?\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001789-456+1230.\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
|
||||
const byte SCAN2ASCII[129] = "\000\0331234567890-=\010\011qwertyuiop[]\n\001asdfghjkl;'`\001\\zxcvbnm,./\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001-\001\001\001+\001\001\001\001\001\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
|
||||
const byte SCAN2ASCIISHIFT[129] = "\000\033!@#$%^&*()_+\010\011QWERTYUIOP{}\n\001ASDFGHJKL:\"~\001|ZXCVBNM<>?\001*\001 \001\001\001\001\001\001\001\001\001\001\001\001\001789-456+1230.\002\002\002\001\001\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002";
|
||||
|
||||
//====FUNCTIONS:
|
||||
// The Keyboard Interrupt Service Routine
|
||||
@@ -1,6 +1,7 @@
|
||||
// mouse.c
|
||||
// 10/03/03
|
||||
// Author: Josh Holtrop
|
||||
// Date: 10/03/03
|
||||
// Modified: 05/21/04
|
||||
|
||||
#include "mouse.h"
|
||||
#include "hos_defines.h"
|
||||
@@ -11,7 +12,7 @@
|
||||
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
int mouse_bytesRead = 0;
|
||||
int mouse_bytesRead;
|
||||
byte mouse_inbuffer[MOUSE_BUFFER_LENGTH];
|
||||
|
||||
//This method initializes the ps/2 mouse
|
||||
@@ -29,6 +30,8 @@ void mouse_init()
|
||||
|
||||
mouse_x = video_getWidth() >> 1;
|
||||
mouse_y = video_getHeight() >> 1;
|
||||
|
||||
mouse_bytesRead = 0;
|
||||
|
||||
//outportb(0x64, 0xD4);
|
||||
//outportb(0x60, 0xE7); //scaling 2:1
|
||||
@@ -59,7 +62,7 @@ void isr_mouse()
|
||||
if (mouse_y >= video_getHeight())
|
||||
mouse_y = video_getHeight() - 1;
|
||||
if (mouse_inbuffer[0] & 0x01) //left button
|
||||
video_pset(mouse_x, mouse_y, 0x00FF8800);
|
||||
video_pset(mouse_x, mouse_y, 0x00FF9900);
|
||||
else
|
||||
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
|
||||
}
|
||||
File renamed without changes.
@@ -128,7 +128,6 @@ FILE *vfat_open(char *fileName, dword attributes, Volume *vol);
|
||||
vfat_bpb *vfat_getBootSector(Volume *vol);
|
||||
int vfat_close(FILE *fp);
|
||||
byte *vfat_loadFAT(Volume *vol, vfat_bpb *bpb)
|
||||
vfat_getEntryInRoot(vol, bpb, fileName, 0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
Volume *firstVolume = 0;
|
||||
Volume *rootVolume = 0;
|
||||
MountPoint *firstMountPoint = 0;
|
||||
|
||||
void vfs_init()
|
||||
{
|
||||
@@ -30,6 +30,13 @@ typedef struct
|
||||
Volume *vol; //what volume this file is on
|
||||
} FILE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *device;
|
||||
char *mount;
|
||||
void *mp;
|
||||
} MountPoint;
|
||||
|
||||
#define FILE_READ 1
|
||||
#define FILE_WRITE 2
|
||||
#define FILE_READ_WRITE 3
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
//Functions.c
|
||||
//05/07/03 Josh Holtrop
|
||||
//for HOS
|
||||
//Modified: 02/26/04
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
+13
-18
@@ -13,17 +13,6 @@ extern dword _code;
|
||||
extern dword _bss;
|
||||
extern dword _end;
|
||||
|
||||
/*
|
||||
inline void enable_ints();
|
||||
inline void disable_ints();
|
||||
inline void restart();
|
||||
inline void halt();
|
||||
inline dword kernel_size();
|
||||
inline void timer_init();
|
||||
inline byte bcd2byte(byte bcd);
|
||||
inline byte byte2bcd(byte bite);
|
||||
*/
|
||||
|
||||
//Enables (SeTs) Interrupt Flag on the processor
|
||||
static inline void enable_ints()
|
||||
{
|
||||
@@ -50,9 +39,7 @@ static inline void restart()
|
||||
|
||||
|
||||
outportb (0x64, 0xfe);
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
for (;;) {}
|
||||
}
|
||||
|
||||
//Halts (freezes) the computer
|
||||
@@ -60,8 +47,7 @@ static inline void halt()
|
||||
{
|
||||
asm("cli");
|
||||
asm("hlt");
|
||||
while (1)
|
||||
;
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Initializes 8253 Programmable Interrupt Timer
|
||||
@@ -73,19 +59,28 @@ static inline void timer_init()
|
||||
outportb(0x40, 0x2e); //msb
|
||||
}
|
||||
|
||||
//Returns the size of the kernel (code & data)
|
||||
// - this does include the bss section
|
||||
// - this should be 4kb aligned per the linker script
|
||||
// - this is the amount of RAM the kernel code, data, & bss take
|
||||
static inline dword kernel_size_used()
|
||||
{
|
||||
return (dword)(&_end)-(dword)(&_code);
|
||||
}
|
||||
|
||||
//Returns the size of the kernel (code & data)
|
||||
// - this does not include the bss section
|
||||
// - this should be 4kb aligned per the linker script
|
||||
// - this should be the size of kernel.bin
|
||||
static inline dword kernel_size()
|
||||
{
|
||||
return (dword)(&_end)-(dword)(&_code);
|
||||
return (dword)(&_bss)-(dword)(&_code);
|
||||
}
|
||||
|
||||
//converts a binary-coded-decimal byte to its decimal equivalent
|
||||
static inline byte bcd2byte(byte bcd)
|
||||
{
|
||||
return (10* ((bcd & 0xF0) >> 4)) + (bcd & 0x0F);
|
||||
return (10 * ((bcd & 0xF0) >> 4)) + (bcd & 0x0F);
|
||||
}
|
||||
|
||||
//converts a binary-coded-decimal byte to its decimal equivalent
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "mm/vmm.h"
|
||||
|
||||
//overload the operator "new"
|
||||
void * operator new (dword size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
//overload the operator "new[]"
|
||||
void * operator new[] (dword size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
//overload the operator "delete"
|
||||
void operator delete (void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
//overload the operator "delete[]"
|
||||
void operator delete[] (void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,18 @@ typedef struct {
|
||||
dword highdword;
|
||||
} __attribute__((packed)) qword;
|
||||
|
||||
//overload the operator "new"
|
||||
void * operator new (dword size);
|
||||
|
||||
//overload the operator "new[]"
|
||||
void * operator new[] (dword size);
|
||||
|
||||
//overload the operator "delete"
|
||||
void operator delete (void *p);
|
||||
|
||||
//overload the operator "delete[]"
|
||||
void operator delete[] (void *p);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "video/stdfont.h" //Standard font bitmask array
|
||||
#include "video/video.h" //video functions
|
||||
|
||||
extern "C" {
|
||||
|
||||
void isr(dword num);
|
||||
void k_init();
|
||||
|
||||
@@ -60,11 +62,12 @@ void k_init()
|
||||
kio_drawConsole();
|
||||
}
|
||||
|
||||
printf("HOS 0.14 - Kernel File Size: %u kb\n", kernel_size()>>10);
|
||||
printf("HOS 0.14 - Kernel File Size: %uKb Mem Used: %uKb\n", kernel_size()>>10, kernel_size_used()>>10);
|
||||
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("%b/%b/%b\t%b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
|
||||
|
||||
printf("Built on %s at %s\n", __DATE__, __TIME__);
|
||||
printf("%b/%b/%b %b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
|
||||
|
||||
dword key = 0;
|
||||
for (;;)
|
||||
{
|
||||
@@ -86,6 +89,13 @@ void isr(dword num)
|
||||
case 0x20: // IRQ0 - timer interrupt
|
||||
timer++;
|
||||
(*(byte *)(0xc00b8000))++;
|
||||
if (!(timer % 100))
|
||||
{
|
||||
dword curPos = kio_getCursorPosition();
|
||||
kio_writeCursorPosition(72);
|
||||
printf("%b:%b:%b\n", rtc_readHour(), rtc_readMinute(), rtc_readSecond());
|
||||
kio_writeCursorPosition(curPos);
|
||||
}
|
||||
pic_eoi();
|
||||
break;
|
||||
case 0x21: // IRQ1 - keyboard interrupt
|
||||
@@ -102,7 +112,7 @@ void isr(dword num)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// kio.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 12/25/03
|
||||
// Modified: 03/09/04
|
||||
// Modified: 04/06/04
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "kio.h"
|
||||
@@ -13,6 +13,7 @@ word console_memory[2000]; //holds a copy of the console's memory
|
||||
|
||||
// This is the main output routine, it uses a format string and a variable
|
||||
// number of arguments to print formatted text
|
||||
extern "C" {
|
||||
void printf(char *fmt, ...)
|
||||
{
|
||||
dword *params = ((dword *)(&fmt)) + 1; //points to the first paramater
|
||||
@@ -38,7 +39,7 @@ void printf(char *fmt, ...)
|
||||
putc(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'd': case 'D':
|
||||
case 'd': case 'D': case 'i': case 'I':
|
||||
putDec(*params);
|
||||
params++;
|
||||
break;
|
||||
@@ -186,7 +187,7 @@ void kio_drawConsole()
|
||||
{
|
||||
for (y = 0; y < 25; y++)
|
||||
{
|
||||
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x00FFFFFF);
|
||||
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x00FFFFFF, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,9 +198,19 @@ void kio_drawConsoleChar(dword position)
|
||||
{
|
||||
int x = position % 80;
|
||||
int y = position / 80;
|
||||
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x00FFFFFF);
|
||||
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x00FFFFFF, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
dword kio_getCursorPosition()
|
||||
{
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
void kio_writeCursorPosition(dword position)
|
||||
{
|
||||
cursorPosition = position;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+15
-9
@@ -1,21 +1,27 @@
|
||||
// kio.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 12/25/03
|
||||
// Modified: 03/09/04
|
||||
// Modified: 05/21/04
|
||||
|
||||
#ifndef __HOS_KIO__
|
||||
#define __HOS_KIO__ __HOS_KIO__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
void printf(char *fmt, ...);
|
||||
void putc(dword chr);
|
||||
void putHex(dword number);
|
||||
void kio_drawConsole();
|
||||
void kio_drawConsoleChar(dword position);
|
||||
void kio_console_scroll();
|
||||
void kio_console_cls();
|
||||
void kio_putBCD(dword bcd);
|
||||
extern "C" {
|
||||
|
||||
void printf(char *fmt, ...);
|
||||
void putc(dword chr);
|
||||
void putHex(dword number);
|
||||
void kio_drawConsole();
|
||||
void kio_drawConsoleChar(dword position);
|
||||
void kio_console_scroll();
|
||||
void kio_console_cls();
|
||||
void kio_putBCD(dword bcd);
|
||||
dword kio_getCursorPosition();
|
||||
void kio_writeCursorPosition(dword position);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+6
-2
@@ -12,8 +12,12 @@ SECTIONS
|
||||
*(.data)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.bss :
|
||||
{
|
||||
.rodata : {
|
||||
rodata = .; _rodata = .; __rodata = .;
|
||||
*(.rodata)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
.bss : {
|
||||
bss = .; _bss = .; __bss = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4096);
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -37,7 +37,7 @@ void video_init()
|
||||
}
|
||||
|
||||
//Renders a character using stdfont[] as a bitmask
|
||||
void video_renderChar(int x, int y, int character, int font, dword color)
|
||||
void video_renderChar(int x, int y, int character, int font, dword color, int drawBack, dword backColor)
|
||||
{
|
||||
int charWidth = stdfont_getFontWidth(font);
|
||||
if (!charWidth)
|
||||
@@ -53,6 +53,8 @@ void video_renderChar(int x, int y, int character, int font, dword color)
|
||||
{
|
||||
if ((charBMP[charpos + row] << col) & 0x80)
|
||||
video_pset(x + col, y + row, color);
|
||||
else if (drawBack)
|
||||
video_pset(x + col, y + row, backColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ void video_psetp16(int pixel, dword color);
|
||||
void video_psetp24(int pixel, dword color);
|
||||
void video_psetp32(int pixel, dword color);
|
||||
void video_psetpnull(int pixel, dword color);
|
||||
void video_renderChar(int x, int y, int character, int font, dword color);
|
||||
void video_renderChar(int x, int y, int character, int font, dword color, int drawBack, dword backColor);
|
||||
int video_getWidth();
|
||||
int video_getHeight();
|
||||
byte video_getBitsPerPixel();
|
||||
|
||||
@@ -1,510 +0,0 @@
|
||||
; asmfuncs.asm
|
||||
; Josh Holtrop
|
||||
; Created: 10/23/03
|
||||
; Modified: 02/26/04
|
||||
|
||||
[extern putc]
|
||||
[extern console_memory]
|
||||
[extern cursorPosition]
|
||||
[extern video_drawConsole]
|
||||
[extern videoMode]
|
||||
|
||||
%macro jzfar 1
|
||||
jnz %%skip
|
||||
jmp %1
|
||||
%%skip:
|
||||
|
||||
%endmacro
|
||||
|
||||
;stores the parameter to the CR0 register
|
||||
;extern dword write_cr0(dword cr0);
|
||||
[global write_cr0]
|
||||
write_cr0:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr0, eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;returns the value in the CR0 register
|
||||
;extern dword read_cr0();
|
||||
[global read_cr0]
|
||||
read_cr0:
|
||||
mov eax, cr0;
|
||||
ret
|
||||
|
||||
;stores the parameter to the CR3 register
|
||||
;extern dword write_cr3(dword cr3);
|
||||
[global write_cr3]
|
||||
write_cr3:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr3, eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;returns the value in the CR2 register
|
||||
;extern dword read_cr2();
|
||||
[global read_cr2]
|
||||
read_cr2:
|
||||
mov eax, cr2;
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;returns the value in the CR3 register
|
||||
;extern dword read_cr3();
|
||||
[global read_cr3]
|
||||
read_cr3:
|
||||
mov eax, cr3;
|
||||
ret
|
||||
|
||||
|
||||
;compares one string to another
|
||||
;returns 0 if the strings are different
|
||||
;extern dword strcmp(char *str1, char *str2);
|
||||
[global strcmp]
|
||||
strcmp:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
|
||||
mov esi, [ebp+8]
|
||||
mov edi, [ebp+12]
|
||||
strcmp_loop1:
|
||||
lodsb
|
||||
mov ah, [edi]
|
||||
inc edi
|
||||
cmp ah, al
|
||||
jnz strcmp_ne
|
||||
or al, al
|
||||
jz strcmp_e
|
||||
jmp strcmp_loop1
|
||||
strcmp_e:
|
||||
mov eax, 1
|
||||
jmp short strcmp_done
|
||||
strcmp_ne:
|
||||
xor eax, eax
|
||||
strcmp_done:
|
||||
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;copies a string from the source to the destination parameter
|
||||
;extern void strcpy(char *dest, char *src);
|
||||
[global strcpy]
|
||||
strcpy:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
strcpyloop:
|
||||
lodsb
|
||||
stosb
|
||||
or al, al
|
||||
jnz strcpyloop
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;copies memory of n bytes from src to destination
|
||||
;void memcpy(void *dest, void *src, dword n);
|
||||
[global memcpy]
|
||||
memcpy:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
cld
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;copies memory of n dwords (n*4 bytes) from src to destination
|
||||
;void memcpyd(void *dest, void *src, dword n);
|
||||
[global memcpyd]
|
||||
memcpyd:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
cld
|
||||
rep movsd
|
||||
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num bytes at buffer to the value of c
|
||||
;void *memset(void *buffer, int c, int num);
|
||||
[global memset]
|
||||
memset:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosb
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num words at buffer to the value of c
|
||||
;void *memsetw(void *buffer, int c, int num);
|
||||
[global memsetw]
|
||||
memsetw:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosw
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num dwords at buffer to the value of c
|
||||
;void *memsetd(void *buffer, int c, int num);
|
||||
[global memsetd]
|
||||
memsetd:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosd
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;returns the number of characters in a string
|
||||
;extern dword strlen(char *str);
|
||||
[global strlen]
|
||||
strlen:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push ebx
|
||||
mov esi, [ebp+8]
|
||||
xor ebx, ebx
|
||||
strlenloop:
|
||||
lodsb
|
||||
or al, al
|
||||
jz strlendone
|
||||
inc ebx
|
||||
jmp strlenloop
|
||||
strlendone:
|
||||
mov eax, ebx
|
||||
pop ebx
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;this function invalidates the page directory/table entry that
|
||||
; would be used to access the memory address given in the parameter
|
||||
;extern void invlpg_(dword addr);
|
||||
[global invlpg_]
|
||||
invlpg_:
|
||||
mov eax, [esp+4]
|
||||
invlpg [eax]
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;void writeCursorPosition(word pos)
|
||||
;
|
||||
[global writeCursorPosition]
|
||||
writeCursorPosition:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
push eax
|
||||
push ebx
|
||||
push edx
|
||||
|
||||
mov eax, [ebp+8] ;cursor position in ax
|
||||
|
||||
mov bl, al
|
||||
mov dx, 0x03D4
|
||||
mov al, 0x0E
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
mov al, ah
|
||||
out dx, al
|
||||
|
||||
dec dx
|
||||
mov al, 0x0F
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
mov al, bl
|
||||
out dx, al
|
||||
|
||||
pop edx
|
||||
pop ebx
|
||||
pop eax
|
||||
pop ebp
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;word getCursorPosition()
|
||||
;
|
||||
[global getCursorPosition]
|
||||
getCursorPosition:
|
||||
push ebx
|
||||
push edx
|
||||
|
||||
xor eax, eax
|
||||
mov dx, 0x03D4
|
||||
mov al, 0x0E
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
in al, dx
|
||||
mov bl, al
|
||||
|
||||
dec dx
|
||||
mov al, 0x0F
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
in al, dx
|
||||
mov ah, bl
|
||||
|
||||
pop edx
|
||||
pop ebx
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;int puts(char *str)
|
||||
;
|
||||
[global puts]
|
||||
puts:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push eax
|
||||
mov esi, [ebp+8] ;esi = to string
|
||||
puts_loop:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
jz puts_done
|
||||
push eax
|
||||
call putc
|
||||
add esp, 4
|
||||
jmp puts_loop
|
||||
|
||||
puts_done:
|
||||
pop eax
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
[global putDecu]
|
||||
putDecu:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 24
|
||||
mov DWORD [ebp-4], 1
|
||||
mov BYTE [ebp-5], 0
|
||||
L2:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
cmp eax, DWORD [ebp-4]
|
||||
jae L4
|
||||
jmp L3
|
||||
L4:
|
||||
mov eax, DWORD [ebp-4]
|
||||
mov edx, eax
|
||||
sal edx, 2
|
||||
add edx, eax
|
||||
lea eax, [edx+edx]
|
||||
mov DWORD [ebp-4], eax
|
||||
jmp L2
|
||||
L3:
|
||||
nop
|
||||
L5:
|
||||
cmp DWORD [ebp-4], 1
|
||||
ja L7
|
||||
jmp L6
|
||||
L7:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, edx
|
||||
mov edx, 0
|
||||
div DWORD [ebp-4]
|
||||
mov DWORD [ebp-12], eax
|
||||
mov al, BYTE [ebp-12]
|
||||
mov BYTE [ebp-5], al
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
imul eax, DWORD [ebp-4]
|
||||
sub DWORD [ebp+8], eax
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
lea eax, [ebp-5]
|
||||
add BYTE [eax], 48
|
||||
sub esp, 12
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
push eax
|
||||
call putc
|
||||
add esp, 16
|
||||
jmp L5
|
||||
L6:
|
||||
sub esp, 12
|
||||
mov al, BYTE [ebp+8]
|
||||
add eax, 48
|
||||
and eax, 255
|
||||
push eax
|
||||
call putc
|
||||
add esp, 16
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
[global putDec]
|
||||
putDec:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 24
|
||||
cmp DWORD [ebp+8], 0
|
||||
jns L9
|
||||
sub esp, 12
|
||||
push 45
|
||||
call putc
|
||||
add esp, 16
|
||||
neg DWORD [ebp+8]
|
||||
L9:
|
||||
mov DWORD [ebp-4], 1
|
||||
mov BYTE [ebp-5], 0
|
||||
L10:
|
||||
mov eax, DWORD [ebp+8]
|
||||
cmp eax, DWORD [ebp-4]
|
||||
jae L12
|
||||
jmp L11
|
||||
L12:
|
||||
mov eax, DWORD [ebp-4]
|
||||
mov edx, eax
|
||||
sal edx, 2
|
||||
add edx, eax
|
||||
lea eax, [edx+edx]
|
||||
mov DWORD [ebp-4], eax
|
||||
jmp L10
|
||||
L11:
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
L13:
|
||||
cmp DWORD [ebp-4], 1
|
||||
ja L15
|
||||
jmp L14
|
||||
L15:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, edx
|
||||
mov edx, 0
|
||||
div DWORD [ebp-4]
|
||||
mov DWORD [ebp-12], eax
|
||||
mov al, BYTE [ebp-12]
|
||||
mov BYTE [ebp-5], al
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
imul eax, DWORD [ebp-4]
|
||||
sub DWORD [ebp+8], eax
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
lea eax, [ebp-5]
|
||||
add BYTE [eax], 48
|
||||
sub esp, 12
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
push eax
|
||||
call putc
|
||||
add esp, 16
|
||||
jmp L13
|
||||
L14:
|
||||
sub esp, 12
|
||||
mov al, BYTE [ebp+8]
|
||||
add eax, 48
|
||||
and eax, 255
|
||||
push eax
|
||||
call putc
|
||||
add esp, 16
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
;idt.inc
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 03/02/04
|
||||
|
||||
idtr:
|
||||
dw 50*8-1 ;size of idt
|
||||
dd IDT_V ;address of idt
|
||||
|
||||
|
||||
%macro isr_label 1
|
||||
isr_%1:
|
||||
push eax
|
||||
mov eax, %1
|
||||
jmp isr_main
|
||||
%endmacro
|
||||
|
||||
isr_label 0
|
||||
isr_label 1
|
||||
isr_label 2
|
||||
isr_label 3
|
||||
isr_label 4
|
||||
isr_label 5
|
||||
isr_label 6
|
||||
isr_label 7
|
||||
isr_label 8
|
||||
isr_label 9
|
||||
isr_label 10
|
||||
isr_label 11
|
||||
isr_label 12
|
||||
isr_label 13
|
||||
isr_label 14
|
||||
isr_label 15
|
||||
isr_label 16
|
||||
isr_label 17
|
||||
isr_label 18
|
||||
isr_label 19
|
||||
isr_label 20
|
||||
isr_label 21
|
||||
isr_label 22
|
||||
isr_label 23
|
||||
isr_label 24
|
||||
isr_label 25
|
||||
isr_label 26
|
||||
isr_label 27
|
||||
isr_label 28
|
||||
isr_label 29
|
||||
isr_label 30
|
||||
isr_label 31
|
||||
isr_label 32
|
||||
isr_label 33
|
||||
isr_label 34
|
||||
isr_label 35
|
||||
isr_label 36
|
||||
isr_label 37
|
||||
isr_label 38
|
||||
isr_label 39
|
||||
isr_label 40
|
||||
isr_label 41
|
||||
isr_label 42
|
||||
isr_label 43
|
||||
isr_label 44
|
||||
isr_label 45
|
||||
isr_label 46
|
||||
isr_label 47
|
||||
isr_label 48
|
||||
isr_label 49
|
||||
|
||||
isr_main:
|
||||
cmp eax, 0x30
|
||||
jz isr_syscall
|
||||
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
push eax
|
||||
|
||||
call isr
|
||||
|
||||
add esp, 4
|
||||
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
pop eax
|
||||
|
||||
iret
|
||||
|
||||
|
||||
isr_syscall:
|
||||
pop eax ;syscall function number
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
sc1:
|
||||
cmp eax, 1 ;syscall 1 - putc
|
||||
jnz sc2
|
||||
push ebx
|
||||
call putc
|
||||
add esp, 4
|
||||
jmp scdone
|
||||
sc2:
|
||||
|
||||
scdone:
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
iret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
;kernel.asm
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 10/30/03
|
||||
|
||||
%define GDT_P 0x100000; ;1mb physical - Global Descriptor Table space
|
||||
%define GDT_V GDT_P+0xC0000000
|
||||
%define IDT_P 0x102000 ;1mb+8kb - Interrupt Descriptor Table space
|
||||
%define IDT_V IDT_P+0xC0000000
|
||||
%define PDBR_P 0x104000 ;1mb+16kb - Page Directory Base Register (first PD)
|
||||
%define PDBR_V PDBR_P+0xC0000000
|
||||
%define LOPT_P 0x105000 ;1mb+20kb - LOw Page Table for mapping first 4mb
|
||||
%define LOPT_V LOPT_P+0xC0000000
|
||||
%define KERNEL_P 0x106000 ;1mb+24kb - the kernel's physical address
|
||||
%define KERNEL_V KERNEL_P+0xC0000000 ;3gb+1mb+24kb, the virtual address of the kernel
|
||||
|
||||
[global start]
|
||||
[extern isr]
|
||||
[extern k_init]
|
||||
[extern putc]
|
||||
|
||||
bits 32
|
||||
|
||||
;This is where the kernel begins execution
|
||||
;At this point, the temporary gdt is set up to "map" 0xC000_0000 to 0x0.
|
||||
;We must enable paging with the first 4mb mapped 1:1 virtual:physical
|
||||
; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical.
|
||||
;Then we can start using our "real" gdt, then unmap the lower 4mb.
|
||||
start:
|
||||
cli ;if they weren't already off
|
||||
|
||||
xor eax, eax
|
||||
mov edi, PDBR_V
|
||||
mov ecx, 1024 ;clear the PDBR
|
||||
rep stosd
|
||||
mov [PDBR_V], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table (read/write, present)
|
||||
mov [PDBR_V+0xC00], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table (read/write, present)
|
||||
|
||||
mov edi, LOPT_V
|
||||
mov ecx, 1024
|
||||
mov eax, 0x03 ;starting physical address = 0x0 (read/write, present flags)
|
||||
fill_lopt_loop: ;fill the page table
|
||||
stosd
|
||||
add eax, 4096 ;increment next phsyical address by 4kb
|
||||
loop fill_lopt_loop
|
||||
|
||||
mov eax, PDBR_P
|
||||
mov cr3, eax ;store the Page Directory Base Address
|
||||
mov eax, cr0
|
||||
or eax, 0x80000000 ;set page enable bit
|
||||
mov cr0, eax ;now paging is active!
|
||||
|
||||
|
||||
mov edi, GDT_V
|
||||
mov esi, gdt
|
||||
mov ecx, gdt_end-gdt
|
||||
copy_gdt:
|
||||
lodsb
|
||||
stosb
|
||||
loop copy_gdt
|
||||
|
||||
mov edi, IDT_V ;destination
|
||||
mov esi, isr_0 ;address of isr0
|
||||
mov edx, isr_1-isr_0 ;distance between isr labels
|
||||
mov ecx, 50 ;number of isrlabels
|
||||
fill_idt:
|
||||
mov ebx, esi
|
||||
mov ax, si
|
||||
stosw ;0 offset 15:0
|
||||
mov ax, KERNEL_CODE
|
||||
stosw ;2 selector 15:0
|
||||
mov ax, 0x8E00
|
||||
stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0]
|
||||
shr esi, 16
|
||||
mov ax, si
|
||||
stosw ;6 offset 31:16
|
||||
mov esi, ebx
|
||||
add esi, edx
|
||||
loop fill_idt
|
||||
mov word [IDT_V+0x30*8+4], 0xEE00 ;interrupt 0x30 has user priviledges
|
||||
|
||||
lgdt [gdtr] ;load gdt
|
||||
jmp KERNEL_CODE:newgdtcontinue
|
||||
newgdtcontinue:
|
||||
mov ax, KERNEL_DATA
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
mov gs, ax
|
||||
mov fs, ax
|
||||
mov ss, ax
|
||||
mov esp, 0xc0200000 ;stack just under 3gb+2mb, moves downward
|
||||
lidt [idtr] ;load idt
|
||||
|
||||
call k_init
|
||||
haltit:
|
||||
hlt ;halt processor when k_init is done
|
||||
jmp haltit ;shouldn't get here...
|
||||
|
||||
%include "gdt.inc"
|
||||
%include "idt.inc"
|
||||
|
||||
|
||||
+61
-4
@@ -1,17 +1,74 @@
|
||||
HOS - Holtrop's Operating System
|
||||
|
||||
|
||||
--------------------------------
|
||||
HOS is a 32-bit, protected mode, graphical, multitasking operating system.
|
||||
It was written by me, Josh Holtrop, with help from a few others along the way.
|
||||
|
||||
|
||||
Goals: (A = accomplished, P = in progress, T = todo)
|
||||
----------------------------------------------------
|
||||
(A) Custom bootloader to load kernel from FAT-formatted boot media, options for video mode/ram disk
|
||||
(A) 32-bit protected mode environment
|
||||
(A) VESA Support for graphics modes
|
||||
(A) PS/2 keyboard & mouse drivers
|
||||
(A) Utilize x86's paging architecture for virtual memory management
|
||||
|
||||
(P) VFS abstraction layer for a single file system
|
||||
(P) ram disk driver
|
||||
(P) vfat file system support
|
||||
|
||||
(T) devfs file system driver
|
||||
(T) Multitasking support
|
||||
(T) Console Manager
|
||||
(T) HASH command shell
|
||||
(T) Window Manager
|
||||
(T) Various other utilities/applications
|
||||
(T) Hard Drive (ATA) driver
|
||||
(T) cdrom (ATAPI) driver
|
||||
(T) ext2/3 file system support
|
||||
|
||||
|
||||
Change Log
|
||||
----------
|
||||
|
||||
0.14
|
||||
05/21/04 - C++ support in kernel, can use classes & templates
|
||||
04/04/04 - video_line function for diagonal lines
|
||||
03/16/04 - new VFS design with support for a loop device
|
||||
03/01/04 - Thanks to Ben Meyer for helping me get a Makefile working and building on linux to work!
|
||||
|
||||
0.1301/26/04 - functions added to read/write CMOS clock date and time01/19/04 - fixed bug GDTR/IDTR pointing to physical rather than linear table base address01/07/04 - fixed bug not reading sectors correctly from floppy12/28/03 - fixed bug not storing eax on interrupt12/25/03 - fixed bug in mm_palloc()12/25/03 - incorporated output functions as regular functions rather than as part of a linked library12/23/03 - re-written physical memory manager using bitmap instead of stack12/22/03 - kernel relocated to 3gb linear / 1mb+24kb physical to allow for app. address space0.1212/21/03 - sample bmp loader tested, works (tests loading a kernel of size ~ 932kb12/20/03 - GDT/IDT now located at 1mb physical, before kernel10/30/03 - turns floppy motor off10/30/03 - keyboard LEDs working10/29/03 - paging functions working10/15/03 - physical memory management page allocators working0.1110/09/03 - PS/2 mouse driver0.1009/11/03 - Rewritten C and assembly kernel with VESA GUI mode support, keyboard driver0.0505/14/03 - HGUI24/HGUI32 commands finished for testing GUI on both 24bpp and 32bpp graphics cards05/14/03 - first web release!0.0403/09/03 - added VM shortcut command03/09/03 - press up to fill retrieve last inputted command for Nate Scholten03/08/03 - press clear to clear console input03/07/03 - added "shortcut" commands PC, IC, ? for Nate Scholten03/06/03 - added PROMPTC, INPUTC commands0.0312/30/02 - Command Line Interface working, accepting basic commands
|
||||
0.13
|
||||
01/26/04 - functions added to read/write CMOS clock date and time
|
||||
01/19/04 - fixed bug GDTR/IDTR pointing to physical rather than linear table base address
|
||||
01/07/04 - fixed bug not reading sectors correctly from floppy
|
||||
12/28/03 - fixed bug not storing eax on interrupt
|
||||
12/25/03 - fixed bug in mm_palloc()
|
||||
12/25/03 - incorporated output functions as regular functions rather than as part of a linked library
|
||||
12/23/03 - re-written physical memory manager using bitmap instead of stack
|
||||
12/22/03 - kernel relocated to 3gb linear / 1mb+24kb physical to allow for app. address space
|
||||
|
||||
0.12
|
||||
12/21/03 - sample bmp loader tested, works (tests loading a kernel of size ~ 932kb
|
||||
12/20/03 - GDT/IDT now located at 1mb physical, before kernel
|
||||
10/30/03 - turns floppy motor off
|
||||
10/30/03 - keyboard LEDs working
|
||||
10/29/03 - paging functions working
|
||||
10/15/03 - physical memory management page allocators working
|
||||
|
||||
0.11
|
||||
10/09/03 - PS/2 mouse driver
|
||||
|
||||
0.10
|
||||
09/11/03 - Rewritten C and assembly kernel with VESA GUI mode support, keyboard driver
|
||||
|
||||
0.05
|
||||
05/14/03 - HGUI24/HGUI32 commands finished for testing GUI on both 24bpp and 32bpp graphics cards
|
||||
05/14/03 - first web release!
|
||||
|
||||
0.04
|
||||
03/09/03 - added VM shortcut command
|
||||
03/09/03 - press up to fill retrieve last inputted command for Nate Scholten
|
||||
03/08/03 - press clear to clear console input
|
||||
03/07/03 - added "shortcut" commands PC, IC, ? for Nate Scholten
|
||||
03/06/03 - added PROMPTC, INPUTC commands
|
||||
|
||||
0.03
|
||||
12/30/02 - Command Line Interface working, accepting basic commands
|
||||
-510
@@ -1,510 +0,0 @@
|
||||
; asmfuncs.asm
|
||||
; Josh Holtrop
|
||||
; Created: 10/23/03
|
||||
; Modified: 02/26/04
|
||||
|
||||
[extern _putc]
|
||||
[extern _console_memory]
|
||||
[extern _cursorPosition]
|
||||
[extern _video_drawConsole]
|
||||
[extern _videoMode]
|
||||
|
||||
%macro jzfar 1
|
||||
jnz %%skip
|
||||
jmp %1
|
||||
%%skip:
|
||||
|
||||
%endmacro
|
||||
|
||||
;stores the parameter to the CR0 register
|
||||
;extern dword write_cr0(dword cr0);
|
||||
[global _write_cr0]
|
||||
_write_cr0:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr0, eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;returns the value in the CR0 register
|
||||
;extern dword read_cr0();
|
||||
[global _read_cr0]
|
||||
_read_cr0:
|
||||
mov eax, cr0;
|
||||
ret
|
||||
|
||||
;stores the parameter to the CR3 register
|
||||
;extern dword write_cr3(dword cr3);
|
||||
[global _write_cr3]
|
||||
_write_cr3:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, [ebp+8]
|
||||
mov cr3, eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;returns the value in the CR2 register
|
||||
;extern dword read_cr2();
|
||||
[global _read_cr2]
|
||||
_read_cr2:
|
||||
mov eax, cr2;
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;returns the value in the CR3 register
|
||||
;extern dword read_cr3();
|
||||
[global _read_cr3]
|
||||
_read_cr3:
|
||||
mov eax, cr3;
|
||||
ret
|
||||
|
||||
|
||||
;compares one string to another
|
||||
;returns 0 if the strings are different
|
||||
;extern dword strcmp(char *str1, char *str2);
|
||||
[global _strcmp]
|
||||
_strcmp:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
|
||||
mov esi, [ebp+8]
|
||||
mov edi, [ebp+12]
|
||||
strcmp_loop1:
|
||||
lodsb
|
||||
mov ah, [edi]
|
||||
inc edi
|
||||
cmp ah, al
|
||||
jnz strcmp_ne
|
||||
or al, al
|
||||
jz strcmp_e
|
||||
jmp strcmp_loop1
|
||||
strcmp_e:
|
||||
mov eax, 1
|
||||
jmp short strcmp_done
|
||||
strcmp_ne:
|
||||
xor eax, eax
|
||||
strcmp_done:
|
||||
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;copies a string from the source to the destination parameter
|
||||
;extern void strcpy(char *dest, char *src);
|
||||
[global _strcpy]
|
||||
_strcpy:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
strcpyloop:
|
||||
lodsb
|
||||
stosb
|
||||
or al, al
|
||||
jnz strcpyloop
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;copies memory of n bytes from src to destination
|
||||
;void memcpy(void *dest, void *src, dword n);
|
||||
[global _memcpy]
|
||||
_memcpy:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
cld
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;copies memory of n dwords (n*4 bytes) from src to destination
|
||||
;void memcpyd(void *dest, void *src, dword n);
|
||||
[global _memcpyd]
|
||||
_memcpyd:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
mov esi, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
cld
|
||||
rep movsd
|
||||
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num bytes at buffer to the value of c
|
||||
;void *memset(void *buffer, int c, int num);
|
||||
[global _memset]
|
||||
_memset:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosb
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num words at buffer to the value of c
|
||||
;void *memsetw(void *buffer, int c, int num);
|
||||
[global _memsetw]
|
||||
_memsetw:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosw
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;sets num dwords at buffer to the value of c
|
||||
;void *memsetd(void *buffer, int c, int num);
|
||||
[global _memsetd]
|
||||
_memsetd:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push edi
|
||||
push ecx
|
||||
mov edi, [ebp+8]
|
||||
push edi ;save for return address
|
||||
mov eax, [ebp+12]
|
||||
mov ecx, [ebp+16]
|
||||
|
||||
rep stosd
|
||||
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
;returns the number of characters in a string
|
||||
;extern dword strlen(char *str);
|
||||
[global _strlen]
|
||||
_strlen:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push ebx
|
||||
mov esi, [ebp+8]
|
||||
xor ebx, ebx
|
||||
strlenloop:
|
||||
lodsb
|
||||
or al, al
|
||||
jz strlendone
|
||||
inc ebx
|
||||
jmp strlenloop
|
||||
strlendone:
|
||||
mov eax, ebx
|
||||
pop ebx
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;this function invalidates the page directory/table entry that
|
||||
; would be used to access the memory address given in the parameter
|
||||
;extern void invlpg_(dword addr);
|
||||
[global _invlpg_]
|
||||
_invlpg_:
|
||||
mov eax, [esp+4]
|
||||
invlpg [eax]
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;void writeCursorPosition(word pos)
|
||||
;
|
||||
[global _writeCursorPosition]
|
||||
_writeCursorPosition:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
push eax
|
||||
push ebx
|
||||
push edx
|
||||
|
||||
mov eax, [ebp+8] ;cursor position in ax
|
||||
|
||||
mov bl, al
|
||||
mov dx, 0x03D4
|
||||
mov al, 0x0E
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
mov al, ah
|
||||
out dx, al
|
||||
|
||||
dec dx
|
||||
mov al, 0x0F
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
mov al, bl
|
||||
out dx, al
|
||||
|
||||
pop edx
|
||||
pop ebx
|
||||
pop eax
|
||||
pop ebp
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;word getCursorPosition()
|
||||
;
|
||||
[global _getCursorPosition]
|
||||
_getCursorPosition:
|
||||
push ebx
|
||||
push edx
|
||||
|
||||
xor eax, eax
|
||||
mov dx, 0x03D4
|
||||
mov al, 0x0E
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
in al, dx
|
||||
mov bl, al
|
||||
|
||||
dec dx
|
||||
mov al, 0x0F
|
||||
out dx, al
|
||||
|
||||
inc dx
|
||||
in al, dx
|
||||
mov ah, bl
|
||||
|
||||
pop edx
|
||||
pop ebx
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
;int puts(char *str)
|
||||
;
|
||||
[global _puts]
|
||||
_puts:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push eax
|
||||
mov esi, [ebp+8] ;esi = to string
|
||||
puts_loop:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
jz puts_done
|
||||
push eax
|
||||
call _putc
|
||||
add esp, 4
|
||||
jmp puts_loop
|
||||
|
||||
puts_done:
|
||||
pop eax
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
[global _putDecu]
|
||||
_putDecu:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 24
|
||||
mov DWORD [ebp-4], 1
|
||||
mov BYTE [ebp-5], 0
|
||||
L2:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
cmp eax, DWORD [ebp-4]
|
||||
jae L4
|
||||
jmp L3
|
||||
L4:
|
||||
mov eax, DWORD [ebp-4]
|
||||
mov edx, eax
|
||||
sal edx, 2
|
||||
add edx, eax
|
||||
lea eax, [edx+edx]
|
||||
mov DWORD [ebp-4], eax
|
||||
jmp L2
|
||||
L3:
|
||||
nop
|
||||
L5:
|
||||
cmp DWORD [ebp-4], 1
|
||||
ja L7
|
||||
jmp L6
|
||||
L7:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, edx
|
||||
mov edx, 0
|
||||
div DWORD [ebp-4]
|
||||
mov DWORD [ebp-12], eax
|
||||
mov al, BYTE [ebp-12]
|
||||
mov BYTE [ebp-5], al
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
imul eax, DWORD [ebp-4]
|
||||
sub DWORD [ebp+8], eax
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
lea eax, [ebp-5]
|
||||
add BYTE [eax], 48
|
||||
sub esp, 12
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
push eax
|
||||
call _putc
|
||||
add esp, 16
|
||||
jmp L5
|
||||
L6:
|
||||
sub esp, 12
|
||||
mov al, BYTE [ebp+8]
|
||||
add eax, 48
|
||||
and eax, 255
|
||||
push eax
|
||||
call _putc
|
||||
add esp, 16
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
[global _putDec]
|
||||
_putDec:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 24
|
||||
cmp DWORD [ebp+8], 0
|
||||
jns L9
|
||||
sub esp, 12
|
||||
push 45
|
||||
call _putc
|
||||
add esp, 16
|
||||
neg DWORD [ebp+8]
|
||||
L9:
|
||||
mov DWORD [ebp-4], 1
|
||||
mov BYTE [ebp-5], 0
|
||||
L10:
|
||||
mov eax, DWORD [ebp+8]
|
||||
cmp eax, DWORD [ebp-4]
|
||||
jae L12
|
||||
jmp L11
|
||||
L12:
|
||||
mov eax, DWORD [ebp-4]
|
||||
mov edx, eax
|
||||
sal edx, 2
|
||||
add edx, eax
|
||||
lea eax, [edx+edx]
|
||||
mov DWORD [ebp-4], eax
|
||||
jmp L10
|
||||
L11:
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
L13:
|
||||
cmp DWORD [ebp-4], 1
|
||||
ja L15
|
||||
jmp L14
|
||||
L15:
|
||||
mov edx, DWORD [ebp+8]
|
||||
mov eax, edx
|
||||
mov edx, 0
|
||||
div DWORD [ebp-4]
|
||||
mov DWORD [ebp-12], eax
|
||||
mov al, BYTE [ebp-12]
|
||||
mov BYTE [ebp-5], al
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
imul eax, DWORD [ebp-4]
|
||||
sub DWORD [ebp+8], eax
|
||||
mov edx, DWORD [ebp-4]
|
||||
mov eax, -858993459
|
||||
mul edx
|
||||
mov eax, edx
|
||||
shr eax, 3
|
||||
mov DWORD [ebp-4], eax
|
||||
lea eax, [ebp-5]
|
||||
add BYTE [eax], 48
|
||||
sub esp, 12
|
||||
mov eax, 0
|
||||
mov al, BYTE [ebp-5]
|
||||
push eax
|
||||
call _putc
|
||||
add esp, 16
|
||||
jmp L13
|
||||
L14:
|
||||
sub esp, 12
|
||||
mov al, BYTE [ebp+8]
|
||||
add eax, 48
|
||||
and eax, 255
|
||||
push eax
|
||||
call _putc
|
||||
add esp, 16
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
;idt.inc
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 03/02/04
|
||||
|
||||
idtr:
|
||||
dw 50*8-1 ;size of idt
|
||||
dd IDT_V ;address of idt
|
||||
|
||||
|
||||
%macro isr_label 1
|
||||
isr_%1:
|
||||
push eax
|
||||
mov eax, %1
|
||||
jmp isr_main
|
||||
%endmacro
|
||||
|
||||
isr_label 0
|
||||
isr_label 1
|
||||
isr_label 2
|
||||
isr_label 3
|
||||
isr_label 4
|
||||
isr_label 5
|
||||
isr_label 6
|
||||
isr_label 7
|
||||
isr_label 8
|
||||
isr_label 9
|
||||
isr_label 10
|
||||
isr_label 11
|
||||
isr_label 12
|
||||
isr_label 13
|
||||
isr_label 14
|
||||
isr_label 15
|
||||
isr_label 16
|
||||
isr_label 17
|
||||
isr_label 18
|
||||
isr_label 19
|
||||
isr_label 20
|
||||
isr_label 21
|
||||
isr_label 22
|
||||
isr_label 23
|
||||
isr_label 24
|
||||
isr_label 25
|
||||
isr_label 26
|
||||
isr_label 27
|
||||
isr_label 28
|
||||
isr_label 29
|
||||
isr_label 30
|
||||
isr_label 31
|
||||
isr_label 32
|
||||
isr_label 33
|
||||
isr_label 34
|
||||
isr_label 35
|
||||
isr_label 36
|
||||
isr_label 37
|
||||
isr_label 38
|
||||
isr_label 39
|
||||
isr_label 40
|
||||
isr_label 41
|
||||
isr_label 42
|
||||
isr_label 43
|
||||
isr_label 44
|
||||
isr_label 45
|
||||
isr_label 46
|
||||
isr_label 47
|
||||
isr_label 48
|
||||
isr_label 49
|
||||
|
||||
isr_main:
|
||||
cmp eax, 0x30
|
||||
jz isr_syscall
|
||||
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
push eax
|
||||
|
||||
call _isr
|
||||
|
||||
add esp, 4
|
||||
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
pop eax
|
||||
|
||||
iret
|
||||
|
||||
|
||||
isr_syscall:
|
||||
pop eax ;syscall function number
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
sc1:
|
||||
cmp eax, 1 ;syscall 1 - putc
|
||||
jnz sc2
|
||||
push ebx
|
||||
call _putc
|
||||
add esp, 4
|
||||
jmp scdone
|
||||
sc2:
|
||||
|
||||
scdone:
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
iret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
;kernel.asm
|
||||
;Author: Josh Holtrop
|
||||
;Date: 10/30/03
|
||||
;Modified: 10/30/03
|
||||
|
||||
%define GDT_P 0x100000; ;1mb physical - Global Descriptor Table space
|
||||
%define GDT_V GDT_P+0xC0000000
|
||||
%define IDT_P 0x102000 ;1mb+8kb - Interrupt Descriptor Table space
|
||||
%define IDT_V IDT_P+0xC0000000
|
||||
%define PDBR_P 0x104000 ;1mb+16kb - Page Directory Base Register (first PD)
|
||||
%define PDBR_V PDBR_P+0xC0000000
|
||||
%define LOPT_P 0x105000 ;1mb+20kb - LOw Page Table for mapping first 4mb
|
||||
%define LOPT_V LOPT_P+0xC0000000
|
||||
%define KERNEL_P 0x106000 ;1mb+24kb - the kernel's physical address
|
||||
%define KERNEL_V KERNEL_P+0xC0000000 ;3gb+1mb+24kb, the virtual address of the kernel
|
||||
|
||||
[global _start]
|
||||
[extern _isr]
|
||||
[extern _k_init]
|
||||
[extern _putc]
|
||||
|
||||
bits 32
|
||||
|
||||
;This is where the kernel begins execution
|
||||
;At this point, the temporary gdt is set up to "map" 0xC000_0000 to 0x0.
|
||||
;We must enable paging with the first 4mb mapped 1:1 virtual:physical
|
||||
; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical.
|
||||
;Then we can start using our "real" gdt, then unmap the lower 4mb.
|
||||
_start:
|
||||
cli ;if they weren't already off
|
||||
|
||||
xor eax, eax
|
||||
mov edi, PDBR_V
|
||||
mov ecx, 1024 ;clear the PDBR
|
||||
rep stosd
|
||||
mov [PDBR_V], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table (read/write, present)
|
||||
mov [PDBR_V+0xC00], dword LOPT_P|0x03 ;store the physical address of the LOw Page Table (read/write, present)
|
||||
|
||||
mov edi, LOPT_V
|
||||
mov ecx, 1024
|
||||
mov eax, 0x03 ;starting physical address = 0x0 (read/write, present flags)
|
||||
fill_lopt_loop: ;fill the page table
|
||||
stosd
|
||||
add eax, 4096 ;increment next phsyical address by 4kb
|
||||
loop fill_lopt_loop
|
||||
|
||||
mov eax, PDBR_P
|
||||
mov cr3, eax ;store the Page Directory Base Address
|
||||
mov eax, cr0
|
||||
or eax, 0x80000000 ;set page enable bit
|
||||
mov cr0, eax ;now paging is active!
|
||||
|
||||
|
||||
mov edi, GDT_V
|
||||
mov esi, gdt
|
||||
mov ecx, gdt_end-gdt
|
||||
copy_gdt:
|
||||
lodsb
|
||||
stosb
|
||||
loop copy_gdt
|
||||
|
||||
mov edi, IDT_V ;destination
|
||||
mov esi, isr_0 ;address of isr0
|
||||
mov edx, isr_1-isr_0 ;distance between isr labels
|
||||
mov ecx, 50 ;number of isrlabels
|
||||
fill_idt:
|
||||
mov ebx, esi
|
||||
mov ax, si
|
||||
stosw ;0 offset 15:0
|
||||
mov ax, KERNEL_CODE
|
||||
stosw ;2 selector 15:0
|
||||
mov ax, 0x8E00
|
||||
stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0]
|
||||
shr esi, 16
|
||||
mov ax, si
|
||||
stosw ;6 offset 31:16
|
||||
mov esi, ebx
|
||||
add esi, edx
|
||||
loop fill_idt
|
||||
mov word [IDT_V+0x30*8+4], 0xEE00 ;interrupt 0x30 has user priviledges
|
||||
|
||||
lgdt [gdtr] ;load gdt
|
||||
jmp KERNEL_CODE:newgdtcontinue
|
||||
newgdtcontinue:
|
||||
mov ax, KERNEL_DATA
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
mov gs, ax
|
||||
mov fs, ax
|
||||
mov ss, ax
|
||||
mov esp, 0xc0200000 ;stack just under 3gb+2mb, moves downward
|
||||
lidt [idtr] ;load idt
|
||||
|
||||
call _k_init
|
||||
haltit:
|
||||
hlt ;halt processor when k_init is done
|
||||
jmp haltit ;shouldn't get here...
|
||||
|
||||
%include "gdt.inc"
|
||||
%include "idt.inc"
|
||||
|
||||
|
||||
Reference in new issue
Block a user