print correctly BCD CMOS RTC values
Re: print correctly BCD CMOS RTC values
thanks for the tips!for the nasm tip (-g -F dwarf), it says: 'unrecognized debug format 'dwarf' for output format 'bin'' even if its elf32, and for the qemu options i cant even boot, and i don't understand at all what it's happening, but anyway i still having those 'S' or '=S' (the '=' was the character with one more line) and it doesn't print any rtc value as it should be
Thanks!
Thanks!
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: print correctly BCD CMOS RTC values
Put the -g -F dwarf after the -f elf
As for those QEMU commands did you try putting them as is into a shell file? Did you make any mods to the commands I gave?
My recommendation for using GDB and debugging is so that you can find out yourself why things are failing rather than rely on others to do it. Getting debugging going allows you to step through the code, display variables,set breakpoints, etc.
As for those QEMU commands did you try putting them as is into a shell file? Did you make any mods to the commands I gave?
My recommendation for using GDB and debugging is so that you can find out yourself why things are failing rather than rely on others to do it. Getting debugging going allows you to step through the code, display variables,set breakpoints, etc.
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: print correctly BCD CMOS RTC values
Getting back to the problems at hand: let's start with the function get_rtc(), which maybe should be named print_rtc(), but whatever.
Now, for reference, let me post the definitions for the string type:
(... I will leave it to others to pontificate on just how advisable this typedef might or might not be...)
and the print() function:
See the problem, yet? If not, here's a simpler example which should make it clear:
It should become especially obvious if you try running GCC with the -Wall option, and I will bet you get a whole bunch of warnings like these:
In other words, at least part of the problem is that you are passing a one-byte unsigned integer to a function which is expecting a char pointer (32 or 64 bit, depending, though the size mismatch is the least of the problems).
As thomtl already said, the solution is to convert the integer value into a string one, though the function thomtl mentioned, itoa() is a) non-standard b) deprecated, and c) wouldn't be part of your own library anyway, as you haven't written it yet.
You will definitely need to write something similar eventually, though.
However... in this case, it may be easier to skip the integer conversion, and simply convert the BCD values - after all, this was always one of the putative advantages of using BCD (there were others, but most of them no longer really apply to modern systems, and the ones which do, are often poorly supported). So, if we assume (uh oh, assuming things...) that you are using ASCII or an ASCII-compatible encoding such as UTF-8 or Latin-1, you could add something like this to the bcd.h and bcd.c files:
bcd.h
bcd.c
Note that it places the two characters somewhere in the string; it is up to the programmer using it to make sure the string is big enough, delimited, etc. Caveat programmer.
Then for the function returning the RTC time, you would use something like this:
You would use it something like this (not tested, I can't promise it will work right):
Which should fill in those "00"s with the hour, minute, and second values into the string time.
While this peculiar setup? Because you might want to have different time string formats, and this will make that a little easier in some ways (and trickier in others). C programming is like that sometimes.
Note that you will need to implement your own strlen(), or at least borrow one from (for example) PDCLib, for this to work. OS programming is like that.
Code: Select all
/* Entry Function */
int get_rtc(void)
{
while(isupdateinprogress());
uint8 hour = bcd_to_int(get_RTC_val(HOUR));
print(hour);
}
Code: Select all
typedef char* string;
and the print() function:
Code: Select all
void print (string ch)
{
uint16 i = 0;
uint8 length = strlength(ch)-1; //Updated (Now we store string length on a variable to call the function only once)
for(i;i<length;i++)
{
printch(ch[i]);
}
}
Code: Select all
#include <stdio.h>
int foo(void)
{
return 23;
}
void bar(char *baz)
{
printf("%s", baz);
}
void foo_bar()
{
bar(foo());
}
Code: Select all
> gcc -Wall -c implconv.c
implconv.c: In function ‘foo_bar’:
implconv.c:15:9: warning: passing argument 1 of ‘bar’ makes pointer from integer without a cast [-Wint-conversion]
bar(foo());
^~~~~
implconv.c:8:16: note: expected ‘char *’ but argument is of type ‘int’
void bar(char *baz)
~~~~~~^~~
As thomtl already said, the solution is to convert the integer value into a string one, though the function thomtl mentioned, itoa() is a) non-standard b) deprecated, and c) wouldn't be part of your own library anyway, as you haven't written it yet.
You will definitely need to write something similar eventually, though.
However... in this case, it may be easier to skip the integer conversion, and simply convert the BCD values - after all, this was always one of the putative advantages of using BCD (there were others, but most of them no longer really apply to modern systems, and the ones which do, are often poorly supported). So, if we assume (uh oh, assuming things...) that you are using ASCII or an ASCII-compatible encoding such as UTF-8 or Latin-1, you could add something like this to the bcd.h and bcd.c files:
bcd.h
Code: Select all
#define BCD_ASCII_OFFSETS 0x30
Code: Select all
string bcd_into_str(bcd_t bcd, string buf, unsigned long offset)
{
unsigned long len;
char* ptr;
len = strlen(buf);
if (len < 2 || len < offset)
{
return NULL;
}
else
{
ptr = buf + offset;
// hex 30 == ASCII '0'
*ptr = (char) (bcd >> 4) + 0x30;
*(++ptr) = (char) (bcd & 0x0F) + 0x30;
}
return buf;
}
Then for the function returning the RTC time, you would use something like this:
Code: Select all
/* get_rtc_time() - get the time from the real-time clock.
Value is given as a packed string; */
void get_rtc_time(string buf, uint32_t h_offset, uint32_t m_offset, uint32_t s_offset)
{
while(isupdateinprogress());
bcd_to_str(get_RTC_val(HOUR), buf, h_offset);
bcd_to_str(get_RTC_val(MINUTE), buf, m_offset);
bcd_to_str(get_RTC_val(SECOND), buf, s_offset);
}
Code: Select all
char time[9];
strncpy("00:00:00", time, 9);
get_rtc_time(time, 0, 3, 6);
While this peculiar setup? Because you might want to have different time string formats, and this will make that a little easier in some ways (and trickier in others). C programming is like that sometimes.
Note that you will need to implement your own strlen(), or at least borrow one from (for example) PDCLib, for this to work. OS programming is like that.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: print correctly BCD CMOS RTC values
it still not working. now i got the same '=S' but with a space before it. i've changed from:
to:
but as i said, still not working. it happens the same with the methods posted before(in page 1 and 2)
Thanks!
Code: Select all
void print(string ch)
{
uint16 i = 0;
uint8 length = strlength(ch) - 1;
for(i;i<length;i++)
{
printch(ch[i]);
}
}
Code: Select all
void print(uint8 *ch)
{
uint8 length = strlength(ch) - 1;
for(uint16 i = 0;i<length;i++)
{
printch(ch[i]);
}
}
Thanks!
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: print correctly BCD CMOS RTC values
.Can you update your github to the most recent code you believe isn't working.alberinfo wrote:but as i said, still not working. it happens the same with the methods posted before(in page 1 and 2)
Re: print correctly BCD CMOS RTC values
i've updated it
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: print correctly BCD CMOS RTC values
I am somewhat speechless. You're now treating uint8_t value as a uint8_t pointer. And then expecting that this single byte containing an integer value will behave like a 32-bit pointer to a zero-delimited array of ... uint8_t?alberinfo wrote:it still not working. now i got the same '=S' but with a space before it. i've changed [...] to:Code: Select all
void print(uint8 *ch) { uint8 length = strlength(ch) - 1; for(uint16 i = 0;i<length;i++) { printch(ch[i]); } }
I think you need to step away from this for a moment, and collect your thoughts, as you seem to be thrashing. It happens to the best of us, but it does mean that you need to step off for a bit and think more carefully about it.
You might need to review the topics of pointers, arrays, arrays to pointers, and arrays to zero-delimited arrays of characters. Even if you do understand them already, you are acting as if you don't understand them, which is why I think you are thrashing about.
I don't want to assume that this is what is happening, but I thought I would say this to give you a chance to look at the possibility.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: print correctly BCD CMOS RTC values
i fixed it. the problem wasn't the print function, i had to convert it to a str with the code provided by @School-R-LEA but changing the 'string buf' to 'uint8 buf'
thanks!
thanks!
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: print correctly BCD CMOS RTC values
I think you may find that this solution is flawed, and I can explain why if you like, but I will leave it to you for now.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: print correctly BCD CMOS RTC values
well, you're actually right; the only function that works is the hour, and the minute and second work bad.the second gives an 'S', and the minute repeats the hour, puts an 'n' and then the minute.
Edit: and please, explain to me, 'cause i dont understand why it fails
Edit: and please, explain to me, 'cause i dont understand why it fails
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: print correctly BCD CMOS RTC values
OK, but I may need a bit more information about what you are doing, where certain things are any how you are using them, and how much you know about certain topics (especially regarding C).alberinfo wrote:please, explain to me, 'cause i dont understand why it fails
To start with, where in your OS code is the strlength() used in print()?
EDIT: nevermind, i found it; for some reason, the GitHub search tool didn't look in include/acpi/string.c, apparently, or perhaps I needed to run the search differently. My Bad. The code is:
Code: Select all
uint16 strlength(string ch)
{
uint16 i = 1;
while(ch[i++]);
return --i;
}
(And why you have both this and a correct implementation of strlen() in the same file...
Code: Select all
size_t strlen(const char *_s)
{
size_t n;
for(n=0; _s[n] != '\0'; n++) {
;
}
return n;
}
Also, what does this comment in string.h about the strEql() function refer to?
Code: Select all
/* Added in episode 3*/
Also, how well do you know C strings, and specifically, what they actually are and how they work? Have you worked with C arrays before? Have you studied C pointers, and used them before in a non-trivial manner (e.g., not just passing them to existing functions)? Do you understand the difference between a string literal, a pointer to a string literal, an array, and a pointer to an array? The problems are all tied up in this topic, and I want to get a better feel for what you know (and what you think you know) before I formulate my explanation.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: print correctly BCD CMOS RTC values
hi,
my knowledge about programming is not much, and are acquired by my own, 'cause i'm only twelve years old (no, i'm not trolling, and i do not know how did i get here) .note that if i do not understand something i search for it, but i try to understand the code in front of me as far as i can, and then modify it to use it in other function and even other projects.i think that the laguage that i worked the most is Visual Basic from visual studio, but, that does not apply to OS development, does it ?, also i've read about C programming (also with c ++ java and uml from "luis joyanes aguilar" (yeah , i'm spanish) from mcgraw hill editorial education, but i havent reached them yet, and another book about Objective-C, from "fernando lopez hernandez", alfaomega editorial), but almost the first book is under windows libraries
the comment comes from: [url] https://www.youtube.com/watch?v=rr-9w2g ... 7UkQP_KLC3 [/ url]. i started like 5 or 6 months ago with this tutorial and it's files, but now i'm planting if i should write my own libraries.
about strings, as far as i know, they are characters together resulting in a string.i have not worked with arrays, but i understand them.i have 'studied' or better said learned that an pointer points to a memory address, but in the practice sometimes acts like a pointer, and sometimes it does not.i do not want to disappoint you, but no, i dont know the difference between a string literal an pointer to string literal etc, but i can deduce that one is the string itself, and the other says where is the string in memory is it
Thanks!
my knowledge about programming is not much, and are acquired by my own, 'cause i'm only twelve years old (no, i'm not trolling, and i do not know how did i get here) .note that if i do not understand something i search for it, but i try to understand the code in front of me as far as i can, and then modify it to use it in other function and even other projects.i think that the laguage that i worked the most is Visual Basic from visual studio, but, that does not apply to OS development, does it ?, also i've read about C programming (also with c ++ java and uml from "luis joyanes aguilar" (yeah , i'm spanish) from mcgraw hill editorial education, but i havent reached them yet, and another book about Objective-C, from "fernando lopez hernandez", alfaomega editorial), but almost the first book is under windows libraries
the comment comes from: [url] https://www.youtube.com/watch?v=rr-9w2g ... 7UkQP_KLC3 [/ url]. i started like 5 or 6 months ago with this tutorial and it's files, but now i'm planting if i should write my own libraries.
about strings, as far as i know, they are characters together resulting in a string.i have not worked with arrays, but i understand them.i have 'studied' or better said learned that an pointer points to a memory address, but in the practice sometimes acts like a pointer, and sometimes it does not.i do not want to disappoint you, but no, i dont know the difference between a string literal an pointer to string literal etc, but i can deduce that one is the string itself, and the other says where is the string in memory is it
Thanks!
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: print correctly BCD CMOS RTC values
OK, this gives me a place to start.
I won't restart the debate over under-13 y.o. members, but I expect this may lead one of the mods to act. It isn't any fault of yours, but there are some legal considerations involved, though only really relevant to the U.S. so they probably don't apply here.
I will say that it sounds as if - in terms of experience with programming - you are jumping the gun on this. OS dev is not a project for novices; it is a challenge for even the most experienced systems programmers. I am not saying you shouldn't go forward with the project, but you might want to shelve it for a while and build up your expertise before coming back to it. That's up to you, though.
I have a 'boilerplate' set of links for pages in the wiki which I recommend to all new members, so I will start by posting that. I'll get to the topics of C arrays and strings shortly, but I may need to head out soon so that will come in a later post.
The wiki pages I recommend reading, before going any further in the project are the following. I don't know which, if any, you have already read, but re-reading them may be worthwhile anyway.
Getting Started
How To Ask Questions
FAQ (you need read everything listed there, but you would do well to look at the category itself to see the range of common questions)
Required Knowledge
Beginner Mistakes
What order should I make things in
Code Management
How kernel, compiler, and C library work together
Using Programming Languages other than C
Why do I need a Cross Compiler?
GCC Cross-Compiler (if you are planning to use GCC)
OS Specific Toolchain (again, only if you are using GCC and binutils)
To this, I would add that if you are focusing on an x86 system, you should read through these as well (again, at minimum, skim all the way through them at least once, ahead of time):
Real Mode, especially the section on memory addressing, and Segmentation
Memory Map, Detecting Memory and A20 Line
BIOS, and Boot Sequence
Interrupts
Bootloader and Rolling Your Own Bootloader
FAT and SFS
While this is a lot of reading, it simply reflects the due diligence that any OS-devver needs to go through in order to get anywhere. OS development, even as a simple project, is not amenable to the Stack Overflow cut-and-paste model of software development; you really need to understand a fair amount of the concepts and principles before writing any code, and the examples given in tutorials and forum posts generally are exactly that. Copying an existing code snippet without at least a basic idea of what it is doing simply won't do. While learning itself is an iterative process - you learn one thing, try it out, see what worked and what didn't, read some more, etc. - in this case a basic foundation is needed at the start. Without a solid understanding of at least some of the core ideas before starting, you simply can't get very far in OS dev.
I won't restart the debate over under-13 y.o. members, but I expect this may lead one of the mods to act. It isn't any fault of yours, but there are some legal considerations involved, though only really relevant to the U.S. so they probably don't apply here.
I will say that it sounds as if - in terms of experience with programming - you are jumping the gun on this. OS dev is not a project for novices; it is a challenge for even the most experienced systems programmers. I am not saying you shouldn't go forward with the project, but you might want to shelve it for a while and build up your expertise before coming back to it. That's up to you, though.
I have a 'boilerplate' set of links for pages in the wiki which I recommend to all new members, so I will start by posting that. I'll get to the topics of C arrays and strings shortly, but I may need to head out soon so that will come in a later post.
The wiki pages I recommend reading, before going any further in the project are the following. I don't know which, if any, you have already read, but re-reading them may be worthwhile anyway.
Getting Started
How To Ask Questions
FAQ (you need read everything listed there, but you would do well to look at the category itself to see the range of common questions)
Required Knowledge
Beginner Mistakes
What order should I make things in
Code Management
How kernel, compiler, and C library work together
Using Programming Languages other than C
Why do I need a Cross Compiler?
GCC Cross-Compiler (if you are planning to use GCC)
OS Specific Toolchain (again, only if you are using GCC and binutils)
To this, I would add that if you are focusing on an x86 system, you should read through these as well (again, at minimum, skim all the way through them at least once, ahead of time):
Real Mode, especially the section on memory addressing, and Segmentation
Memory Map, Detecting Memory and A20 Line
BIOS, and Boot Sequence
Interrupts
Bootloader and Rolling Your Own Bootloader
FAT and SFS
While this is a lot of reading, it simply reflects the due diligence that any OS-devver needs to go through in order to get anywhere. OS development, even as a simple project, is not amenable to the Stack Overflow cut-and-paste model of software development; you really need to understand a fair amount of the concepts and principles before writing any code, and the examples given in tutorials and forum posts generally are exactly that. Copying an existing code snippet without at least a basic idea of what it is doing simply won't do. While learning itself is an iterative process - you learn one thing, try it out, see what worked and what didn't, read some more, etc. - in this case a basic foundation is needed at the start. Without a solid understanding of at least some of the core ideas before starting, you simply can't get very far in OS dev.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: print correctly BCD CMOS RTC values
thanks for the links!much of them i have readed yet, but anyway theres happens nothing on re-reading them.also i've fixed the problem, the offset for the hour the minute and the second should be '0'.
Thanks!
Thanks!