Combuster wrote: /* Begin putting sections at 1 MiB, a conventional place for kernels to be
loaded at by the bootloader. */
. = 0xEFFF;
-1 point for not following the tutorial. And judging from this, I fear there's a big broken hack hiding behind all the other instructions you didn't follow. Which begs the question: why?
i change to 0xEFFF because my boot file have to jump to position 0xEFFF to start 32bit
did I did somethings wrong in my bootloader?
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; File: boot.asm
; Title: Sample bootloader
; Desc: Starting up Booting to kernel - Stage 1
; containing load GDT and loading booting devices
;
; This is a i686(i386) 32bit loader
;
;
; Author: Sebastian Ko
; Date: 09/01/2011 v1.0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16] ;asign to 16bit CPU
[org 0x7c00] ;origin start point
jmp start
;Data
BootTitle db 'OS BootLoader x16 07122012 - Loading in Real Mode ...',13,10,0
GotoStage2 db 'Switching to Stage 2 ...',13,10,0
start:
mov ax, 0x0000 ;asignning a 0 address to ax for data segment address
mov ds, ax ;move the address 0x0000 to data segment register
mov si, BootTitle ;moving the String data to String interrupts register preper to print out
call printString ;call print out method
call reset_drive ;load kernel
;;;;;;;;;;;;;;;;;;;;;
;Goto Stage 2 file
;;;;;;;;;;;;;;;;;;;;;
mov si, GotoStage2 ;moving the String data to String interrupts register preper to print out
call printString ;call print out method
cli
lgdt [gdt_desc] ;Load GDT Descriptor
jmp 0:0xEFFF ;code selector is 8 , goto kernel position EFFFh
hlt ;Stop CPU moving
;-----------------------------------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Startup Drive
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
reset_drive: ;reset floppy drive
mov ah, 0x00 ;
int 0x13 ;floppy drive interrupt
or ah, ah ;if it's 0(return code)
jnz reset_drive ;jump back
mov ax, 0 ;
mov es, ax ;reset extended segment
mov bx, 0xEFFF ;set kernel location to 0000:EFFF(ES:BX)
mov ah, 0x02 ;commend - "read sector from disk"
mov al, 0x02 ;Number of sectors need to read
mov ch, 0 ;disk cylinder
mov cl, 0x02 ;set sector (0x01 is bootloader)
mov dh, 0 ;disk head
int 0x13 ;call floppy drive interrupt
or ah, ah ;check error
jnz reset_drive
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;String printing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printString: ;method (printString)
pusha
mov ah, 0x0E ;asignning 0x0E(video display) instruction to ah(accumulator register)
mov bh, 0x00 ;asignning page no (default is 0x00)
mov bl, 0x07 ;asignning text color (07 = White)
;
;FULL string display in 16bits
;AX(AH+AL) 0x0E?? <-- adding to register, not yet execute (int)
; | |-Means ACSII code (XY) X = bg color Y = Text Color (16bit)
; |---Means Display
;
;BX(BH+BL) 0x00?? <-- adding to register, means display usage
; | |-Means front color (Can't display without no color
; |---Means Page no (Default is page 0)
;
;int 0x10 <------------ interrupt address (execute)
; |------ 0x10 is display port address services
;
.getChar:
;lodsb ;load a string block 'x''y''z' = "xyz" (LOaD String Block)
;load a put it into AL register
mov al,[si] ;get data from pointer of source index ;This method same as using lodsb
inc si ;si check location + 1 ;
or al,al ;or gate (if-or)
jz .return ;jump if the or gate returns 0
int 0x10 ;interrupt the Video Display instruction
jmp .getChar ;loop if bytes not equals to 0
.return:
popa
ret ;return method back to main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set GDT
;If you write wrong any word
;means you will die for debugging
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GDT:
;00000000 00000000 00000000 00000000 00000000 00000000 ;GDT_Null
;11111111 00000000 00000000 10011010 11001111 00000000 ;GDT_Code
;11111111 00000000 00000000 10010010 11001111 00000000 ;GDT_Data
gdt: ;making Global Description Table
;first is null segment description
;then is code segment
;and the last is data segment
gdt_null: ;Null Segment
dd 0 ;all 64bits 0
dd 0 ;
gdt_code: ;Code Segment description
dw 0FFFFh ;16 bits
dw 0 ;16 bits
db 0 ;8 bits
db 10011010b ;8 bits
db 11001111b ;8 bits
db 0 ;8 bits
gdt_data: ;Data Segment description
dw 0FFFFh
dw 0
db 0
db 10010010b ;number 4 bit will change to 0 mean data segment description
db 11001111b
db 0
gdt_end:
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
times 510-($-$$) db 0 ;for boot loader size MUST be 512bytes
;adding bytes with 0 to increase the size of file
dw 0xAA55 ;BOOT sign
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; File: loader.asm
; Desc: File that using for preparing starting up OS.
; Starting at bits 16 is setting UP Protected Mode
; and enable A20.
; Starting at bits 32 is checking for PMode
; and change the memory section to Kernel(in C).
;
; Author: Sebastian Ko
; Data: 09/01/2012 v1.0
;
; PS. File (.asm) was written in Notepad++
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
[global start]
jmp start
start:
mov al, 'J' ;Jump to kernel
call printChar
mov al, 'u'
call printChar
mov al, 'm'
call printChar
mov al, 'p'
call printChar
mov al, ' '
call printChar
mov al, 't'
call printChar
mov al, 'o'
call printChar
mov al, ' '
call printChar
mov al, 'k'
call printChar
mov al, 'e'
call printChar
mov al, 'r'
call printChar
mov al, 'n'
call printChar
mov al, 'e'
call printChar
mov al, 'l'
call printChar
mov al, 13
call printChar
mov al, 10
call printChar
;;;;;;;;;;;;;;;;;;;;;;;
;Switch PMode
;;;;;;;;;;;;;;;;;;;;;;;
mov eax, cr0 ;move cr0(including protected mode instruction) to eax for checking
or eax, 1 ;checking al(2bits) 0001b
mov cr0, eax ;giving back
jmp 08:loadBit ;jump to 32bit kernel loader
;;;;;;;;;;;;;;;;;;;;;;
;Print Char
;;;;;;;;;;;;;;;;;;;;;;
printChar:
mov ah, 0x0E ;instruction of 0x10 (display char)
mov bx, 0x0007 ;00 = page 07 = black color bg and white text
int 0x10 ;interrupt display code
ret
;================================================================================
;================================================================================
[bits 32]
[section .text]
[extern k_main]
loadBit:
mov ax, 10h ;reset segment to 10h (data selector)
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov word [es: 0xb8000],'P' ;Protected Mode
mov word [es: 0xb8001],02h
mov word [es: 0xb8002],'M'
mov word [es: 0xb8003],02h
mov word [es: 0xb8004],'o'
mov word [es: 0xb8005],02h
mov word [es: 0xb8006],'d'
mov word [es: 0xb8007],02h
mov word [es: 0xb8008],'e'
mov word [es: 0xb8009],02h
;mov esp, 0x90000 ;stack begins from 90000h
call k_main
hlt
;================================================================================
;================================================================================