Browse Source

Remove useless multiboot mmap stuff.

Giovanni Mascellani 5 years ago
parent
commit
541c6dc267
5 changed files with 230 additions and 264 deletions
  1. 2 2
      Makefile
  2. 1 3
      asmg0/asmg0.asm
  3. 221 0
      attic/mb_mmap.asm
  4. 1 249
      lib/kernel.asm
  5. 5 10
      lib/mb_header.asm

+ 2 - 2
Makefile

@@ -67,7 +67,7 @@ build/diskfs.img: build/diskfs.list
 build/script.g:
 	bash -c "echo -n" > $@
 
-build/full-asmg.asm: lib/multiboot.asm lib/kernel.asm lib/shutdown.asm lib/ar.asm lib/library.asm lib/setjmp.asm lib/pmc.asm asmg/asmg.asm asmg/kernel-asmg.asm lib/top.asm
+build/full-asmg.asm: lib/mb_header.asm lib/kernel.asm lib/shutdown.asm lib/ar.asm lib/library.asm lib/setjmp.asm lib/pmc.asm asmg/asmg.asm asmg/kernel-asmg.asm lib/top.asm
 	cat $^ | grep -v "^ *section " > $@
 
 build/initrd-asmg.ar: asmg/*.g build/script.g test/test.hex2 test/test.m1 test/test_mes.c test/test.asm build/END
@@ -88,7 +88,7 @@ build/boot_asmg.x86: build/bootloader.x86.mbr build/bootloader.x86.stage2 build/
 	./create_partition.py $^ > $@
 
 # Asmg0 kernel
-build/full-asmg0.asm: lib/multiboot.asm asmg0/asmg0.asm lib/shutdown.asm asmg0/debug.asm lib/top.asm
+build/full-asmg0.asm: lib/mb_header.asm asmg0/asmg0.asm lib/shutdown.asm asmg0/debug.asm lib/top.asm
 	cat $^ | grep -v "^ *section " > $@
 
 build/asmg0.x86.exe: build/full-asmg0.asm

+ 1 - 3
asmg0/asmg0.asm

@@ -18,9 +18,7 @@
 	PROGRAM_SIZE equ 0x100000
 	SKIP_SIZE equ 0x1000000
 
-start_from_raw:
-start_from_multiboot:
-
+entry:
 	;; Store the address of the script in ESI
 	mov esi, initrd
 

+ 221 - 0
attic/mb_mmap.asm

@@ -0,0 +1,221 @@
+;; This file is part of asmc, a bootstrapping OS with minimal seed
+;; Copyright (C) 2018-2019 Giovanni Mascellani <gio@debian.org>
+;; https://gitlab.com/giomasce/asmc
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+dump_multiboot:
+  push ebp
+  mov ebp, esp
+  push ebx
+  push esi
+
+  ;; Save multiboot location
+  mov ebx, [ebp+8]
+
+  ;; Log
+  push str_dump_multiboot
+  push 1
+  call platform_log
+  add esp, 8
+
+  ;; Check mem_lower and mem_upper are supported
+  mov eax, [ebx]
+  test eax, 1
+  je dump_multiboot_mmap
+
+  ;; Print mem_lower
+  push str_mem_lower
+  push 1
+  call platform_log
+  add esp, 8
+  mov eax, [ebx+4]
+  push eax
+  call itoa
+  add esp, 4
+  push eax
+  push 1
+  call platform_log
+  add esp, 8
+  push str_newline
+  push 1
+  call platform_log
+  add esp, 8
+
+  ;; Print mem_upper
+  push str_mem_upper
+  push 1
+  call platform_log
+  add esp, 8
+  mov eax, [ebx+8]
+  push eax
+  call itoa
+  add esp, 4
+  push eax
+  push 1
+  call platform_log
+  add esp, 8
+  push str_newline
+  push 1
+  call platform_log
+  add esp, 8
+
+dump_multiboot_mmap:
+  ;; Check mmap_* are supported
+  mov eax, [ebx]
+  test eax, 64
+  je dump_multiboot_end
+
+  ;; Save mmap buffer in registers
+  mov esi, [ebx+48]
+  mov ebx, [ebx+44]
+  add ebx, esi
+
+dump_multiboot_mmap_dump:
+  ;; Call mmap_dump
+  push esi
+  call mmap_dump
+  add esp, 4
+
+  ;; Increment pointer
+  add esi, [esi]
+  add esi, 4
+
+  cmp esi, ebx
+  jb dump_multiboot_mmap_dump
+
+dump_multiboot_end:
+  pop esi
+  pop ebx
+  pop ebp
+  ret
+
+
+mmap_dump:
+  push ebp
+  mov ebp, esp
+  push ebx
+
+  mov ebx, [ebp+8]
+
+  ;; Check that ignored fields are not used
+  cmp DWORD [ebx+8], 0
+  jne platform_panic
+  cmp DWORD [ebx+16], 0
+  jne platform_panic
+
+  ;; Print size
+  ;; push str_mmap_size
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+  ;; mov eax, [ebx]
+  ;; push eax
+  ;; call itoa
+  ;; add esp, 4
+  ;; push eax
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+  ;; push str_newline
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+
+  ;; Print base_addr
+  ;; push str_mmap_base_addr
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+  push str_mmap
+  push 1
+  call platform_log
+  add esp, 8
+  mov eax, [ebx+4]
+  push eax
+  call itoa
+  add esp, 4
+  push eax
+  push 1
+  call platform_log
+  add esp, 8
+  ;; push str_newline
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+
+  ;; Print length
+  ;; push str_mmap_length
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+  push str_slash
+  push 1
+  call platform_log
+  add esp, 8
+  mov eax, [ebx+12]
+  push eax
+  call itoa
+  add esp, 4
+  push eax
+  push 1
+  call platform_log
+  add esp, 8
+  ;; push str_newline
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+
+  ;; Print type
+  ;; push str_mmap_type
+  ;; push 1
+  ;; call platform_log
+  ;; add esp, 8
+  push str_slash
+  push 1
+  call platform_log
+  add esp, 8
+  mov eax, [ebx+20]
+  push eax
+  call itoa
+  add esp, 4
+  push eax
+  push 1
+  call platform_log
+  add esp, 8
+  push str_newline
+  push 1
+  call platform_log
+  add esp, 8
+
+  pop ebx
+  pop ebp
+  ret
+
+str_dump_multiboot:
+  db 'Dumping multiboot boot information...'
+  db NEWLINE
+  db 0
+str_mem_lower:
+  db 'mem_lower = '
+  db 0
+str_mem_upper:
+  db 'mem_lower = '
+  db 0
+str_mmap:
+  db 'Memory region: '
+  db 0
+str_slash:
+  db ' / '
+  db 0

+ 1 - 249
lib/kernel.asm

@@ -55,14 +55,6 @@ str_hello_asmc:
   db 'Hello, asmc!'
   db NEWLINE
   db 0
-str_started_multiboot:
-  db 'Called from multiboot'
-  db NEWLINE
-  db 0
-str_started_raw:
-  db 'Called directly'
-  db NEWLINE
-  db 0
 
 str_init_heap_stack:
   db 'Initializing heap and stack... '
@@ -78,23 +70,6 @@ str_done:
   db NEWLINE
   db 0
 
-str_dump_multiboot:
-  db 'Dumping multiboot boot information...'
-  db NEWLINE
-  db 0
-str_mem_lower:
-  db 'mem_lower = '
-  db 0
-str_mem_upper:
-  db 'mem_lower = '
-  db 0
-str_mmap:
-  db 'Memory region: '
-  db 0
-str_slash:
-  db ' / '
-  db 0
-
 str_END:
   db 'END'
   db 0
@@ -103,7 +78,7 @@ temp_stack:
   resb 128
 temp_stack_top:
 
-start_from_raw:
+entry:
   ;; Setup a temporary stack
   mov esp, temp_stack_top
   and esp, 0xfffffff0
@@ -120,40 +95,6 @@ start_from_raw:
   call platform_log
   add esp, 8
 
-  push str_started_raw
-  push 1
-  call platform_log
-  add esp, 8
-
-  jmp start_common
-
-start_from_multiboot:
-  ;; Setup a temporary stack
-  mov esp, temp_stack_top
-  and esp, 0xfffffff0
-
-  ;; Initialize terminal
-  call term_setup
-
-  ;; Log
-  push str_hello_asmc
-  push 1
-  call platform_log
-  add esp, 8
-
-  push str_started_multiboot
-  push 1
-  call platform_log
-  add esp, 8
-
-  ;; Dump data from multiboot information structure
-  push ebx
-  call dump_multiboot
-  add esp, 4
-
-  jmp start_common
-
-start_common:
   ;; Log
   push str_init_heap_stack
   push 1
@@ -239,195 +180,6 @@ start_common:
   call platform_exit
 
 
-dump_multiboot:
-  push ebp
-  mov ebp, esp
-  push ebx
-  push esi
-
-  ;; Save multiboot location
-  mov ebx, [ebp+8]
-
-  ;; Log
-  push str_dump_multiboot
-  push 1
-  call platform_log
-  add esp, 8
-
-  ;; Check mem_lower and mem_upper are supported
-  mov eax, [ebx]
-  test eax, 1
-  je dump_multiboot_mmap
-
-  ;; Print mem_lower
-  push str_mem_lower
-  push 1
-  call platform_log
-  add esp, 8
-  mov eax, [ebx+4]
-  push eax
-  call itoa
-  add esp, 4
-  push eax
-  push 1
-  call platform_log
-  add esp, 8
-  push str_newline
-  push 1
-  call platform_log
-  add esp, 8
-
-  ;; Print mem_upper
-  push str_mem_upper
-  push 1
-  call platform_log
-  add esp, 8
-  mov eax, [ebx+8]
-  push eax
-  call itoa
-  add esp, 4
-  push eax
-  push 1
-  call platform_log
-  add esp, 8
-  push str_newline
-  push 1
-  call platform_log
-  add esp, 8
-
-dump_multiboot_mmap:
-  ;; Check mmap_* are supported
-  mov eax, [ebx]
-  test eax, 64
-  je dump_multiboot_end
-
-  ;; Save mmap buffer in registers
-  mov esi, [ebx+48]
-  mov ebx, [ebx+44]
-  add ebx, esi
-
-dump_multiboot_mmap_dump:
-  ;; Call mmap_dump
-  push esi
-  call mmap_dump
-  add esp, 4
-
-  ;; Increment pointer
-  add esi, [esi]
-  add esi, 4
-
-  cmp esi, ebx
-  jb dump_multiboot_mmap_dump
-
-dump_multiboot_end:
-  pop esi
-  pop ebx
-  pop ebp
-  ret
-
-
-mmap_dump:
-  push ebp
-  mov ebp, esp
-  push ebx
-
-  mov ebx, [ebp+8]
-
-  ;; Check that ignored fields are not used
-  cmp DWORD [ebx+8], 0
-  jne platform_panic
-  cmp DWORD [ebx+16], 0
-  jne platform_panic
-
-  ;; Print size
-  ;; push str_mmap_size
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-  ;; mov eax, [ebx]
-  ;; push eax
-  ;; call itoa
-  ;; add esp, 4
-  ;; push eax
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-  ;; push str_newline
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-
-  ;; Print base_addr
-  ;; push str_mmap_base_addr
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-  push str_mmap
-  push 1
-  call platform_log
-  add esp, 8
-  mov eax, [ebx+4]
-  push eax
-  call itoa
-  add esp, 4
-  push eax
-  push 1
-  call platform_log
-  add esp, 8
-  ;; push str_newline
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-
-  ;; Print length
-  ;; push str_mmap_length
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-  push str_slash
-  push 1
-  call platform_log
-  add esp, 8
-  mov eax, [ebx+12]
-  push eax
-  call itoa
-  add esp, 4
-  push eax
-  push 1
-  call platform_log
-  add esp, 8
-  ;; push str_newline
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-
-  ;; Print type
-  ;; push str_mmap_type
-  ;; push 1
-  ;; call platform_log
-  ;; add esp, 8
-  push str_slash
-  push 1
-  call platform_log
-  add esp, 8
-  mov eax, [ebx+20]
-  push eax
-  call itoa
-  add esp, 4
-  push eax
-  push 1
-  call platform_log
-  add esp, 8
-  push str_newline
-  push 1
-  call platform_log
-  add esp, 8
-
-  pop ebx
-  pop ebp
-  ret
-
-
   SERIAL_PORT equ 0x3f8
 
 	;; void serial_setup()

+ 5 - 10
lib/multiboot.asm → lib/mb_header.asm

@@ -21,26 +21,21 @@
   MBMAGIC equ 0x1badb002
   ;; Set flags for alignment, memory map and load adds
   MBFLAGS equ 0x10003
-  ;; 0x100000000 - MBMAGIC - MBFLAGS
-  MBCHECKSUM equ 0xe4514ffb
+  MBCHECKSUM equ 0x100000000 - MBMAGIC - MBFLAGS
 
-  ;; MB_ENTRY_ADDR equ _start
-
-  jmp start_from_raw
+  jmp entry
 
   align 4
 
-  jmp start_from_multiboot
-
-  align 4
+  MBBEGIN equ $
 
   ;; Multiboot header
   dd MBMAGIC
   dd MBFLAGS
   dd MBCHECKSUM
 
-  dd 0x100010
+  dd MBBEGIN
   dd 0x100000
   dd 0x0
   dd 0x0
-  dd 0x100008
+  dd 0x100000