mes/elf.mes

48 lines
1.6 KiB
Plaintext
Raw Normal View History

;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; scm.mes: This file is part of Mes.
;;;
;;; Mes 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.
;;;
;;; Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
(define (i386:puts data length)
2016-08-13 21:43:55 +01:00
`(
#xba ,@(int->bv32 length) ;; mov $0xe,%edx
2016-08-13 21:43:55 +01:00
#xb9 ,@(int->bv32 data) ;; mov $data,%ecx
#xbb #x01 #x00 #x00 #x00 ;; mov $0x1,%ebx
#xb8 #x04 #x00 #x00 #x00 ;; mov $0x4,%eax
#xcd #x80 ;; int $0x80
))
2016-08-12 15:38:59 +01:00
2016-08-13 21:43:55 +01:00
(define (i386:exit code)
`(
#xbb ,@(int->bv32 code) ;; mov $code,%ebx
#xb8 #x01 #x00 #x00 #x00 ;; mov $0x1,%eax
#xcd #x80 ;; int $0x80
))
(define data
(string->list "Hello, world!\n"))
(define (text d)
(append
(i386:puts d (length data))
2016-08-13 21:43:55 +01:00
(i386:exit 0)
))
2016-08-13 21:43:55 +01:00
2016-08-13 21:21:59 +01:00
(define (write-any x) (write-char (if (char? x) x (integer->char x))))
2016-08-13 21:43:55 +01:00
(map write-any (make-elf text data))