From 3c531f3b7bb01d975a7834212e78e16e4cd09bb1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 17 Dec 2004 22:00:00 -0500 Subject: [PATCH] Import backup from 2004-12-17 --- Makefile | 2 +- kernel/boot.asm | 51 ++++++++++----------- kernel/kernel.c | 12 ++--- kernel/kernel.h | 1 - menu.lst | 2 +- readme.txt | 87 ----------------------------------- rmmod/rmmod.asm | 119 +++++++++++++++++++----------------------------- 7 files changed, 80 insertions(+), 194 deletions(-) delete mode 100644 readme.txt diff --git a/Makefile b/Makefile index 7289a5a..3814c25 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ install: install_img: -mkdir $(FLOPPY_MOUNT) - cp grub.flp $(FLOPPY_IMAGE) + cp $(GRUB_IMAGE) $(FLOPPY_IMAGE) mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) cp kernel/kernel.bin $(FLOPPY_MOUNT) cp rmmod/rmmod.bin $(FLOPPY_MOUNT) diff --git a/kernel/boot.asm b/kernel/boot.asm index 750f35f..a9e1a42 100644 --- a/kernel/boot.asm +++ b/kernel/boot.asm @@ -72,34 +72,33 @@ segmented_start: call _k_mbsave ;save multiboot info structures add esp, 8 - cmp eax, 0 ; eax = pointer to mb_module_t struct for rmmod + cmp eax, 0 ; eax = pointer to mb_module_t struct for rmmod jz pm_return ;go back to real mode to initialize video mode - mov ebx, eax ; pointer to mb_module_t - mov ecx, [ebx+4] ; end of module - mov eax, [ebx] ; start of module - mov esi, eax ; start of module - sub ecx, eax ; ecx = length of rmmod - shr ecx, 2 ; ecx = length of rmmod in dwords - mov edi, 0xC0005000 ; where to copy rmmod to (0x5000 physical) + mov ebx, eax ; pointer to mb_module_t + mov ecx, [ebx+4] ; end of module + mov eax, [ebx] ; start of module + mov esi, eax ; start of module + sub ecx, eax ; ecx = length of rmmod + shr ecx, 2 ; ecx = length of rmmod in dwords + mov edi, 0xC0005000 ; where to copy rmmod to (0x5000 physical) - rep movsd ; copy rmmod to first 1mb + rep movsd ; copy rmmod to first 1mb - mov ebx, pm_return ; return address - mov ecx, _rm_params ; put real mode params here (video mode etc...) + mov ebx, pm_return ; return address + mov ecx, _rm_params ; put real mode params here (video mode etc...) sub ecx, VIRT_OFFSET - mov edx, _initrd ; load the 'floppy' image here - sub edx, VIRT_OFFSET mov eax, cr0 - and eax, 0x7FFFFFFE ; leave PM + and eax, 0x7FFFFFFE ; leave PM mov cr0, eax - jmp 0x0:0x5010 ; jump to rmmod + jmp 0x0:0x5010 ; jump to rmmod ;Next we enable paging with the first 4mb mapped 1:1 virtual:physical ; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical. pm_return: + mov esp, STACK_V+0x1000 ;ok, now we can access our data again xor eax, eax mov edi, PDBR_V mov ecx, 1024 ;clear the PDBR @@ -133,28 +132,28 @@ fill_lopt_loop: ;fill the page table mov ecx, gdt_end-gdt rep movsb - mov edi, IDT_V ;destination - mov esi, isr_0 ;address of isr0 - mov edx, isr_1-isr_0 ;distance between isr labels - mov ecx, 50 ;number of isrlabels + mov edi, IDT_V ;destination + mov esi, isr_0 ;address of isr0 + mov edx, isr_1-isr_0 ;distance between isr labels + mov ecx, 50 ;number of isrlabels fill_idt: mov ebx, esi mov ax, si - stosw ;0 offset 15:0 + stosw ;0 offset 15:0 mov ax, KERNEL_CODE - stosw ;2 selector 15:0 + stosw ;2 selector 15:0 mov ax, 0x8E00 - stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0] + stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0] shr esi, 16 mov ax, si - stosw ;6 offset 31:16 + stosw ;6 offset 31:16 mov esi, ebx add esi, edx loop fill_idt mov word [IDT_V+0x30*8+4], 0xEE00 ;interrupt 0x30 has user priviledges ;Then we can start using our "real" gdt, then unmap the lower 4mb. - lgdt [gdtr] ;load gdt + lgdt [gdtr] ;load gdt jmp KERNEL_CODE:newgdtcontinue newgdtcontinue: mov ax, KERNEL_DATA @@ -167,9 +166,9 @@ newgdtcontinue: lidt [idtr] ;load idt mov [PDBR_V], dword 0 ;unmap 0x0, we are running completely paged at 0xC000_0000 - call _k_init ;C kernel initialization + call _k_init ;C kernel initialization -idle_loop: +idle_loop: ; system idle loop sti hlt jmp idle_loop diff --git a/kernel/kernel.c b/kernel/kernel.c index cd6f694..324f3ec 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -30,14 +30,13 @@ mb_mmap_t mb_mmap[MAX_MMAP]; u32_t mmap_entries; mb_module_t mb_modules[MAX_MODULES]; mb_apm_t mb_apm_table; -mb_module_t *real_mode_module; // pointer to real mode module (if present) +mb_module_t *real_mode_module; // pointer to real mode module (if present) real_mode_param_t rm_params; char mb_cmdline[256]; -int criticalCounter; // semaphore for if interrupts are disabled -u32_t timer; // number of IRQ 0's +int criticalCounter; // semaphore for if interrupts are disabled +u32_t timer; // number of IRQ 0's minor_t devfs_minor = -1; minor_t initrd_minor = -1; -byte initrd[2880*512]; // buffer in bss for loading a floppy image extern u32_t mm_freepages; @@ -115,12 +114,11 @@ void k_init() { if (rm_params.vid_mem) // there is video memory to map in vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (rm_params.vid_mem >> 12) + 1); - if (rm_params.initrd_loaded) // there is an initrd to register - initrd_minor = ramdisk_register(initrd, 2880*512); +// initrd_minor = ramdisk_register(initrd, 2880*512); } display_init(); //get us some virtual consoles to look at display_activate(11); - kprintf("HOS v0.15 initializing...\n"); + kprintf("HOS v0.16 initializing...\n"); kprintf("Kernel load size: %d (0x%x) bytes (%d kb)\n", kernel_size(), kernel_size(), kernel_size() >> 10); kprintf("Kernel memory size: %d (0x%x) bytes (%d kb)\n", kernel_size_used(), kernel_size_used(), kernel_size_used() >> 10); if ((devfs_minor = ramdisk_new(4096)) < 0) diff --git a/kernel/kernel.h b/kernel/kernel.h index de007d1..cfbc419 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -15,7 +15,6 @@ typedef struct { u32_t height; // height in pixels or columns if vid_mem == 0 u32_t vid_mem; // amount of memory for video buffer u32_t bpp; // bits per pixel - 16/24/32 - byte initrd_loaded; // did we load an initrd? } __attribute__ ((packed)) real_mode_param_t; /* returns true to callee if we should jump to a real mode module */ diff --git a/menu.lst b/menu.lst index 709d58c..bc56c19 100644 --- a/menu.lst +++ b/menu.lst @@ -2,7 +2,7 @@ timeout 10 default 0 -title HOS 0.15 +title HOS 0.16 root (fd0) kernel /kernel.bin #module /rmmod.bin diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 068024b..0000000 --- a/readme.txt +++ /dev/null @@ -1,87 +0,0 @@ -HOS - Holtrop's Operating System --------------------------------- - -HOS is (in the process of becoming) a 32-bit, protected mode, graphical, multitasking operating system. -It was written by me, Josh Holtrop, with help from a few others along the way. - - -Goals: (A = accomplished, P = in progress, T = todo) ----------------------------------------------------- -(A) Custom bootloader to load kernel from FAT-formatted boot media, options for video mode/ram disk -(A) Multiboot compliance - kernel can be loaded by GRUB -(A) 32-bit protected mode environment -(A) VESA Support for graphics modes -(A) PS/2 keyboard & mouse drivers -(A) Utilize x86's paging architecture for virtual memory management - -(P) Console Manager -(P) VFS abstraction layer for a single file system -(P) ram disk driver -(P) devfs file system driver -(P) ext2 file system support - -(T) vfat file system support -(T) Multitasking support -(T) HASH command shell -(T) Window Manager -(T) Various other utilities/applications -(T) Hard Drive (ATA) driver -(T) cdrom (ATAPI) driver - - -Change Log ----------- - -0.15 -07/10/04 - Multiboot support added, loadable by GRUB - -0.14 -05/21/04 - C++ support in kernel, can use classes & templates -04/04/04 - video_line function for diagonal lines -03/16/04 - new VFS design with support for a loop device -03/01/04 - Thanks to Ben Meyer for helping me get a Makefile working and building on linux to work! - -0.13 -01/26/04 - functions added to read/write CMOS clock date and time -01/19/04 - fixed bug GDTR/IDTR pointing to physical rather than linear table base address -01/07/04 - fixed bug not reading sectors correctly from floppy -12/28/03 - fixed bug not storing eax on interrupt -12/25/03 - fixed bug in mm_palloc() -12/25/03 - incorporated output functions as regular functions rather than as part of a linked library -12/23/03 - re-written physical memory manager using bitmap instead of stack -12/22/03 - kernel relocated to 3gb linear / 1mb+24kb physical to allow for app. address space - -0.12 -12/21/03 - sample bmp loader tested, works (tests loading a kernel of size ~ 932kb) -12/20/03 - GDT/IDT now located at 1mb physical, before kernel -10/30/03 - turns floppy motor off -10/30/03 - keyboard LEDs working -10/29/03 - paging functions working -10/15/03 - physical memory management page allocators working - -0.11 -10/09/03 - PS/2 mouse driver - -0.10 -09/11/03 - Rewritten C and assembly kernel with VESA GUI mode support, keyboard driver - -0.05 -05/14/03 - HGUI24/HGUI32 commands finished for testing GUI on both 24bpp and 32bpp graphics cards -05/14/03 - first web release! - -0.04 -03/09/03 - added VM shortcut command -03/09/03 - press up to fill retrieve last inputted command for Nate Scholten -03/08/03 - press clear to clear console input -03/07/03 - added "shortcut" commands PC, IC, ? for Nate Scholten -03/06/03 - added PROMPTC, INPUTC commands - -0.03 -12/30/02 - Command Line Interface working, accepting basic commands - -0.02 -12/11/02 - Assembly bootsector can load stage2 ("console") - -0.01 -12/01/02 - Real mode assembly bootsector boots from floppy disk successfully - diff --git a/rmmod/rmmod.asm b/rmmod/rmmod.asm index 9a78e60..372d441 100644 --- a/rmmod/rmmod.asm +++ b/rmmod/rmmod.asm @@ -14,7 +14,6 @@ ; ebx = return address ; ecx = where to store real mode parameter table -; edx = initrd, where to put ram disk start: jmp 0:start_refreshed start_refreshed: @@ -24,81 +23,28 @@ start_refreshed: mov ss, ax mov esp, 0x7000 mov [dat_rmadd], ecx - mov [dat_initrd], edx mov [dat_retn], ebx - sti - mov ah, 0 ;reset floppy controller - mov dl, 0 - int 0x13 -; xor ax, ax -; int 0x16 -; push txt_loading_initrd ;print loading initrd string -; push 23*80 -; call putString -; add sp, 4 + mov ebx, [dat_retn] + lgdt [gdtrbs32] + mov eax, cr0 + or eax, 0x01 + mov cr0, eax + jmp KERNEL_CODE_BS32:segmented_start +[bits 32] +segmented_start: + mov cx, KERNEL_DATA_BS32 + mov ss, cx + mov ds, cx + mov es, cx + mov gs, cx + mov fs, cx + jmp ebx -; push es ; draw a red bar to fill in -; mov ax, 0xb800 -; mov es, ax -; mov di, 24*160 -; mov cx, 80 -; mov ax, 0x04B0 -; rep stosw -; pop es - - mov cx, 80 ;80 cylinders to read - xor si, si ;start at cylinder 0 - mov edi, [dat_initrd] ;ram disk address -read_cylinder: - push cx - - mov bx, 0x1000 ;read sectors from head 0 - mov es, bx - xor bx, bx ;es:bx = data buffer for read - mov ax, 0x0212 ;ah = int 0x13 function 2, al = number of sectors to read - mov cx, si ;what cyl. we are on is now in cx - mov ch, cl ;ch = cyl. number - mov cl, 1 ;cl = sector number 1-63 - xor dx, dx ;dh = head number -; mov dl, 0 ;dl = drive number - int 0x13 - - mov bx, 0x1000 ;now read sectors from head 1 - mov es, bx - mov bx, 9216 ;es:bx = data buffer for read - mov ax, 0x0212 ;ah = int 0x13 function 2, al = number of sectors to read - mov cx, si ;what cyl. we are on is now in cx - mov ch, cl ;ch = cyl. number - mov cl, 1 ;cl = sector number 1-63 -; mov dh, 1 ;dh = head number -; mov dl, 0 ;dl = drive number - mov dx, 0x0100 - int 0x13 - - mov ebx, 0xb8000 ;draw a green block - add bx, si - shl bl, 1 - mov word [ds:ebx+160*24], 0x0200+219 - - push si - mov esi, 0x10000 ;now copy the disk up to where we will keep it - mov cx, 0x2400 -; rep o32 movsb - - pop si ;what cylinder# we are on... - inc si - pop cx -; loop read_cylinder - - xor ax, ax - int 0x16 - - mov al, 0xfe - out 0x64, al ;reboot +[bits 16] ; putString(int position, char *str) putString: push bp @@ -137,7 +83,38 @@ putString_loop_done: pop bp ret -txt_loading_initrd: db "Loading initrd... ", 0 +;------------------------------------------------------- +gdtrbs32: + dw gdt_endbs32-gdtbs32-1 + dd gdtbs32 +gdtbs32: ;null descriptor + dd 0 + dd 0 + + ;a base of 0x4000_0000, when added to 0xC000_0000 will produce 0x0000_0000 physical before paging in effect +KERNEL_CODE_BS32 equ $-gdtbs32 + db 0xff ;limit 7:0 + db 0xff ;limit 15:8 + db 0x00 ;base 7:0 + db 0x00 ;base 15:8 + db 0x00 ;base 23:16 + db 0x9a ;access + db 0xcf ;flags / limit 19:16 + db 0x40 ;base 31:24 + +KERNEL_DATA_BS32 equ $-gdtbs32 + db 0xff ;limit 7:0 + db 0xff ;limit 15:8 + db 0x00 ;base 7:0 + db 0x00 ;base 15:8 + db 0x00 ;base 23:16 + db 0x92 ;access + db 0xcf ;flags / limit 19:16 + db 0x40 ;base 31:24 + +gdt_endbs32: + + dat_rmadd dd 0 dat_initrd dd 0 dat_retn dd 0