From 692cf2fc08590d6bae89d0b6088853e8dbae1624 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 2 Jun 2005 22:00:00 -0400 Subject: [PATCH] Import backup from 2005-06-02 --- kernel/Makefile | 4 +- kernel/char/keyboard.c | 57 ++------------- kernel/char/keyboard.h | 35 +++++----- kernel/char/vconsole.cpp | 42 ++++++++---- kernel/char/vconsole.h | 6 +- kernel/devices.cpp | 2 + kernel/devices.h | 5 +- kernel/display/display.c | 104 +++++++++------------------- kernel/display/display.h | 11 ++- kernel/display/kout.c | 2 +- kernel/fs/ext2.h | 136 +++++++++++++++++++++++++++++++++++- kernel/fs/ext2_old.h | 8 +-- kernel/fs/vfs.cpp | 37 ++++++++++ kernel/fs/vfs.h | 62 ++++++++++++++++- kernel/fs/vfs_old.h | 52 -------------- kernel/hos_defines.h | 23 ++++--- kernel/kernel.c | 9 +-- kernel/lang/string.h | 3 + kernel/lang/vector.h | 145 +++++++++++++++++++++++++++++++++++++++ kernel/link.ld | 6 +- kernel/mm/mm.c | 5 +- kernel/mm/vmm.c | 2 +- 22 files changed, 512 insertions(+), 244 deletions(-) create mode 100644 kernel/lang/vector.h diff --git a/kernel/Makefile b/kernel/Makefile index bc45973..4c25972 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -22,7 +22,7 @@ all: Asm_Kernel C_Kernel @$(LD) $(LD_FLAGS) -Map kernel.map \ boot.o kernel.o lang_a.o mm.o vmm.o conv.o kout.o \ vconsole.o display.o devices.o pic.o keyboard.o \ - ramdisk.o vfs.o lang_c.o vesafb.o \ + ramdisk.o vfs.o lang_c.o \ string.o new.o ext2.o misc_char.o -o kernel.bin @echo ' Kernel built: ' `ls -sk kernel.bin | cut -d' ' -f1`kb @@ -51,8 +51,6 @@ C_Kernel: @$(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o @echo ' CC lang_c.o' @$(CC) $(CC_FLAGS) -c lang/lang.c -o lang_c.o - @echo ' CC vesafb.o' - @$(CC) $(CC_FLAGS) -c display/vesafb.c -o vesafb.o @echo ' CPP string.o' @$(CPP) $(CPP_FLAGS) -c lang/string.cpp -o string.o diff --git a/kernel/char/keyboard.c b/kernel/char/keyboard.c index cf76700..cf454b1 100644 --- a/kernel/char/keyboard.c +++ b/kernel/char/keyboard.c @@ -1,28 +1,21 @@ // keyboard.c // Author: Josh Holtrop // Created: 04/17/03 -// Modified: 08/16/04 +// Modified: 05/19/05 #include "hos_defines.h" #include "char/keyboard.h" #include "sys/io.h" // inportb, outportb #include "functions.h" #include "lang/conv.h" // asciiSwitchCase() - -#include "display/kout.h" +#include "display/kout.h" // kprintf() #include "display/display.h" // display_activate() -#define KBD_BUFFER_LENGTH 64 - u8_t kbdFlags = 0; // holds current keyboard flags - caps/num/scroll/shift/ctrl/alt u8_t lastWasE0 = 0; // was the last byte 0x0E ? -u32_t kbdBuffer[KBD_BUFFER_LENGTH]; // a buffer for all keypresses -int kbdBufferStart = 0; // position of next key in buffer -int kbdBufferLen = 0; // number of keys left in the buffer u8_t rawIgnore = 0; // how many signals to blatantly ignore u8_t ackReason = 0; // used to record the reason why we would get an acknowledge byte (0xFA) - //these arrays convert a keyboard scan code to an ASCII character value const u8_t SCAN2ASCII[129] = // for normal keys "\000\0331234567890-=\010\011" // null,esc,1234567890-=,bksp,tab @@ -83,7 +76,6 @@ void isr_keyboard() return; } - switch (kbdScan) // handle control keys { case KBD_SCAN_LSHIFT: @@ -111,6 +103,7 @@ void isr_keyboard() case KBD_SCAN_ALT + KBD_SCAN_RELEASED: kbdFlags &= (KBDF_ALT ^ 0xFF); break; + case KBD_SCAN_CAPS+KBD_SCAN_RELEASED: kbdFlags ^= KBDF_CAPS; kbd_resetLEDs(); // update LEDs @@ -142,48 +135,9 @@ void isr_keyboard() } if (kbdScan & KBD_SCAN_RELEASED) kbdAscii = 0; - if (kbdBufferLen < KBD_BUFFER_LENGTH) //no key slots available - kbdBuffer[(kbdBufferStart+kbdBufferLen++)%KBD_BUFFER_LENGTH] = (u32_t) ((kbdFlags << 16) | (kbdScan << 8) | kbdAscii); - - if (kbdAscii) - kprintf("%c", kbdAscii); -// if (kbdFlags & KBDF_ALT) -// { - if (kbdScan >= 0x3B && kbdScan <= 0x44) - display_activate(kbdScan - 0x3B); - if (kbdScan >= 0x57 && kbdScan <= 0x58) - display_activate(kbdScan - 0x4D); -// } -} - -//Gets a key from the buffer, returns 0 if no keys available, returns immediately -u32_t kbdGetKey() -{ - if (kbdBufferLen == 0) // buffer empty - return 0; - u32_t retVal = kbdBuffer[kbdBufferStart]; - kbdBufferStart++; - kbdBufferLen--; - if (kbdBufferStart >= KBD_BUFFER_LENGTH) - kbdBufferStart = 0; - return retVal; -} - -//Gets a key from the buffer, if no keys available, waits for one to be entered -u32_t kbdWaitKey() -{ - for (;;) - { - if (kbdBufferLen != 0) // buffer empty - break; - } - u32_t retVal = kbdBuffer[kbdBufferStart]; - kbdBufferStart++; - kbdBufferLen--; - if (kbdBufferStart >= KBD_BUFFER_LENGTH) - kbdBufferStart = 0; - return retVal; + // send a key event to the display subsystem + display_key_event((kbdFlags << 16) | (kbdScan << 8) | kbdAscii); } //Resets the keyboard LEDs to reflect the current state of the num lock, caps lock, and scroll lock bits @@ -195,4 +149,3 @@ void kbd_resetLEDs() - diff --git a/kernel/char/keyboard.h b/kernel/char/keyboard.h index 223e5b9..307b86a 100644 --- a/kernel/char/keyboard.h +++ b/kernel/char/keyboard.h @@ -1,35 +1,36 @@ // keyboard.h // Author: Josh Holtrop // Created: 04/17/03 -// Modified: 08/20/04 +// Modified: 05/19/05 #include "hos_defines.h" #ifndef __HOS_KEYBOARD__ #define __HOS_KEYBOARD__ __HOS_KEYBOARD__ -#define KBDF_SCROLL 0x01 -#define KBDF_NUM 0x02 -#define KBDF_CAPS 0x04 -#define KBDF_SHIFT 0x10 -#define KBDF_CTRL 0x20 -#define KBDF_ALT 0x40 +#define KBDF_SCROLL 0x01 +#define KBDF_NUM 0x02 +#define KBDF_CAPS 0x04 +#define KBDF_SHIFT 0x10 +#define KBDF_CTRL 0x20 +#define KBDF_ALT 0x40 -#define KBD_SCAN_RELEASED 0x80 +#define KBD_SCAN_RELEASED 0x80 -#define KBD_SCAN_CTRL 29 -#define KBD_SCAN_LSHIFT 42 -#define KBD_SCAN_RSHIFT 54 -#define KBD_SCAN_ALT 56 -#define KBD_SCAN_SCROLL 70 -#define KBD_SCAN_CAPS 58 -#define KBD_SCAN_NUM 69 +#define KBD_SCAN_CTRL 29 +#define KBD_SCAN_LSHIFT 42 +#define KBD_SCAN_RSHIFT 54 +#define KBD_SCAN_ALT 56 +#define KBD_SCAN_SCROLL 70 +#define KBD_SCAN_CAPS 58 +#define KBD_SCAN_NUM 69 +#define KBD_ASCII(x) ((x) & 0xFF) +#define KBD_SCAN(x) (((x) >> 8) & 0xFF) +#define KBD_FLAGS(x) (((x) >> 16) &0xFF) void isr_keyboard(); void kbd_resetLEDs(); -u32_t kbdGetKey(); -u32_t kbdWaitKey(); #endif diff --git a/kernel/char/vconsole.cpp b/kernel/char/vconsole.cpp index 7fbbb59..bd911bb 100644 --- a/kernel/char/vconsole.cpp +++ b/kernel/char/vconsole.cpp @@ -18,7 +18,6 @@ extern "C" #include "char/vconsole.h" VConsole *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs -extern int display_activeConsole; // display subsystem active virtual console number char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7}; void vconsole_setup(int width, int height) @@ -27,6 +26,22 @@ void vconsole_setup(int width, int height) vconsoles[i] = new VConsole(width, height); } +int vconsole_activate(u32_t id) +{ + if (id >= VCONSOLE_MAX) + return -1; + vconsoles[id]->activate(); + return 0; +} + +int vconsole_deactivate(u32_t id) +{ + if (id >= VCONSOLE_MAX) + return -1; + vconsoles[id]->deactivate(); + return 0; +} + VConsoleDriver::~VConsoleDriver() { for (int i = 0; i < VCONSOLE_MAX; i++) @@ -46,6 +61,7 @@ int VConsoleDriver::char_write(minor_t minor, int c) VConsole::VConsole(int width, int height) { myBuffer = new u16_t[width * height]; + myBuffer2 = NULL; myWidth = width; myHeight = height; myAttribute = myForeground = 0x07; @@ -63,12 +79,23 @@ VConsole::~VConsole() void VConsole::activate() { + if (myActive) // don't activate if already active + return; myActive = 1; + myBuffer2 = myBuffer; + myBuffer = (u16_t *)CONSOLE_MEMORY; + memcpyd(myBuffer, myBuffer2, (myWidth * myHeight) >> 1); + writeCursorPosition(myCursorPosition); } void VConsole::deactivate() { + if (!myActive) // don't deactivate non-active console + return; myActive = 0; + myBuffer = myBuffer2; + myBuffer2 = NULL; + memcpyd(myBuffer, (u16_t *)CONSOLE_MEMORY, (myWidth * myHeight) >> 1); } int VConsole::char_write(int c) @@ -110,12 +137,10 @@ int VConsole::char_write(int c) break; case 'J': // clear screen, home cursor memsetw(myBuffer, 0x0720, myWidth * myHeight); -// vconsole_draw(id); update_cursor_coord(0, 0); break; case 'K': // erase line from cursor position (including char. under cursor) to end of line memsetw(myBuffer + myCursorPosition, 0x0720, myWidth - cursorX); -// vconsole_draw(id); break; case 's': // push cursor position on an internal stack if (myCursorStackPosition < 16) @@ -202,8 +227,6 @@ void VConsole::put_char(int c) break; default: myBuffer[myCursorPosition] = c | (myAttribute << 8); -// if (myActive) -// display_console_put_char(c | (myAttribute << 8), myCursorPosition); update_cursor(myCursorPosition + 1); } } @@ -237,14 +260,9 @@ void VConsole::update_cursor(u16_t position) myCursorPosition -= myWidth; memcpyw(myBuffer, myBuffer + myWidth, myWidth * (myHeight - 1)); memsetw(myBuffer + (myWidth * (myHeight - 1)), 0x0720, myWidth); -// if (myActive) -// { -// vconsole_draw(id); -// return; -// } } -// if (myActive) -// display_console_update_cursor(id, position); + if (myActive) + writeCursorPosition(position); } void VConsole::update_attribute() diff --git a/kernel/char/vconsole.h b/kernel/char/vconsole.h index 7cd2c15..e9eba39 100644 --- a/kernel/char/vconsole.h +++ b/kernel/char/vconsole.h @@ -6,7 +6,7 @@ #ifndef __HOS_VCONSOLE__ #define __HOS_VCONSOLE__ __HOS_VCONSOLE__ -#define VCONSOLE_MAX 7 +#define VCONSOLE_MAX 12 #ifdef _HOS_CPP_ extern "C" { @@ -15,6 +15,9 @@ extern "C" { #include "hos_defines.h" void vconsole_setup(int width, int height); +int vconsole_activate(u32_t id); +int vconsole_deactivate(u32_t id); + #ifdef _HOS_CPP_ } @@ -32,6 +35,7 @@ class VConsole { protected: u16_t *myBuffer; + u16_t *myBuffer2; u16_t myWidth; u16_t myHeight; u16_t myCursorPosition; diff --git a/kernel/devices.cpp b/kernel/devices.cpp index a800e2e..a26e783 100644 --- a/kernel/devices.cpp +++ b/kernel/devices.cpp @@ -10,6 +10,7 @@ #include "devices.h" #include "char/misc_char.h" #include "char/vconsole.h" +#include "block/ramdisk.h" DeviceDriver *drivers[256]; @@ -17,6 +18,7 @@ int devices_init() { drivers[MAJOR_MISC_CHAR] = new MiscChar(); drivers[MAJOR_VCONSOLE] = new VConsoleDriver(); + drivers[MAJOR_RAMDISK] = new Ramdisk(); return 0; } diff --git a/kernel/devices.h b/kernel/devices.h index d323469..b1e2eb7 100644 --- a/kernel/devices.h +++ b/kernel/devices.h @@ -2,7 +2,7 @@ // Device subsystem for HOS // Author: Josh Holtrop // Date: 05/11/05 -// Modified: 05/11/05 +// Modified: 06/02/05 #ifndef __HOS_DEVICES_H__ #define __HOS_DEVICES_H__ __HOS_DEVICES_H__ @@ -20,6 +20,9 @@ #define BLOCK_SIZE 512 #define BLOCK_SIZE_LOG 9 +#define DEV_MAJOR (x) (((x) >> 8) & 0xFF) +#define DEV_MINOR (x) ((x) & 0xFF) + typedef short major_t; typedef short minor_t; typedef u32_t device_t; diff --git a/kernel/display/display.c b/kernel/display/display.c index 71c5f1f..1b5c8a0 100644 --- a/kernel/display/display.c +++ b/kernel/display/display.c @@ -9,27 +9,24 @@ #include "lang/lang.h" #include "kernel.h" #include "display/vesafb.h" +#include "char/keyboard.h" +#include "display/kout.h" extern real_mode_param_t rm_params; // check if a video mode is activated +int display_type; int display_activeConsole = -1; // start with no active console -display_t myDisplays[12]; // f1-f12 change displays + // initialization routine for display subsystem int display_init() { - int width = 80; - int height = 25; - int displayType = DISPLAY_CONSOLE; - if (rm_params.vid_addr) // framebuffer mode + if (!rm_params.vid_addr) // framebuffer mode { - vesafb_init(rm_params.width, rm_params.height, rm_params.bpp); - width = vesafb_getWidth(); - height = vesafb_getHeight(); - displayType = DISPLAY_FB; + vconsole_setup(80, 25); + display_activate(KERNEL_MSG_CONSOLE); } - vconsole_setup(width, height); -// vconsole_activate(0); - + else + display_type = DISPLAY_GRAPHICAL; return 0; } @@ -37,73 +34,40 @@ int display_init() // activate the given display int display_activate(u32_t id) { - if (id > 11) + if (id == display_activeConsole) + return 0; + if (display_type != DISPLAY_CONSOLE) return -1; - switch (myDisplays[id].type) + if (id >= VCONSOLE_MAX) + return -2; + if (display_activeConsole >= 0) + vconsole_deactivate(display_activeConsole); + if (vconsole_activate(id)) // if true, didn't work to activate console { - case DISPLAY_CONSOLE: - case DISPLAY_FB: - display_activeConsole = myDisplays[id].id; -// return vconsole_draw(display_activeConsole); - case DISPLAY_GRAPHICAL: - default: - return -2; + vconsole_activate(display_activeConsole); // restore old one + return -3; } + display_activeConsole = id; + return 0; } -// routine to refresh a console window -int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len) +void display_key_event(u32_t keyCode) { - if (id == display_activeConsole) + if (display_type == DISPLAY_CONSOLE) { - int i; - for (i = 0; i < 12; i++) + u32_t kbdScan = KBD_SCAN(keyCode); + if ( /* kbdFlags & KBDF_ALT && */ kbdScan >= 0x3B && kbdScan <= 0x44) // switch displays F1-F10 { - if (myDisplays[i].id == id) - { - if (myDisplays[i].type == DISPLAY_CONSOLE) - { - memcpyw((void *)CONSOLE_MEMORY, buffer, buff_len); - writeCursorPosition(cursorPosition); - return 0; - } - else if (myDisplays[i].type == DISPLAY_FB) - return vesafb_draw(buffer, buff_len, cursorPosition); - return -2; - } + display_activate(kbdScan - 0x3B); + return; + } + if ( /* kbdFlags & KBDF_ALT && */ kbdScan >= 0x57 && kbdScan <= 0x58) // F11-F12 + { + display_activate(kbdScan - 0x4D); + return; } } - return -1; + if (KBD_ASCII(keyCode)) + putc(KBD_ASCII(keyCode)); } - -// write a character to the screen -int display_console_put_char(minor_t id, u16_t c, int position) -{ - if (id == display_activeConsole) - { - if (myDisplays[id].type == DISPLAY_CONSOLE) - *(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c; - else if (myDisplays[id].type == DISPLAY_FB) - vesafb_draw_char(position, c); - return 0; - } - return -1; -} - - -// move the cursor on the screen -int display_console_update_cursor(minor_t id, int cursorPosition) -{ - if (id == display_activeConsole) - { - if (myDisplays[id].type == DISPLAY_CONSOLE) - writeCursorPosition(cursorPosition); - else if (myDisplays[id].type == DISPLAY_FB) - vesafb_update_cursor(cursorPosition); - return 0; - } - return -1; -} - - diff --git a/kernel/display/display.h b/kernel/display/display.h index 64e572d..0bdcdf0 100644 --- a/kernel/display/display.h +++ b/kernel/display/display.h @@ -9,10 +9,8 @@ #include "hos_defines.h" #include "devices.h" -#define DISPLAY_NULL 0 -#define DISPLAY_CONSOLE 1 -#define DISPLAY_FB 2 -#define DISPLAY_GRAPHICAL 3 +#define DISPLAY_CONSOLE 0 +#define DISPLAY_GRAPHICAL 1 typedef struct { @@ -22,9 +20,8 @@ typedef struct int display_init(); int display_activate(u32_t id); -int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len); -int display_console_put_char(minor_t id, u16_t c, int position); -int display_console_update_cursor(minor_t id, int cursorPosition); + +void display_key_event(u32_t keyCode); #endif diff --git a/kernel/display/kout.c b/kernel/display/kout.c index b646561..1a3351a 100644 --- a/kernel/display/kout.c +++ b/kernel/display/kout.c @@ -17,7 +17,7 @@ void putc(int c) #ifdef PARALLEL_DEBUG char_write(MAJOR_MISC_CHAR, MISC_CHAR_LP0, c); #endif - char_write(MAJOR_VCONSOLE, 1, c); // write to vconsole with minor 1, first allocated + char_write(MAJOR_VCONSOLE, KERNEL_MSG_CONSOLE, c); // write to vconsole with minor 1, first allocated } diff --git a/kernel/fs/ext2.h b/kernel/fs/ext2.h index 06f2cb2..13a0e95 100644 --- a/kernel/fs/ext2.h +++ b/kernel/fs/ext2.h @@ -2,17 +2,151 @@ // ext2 filesystem driver for HOS // Author: Josh Holtrop // Date: 05/10/05 -// Modified: 05/10/05 +// Modified: 05/23/05 #ifndef __HOS_EXT2_H__ #define __HOS_EXT2_H__ __HOS_EXT2_H__ +#define EXT2_MAGIC 0xEF53 +#define EXT2_NAME_LEN 255 + +#define EXT2_I_MODE_ATTR_MASK 0x0FFF +#define EXT2_I_MODE_OX 0x0001 +#define EXT2_I_MODE_OW 0x0002 +#define EXT2_I_MODE_OR 0x0004 +#define EXT2_I_MODE_GX 0x0008 +#define EXT2_I_MODE_GW 0x0010 +#define EXT2_I_MODE_GR 0x0020 +#define EXT2_I_MODE_UX 0x0040 +#define EXT2_I_MODE_UW 0x0080 +#define EXT2_I_MODE_UR 0x0100 +#define EXT2_I_MODE_STICKY 0x0200 +#define EXT2_I_MODE_SGID 0x0400 +#define EXT2_I_MODE_SUID 0x0800 + +#define EXT2_I_MODE_TYPE_MASK 0xF000 +#define EXT2_I_MODE_FIFO 0x1000 +#define EXT2_I_MODE_CHAR 0x2000 +#define EXT2_I_MODE_DIR 0x4000 +#define EXT2_I_MODE_BLOCK 0x6000 +#define EXT2_I_MODE_FILE 0x8000 +#define EXT2_I_MODE_SYM 0xA000 +#define EXT2_I_MODE_SOCK 0xC000 + +#define EXT2_I_FLAGS_SEC_DEL 0x01 +#define EXT2_I_FLAGS_UNDELETE 0x02 +#define EXT2_I_FLAGS_COMPRESS 0x04 +#define EXT2_I_FLAGS_SYNC 0x08 +#define EXT2_I_FLAGS_IMMUTABLE 0x10 +#define EXT2_I_FLAGS_APPEND 0x20 +#define EXT2_I_FLAGS_NODUMP 0x40 + +#define EXT2_INODE_BAD_BLOCKS 1 +#define EXT2_INODE_ROOT 2 +#define EXT2_INODE_ACL_INDEX 3 +#define EXT2_INODE_ACL_DATA 4 +#define EXT2_INODE_BOOT_LOADER 5 +#define EXT2_INODE_UNDELETE_DIR 6 +#define EXT2_INODE_AVAIL 11 + +#define EXT2_FT_UNKNOWN 0 +#define EXT2_FT_FILE 1 +#define EXT2_FT_DIR 2 +#define EXT2_FT_CHAR 3 +#define EXT2_FT_BLOCK 4 +#define EXT2_FT_FIFO 5 +#define EXT2_FT_SOCK 6 +#define EXT2_FT_SYMLINK 7 +#define EXT2_FT_MAX 8 + #include "vfs.h" +typedef struct +{ + u32_t s_inodes_count; /* Inodes count */ + u32_t s_blocks_count; /* Blocks count */ + u32_t s_r_blocks_count; /* Reserved blocks count */ + u32_t s_free_blocks_count; /* Free blocks count */ + u32_t s_free_inodes_count; /* Free inodes count */ + u32_t s_first_data_block; /* First Data Block */ + u32_t s_log_block_size; /* Block size: 0->1024, 1->2048, 2->4096 */ + int s_log_frag_size; /* Fragment size */ + u32_t s_blocks_per_group; /* # Blocks per group */ + u32_t s_frags_per_group; /* # Fragments per group */ + u32_t s_inodes_per_group; /* # Inodes per group */ + u32_t s_mtime; /* Mount time */ + u32_t s_wtime; /* Write time */ + u16_t s_mnt_count; /* Mount count */ + short s_max_mnt_count; /* Maximal mount count */ + u16_t s_magic; /* Magic signature */ + u16_t s_state; /* File system state */ + u16_t s_errors; /* Behaviour when detecting errors */ + u16_t s_minor_rev_level; /* minor revision level */ + u32_t s_lastcheck; /* time of last check */ + u32_t s_checkinterval; /* max. time between checks */ + u32_t s_creator_os; /* OS */ + u32_t s_rev_level; /* Revision level */ + u16_t s_def_resuid; /* Default uid for reserved blocks */ + u16_t s_def_resgid; /* Default gid for reserved blocks */ + + u32_t s_reserved[235]; +} ext2_super_block_t; + +typedef struct +{ + u32_t bg_block_bitmap; // Blocks bitmap block + u32_t bg_inode_bitmap; // Inode bitmap block + u32_t bg_inode_table; // Inode table block + u16_t bg_free_blocks_count; // Free blocks count + u16_t bg_free_inodes_count; // Free Inodes count + u16_t bg_used_dirs_count; // Directories count + u16_t bg_pad1; + u32_t bg_reserved[3]; +} ext2_group_desc_t; + +typedef struct +{ + u16_t i_mode; // File mode + u16_t i_uid; // Owner UID + u32_t i_size; // Size in bytes + u32_t i_atime; // Access time + u32_t i_ctime; // Creation time + u32_t i_mtime; // Modification time + u32_t i_dtime; // Deletion time + u16_t i_gid; // Group ID + u16_t i_links_count; // Links count + u32_t i_blocks; // Blocks count + u32_t i_flags; // File flags + u32_t i_reserved1; + u32_t i_block[15]; // Pointers to blocks (12 direct, single, double, triple indirect) + u32_t i_version; // File version (for NFS) + u32_t i_file_acl; // File ACL + u32_t i_dir_acl; // Directory ACL + u32_t i_faddr; // Fragment address + u8_t i_frag; // Fragment number + u8_t i_fsize; // Fragment size + u16_t i_pad1; + u32_t i_reserved2[2]; +} ext2_inode_t; + +typedef struct +{ + u32_t inode; // inode number + u16_t length; // directory entry length + u8_t name_length; // name length + u8_t file_type; // File type + char name[EXT2_NAME_LEN]; +} ext2_dir_entry_t; + + #ifdef _HOS_CPP_ class Ext2 : public FileSystem { +protected: + +public: + }; #endif diff --git a/kernel/fs/ext2_old.h b/kernel/fs/ext2_old.h index 15ca416..f51249d 100644 --- a/kernel/fs/ext2_old.h +++ b/kernel/fs/ext2_old.h @@ -75,11 +75,11 @@ typedef struct u32_t s_blocks_per_group; /* # Blocks per group */ u32_t s_frags_per_group; /* # Fragments per group */ u32_t s_inodes_per_group; /* # Inodes per group */ - u32_t s_mtime; /* Mount time */ - u32_t s_wtime; /* Write time */ + u32_t s_mtime; /* Mount time */ + u32_t s_wtime; /* Write time */ u16_t s_mnt_count; /* Mount count */ - short s_max_mnt_count; /* Maximal mount count */ - u16_t s_magic; /* Magic signature */ + short s_max_mnt_count; /* Maximal mount count */ + u16_t s_magic; /* Magic signature */ u16_t s_state; /* File system state */ u16_t s_errors; /* Behaviour when detecting errors */ u16_t s_minor_rev_level; /* minor revision level */ diff --git a/kernel/fs/vfs.cpp b/kernel/fs/vfs.cpp index e85d2f0..f896194 100644 --- a/kernel/fs/vfs.cpp +++ b/kernel/fs/vfs.cpp @@ -6,11 +6,48 @@ #define _HOS_CPP_ _HOS_CPP_ +extern "C" { #include "hos_defines.h" +#include "display/kout.h" +} + #include "vfs.h" +#include "lang/vector.h" +#include "lang/string.h" +#include "devices.h" + +inode_num_t rootInode; +vector *mountPoints; int vfs_init() { + mountPoints = new vector; return 0; } +int vfs_mount(device_t device, int fsType, char *mountPoint) +{ + string mountPt(mountPoint); + if (mountPt == "/") + { + + } + return 0; +} + +VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode) +{ + myDev = dev; + myFS = fs; + myRefs = 0; + myMountPoint = mountPoint; + myMountInode = mountInode; +} + +VFSMount::~VFSMount() +{ + if (myFS) + delete myFS; + if (myRefs) + kprintf("Filesystem uncleanly mounted from %s\n", myMountPoint.data()); +} diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h index 8172957..f1e7a33 100644 --- a/kernel/fs/vfs.h +++ b/kernel/fs/vfs.h @@ -7,20 +7,78 @@ #ifndef __HOS_VFS_H__ #define __HOS_VFS_H__ __HOS_VFS_H__ +#define FS_EXT2 1 + +#define VFS_FT_UNKNOWN 0 +#define VFS_FT_FILE 1 +#define VFS_FT_DIR 2 +#define VFS_FT_CHAR 3 +#define VFS_FT_BLOCK 4 +#define VFS_FT_FIFO 5 +#define VFS_FT_SOCK 6 +#define VFS_FT_SYMLINK 7 + +#define VFS_PERMS_OX 0x0001 +#define VFS_PERMS_OW 0x0002 +#define VFS_PERMS_OR 0x0004 +#define VFS_PERMS_GX 0x0008 +#define VFS_PERMS_GW 0x0010 +#define VFS_PERMS_GR 0x0020 +#define VFS_PERMS_UX 0x0040 +#define VFS_PERMS_UW 0x0080 +#define VFS_PERMS_UR 0x0100 +#define VFS_PERMS_STICKY 0x0200 +#define VFS_PERMS_SGID 0x0400 +#define VFS_PERMS_SUID 0x0800 + +#define EOF 1000000 + +#include "hos_defines.h" +#include "devices.h" + #ifdef _HOS_CPP_ extern "C" { #endif +typedef u64_t inode_num_t; + int vfs_init(); +int vfs_mount(device_t device, int fsType, char *mountPoint); #ifdef _HOS_CPP_ } +#include "lang/string.h" + class FileSystem { public: - FileSystem(); - ~FileSystem(); + FileSystem(device_t dev); + virtual ~FileSystem(); + + virtual u32_t totalBlocks(); /* 512 byte blocks */ + virtual u32_t usedBlocks(); + virtual u32_t freeBlocks(); + + virtual u32_t totalInodes(); + virtual u32_t usedInodes(); + virtual u32_t freeInodes(); + + virtual u32_t getRootInodeNumber(); +}; + +class VFSMount +{ +protected: + device_t myDev; + FileSystem *myFS; + int myRefs; + string myMountPoint; + inode_num_t myMountInode; + VFSMount +public: + VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode); + ~VFSMount(); }; #endif diff --git a/kernel/fs/vfs_old.h b/kernel/fs/vfs_old.h index 813593c..3985d0e 100644 --- a/kernel/fs/vfs_old.h +++ b/kernel/fs/vfs_old.h @@ -162,57 +162,5 @@ int vfs_read_block_file(vfs_open_file_t *open_file, void *buffer); int vfs_block_file_seek(vfs_open_file_t *open_file, u32_t block_number); int vfs_close_block_file(vfs_open_file_t *open_file); -#ifdef _HOS_CPP_ - -class FileSystem -{ -public: - FileSystem(); - virtual void out(); -}; - -FileSystem::FileSystem() -{ - kprintf("FileSystem()\n"); -} -void FileSystem::out() -{ - kprintf("I am a FileSystem object.\n"); -} - -class Ext2 : public FileSystem -{ -public: - Ext2(); - void out(); -}; - -Ext2::Ext2() -{ - kprintf("Ext2()\n"); -} -void Ext2::out() -{ - kprintf("I am an Ext2 object.\n"); -} - -class JoshsFS : public FileSystem -{ -public: - JoshsFS(); - void out(); -}; - -JoshsFS::JoshsFS() -{ - kprintf("JoshsFS()\n"); -} -void JoshsFS::out() -{ - kprintf("I am an JoshsFS object.\n"); -} - -#endif - #endif diff --git a/kernel/hos_defines.h b/kernel/hos_defines.h index 3771e7d..986d6cf 100644 --- a/kernel/hos_defines.h +++ b/kernel/hos_defines.h @@ -8,21 +8,22 @@ #define PARALLEL_DEBUG -#define HOS_TIMER_FREQ 1000 +#define HOS_TIMER_FREQ 1000 +#define KERNEL_MSG_CONSOLE 11 -#define VIRT_OFFSET 0xC0000000 -#define PHYS_LOAD 0x00108000 -#define HEAP_START 0xD0000000 -#define HEAP_LENGTH 0x20000000 +#define VIRT_OFFSET 0xC0000000 +#define PHYS_LOAD 0x00108000 +#define HEAP_START 0xD0000000 +#define HEAP_LENGTH 0x20000000 -#define CONSOLE_MEMORY 0xC00B8000 -#define BIOS_CHAR_MAP 0xC00FFA6E +#define CONSOLE_MEMORY 0xC00B8000 +#define BIOS_CHAR_MAP 0xC00FFA6E +#define LFB_MEMORY 0xF0000000 -#define MAX_MODULES 16 -#define MAX_MMAP 16 +#define MAX_MODULES 16 +#define MAX_MMAP 16 -#define NULL 0 -#define INT_MIN -42 +#define NULL 0 #define New(x) kcalloc(1, sizeof(x)) diff --git a/kernel/kernel.c b/kernel/kernel.c index 848789b..e2c4fbc 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -121,7 +121,7 @@ void k_init() vid_mem <<= 2; break; } // map in video memory so we can access the video card's LFB - vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (vid_mem >> 12) + 1); + vmm_mapn(LFB_MEMORY, (u32_t)rm_params.vid_addr, (vid_mem >> 12) + 1); } } display_init(); // initialize display subsystem @@ -136,15 +136,15 @@ void k_init() for (i = 0; i < mb_info_block.mods_count; i++) { kprintf("Loaded kernel module %d: 0x%x - 0x%x (%d bytes)\n", i, mb_modules[i].mod_start, mb_modules[i].mod_end, mb_modules[i].mod_end - mb_modules[i].mod_start); -/* if (((mb_modules[i].mod_end - mb_modules[i].mod_start) > 1024) && + if (((mb_modules[i].mod_end - mb_modules[i].mod_start) > 1024) && ((ext2_super_block_t *)(mb_modules[i].mod_start + 1024))->s_magic == EXT2_MAGIC) { // we found an initrd minor_t initrd_minor = ramdisk_register((void *)mb_modules[i].mod_start, mb_modules[i].mod_end - mb_modules[i].mod_start); kprintf("initrd (%dkb) loaded\n", (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 10); - k_check(vfs_mount(MAJORB_RAMDISK, initrd_minor, FS_EXT2, "/"), "Could not mount initrd to /!"); + k_check(vfs_mount((MAJOR_RAMDISK << 8) | initrd_minor, FS_EXT2, "/"), "Could not mount initrd to /!"); } -*/ } + } /* vfs_open_file_t *root = vfs_open_dir("////"); if (root) @@ -185,6 +185,7 @@ void k_init() else kprintf("Error: Could not open directory\n"); */ + criticalCounter--; } diff --git a/kernel/lang/string.h b/kernel/lang/string.h index e008758..ba5b1de 100644 --- a/kernel/lang/string.h +++ b/kernel/lang/string.h @@ -102,6 +102,9 @@ static inline bool operator<=(const char *cstring, const string & str) static inline bool operator>=(const char *cstring, const string & str) { return str <= cstring; } +static inline string operator+(const char *cstring, const string & str) +{ return string(cstring, str); } + #endif diff --git a/kernel/lang/vector.h b/kernel/lang/vector.h new file mode 100644 index 0000000..b26a535 --- /dev/null +++ b/kernel/lang/vector.h @@ -0,0 +1,145 @@ + +// vector.h +// implements c++ vector object for HOS +// Author: Josh Holtrop +// Date: 05/30/05 +// Modified: 05/30/05 + + +#ifndef __HOS_VECTOR__ +#define __HOS_VECTOR__ __HOS_VECTOR__ + +template +class vector +{ +protected: + /* Pointers to vector elements */ + type **myData; + + /* How many elements are present */ + unsigned int mySize; + + /* How many elements there are pointers for */ + unsigned int myAllocated; + + /* Causes the vector to double in its allocated size */ + void grow(); + +public: + /* Constructors/Destructor */ + vector(); + vector(unsigned int size); + ~vector(); + + /* Returns the size of the vector */ + unsigned int size() const; + + /* Add an element to the end of the vector */ + vector & add(type elem); + + /* Remove an element from the vector */ + vector & remove(unsigned int index); + + /* Insert an element into a position in the vector */ + vector & insert(type elem, unsigned int position); + + /* Direct access operators */ + const type & operator[](unsigned int index) const; + type & operator[](unsigned int index); + +}; + +template +vector::vector() +{ + myData = NULL; + mySize = 0; + myAllocated = 0; +} + +template +vector::vector(unsigned int size) +{ + myData = new (type *)[size]; + mySize = 0; + myAllocated = size; +} + +template +vector::~vector() +{ + for (unsigned int i = 0; i < mySize; i++) + delete myData[i]; + delete[] myData; +} + +template +u32_t vector::size() const +{ + return mySize; +} + +template +const type & vector::operator[](unsigned int index) const +{ + return *myData[index]; +} + +template +type & vector::operator[](unsigned int index) +{ + return *myData[index]; +} + +template +vector & vector::add(type elem) +{ + while (mySize >= myAllocated) + grow(); + myData[mySize++] = new type(elem); + return *this; +} + +template +void vector::grow() +{ + myAllocated <<= 1; + if (myAllocated == 0) + myAllocated = 1; + type **data_new = new (type *)[myAllocated]; + for (unsigned int i = 0; i < mySize; i++) + data_new[i] = myData[i]; + if (myData) + delete[] myData; + myData = data_new; +} + +template +vector & vector::remove(unsigned int index) +{ + if (index < mySize) + { + delete myData[index]; + for (unsigned int i = index; i < (mySize - 1); i++) + myData[i] = myData[i+1]; + mySize--; + } + return *this; +} + +template +vector & vector::insert(type elem, unsigned int position) +{ + if (position <= mySize) + { + if (mySize == myAllocated) + grow(); + for (unsigned int i = mySize; i > position; i--) + myData[i] = myData[i-1]; + myData[position] = new type(elem); + mySize++; + } + return *this; +} + +#endif diff --git a/kernel/link.ld b/kernel/link.ld index 61febd2..a9dafac 100644 --- a/kernel/link.ld +++ b/kernel/link.ld @@ -5,6 +5,10 @@ SECTIONS .text 0xC0108000 : { code = .; _code = .; __code = .; *(.text) +/* . = ALIGN(4096); */ + } + .gnulinkonce : { + *(.gnu.linkonce*) . = ALIGN(4096); } .data : { @@ -15,8 +19,8 @@ SECTIONS .rodata : { rodata = .; _rodata = .; __rodata = .; *(.rodata) - . = ALIGN(4096); } + . = ALIGN(4096); .bss : { bss = .; _bss = .; __bss = .; *(.bss) diff --git a/kernel/mm/mm.c b/kernel/mm/mm.c index a16ba4e..4762bbe 100644 --- a/kernel/mm/mm.c +++ b/kernel/mm/mm.c @@ -50,10 +50,7 @@ void mm_init() { mm_preserven(mb_modules[i].mod_start - VIRT_OFFSET, (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 12); } - if (mm_totalmem % 0x100000) - mm_megabytes = (mm_totalmem >> 20) + 1; - else - mm_megabytes = mm_totalmem >> 20; + mm_megabytes = (mm_totalmem >> 20) + ((mm_totalmem % 0x100000) ? 1 : 0); } diff --git a/kernel/mm/vmm.c b/kernel/mm/vmm.c index 73bc5a1..b030815 100644 --- a/kernel/mm/vmm.c +++ b/kernel/mm/vmm.c @@ -11,7 +11,7 @@ #include "mm/mm.h" int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start); -void *vmm_getFreeChunk(u32_t size); +void *vmm_getFreeChunk(u32_t size); void vmm_removeHeapEntry(u32_t queue, HeapEntry_t *he); int vmm_moreCore(u32_t size); int vmm_coalesceEntry(u32_t queue, HeapEntry_t *newHE);