Skip to content

Commit

Permalink
setup stack
Browse files Browse the repository at this point in the history
  • Loading branch information
viren-nadkarni committed Jun 22, 2016
1 parent 3523ebe commit 3784206
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
8 changes: 3 additions & 5 deletions boot/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@
call print_str
call pm_switch

jmp $ ; hang. this shouldn't happen
jmp $ ; hang. this should never happen

load_kernel:
mov bx, KERNEL_OFFSET
mov dh, 16
mov dl, [BOOT_DISK]
call disk_read

ret

[bits 32]

pm_begin:
jmp KERNEL_OFFSET


BOOT_DISK:
db 0

Expand All @@ -57,6 +55,6 @@ PROT_MODE_MSG:
%include "gdt.asm"
%include "pm.asm"
times 510-($-$$) db 0
dw 0xaa55
times 510-($-$$) db 0 ; empty
dw 0xaa55 ; magic number

3 changes: 0 additions & 3 deletions boot/pm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ pm_init:
mov fs, ax
mov gs, ax

mov ebp, 0x9000
mov esp, ebp

call pm_begin

12 changes: 11 additions & 1 deletion kernel/entry.asm
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[bits 32]
[global start]
[extern kmain]
_start:
start:
; initialise stack
mov esp, sys_stack
call kmain
jmp $ ; this should happen when returning from kernel main
; shutdown?

; multiboot headers to be put here

; loads interrupt descriptor table
[global idt_load]
[extern idtp]
Expand Down Expand Up @@ -429,3 +434,8 @@ irq15:
push byte 47
jmp irq_common_stub

; bss definition
section .bss
resb 8192 ; stack grows downwards. so reserve space,
sys_stack: ; and then declare the identifier

27 changes: 13 additions & 14 deletions kernel/link.ld
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
ENTRY(_start)
ENTRY(start)
_start_ = 0x1000;

SECTIONS
{
. = 0x1000;

.text BLOCK(1K) : ALIGN(1K)
.text _start_ :
{
_code_ = .;
*(.text)
}

/* Read-only data. */
.rodata BLOCK(1K) : ALIGN(1K)
{
*(.rodata)
. = ALIGN(4K);
}

/* Read-write data (initialized) */
.data BLOCK(1K) : ALIGN(1K)
.data :
{
_data_ = .;
*(.data)
. = ALIGN(4K);
}

/* Read-write data (uninitialized) and stack */
.bss BLOCK(1K) : ALIGN(1K)
.bss :
{
*(COMMON)
_bss_ = .;
*(.bss)
. = ALIGN(8K);
}

_end_ = .;
}

0 comments on commit 3784206

Please sign in to comment.