[BITS 32]
[SECTION .text]
EXTERN code
EXTERN bss
EXTERN end
mboot:
dd 0x1BADB002
dd 0x10001
dd -(0x1BADB002+0x10001)
dd mboot
dd code
dd bss
dd end
dd start
GLOBAL start
start:
cli
mov esp,kstack+4096
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
lgdt [gdt_descr]
jmp .1
.1:
push dword 0
push dword 0
push dword 0
push dword L6
EXTERN kernel
push dword kernel
ret
L6:
jmp L6
[SECTION .bss]
kstack: resd 1024
[SECTION .data]
gdt_descr:
dw 256*8-1
dd _gdt
GLOBAL _gdt
_gdt:
dd 0,0
dd 0x0000FFFF,0x00CF9A00
dd 0x0000FFFF,0x00CF9200
dd 0,0
times 254 dd 0,0
Powyżej init.asm
void kernel()
{
unsigned char *vga=(char *)0xb8000;
void kernel_printf(char *phrase)
{
while(*phrase != '\0')
{
*vga++= *phrase;
*vga++ = 0x07;
phrase++;
}
}
void kernel_halt()
{
while(1) {}
}
kernel_printf("Hello World");
kernel_halt();
}
Powyżej kernel.c
OUTPUT_FORMAT("binary")
ENTRY("start")
SECTIONS {
.text 0x100000 : {
code = . ; _code = . ;
*(.text)
}
.data : {
*(.data)
}
.bss : {
bss = . ; _bss = . ;
*(.bss)
*(.COMMON)
}
end = . ; _end = . ;
}
Powyżej kernel.ld
#!/bin/bash
#apt-get update -y
#apt-get upgrade -y
#apt-get -f install -y
#apt-get install build-essential nasm xorriso
gcc kernel.c -O2 -fomit-frame-pointer -c -o kernel.o
nasm init.asm -o init.o -f elf64
ld -Tkernel.ld -o kernel.bin init.o kernel.o
grub-mkrescue -o systemik.iso iso
Powyżej pseudo-make.
I teraz mam do Was prośbę, dlaczego VirtualBox nie wyświetla HelloWorld po wyjściu z gruba?