summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-09-05 09:34:53 +0200
committerMichal Idziorek <m.i@gmx.at>2014-09-05 09:34:53 +0200
commitc245268812a63bae0610de9a416dc7de97edde07 (patch)
tree1f3707e9d53fbf1d3265feb138d499a58b03cf69
parentb75c10c9d8c7405ba2f89724b485154d5201c404 (diff)
Moved kernel and reclaimed ACPI memory
finally our 2 stage bootloader also works with LBA loading via BIOS
-rw-r--r--Makefile4
-rw-r--r--boot/disk_load_16.asm15
-rw-r--r--boot/stage2.asm12
-rw-r--r--kernel/kernel.c25
-rw-r--r--kernel/mem.c20
5 files changed, 39 insertions, 37 deletions
diff --git a/Makefile b/Makefile
index a039991..3e98bf8 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@
USB_STICK=/dev/sdf #take care!
#here our kernel will be loaded by the bootloader.
-KERNEL_START=0x10000
+KERNEL_START=0x18000
############ flags ############
@@ -96,7 +96,7 @@ FoolOS.img: $(MBR) $(STAGE2) kernel.bin $(FILLUP) FoolData.img
dd if=$(MBR) of=$@ bs=512 seek=0 conv=notrunc
dd if=$(STAGE2) of=$@ bs=512 seek=1 conv=notrunc
dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc
- dd if=FoolData.img of=$@ bs=512 seek=906 conv=notrunc
+ dd if=FoolData.img of=$@ bs=512 seek=842 conv=notrunc
binfont.img: binfont.bin
cat $^ > $@
diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm
index 764b80d..fe573ea 100644
--- a/boot/disk_load_16.asm
+++ b/boot/disk_load_16.asm
@@ -10,7 +10,7 @@
STR_ERROR:
db "Disk Read Error",0
-STR_SPACE
+STR_SPACE:
db " ",0
STR_OK:
@@ -41,12 +41,13 @@ disk_load_lba:
pusha
- mov bx,0x1000 ;target es:bx
+ mov bx,0x1800 ;target es:bx
mov es,bx
mov bx,0
next_sectors_lba:
+ jmp skip_debug_lba
;show es - target
pusha
mov bx,es
@@ -59,6 +60,8 @@ disk_load_lba:
popa
;--
+ skip_debug_lba:
+
mov [lba_addr_sector],es
mov ax,[LBA]
mov [lba_first_sector],ax
@@ -93,11 +96,11 @@ disk_load_chs:
pusha
- mov bx,0x1000 ;target es:bx
+ mov bx,0x1800 ;target es:bx
mov es,bx
mov bx,0
- next_sectors_chs
+ next_sectors_chs:
jmp skip_debug
pusha
@@ -147,7 +150,7 @@ disk_load_chs:
call print_nextline
- skip_debug
+ skip_debug:
mov ax,[LBA]
@@ -225,7 +228,7 @@ lba_adr:
dw 0x0000 ; target addr. offset
lba_addr_sector:
- dw 0x1000 ; target addr. sector
+ dw 0x1800 ; target addr. sector
lba_first_sector:
dw 10 ; first sector to read
diff --git a/boot/stage2.asm b/boot/stage2.asm
index de2497e..a1dbb46 100644
--- a/boot/stage2.asm
+++ b/boot/stage2.asm
@@ -37,16 +37,13 @@
;;where we will load our kernel into memory and some
;;other memory locations
;
-KERNEL_DATA equ 10 ;sector on disk where the kernel starts
-KERNEL_SECTOR equ 0x1000
-KERNEL_OFFSET equ 0x0000
-
MEMMAP_SIZE_OFFSET equ 0x7c00
MEMMAP_OFFSET equ 0x7c01
VESA_MODES equ 0x8300
VESA_MODE_INFO equ 0x8400
VESA_MODE_SELECT equ 0x4114
;
+
jmp boot_16 ;start boot process
;;SOME Global Data, mainly info/error strings
@@ -55,9 +52,9 @@ BOOT_DRIVE:
STR_VERSION:
db "Fool Loader Stage 2 v0.5",0
-STR_LOAD
+STR_LOAD:
db "Loading Kernel...",0
-STR_BOOT
+STR_BOOT:
db "Boot Drive: ",0
MEMMAP_INFO:
db "Getting Memory Map from BIOS.",0
@@ -112,6 +109,7 @@ boot_16:
mov bx,MEMMAP_INFO
call print_string
call print_nextline
+
;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
@@ -137,5 +135,5 @@ boot_32_pm:
; call kernel!
mov eax,0 ;tell the kernel
; we are the booting processor
- call 0x10000 ;jump into our Kernel!
+ call 0x18000 ;jump into our Kernel!
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 0feca14..45f798d 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -108,18 +108,6 @@ void kernel_main(uint32_t initial_stack, int mp)
int_init(0x08);
//
- // Memory Init
- //
- // after this is set up we can allocate and deallocate blocks
- // of physical memory :)
- //
- // we know that here, the bootloader placed the mamory map and
- // the number of entries.
- //
- mem_init(0x7c00+1,*((uint16_t *)(0x7c00)));
-
-
- //
// Gather Info about other processors. (APs)
// ACPI or MP
//
@@ -130,10 +118,21 @@ void kernel_main(uint32_t initial_stack, int mp)
if(!mp_find(&procdata))
panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
+ //
+ // Memory Init
+ //
+ // after this is set up we can allocate and deallocate blocks
+ // of physical memory :)
+ //
+ // we know that here, the bootloader placed the mamory map and
+ // the number of entries.
+ //
+ mem_init(0x7c00+1,*((uint16_t *)(0x7c00)));
+
//
// Start the other Processors (also before paging !)
//
- smp_start_aps(&procdata,0x80000); // starts at 0x90000
+// smp_start_aps(&procdata,0x80000); // starts at 0x90000
// but it will be copied over mbr
//
diff --git a/kernel/mem.c b/kernel/mem.c
index ffa56c4..af58877 100644
--- a/kernel/mem.c
+++ b/kernel/mem.c
@@ -159,7 +159,7 @@ void mem_init(uint16_t *memmap,uint16_t entries)
mem_free_blocks=0;
// count available mem
- uint32_t total_mem=0, highest_end=0, high_end_low=0;
+ uint32_t total_mem=0, highest_end=0, high_end_low=0,last_end=0;
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries);
@@ -178,18 +178,20 @@ void mem_init(uint16_t *memmap,uint16_t entries)
memmap[8],low_end,high_end);
#endif
- if(memmap[8]==1)
+ if(memmap[8]==1||memmap[8]==3)
{
total_mem+=memmap[4]+(memmap[5]<<16);
- }
- if(memmap[8]==1)
- {
- if(high_end>highest_end){
+ if(high_end>highest_end)
+ {
highest_end=high_end;
- high_end_low=low_end;
+ high_end_low=last_end;
}
}
+ else
+ {
+ last_end=high_end+1;
+ }
memmap+=12;
@@ -201,9 +203,9 @@ void mem_init(uint16_t *memmap,uint16_t entries)
mem_array_size=blocks/32+1;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Highest end area: 0x%08X - 0x%08X",high_end_low,highest_end);
if(highest_end-high_end_low<mem_array_size*4)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Highest end area: 0x%08X - 0x%08X",high_end_low,highest_end);
panic(FOOLOS_MODULE_NAME,"not enough space at high end :( sorry.");
}
@@ -215,7 +217,7 @@ void mem_init(uint16_t *memmap,uint16_t entries)
for(int i=0;i<entries;i++)
{
- if(memmap[8]==1)
+ if(memmap[8]==1||memmap[8]==3)
{
pmmngr_init_region(memmap[0]+(memmap[1]<<16),memmap[4]+((memmap[5])<<16));
}