Browse Source

Implement a basic debugfs.

Giovanni Mascellani 5 years ago
parent
commit
6969709bdd
7 changed files with 184 additions and 2 deletions
  1. 5 1
      Makefile
  2. 11 0
      asmg/atapio.g
  3. 148 0
      asmg/debugfs.g
  4. 4 0
      asmg/main.g
  5. 7 0
      asmg/mbr.g
  6. 1 1
      asmg/tinycc.g
  7. 8 0
      diskfs/stdlib/stdint.h

+ 5 - 1
Makefile

@@ -146,7 +146,11 @@ endif
 build/asmg.x86: build/asmg.x86.exe build/initrd-asmg.ar
 	cat $^ > $@
 
-build/boot_asmg.x86: build/bootloader.x86.mbr build/bootloader.x86.stage2 build/asmg.x86 build/diskfs.img
+build/debugfs.img:
+	echo 'DEBUGFS ' > $@
+	dd if=/dev/zero of=$@ bs=1M count=10 oflag=append conv=notrunc
+
+build/boot_asmg.x86: build/bootloader.x86.mbr build/bootloader.x86.stage2 build/asmg.x86 build/diskfs.img build/debugfs.img
 	./create_partition.py $^ > $@
 
 # Asmg0 kernel

+ 11 - 0
asmg/atapio.g

@@ -158,6 +158,17 @@ fun atapio_identify 1 {
   }
 }
 
