Browse Source

Reintroduce init filesystem, and use it for MM0.

Giovanni Mascellani 5 years ago
parent
commit
f5f9504860
6 changed files with 187 additions and 23 deletions
  1. 1 1
      Makefile
  2. 36 18
      asmg/main.g
  3. 1 0
      asmg/mm0.g
  4. 116 1
      asmg/vfs.g
  5. 5 3
      lib/io.asm
  6. 28 0
      lib/kernel.asm

+ 1 - 1
Makefile

@@ -51,7 +51,7 @@ build/full-asmg.asm: lib/mb_header.asm lib/kernel.asm lib/io.asm lib/shutdown.as
 	cat $^ | sed -e 's|section .bss|section .data|' > $@
 	#cat $^ > $@
 
-build/initrd-asmg.list: asmg/*.g
+build/initrd-asmg.list: asmg/*.g diskfs/mm0/set.mm0
 	ls $^ | sed -e 's|\(.*\)/\([^/]*\)|\2 \1/\2|g' > $@
 
 build/initrd-asmg.diskfs: build/initrd-asmg.list

+ 36 - 18
asmg/main.g

@@ -46,10 +46,12 @@ fun main 0 {
   $compile_asm
   $compile_int64
   $compile_c
+  $compile_disk
   @compile_mm0 0 = ;
   @compile_asm 0 = ;
   @compile_int64 0 = ;
   @compile_c 0 = ;
+  @compile_disk 0 = ;
   if RUN_MM0 {
     @compile_mm0 1 = ;
   }
@@ -64,9 +66,14 @@ fun main 0 {
   }
   if compile_c {
     @compile_int64 1 = ;
+    @compile_disk 1 = ;
   }
   if compile_int64 {
     @compile_asm 1 = ;
+    @compile_disk 1 = ;
+  }
+  if compile_asm {
+    @compile_disk 1 = ;
   }
 
   "Compiling utils.g... " log ;
@@ -137,26 +144,28 @@ fun main 0 {
   "utils2.g" platform_g_compile ;
   "done!\n" log ;
 
-  "Compiling atapio.g... " log ;
-  "atapio.g" platform_g_compile ;
-  "done!\n" log ;
+  if compile_disk {
+     "Compiling atapio.g... " log ;
+    "atapio.g" platform_g_compile ;
+    "done!\n" log ;
 
-  "Compiling diskfs.g... " log ;
-  "diskfs.g" platform_g_compile ;
-  "done!\n" log ;
+    "Compiling diskfs.g... " log ;
+    "diskfs.g" platform_g_compile ;
+    "done!\n" log ;
 
-  "Compiling debugfs.g... " log ;
-  "debugfs.g" platform_g_compile ;
-  "done!\n" log ;
+    "Compiling debugfs.g... " log ;
+    "debugfs.g" platform_g_compile ;
+    "done!\n" log ;
+
+    "Compiling mbr.g... " log ;
+    "mbr.g" platform_g_compile ;
+    "done!\n" log ;
+  }
 
   "Compiling ramfs.g... " log ;
   "ramfs.g" platform_g_compile ;
   "done!\n" log ;
 
-  "Compiling mbr.g... " log ;
-  "mbr.g" platform_g_compile ;
-  "done!\n" log ;
-
   "Compiling vfs.g... " log ;
   "vfs.g" platform_g_compile ;
   "done!\n" log ;
@@ -252,7 +261,7 @@ fun main 0 {
   }
 
   "Initializing Virtual File System...\n" log ;
-  0 "vfs_init" platform_get_symbol \0 ;
+  compile_disk 0 "vfs_init" platform_get_symbol \1 ;
   "Virtual File System initialized!\n" log ;
 
   if compile_int64 {
@@ -266,7 +275,7 @@ fun main 0 {
   "done!\n" log ;
 
   if RUN_MM0 {
-    "/disk1/mm0/set.mm0" 0 "mm0_process" platform_get_symbol \1 ;
+    "/init/set.mm0" 0 "mm0_process" platform_get_symbol \1 ;
   }
 
   if RUN_ASM {
@@ -331,9 +340,18 @@ fun main 0 {
   0 "vfs_destroy" platform_get_symbol \0 ;
   "done!\n" log ;
 
-  "Destroying debugfs... " log ;
-  0 "debugfs_deinit" platform_get_symbol \0 ;
-  "done!\n" log ;
+  if compile_disk {
+    "Destroying debugfs... " log ;
+    0 "debugfs_deinit" platform_get_symbol \0 ;
+    "done!\n" log ;
+  }
+
+  "Top of initrd: " log ;
+  $begin
+  $end
+  @begin @end "" platform_walk_initrd ;
+  end itoa log ;
+  "\n" log ;
 
   "Memory break before exiting main: " log ;
   0 platform_allocate itoa log ;

+ 1 - 0
asmg/mm0.g

@@ -747,6 +747,7 @@ fun mm0_process 1 {
 
   $lexer
   @lexer filename mm0lexer_init = ;
+  lexer "mm0_process: cannot open file" assert_msg ;
 
   $theory
   "Parsing MM0 theory: " log ;

+ 116 - 1
asmg/vfs.g

@@ -28,6 +28,113 @@ const FD_SEEK 16
 const MOUNT_DESTROY 0
 const MOUNT_OPEN 4
 
+const INITFD_DESTROY 0
+const INITFD_READ 4
+const INITFD_WRITE 8
+const INITFD_TRUNCATE 12
+const INITFD_SEEK 16
+const INITFD_START 20
+const INITFD_CUR 24
+const INITFD_END 28
+const SIZEOF_INITFD 32
+
+fun initfd_destroy 1 {
+  $fd
+  @fd 0 param = ;
+
+  fd free ;
+}
+
+fun initfd_read 1 {
+  $fd
+  @fd 0 param = ;
+
+  if fd INITFD_CUR take fd INITFD_END take == {
+    0xffffffff ret ;
+  } else {
+    $c
+    @c fd INITFD_CUR take **c = ;
+    fd INITFD_CUR take_addr fd INITFD_CUR take 1 + = ;
+    c ret ;
+  }
+}
+
+fun initfd_write 2 {
+  0 "initfd_write: not supported" assert_msg ;
+}
+
+fun initfd_truncate 1 {
+  0 "initfd_truncate: not supported" assert_msg ;
+}
+
+fun initfd_seek 3 {
+  $fd
+  $off
+  $whence
+  @fd 2 param = ;
+  @off 1 param = ;
+  @whence 0 param = ;
+
+  if whence SEEK_SET == off 0 == && {
+    fd INITFD_CUR take_addr fd INITFD_START take = ;
+    0 ret ;
+  }
+
+  0 "initfd_seek: unsupported seek" assert_msg ;
+}
+
+fun initfd_init 1 {
+  $name
+  @name 0 param = ;
+
+  $begin
+  $end
+  @begin @end name platform_walk_initrd ;
+  if begin 0 == {
+    0 ret ;
+  }
+
+  $fd
+  @fd SIZEOF_INITFD malloc = ;
+  fd INITFD_DESTROY take_addr @initfd_destroy = ;
+  fd INITFD_READ take_addr @initfd_read = ;
+  fd INITFD_WRITE take_addr @initfd_write = ;
+  fd INITFD_TRUNCATE take_addr @initfd_truncate = ;
+  fd INITFD_SEEK take_addr @initfd_seek = ;
+  fd INITFD_START take_addr begin = ;
+  fd INITFD_CUR take_addr begin = ;
+  fd INITFD_END take_addr end = ;
+  fd ret ;
+}
+
+const INITMOUNT_DESTROY 0
+const INITMOUNT_OPEN 4
+const SIZEOF_INITMOUNT 8
+
+fun initmount_destroy 1 {
+  $mount
+  @mount 0 param = ;
+
+  mount free ;
+}
+
+fun initmount_open 2 {
+  $mount
+  $name
+  @mount 1 param = ;
+  @name 0 param = ;
+
+  name initfd_init ret ;
+}
+
+fun initmount_init 0 {
+  $mount
+  @mount SIZEOF_INITMOUNT malloc = ;
+  mount INITMOUNT_DESTROY take_addr @initmount_destroy = ;
+  mount INITMOUNT_OPEN take_addr @initmount_open = ;
+  mount ret ;
+}
+
 const VFSINST_MOUNTS 0
 const SIZEOF_VFSINST 4
 
@@ -124,9 +231,17 @@ fun vfsinst_open 2 {
 $vfs
 
 fun vfs_init 0 {
+  $compile_disk
+  @compile_disk 0 param = ;
+
   @vfs vfsinst_init = ;
   vfs "ram" rammount_init vfsinst_mount ;
-  vfs mbr_vfs_scan ;
+  vfs "init" initmount_init vfsinst_mount ;
+  if compile_disk {
+    # Symbol has to be retrieved indirectly, because it is not
+    # available if compile_disk is false
+    vfs 0 "mbr_vfs_scan" platform_get_symbol \1 ;
+  }
 }
 
 fun vfs_destroy 0 {

+ 5 - 3
lib/io.asm

@@ -264,10 +264,12 @@ write_hex:
 
 single_stepping_handler:
   mov ebx, [instr_num]
-  sub ebx, 0x15000
+  sub ebx, 0x036c7600
+  test ebx, 0x0
+  jnz single_stepping_handler_end
   cmp ebx, 0
   jl single_stepping_handler_end
-  cmp ebx, 0x2000
+  cmp ebx, 0x100000
   jge shutdown
 
   mov ebx, [esp+4]
@@ -320,7 +322,7 @@ single_stepping_handler_end:
 
 
 enable_single_stepping:
-  mov DWORD [instr_num], 0x3126
+  mov DWORD [instr_num], 0x3180
   mov DWORD [0x10010], single_stepping_handler
   call [0x1001c]
   ret

+ 28 - 0
lib/kernel.asm

@@ -65,6 +65,9 @@ str_platform_allocate:
 str_platform_get_symbol:
   db 'platform_get_symbol'
   db 0
+str_platform_walk_initrd:
+  db 'platform_walk_initrd'
+  db 0
 
   section .text
 
@@ -185,6 +188,26 @@ allocate:
   ret
 
 
+platform_walk_initrd:
+  ;; Decode argument
+  mov ecx, [esp+4]
+
+  ;; Call walk_initrd protecting registers
+  push esi
+  push edi
+  call walk_initrd
+  pop edi
+  pop esi
+
+  ;; Save result in the pointers indicated in the stack
+  mov ecx, [esp+8]
+  mov [ecx], edx
+  mov ecx, [esp+12]
+  mov [ecx], eax
+
+  ret
+
+
   ;; Initialize the symbols table with the "kernel API"
 init_kernel_api:
   mov edx, 0
@@ -202,6 +225,11 @@ init_kernel_api:
   mov eax, str_platform_get_symbol
   call add_symbol
 
+  mov edx, 3
+  mov ecx, platform_walk_initrd
+  mov eax, str_platform_walk_initrd
+  call add_symbol
+
   ret