...
 
Commits (2)
......@@ -3,13 +3,13 @@
# Requirements are nasm, and a i586 cross compiler
# Directions to download is at http://wiki.osdev.org/GCC_Cross-Compiler_on_Debian_Linux
C_COMPILER=i586-elf-gcc
C_COMPILER=i686-elf-gcc
ASM_COMPILER=nasm
LINKER=i586-elf-ld
LINKER=i686-elf-ld
CFLAGS=-I./src/include -fleading-underscore -O -ffreestanding -finline-functions-called-once -nostdlib
CFLAGS=-I./src/include -std=gnu99 -fleading-underscore -O -ffreestanding -finline-functions-called-once -nostdlib -Werror=implicit-function-declaration
LDFLAGS=-T./src/link.ld
ASFLAGS=-felf
ASFLAGS=-felf -I$(CURDIR)/src/
C_SOURCES = $(shell ls src/*.c)
ASM_SOURCES = $(shell ls src/*.s)
......
#!/bin/sh
# ScorchOS Build Script (Linux)
# Copyright (C) 2008-2011 ScorchOS Developers
# For Terms see License.txt
echo '> Starting Build...'
# This makes sure the user is root (needed for the loop-back mount of the floppy
# image I created earlier with a grub bootloader
#if test "`whoami`" != "root" ; then
# echo "You must be logged in as root to build (for loopback mounting)"
# echo "Enter 'su' or 'sudo bash' to switch to root"
# exit
#fi
# This build script requires the presence of a cross-compiler
echo '> Assembling and Compiling ScorchOS Kernel...'
# (Primis) I've added the makefile support here to consolidate the build scripts
make all
#echo '> Adding Kernel to Floppy Image...'
#Time for that loop-back mount!
rm -rf tmp-loop
mkdir tmp-loop &&
hdiutil attach -mountpoint tmp-loop disk_images/scorch.img
# Remove previous kernel.x before adding the new one...
cd tmp-loop
rm -rf kernel.x || exit
cd ..
cp bin/kernel.x tmp-loop/kernel.x || exit
# Move included program binaries onto the floppy image (will be used with ScorchOS 0.2)
#echo '> Moving binaries in Apps Directory to Floppy Image...'
#cp app/*.app tmp-loop
sleep 0.2
echo '> Unmounting Loop-back Floppy...'
# Unmount the loop-back floppy
umount tmp-loop || exit
rm -rf tmp-loop
#echo '> Quick Cleanup...'
# A quick cleanup (comment this out while debugging)
make clean
echo '> Build Complete!'
# ScorchOS Testing Script (Linux) - Requires Qemu (and additional kvm-pxe in Ubuntu Lucid)
# Copyright (C) 2008-2011 ScorchOS Developers
# For Terms see license.txt
#VBoxManage startvm "Test OS"
sudo qemu-system-i386 -fda disk_images/scorch.img -m 256 -monitor stdio -netdev tap,id=mynet0,script=tap-up,downscript=tap-down -net nic,model=rtl8139,netdev=mynet0 -usb -device ahci,id=ahci0 -drive if=none,file=/Users/mike/ScorchOS/disk_images/hd.raw,format=raw,id=drive-sata0-0-0 -device ide-drive,bus=ahci0.0,drive=drive-sata0-0-0,id=sata0-0-0 -boot order=ac
This diff is collapsed.
This diff is collapsed.
File added
//
// arp.c
//
//
// Created by Mike Evans on 5/20/15.
//
//
#include "arp.h"
uint8_t packet[4096];
uint16_t arp_point;
void sp()
{
arp_point=0;
}
void bp(uint8_t byte)
{
packet[arp_point++]=byte;
}
void * ep(uint16_t * packetsize)
{
*packetsize = arp_point;
return packet;
}
\ No newline at end of file
//
// arp.h
//
//
// Created by Mike Evans on 5/20/15.
//
//
#ifndef ____arp__
#define ____arp__
#include <stdint.h>
extern void sp();
extern void bp(uint8_t);
extern void * ep(uint16_t * packetsize);
#endif /* defined(____arp__) */
//****************************************************************************
//**
//** bpb.h
//** -Bios Paramater Block
//**
//****************************************************************************
#ifndef BPB_H
#define BPB_H
#include <stdint.h>
/**
* bios paramater block
*/
typedef struct _BIOS_PARAMATER_BLOCK {
uint8_t OEMName[8];
uint16_t BytesPerSector;
uint8_t SectorsPerCluster;
uint16_t ReservedSectors;
uint8_t NumberOfFats;
uint16_t NumDirEntries;
uint16_t NumSectors;
uint8_t Media;
uint16_t SectorsPerFat;
uint16_t SectorsPerTrack;
uint16_t HeadsPerCyl;
uint32_t HiddenSectors;
uint32_t LongSectors;
}__attribute__((packed)) BIOSPARAMATERBLOCK, *PBIOSPARAMATERBLOCK;
/**
* bios paramater block extended attributes
*/
typedef struct _BIOS_PARAMATER_BLOCK_EXT {
uint32_t SectorsPerFat32;
uint16_t Flags;
uint16_t Version;
uint32_t RootCluster;
uint16_t InfoCluster;
uint16_t BackupBoot;
uint16_t Reserved[6];
}__attribute__((packed)) BIOSPARAMATERBLOCKEXT, *PBIOSPARAMATERBLOCKEXT;
/**
* boot sector
*/
typedef struct _BOOT_SECTOR {
uint8_t Ignore[3]; //first 3 bytes are ignored
BIOSPARAMATERBLOCK Bpb;
BIOSPARAMATERBLOCKEXT BpbExt;
uint8_t Filler[448]; //needed to make struct 512 bytes
}__attribute__((packed)) BOOTSECTOR, *PBOOTSECTOR;
#endif
......@@ -6,6 +6,7 @@
*/
#include <system.h>
#include <stdint.h>
unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count)
{
......@@ -26,3 +27,52 @@ void outportb (unsigned short _port, unsigned char _data)
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
uint8_t inb (uint16_t port)
{
/* See [IA32-v2a] "IN". */
uint8_t data;
asm volatile ("inb %w1, %b0" : "=a" (data) : "Nd" (port));
return data;
}
void outb (uint16_t port, uint8_t data)
{
/* See [IA32-v2b] "OUT". */
asm volatile ("outb %b0, %w1" : : "a" (data), "Nd" (port));
}
uint16_t
inw (uint16_t port)
{
uint16_t data;
/* See [IA32-v2a] "IN". */
asm volatile ("inw %w1, %w0" : "=a" (data) : "Nd" (port));
return data;
}
void outw (uint16_t port, uint16_t data)
{
/* See [IA32-v2b] "OUT". */
asm volatile ("outw %w0, %w1" : : "a" (data), "Nd" (port));
}
uint32_t
inl (uint16_t port)
{
/* See [IA32-v2a] "IN". */
uint32_t data;
asm volatile ("inl %w1, %0" : "=a" (data) : "Nd" (port));
return data;
}
void
outl (uint16_t port, uint32_t data)
{
/* See [IA32-v2b] "OUT". */
asm volatile ("outl %0, %w1" : : "a" (data), "Nd" (port));
}
//****************************************************************************
//**
//** dma.cpp
//** 8237 ISA Direct Memory Access Controller (DMAC)
//**
//****************************************************************************
#include <system.h>
#include "dma.h"
//! masks a channel
void dma_mask_channel(uint8_t channel){
if (channel <= 4)
outportb(DMA0_CHANMASK_REG, (1 << (channel-1)));
else
outportb(DMA1_CHANMASK_REG, (1 << (channel-5)));
}
//! unmasks a channel
void dma_unmask_channel (uint8_t channel) {
if (channel <= 4)
outportb(DMA0_CHANMASK_REG, channel);
else
outportb(DMA1_CHANMASK_REG, channel);
}
//! unmasks all channels
void dma_unmask_all (int dma){
//! it doesnt matter what is written to this register
outportb(DMA1_UNMASK_ALL_REG, 0xff);
}
//! resets controller to defaults
void dma_reset (int dma){
//! it doesnt matter what is written to this register
outportb(DMA0_TEMP_REG, 0xff);
}
//! resets flipflop
void dma_reset_flipflop(int dma){
if (dma < 2)
return;
//! it doesnt matter what is written to this register
outportb( (dma==0) ? DMA0_CLEARBYTE_FLIPFLOP_REG : DMA1_CLEARBYTE_FLIPFLOP_REG, 0xff);
}
//! sets the address of a channel
void dma_set_address(uint8_t channel, uint8_t low, uint8_t high) {
if ( channel > 8 )
return;
unsigned short port = 0;
switch ( channel ) {
case 0: {port = DMA0_CHAN0_ADDR_REG; break;}
case 1: {port = DMA0_CHAN1_ADDR_REG; break;}
case 2: {port = DMA0_CHAN2_ADDR_REG; break;}
case 3: {port = DMA0_CHAN3_ADDR_REG; break;}
case 4: {port = DMA1_CHAN4_ADDR_REG; break;}
case 5: {port = DMA1_CHAN5_ADDR_REG; break;}
case 6: {port = DMA1_CHAN6_ADDR_REG; break;}
case 7: {port = DMA1_CHAN7_ADDR_REG; break;}
}
outportb(port, low);
outportb(port, high);
}
//! sets the counter of a channel
void dma_set_count(uint8_t channel, uint8_t low, uint8_t high) {
if ( channel > 8 )
return;
unsigned short port = 0;
switch ( channel ) {
case 0: {port = DMA0_CHAN0_COUNT_REG; break;}
case 1: {port = DMA0_CHAN1_COUNT_REG; break;}
case 2: {port = DMA0_CHAN2_COUNT_REG; break;}
case 3: {port = DMA0_CHAN3_COUNT_REG; break;}
case 4: {port = DMA1_CHAN4_COUNT_REG; break;}
case 5: {port = DMA1_CHAN5_COUNT_REG; break;}
case 6: {port = DMA1_CHAN6_COUNT_REG; break;}
case 7: {port = DMA1_CHAN7_COUNT_REG; break;}
}
outportb(port, low);
outportb(port, high);
}
void dma_set_mode (uint8_t channel, uint8_t mode) {
int dma = (channel < 4) ? 0 : 1;
int chan = (dma==0) ? channel : channel-4;
dma_mask_channel (channel);
outportb ( (channel < 4) ? (DMA0_MODE_REG) : DMA1_MODE_REG, chan | (mode) );
dma_unmask_all ( dma );
}
//! prepares channel for read
void dma_set_read (uint8_t channel) {
dma_set_mode (channel, DMA_MODE_READ_TRANSFER | DMA_MODE_TRANSFER_SINGLE);
}
//! prepares channel for write
void dma_set_write (uint8_t channel) {
dma_set_mode (channel,
DMA_MODE_WRITE_TRANSFER | DMA_MODE_TRANSFER_SINGLE);
}
//! writes to an external page register
void dma_set_external_page_register (uint8_t reg, uint8_t val) {
if (reg > 14)
return;
unsigned short port = 0;
switch ( reg ) {
case 1: {port = DMA_PAGE_CHAN1_ADDRBYTE2; break;}
case 2: {port = DMA_PAGE_CHAN2_ADDRBYTE2; break;}
case 3: {port = DMA_PAGE_CHAN3_ADDRBYTE2; break;}
case 4: {return;}//! nothing should ever write to register 4
case 5: {port = DMA_PAGE_CHAN5_ADDRBYTE2; break;}
case 6: {port = DMA_PAGE_CHAN6_ADDRBYTE2; break;}
case 7: {port = DMA_PAGE_CHAN7_ADDRBYTE2; break;}
}
outportb(port, val);
}
#ifndef _DMA_H_INCLUDED
# define _DMA_H_INCLUDED
//****************************************************************************
//**
//** dma.h
//** 8237 ISA Direct Memory Access Controller (DMAC)
//**
//****************************************************************************
//============================================================================
// INTERFACE REQUIRED HEADERS
//============================================================================
#include <stdint.h>
/**
* 2 DMACs, 32 bit master & 16bit slave each having 8 channels
*/
#define DMA_MAX_CHANNELS 16
#define DMA_CHANNELS_PER_DMAC 8
/**
* DMA0 address/count registers
*/
enum DMA0_CHANNEL_IO {
DMA0_CHAN0_ADDR_REG = 0, //! Thats right, i/o port 0
DMA0_CHAN0_COUNT_REG = 1,
DMA0_CHAN1_ADDR_REG = 2,
DMA0_CHAN1_COUNT_REG = 3,
DMA0_CHAN2_ADDR_REG = 4,
DMA0_CHAN2_COUNT_REG = 5,
DMA0_CHAN3_ADDR_REG = 6,
DMA0_CHAN3_COUNT_REG = 7,
};
/**
* Generic DMA0 registers
*/
enum DMA0_IO {
DMA0_STATUS_REG = 0x08,
DMA0_COMMAND_REG = 0x08,
DMA0_REQUEST_REG = 0x09,
DMA0_CHANMASK_REG = 0x0a,
DMA0_MODE_REG = 0x0b,
DMA0_CLEARBYTE_FLIPFLOP_REG = 0x0c,
DMA0_TEMP_REG = 0x0d,
DMA0_MASTER_CLEAR_REG = 0x0d,
DMA0_CLEAR_MASK_REG = 0x0e,
DMA0_MASK_REG = 0x0f
};
/**
* DMA1 address/count registers
*/
enum DMA1_CHANNEL_IO {
DMA1_CHAN4_ADDR_REG = 0xc0,
DMA1_CHAN4_COUNT_REG = 0xc2,
DMA1_CHAN5_ADDR_REG = 0xc4,
DMA1_CHAN5_COUNT_REG = 0xc6,
DMA1_CHAN6_ADDR_REG = 0xc8,
DMA1_CHAN6_COUNT_REG = 0xca,
DMA1_CHAN7_ADDR_REG = 0xcc,
DMA1_CHAN7_COUNT_REG = 0xce,
};
/**
* DMA External Page Registers
*/
enum DMA0_PAGE_REG {
DMA_PAGE_EXTRA0 = 0x80, //! Also diagnostics port
DMA_PAGE_CHAN2_ADDRBYTE2 = 0x81,
DMA_PAGE_CHAN3_ADDRBYTE2 = 0x82,
DMA_PAGE_CHAN1_ADDRBYTE2 = 0x83,
DMA_PAGE_EXTRA1 = 0x84,
DMA_PAGE_EXTRA2 = 0x85,
DMA_PAGE_EXTRA3 = 0x86,
DMA_PAGE_CHAN6_ADDRBYTE2 = 0x87,
DMA_PAGE_CHAN7_ADDRBYTE2 = 0x88,
DMA_PAGE_CHAN5_ADDRBYTE2 = 0x89,
DMA_PAGE_EXTRA4 = 0x8c,
DMA_PAGE_EXTRA5 = 0x8d,
DMA_PAGE_EXTRA6 = 0x8e,
DMA_PAGE_DRAM_REFRESH = 0x8f //!no longer used in new PCs
};
/**
* Generic DMA1 registers
*/
enum DMA1_IO {
DMA1_STATUS_REG = 0xd0,
DMA1_COMMAND_REG = 0xd0,
DMA1_REQUEST_REG = 0xd2,
DMA1_CHANMASK_REG = 0xd4,
DMA1_MODE_REG = 0xd6,
DMA1_CLEARBYTE_FLIPFLOP_REG = 0xd8,
DMA1_INTER_REG = 0xda,
DMA1_UNMASK_ALL_REG = 0xdc,
DMA1_MASK_REG = 0xde
};
/**
* DMA mode bit mask (Non MASK Values can be ORed together)
*/
enum DMA_MODE_REG_MASK {
DMA_MODE_MASK_SEL = 3,
DMA_MODE_MASK_TRA = 0xc,
DMA_MODE_SELF_TEST = 0,
DMA_MODE_READ_TRANSFER =4,
DMA_MODE_WRITE_TRANSFER = 8,
DMA_MODE_MASK_AUTO = 0x10,
DMA_MODE_MASK_IDEC = 0x20,
DMA_MODE_MASK = 0xc0,
DMA_MODE_TRANSFER_ON_DEMAND= 0,
DMA_MODE_TRANSFER_SINGLE = 0x40,
DMA_MODE_TRANSFER_BLOCK = 0x80,
DMA_MODE_TRANSFER_CASCADE = 0xC0
};
enum DMA_CMD_REG_MASK {
DMA_CMD_MASK_MEMTOMEM = 1,
DMA_CMD_MASK_CHAN0ADDRHOLD = 2,
DMA_CMD_MASK_ENABLE = 4,
DMA_CMD_MASK_TIMING = 8,
DMA_CMD_MASK_PRIORITY = 0x10,
DMA_CMD_MASK_WRITESEL = 0x20,
DMA_CMD_MASK_DREQ = 0x40,
DMA_CMD_MASK_DACK = 0x80
};
//! sets the mode of a channel
void dma_set_mode (uint8_t channel, uint8_t mode);
//! prepares for generic channel read
void dma_set_read (uint8_t channel);
//! prepares for generic channel write
void dma_set_write (uint8_t channel);
//! sets the address of a channel
void dma_set_address(uint8_t channel, uint8_t low, uint8_t high);
//! sets the counter of a channel
void dma_set_count(uint8_t channel, uint8_t low, uint8_t high);
//! masks a channel
void dma_mask_channel (uint8_t channel);
//! unmasks a channel
void dma_unmask_channel (uint8_t channel);
//! resets a flipflop
void dma_reset_flipflop (int dma);
//! reset the dma to defaults
void dma_reset (int dma);
//! sets an external page register
void dma_set_external_page_register (uint8_t reg, uint8_t val);
//! unmasks all registers
void dma_unmask_all (int dma);
#endif
This diff is collapsed.
//
// fat12.h
//
//
// Created by Mike Evans on 5/12/15.
//
//
#ifndef ____fat12__
#define ____fat12__
#include <system.h>
#include <stdint.h>
#include "fsys.h"
/**
* Directory entry
*/
typedef struct _DIRECTORY {
uint8_t Filename[8];
uint8_t Ext[3];
uint8_t Attrib;
uint8_t Reserved;
uint8_t TimeCreatedMs;
uint16_t TimeCreated;
uint16_t DateCreated;
uint16_t DateLastAccessed;
uint16_t FirstClusterHiBytes;
uint16_t LastModTime;
uint16_t LastModDate;
uint16_t FirstCluster;
uint32_t FileSize;
}__attribute__((packed)) DIRECTORY, *PDIRECTORY;
typedef struct _MOUNT_INFO {
uint32_t numSectors;
uint32_t fatOffset;
uint32_t numRootEntries;
uint32_t rootOffset;
uint32_t rootSize;
uint32_t fatSize;
uint32_t fatEntrySize;
}MOUNT_INFO, *PMOUNT_INFO;
extern FILE fsysFatDirectory (const char* DirectoryName);
extern void fsysFatRead(PFILE file, unsigned char* Buffer, unsigned int Length);
extern FILE fsysFatOpen (const char* FileName);
extern void fsysFatInitialize ();
extern void fsysFatMount ();
#endif /* defined(____fat12__) */
This diff is collapsed.
#ifndef _FLPYDSK_DRIVER_H
#define _FLPYDSK_DRIVER_H
//****************************************************************************
//**
//** flpydsk.h
//**
//****************************************************************************
//============================================================================
// INTERFACE REQUIRED HEADERS
//============================================================================
#include <stdint.h>
//============================================================================
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
//============================================================================
//============================================================================
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
//============================================================================
//============================================================================
// INTERFACE STRUCTURES / UTILITY CLASSES
//============================================================================
//============================================================================
// INTERFACE DATA DECLARATIONS
//============================================================================
//============================================================================
// INTERFACE FUNCTION PROTOTYPES
//============================================================================
//! install floppy driver
void flpydsk_install (int irq);
//! set current working drive
void flpydsk_set_working_drive (uint8_t drive);
//! get current working drive
uint8_t flpydsk_get_working_drive ();
//! read a sector
uint8_t* flpydsk_read_sector (int sectorLBA);
//! converts an LBA address to CHS
void flpydsk_lba_to_chs (int lba,int *head,int *track,int *sector);
//============================================================================
// INTERFACE OBJECT CLASS DEFINITIONS
//============================================================================
//============================================================================
// INTERFACE TRAILING HEADERS
//============================================================================
//****************************************************************************
//**
//** END [flpydsk.h]
//**
//****************************************************************************
#endif
//
// fsys.c
//
//
// Created by Mike Evans on 5/12/15.
//
//
#include <system.h>
#include "fsys.h"
#define DEVICE_MAX 26
//! File system list
PFILESYSTEM _FileSystems[DEVICE_MAX];
/**
* Opens a file
*/
FILE volOpenFile (const char* fname) {
if (fname) {
//! default to device 'a'
unsigned char device = 'a';
//! filename
char* filename = (char*) fname;
//! in all cases, if fname[1]==':' then the first character must be device letter
//! FIXME: Using fname[2] do to BUG 2. Please see main.cpp for info
if (fname[2]==':') {
device = fname[0];
filename += 3; //strip it from pathname
}
//! call filesystem
if (_FileSystems [device - 'a']) {
//! set volume specific information and return file
FILE file = _FileSystems[device - 'a']->Open (filename);
file.deviceID = device;
return file;
}
}
//! return invalid file
FILE file;
file.flags = FS_INVALID;
return file;
}
/**
* Reads file
*/
void volReadFile (PFILE file, unsigned char* Buffer, unsigned int Length) {
if (file)
if (_FileSystems [file->deviceID - 'a'])
_FileSystems[file->deviceID - 'a']->Read (file,Buffer,Length);
}
/**
* Close file
*/
void volCloseFile (PFILE file) {
if (file)
if (_FileSystems [file->deviceID - 'a'])
_FileSystems[file->deviceID - 'a']->Close (file);
}
/**
* Registers a filesystem
*/
void volRegisterFileSystem (PFILESYSTEM fsys, unsigned int deviceID) {
static int i=0;
if (i < DEVICE_MAX)
if (fsys) {
_FileSystems[ deviceID ] = fsys;
i++;
}
}
/**
* Unregister file system
*/
void volUnregisterFileSystem (PFILESYSTEM fsys) {
for (int i=0;i < DEVICE_MAX; i++)
if (_FileSystems[i]==fsys)
_FileSystems[i]=0;
}
/**
* Unregister file system
*/
void volUnregisterFileSystemByID (unsigned int deviceID) {
if (deviceID < DEVICE_MAX)
_FileSystems [deviceID] = 0;
}
//
// fsys.h
//
//
// Created by Mike Evans on 5/12/15.
//
//
#ifndef ____fsys__
#define ____fsys__
#include <stdint.h>
/**
* File
*/
typedef struct _FILE {
char name[32];
uint32_t flags;
uint32_t fileLength;
uint32_t id;
uint32_t eof;
uint32_t position;
uint32_t currentCluster;
uint32_t deviceID;
}FILE, *PFILE;
/**
* Filesystem interface
*/
typedef struct _FILE_SYSTEM {
char Name [8];
FILE (*Directory) (const char* DirectoryName);
void (*Mount) ();
void (*Read) (PFILE file, unsigned char* Buffer, unsigned int Length);
void (*Close) (PFILE);
FILE (*Open) (const char* FileName);
}FILESYSTEM, *PFILESYSTEM;
/**
* File flags
*/
#define FS_FILE 0
#define FS_DIRECTORY 1
#define FS_INVALID 2
extern FILE volOpenFile (const char* fname);
extern void volReadFile (PFILE file, unsigned char* Buffer, unsigned int Length);
extern void volCloseFile (PFILE file);
extern void volRegisterFileSystem (PFILESYSTEM, unsigned int deviceID);
extern void volUnregisterFileSystem (PFILESYSTEM);
extern void volUnregisterFileSystemByID (unsigned int deviceID);
#endif /* defined(____fsys__) */
......@@ -25,7 +25,7 @@ struct gdt_ptr
unsigned int base;
} __attribute__((packed));
struct gdt_entry gdt[3]; // 3 Entry GDT; Null, Code, & Data
struct gdt_entry gdt[5]; // 3 Entry GDT; Null, Code, & Data
struct gdt_ptr gp; // Pointer to that GDT
extern void gdt_flush(); // Function in start.s
......@@ -56,6 +56,9 @@ void gdt_install()
gdt_set_gate(0, 0, 0, 0, 0); // 1st Descriptor is null
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code Segment, Kernel Mode
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data Segment, Kernel Mode
gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // Code Segment, User Mode
gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // Data Segment, User Mode
gdt_flush(); // Tell CPU we have a new GDT
}
......
#include <system.h>
#include <stdint.h>
#include "pmm.h"
#include "vmm.h"
#define KHEAP 0xC8000000
uint32_t heaptop;
bool init_heap()
{
heaptop=KHEAP;
return true;
}
int liballoc_lock()
{
//TODO !
//pthread_mutex_lock( &mutex );
return 0;
}
int liballoc_unlock()
{
//TODO !
//pthread_mutex_unlock( &mutex );
return 0;
}
void* liballoc_alloc( int pages )
{
unsigned int size = pages * PAGE_SIZE;
void * outmem;
bool valid= vmmngr_alloc_pages_at_virtual_address(pages,heaptop);
if(valid)
{
outmem=(void*)heaptop;
heaptop+=PAGE_SIZE*pages;
}
return outmem;
}
int liballoc_free( void* ptr, int pages )
{
if(vmmngr_dealloc_pages_at_virtual_address(pages,ptr)) return 1;
return 0;
}
#ifndef __CTYPE_H
#define __CTYPE_H
//****************************************************************************
//**
//** ctype.h
//** - character macros
//**
//****************************************************************************
//============================================================================
// INTERFACE REQUIRED HEADERS
//============================================================================
//============================================================================
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
//============================================================================
#ifdef _MSC_VER
// Get rid of conversion warnings
#pragma warning (disable:4244)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#define isspace(c) ((c) == ' ' || ((c) >= '\t' && (c) <= '\r'))
#define isascii(c) (((c) & ~0x7f) == 0)
#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#define islower(c) ((c) >= 'a' && (c) <= 'z')
#define isalpha(c) (isupper(c) || islower(c))
#define isdigit(c) ((c) >= '0' && (c) <= '9')
#define isxdigit(c) (isdigit(c) \
|| ((c) >= 'A' && (c) <= 'F') \
|| ((c) >= 'a' && (c) <= 'f'))
#define isprint(c) ((c) >= ' ' && (c) <= '~')
#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
#define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))
#define isascii(c) ((unsigned)(c) <= 0x7F)
#define toascii(c) ((unsigned)(c) & 0x7F)
#if 0
extern unsigned short _ctype[];
/* Constants */
#define _UPPER 0x1 // Upper case letter
#define _LOWER 0x2 // Lower case letter
#define _DIGIT 0x4 // Digit[0-9]
#define _SPACE 0x8 // Tab, carriage return, newline, vertical tab or form feed
#define _PUNCT 0x10 // Punctuation character
#define _CONTROL 0x20 // Control character
#define _BLANK 0x40 // Space char
#define _HEX 0x80 // Hexadecimal digit
#define _LEADBYTE 0x8000 // Multibyte leadbyte
#define _ALPHA (0x0100 | _UPPER| _LOWER) // Alphabetic character
#define CT_UP 0x01 /* upper case */
#define CT_LOW 0x02 /* lower case */
#define CT_DIG 0x04 /* digit */
#define CT_CTL 0x08 /* control */
#define CT_PUN 0x10 /* punctuation */
#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */
#define CT_HEX 0x40 /* hex digit */
#define CT_SP 0x80 /* hard space (0x20) */
/* Basic macros */
#define isalnum(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG))
#define isalpha(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW))
#define iscntrl(c) ((_ctype + 1)[(unsigned)(c)] & (CT_CTL))
#define isdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG))
#define isgraph(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG))
#define islower(c) ((_ctype + 1)[(unsigned)(c)] & (CT_LOW))
#define isprint(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP))
#define ispunct(c) ((_ctype + 1)[(unsigned)(c)] & (CT_PUN))
#define isspace(c) ((_ctype + 1)[(unsigned)(c)] & (CT_WHT))
#define isupper(c) ((_ctype + 1)[(unsigned)(c)] & (CT_UP))
#define isxdigit(c) ((_ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX))
#endif
#ifdef __cplusplus
}
#endif
//============================================================================
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
//============================================================================
//============================================================================
// INTERFACE STRUCTURES / UTILITY CLASSES
//============================================================================
//============================================================================
// INTERFACE DATA DECLARATIONS
//============================================================================
//============================================================================
// INTERFACE FUNCTION PROTOTYPES
//============================================================================
//============================================================================
// INTERFACE OBJECT CLASS DEFINITIONS
//============================================================================
//============================================================================
// INTERFACE TRAILING HEADERS
//============================================================================
//****************************************************************************
//**
//** END ctype.h
//**
//****************************************************************************
#endif
#ifndef STDBOOL_H_
#define STDBOOL_H_
/**
* stdbool.h
* Author - Yaping Xin
* E-mail - xinyp at live dot com
* Date - February 10, 2014
* Copyright - You are free to use for any purpose except illegal acts
* Warrenty - None: don't blame me if it breaks something
*
* In ISO C99, stdbool.h is a standard header and _Bool is a keyword, but
* some compilers don't offer these yet. This header file is an
* implementation of the stdbool.h header file.
*
*/
#ifndef _Bool
//typedef unsigned char _Bool;
#endif /* _Bool */
/**
* Define the Boolean macros only if they are not already defined.
*/
#ifndef __bool_true_false_are_defined
#define bool _Bool
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif /* __bool_true_false_are_defined */
#endif /* STDBOOL_H_ */
\ No newline at end of file
#ifndef _STDINT_H
#define _STDINT_H
#define __need_wint_t
#define __need_wchar_t
#include <stdbool.h>
//****************************************************************************
//**
//** stdint.h
//** - Standard C++ integral types
//**
//****************************************************************************
//============================================================================
// INTERFACE REQUIRED HEADERS
//============================================================================
//============================================================================
// INTERFACE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
//============================================================================
/* 7.18.1.1 Exact-width integer types */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
typedef long long int_least64_t;
typedef unsigned long long uint_least64_t;
/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef char int_fast8_t;
typedef unsigned char uint_fast8_t;
typedef short int_fast16_t;
typedef unsigned short uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
typedef long long int_fast64_t;
typedef unsigned long long uint_fast64_t;
/* 7.18.1.4 Integer types capable of holding object pointers */
typedef int intptr_t;
typedef unsigned uintptr_t;
/* 7.18.1.5 Greatest-width integer types */
typedef long long intmax_t;
typedef unsigned long long uintmax_t;
/* 7.18.2 Limits of specified-width integer types */
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
/* 7.18.2.1 Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
/* 7.18.2.2 Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* 7.18.2.3 Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* 7.18.2.4 Limits of integer types capable of holding
object pointers */
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
/* 7.18.2.5 Limits of greatest-width integer types */
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
/* 7.18.3 Limits of other integer types */
#define PTRDIFF_MIN INT32_MIN
#define PTRDIFF_MAX INT32_MAX
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#define SIZE_MAX UINT32_MAX
#ifndef WCHAR_MIN /* also in wchar.h */
#define WCHAR_MIN 0
#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */
#endif
/*
* wint_t is unsigned short for compatibility with MS runtime
*/
#define WINT_MIN 0
#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
/* 7.18.4 Macros for integer constants */
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
/* 7.18.4.1 Macros for minimum-width integer constants */
#define INT8_C(val) ((int8_t) + (val))
#define UINT8_C(val) ((uint8_t) + (val##U))
#define INT16_C(val) ((int16_t) + (val))
#define UINT16_C(val) ((uint16_t) + (val##U))
#define INT32_C(val) val##L
#define UINT32_C(val) val##UL
#define INT64_C(val) val##LL
#define UINT64_C(val) val##ULL
/* 7.18.4.2 Macros for greatest-width integer constants */
#define INTMAX_C(val) INT64_C(val)
#define UINTMAX_C(val) UINT64_C(val)
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
//! Set bit
inline uint8_t SetBit(uint8_t word, uint8_t mask) {
return word | mask;
}
//! Clears bit
inline uint8_t ClrBit(uint8_t word, uint8_t mask) {
return word & (~mask);
}
//! Assigns the bit defined in mask to a value
inline uint8_t AssignBit(uint8_t word, uint8_t mask, bool value) {
return value ? SetBit(word, mask) : ClrBit(word, mask);
}
//============================================================================
// INTERFACE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
//============================================================================
//============================================================================
// INTERFACE STRUCTURES / UTILITY CLASSES
//============================================================================
//============================================================================
// INTERFACE DATA DECLARATIONS
//============================================================================
//============================================================================
// INTERFACE FUNCTION PROTOTYPES
//============================================================================
//============================================================================
// INTERFACE OBJECT CLASS DEFINITIONS
//============================================================================
//============================================================================
// INTERFACE TRAILING HEADERS
//============================================================================
//****************************************************************************
//**
//** END stdint.h
//**
//****************************************************************************
#endif
/*
** Copyright 2008-12 ScorchOS Developers
** See doc/License.txt for terms of use.
......@@ -9,6 +10,8 @@
#include <mboot.h>
#include <command.h>
#include <stdint.h>
typedef int size_t;
......@@ -25,6 +28,22 @@ struct regs
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count);
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data);
extern uint32_t inl (uint16_t port);
extern void outl (uint16_t port, uint32_t data);
extern uint16_t inw (uint16_t port);
extern void outw (uint16_t port, uint16_t data);
extern void outb (uint16_t port, uint8_t data);
extern uint8_t inb (uint16_t port);
/* HEAP.C */
extern bool init_heap(void);
extern void *malloc(size_t); //< The standard function.
extern void *realloc(void *, size_t); //< The standard function.
extern void *calloc(size_t, size_t); //< The standard function.
extern void free(void *); //< The standard function.
/* SCRN.C */
extern void init_video(void);
......@@ -34,6 +53,13 @@ extern void putch(char c);
extern void cls();
extern void shell_csr_fix();
extern void putd(int n);
extern void itoa(unsigned i,unsigned base,char* buf);
extern void pad (char * instr,int padnum, char padchar);
extern void putx(int n);
extern void putlx(long long n);
extern void moveto(int x, int y);
extern void pushcsr();
extern void popcsr();
/* GDT.C */
extern void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
......@@ -52,7 +78,7 @@ extern void irq_uninstall_handler(int irq);
extern void irq_install();
/* TIMER.C */
extern void timer_wait(int ticks);
extern void wait(int ticks);
extern void timer_install();
/* KB.C */
......
//
// inet.h
//
//
// Created by Mike Evans on 5/20/15.
//
//
#ifndef _inet_h
#define _inet_h
#define HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
#define NTOHS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))
#define NTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))
#endif
......@@ -7,6 +7,80 @@
#include <system.h>
#include <kb.h>
#include "pmm.h"
#include "vmm.h"
#include "pci.h"
#include "flpydsk.h"
#include "fat12.h"
#include "rtl8139.h"
extern unsigned int endkernel;
extern unsigned int startkernel;
unsigned int sizekernel;
void cmd_read () {
//! get pathname
char path[]="test.txt";
//DebugPrintf ("\n\rex: \"file.txt\", \"a:\\file.txt\", \"a:\\folder\\file.txt\"\n\rFilename> ");
//get_cmd (path,32);
puts(path);
//! open file
FILE file = volOpenFile (path);
//! test for invalid file
if (file.flags == FS_INVALID) {
puts("\n\rUnable to open file");
return;
}
//! cant display directories
if (( file.flags & FS_DIRECTORY ) == FS_DIRECTORY) {
puts("\n\rUnable to display contents of directory.");
return;
}
//! top line
puts ("\n\n\r-------[");
puts(file.name);
puts("]-------\n\r");
//! display file contents
while (file.eof != 1) {
//! read cluster
unsigned char buf[512];
volReadFile ( &file, buf, 512);
//! display file
for (int i=0; i<512; i++)
putch (buf[i]);
// //! wait for input to continue if not EOF
// if (file.eof != 1) {
// puts ("\n\r------[Press a key to continue]------");
// getch ();
// DebugPrintf ("\r"); //clear last line
// }
}
//! done :)
puts("\n\n\r--------[EOF]--------");
}
char username [32];
int prompt;
......@@ -26,6 +100,7 @@ int main(void* mbd, unsigned int magic)
{
mbi = (multiboot_info_t *) mbd;
}
gdt_install();
idt_install();
isrs_install();
......@@ -33,13 +108,119 @@ int main(void* mbd, unsigned int magic)
init_video();
timer_install();
keyboard_install();
__asm__ __volatile__ ("sti");
//! set drive 0 as current drive
//flpydsk_set_working_drive (0);
//! install floppy disk to IR 38, uses IRQ 6
//flpydsk_install (6);
initShell();
puts("\n\t\t\tWelcome to ScorchOS 0.1.5!\n");
puts("\t\t\t(C)2008-12 ScorchOS Developers\n\n");
//initShell();
char tempbuf[64];
sizekernel = (unsigned int)&endkernel - (unsigned int) &startkernel;
puts("KERNEL SIZE : ");
putd(sizekernel);
puts("\nBIOS MEMORY INFO: ");
unsigned int mem_kb = mbi->mem_lower + mbi->mem_upper;
putd(mem_kb);
puts("KB\n");
pmmngr_init ((size_t) mem_kb, 0xC0100000 + sizekernel);
if(mbi&&MULTIBOOT_INFO_MEM_MAP)
{
int region_count=mbi->mmap_length/sizeof(multiboot_memory_map_t);
multiboot_memory_map_t * mmap_item = (multiboot_memory_map_t *) mbi->mmap_addr;
for(int i=0;i<region_count;++i)
{
unsigned int lownib = (mmap_item[i].addr & 0xFFFFFFFF);
unsigned int highnib=(mmap_item[i].addr>>32) & 0xFFFFFFFF;
unsigned int startLo;
unsigned int sizeLo;
startLo=lownib;
lownib = (mmap_item[i].len & 0xFFFFFFFF);
highnib=(mmap_item[i].len >>32) & 0xFFFFFFFF;
sizeLo=lownib;
if (mmap_item[i].type==1)
{
pmmngr_init_region (startLo, sizeLo);
}
}
}
pmmngr_deinit_region (0x100000, sizekernel);
pmmngr_deinit_region (0x0, 0x10000);
vmmngr_initialize();
puts("\nTotal Blocks: ");
putd(pmmngr_get_block_count());
puts("\nFree Blocks: ");
putd(pmmngr_get_free_block_count());
puts("\nUsed Blocks: ");
putd(pmmngr_get_use_block_count());
puts("\n");
init_heap();
uint32_t * testvar = malloc(sizeof(uint32_t));
*testvar=0x12345678;
__asm__ __volatile__ ("sti");
puts("\nFree Blocks: ");
putd(pmmngr_get_free_block_count());
puts("\nUsed Blocks: ");
putd(pmmngr_get_use_block_count());
puts("\n");
init_pci();
//fsysFatInitialize ();
// puts("\n\t\t\tWelcome to ScorchOS 0.1.5!\n");
// puts("\t\t\t(C)2008-12 ScorchOS Developers\n\n");
while(1) {
runShell();
}
......
This diff is collapsed.
#ifndef _LIBALLOC_H
#define _LIBALLOC_H
// If we are told to not define our own size_t, then we
// skip the define.
#ifndef _ALLOC_SKIP_DEFINE
#ifndef _HAVE_SIZE_T
#define _HAVE_SIZE_T
typedef unsigned int size_t;
#endif