123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- # 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 SEEK_SET 0
- const SEEK_CUR 1
- const SEEK_END 2
- const FD_DESTROY 0
- const FD_READ 4
- const FD_WRITE 8
- const FD_TRUNCATE 12
- 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
- fun vfsinst_init 0 {
- $vfsinst
- @vfsinst SIZEOF_VFSINST malloc = ;
- vfsinst VFSINST_MOUNTS take_addr map_init = ;
- vfsinst ret ;
- }
- fun mount_destroy_closure 3 {
- $ctx
- $key
- $value
- @ctx 2 param = ;
- @key 1 param = ;
- @value 0 param = ;
- value value MOUNT_DESTROY take \1 ;
- }
- fun vfsinst_destroy 1 {
- $vfsinst
- @vfsinst 0 param = ;
- $mounts
- @mounts vfsinst VFSINST_MOUNTS take = ;
- mounts @mount_destroy_closure 0 map_foreach ;
- mounts map_destroy ;
- vfsinst free ;
- }
- fun vfsinst_mount 3 {
- $vfsinst
- $point
- $mount
- @vfsinst 2 param = ;
- @point 1 param = ;
- @mount 0 param = ;
- "Mounting file system /" log ;
- point log ;
- "\n" log ;
- $mounts
- @mounts vfsinst VFSINST_MOUNTS take = ;
- mounts point mount map_set ;
- }
- fun find_slash 1 {
- $s
- @s 0 param = ;
- $t
- @t s = ;
- while 1 {
- $c
- @c t **c = ;
- if c 0 == c '/' == || {
- t s - ret ;
- }
- @t t 1 + = ;
- }
- }
- fun vfsinst_open 2 {
- $vfsinst
- $name
- @vfsinst 1 param = ;
- @name 0 param = ;
- name **c '/' == "vfsinst_open: missing initial slash" assert_msg ;
- @name name 1 + = ;
- $mountname
- @mountname name strdup = ;
- $slash_pos
- @slash_pos mountname find_slash = ;
- mountname slash_pos + **c '/' == "vfsinst_open: missing mountpoint slash" assert_msg ;
- mountname slash_pos + 0 =c ;
- $mountpath
- @mountpath mountname slash_pos + 1 + = ;
- $mount
- mount vfsinst VFSINST_MOUNTS take mountname map_has "vfsinst_open: mount point does not exist" assert_msg ;
- @mount vfsinst VFSINST_MOUNTS take mountname map_at = ;
- $res
- @res mount mountpath mount MOUNT_OPEN take \2 = ;
- mountname free ;
- res ret ;
- }
- $vfs
- fun vfs_init 0 {
- $compile_disk
- @compile_disk 0 param = ;
- @vfs vfsinst_init = ;
- vfs "ram" rammount_init vfsinst_mount ;
- 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 {
- vfs vfsinst_destroy ;
- }
- fun vfs_open 1 {
- $name
- @name 0 param = ;
- vfs name vfsinst_open ret ;
- }
- fun vfs_close 1 {
- $fd
- @fd 0 param = ;
- fd fd FD_DESTROY take \1 ;
- }
- fun vfs_read 1 {
- $fd
- @fd 0 param = ;
- fd fd FD_READ take \1 ret ;
- }
- fun vfs_write 2 {
- $fd
- $c
- @fd 1 param = ;
- @c 0 param = ;
- fd c fd FD_WRITE take \1 ;
- }
- fun vfs_truncate 1 {
- $fd
- @fd 0 param = ;
- fd fd FD_TRUNCATE take \1 ;
- }
- fun vfs_seek 3 {
- $fd
- $off
- $whence
- @fd 2 param = ;
- @off 1 param = ;
- @whence 0 param = ;
- fd off whence fd FD_SEEK take \3 ret ;
- }
- fun vfs_reset 1 {
- $fd
- @fd 0 param = ;
- fd 0 SEEK_SET vfs_seek ;
- }
|