Import backup from 2004-03-10

This commit is contained in:
Josh Holtrop 2004-03-10 22:00:00 -05:00
parent 7f886e44e1
commit 302538b8ff
24 changed files with 799 additions and 694 deletions

View File

@ -99,12 +99,12 @@ install_img: $(FLOPPY_IMAGE)
@echo "Writing boot sector to image..." @echo "Writing boot sector to image..."
dd if=stage1.bin of=$(FLOPPY_IMAGE) seek=0 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 # # 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..." @echo "Copying stage 2 bootloader to the floppy image..."
$(COPY_BIN) stage2.bin $(FLOPPY_MOUNT) $(COPY_BIN) stage2.bin $(FLOPPY_MOUNT)
@echo "Copying kernel to the floppy image..." @echo "Copying kernel to the floppy image..."

View File

@ -1,5 +1,5 @@
%define VERSION "0.13" ;HOS version %define VERSION "0.14" ;HOS version
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector %define BOOT_FAT_SEG 0x07E0 ;right after boot sector
%define BOOT_ROOT_SEG 0x0900 ;right after FAT %define BOOT_ROOT_SEG 0x0900 ;right after FAT

View File

@ -19,7 +19,7 @@ NASM_FLAGS=-f $(KERNEL_FORMAT)
# C Compile Information: # C Compile Information:
CC=gcc CC=gcc
CC_FLAGS=-ffreestanding -fno-builtin -nostdlib -nodefaultlibs -I. CC_FLAGS=-ffreestanding -fno-builtin -nostdlib -nodefaultlibs -I. -Wall
# Linker Information: # Linker Information:
LD=ld LD=ld
@ -30,7 +30,7 @@ LD_FLAGS=-nodefaultlibs -nostdlib -T link.ld
# Linking the kernel together # # Linking the kernel together #
############################### ###############################
all: Asm_Kernel Asm_Functions C_Kernel 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 $(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
########################## ##########################
# Assembly Kernel Loader # # Assembly Kernel Loader #

71
kernel/Makefile.ms 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. -Wall
# 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 kernel.o asmfuncs.o fdc.o functions.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.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 ./lst/*.doc *.bin

View File

@ -3,11 +3,11 @@
; Created: 10/23/03 ; Created: 10/23/03
; Modified: 02/26/04 ; Modified: 02/26/04
[extern _putc] [extern putc]
[extern _console_memory] [extern console_memory]
[extern _cursorPosition] [extern cursorPosition]
[extern _video_drawConsole] [extern video_drawConsole]
[extern _videoMode] [extern videoMode]
%macro jzfar 1 %macro jzfar 1
jnz %%skip jnz %%skip
@ -18,8 +18,8 @@
;stores the parameter to the CR0 register ;stores the parameter to the CR0 register
;extern dword write_cr0(dword cr0); ;extern dword write_cr0(dword cr0);
[global _write_cr0] [global write_cr0]
_write_cr0: write_cr0:
push ebp push ebp
mov ebp, esp mov ebp, esp
mov eax, [ebp+8] mov eax, [ebp+8]
@ -29,15 +29,15 @@ _write_cr0:
;returns the value in the CR0 register ;returns the value in the CR0 register
;extern dword read_cr0(); ;extern dword read_cr0();
[global _read_cr0] [global read_cr0]
_read_cr0: read_cr0:
mov eax, cr0; mov eax, cr0;
ret ret
;stores the parameter to the CR3 register ;stores the parameter to the CR3 register
;extern dword write_cr3(dword cr3); ;extern dword write_cr3(dword cr3);
[global _write_cr3] [global write_cr3]
_write_cr3: write_cr3:
push ebp push ebp
mov ebp, esp mov ebp, esp
mov eax, [ebp+8] mov eax, [ebp+8]
@ -48,8 +48,8 @@ _write_cr3:
;returns the value in the CR2 register ;returns the value in the CR2 register
;extern dword read_cr2(); ;extern dword read_cr2();
[global _read_cr2] [global read_cr2]
_read_cr2: read_cr2:
mov eax, cr2; mov eax, cr2;
ret ret
@ -57,8 +57,8 @@ _read_cr2:
;returns the value in the CR3 register ;returns the value in the CR3 register
;extern dword read_cr3(); ;extern dword read_cr3();
[global _read_cr3] [global read_cr3]
_read_cr3: read_cr3:
mov eax, cr3; mov eax, cr3;
ret ret
@ -66,8 +66,8 @@ _read_cr3:
;compares one string to another ;compares one string to another
;returns 0 if the strings are different ;returns 0 if the strings are different
;extern dword strcmp(char *str1, char *str2); ;extern dword strcmp(char *str1, char *str2);
[global _strcmp] [global strcmp]
_strcmp: strcmp:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -98,8 +98,8 @@ strcmp_done:
;copies a string from the source to the destination parameter ;copies a string from the source to the destination parameter
;extern void strcpy(char *dest, char *src); ;extern void strcpy(char *dest, char *src);
[global _strcpy] [global strcpy]
_strcpy: strcpy:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -118,8 +118,8 @@ strcpyloop:
;copies memory of n bytes from src to destination ;copies memory of n bytes from src to destination
;void memcpy(void *dest, void *src, dword n); ;void memcpy(void *dest, void *src, dword n);
[global _memcpy] [global memcpy]
_memcpy: memcpy:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -129,6 +129,7 @@ _memcpy:
mov esi, [ebp+12] mov esi, [ebp+12]
mov ecx, [ebp+16] mov ecx, [ebp+16]
cld
rep movsb rep movsb
pop ecx pop ecx
@ -140,8 +141,8 @@ _memcpy:
;copies memory of n dwords (n*4 bytes) from src to destination ;copies memory of n dwords (n*4 bytes) from src to destination
;void memcpyd(void *dest, void *src, dword n); ;void memcpyd(void *dest, void *src, dword n);
[global _memcpyd] [global memcpyd]
_memcpyd: memcpyd:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -151,6 +152,7 @@ _memcpyd:
mov esi, [ebp+12] mov esi, [ebp+12]
mov ecx, [ebp+16] mov ecx, [ebp+16]
cld
rep movsd rep movsd
pop ecx pop ecx
@ -162,11 +164,10 @@ _memcpyd:
;sets num bytes at buffer to the value of c ;sets num bytes at buffer to the value of c
;void *memset(void *buffer, int c, int num); ;void *memset(void *buffer, int c, int num);
[global _memset] [global memset]
_memset: memset:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi
push edi push edi
push ecx push ecx
mov edi, [ebp+8] mov edi, [ebp+8]
@ -179,18 +180,16 @@ _memset:
pop eax pop eax
pop ecx pop ecx
pop edi pop edi
pop esi
pop ebp pop ebp
ret ret
;sets num words at buffer to the value of c ;sets num words at buffer to the value of c
;void *memsetw(void *buffer, int c, int num); ;void *memsetw(void *buffer, int c, int num);
[global _memsetw] [global memsetw]
_memsetw: memsetw:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi
push edi push edi
push ecx push ecx
mov edi, [ebp+8] mov edi, [ebp+8]
@ -203,18 +202,16 @@ _memsetw:
pop eax pop eax
pop ecx pop ecx
pop edi pop edi
pop esi
pop ebp pop ebp
ret ret
;sets num dwords at buffer to the value of c ;sets num dwords at buffer to the value of c
;void *memsetd(void *buffer, int c, int num); ;void *memsetd(void *buffer, int c, int num);
[global _memsetd] [global memsetd]
_memsetd: memsetd:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi
push edi push edi
push ecx push ecx
mov edi, [ebp+8] mov edi, [ebp+8]
@ -227,15 +224,14 @@ _memsetd:
pop eax pop eax
pop ecx pop ecx
pop edi pop edi
pop esi
pop ebp pop ebp
ret ret
;returns the number of characters in a string ;returns the number of characters in a string
;extern dword strlen(char *str); ;extern dword strlen(char *str);
[global _strlen] [global strlen]
_strlen: strlen:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -257,9 +253,9 @@ strlendone:
;this function invalidates the page directory/table entry that ;this function invalidates the page directory/table entry that
; would be used to access the memory address given in the parameter ; would be used to access the memory address given in the parameter
;extern void invlpg(dword addr); ;extern void invlpg_(dword addr);
[global _invlpg] [global invlpg_]
_invlpg: invlpg_:
mov eax, [esp+4] mov eax, [esp+4]
invlpg [eax] invlpg [eax]
ret ret
@ -268,8 +264,8 @@ _invlpg:
; ;
;void writeCursorPosition(word pos) ;void writeCursorPosition(word pos)
; ;
[global _writeCursorPosition] [global writeCursorPosition]
_writeCursorPosition: writeCursorPosition:
push ebp push ebp
mov ebp, esp mov ebp, esp
@ -307,8 +303,8 @@ _writeCursorPosition:
; ;
;word getCursorPosition() ;word getCursorPosition()
; ;
[global _getCursorPosition] [global getCursorPosition]
_getCursorPosition: getCursorPosition:
push ebx push ebx
push edx push edx
@ -338,8 +334,8 @@ _getCursorPosition:
; ;
;int puts(char *str) ;int puts(char *str)
; ;
[global _puts] [global puts]
_puts: puts:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
@ -350,7 +346,7 @@ puts_loop:
cmp al, 0 cmp al, 0
jz puts_done jz puts_done
push eax push eax
call _putc call putc
add esp, 4 add esp, 4
jmp puts_loop jmp puts_loop
@ -363,8 +359,8 @@ puts_done:
[global _putDecu] [global putDecu]
_putDecu: putDecu:
push ebp push ebp
mov ebp, esp mov ebp, esp
sub esp, 24 sub esp, 24
@ -417,7 +413,7 @@ L7:
mov eax, 0 mov eax, 0
mov al, BYTE [ebp-5] mov al, BYTE [ebp-5]
push eax push eax
call _putc call putc
add esp, 16 add esp, 16
jmp L5 jmp L5
L6: L6:
@ -426,7 +422,7 @@ L6:
add eax, 48 add eax, 48
and eax, 255 and eax, 255
push eax push eax
call _putc call putc
add esp, 16 add esp, 16
leave leave
ret ret
@ -434,8 +430,8 @@ L6:
[global _putDec] [global putDec]
_putDec: putDec:
push ebp push ebp
mov ebp, esp mov ebp, esp
sub esp, 24 sub esp, 24
@ -443,7 +439,7 @@ _putDec:
jns L9 jns L9
sub esp, 12 sub esp, 12
push 45 push 45
call _putc call putc
add esp, 16 add esp, 16
neg DWORD [ebp+8] neg DWORD [ebp+8]
L9: L9:
@ -497,7 +493,7 @@ L15:
mov eax, 0 mov eax, 0
mov al, BYTE [ebp-5] mov al, BYTE [ebp-5]
push eax push eax
call _putc call putc
add esp, 16 add esp, 16
jmp L13 jmp L13
L14: L14:
@ -506,7 +502,7 @@ L14:
add eax, 48 add eax, 48
and eax, 255 and eax, 255
push eax push eax
call _putc call putc
add esp, 16 add esp, 16
leave leave
ret ret

View File

@ -5,6 +5,8 @@
#ifndef __HOS_ASMFUNCS__ #ifndef __HOS_ASMFUNCS__
#define __HOS_ASMFUNCS__ __HOS_ASMFUNCS__ #define __HOS_ASMFUNCS__ __HOS_ASMFUNCS__
#include "hos_defines.h"
dword write_cr0(dword cr0); dword write_cr0(dword cr0);
dword read_cr0(); dword read_cr0();
dword write_cr3(dword cr3); dword write_cr3(dword cr3);
@ -22,6 +24,7 @@ void *memset(void *buffer, int c, int num);
void *memsetw(void *buffer, int c, int num); void *memsetw(void *buffer, int c, int num);
void *memsetd(void *buffer, int c, int num); void *memsetd(void *buffer, int c, int num);
dword strlen(char *str); dword strlen(char *str);
void invlpg_(dword addr);
#endif #endif

View File

@ -11,9 +11,9 @@
#define FDC_DOR 0x3f2 #define FDC_DOR 0x3f2
#define FDC_MSR 0x3f4 #define FDC_MSR 0x3f4
inline void fdc_sendDOR(byte dor); //inline void fdc_sendDOR(byte dor);
inline void fdc_sendDOR(byte dor) static inline void fdc_sendDOR(byte dor)
{ {
outportb(FDC_DOR, dor); outportb(FDC_DOR, dor);
} }

View File

@ -5,6 +5,10 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "keyboard.h" #include "keyboard.h"
#include "sys/io.h"
#include "sys/pic.h"
#include "functions.h"
#include "kio.h"
#define KBD_BUFFER_LENGTH 64 #define KBD_BUFFER_LENGTH 64
@ -49,13 +53,13 @@ void isr_keyboard()
if (kbdScan == 224) //extended key if (kbdScan == 224) //extended key
{ {
kbdExt = 1; kbdExt = 1;
eoi(); pic_eoi();
return; return;
} }
if (kbdScan == 225) //2nd-set-extended key if (kbdScan == 225) //2nd-set-extended key
{ {
kbdExt2 = 2; kbdExt2 = 2;
eoi(); pic_eoi();
return; return;
} }
@ -117,7 +121,7 @@ void isr_keyboard()
{ {
if (kbdExt > 0) if (kbdExt > 0)
kbdExt--; kbdExt--;
eoi(); pic_eoi();
return; return;
} }
//====determine ASCII value of key:: //====determine ASCII value of key::
@ -182,14 +186,14 @@ void isr_keyboard()
} }
if (kbdAscii == 2) //unknown key / ignore key if (kbdAscii == 2) //unknown key / ignore key
{ {
eoi(); pic_eoi();
return; return;
} }
if (kbdScan < KBD_SCAN_RELEASED) //a key was pressed, save it if (kbdScan < KBD_SCAN_RELEASED) //a key was pressed, save it
{ {
if (kbdBufferLen >= KBD_BUFFER_LENGTH) //no key slots available if (kbdBufferLen >= KBD_BUFFER_LENGTH) //no key slots available
{ {
eoi(); pic_eoi();
return; return;
} }
else else
@ -199,7 +203,7 @@ void isr_keyboard()
} }
} }
eoi(); pic_eoi();
} }

