メモリサイズ取得
int 15hのFunction 0xE801と0x88でのメモリサイズの取得が出来た
/* We have to get the phisical memory map. * Using "Function E820" and "Function E801" but not "Function 88H", * we'll get it. * EAX 0xE820 - BIOS command to get the memory map * EDX "SMAP" - special string to get the memory map * ES:DI - entry buffer address to set the memory map * ECX - the size of the entry buffer */ e820_mmap_maxsize: .byte 32 SMAP = 0x534d4150 # "SMAP" xorl %ebx, %ebx movw $MEMORY_MAP, %di e820_start: movl 0x0000e820, %eax movl $SMAP, %edx movl $20, %ecx int $0x15 jc e820_error cmpl $SMAP, %eax jc e820_error cmpl $0, %ebx jz e820_end movb (e820_mmap_maxsize), %al cmpb $0, %al jz e820_end decb (e820_mmap_maxsize) movw %di, %ax addw $20, %ax movw %ax, %di jmp e820_start # get the next memory map e820_error: call print_all_registers movw $e820_fail_mes, %si call printstr e820_end: /* We have to get the memory size. * This function is the getting physical memory size from BIOS. * If memory size is less than 64MB, this function will be failed. * At the time, we'll use the 88 function. */ e801_start: movw $0xe801, %ax int $0x15 jc e801_error #if DEBUG call print_all_registers #endif pushw %bx shr $10, %ax xorb %ah, %ah incb %al movw %ax, (MEMORY_SIZE) popw %bx shr $4, %bx addw %bx, (MEMORY_SIZE) #if DEBUG movw (MEMORY_SIZE), %ax call print_register #endif jmp mem_check_end e801_error: call print_all_registers movw $e801_fail_mes, %si call printstr /* This function have the feature getting memory size less than 64MB * If this function also fail, we set 64MB as default memory size. */ m88_start: movb $0x88, %ah int $0x15 shr $10, %ax xorb %ah, %ah incb %al movw %ax, (MEMORY_SIZE) #if DEBUG movw (MEMORY_SIZE), %ax call print_register #endif jmp mem_check_end m88_error: call print_all_registers movw $m88_fail_mes, %si call printstr mem_set_default: movw $0x40, %ax # set 64MB movw %ax, (MEMORY_SIZE) mem_check_end:
次の処理としてはA20の有効化(0x100000以上のメモリアドレスのアクセスに必要な処理)をする必要があるけど、とりあえず置いといてCPUをプロテクトモードに移行しよう。
IDT,GDTは仮の値を入れてCで書きはじめる部分で正式な値を入れようと思う。