transfer control to C
This commit is contained in:
parent
203483d8b2
commit
2b1b7568b0
4
Makefile
4
Makefile
|
@ -2,7 +2,9 @@ CC = i686-elf-gcc
|
|||
AS = nasm
|
||||
|
||||
BUILDDIR := build
|
||||
CFLAGS := -ffreestanding -Wall -Wextra -Werror
|
||||
INCLUDEDIR := include
|
||||
|
||||
CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR)
|
||||
LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld
|
||||
|
||||
KSRC := $(wildcard kernel/*.asm kernel/*.c)
|
||||
|
|
29
include/kernel/multiboot.h
Normal file
29
include/kernel/multiboot.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef HAZEL_MULTIBOOT_H_
|
||||
#define HAZEL_MULTIBOOT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags; //required
|
||||
uint32_t memlower; //if bit 0 in flags are set
|
||||
uint32_t memupper; //if bit 0 in flags are set
|
||||
uint32_t bootdevice; //if bit 1 in flags are set
|
||||
uint32_t commandline; //if bit 2 in flags are set
|
||||
uint32_t modulecount; //if bit 3 in flags are set
|
||||
uint32_t moduleaddress; //if bit 3 in flags are set
|
||||
uint32_t syms[4]; //if bits 4 or 5 in flags are set
|
||||
uint32_t memmaplength; //if bit 6 in flags is set
|
||||
uint32_t memmapaddress; //if bit 6 in flags is set
|
||||
uint32_t driveslength; //if bit 7 in flags is set
|
||||
uint32_t drivesaddress; //if bit 7 in flags is set
|
||||
uint32_t configtable; //if bit 8 in flags is set
|
||||
uint32_t apmtable; //if bit 9 in flags is set
|
||||
uint32_t vbecontrolinfo; //if bit 10 in flags is set
|
||||
uint32_t vbemodeinfo; //if bit 11 in flags is set
|
||||
uint32_t vbemode; // all vbe_* set if bit 12 in flags are set
|
||||
uint32_t vbeinterfaceseg;
|
||||
uint32_t vbeinterfaceoff;
|
||||
uint32_t vbeinterfacelength;
|
||||
} multiboot_info_t;
|
||||
|
||||
#endif
|
|
@ -9,8 +9,64 @@ dd -(MAGIC + FLAGS)
|
|||
section .text
|
||||
global _start
|
||||
_start:
|
||||
mov byte [0xb8000], 'X'
|
||||
mov byte [0xb8001], 0x0f
|
||||
cli
|
||||
|
||||
cli
|
||||
jmp $
|
||||
; Check if EAX contains this magic value that our bootloader should've set
|
||||
cmp eax, 0x2BADB002
|
||||
jne halt
|
||||
|
||||
; Load GDT
|
||||
lgdt [gdtp]
|
||||
; Offset to kernel data descriptor
|
||||
mov ax, 0x10
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
; Offset to kernel code descriptor
|
||||
jmp 0x8:.use_code_seg
|
||||
.use_code_seg:
|
||||
mov esp, stack_bottom
|
||||
mov ebp, esp
|
||||
push ebx
|
||||
and esp, 0xfffffff0
|
||||
extern kernel
|
||||
call kernel
|
||||
cli
|
||||
halt:
|
||||
hlt
|
||||
jmp halt
|
||||
|
||||
section .data
|
||||
; GDT for a flat memory layout
|
||||
; We get access to all memory and can utilize paging
|
||||
global gdt
|
||||
gdt:
|
||||
gdt_null:
|
||||
dq 0
|
||||
gdt_kern_code:
|
||||
dw 0xffff
|
||||
dw 0x0000
|
||||
db 0x00
|
||||
db 0b10011010
|
||||
db 0b11001111
|
||||
db 0x00
|
||||
gdt_kern_data:
|
||||
dw 0xffff
|
||||
dw 0x0000
|
||||
db 0x00
|
||||
db 0b10010010
|
||||
db 0b11001111
|
||||
db 0x00
|
||||
gdt_end:
|
||||
|
||||
gdtp:
|
||||
dw gdt_end - gdt - 1
|
||||
dd gdt
|
||||
|
||||
section .bss
|
||||
align 16
|
||||
stack_top:
|
||||
resb 16384
|
||||
stack_bottom:
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
void kernel() {
|
||||
#include <kernel/multiboot.h>
|
||||
|
||||
void kernel(multiboot_info_t *info) {
|
||||
char *vmem = (char *)0xb8000;
|
||||
vmem[0] = info->flags;
|
||||
vmem[1] = 0x0f;
|
||||
|
||||
asm volatile ("cli" ::);
|
||||
for (;;) {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user