Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

a bit of cleanup in kstart.asm formatting

  • Loading branch information...
commit e7f6026b45a0162dc9495988ce0350c94c62fc25 1 parent 500fa00
James Tauber authored
Showing with 103 additions and 100 deletions.
  1. +18 −18 hello_world/kstart.asm
  2. +85 −82 oneplusone/kstart.asm
36 hello_world/kstart.asm
View
@@ -1,32 +1,32 @@
-global loader ; making entry point visible to linker
-extern kmain ; main is defined elsewhere
+global loader ; making entry point visible to linker
+extern kmain ; main is defined elsewhere
; setting up the Multiboot header - see GRUB docs for details
-MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
-MEMINFO equ 1<<1 ; provide memory map
-FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
-MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
-CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
+MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
+MEMINFO equ 1<<1 ; provide memory map
+FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
+MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
+CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
section .text
align 4
MultiBootHeader:
- dd MAGIC
- dd FLAGS
- dd CHECKSUM
+ dd MAGIC
+ dd FLAGS
+ dd CHECKSUM
; reserve initial kernel stack space
-STACKSIZE equ 0x4000 ; that's 16k.
+STACKSIZE equ 0x4000 ; that's 16k.
loader:
- mov esp, stack+STACKSIZE ; set up the stack
- push eax ; pass Multiboot magic number
- push ebx ; pass Multiboot info structure
-
- call kmain ; call kernel proper
- hlt ; halt machine should kernel return
+ mov esp, stack+STACKSIZE ; set up the stack
+ push eax ; pass Multiboot magic number
+ push ebx ; pass Multiboot info structure
+
+ call kmain ; call kernel proper
+ hlt ; halt machine should kernel return
section .bss
align 32
stack:
- resb STACKSIZE ; reserve 16k stack on a quadword boundary
+ resb STACKSIZE ; reserve 16k stack on a quadword boundary
167 oneplusone/kstart.asm
View
@@ -3,16 +3,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; macros to handle leading underscores added by DOS/Windows compilers
-%macro IMP 1
+%macro IMP 1
%ifdef UNDERBARS
- EXTERN _%1
- %define %1 _%1
+ EXTERN _%1
+ %define %1 _%1
%else
- EXTERN %1
+ EXTERN %1
%endif
%endmacro
-DS_MAGIC equ 3544DA2Ah
+DS_MAGIC equ 3544DA2Ah
SECTION .text
BITS 32
@@ -23,41 +23,42 @@ BITS 32
GLOBAL entry
entry:
-; check if data segment linked, located, and loaded properly
- mov eax,[ds_magic]
- cmp eax,DS_MAGIC
- je ds_ok
-
-; display a blinking white-on-blue 'D' and freeze
- mov word [0B8000h],9F44h
- jmp short $
-ds_ok:
+ ; check if data segment linked, located, and loaded properly
+ mov eax,[ds_magic]
+ cmp eax,DS_MAGIC
+ je ds_ok
+
+ ; display a blinking white-on-blue 'D' and freeze
+ mov word [0B8000h],9F44h
+ jmp short $
-; stop using bootloader GDT, and load new GDT
- lgdt [gdt_ptr]
+ds_ok:
+ ; stop using bootloader GDT, and load new GDT
+ lgdt [gdt_ptr]
+
+ mov ax,LINEAR_DATA_SEL
+ mov ds,ax
+ mov es,ax
+ mov ss,ax
+ mov fs,ax
+ mov gs,ax
+ jmp LINEAR_CODE_SEL:sbat
- mov ax,LINEAR_DATA_SEL
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov fs,ax
- mov gs,ax
- jmp LINEAR_CODE_SEL:sbat
sbat:
-
-; zero the C language BSS
-; 'bss' and 'end' are defined in the linker script file
+ ; zero the C language BSS
+ ; 'bss' and 'end' are defined in the linker script file
EXTERN bss, end
- mov edi,bss
- mov ecx,end
- sub ecx,edi
- xor eax,eax
- rep stosb
-
- mov esp,stack
+ mov edi,bss
+ mov ecx,end
+ sub ecx,edi
+ xor eax,eax
+ rep stosb
+
+ mov esp,stack
+
IMP main
- call main ; call C code
- jmp $ ; freeze
+ call main ; call C code
+ jmp $ ; freeze
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiboot header for GRUB bootloader. This must be in the first 8K
@@ -65,76 +66,78 @@ IMP main
; DJGPP COFF, Win32 PE, or other formats.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-MULTIBOOT_PAGE_ALIGN equ 1<<0
-MULTIBOOT_MEMORY_INFO equ 1<<1
-MULTIBOOT_AOUT_KLUDGE equ 1<<16
-MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
-MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
-MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
+MULTIBOOT_PAGE_ALIGN equ 1<<0
+MULTIBOOT_MEMORY_INFO equ 1<<1
+MULTIBOOT_AOUT_KLUDGE equ 1<<16
+MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
+MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
+MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
; these are in the linker script file
EXTERN code, bss, end
ALIGN 4
mboot:
- dd MULTIBOOT_HEADER_MAGIC
- dd MULTIBOOT_HEADER_FLAGS
- dd MULTIBOOT_CHECKSUM
-; aout kludge. These must be PHYSICAL addresses
- dd mboot
- dd code
- dd bss
- dd end
- dd entry
+ dd MULTIBOOT_HEADER_MAGIC
+ dd MULTIBOOT_HEADER_FLAGS
+ dd MULTIBOOT_CHECKSUM
+
+ ; aout kludge. These must be PHYSICAL addresses
+ dd mboot
+ dd code
+ dd bss
+ dd end
+ dd entry
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SECTION .data
ds_magic:
- dd DS_MAGIC
+ dd DS_MAGIC
gdt:
; NULL descriptor
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
+ dw 0 ; limit 15:0
+ dw 0 ; base 15:0
+ db 0 ; base 23:16
+ db 0 ; type
+ db 0 ; limit 19:16, flags
+ db 0 ; base 31:24
; unused descriptor
- dw 0
- dw 0
- db 0
- db 0
- db 0
- db 0
-
-LINEAR_DATA_SEL equ $-gdt
- dw 0FFFFh
- dw 0
- db 0
- db 92h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular (4 gig limit), 32-bit
- db 0
-
-LINEAR_CODE_SEL equ $-gdt
- dw 0FFFFh
- dw 0
- db 0
- db 9Ah ; present,ring 0,code,non-conforming,readable
- db 0CFh ; page-granular (4 gig limit), 32-bit
- db 0
+ dw 0
+ dw 0
+ db 0
+ db 0
+ db 0
+ db 0
+
+LINEAR_DATA_SEL equ $-gdt
+ dw 0FFFFh
+ dw 0
+ db 0
+ db 92h ; present, ring 0, data, expand-up, writable
+ db 0CFh ; page-granular (4 gig limit), 32-bit
+ db 0
+
+LINEAR_CODE_SEL equ $-gdt
+ dw 0FFFFh
+ dw 0
+ db 0
+ db 9Ah ; present,ring 0,code,non-conforming,readable
+ db 0CFh ; page-granular (4 gig limit), 32-bit
+ db 0
+
gdt_end:
gdt_ptr:
- dw gdt_end - gdt - 1
- dd gdt
+ dw gdt_end - gdt - 1
+ dd gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SECTION .bss
+ resd 1024
- resd 1024
stack:
Please sign in to comment.
Something went wrong with that request. Please try again.