Import backup from 2004-12-17

This commit is contained in:
Josh Holtrop 2004-12-17 22:00:00 -05:00
parent 11cc0c87f3
commit 3c531f3b7b
7 changed files with 80 additions and 194 deletions

View File

@ -42,7 +42,7 @@ install:
install_img: install_img:
-mkdir $(FLOPPY_MOUNT) -mkdir $(FLOPPY_MOUNT)
cp grub.flp $(FLOPPY_IMAGE) cp $(GRUB_IMAGE) $(FLOPPY_IMAGE)
mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT)
cp kernel/kernel.bin $(FLOPPY_MOUNT) cp kernel/kernel.bin $(FLOPPY_MOUNT)
cp rmmod/rmmod.bin $(FLOPPY_MOUNT) cp rmmod/rmmod.bin $(FLOPPY_MOUNT)

View File

@ -72,34 +72,33 @@ segmented_start:
call _k_mbsave ;save multiboot info structures call _k_mbsave ;save multiboot info structures
add esp, 8 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 jz pm_return
;go back to real mode to initialize video mode ;go back to real mode to initialize video mode
mov ebx, eax ; pointer to mb_module_t mov ebx, eax ; pointer to mb_module_t
mov ecx, [ebx+4] ; end of module mov ecx, [ebx+4] ; end of module
mov eax, [ebx] ; start of module mov eax, [ebx] ; start of module
mov esi, eax ; start of module mov esi, eax ; start of module
sub ecx, eax ; ecx = length of rmmod sub ecx, eax ; ecx = length of rmmod
shr ecx, 2 ; ecx = length of rmmod in dwords shr ecx, 2 ; ecx = length of rmmod in dwords
mov edi, 0xC0005000 ; where to copy rmmod to (0x5000 physical) 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 ebx, pm_return ; return address
mov ecx, _rm_params ; put real mode params here (video mode etc...) mov ecx, _rm_params ; put real mode params here (video mode etc...)
sub ecx, VIRT_OFFSET sub ecx, VIRT_OFFSET
mov edx, _initrd ; load the 'floppy' image here
sub edx, VIRT_OFFSET
mov eax, cr0 mov eax, cr0
and eax, 0x7FFFFFFE ; leave PM and eax, 0x7FFFFFFE ; leave PM
mov cr0, eax 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 ;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. ; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical.
pm_return: pm_return:
mov esp, STACK_V+0x1000 ;ok, now we can access our data again
xor eax, eax xor eax, eax
mov edi, PDBR_V mov edi, PDBR_V
mov ecx, 1024 ;clear the PDBR mov ecx, 1024 ;clear the PDBR
@ -133,28 +132,28 @@ fill_lopt_loop: ;fill the page table
mov ecx, gdt_end-gdt mov ecx, gdt_end-gdt
rep movsb rep movsb
mov edi, IDT_V ;destination mov edi, IDT_V ;destination
mov esi, isr_0 ;address of isr0 mov esi, isr_0 ;address of isr0
mov edx, isr_1-isr_0 ;distance between isr labels mov edx, isr_1-isr_0 ;distance between isr labels
mov ecx, 50 ;number of isrlabels mov ecx, 50 ;number of isrlabels
fill_idt: fill_idt:
mov ebx, esi mov ebx, esi
mov ax, si mov ax, si
stosw ;0 offset 15:0 stosw ;0 offset 15:0
mov ax, KERNEL_CODE mov ax, KERNEL_CODE
stosw ;2 selector 15:0 stosw ;2 selector 15:0
mov ax, 0x8E00 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 shr esi, 16
mov ax, si mov ax, si
stosw ;6 offset 31:16 stosw ;6 offset 31:16
mov esi, ebx mov esi, ebx
add esi, edx add esi, edx
loop fill_idt loop fill_idt
mov word [IDT_V+0x30*8+4], 0xEE00 ;interrupt 0x30 has user priviledges 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. ;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 jmp KERNEL_CODE:newgdtcontinue
newgdtcontinue: newgdtcontinue:
mov ax, KERNEL_DATA mov ax, KERNEL_DATA
@ -167,9 +166,9 @@ newgdtcontinue:
lidt [idtr] ;load idt lidt [idtr] ;load idt
mov [PDBR_V], dword 0 ;unmap 0x0, we are running completely paged at 0xC000_0000 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 sti
hlt hlt
jmp idle_loop jmp idle_loop

View File

@ -30,14 +30,13 @@ mb_mmap_t mb_mmap[MAX_MMAP];
u32_t mmap_entries; u32_t mmap_entries;
mb_module_t mb_modules[MAX_MODULES]; mb_module_t mb_modules[MAX_MODULES];
mb_apm_t mb_apm_table; 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; real_mode_param_t rm_params;
char mb_cmdline[256]; char mb_cmdline[256];
int criticalCounter; // semaphore for if interrupts are disabled int criticalCounter; // semaphore for if interrupts are disabled
u32_t timer; // number of IRQ 0's u32_t timer; // number of IRQ 0's
minor_t devfs_minor = -1; minor_t devfs_minor = -1;
minor_t initrd_minor = -1; minor_t initrd_minor = -1;
byte initrd[2880*512]; // buffer in bss for loading a floppy image
extern u32_t mm_freepages; extern u32_t mm_freepages;
@ -115,12 +114,11 @@ void k_init()
{ {
if (rm_params.vid_mem) // there is video memory to map in 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); 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_init(); //get us some virtual consoles to look at
display_activate(11); 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 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); 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) if ((devfs_minor = ramdisk_new(4096)) < 0)

View File

@ -15,7 +15,6 @@ typedef struct {
u32_t height; // height in pixels or columns if vid_mem == 0 u32_t height; // height in pixels or columns if vid_mem == 0
u32_t vid_mem; // amount of memory for video buffer u32_t vid_mem; // amount of memory for video buffer
u32_t bpp; // bits per pixel - 16/24/32 u32_t bpp; // bits per pixel - 16/24/32
byte initrd_loaded; // did we load an initrd?
} __attribute__ ((packed)) real_mode_param_t; } __attribute__ ((packed)) real_mode_param_t;
/* returns true to callee if we should jump to a real mode module */ /* returns true to callee if we should jump to a real mode module */

View File

@ -2,7 +2,7 @@
timeout 10 timeout 10
default 0 default 0
title HOS 0.15 title HOS 0.16
root (fd0) root (fd0)
kernel /kernel.bin kernel /kernel.bin
#module /rmmod.bin #module /rmmod.bin

View File

@ -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

View File

@ -14,7 +14,6 @@
; ebx = return address ; ebx = return address
; ecx = where to store real mode parameter table ; ecx = where to store real mode parameter table
; edx = initrd, where to put ram disk
start: start:
jmp 0:start_refreshed jmp 0:start_refreshed
start_refreshed: start_refreshed:
@ -24,81 +23,28 @@ start_refreshed:
mov ss, ax mov ss, ax
mov esp, 0x7000 mov esp, 0x7000
mov [dat_rmadd], ecx mov [dat_rmadd], ecx
mov [dat_initrd], edx
mov [dat_retn], ebx 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 mov ebx, [dat_retn]
; push 23*80 lgdt [gdtrbs32]
; call putString mov eax, cr0
; add sp, 4 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(int position, char *str)
putString: putString:
push bp push bp
@ -137,7 +83,38 @@ putString_loop_done:
pop bp pop bp
ret 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_rmadd dd 0
dat_initrd dd 0 dat_initrd dd 0
dat_retn dd 0 dat_retn dd 0