I'm writing small kernel and bootloader. The kernel works prefect with grub but I decided to make my own bootloader. First stage load second stage file to memory and execute it in real mode, than load kernel to low mem < 1MB switch to pmode anable a20 line and copy kernel to 0x00100000. I have tested it with bochs, vmware and it works ok but with virtual pc it is not
![Sad :(](./images/smilies/icon_sad.gif)
![Shocked :shock:](./images/smilies/icon_eek.gif)
here is the code
ps. sorry for my english
first stage just load a file from fat12 formatted floppy so I think it is no need to place it's code
here is stage2
Code: Select all
BITS 16
ORG 0x0500
jmp start
%include "fat12/bpb.inc"
%include "fat12/fat12.inc"
%include "console.inc"
%include "a20.inc"
error:
mov si, messageError
call puts
jmp $
start:
mov cx, 0x19
clear:
mov si, messageLFCR
call puts
;loop clear
mov dl, 0x16
mov dh, 0x0A
call gotoxy
mov si, messageLoading
call puts
mov dl, 0x16
mov dh, 0x0C
call gotoxy
call enableA20
bt ax, 0x0001
jc $
call calculate
mov ax, WORD [calculate_rootStart]
mov cx, WORD [calculate_rootSize]
mov bx, 0x7E00
call read
mov cx, WORD [bpbRootEntries]
mov si, fileName
mov di, 0x7E00
search:
push cx
mov cx, 0x000B
push si
push di
rep cmpsb
pop di
pop si
je found
add di, 0x0020
pop cx
loop search
jmp error
found:
mov dx, WORD [di + 0x001A]
mov WORD [cluster], dx
mov ax, WORD [calculate_FATstart]
mov cx, WORD [calculate_FATsize]
mov bx, 0x7E00
call read
mov ax, WORD [cluster]
mov bx, 0x0D00
push bx
next:
pop bx
push ax
call FATtoLBA
xor cx, cx
mov cl, BYTE [bpbSectorsPerCluster]
call read
pop ax
push bx
mov cx, ax
mov dx, ax
shr dx, 0x0001
add cx, dx
mov bx, 0x7E00
add bx, cx
mov dx, WORD [bx]
test ax, 0x0001
jnz odd
even:
and dx, 0x0FFF
jmp done
odd:
shr dx, 0x0004
done:
mov ax, dx
cmp dx, 0x0FF0
jb next
pop bx
cli
lgdt [gdth]
mov eax, cr0
inc ax
mov cr0, eax
jmp DWORD 0x08:protected
BITS 32
protected:
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0xFFFF
mov si, 0x0D00
mov edi, [destination]
mov cx, 8192
rep movsb
mov [destination], edi
jmp 0x08:0x00100000
gdt:
gdt_null:
dw 0x0000
dw 0x0000
db 0x00
db 0x00
db 0x00
db 0x00
gdt_code_32:
dw 0xFFFF
dw 0x0000
db 0x00
db 0x9A
db 0xCF
db 0x00
gdt_data_32:
dw 0xFFFF
dw 0x0000
db 0x00
db 0x92
db 0xCF
db 0x00
gdt_code_16: ; selektor: 0x18
dw 0xFFFF
dw 0x0000
db 0x00
db 0x9a
db 0x00
db 0x00
gdt_data_16:
dw 0xFFFF
dw 0x0000
db 0x00
db 0x92
db 0x00
db 0x00
gdth:
dw gdth - gdt - 0x01
dd gdt
LBAtoCHS_sector db 0x00
LBAtoCHS_head db 0x00
LBAtoCHS_track db 0x00
calculate_rootSize dw 0x0000
calculate_rootStart dw 0x0000
calculate_dataStart dw 0x0000
calculate_FATsize dw 0x0000
calculate_FATstart dw 0x0000
cluster dw 0x0000
address dw 0x0000
counter dw 0x0000
fat db 0x0000
progress db 0x00
destination dd 0x00100000
kernel db 0x00
messageLFCR db 0x0D, 0x0A, 0x00
messageBackground db 0xB1, 0x00
messageProgress db 0xDB, 0x00
messageLoading db 'Trawa uruchamianie systemu Thorn...', 0x00
messageError db 'ERROR: Brak pliku "/system/thorn" lub jest on uszkodzony!', 0x00
fileName db 'THORN ', 0x00
times 0x7FE - ($ - $$) db 0x00
Code: Select all
BITS 32
SECTION .text
global start
start:
mov esp, system_stack
extern kernel_main
call kernel_main
cli
hlt
SECTION .bss
resb 8192
system_stack: