Page 1 of 1

Grub2.12 boot failed:Unsupported tag 0x8

Posted: Mon Apr 08, 2024 6:35 am
by TYDQSoft
Look below there is my assembly code,which the grub2.12 execute and show me an error that unsupported tag and I cannot solve it.
I have 8-byte aligned,but it still show me the same error I occured.I cannot position where my error is,so does anyone know where the error?

Code: Select all

KERNEL_STACKSIZE equ 128*1024*1024

section .text
bits 64
header_start:
    ; magic number
    dd 0xe85250d6
    ; architecture
    dd 0
    ; header length
    dd header_end-header_start
    ; checksum
    dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))
    
    align 8
    framebuffer_tag:
        dd 5 ; type
        dd 20  ; size
        dd 800 ; width
        dd 600 ; height
        dd 32   ; depth
    align 8
    framebuffer_tag_end:
    
    align 8
    bootinfo_request_tag:
        dd 1 ; type
        dd bootinfo_request_tag_end - bootinfo_request_tag ;size
        dd 4    ; basic memory info
        dd 1    ; boot command line
        dd 8    ; framebuffer info
        dd 12   ; efi64 system table pointer
    align 8
    bootinfo_request_tag_end:
    
    align 8
    framebuffer_info:
     dd 8 ;type
     dd framebuffer_info_end-framebuffer_info ;size
     dq 256*1024*1024 ;framebuffer_address
     dd 4 ;framebuffer_pitch
     dd 800 ; framebuffer_width
     dd 600 ; framebuffer_height
     db 32 ;framebuffer bits per pixel
     db 1 ;framebuffer type
     db 0 ;reserved
     db 0 ;red_field_position
     db 1 ;red_mask_size
     db 2 ;blue_field_position
     db 1 ;blue_mask_size
     db 1 ;green_field_position
     db 1 ;green_mask_size
    align 8
    framebuffer_info_end:
    
    ; end tag
    dd 0
    dd 8 
align 8
header_end:

bits 32 

global start

start:
	mov esp, stack_top

	call check_multiboot
	call check_cpuid
	call check_long_mode

	call setup_page_tables
	call enable_paging

	lgdt [gdt64.pointer]
	jmp 0x8:long_mode_start

	hlt

check_multiboot:
	cmp eax, 0x36d76289
	jne .no_multiboot
	ret
.no_multiboot:
	mov al, "M"
	jmp error

check_cpuid:
	pushfd
	pop eax
	mov ecx, eax
	xor eax, 1 << 21
	push eax
	popfd
	pushfd
	pop eax
	push ecx
	popfd
	cmp eax, ecx
	je .no_cpuid
	ret
.no_cpuid:
	mov al, "C"
	jmp error

check_long_mode:
	mov eax, 0x80000000
	cpuid
	cmp eax, 0x80000001
	jb .no_long_mode

	mov eax, 0x80000001
	cpuid
	test edx, 1 << 29
	jz .no_long_mode
	
	ret
.no_long_mode:
	mov al, "L"
	jmp error

setup_page_tables:
	mov eax, page_table_l3
	or eax, 0b11 ; present, writable
	mov [page_table_l4], eax
	
	mov eax, page_table_l2
	or eax, 0b11 ; present, writable
	mov [page_table_l3], eax

	mov ecx, 0 ; counter
.loop:

	mov eax, 0x200000 ; 2MiB
	mul ecx
	or eax, 0b10000011 ; present, writable, huge page
	mov [page_table_l2 + ecx * 8], eax

	inc ecx ; increment counter
	cmp ecx, 512 ; checks if the whole table is mapped
	jne .loop ; if not, continue

	ret

enable_paging:
	; pass page table location to cpu
	mov eax, page_table_l4
	mov cr3, eax

	; enable PAE
	mov eax, cr4
	or eax, 1 << 5
	mov cr4, eax

	; enable long mode
	mov ecx, 0xC0000080
	rdmsr
	or eax, 1 << 8
	wrmsr

	; enable paging
	mov eax, cr0
	or eax, 1 << 31
	mov cr0, eax

	ret

error:
	; print "ERR: X" where X is the error code
	mov dword [0xb8000], 0x4f524f45
	mov dword [0xb8004], 0x4f3a4f52
	mov dword [0xb8008], 0x4f204f20
	mov byte  [0xb800a], al
	hlt

bits 64
long_mode_start:
    ; load null into all data segment registers
    mov ax, 0
    mov ss, ax
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    
    mov rsp,KERNEL_STACK+KERNEL_STACKSIZE
    
    extern kernel_main
    call kernel_main
    
    hlt	

bits 32
section .bss
align 4096
page_table_l4:
	resb 4096
page_table_l3:
	resb 4096
page_table_l2:
	resb 4096
stack_bottom:
	resb 4096 * 4
stack_top:

bits 64
KERNEL_STACK:
 resb KERNEL_STACKSIZE

bits 32
section .rodata
gdt64:
	dq 0 ; zero entry
.code_segment: equ $ - gdt64
	dq (1 << 43) | (1 << 44) | (1 << 47) | (1 << 53) ; code segment
.pointer:
	dw $ - gdt64 - 1 ; length
	dq gdt64 ; address
Can anyone solve my problem?I will thank to this friend!

Re: Grub2.12 boot failed:Unsupported tag 0x8

Posted: Tue Jun 11, 2024 6:33 pm
by Octocontrabass
You're not aligning the start of your Multiboot header, but I don't think it would boot at all if that were the problem. Perhaps we need to see the rest of your code.

Re: Grub2.12 boot failed:Unsupported tag 0x8

Posted: Tue Jun 11, 2024 7:03 pm
by MichaelPetch
I thought this question looked familiar. See https://stackoverflow.com/questions/782 ... ted-tag0x8

Type 8 isn't a valid multiboot *header* tag.