summaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/acer/mbr.asm167
-rw-r--r--boot/disk_load_16.asm59
-rw-r--r--boot/mbr.asm140
-rw-r--r--boot/pic.asm80
4 files changed, 125 insertions, 321 deletions
diff --git a/boot/acer/mbr.asm b/boot/acer/mbr.asm
deleted file mode 100644
index b3ae034..0000000
--- a/boot/acer/mbr.asm
+++ /dev/null
@@ -1,167 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;
-; THE FOOL-BOOT-LOADER
-;
-; So we have just been loaded by the BIOS and are in 16-bits real mode!
-; Now the following work will bee accomplished (chronologically):
-;
-; * BOOT_DRIVE set
-;
-; * 50 sectors of our kernel loaded at KERNEL_OFFSET from floppy
-;
-; * memory map made available at MEMMAP_OFFSET
-; (check at MEMMEP_SIZE_OFFSET for number of entries)
-;
-; * the VESA mode specified by VESA_MODE_SELECT will be set up
-; (check at VESA_MODES, and VESA_MODE_INFO
-; for additional information)
-;
-; * interrupts disabled
-;
-; * 32-bit protected mode set up.
-;
-; * esp set to 0x90000 (Todo: take care of it!?)
-;
-; * A20 gate opened (Todo: really necessary?)
-;
-; * PICs configured
-;
-; * and finally we will jump into the C world to kernel_main() !
-;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;we want 16-bit instructions, before we switch to 32-bit protected mode.
-[bits 16]
-
-;define origin of boot record in memory: 0x7c00
-;this is where the BIOS per definition will put the first
-;512 bytes of data from the boot device
-;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?)
-[org 0x7c00]
-
-;;define some constants
-;;where we will load our kernel into memory and some
-;;other memory locations
-;
-KERNEL_OFFSET equ 0x1000
-MEMMAP_SIZE_OFFSET equ 0x7c00+0x600
-MEMMAP_OFFSET equ 0x7c00+0x400
-VESA_MODES equ 0x8300
-VESA_MODE_INFO equ 0x8400
-VESA_MODE_SELECT equ 0x4114
-;VESA_MODE_SELECT equ 0x0
-;
-jmp boot_16 ;start boot process
-;
-;;SOME Global Data, mainly info/error strings
-BOOT_DRIVE:
- db 0xff
-STR_VERSION:
- db "v0.3.1~",0
-VESA_CHECK1:
- db " V1.",0
-VESA_CHECK2:
- db " V2",0
-VESA_CHECK3:
- db " V3",0
-CHECK_A20:
- db " A20",0
-;
-;;lets put our temporary GDT (Global Descriptor Table) here
-;;kernel should move this away
-%include "boot/GDT.asm"
-;
-;;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20)
-%include "boot/disk_load_16.asm"
-;%include "boot/check_a20_16.asm"
-%include "boot/print_string_16.asm"
-%include "boot/vesa_setup_16.asm"
-;
-;;include our routines for switching to 32-bit protected mode
-%include "boot/pm.asm"
-;
-;;pic_setup mapping routing
-%include "boot/pic.asm"
-;
-;;get memory map routine
-%include "boot/memmap.asm"
-;
-;;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;
-;;lets start
-[bits 16]
-;
-boot_16:
-;
-;
- mov bx, STR_VERSION
- call print_string
-;
-;
-; ;setup the stack
- mov bp,0x8000
- mov sp,bp
-;
-; ;remember BOOT_DRIVE (as was set by BIOS)
- mov [BOOT_DRIVE],dl
-;
-; ;Load the KERNEL (52 sectors starting at sector 2)
- mov bx,KERNEL_OFFSET
- mov dh, 52
- mov dl, [BOOT_DRIVE]
- call disk_load
-
- mov bx, KERNEL_OFFSET
- call print_string
-
-;
-; ;get memory map from bios before we enter 32 bit protected mode
- mov ax,0 ; set target address in es:di (0:offset)
- mov es,ax
- mov di,MEMMAP_OFFSET
- call BiosGetMemoryMap ; this will also put the number of entries
-; ; of the memory map at MEMMAP_SIZE_OFFSET
-;
-;a20check:
-;
-; mov bx, CHECK_A20
-; call print_string
-;
-; call check_a20
-; cmp ax,0
-; je a20check ;hang if a20 is disabled!
-;
-; ;VESA: also setup vesa stuff before entering 32 bit protected mode
- call VesaSetup
-;
-; ;finally lets enter Protected mode!!!
- call switch_to_pm
-;
-;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-[bits 32]
-boot_32_pm:
-;
-;; we could do ALL This inside the kernel!!!!!! TODO
-;
-; ;enable A20
-; ;http://www.brokenthorn.com/Resources/OSDev9.html
-; ;Method 3.1: Enables A20 through keyboard controller
-; ;Not all keyboard controllers support this
-; ;todo: check if this has any effect at all !?!?
- mov al, 0xdd ; command 0xdd: enable a20
-; ;mov al, 0xdf ; command 0xdf: disable a20
- out 0x64, al ; send command to controller
-
-;
-; ;pic setup
- call pic_setup
-
-;
- call KERNEL_OFFSET ;jump into our Kernel!
-;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;
-;so we get identified as MBR
-times 510-($-$$) db 0x0
-dw 0xaa55
-
diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm
index 3d0951d..a96ad11 100644
--- a/boot/disk_load_16.asm
+++ b/boot/disk_load_16.asm
@@ -8,19 +8,76 @@
[bits 16]
+DISK_LOAD_HANG_MSG:
+ db " D",0
;disk_load routune (load dh sectors from drive dl to es:bx)
disk_load:
pusha
+
+; mov ah,0x41
+; mov bx,0x55AA
+; ;mov dl,[disk]
+; int 0x13
+; jne disk_load_hang
+
+
+ ;mov ah,0x42
+ ; llea si,[lbaadr]
+ ; int 0x13
+; cmp ah,0x00 ; check for error
+; jne disk_load_hang
+
+ ; check if LBA is supported
+ pusha
+ mov ah,0x41
+ mov bx,0x55aa
+ int 0x13
+ jnc disk_load_lba
+ popa
mov ah,0x02 ;BIOS read sector func
mov al,dh ;read dh sectors (amount)
mov ch,0x00 ;cyl 0
mov dh,0x00 ;head 0
mov cl,0x02 ;start at sector 2
-
+;
int 0x13 ;bios interrupt
+; jc disk_load_hang
+
+ popa
+ ret
+
+disk_load_lba:
+ popa
+
+ xor ah,ah
+ mov ah,0x42
+ lea si,[lbaadr]
+ int 0x13
+ jc skip_print
+
+ mov bx, 0x1000
+ call print_string
+
+ skip_print:
popa
ret
+lbaadr:
+dw 0x10
+dw 52
+dw 0x1000
+dw 0
+dd 1
+dd 0
+
+;
+;lbaadr:
+; dw 0x0010 ; 2byte, reserved - size of packet.
+; dw 0x0010 ; WORD 2bytes nr of blocks read.
+; dd 0x00001000 ; DWORD 4bytes Transfer buffer
+; ; dq 0x0000000034009605 ; QWORD 4bytes,32bit LBA address
+; dq 0x0000000000000000
+
diff --git a/boot/mbr.asm b/boot/mbr.asm
index 96fc788..bb74d23 100644
--- a/boot/mbr.asm
+++ b/boot/mbr.asm
@@ -39,121 +39,115 @@
;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?)
[org 0x7c00]
-;define some constants
-;where we will load our kernel into memory and some
-;other memory locations
-
+;;define some constants
+;;where we will load our kernel into memory and some
+;;other memory locations
+;
KERNEL_OFFSET equ 0x1000
MEMMAP_SIZE_OFFSET equ 0x7c00+0x600
MEMMAP_OFFSET equ 0x7c00+0x400
VESA_MODES equ 0x8300
VESA_MODE_INFO equ 0x8400
VESA_MODE_SELECT equ 0x4114
-;VESA_MODE_SELECT equ 0x0
-
+;
jmp boot_16 ;start boot process
-
-;SOME Global Data, mainly info/error strings
+;
+;;SOME Global Data, mainly info/error strings
BOOT_DRIVE:
db 0xff
STR_VERSION:
- db "v0.3.1~",0
+ db "v0.4",0
VESA_CHECK1:
- db " V1.",0
+ db "1",0
VESA_CHECK2:
- db " V2",0
+ db "2",0
VESA_CHECK3:
- db " V3",0
+ db "3",0
CHECK_A20:
- db " A20",0
-
-;lets put our temporary GDT (Global Descriptor Table) here
-;kernel should move this away
+ db "A",0
+;
+;;lets put our temporary GDT (Global Descriptor Table) here
+;;kernel should move this away
%include "boot/GDT.asm"
-
-;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20)
+;
+;;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20)
%include "boot/disk_load_16.asm"
-%include "boot/check_a20_16.asm"
+;%include "boot/check_a20_16.asm"
%include "boot/print_string_16.asm"
%include "boot/vesa_setup_16.asm"
-
-;include our routines for switching to 32-bit protected mode
+;
+;;include our routines for switching to 32-bit protected mode
%include "boot/pm.asm"
-
-;pic_setup mapping routing
-%include "boot/pic.asm"
-
-;get memory map routine
+;
+;
+;;get memory map routine
%include "boot/memmap.asm"
-
-;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;lets start
+;
+;;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+;;lets start
[bits 16]
-
+;
boot_16:
-
+;
+;
mov bx, STR_VERSION
call print_string
-
- ;setup the stack
+;
+;
+; ;setup the stack
mov bp,0x8000
mov sp,bp
-
- ;remember BOOT_DRIVE (as was set by BIOS)
+;
+; ;remember BOOT_DRIVE (as was set by BIOS)
mov [BOOT_DRIVE],dl
-
- ;Load the KERNEL (52 sectors starting at sector 2)
+; mov bx, BOOT_DRIVE
+; call print_string
+;
+; ;Load the KERNEL (52 sectors starting at sector 2)
mov bx,KERNEL_OFFSET
mov dh, 52
mov dl, [BOOT_DRIVE]
call disk_load
- ;get memory map from bios before we enter 32 bit protected mode
+ mov bx, KERNEL_OFFSET
+ call print_string
+
+;
+; ;get memory map from bios before we enter 32 bit protected mode
mov ax,0 ; set target address in es:di (0:offset)
mov es,ax
mov di,MEMMAP_OFFSET
call BiosGetMemoryMap ; this will also put the number of entries
- ; of the memory map at MEMMAP_SIZE_OFFSET
-
-a20check:
-
- mov bx, CHECK_A20
- call print_string
-
- call check_a20
- cmp ax,0
- je a20check ;hang if a20 is disabled!
-
- ;VESA: also setup vesa stuff before entering 32 bit protected mode
+; ; of the memory map at MEMMAP_SIZE_OFFSET
+;
+;a20check:
+;
+; mov bx, CHECK_A20
+; call print_string
+;
+; call check_a20
+; cmp ax,0
+; je a20check ;hang if a20 is disabled!
+;
+; ;VESA: also setup vesa stuff before entering 32 bit protected mode
call VesaSetup
-
- ;finally lets enter Protected mode!!!
+;
+; ;finally lets enter Protected mode!!!
call switch_to_pm
-
-;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 32]
boot_32_pm:
+;
-; we could do ALL This inside the kernel!!!!!! TODO
-
- ;enable A20
- ;http://www.brokenthorn.com/Resources/OSDev9.html
- ;Method 3.1: Enables A20 through keyboard controller
- ;Not all keyboard controllers support this
- ;todo: check if this has any effect at all !?!?
- ;mov al, 0xdd ; command 0xdd: enable a20
- ;mov al, 0xdf ; command 0xdf: disable a20
- ;out 0x64, al ; send command to controller
-
- ;pic setup
- call pic_setup
-
+;
call KERNEL_OFFSET ;jump into our Kernel!
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
;so we get identified as MBR
-times 510-($-$$) db 0
+times 510-($-$$) db 0x0
+;dw 0x0
dw 0xaa55
diff --git a/boot/pic.asm b/boot/pic.asm
deleted file mode 100644
index 5724af6..0000000
--- a/boot/pic.asm
+++ /dev/null
@@ -1,80 +0,0 @@
-;************************************************************************
-; Map the 8259A PIC to use interrupts 32-47 within our interrupt table
-;************************************************************************
-
-%define ICW_1 0x11 ; 00010001 binary. Enables initialization mode and we are sending ICW 4
-
-%define PIC_1_CTRL 0x20 ; Primary PIC control register
-%define PIC_2_CTRL 0xA0 ; Secondary PIC control register
-
-%define PIC_1_DATA 0x21 ; Primary PIC data register
-%define PIC_2_DATA 0xA1 ; Secondary PIC data register
-
-%define IRQ_0 0x20 ; IRQs 0-7 mapped to use interrupts 0x20-0x27
-%define IRQ_8 0x28 ; IRQs 8-15 mapped to use interrupts 0x28-0x36
-
-pic_setup:
-
-; Send ICW 1 - Begin initialization -------------------------
-
- ; Setup to initialize the primary PIC. Send ICW 1
-
- mov al, ICW_1
- out PIC_1_CTRL, al
-
-; Send ICW 2 - Map IRQ base interrupt numbers ---------------
-
- ; Remember that we have 2 PICs. Because we are cascading with this second PIC, send ICW 1 to second PIC command register
-
- out PIC_2_CTRL, al
-
- ; send ICW 2 to primary PIC
-
- mov al, IRQ_0
- out PIC_1_DATA, al
-
- ; send ICW 2 to secondary controller
-
- mov al, IRQ_8
- out PIC_2_DATA, al
-
-; Send ICW 3 - Set the IR line to connect both PICs ---------
-
- ; Send ICW 3 to primary PIC
-
- mov al, 0x4 ; 0x04 => 0100, second bit (IR line 2)
- out PIC_1_DATA, al ; write to data register of primary PIC
-
- ; Send ICW 3 to secondary PIC
-
- mov al, 0x2 ; 010=> IR line 2
- out PIC_2_DATA, al ; write to data register of secondary PIC
-
-; Send ICW 4 - Set x86 mode --------------------------------
-
- mov al, 1 ; bit 0 enables 80x86 mode
-
- ; send ICW 4 to both primary and secondary PICs
-
- out PIC_1_DATA, al
- out PIC_2_DATA, al
-
-; All done. Null out the data registers
-
- mov al, 0
- out PIC_1_DATA, al
- out PIC_2_DATA, al
-
- ;mask
-in al, 0x21 ; read in the primary PIC Interrupt Mask Register (IMR)
-and al, 0x00 ; 0xEF => 11101111b. This sets the IRQ4 bit (Bit 5) in AL
-out 0x21, al ; write the value back into IMR
-
-
-in al, 0xA1 ; read in the primary PIC Interrupt Mask Register (IMR)
-and al, 0x00 ; 0xEF => 11101111b. This sets the IRQ4 bit (Bit 5) in AL
-out 0xA1, al ; write the value back into IMR
-
-ret
-
-;;;;;;;;;;;;;;;;;;;;