From 0bb09d2e14cdf1c1571a8e80ae30460699d00e82 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 20 Aug 2019 00:20:38 -0700 Subject: 5522 - example app: random number stream Turns out Mu's kernel isn't populating /dev/random correctly. --- html/apps/random.subx.html | 124 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 html/apps/random.subx.html (limited to 'html/apps') diff --git a/html/apps/random.subx.html b/html/apps/random.subx.html new file mode 100644 index 00000000..838fa753 --- /dev/null +++ b/html/apps/random.subx.html @@ -0,0 +1,124 @@ + + + + +Mu - apps/random.subx + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/apps/random.subx +
+ 1 # Repeatedly read 32-bit numbers from /dev/random, print them to stdout.
+ 2 #
+ 3 # To run:
+ 4 #   $ ./subx translate 0*.subx apps/random.subx -o apps/random
+ 5 #   $ ./subx run apps/random
+ 6 
+ 7 == code 0x09000000
+ 8 #   instruction                     effective address                                                   register    displacement    immediate
+ 9 # . op          subop               mod             rm32          base        index         scale       r32
+10 # . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
+11 
+12 Entry:
+13     # stream/ESI = syscall(open, "/dev/null", O_RDONLY, 0)  # we can't use 'fd' because it looks like a hex byte
+14     bb/copy-to-EBX  Filename/imm32
+15     b9/copy-to-ECX  0/imm32/rdonly
+16     ba/copy-to-EDX  0x180/imm32/fixed-perms
+17     b8/copy-to-EAX  5/imm32/open
+18     cd/syscall  0x80/imm8
+19     # . stream = EAX
+20     89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           0/r32/EAX   .               .                 # copy EAX to ESI
+21 
+22 $loop:
+23 
+24     # syscall(read, Stream, N, 4)
+25     89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           6/r32/ESI   .               .                 # copy ESI to EBX
+26     b9/copy-to-ECX  N/imm32
+27     ba/copy-to-EDX  4/imm32/size
+28     b8/copy-to-EAX  3/imm32/read
+29     cd/syscall  0x80/imm8
+30 
+31     # print-int32-buffered(Stdout, *N)
+32     # . . push args
+33     ff          6/subop/push        0/mod/indirect  5/rm32/.disp32            .             .           .           N/disp32                          # push *N
+34     68/push  Stdout/imm32
+35     # . . call
+36     e8/call  print-int32-buffered/disp32
+37 
+38     # write-buffered(Stdout, Newline)
+39     # . . push args
+40     68/push  Newline/imm32
+41     68/push  Stdout/imm32
+42     # . . call
+43     e8/call  write-buffered/disp32
+44     # . . discard args
+45     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+46 
+47     eb/jump  $loop/disp8
+48 
+49     # syscall(exit, 0)
+50     bb/copy-to-EBX  0/imm32
+51     b8/copy-to-EAX  1/imm32/exit
+52     cd/syscall  0x80/imm8
+53 
+54 == data 0x0a000000
+55 
+56 N:
+57     0/imm32
+58 Filename:
+59     2f 64 65 76 2f 72 61 6e 64 6f 6d 00
+60 #   /  d  e  v  /  r  a  n  d  o  m  null
+61 
+62 # . . vim:nowrap:textwidth=0
+
+ + + -- cgit 1.4.1-2-gfad0