View File

@ -4,6 +4,8 @@
#include "mouse.h" #include "mouse.h"
#include "hos_defines.h" #include "hos_defines.h"
#include "video/video.h"
#include "sys/io.h"
#define MOUSE_BUFFER_LENGTH 16 #define MOUSE_BUFFER_LENGTH 16

View File

@ -13,6 +13,7 @@ extern dword _code;
extern dword _bss; extern dword _bss;
extern dword _end; extern dword _end;
/*
inline void enable_ints(); inline void enable_ints();
inline void disable_ints(); inline void disable_ints();
inline void restart(); inline void restart();
@ -21,21 +22,22 @@ inline dword kernel_size();
inline void timer_init(); inline void timer_init();
inline byte bcd2byte(byte bcd); inline byte bcd2byte(byte bcd);
inline byte byte2bcd(byte bite); inline byte byte2bcd(byte bite);
*/
//Enables (SeTs) Interrupt Flag on the processor //Enables (SeTs) Interrupt Flag on the processor
inline void enable_ints() static inline void enable_ints()
{ {
asm("sti"); asm("sti");
} }
//Disables (CLears) Interrupt Flag on the processor //Disables (CLears) Interrupt Flag on the processor
inline void disable_ints() static inline void disable_ints()
{ {
asm("cli"); asm("cli");
} }
//Restarts the computer //Restarts the computer
inline void restart() static inline void restart()
{ {
enable_ints(); enable_ints();
byte temp; byte temp;
@ -54,7 +56,7 @@ inline void restart()
} }
//Halts (freezes) the computer //Halts (freezes) the computer
inline void halt() static inline void halt()
{ {
asm("cli"); asm("cli");
asm("hlt"); asm("hlt");
@ -63,7 +65,7 @@ inline void halt()
} }
//Initializes 8253 Programmable Interrupt Timer //Initializes 8253 Programmable Interrupt Timer
inline void timer_init() static inline void timer_init()
{ {
//set timer : 2e9c = 100hz //set timer : 2e9c = 100hz
outportb(0x43, 0x34); outportb(0x43, 0x34);
@ -75,19 +77,19 @@ inline void timer_init()
// - this does not include the bss section // - this does not include the bss section
// - this should be 4kb aligned per the linker script // - this should be 4kb aligned per the linker script
// - this should be the size of kernel.bin // - this should be the size of kernel.bin
inline dword kernel_size() static inline dword kernel_size()
{ {
return (dword)(&_bss)-(dword)(&_code); return (dword)(&_bss)-(dword)(&_code);
} }
//converts a binary-coded-decimal byte to its decimal equivalent //converts a binary-coded-decimal byte to its decimal equivalent
inline byte bcd2byte(byte bcd) 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 //converts a binary-coded-decimal byte to its decimal equivalent
inline byte byte2bcd(byte bite) static inline byte byte2bcd(byte bite)
{ {
return ((bite / 10) << 4) | (bite % 10); return ((bite / 10) << 4) | (bite % 10);
} }

View File

@ -76,7 +76,7 @@ isr_main:
push eax push eax
call _isr call isr
add esp, 4 add esp, 4
@ -98,7 +98,7 @@ sc1:
cmp eax, 1 ;syscall 1 - putc cmp eax, 1 ;syscall 1 - putc
jnz sc2 jnz sc2
push ebx push ebx
call _putc call putc
add esp, 4 add esp, 4
jmp scdone jmp scdone
sc2: sc2:

View File

@ -15,9 +15,9 @@
%define KERNEL_V KERNEL_P+0xC0000000 ;3gb+1mb+24kb, the virtual address of the kernel %define KERNEL_V KERNEL_P+0xC0000000 ;3gb+1mb+24kb, the virtual address of the kernel
[global start] [global start]
[extern _isr] [extern isr]
[extern _k_init] [extern k_init]
[extern _putc] [extern putc]
bits 32 bits 32
@ -91,7 +91,7 @@ newgdtcontinue:
mov esp, 0xc0200000 ;stack just under 3gb+2mb, moves downward mov esp, 0xc0200000 ;stack just under 3gb+2mb, moves downward
lidt [idtr] ;load idt lidt [idtr] ;load idt
call _k_init call k_init
haltit: haltit:
hlt ;halt processor when k_init is done hlt ;halt processor when k_init is done
jmp haltit ;shouldn't get here... jmp haltit ;shouldn't get here...

View File

@ -32,29 +32,29 @@ void k_init()
{ {
// ===== Initialization // ===== Initialization
fdc_sendDOR(0x0C); //turn off floppy motor!! fdc_sendDOR(0x0C); //turn off floppy motor!!
console_cls(); kio_console_cls();
video_init(); video_init();
mm_init(); mm_init();
vmm_init(); vmm_init();
remap_pics(0x20, 0x28); pic_remap(0x20, 0x28);
init_timer(); timer_init();
mouse_init(); mouse_init();
pic1_mask(0); //unmask IRQ's 0-7 pic_mask1(0); //unmask IRQ's 0-7
pic2_mask(0); //unmask IRQ's 8-15 pic_mask2(0); //unmask IRQ's 8-15
enable_ints(); enable_ints();
kbd_resetLEDs(); //after enabling interrupts!! kbd_resetLEDs(); //after enabling interrupts!!
if (video_Mode()) if (video_Mode())
{ {
int p = video_getWidth()*video_getHeight()-1; int p = video_getWidth()*video_getHeight()-1;
for (; p >= 0; p--) for (; p >= 0; p--)
video_psetp(p, 0x00000077); video_pseti(p, 0x00000066);
kio_drawConsole(); kio_drawConsole();
} }
printf("HOS 0.13 - Kernel File Size: %u kb\tData Size: %u bytes\n", kernel_size()>>10, (dword)(&_end)-(dword)(&_code)); printf("HOS 0.14 - 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_getTotalMegs(), mm_getTotalMem()); 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("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("%b/%b/%b\t%b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond());
dword key = 0; dword key = 0;
for (;;) for (;;)
@ -77,14 +77,14 @@ void isr(dword num)
case 0x20: // IRQ0 - timer interrupt case 0x20: // IRQ0 - timer interrupt
timer++; timer++;
(*(byte *)(0xc00b8000))++; (*(byte *)(0xc00b8000))++;
eoi(); pic_eoi();
break; break;
case 0x21: // IRQ1 - keyboard interrupt case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); //isr_keybard() takes care of calling eoi() isr_keyboard(); //isr_keybard() takes care of calling eoi()
break; break;
case 0x2C: // IRQ12 - PS/2 mouse case 0x2C: // IRQ12 - PS/2 mouse
isr_mouse(); isr_mouse();
eoi2(); pic_eoi2();
break; break;
default: default:
printf("Interrupt %d (0x%x) Unhandled!!\n", num, num); printf("Interrupt %d (0x%x) Unhandled!!\n", num, num);

View File

@ -5,6 +5,8 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "kio.h" #include "kio.h"
#include "asmfuncs.h"
#include "video/video.h"
dword cursorPosition = 0; //Caches the current cursor position dword cursorPosition = 0; //Caches the current cursor position
word console_memory[2000]; //holds a copy of the console's memory word console_memory[2000]; //holds a copy of the console's memory
@ -48,6 +50,10 @@ void printf(char *fmt, ...)
putHex(*params); putHex(*params);
params++; params++;
break; break;
case 'b': case 'B':
kio_putBCD(*params);
params++;
break;
} }
} }
else else
@ -91,7 +97,7 @@ void putc(dword chr)
if (video_Mode()) if (video_Mode())
{ {
console_memory[cursorPosition] = charac | 0x0700; console_memory[cursorPosition] = charac | 0x0700;
video_drawConsoleChar(cursorPosition); kio_drawConsoleChar(cursorPosition);
} }
else else
{ {
@ -111,7 +117,7 @@ void putc(dword chr)
// This function displays a number in hexadecimal // This function displays a number in hexadecimal
int putHex(dword number) void putHex(dword number)
{ {
int hitNum = 0; int hitNum = 0;
int i; int i;
@ -131,14 +137,21 @@ int putHex(dword number)
} }
void kio_putBCD(dword bcd)
{
putDecu((bcd & 0xF) >> 4);
putDecu(bcd & 0xF);
}
void kio_console_scroll() void kio_console_scroll()
{ {
memcpyd(console_memory + 80, console_memory, 960); memcpyd(console_memory, console_memory + 80, 960);
memsetw(console_memory + 1920, 0x0720, 80); memsetw(console_memory + 1920, 0x0720, 80);
if (video_Mode()) if (video_Mode())
kio_drawConsole(); kio_drawConsole();
else else
memcpyd(console_memory, 0xC00B8000, 1000); memcpyd((void *)0xC00B8000, console_memory, 1000);
} }
@ -148,7 +161,7 @@ void kio_console_cls()
if (video_Mode()) if (video_Mode())
kio_drawConsole(); kio_drawConsole();
else else
memcpyd(console_memory, 0xC00B8000, 1000); memcpyd((void *)0xC00B8000, console_memory, 1000);
writeCursorPosition(0); writeCursorPosition(0);
} }

View File

@ -10,11 +10,12 @@
void printf(char *fmt, ...); void printf(char *fmt, ...);
void putc(dword chr); void putc(dword chr);
int putHex(dword number); void putHex(dword number);
void kio_drawConsole(); void kio_drawConsole();
void kio_drawConsoleChar(dword position); void kio_drawConsoleChar(dword position);
void kio_console_scroll(); void kio_console_scroll();
void kio_console_cls(); void kio_console_cls();
void kio_putBCD(dword bcd);
#endif #endif

View File

@ -6,6 +6,10 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "vmm.h" #include "vmm.h"
#include "video/video.h"
#include "asmfuncs.h"
#include "mm/mm.h"
#include "video/stdfont.h"
HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000; //this is where heap memory starts HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000; //this is where heap memory starts
@ -16,7 +20,7 @@ void vmm_init()
unsigned int *pageTables = (unsigned int *)0xC0104000; //this is the location of the page directory unsigned int *pageTables = (unsigned int *)0xC0104000; //this is the location of the page directory
pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself
pageTables[0] = 0; pageTables[0] = 0;
invlpg(0); invlpg_(0);
if (video_Mode()) //we are in a graphical mode if (video_Mode()) //we are in a graphical mode
{ {
unsigned int vidPages = video_getWidth() * video_getHeight() * (video_getBitsPerPixel() >> 3); unsigned int vidPages = video_getWidth() * video_getHeight() * (video_getBitsPerPixel() >> 3);
@ -35,7 +39,7 @@ void vmm_init()
heb->entry[0].attributes = VMM_HE_HEB; //this is a HeapEntryBlock heb->entry[0].attributes = VMM_HE_HEB; //this is a HeapEntryBlock
heb->entry[1].base = (unsigned int)firstHeapEntry+4096; //this is the start of the rest of the kernel's heap memory heb->entry[1].base = (unsigned int)firstHeapEntry+4096; //this is the start of the rest of the kernel's heap memory
heb->entry[1].size = 0x10000000-4096; //the rest of the kernel's heap memory: 256mb - 4kb heb->entry[1].size = 0x10000000-4096; //the rest of the kernel's heap memory: 256mb - 4kb
heb->entry[1].attributes = VMM_HE_HOLE; //this is a hold - an unmapped section of heap memory heb->entry[1].attributes = VMM_HE_HOLE; //this is a hole - an unmapped section of heap memory
} }
@ -64,7 +68,7 @@ void vmm_map1(unsigned int virt, unsigned int physical)
{ {
unsigned int *newpagetable = (dword *)mm_palloc(); unsigned int *newpagetable = (dword *)mm_palloc();
pageTables[pde] = ((unsigned int)newpagetable) | 0x03; pageTables[pde] = ((unsigned int)newpagetable) | 0x03;
invlpg(virt); invlpg_(virt);
unsigned int *newpteptr = (unsigned int *)(0xFFC00000 | (pde << 12)); //points to first unsigned int of newly allocated page table unsigned int *newpteptr = (unsigned int *)(0xFFC00000 | (pde << 12)); //points to first unsigned int of newly allocated page table
int a; int a;
for (a = 0; a < 1024; a++) for (a = 0; a < 1024; a++)
@ -74,7 +78,7 @@ void vmm_map1(unsigned int virt, unsigned int physical)
} }
unsigned int *pteptr = (unsigned int *)(0xFFC00000 | (pde << 12) | (pte << 2)); unsigned int *pteptr = (unsigned int *)(0xFFC00000 | (pde << 12) | (pte << 2));
*pteptr = physical | 0x03; *pteptr = physical | 0x03;
invlpg(virt); invlpg_(virt);
} }
@ -95,7 +99,7 @@ void vmm_unmap1(unsigned int virt)
{ {
unsigned int *pteptr = (unsigned int *)(0xFFC00000 | ((virt & 0xFFC00000) >> 10) | ((virt & 0x003FF000) >> 10)); unsigned int *pteptr = (unsigned int *)(0xFFC00000 | ((virt & 0xFFC00000) >> 10) | ((virt & 0x003FF000) >> 10));
*pteptr = 0; *pteptr = 0;
invlpg(virt); invlpg_(virt);
} }

