BOTOKILLER
Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
|
Hi everyone!
I've rewritten everything that I had before succefully, bootloader done and working OK, now im trying to code second stage bootloader, but I got stuck at one place, here is the code:
USE16
ORG 0h
BEGIN:
jmp START
DATASECT:
DAP:
DAP_Size db 10h ;1h
DAP_Res1 db 0 ;2h
DAP_Bytes2Transfer db 1h ;3h
DAP_Res2 db 0 ;4h
DAP_Buff_Addr1 dw 0h ;6h
DAP_Buff_Addr2 dw 80h ;8h
DAP_LBA dq 3h ;9h
DAT_Disk_Num db 80h ;12h number of device 80h-winchester
DAT_Num_Of_Sects dw 10h ;13h the number of 512byte sectors, that contain your kernel
END_DAP:
VID:
VID_Cursor dw 0h ;15h
END_VID:
GDT:
dw GDT_ENDS - GDT_STARTS - 1h ;17h
dd 80000h + GDT_STARTS
GDT_STARTS:
REC0:
dq 0h
REC1:
Limit_0_15 dw 0FFFFh
Base_0_15 dw 0h
Base_16_23 db 0h
Access db 10011010b;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
LimAndFlags db 11001111b;||Granularity||1||0||0||Limit 16-19||
Base_24_31 db 0h
REC2:
aLimit_0_15 dw 0FFFFh
aBase_0_15 dw 0h
aBase_16_23 db 0h
aAccess db 10010010b;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
aLimAndFlags db 11001111b;||Granularity||1||0||0||Limit 16-19||
aBase_24_31 db 0h
REC3:
bLimit_0_15 dw 1FFh
bBase_0_15 dw 800h
bBase_16_23 db 0h
bAccess db 11110000b;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
bLimAndFlags db 01000000b;||Granularity||1||0||0||Limit 16-19||
bBase_24_31 db 0h
REC4: ;I cant say exactly but probably TSS is going to be here
cLimit_0_15 dw 0FFh
cBase_0_15 dw 0A00h
cBase_16_23 db 0h
cAccess db 89h;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
cLimAndFlags db 40h;||Granularity||1||0||0||Limit 16-19||
cBase_24_31 db 0h
; ______________________________________________
;| MEMORY HOLE OF 2048d BYTES FOR IDT |
;|______________________________________________|
REC5:
dLimit_0_15 dw 04FFh
dBase_0_15 dw 1300h
dBase_16_23 db 0h
dAccess db 10010010b;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
dLimAndFlags db 11000000b;||Granularity||1||0||0||Limit 16-19||
dBase_24_31 db 0h
REC6:
eLimit_0_15 dw 0FFFFh
eBase_0_15 dw 0h
eBase_16_23 db 0h
eAccess db 10011010b;||Present bit||Priviligies||1||Code-1, Data - 0||if want to execute from low levels - 1, else 0|| can write here? yes=1||0||
eLimAndFlags db 11001111b;||Granularity||1||0||0||Limit 16-19||
eBase_24_31 db 0h
GDT_ENDS:
;FINALY OS IS MAPPED LIKE THIS
; 00000000h | 000007FFh | GDT (descriptor + 255 entries)
; 00000800h | 000009FFh | SDA(system data area)
; 00000A00h | 00000AFFh | TSS and small space(maybe one more TSS later)
; 00000B00h | 000012FFh | IDT (255 entries + descriptor)
; 00001300h | 000017FFh | SYSTEM STACK (1280 bytes)
; 00001800h | x | kernel code(ints inside)
;
;
;
END_DATASECT:
ERROR:
jmp ERROR
START:
mov ax, 8000h
mov ds, ax
xor ax, ax
mov fs, ax
mov ax, 9000h
mov ss, ax
mov esp, 0500h
mov ax, 80h
mov gs, ax
mov bp, BEGIN
;here is it! everything prepared
;ds,cs - point to this segment
;es points to b800h
;ss points to higher place
;gs points to the first secto of kernel
;bp points to the start of datasect
;fs points to 0
; its time for action!
LOAD_KERN: ; service for reading data from disk specified DAT_Disk_Num
mov ah, 42h
xor al, al
mov dl, [cs:bp+12h]
mov si, DAP
mov cx, [cs:bp+13h]
READ_LOOP:
pusha
int 13h
jc ERROR
popa
add word [ds:si+6h], 20h
inc byte [ds:si+8h]
loop READ_LOOP ; service ends here
END_LOAD_KERN:
COLLECT_DATA:
DETECT_VENDOR:
xor eax, eax
cpuid
mov [gs:0h], ecx
DETECT_CPU:
mov eax, 01h
cpuid
mov [gs:4h], eax
NUMBER_OF_HDD:
mov al, [fs:475h]
mov [gs:0Ch], al
BIOS_HARDWARE:
mov ax, [fs:410h]
mov [gs:0Dh], ax
MEMORY_MAP:
mov byte [gs:10h], 0h
mov di, gs
mov es, di
mov di, 11h
xor ebx, ebx
mov edx, 534D4150h
MM_LOOP:
mov eax, 0E820h
mov ecx, 24d
int 15h
jc ERROR
add di, 24d
inc byte [gs:10h]
cmp ebx, 0h
jne MM_LOOP
;
; enogh data about cpu, time to go further.........
;
;_________________________________I WILL WORK ON IT LATER
; PCI_BUS_INFO:
; mov ax, 0B101h
; xor edi, edi
; int 1Ah
; jc ERROR
; mov [gs:0Fh], cl
; inc cx
; push cx
; xor edx, edx
;xor ebx, ebx
; SCAN_DEVICES:
; pop cx
; dec cx
; push cx
; xor ch, ch
; shl ecx, 10h
; xor eax, eax
; add eax, ecx
;mov al, 00100000b
; mov dx, 0CF8h
; out dx, eax
;mov dx, 0CFCh
;in eax, dx
;______________________________________________________________________
;here we loaded SDA(System Data Area) with following
;800h(dd) vendor: 'ntel' - Intel
;804h(dd) system info
;808h(dd) !!reserved!!
;80Ch(db) number of hdd detected by bios
;80Dh(dw) BIOS flags for detected hardware
;80Fh(db) !!reserved!!
;810h(db) number of memory map tables entries
;811h( ) memory map
;done
; its time to set up our kernel for pmode
PMJMP:
cli
lea eax, [cs:bp+17h]
lgdt [eax]
mov ax, 0x2401
int 0x15
mov eax, cr0
or eax, 1h
mov cr0, eax
jmp pword 08h:80000h+PMODE
USE32
PMODE: ;congrates! we are in PM!
SETREG32: ; here it loads segment registers and esp
mov ax, 10h
mov ds, ax
mov fs, ax
mov gs, ax
mov es, ax
mov ax, 28h
mov ss, ax
mov esp, 4FFh
;________________
:PROBLEM STARTS HERE
;_______________________________
MAKE_IT_WORK:
mov ebp, 80000h+17h
xor esi, esi
mov ecx, GDT_ENDS - GDT_STARTS + 6d
call MOVE_BLOCK
jmp pword 30h:80000h+THIS
THIS:
mov dword [ds:2h], 6h
mov dword [ds:0Eh], 18001000h
mov dword [ds:12h], 00409A00h
lgdt [0h]
jmp pword 08h:0000h
LOOLP:
nop
jmp LOOLP
MOVE_BLOCK: ; function that moves block of data specified in ds:ebp to ds:esi with length ecx
mov al, [ds:ebp+ecx-1]
mov [ds:esi+ecx-1], al
loop MOVE_BLOCK
ret
times 646 db 0 ;total must be 7680d
db 'F'
this code is loaded at 8000:0000h, starts working, loads kerenel, collects data, go to PM, but it fails when i try to put kenel code segment to 08h.
How to solve the problem???
PS: Dont look at my slogan, it doesnt applies now)))
_________________ _______________________________
NSOS
|