kmain:
Code: Select all
void kmain(void* mmap_address, uint32_t mmapentrycount, uint32_t memSize)
{
SetColour(0x1F);
ClearScreen();
PrintString("Skux OS\n");
SetupInterrupts();
timer_install();
keyboard_install();
__asm__ __volatile__("sti");
//initialise physical memory manager
PrintNumberBase16(memSize >> 24);
PrintNumberBase16(memSize >> 16 & 0xFF);
PrintNumberBase16(memSize >> 8 & 0xFF);
PrintNumberBase16(memSize & 0xFF);
//Process memory map
SMAP_entry* sm = (SMAP_entry*)mmap_address;
for(unsigned int i=0;i<mmapentrycount;i++)
{
if(sm[i].Type == 1 || sm[i].Type == 3) //Free for use or ACPI reclaimable
{
//init region
}
}
for(;;)
{
__asm__ __volatile__("hlt");
}
}
This is the assembly code generated by gcc:
Code: Select all
.file "kernel.c"
.section .rodata
.LC0:
.string "Skux OS\n"
.text
.globl kmain
.type kmain, @function
kmain:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $40, %esp
movl $31, (%esp)
call SetColour
call ClearScreen
movl $.LC0, (%esp)
call PrintString
call SetupInterrupts
call timer_install
call keyboard_install
#APP
# 14 "kernel.c" 1
sti
# 0 "" 2
#NO_APP
movl 16(%ebp), %eax
shrl $24, %eax
movzbl %al, %eax
movl %eax, (%esp)
call PrintNumberBase16
movl 16(%ebp), %eax
shrl $16, %eax
movzbl %al, %eax
movl %eax, (%esp)
call PrintNumberBase16
movl 16(%ebp), %eax
shrl $8, %eax
movzbl %al, %eax
movl %eax, (%esp)
call PrintNumberBase16
movl 16(%ebp), %eax
movzbl %al, %eax
movl %eax, (%esp)
call PrintNumberBase16
movl 8(%ebp), %eax
movl %eax, -16(%ebp)
movl $0, -12(%ebp)
jmp .L2
.L4:
movl -12(%ebp), %edx
movl %edx, %eax
addl %eax, %eax
addl %edx, %eax
sall $3, %eax
movl %eax, %edx
movl -16(%ebp), %eax
addl %edx, %eax
movzwl 16(%eax), %eax
cmpw $1, %ax
je .L3
movl -12(%ebp), %edx
movl %edx, %eax
addl %eax, %eax
addl %edx, %eax
sall $3, %eax
.L3:
addl $1, -12(%ebp)
.L2:
movl -12(%ebp), %eax
cmpl 12(%ebp), %eax
jb .L4
.L5:
#APP
# 39 "kernel.c" 1
hlt
# 0 "" 2
#NO_APP
jmp .L5
.cfi_endproc
.LFE0:
.size kmain, .-kmain
.ident "GCC: (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2"
.section .note.GNU-stack,"",@progbits
And this is how I compile kmain:
Code: Select all
gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -std=c99
I have had a look at the assembly code but I don't really understand GAS that well.