2
kernel/search.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/sh
grep -R -n -i $1 *

View File

@ -4,10 +4,12 @@
// Implements string functions // Implements string functions
#include "string.h" #include "string.h"
#include "asmfuncs.h"
char *strcat(char *dest, char *src) char *strcat(char *dest, char *src)
{ {
strcpy(dest+strlen(dest), src); strcpy(dest+strlen(dest), src);
return dest;
} }

View File

@ -5,6 +5,7 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "cmos.h" #include "cmos.h"
#include "sys/io.h"
//Returns the cmos type of floppy disk drive 0 (0 = not present) //Returns the cmos type of floppy disk drive 0 (0 = not present)
unsigned char cmos_getfd0() unsigned char cmos_getfd0()

View File

@ -8,24 +8,24 @@
#include "hos_defines.h" #include "hos_defines.h"
inline void outportb(unsigned int port, unsigned char value); //void outportb(unsigned int port, unsigned char value);
inline void outportw(unsigned int port, unsigned int value); //inline void outportw(unsigned int port, unsigned int value);
inline unsigned char inportb(unsigned short port); //inline unsigned char inportb(unsigned short port);
//Writes a byte out to a port //Writes a byte out to a port
inline void outportb(unsigned int port, unsigned char value) // Output a byte to a port static inline void outportb(unsigned int port, unsigned char value) // Output a byte to a port
{ {
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value)); asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
} }
//Writes a word out to a port //Writes a word out to a port
inline void outportw(unsigned int port, unsigned int value) // Output a word to a port static inline void outportw(unsigned int port, unsigned int value) // Output a word to a port
{ {
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value)); asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
} }
//Reads a byte from a port //Reads a byte from a port
inline unsigned char inportb(unsigned short port) static inline unsigned char inportb(unsigned short port)
{ {
unsigned char ret_val; unsigned char ret_val;

View File

@ -4,6 +4,7 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "pic.h" #include "pic.h"
#include "sys/io.h"
//Re-maps the Programmable Interrupr Controllers so IRQ0->pic1 base address, IRG8->pic2 base address //Re-maps the Programmable Interrupr Controllers so IRQ0->pic1 base address, IRG8->pic2 base address
void pic_remap(int pic1, int pic2) void pic_remap(int pic1, int pic2)

View File

@ -2,11 +2,12 @@
// Author: Josh Holtrop // Author: Josh Holtrop
// Created: 02/26/04 // Created: 02/26/04
#include "hos_defines.h"
#ifndef __HOS_PIC__ #ifndef __HOS_PIC__
#define __HOS_PIC__ __HOS_PIC__ #define __HOS_PIC__ __HOS_PIC__
#include "hos_defines.h"
#include "sys/io.h"
#define PIC1 0x20 #define PIC1 0x20
#define PIC2 0xA0 #define PIC2 0xA0
#define PIC1_COMMAND PIC1 #define PIC1_COMMAND PIC1
@ -28,32 +29,32 @@
#define ICW4_SFNM 0x10 /* Special fully nested (not) */ #define ICW4_SFNM 0x10 /* Special fully nested (not) */
void pic_remap(int pic1, int pic2); void pic_remap(int pic1, int pic2);
inline void pic_mask1(byte mask); //inline void pic_mask1(byte mask);
inline void pic_mask2(byte mask); //inline void pic_mask2(byte mask);
inline void pic_eoi(); //inline void pic_eoi();
inline void pic_eoi2(); //inline void pic_eoi2();
//Masks interrupts on first Programmable Interrupt Controller //Masks interrupts on first Programmable Interrupt Controller
inline void pic_mask1(byte mask) static inline void pic_mask1(byte mask)
{ {
outportb(PIC1_DATA, mask); //0x21, maskfield *OCW1* outportb(PIC1_DATA, mask); //0x21, maskfield *OCW1*
} }
//Masks interrupts on second Programmable Interrupt Controller //Masks interrupts on second Programmable Interrupt Controller
inline void pic_mask2(byte mask) static inline void pic_mask2(byte mask)
{ {
outportb(PIC2_DATA, mask); //0xA1, maskfield *OCW1* outportb(PIC2_DATA, mask); //0xA1, maskfield *OCW1*
} }
//Signals an End Of Interrupt signal to the first PIC //Signals an End Of Interrupt signal to the first PIC
inline void pic_eoi() static inline void pic_eoi()
{ {
outportb(0x20, 0x20); outportb(0x20, 0x20);
} }
//Signals an End Of Interrupt signal to both the second and first PIC unit //Signals an End Of Interrupt signal to both the second and first PIC unit
inline void pic_eoi2() static inline void pic_eoi2()
{ {
outportb(0xA0, 0x20); outportb(0xA0, 0x20);
outportb(0x20, 0x20); outportb(0x20, 0x20);

View File

@ -7,6 +7,7 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "rtc.h" #include "rtc.h"
#include "sys/io.h"
unsigned char rtc_readDay() unsigned char rtc_readDay()
{ {

View File

@ -4,6 +4,7 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "video.h" #include "video.h"
#include "video/stdfont.h"
ModeInfoBlock video_mode; ModeInfoBlock video_mode;
dword videoMode = 0; //what video mode # we are in, 0 for console mode dword videoMode = 0; //what video mode # we are in, 0 for console mode