Commit dd9209b7 by triazo

Add multiboot header and test read some info

parent 09b732fe
Showing with 24 additions and 12 deletions
...@@ -4,7 +4,7 @@ MEMINFO equ 1<<1 ; provide memory map ...@@ -4,7 +4,7 @@ MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MBALIGN | MEMINFO ; this is the Multiboot 'flag' field FLAGS equ MBALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot
; Declare a header as in the Multiboot Standard. We put this into a special ; Declare a header as in the Multiboot Standard. We put this into a special
; section so we can force the header to be in the start of the final program. ; section so we can force the header to be in the start of the final program.
; You don't need to understand all these details as it is just magic values that ; You don't need to understand all these details as it is just magic values that
...@@ -15,7 +15,7 @@ align 4 ...@@ -15,7 +15,7 @@ align 4
dd MAGIC dd MAGIC
dd FLAGS dd FLAGS
dd CHECKSUM dd CHECKSUM
; Currently the stack pointer register (esp) points at anything and using it may ; Currently the stack pointer register (esp) points at anything and using it may
; cause massive harm. Instead, we'll provide our own stack. We will allocate ; cause massive harm. Instead, we'll provide our own stack. We will allocate
; room for a small temporary stack by creating a symbol at the bottom of it, ; room for a small temporary stack by creating a symbol at the bottom of it,
...@@ -25,7 +25,7 @@ align 4 ...@@ -25,7 +25,7 @@ align 4
stack_bottom: stack_bottom:
resb 16384 resb 16384
stack_top: stack_top:
; The linker script specifies _start as the entry point to the kernel and the ; The linker script specifies _start as the entry point to the kernel and the
; bootloader will jump to this position once the kernel has been loaded. It ; bootloader will jump to this position once the kernel has been loaded. It
; doesn't make sense to return from this function as the bootloader is gone. ; doesn't make sense to return from this function as the bootloader is gone.
...@@ -42,7 +42,7 @@ _start: ...@@ -42,7 +42,7 @@ _start:
; you get to make the entire system yourself. You have absolute and complete ; you get to make the entire system yourself. You have absolute and complete
; power over the machine, there are no security restrictions, no safe ; power over the machine, there are no security restrictions, no safe
; guards, no debugging mechanisms, there is nothing but what you build. ; guards, no debugging mechanisms, there is nothing but what you build.
; By now, you are perhaps tired of assembly language. You realize some ; By now, you are perhaps tired of assembly language. You realize some
; things simply cannot be done in C, such as making the multiboot header in ; things simply cannot be done in C, such as making the multiboot header in
; the right section and setting up the stack. However, you would like to ; the right section and setting up the stack. However, you would like to
...@@ -51,17 +51,20 @@ _start: ...@@ -51,17 +51,20 @@ _start:
; such code. C doesn't expect much at this point and we only need to set up ; such code. C doesn't expect much at this point and we only need to set up
; a stack. Note that the processor is not fully initialized yet and stuff ; a stack. Note that the processor is not fully initialized yet and stuff
; such as floating point instructions are not available yet. ; such as floating point instructions are not available yet.
; To set up a stack, we simply set the esp register to point to the top of ; To set up a stack, we simply set the esp register to point to the top of
; our stack (as it grows downwards). ; our stack (as it grows downwards).
mov esp, stack_top mov esp, stack_top
push eax ; Multiboot magic number
push ebx ; Multiboot info struct
; We are now ready to actually execute C code. We cannot embed that in an ; We are now ready to actually execute C code. We cannot embed that in an
; assembly file, so we'll create a kernel.c file in a moment. In that file, ; assembly file, so we'll create a kernel.c file in a moment. In that file,
; we'll create a C entry point called kernel_main and call it here. ; we'll create a C entry point called kernel_main and call it here.
extern kernel_main extern kernel_main
call kernel_main call kernel_main
; In case the function returns, we'll want to put the computer into an ; In case the function returns, we'll want to put the computer into an
; infinite loop. To do that, we use the clear interrupt ('cli') instruction ; infinite loop. To do that, we use the clear interrupt ('cli') instruction
; to disable interrupts, the halt instruction ('hlt') to stop the CPU until ; to disable interrupts, the halt instruction ('hlt') to stop the CPU until
......
#include <stdbool.h> /* C doesn't have booleans by default. */ /*
kern.c is where the c code starts, as invoked by our heading
assembly. It should only contain high level code
*/
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -9,11 +14,10 @@ ...@@ -9,11 +14,10 @@
#include "gdt.h" #include "gdt.h"
#include "idt.h" #include "idt.h"
#include "test.h" #include "test.h"
#include "multiboot.h"
#if defined(__cplusplus) // The parameters passed here ultimately come through the bootloader
extern "C" /* Use C linkage for kernel_main. */ void kernel_main(multiboot_info* mbd, uint32_t magic)
#endif
void kernel_main()
{ {
/* Initialize terminal and serial interfaces */ /* Initialize terminal and serial interfaces */
terminal_initialize(); terminal_initialize();
...@@ -29,6 +33,11 @@ void kernel_main() ...@@ -29,6 +33,11 @@ void kernel_main()
terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Hello, kernel World!\n");
//serial_writestring("Second Serial Test\n"); //serial_writestring("Second Serial Test\n");
serial_hexstring(&magic, 4);
serial_writestring("\n");
serial_hexstring(&(mbd->flags), 8);
serial_writestring("\n");
// Enable paging of memory. For now there is only one virtual // Enable paging of memory. For now there is only one virtual
// memory space defined by page_dir // memory space defined by page_dir
page_directory_entry* page_dir; page_directory_entry* page_dir;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment