semihosting.zig
1 const std = @import("std"); 2 const microzig = @import("microzig"); 3 const semihosting = microzig.core.arm_semihosting; 4 5 pub fn main() void { 6 const path = ""; 7 const file_name = path ++ "foo.txt"; 8 const new_name = path ++ "bar.txt"; 9 var some_buf: [80]u8 = undefined; 10 11 // Debug features 12 semihosting.Debug.print("Hello World\n", .{}); 13 14 const args = semihosting.Debug.get_cmd_args(&some_buf) catch return; 15 semihosting.Debug.print("receive args: {s}\n", .{args}); 16 17 semihosting.Debug.print("feature support: STDOUT FILE: {any}, EXIT CODE {any}\n", .{ 18 semihosting.Debug.check_extensions(0, 1), 19 semihosting.Debug.check_extensions(0, 0), 20 }); 21 22 const stdout = semihosting.Debug.stdout() catch return; 23 stdout.print("hello STDOUT!!!!\n", .{}); 24 25 // Time features 26 const clock = semihosting.Time.absolute(); 27 const host_time = semihosting.Time.system_time(); 28 29 // fs features 30 const file = semihosting.fs.open(file_name, .@"W+") catch { 31 semihosting.Debug.print("fail to open {s}!", .{file_name}); 32 return; 33 }; 34 35 file.print("[{any}:{d}] | Hello File {s} id {d}", .{ 36 clock, 37 host_time, 38 file_name, 39 @intFromEnum(file), 40 }); 41 42 const f_size = file.size() catch return; 43 44 semihosting.Debug.print("now file has size {d}\n", .{f_size}); 45 file.close() catch { 46 semihosting.Debug.print("fail to close {s}!", .{file_name}); 47 return; 48 }; 49 50 semihosting.fs.rename(file_name, new_name) catch { 51 semihosting.Debug.print("fail to rename {s} to {s}", .{ file_name, new_name }); 52 }; 53 54 semihosting.Debug.exit(0); 55 56 while (true) {} 57 }