+fun atapio_write_sect 3 {
+  $a
+  $lba
+  $buf
+  @a 2 param = ;
+  @lba 1 param = ;
+  @buf 0 param = ;
+
+  0 "atapio_write_sect: not implemented" assert_msg ;
+}
+
 fun atapio_read_sect 2 {
   $a
   $lba

+ 148 - 0
asmg/debugfs.g

@@ -0,0 +1,148 @@
+# This file is part of asmc, a bootstrapping OS with minimal seed
+# Copyright (C) 2018 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/>.
+
+const DEBUGFS_ATAPIO 0
+const DEBUGFS_START 4
+const DEBUGFS_END 8
+const DEBUGFS_POS 12
+const DEBUGFS_BUF 16
+const DEBUGFS_BUF_POS 20
+const SIZEOF_DEBUGFS 24
+
+fun debugfsinst_init 3 {
+  $atapio
+  $start
+  $size
+  @atapio 2 param = ;
+  @start 1 param = ;
+  @size 0 param = ;
+
+  $debugfs
+  @debugfs SIZEOF_DEBUGFS malloc = ;
+  debugfs DEBUGFS_ATAPIO take_addr atapio = ;
+  debugfs DEBUGFS_START take_addr start = ;
+  debugfs DEBUGFS_END take_addr start size + = ;
+  debugfs DEBUGFS_POS take_addr start 1 + = ;
+  debugfs DEBUGFS_BUF take_addr 0 = ;
+  debugfs ret ;
+}
+
+fun debugfsinst_destroy 1 {
+  $debugfs
+  @debugfs 0 param = ;
+
+  debugfs DEBUGFS_ATAPIO take atapio_destroy ;
+  debugfs DEBUGFS_BUF take free ;
+  debugfs free ;
+}
+
+fun debugfsinst_begin_file 2 {
+  $debugfs
+  $filename
+  @debugfs 1 param = ;
+  @filename 0 param = ;
+
+  debugfs DEBUGFS_BUF take 0 == "debugfsinst_begin_file: already in file" assert_msg ;
+  debugfs DEBUGFS_BUF take_addr 512 1 calloc = ;
+  debugfs DEBUGFS_BUF_POS take_addr 0 = ;
+
+  filename strlen 511 < "debugfsinst_begin_file: filename too long" assert_msg ;
+  $sector
+  @sector 512 1 calloc = ;
+  filename sector strcpy ;
+  debugfs DEBUGFS_POS take debugfs DEBUGFS_END take != "debugfsinst_begin_file: partition limit exceeded" assert_msg ;
+  debugfs DEBUGFS_ATAPIO take debugfs DEBUGFS_POS take sector atapio_write_sect ;
+  sector free ;
+  debugfs DEBUGFS_POS take_addr debugfs DEBUGFS_POS take 1 + = ;
+}
+
+fun _debugfsinst_flush_buffer 1 {
+  $debugfs
+  @debugfs 0 param = ;
+
+  debugfs DEBUGFS_BUF take 0 != "_debugfsinst_flush_buffer: not in file" assert_msg ;
+  debugfs DEBUGFS_POS take debugfs DEBUGFS_END take != "_debugfsinst_flush_buffer: partition limit exceeded" assert_msg ;
+  debugfs DEBUGFS_ATAPIO take debugfs DEBUGFS_POS take debugfs DEBUGFS_BUF take atapio_write_sect ;
+  debugfs DEBUGFS_BUF take free ;
+  debugfs DEBUGFS_BUF take_addr 512 1 calloc = ;
+  debugfs DEBUGFS_BUF_POS take_addr 0 = ;
+}
+
+fun debugfsinst_write_char 2 {
+  $debugfs
+  $c
+  @debugfs 1 param = ;
+  @c 0 param = ;
+
+  debugfs DEBUGFS_BUF take debugfs DEBUGFS_BUF_POS take + c =c ;
+  debugfs DEBUGFS_BUF_POS take_addr debugfs DEBUGFS_BUF_POS take 1 + = ;
+  if debugfs DEBUGFS_BUF_POS take 512 == {
+    debugfs _debugfsinst_flush_buffer ;
+  }
+}
+
+fun debugfsinst_finish_file 1 {
+  $debugfs
+  @debugfs 0 param = ;
+
+  debugfs DEBUGFS_BUF take 0 != "debugfsinst_finish_file: not in file" assert_msg ;
+  if debugfs DEBUGFS_BUF_POS take 0 != {
+    debugfs _debugfsinst_flush_buffer ;
+  }
+
+  debugfs DEBUGFS_BUF take_addr 0 = ;
+}
+
+$global_debugfs
+
+fun debugfs_set 1 {
+  $debugfs
+  @debugfs 0 param = ;
+
+  if global_debugfs {
+    global_debugfs debugfsinst_destroy ;
+  }
+  @global_debugfs debugfs = ;
+}
+
+fun debugfs_deinit 0 {
+  0 debugfs_set ;
+}
+
+fun debugfs_begin_file 1 {
+  $filename
+  @filename 0 param = ;
+
+  if global_debugfs {
+    global_debugfs filename debugfsinst_begin_file ;
+  }
+}
+
+fun debugfs_write_char 1 {
+  $c
+  @c 0 param = ;
+
+  if global_debugfs {
+    global_debugfs c debugfsinst_write_char ;
+  }
+}
+
+fun debugfs_finish_file 0 {
+  if global_debugfs {
+    global_debugfs debugfsinst_finish_file ;
+  }
+}

+ 4 - 0
asmg/main.g

@@ -104,6 +104,10 @@ fun main 0 {
   "diskfs.g" platform_g_compile ;
   "done!\n" 1 platform_log ;
 
+  "Compiling debugfs.g... " 1 platform_log ;
+  "debugfs.g" platform_g_compile ;
+  "done!\n" 1 platform_log ;
+
   "Compiling ramfs.g... " 1 platform_log ;
   "ramfs.g" platform_g_compile ;
   "done!\n" 1 platform_log ;

+ 7 - 0
asmg/mbr.g

@@ -90,6 +90,13 @@ fun mbr_vfs_scan_drive 3 {
           vfs point  mount 0 "vfsinst_mount" platform_get_symbol \3 ;
           point free ;
           @count count 1 + = ;
+        } else {
+          if sect ** "DEBU" ** == sect 4 + ** "GFS " ** == && {
+            "    Found a debugfs file system!\n" 1 platform_log ;
+            $debugfs
+            @debugfs a atapio_duplicate parts i vector_at parts i vector_at_addr 4 + ** debugfsinst_init = ;
+            debugfs debugfs_set ;
+          }
         }
         sect free ;
 

+ 1 - 1
asmg/tinycc.g

@@ -22,7 +22,7 @@ fun compile_tinycc 0 {
   # Preprocessing
   $ctx
   @ctx ppctx_init = ;
-  ctx "ONE_SOURCE" "1" ppctx_define ;
+  ctx "ONE_SOURCE" "0" ppctx_define ;
   ctx "USE_SOFTFLOAT" "1" ppctx_define ;
   ctx filename ppctx_set_base_filename ;
   ctx "/disk1/tinycc/softfloat/" ppctx_add_include_path ;

+ 8 - 0
diskfs/stdlib/stdint.h

@@ -1,4 +1,12 @@
 #ifndef __STDINT_H
 #define __STDINT_H
 
+typedef signed char int_8;
+typedef signed short int16_t;
+typedef signed int int32_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
 #endif