Added support for GRUB multiboot header data. Disabled all GC.
This commit is contained in:
parent
6984bf42b2
commit
e9db400e15
@ -2,7 +2,7 @@
|
||||
{.passL: "-ffreestanding -target i386 -nostdlib -T arch/i386/linker.ld".}
|
||||
{.passC: "-ffreestanding -nostdlib --target=i386-pc-none-elf -march=i386".}
|
||||
|
||||
import tty, gdt, interrupts, serial
|
||||
import tty, gdt, interrupts, serial, multiboot
|
||||
|
||||
const version {.strdefine.} = "UNKNOWN"
|
||||
|
||||
@ -20,10 +20,14 @@ proc memset*(dest: ByteAddress, value: char, count: int){.exportc.} =
|
||||
for i in 0..count-1:
|
||||
destMem[i] = value
|
||||
|
||||
proc kernelMain() {.exportc: "kernel_main"}=
|
||||
proc getMemoryMap(mbd: multiboot_info) =
|
||||
discard # Use this if we need to do anything with the GRUB memory map
|
||||
|
||||
proc kernelMain(mbd: multiboot_info, magic: uint) {.exportc: "kernel_main"}=
|
||||
serial.init()
|
||||
serial.writeLine("Version:" & (version))
|
||||
serial.writeLine("Booting OS")
|
||||
getMemoryMap(mbd)
|
||||
gdt.gdtInstall()
|
||||
serial.writeLine("GDT installed")
|
||||
interrupts.idtInstall()
|
||||
|
280
kernel/multiboot.nim
Normal file
280
kernel/multiboot.nim
Normal file
@ -0,0 +1,280 @@
|
||||
## multiboot.h - Multiboot header file.
|
||||
## Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
##
|
||||
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
## of this software and associated documentation files (the "Software"), to
|
||||
## deal in the Software without restriction, including without limitation the
|
||||
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
## sell copies of the Software, and to permit persons to whom the Software is
|
||||
## furnished to do so, subject to the following conditions:
|
||||
##
|
||||
## The above copyright notice and this permission notice shall be included in
|
||||
## all copies or substantial portions of the Software.
|
||||
##
|
||||
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
|
||||
## DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
## IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
##
|
||||
|
||||
## How many bytes from the start of the file we search for the header.
|
||||
|
||||
const
|
||||
MULTIBOOT_SEARCH* = 8192
|
||||
MULTIBOOT_HEADER_ALIGN* = 4
|
||||
|
||||
## The magic field should contain this.
|
||||
|
||||
const
|
||||
MULTIBOOT_HEADER_MAGIC* = 0x1BADB002
|
||||
|
||||
## This should be in %eax.
|
||||
|
||||
const
|
||||
MULTIBOOT_BOOTLOADER_MAGIC* = 0x2BADB002
|
||||
|
||||
## Alignment of multiboot modules.
|
||||
|
||||
const
|
||||
MULTIBOOT_MOD_ALIGN* = 0x00001000
|
||||
|
||||
## Alignment of the multiboot info structure.
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_ALIGN* = 0x00000004
|
||||
|
||||
## Flags set in the 'flags' member of the multiboot header.
|
||||
## Align all boot modules on i386 page (4KB) boundaries.
|
||||
|
||||
const
|
||||
MULTIBOOT_PAGE_ALIGN* = 0x00000001
|
||||
|
||||
## Must pass memory information to OS.
|
||||
|
||||
const
|
||||
MULTIBOOT_MEMORY_INFO* = 0x00000002
|
||||
|
||||
## Must pass video information to OS.
|
||||
|
||||
const
|
||||
MULTIBOOT_VIDEO_MODE* = 0x00000004
|
||||
|
||||
## This flag indicates the use of the address fields in the header.
|
||||
|
||||
const
|
||||
MULTIBOOT_AOUT_KLUDGE* = 0x00010000
|
||||
|
||||
## Flags to be set in the 'flags' member of the multiboot info structure.
|
||||
## is there basic lower/upper memory information?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_MEMORY* = 0x00000001
|
||||
|
||||
## is there a boot device set?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_BOOTDEV* = 0x00000002
|
||||
|
||||
## is the command-line defined?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_CMDLINE* = 0x00000004
|
||||
|
||||
## are there modules to do something with?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_MODS* = 0x00000008
|
||||
|
||||
## These next two are mutually exclusive
|
||||
## is there a symbol table loaded?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_AOUT_SYMS* = 0x00000010
|
||||
|
||||
## is there an ELF section header table?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_ELF_SHDR* = 0x00000020
|
||||
|
||||
## is there a full memory map?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_MEM_MAP* = 0x00000040
|
||||
|
||||
## Is there drive info?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_DRIVE_INFO* = 0x00000080
|
||||
|
||||
## Is there a config table?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_CONFIG_TABLE* = 0x00000100
|
||||
|
||||
## Is there a boot loader name?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_BOOT_LOADER_NAME* = 0x00000200
|
||||
|
||||
## Is there a APM table?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_APM_TABLE* = 0x00000400
|
||||
|
||||
## Is there video information?
|
||||
|
||||
const
|
||||
MULTIBOOT_INFO_VBE_INFO* = 0x00000800
|
||||
MULTIBOOT_INFO_FRAMEBUFFER_INFO* = 0x00001000
|
||||
|
||||
when not defined(ASM_FILE):
|
||||
type
|
||||
multiboot_uint8_t* = cuchar
|
||||
multiboot_uint16_t* = cushort
|
||||
multiboot_uint32_t* = cuint
|
||||
multiboot_uint64_t* = culonglong
|
||||
type
|
||||
multiboot_header* {.bycopy.} = object
|
||||
magic*: multiboot_uint32_t ## Must be MULTIBOOT_MAGIC - see above.
|
||||
## Feature flags.
|
||||
flags*: multiboot_uint32_t ## The above fields plus this one must equal 0 mod 2^32.
|
||||
checksum*: multiboot_uint32_t ## These are only valid if MULTIBOOT_AOUT_KLUDGE is set.
|
||||
header_addr*: multiboot_uint32_t
|
||||
load_addr*: multiboot_uint32_t
|
||||
load_end_addr*: multiboot_uint32_t
|
||||
bss_end_addr*: multiboot_uint32_t
|
||||
entry_addr*: multiboot_uint32_t ## These are only valid if MULTIBOOT_VIDEO_MODE is set.
|
||||
mode_type*: multiboot_uint32_t
|
||||
width*: multiboot_uint32_t
|
||||
height*: multiboot_uint32_t
|
||||
depth*: multiboot_uint32_t
|
||||
|
||||
|
||||
## The symbol table for a.out.
|
||||
type
|
||||
multiboot_aout_symbol_table* {.bycopy.} = object
|
||||
tabsize*: multiboot_uint32_t
|
||||
strsize*: multiboot_uint32_t
|
||||
`addr`*: multiboot_uint32_t
|
||||
reserved*: multiboot_uint32_t
|
||||
|
||||
type
|
||||
multiboot_aout_symbol_table_t* = multiboot_aout_symbol_table
|
||||
|
||||
## The section header table for ELF.
|
||||
type
|
||||
multiboot_elf_section_header_table* {.bycopy.} = object
|
||||
num*: multiboot_uint32_t
|
||||
size*: multiboot_uint32_t
|
||||
`addr`*: multiboot_uint32_t
|
||||
shndx*: multiboot_uint32_t
|
||||
|
||||
type
|
||||
multiboot_elf_section_header_table_t* = multiboot_elf_section_header_table
|
||||
type
|
||||
INNER_C_UNION_181031587* {.bycopy.} = object {.union.}
|
||||
aout_sym*: multiboot_aout_symbol_table_t
|
||||
elf_sec*: multiboot_elf_section_header_table_t
|
||||
|
||||
type
|
||||
INNER_C_STRUCT_3866696476* {.bycopy.} = object
|
||||
framebuffer_palette_addr*: multiboot_uint32_t
|
||||
framebuffer_palette_num_colors*: multiboot_uint16_t
|
||||
|
||||
type
|
||||
INNER_C_STRUCT_1103324769* {.bycopy.} = object
|
||||
framebuffer_red_field_position*: multiboot_uint8_t
|
||||
framebuffer_red_mask_size*: multiboot_uint8_t
|
||||
framebuffer_green_field_position*: multiboot_uint8_t
|
||||
framebuffer_green_mask_size*: multiboot_uint8_t
|
||||
framebuffer_blue_field_position*: multiboot_uint8_t
|
||||
framebuffer_blue_mask_size*: multiboot_uint8_t
|
||||
|
||||
type
|
||||
INNER_C_UNION_2305456475* {.bycopy.} = object {.union.}
|
||||
ano_2282080798*: INNER_C_STRUCT_3866696476
|
||||
ano_3054406492*: INNER_C_STRUCT_1103324769
|
||||
|
||||
const
|
||||
MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED* = 0
|
||||
MULTIBOOT_FRAMEBUFFER_TYPE_RGB* = 1
|
||||
MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT* = 2
|
||||
type
|
||||
multiboot_info* {.bycopy.} = object
|
||||
flags*: multiboot_uint32_t ## Multiboot info version number
|
||||
## Available memory from BIOS
|
||||
mem_lower*: multiboot_uint32_t
|
||||
mem_upper*: multiboot_uint32_t ## "root" partition
|
||||
boot_device*: multiboot_uint32_t ## Kernel command line
|
||||
cmdline*: multiboot_uint32_t ## Boot-Module list
|
||||
mods_count*: multiboot_uint32_t
|
||||
mods_addr*: multiboot_uint32_t
|
||||
u*: INNER_C_UNION_181031587 ## Memory Mapping buffer
|
||||
mmap_length*: multiboot_uint32_t
|
||||
mmap_addr*: multiboot_uint32_t ## Drive Info buffer
|
||||
drives_length*: multiboot_uint32_t
|
||||
drives_addr*: multiboot_uint32_t ## ROM configuration table
|
||||
config_table*: multiboot_uint32_t ## Boot Loader Name
|
||||
boot_loader_name*: multiboot_uint32_t ## APM table
|
||||
apm_table*: multiboot_uint32_t ## Video
|
||||
vbe_control_info*: multiboot_uint32_t
|
||||
vbe_mode_info*: multiboot_uint32_t
|
||||
vbe_mode*: multiboot_uint16_t
|
||||
vbe_interface_seg*: multiboot_uint16_t
|
||||
vbe_interface_off*: multiboot_uint16_t
|
||||
vbe_interface_len*: multiboot_uint16_t
|
||||
framebuffer_addr*: multiboot_uint64_t
|
||||
framebuffer_pitch*: multiboot_uint32_t
|
||||
framebuffer_width*: multiboot_uint32_t
|
||||
framebuffer_height*: multiboot_uint32_t
|
||||
framebuffer_bpp*: multiboot_uint8_t
|
||||
framebuffer_type*: multiboot_uint8_t
|
||||
ano_3062667995*: INNER_C_UNION_2305456475
|
||||
|
||||
type
|
||||
multiboot_info_t* = multiboot_info
|
||||
type
|
||||
multiboot_color* {.bycopy.} = object
|
||||
red*: multiboot_uint8_t
|
||||
green*: multiboot_uint8_t
|
||||
blue*: multiboot_uint8_t
|
||||
|
||||
const
|
||||
MULTIBOOT_MEMORY_AVAILABLE* = 1
|
||||
MULTIBOOT_MEMORY_RESERVED* = 2
|
||||
MULTIBOOT_MEMORY_ACPI_RECLAIMABLE* = 3
|
||||
MULTIBOOT_MEMORY_NVS* = 4
|
||||
MULTIBOOT_MEMORY_BADRAM* = 5
|
||||
type
|
||||
multiboot_mmap_entry* {.bycopy,packed.} = object
|
||||
size*: multiboot_uint32_t
|
||||
`addr`*: multiboot_uint64_t
|
||||
len*: multiboot_uint64_t
|
||||
`type`*: multiboot_uint32_t
|
||||
|
||||
type
|
||||
multiboot_memory_map_t* = multiboot_mmap_entry
|
||||
type
|
||||
multiboot_mod_list* {.bycopy.} = object
|
||||
mod_start*: multiboot_uint32_t ## the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive
|
||||
mod_end*: multiboot_uint32_t ## Module command line
|
||||
cmdline*: multiboot_uint32_t ## padding to take it to 16 bytes (must be zero)
|
||||
pad*: multiboot_uint32_t
|
||||
|
||||
type
|
||||
multiboot_module_t* = multiboot_mod_list
|
||||
|
||||
## APM BIOS info.
|
||||
type
|
||||
multiboot_apm_info* {.bycopy.} = object
|
||||
version*: multiboot_uint16_t
|
||||
cseg*: multiboot_uint16_t
|
||||
offset*: multiboot_uint32_t
|
||||
cseg_16*: multiboot_uint16_t
|
||||
dseg*: multiboot_uint16_t
|
||||
flags*: multiboot_uint16_t
|
||||
cseg_len*: multiboot_uint16_t
|
||||
cseg_16_len*: multiboot_uint16_t
|
||||
dseg_len*: multiboot_uint16_t
|
@ -5,7 +5,7 @@ path="arch/i386"
|
||||
|
||||
deadCodeElim=on
|
||||
boundChecks=on
|
||||
gc=regions
|
||||
gc=none
|
||||
cpu=i386
|
||||
os=standalone
|
||||
verbosity=2
|
Loading…
Reference in New Issue
Block a user