]> Devi Nivas Git - cs3210-lab1.git/commitdiff
Added very minimal e820 support to the bootblock, had to omit frame pointers to compile
authorDavid Devecsery <ddevec@gatech.edu>
Mon, 18 May 2020 15:59:06 +0000 (11:59 -0400)
committerDavid Devecsery <ddevec@gatech.edu>
Mon, 18 May 2020 15:59:06 +0000 (11:59 -0400)
bootblock/CMakeLists.txt
bootblock/e820.S [new file with mode: 0644]

index 5e0f66c4e4addddf9c096c48bca75bb11f9b2600..b25db5c8201b689af6300d57a0ff09f60a31f9f9 100644 (file)
@@ -6,12 +6,15 @@ set(bootblock_SOURCES
   # NOTE: bootasm.S must go first in this list, to ensure its placed at 0x7c00
   #   in the bootloader dump
   bootasm.S
+  e820.S
   bootmain.c)
 
 add_library(bootblockobjs OBJECT
   ${bootblock_SOURCES})
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -fno-builtin -fno-pic -nostdinc -m32")
+# NOTE: I'm omitting frame pointers, which will screw hard with debugging,
+#   but it should be fine for the boot block?
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -fno-builtin -fno-pic -fomit-frame-pointer -nostdinc -m32")
 set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m elf_i386")
 
diff --git a/bootblock/e820.S b/bootblock/e820.S
new file mode 100644 (file)
index 0000000..03eb0ba
--- /dev/null
@@ -0,0 +1,48 @@
+.code16                       # Assemble for 16-bit mode
+
+magic:
+  .long 0x0534d4150
+
+e820:
+  .long 0xe820
+
+# Only 16 bit.
+dest_addr:
+  .word 0x0
+
+
+# The desetination adder (where the data will be stored) is passed in eax
+.globl do_e820
+do_e820:
+  mov %ax, (dest_addr)
+  add $4, %ax
+  mov %ax, %di
+  xor %ebx, %ebx
+  xor %bp, %bp
+  mov (magic), %edx
+
+.e820lp:
+  mov (e820), %eax
+  movl $1, %es:20(%di)
+  mov $24, %ecx
+  int $0x15
+  jc .e820f
+  mov (magic), %edx
+
+  cmp %edx, %eax
+  jne .e820f
+  test %ebx, %ebx
+  je .e820f
+  jcxz .skipent
+  cmp $20, %cl
+  inc %bp              
+  add $24, %di
+.skipent:
+  test %ebx, %ebx
+  jne .e820lp
+.e820f:
+  xor %eax, %eax
+  mov (dest_addr), %ax
+  mov %bp, (%eax)
+  ret
+