Hi, Dex. Here is what I've got:
Code: Select all
[BITS 16]
[SECTION .text]
[ORG 0x500]
[GLOBAL start]
start:
jmp Entry
%include "stdio.inc" ; basic i/o routines
%include "Gdt.inc" ; Gdt routines
%include "A20.inc" ; A20 enabling
%include "Common.inc"
%include "bootinfo.inc"
%include "memory.inc"
%include "vesa.inc"
%include "vesaModes.asm"
%define bpp 32
%define y_res 480
%define x_res 640
mode dd 0
boot_info:
istruc multiboot_info
at multiboot_info.flags, dd 0
at multiboot_info.memoryLo, dd 0
at multiboot_info.memoryHi, dd 0
at multiboot_info.bootDevice, dd 0
at multiboot_info.cmdLine, dd 0
at multiboot_info.mods_count, dd 0
at multiboot_info.mods_addr, dd 0
at multiboot_info.syms0, dd 0
at multiboot_info.syms1, dd 0
at multiboot_info.syms2, dd 0
at multiboot_info.mmap_length, dd 0
at multiboot_info.mmap_addr, dd 0
at multiboot_info.drives_length, dd 0
at multiboot_info.drives_addr, dd 0
at multiboot_info.config_table, dd 0
at multiboot_info.bootloader_name, dd 0
at multiboot_info.apm_table, dd 0
at multiboot_info.vbe_control_info, dd 0
at multiboot_info.vbe_mode_info, dw 0
at multiboot_info.vbe_interface_seg, dw 0
at multiboot_info.vbe_interface_off, dw 0
at multiboot_info.vbe_interface_len, dw 0
iend
Entry:
;-------------------------------;
; Setup segments and stack ;
;-------------------------------;
cli ; clear interrupts
xor ax, ax ; null segments
mov ds, ax
mov es, ax
mov ax, 0x0000 ; stack begins at 0x9000-0xffff
mov ss, ax
mov sp, 0xFFFF
sti ; enable interrupts
mov [boot_info+multiboot_info.bootDevice], dl
call _EnableA20
call InstallGDT
sti
xor eax, eax
xor ebx, ebx
call BiosGetMemorySize64MB
push eax
mov eax, 64
mul ebx
mov ecx, eax
pop eax
add eax, ecx
add eax, 1024 ; the routine doesnt add the KB between 0-1MB; add it
mov dword [boot_info+multiboot_info.memoryHi], 0
mov dword [boot_info+multiboot_info.memoryLo], eax
mov eax, 0x0
mov ds, ax
mov di, 0x1000
call BiosGetMemoryMap
jmp EnterStage3
EnterStage3:
cli ; clear interrupts
mov eax, cr0 ; set bit 0 in cr0--enter pmode
or eax, 1
mov cr0, eax
jmp CODE_DESC:Stage3
bits 32
%include "Paging.inc"
%include "HDD.inc"
%define ba 0x7C00
%define data_start ba+0x4C
%define fat_start ba+0x48
%define fat_sector ba+0x44
%define root_cluster ba+0x2C
%define sec_per_cluster ba+0x0D
%define bytes_per_sec ba+0x0b ; bytes/sector (dw)
%define res_sectors ba+0x0e ; # reserved sectors (dw)
%define fat_count ba+0x10 ; # of fats (db)
%define hidden_sectors ba+0x1c ; # hidden sectors (dd)
%define sec_per_fat ba+0x24 ; Sectors/Fat (dd)
msgWelcome db " SYOS Bootstrap utility", 0x00
msgControls db " Use arrows <UP> and <DOWN> to select item and use <ENTER> to boot selected OS", 0x00
msgChoise db " Please, make a choise from following variants: ", 0x00
X db 0
Y db 0
W db 0
C db 0
B db 0
R dd 0
Stage3:
;-------------------------------;
; Set registers ;
;-------------------------------;
mov ax, DATA_DESC ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
mov al, 0x09
mov [CHAR_ATTRIB], al
call ClrScr32
mov al, 0
mov [X], al
mov [Y], al
mov al, 0x07
mov [C], al
mov al, 80
mov [W], al
call DrawFilledRect
mov al, 0
mov ah, 24
mov [X], al
mov [Y], ah
call DrawFilledRect
mov al, 0
mov ah, 0
call GotoXY
mov al, 0x70
mov [CHAR_ATTRIB], al
mov ebx, msgWelcome
call Puts32
mov al, 0
mov ah, 24
call GotoXY
mov ebx, msgControls
call Puts32
mov al, 0
mov ah, 2
call GotoXY
mov al, 0x07
mov [CHAR_ATTRIB], al
mov ebx, msgChoise
call Puts32
mov eax, dword 63 ;63 - This is bootsector of first partition on master drive
mov ebx, 0x7C00
mov [HddBuffer], ebx
call HddRead
call LoadRoot
call FindFile
mov bl, '1'
call Putch32
cli
jmp 0x08:0x100000
infinite:
jmp infinite
;Loads root directory of 1st partition to 0x7E00
LoadRoot:
mov al, [fat_count]
mov ebx, [sec_per_fat]
mul ebx
add eax, [hidden_sectors]
add ax, [res_sectors]
mov [R], eax
mov [data_start], eax
mov ebx, 0x7E00
mov [HddBuffer], ebx
call HddRead
ret
FindFile:
pusha
mov eax, 0x7E00
next:
mov ecx, 11
mov edi, KERNEL_DIR1 ;This finds '\SYOS'
mov esi, eax
repe cmpsb
jz done
add eax, dword 0x20
jmp next
done:
add eax, 0x1A
mov ebx, [eax]
mov [R], ebx
dec dword [R]
dec dword [R]
mov eax, [R]
movzx edx, byte [sec_per_cluster]
push edx
mul edx
pop edx
add eax, [data_start]
mov ebx, 0x7E00
mov [HddBuffer], ebx ;This loads '\SYOS'
call HddRead
mov eax, 0x7E00 ;This finds '\system32'
next_m:
mov ecx, 11
mov edi, KERNEL_DIR2
mov esi, eax
repe cmpsb
jz done_m
add eax, dword 0x20
jmp next_m
done_m:
add eax, 0x1A
mov ebx, [eax]
mov [R], ebx
dec dword [R]
dec dword [R]
mov eax, [R]
movzx edx, byte [sec_per_cluster]
push edx
mul edx
pop edx
add eax, [data_start]
mov ebx, 0x7E00
mov [HddBuffer], ebx ;This loads '\system32'
call HddRead
mov eax, 0x7E00 ;This finds '\KRNL32.EXE'
next_m1:
mov ecx, 11
mov edi, KERNEL_FN
mov esi, eax
repe cmpsb
jz done_m1
add eax, dword 0x20
jmp next_m1
done_m1:
add eax, 0x1A
mov ebx, [eax]
mov [R], ebx
dec dword [R]
dec dword [R]
mov eax, [R]
movzx edx, byte [sec_per_cluster]
push edx
mul edx
pop edx
add eax, [data_start]
mov ebx, 0x100000
mov [HddBuffer], ebx ;This loads '\KRNL32.EXE'
call HddRead
popa
ret
DrawFilledRect:
pusha
mov al, [X]
mov ah, [Y]
call GotoXY
mov al, [C]
mov [CHAR_ATTRIB], al
mov ch, 0
mov bl, 0xDB
draw1:
call Putch32
inc ch
cmp ch, byte [W]
je done1
jmp draw1
done1:
popa
ret
KERNEL_DIR1 db "SYOS ", 0x00
KERNEL_DIR2 db "SYSTEM32 ", 0x00
KERNEL_FN db "KRNL34 ", 0x00
and HDD.inc:
Code: Select all
HddBuffer dd 0
hdbase equ 0x1f0 ; 0x1f0 for primary device
; 0x170 for secondary device
hdid equ 0x00 ; 0x00 for master hd
; 0x10 for slave hd
;---------------------------------------------------------;
; hd_read. ; eax = sector to read ;
;---------------------------------------------------------;
HddRead:
pushad
push eax
newhdread:
mov edx,hdbase
inc edx
mov al,0
out dx,al
inc edx
mov al,1
out dx,al
inc edx
pop ax
out dx,al
inc edx
shr ax,8
out dx,al
inc edx
pop ax
out dx,al
inc edx
shr ax,8
and al,1+2+4+8
add al,hdid
add al,128+64+32
out dx,al
inc edx
mov al,20h
out dx,al
hddwait:
in al,dx
test al,128
jnz hddwait
mov edi,[HddBuffer]
mov ecx,256
mov edx,hdbase
cld
rep insw
popad
ret
See, I tried to get known where is error and when is it called? I got known that error is while executing these two opcodes:
I know it because I made it commented and really got no error. So it is somewhere here. This trouble is called after the fourth calling of HddRead. See, if I do this I else get error:
Code: Select all
mov eax, dword 1
mov ebx, 0x7E00
mov [HddBuffer], ebx
call HddRead
mov eax, dword 2
mov ebx, 0x7E00
mov [HddBuffer], ebx
call HddRead
mov eax, dword 3
mov ebx, 0x7E00
mov [HddBuffer], ebx
call HddRead
mov eax, dword 4
mov ebx, 0x7E00
mov [HddBuffer], ebx
call HddRead
But if I remove last four strings (then just three times HddRead is called) there is no errors.
Even when I try to use other registers(not ecx and edi) everything is the same.
And one more: I tried to set that values via stack in such a way:
Code: Select all
push dword 256
pop ecx
push dword hdbase
pop edi
But in this case I get infinity loop
(my last instructions are CLI HLT, so I can get known if everything is great with VMware message about halting, but using stack I really do not get it and nothing is displayed!!!)
Thanks, Daniel.
PS: I use VMWare and it shows me Kernel Stack Error Message (maybe it is something another, but in my bootloader I do not set IDT and that is why I cannot use exceptions fully)